Author: simoneg Date: Tue Aug 11 15:15:31 2009 New Revision: 803148 URL: http://svn.apache.org/viewvc?rev=803148&view=rev Log: LABS-398 : review of the linked source folder system
Modified: labs/magma/trunk/magma-eclipse/META-INF/MANIFEST.MF labs/magma/trunk/magma-eclipse/build.properties labs/magma/trunk/magma-eclipse/plugin.xml labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/MFileUtils.java labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/basics/MagmaMavenListener.java labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/basics/MagmaPDEUtils.java Modified: labs/magma/trunk/magma-eclipse/META-INF/MANIFEST.MF URL: http://svn.apache.org/viewvc/labs/magma/trunk/magma-eclipse/META-INF/MANIFEST.MF?rev=803148&r1=803147&r2=803148&view=diff ============================================================================== --- labs/magma/trunk/magma-eclipse/META-INF/MANIFEST.MF (original) +++ labs/magma/trunk/magma-eclipse/META-INF/MANIFEST.MF Tue Aug 11 15:15:31 2009 @@ -2,7 +2,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: Magma Eclipse Bundle-SymbolicName: org.apache.magma.tools.magmaeclipse;singleton:=true -Bundle-Version: 0.0.3 +Bundle-Version: 0.0.3.0004 Bundle-Activator: org.apache.magma.tools.magmaeclipse.Activator Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, @@ -17,8 +17,12 @@ org.eclipse.jdt.launching;bundle-version="3.5.0", org.eclipse.debug.core;bundle-version="3.5.0", org.eclipse.debug.ui;bundle-version="3.5.0", - org.eclipse.core.expressions;bundle-version="3.4.100" + org.eclipse.core.expressions;bundle-version="3.4.100", + org.eclipse.contribution.weaving.jdt;bundle-version="2.0.0", + org.eclipse.equinox.weaving.aspectj;bundle-version="1.0.0", + org.maven.ide.components.maven_embedder Bundle-RequiredExecutionEnvironment: J2SE-1.5 Import-Package: org.apache.maven, org.eclipse.ui.actions Bundle-ActivationPolicy: lazy +Bundle-ClassPath: . Modified: labs/magma/trunk/magma-eclipse/build.properties URL: http://svn.apache.org/viewvc/labs/magma/trunk/magma-eclipse/build.properties?rev=803148&r1=803147&r2=803148&view=diff ============================================================================== --- labs/magma/trunk/magma-eclipse/build.properties (original) +++ labs/magma/trunk/magma-eclipse/build.properties Tue Aug 11 15:15:31 2009 @@ -2,4 +2,5 @@ output.. = bin/ bin.includes = plugin.xml,\ META-INF/,\ - . + .,\ + icons/ Modified: labs/magma/trunk/magma-eclipse/plugin.xml URL: http://svn.apache.org/viewvc/labs/magma/trunk/magma-eclipse/plugin.xml?rev=803148&r1=803147&r2=803148&view=diff ============================================================================== --- labs/magma/trunk/magma-eclipse/plugin.xml (original) +++ labs/magma/trunk/magma-eclipse/plugin.xml Tue Aug 11 15:15:31 2009 @@ -24,7 +24,7 @@ <extension point="org.eclipse.ui.decorators"> <decorator adaptable="true" - icon="bin/icons/magma_overlay.gif" + icon="icons/magma_overlay.gif" id="org.apache.magma.toos.magmaeclipse.magmadecorator" label="Magma project" lightweight="true" @@ -96,7 +96,7 @@ locationURI="popup:org.eclipse.jdt.ui.PackageExplorer?before=additions"> <command commandId="org.apache.magma.tools.magmaeclipse.converttomagma" - icon="bin/icons/magma_add.gif" + icon="icons/magma_add.gif" id="org.apache.magma.tools.magmaeclipse.converttomagmamenuitem" label="Convert to Magma project" style="push"> @@ -108,12 +108,12 @@ <menuContribution locationURI="popup:org.eclipse.jdt.ui.PackageExplorer?before=additions"> <menu - icon="bin/icons/magma_icon.gif" + icon="icons/magma_icon.gif" label="Magma " tooltip="Magma operations"> <command commandId="org.apache.magma.tools.magmaeclipse.projectsetup" - icon="src/icons/magma_refresh.gif" + icon="icons/magma_refresh.gif" label="Update project settings" style="push"> </command> @@ -123,7 +123,7 @@ </separator> <command commandId="org.apache.magma.tools.magmaeclipse.runmagmacmd" - icon="src/icons/magma_run.gif" + icon="icons/magma_run.gif" label="Magma run" style="push"> <parameter @@ -133,7 +133,7 @@ </command> <command commandId="org.apache.magma.tools.magmaeclipse.runmagmacmd" - icon="src/icons/magma_debug.gif" + icon="icons/magma_debug.gif" label="Magma run debug" style="push"> <parameter @@ -147,7 +147,7 @@ </command> <command commandId="org.apache.magma.tools.magmaeclipse.runmagmacmd" - icon="src/icons/magma_install.gif" + icon="icons/magma_install.gif" label="Magma clean install" style="push"> <parameter @@ -163,7 +163,7 @@ commandId="org.apache.magma.tools.magmaeclipse.removemagma" id="org.apache.magma.tools.magmaeclipse.removemagmamenuitem" label="Remove Magma capabilities" - icon="bin/icons/magma_remove.gif" + icon="icons/magma_remove.gif" style="push"> </command> <visibleWhen> @@ -179,7 +179,7 @@ id="org.apache.magma.tools.magmaeclipse.toolbar"> <command commandId="org.apache.magma.tools.magmaeclipse.runmagmacmd" - icon="src/icons/magma_run.gif" + icon="icons/magma_run.gif" label="Magma run" style="push"> <parameter @@ -189,7 +189,7 @@ </command> <command commandId="org.apache.magma.tools.magmaeclipse.runmagmacmd" - icon="src/icons/magma_debug.gif" + icon="icons/magma_debug.gif" label="Magma run debug" style="push"> <parameter @@ -203,7 +203,7 @@ </command> <command commandId="org.apache.magma.tools.magmaeclipse.runmagmacmd" - icon="src/icons/magma_install.gif" + icon="icons/magma_install.gif" label="Magma clean install" style="push"> <parameter @@ -316,19 +316,13 @@ </builder> </extension> - <extension - point="org.maven.ide.eclipse.jdt.classpathConfiguratorFactories"> - <classpathConfiguratorFactory id="org.apache.magma.tools.magmaeclipse.MavenClasspathConfiguratorFactory" - class="org.apache.magma.tools.magmaeclipse.basics.MavenClasspathConfiguratorFactory" - priority="900"/> - </extension> <!-- Launch configurations --> <extension point="org.eclipse.debug.ui.launchShortcuts"> <shortcut id="org.apache.magma.tools.magmaeclipse.runcleaninstall" class="org.maven.ide.eclipse.actions.ExecutePomAction:clean install" - icon="src/icons/magma_install.gif" + icon="icons/magma_install.gif" label="Magma clean install" modes="run"> <contextualLaunch> @@ -349,7 +343,7 @@ </shortcut> <shortcut id="org.apache.magma.tools.magmaeclipse.run" class="org.maven.ide.eclipse.actions.ExecutePomAction:magma:run" - icon="src/icons/magma_run.gif" + icon="icons/magma_run.gif" label="Magma run" modes="run,debug"> <contextualLaunch> @@ -370,6 +364,14 @@ </contextualLaunch> </shortcut> </extension> + <extension + point="org.maven.ide.eclipse.projectConfigurators"> + <configurator + class="org.apache.magma.tools.magmaeclipse.basics.MagmaMavenListener" + id="magma-eclipse.configurator1" + name="Magma"> + </configurator> + </extension> </plugin> Modified: labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/MFileUtils.java URL: http://svn.apache.org/viewvc/labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/MFileUtils.java?rev=803148&r1=803147&r2=803148&view=diff ============================================================================== --- labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/MFileUtils.java (original) +++ labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/MFileUtils.java Tue Aug 11 15:15:31 2009 @@ -10,6 +10,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +import org.codehaus.plexus.util.FileUtils; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFolder; import org.eclipse.core.runtime.CoreException; @@ -28,6 +29,12 @@ * @param dir */ public static void deleteDirectory(File dir) { + try { + FileUtils.deleteDirectory(dir); + } catch (IOException e) { + MLog.exception(e, "Deleting folder " + dir.getAbsolutePath()); + } + /* if (!dir.exists()) return; File[] fls = dir.listFiles(); @@ -39,6 +46,7 @@ } } dir.delete(); + */ } /** Modified: labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/basics/MagmaMavenListener.java URL: http://svn.apache.org/viewvc/labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/basics/MagmaMavenListener.java?rev=803148&r1=803147&r2=803148&view=diff ============================================================================== --- labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/basics/MagmaMavenListener.java (original) +++ labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/basics/MagmaMavenListener.java Tue Aug 11 15:15:31 2009 @@ -1,14 +1,24 @@ package org.apache.magma.tools.magmaeclipse.basics; +import java.util.Map; + import org.apache.magma.tools.magmaeclipse.Activator; import org.apache.magma.tools.magmaeclipse.MLog; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.embedder.MavenEmbedder; +import org.apache.maven.project.MavenProject; import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; import org.maven.ide.eclipse.jdt.BuildPathManager; import org.maven.ide.eclipse.jdt.MavenJdtPlugin; import org.maven.ide.eclipse.project.IMavenProjectChangedListener; import org.maven.ide.eclipse.project.IMavenProjectFacade; import org.maven.ide.eclipse.project.MavenProjectChangedEvent; +import org.maven.ide.eclipse.project.configurator.AbstractProjectConfigurator; +import org.maven.ide.eclipse.project.configurator.ProjectConfigurationRequest; /** * Listens to changes in the Maven project model to update linked @@ -18,29 +28,57 @@ * * @author Simone Gianni <simo...@apache.org> */ -public class MagmaMavenListener implements IMavenProjectChangedListener { +public class MagmaMavenListener extends AbstractProjectConfigurator { - public void mavenProjectChanged(MavenProjectChangedEvent[] chevs, - IProgressMonitor prog) { - for (int i = 0; i < chevs.length; i++) { - MavenProjectChangedEvent ev = chevs[i]; - try { - if (ev.getMavenProject() != null && ev.getMavenProject().getProject().hasNature(MagmaPDEUtils.ID_NATURE)) { - MLog.debug("Maven change in Magma project"); - - IMavenProjectFacade mavenProject = ev.getMavenProject(); - IProject project = mavenProject.getProject(); - - BuildPathManager manager = MavenJdtPlugin.getDefault().getBuildpathManager(); - manager.downloadSources(project, null); - - MagmaPDEUtils.setupProject(project, false, prog); - } - } catch (Exception e) { - MLog.exception(e, "Error while refreshing Maven data"); + @Override + public void configure(MavenEmbedder arg0, ProjectConfigurationRequest arg1, + IProgressMonitor arg2) throws CoreException { + } + + @Override + protected void mavenProjectChanged(MavenProjectChangedEvent event, + IProgressMonitor monitor) throws CoreException { + logme(event); + try { + if (event.getMavenProject() != null && event.getMavenProject().getProject().hasNature(MagmaPDEUtils.ID_NATURE)) { + MLog.debug("Maven change in Magma project"); + + IMavenProjectFacade mavenProject = event.getMavenProject(); + BuildPathManager manager = MavenJdtPlugin.getDefault().getBuildpathManager(); + IProject project = mavenProject.getProject(); + manager.downloadSources(project, null); + + MagmaPDEUtils.setupSourceDependencies(mavenProject, false, monitor); } + } catch (Exception e) { + MLog.exception(e, "Error while refreshing Maven data"); } + + super.mavenProjectChanged(event, monitor); + } + private void logme(MavenProjectChangedEvent event) { + String type = ""; + if (event.getKind() == MavenProjectChangedEvent.KIND_ADDED) { + type ="add "; + } else if (event.getKind() == MavenProjectChangedEvent.KIND_CHANGED) { + type ="cng "; + } else if (event.getKind() == MavenProjectChangedEvent.KIND_REMOVED) { + type ="rem "; + } + + if (event.getFlags() == MavenProjectChangedEvent.FLAG_DEPENDENCIES) { + type += "deps"; + } else if (event.getFlags() == MavenProjectChangedEvent.FLAG_DEPENDENCY_SOURCES) { + type += "dep src "; + } else if (event.getFlags() == MavenProjectChangedEvent.FLAG_ENTRY_SOURCES) { + type += "entry src "; + } else if (event.getFlags() == MavenProjectChangedEvent.FLAG_NONE) { + type += "none "; + } + + MLog.debug("Maven change " + type); + } } Modified: labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/basics/MagmaPDEUtils.java URL: http://svn.apache.org/viewvc/labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/basics/MagmaPDEUtils.java?rev=803148&r1=803147&r2=803148&view=diff ============================================================================== --- labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/basics/MagmaPDEUtils.java (original) +++ labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/basics/MagmaPDEUtils.java Tue Aug 11 15:15:31 2009 @@ -7,9 +7,13 @@ import java.util.Comparator; import java.util.Iterator; import java.util.List; +import java.util.Map; import org.apache.magma.tools.magmaeclipse.MFileUtils; import org.apache.magma.tools.magmaeclipse.MLog; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.embedder.MavenEmbedder; +import org.apache.maven.project.MavenProject; import org.eclipse.ajdt.internal.ui.lazystart.Utils; import org.eclipse.ajdt.internal.ui.preferences.AspectJPreferences; import org.eclipse.ajdt.internal.utils.AJDTUtils; @@ -38,6 +42,10 @@ import org.eclipse.ui.actions.WorkspaceModifyOperation; import org.eclipse.ui.progress.UIJob; import org.maven.ide.eclipse.MavenPlugin; +import org.maven.ide.eclipse.embedder.ArtifactKey; +import org.maven.ide.eclipse.embedder.ArtifactRef; +import org.maven.ide.eclipse.jdt.BuildPathManager; +import org.maven.ide.eclipse.project.IMavenProjectFacade; import org.maven.ide.eclipse.project.ResolverConfiguration; import org.osgi.service.prefs.BackingStoreException; @@ -93,8 +101,18 @@ private static void internal_addMagmaNature(IProject project, boolean prompt) throws CoreException { MLog.log("Adding magma nature to " + project); - + IProjectDescription description = project.getDescription(); + if (!description.hasNature(JavaCore.NATURE_ID)) { + MLog.debug("Adding Java nature"); + String[] prevNatures = description.getNatureIds(); + String[] newNatures = new String[prevNatures.length + 1]; + System.arraycopy(prevNatures, 0, newNatures, 1, prevNatures.length); + newNatures[0] = JavaCore.NATURE_ID; + description.setNatureIds(newNatures); + project.setDescription(description, null); + } + if (!description.hasNature(Utils.ID_NATURE)) { MLog.debug("Adding AJ nature"); AJDTUtils.addAspectJNature(project, true); @@ -256,8 +274,15 @@ public static void internal_setupProject(IProject project, boolean complete, IProgressMonitor mon) { setupProjectStructure(project, complete, mon); - setupSourceDependencies(project, complete, mon); - doneProjectSetup(project); + try { + if (project.hasNature(ID_MAVEN_NATURE)) { + IMavenProjectFacade projectFacade = MavenPlugin.getDefault().getMavenProjectManager().create(project, mon); + setupSourceDependencies(projectFacade, complete, mon); + } + doneProjectSetup(project); + } catch (Exception e) { + MLog.exception(e, "Error setting up project"); + } } /** @@ -408,6 +433,8 @@ } } + + /** * Creates the magmalnk- linked source folders pointing to unzipped * sources of magma projects present on the maven dependencies. @@ -416,12 +443,17 @@ * @param complete * @param prog */ - public static void setupSourceDependencies(IProject project, - boolean complete, IProgressMonitor prog) { - // prog = SubMonitor.convert(prog, "Creating source links", 100); - IJavaProject prj = JavaCore.create(project); - - try { + public static void setupSourceDependencies + (IMavenProjectFacade mavenProject, boolean complete, IProgressMonitor prog) { + + try { + MavenProject mp = mavenProject.getMavenProject(prog); + Map<String,Artifact> artifactMap = mp.getArtifactMap(); + IProject project = mavenProject.getProject(); + IJavaProject prj = JavaCore.create(project); + + MavenEmbedder embedder = MavenPlugin.getDefault().getMavenProjectManager().createWorkspaceEmbedder(); + // Holds a list of previously existing magmalnk- folders List<String> existing = new ArrayList<String>(); IClasspathEntry[] rawClasspath = prj.getRawClasspath(); @@ -433,12 +465,7 @@ existing.add(entpath); } } - - // Takes the Maven IClasspathContainer - IClasspathContainer cont = JavaCore.getClasspathContainer(new Path( - "org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"), prj); - MLog.debug("found container " + cont); - + // Create a folder for unzipped sources File localrepo = MavenPlugin.getDefault().getMavenEmbedderManager() .getLocalRepositoryDir(); @@ -447,47 +474,37 @@ if (!unzippeds.exists()) { unzippeds.mkdir(); } - + // Create a folder for linked folders output IFolder linkoutfld = project .getFolder("target-eclipse/extra-classes"); if (!linkoutfld.exists()) { MFileUtils.createEntire(linkoutfld, true, true, null); } - // Useless, trying not to include extra-classes in the class files contributed to other projects - //linkoutfld.setHidden(true); - + // Holds a list of newly created magmalnk- folders to add to the classpath List<IClasspathEntry> linkstoadd = new ArrayList<IClasspathEntry>(); - // Check each dependency in the maven classpath - IClasspathEntry[] entries = cont.getClasspathEntries(); - // Holds a list of dependencies Maven should ignore - List<String> toExclude = new ArrayList<String>(); - for (int j = 0; j < entries.length; j++) { - IPath entpath = entries[j].getPath(); - // Only check magma stuff not being a project itself - if (entpath.toString().indexOf("magma") != -1) { - String depname = entpath.lastSegment(); - depname = depname.substring(0, depname.lastIndexOf('.')); + for (Artifact art : artifactMap.values()) { + if (art.getGroupId().startsWith("org.apache.magma")) { + String depname = art.getArtifactId() + "-" + art.getVersion(); + if (prog != null) prog.subTask("Processing " + depname); MLog.debug("Found magma dep " + depname); - IPath src = entries[j].getSourceAttachmentPath(); + + Artifact srcart = embedder.createArtifactWithClassifier( + art.getGroupId(), // + art.getArtifactId(), art.getVersion(), "java-source", "sources"); + + String deppath = embedder.getLocalRepository().pathOf(srcart); + File srcfile = new File(localrepo, deppath); // Only do it if it has source attachment - if (src != null) { + if (srcfile.exists()) { // Remove it from the existing, cause now it exists existing.remove(depname); - // Add to the list of dependency to exclude - toExclude.add(depname); - String deppath = src.toString().substring( - localrepo.getAbsolutePath().length()); - while (deppath.startsWith(File.separator) - || deppath.startsWith("/")) - deppath = deppath.substring(1); MLog.debug(" having source " + deppath); File localunzip = new File(unzippeds, deppath); - File srcfile = src.toFile(); // Check if the physical sources folder exist or is old boolean needupdate = true; if (localunzip.exists()) { @@ -507,6 +524,7 @@ } localunzip.mkdirs(); localunzip.mkdir(); + localunzip.setLastModified(System.currentTimeMillis()); MFileUtils.unzip(srcfile, localunzip); } // Search for an existing linked source @@ -538,55 +556,60 @@ linkstoadd.add(ent); } } - } + } } - // Adjust the project classpath - IClasspathEntry[] nrawClasspath = new IClasspathEntry[rawClasspath.length - - existing.size() + linkstoadd.size()]; - int j = 0; - for (int i = 0; i < rawClasspath.length; i++) { - String entpath = rawClasspath[i].getPath().toString(); - if (entpath.indexOf("magmalnk-") != -1) { - entpath = entpath.substring(entpath.indexOf("magmalnk-")); - entpath = entpath.substring(9); - // Existing at this point contains only those magmalnk- - // folders which were there but should not be there anymore - if (!existing.contains(entpath)) { + if (existing.size() != 0 || linkstoadd.size() != 0) { + IClasspathEntry[] nrawClasspath = new IClasspathEntry[rawClasspath.length + - existing.size() + linkstoadd.size()]; + int j = 0; + for (int i = 0; i < rawClasspath.length; i++) { + String entpath = rawClasspath[i].getPath().toString(); + if (entpath.indexOf("magmalnk-") != -1) { + entpath = entpath.substring(entpath.indexOf("magmalnk-")); + entpath = entpath.substring(9); + // Existing at this point contains only those magmalnk- + // folders which were there but should not be there anymore + if (!existing.contains(entpath)) { + nrawClasspath[j++] = rawClasspath[i]; + continue; + } + } else { + // bypass all the rest nrawClasspath[j++] = rawClasspath[i]; - continue; } - } else { - // bypass all the rest - nrawClasspath[j++] = rawClasspath[i]; } - } - // Add newly created magmalnk- folders or those not on the classpath - for (Iterator iterator = linkstoadd.iterator(); iterator.hasNext();) { - IClasspathEntry nentry = (IClasspathEntry) iterator.next(); - nrawClasspath[j++] = nentry; - } - - sortClasspath(nrawClasspath); - prj.setRawClasspath(nrawClasspath, prog); - - // Delete the links that are still in the "existing" list - for (Iterator iterator = existing.iterator(); iterator.hasNext();) { - String depname = (String) iterator.next(); - IFolder linkfolder = project.getFolder("magmalnk-" + depname); - if (linkfolder.exists()) { - linkfolder.delete(true, prog); + // Add newly created magmalnk- folders or those not on the classpath + for (Iterator iterator = linkstoadd.iterator(); iterator.hasNext();) { + IClasspathEntry nentry = (IClasspathEntry) iterator.next(); + nrawClasspath[j++] = nentry; + } + + sortClasspath(nrawClasspath); + prj.setRawClasspath(nrawClasspath, prog); + + // Delete the links that are still in the "existing" list + for (Iterator iterator = existing.iterator(); iterator.hasNext();) { + String depname = (String) iterator.next(); + IFolder linkfolder = project.getFolder("magmalnk-" + depname); + if (linkfolder.exists()) { + linkfolder.delete(true, prog); + } } } - + + } catch (Exception e) { MLog.exception(e, "Error setting up linked folders"); } finally { // prog.done(); } + + } + /** * Adds a single entry, as the first one, to a classpath array. * @param prj The project --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@labs.apache.org For additional commands, e-mail: commits-h...@labs.apache.org