[jbosstools-commits] JBoss Tools SVN: r40713 - in trunk/common/plugins: org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog and 1 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Wed May 2 08:19:16 EDT 2012


Author: fbricon
Date: 2012-05-02 08:19:15 -0400 (Wed, 02 May 2012)
New Revision: 40713

Modified:
   trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/MaterializeLibraryDialog.java
   trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/handlers/MaterializeLibraryHandler.java
   trunk/common/plugins/org.jboss.tools.common.jdt/src/org/jboss/tools/common/jdt/core/buildpath/MaterializeLibraryJob.java
Log:
JBIDE-11723 : fix library materialization to project root

Modified: trunk/common/plugins/org.jboss.tools.common.jdt/src/org/jboss/tools/common/jdt/core/buildpath/MaterializeLibraryJob.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.jdt/src/org/jboss/tools/common/jdt/core/buildpath/MaterializeLibraryJob.java	2012-05-02 11:24:30 UTC (rev 40712)
+++ trunk/common/plugins/org.jboss.tools.common.jdt/src/org/jboss/tools/common/jdt/core/buildpath/MaterializeLibraryJob.java	2012-05-02 12:19:15 UTC (rev 40713)
@@ -39,7 +39,7 @@
 
 public class MaterializeLibraryJob extends WorkspaceJob {
 
-	private final IFolder libFolder;
+	private final IContainer libFolder;
 	private final IJavaProject javaProject;
 	private final Map<IPath, String> jars;
 	private final IClasspathContainer containerToRemove;
@@ -48,7 +48,7 @@
 	public MaterializeLibraryJob(IJavaProject javaProject,
 								 IClasspathContainer containerToMaterialize,
 								 Map<IPath, String> jars, 
-								 IFolder libFolder, 
+								 IContainer libFolder, 
 								 boolean keepSourceAttachments) {
 		super(Messages.Materialize_Library); 
 		if (javaProject == null || javaProject.getProject() == null) {
@@ -114,7 +114,9 @@
 		
 		monitor.beginTask(Messages.Materialize_Library, jarSize); 
 		
-		mkdirs(libFolder, monitor);
+		if (libFolder instanceof IFolder) {
+			mkdirs((IFolder)libFolder, monitor);
+		}
 
 		IPath destination = libFolder.getLocation();
 
@@ -235,6 +237,5 @@
 				x = x.getParent();
 			}
 		}
-
 	}
 }
\ No newline at end of file

Modified: trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/MaterializeLibraryDialog.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/MaterializeLibraryDialog.java	2012-05-02 11:24:30 UTC (rev 40712)
+++ trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/MaterializeLibraryDialog.java	2012-05-02 12:19:15 UTC (rev 40713)
@@ -16,10 +16,11 @@
 import java.util.Map;
 import java.util.Set;
 
-import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRoot;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IStatus;
@@ -71,7 +72,7 @@
 
 	private static final String FILENAME_PROPERTY = "FILENAME_PROPERTY";
 
-	private IFolder libFolder;
+	private IContainer libFolder;
 	private Map<IClasspathEntry, String> classpathEntryPaths;
 	private Map<IPath, String> selectedClasspathEntryPaths;
 	private IClasspathContainer containerToMaterialize;
@@ -298,7 +299,7 @@
 		return selectedClasspathEntryPaths;
 	}
 
-	public IFolder getLibFolder() {
+	public IContainer getLibFolder() {
 		return libFolder;
 	}
 
@@ -306,10 +307,16 @@
 		return keepSources;
 	}
 
-	private static IFolder getLibFolderFromText(String text) {
+	private static IContainer getLibFolderFromText(String text) {
 		String portablePath = text.replaceAll("\\\\", "/");
+		IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
 		IPath path = new Path(portablePath);
-		return ResourcesPlugin.getWorkspace().getRoot().getFolder(path);
+		if (path.segmentCount() == 1) {
+			return workspaceRoot.getProject(path.segment(0));
+		} if (path.segmentCount() > 1) {
+			return ResourcesPlugin.getWorkspace().getRoot().getFolder(path);
+		}
+		return null;
 	}
 
 	@Override
@@ -343,10 +350,15 @@
 	}
 
 	private boolean validateLibFolder() {
-		IFolder folder = getLibFolderFromText(libfolderText.getText());
+		IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+		
+		IContainer folder = getLibFolderFromText(libfolderText.getText());
+		if (folder == null || workspaceRoot.equals(folder)) {
+			setErrorMessage("You must select a project destination to copy classpath entries");
+			return false;
+		}
 		String ancestorPath = folder.getFullPath().segment(0);
-		IResource ancestor = ResourcesPlugin.getWorkspace().getRoot()
-				.findMember(ancestorPath);
+		IResource ancestor = workspaceRoot.findMember(ancestorPath);
 		if (ancestor == null || !ancestor.exists()) {
 			setErrorMessage(ancestorPath + " does not exist ");
 			return false;
@@ -354,12 +366,12 @@
 		return true;
 	}
 
+	@SuppressWarnings("unchecked")
 	private boolean validateEntries() {
 		Object[] selection = classpathEntriesViewer.getCheckedElements();
 		selectedClasspathEntryPaths = new LinkedHashMap<IPath, String>(
 				selection.length);
 		for (Object o : selection) {
-			@SuppressWarnings("unchecked")
 			Map.Entry<IClasspathEntry, String> entry = (Map.Entry<IClasspathEntry, String>) o;
 			if (entry.getKey().getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
 				String name = entry.getValue();

Modified: trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/handlers/MaterializeLibraryHandler.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/handlers/MaterializeLibraryHandler.java	2012-05-02 11:24:30 UTC (rev 40712)
+++ trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/handlers/MaterializeLibraryHandler.java	2012-05-02 12:19:15 UTC (rev 40713)
@@ -15,7 +15,7 @@
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResourceRuleFactory;
 import org.eclipse.core.resources.ResourcesPlugin;
@@ -85,7 +85,7 @@
         if(dialog.open() == Dialog.OK) {
           Map<IPath, String> jarsToMaterialize = dialog.getSelectedClasspathEntryPaths();
   
-          IFolder libFolder = dialog.getLibFolder();
+          IContainer libFolder = dialog.getLibFolder();
           
           Job job = new MaterializeLibraryJob(javaProject, 
                                               containerToMaterialize,



More information about the jbosstools-commits mailing list