From be3f03e319706890f8dcdacaa36a5eea89ddeee8 Mon Sep 17 00:00:00 2001 From: rfeng Date: Thu, 2 Apr 2009 18:16:21 +0000 Subject: Update to the latest maven-eclipse-plugin 2.6 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@761364 13f79535-47bb-0310-9956-ffa450edef68 --- maven-plugins/trunk/maven-bundle-plugin/pom.xml | 18 +- .../plugin/eclipse/AbstractIdeSupportMojo.java | 348 +++++----- .../plugin/eclipse/EclipseClasspathWriter.java | 204 ++++-- .../maven/plugin/eclipse/EclipseCleanMojo.java | 55 +- .../maven/plugin/eclipse/EclipsePlugin.java | 729 +++++++++++++++------ .../maven/plugin/eclipse/EclipseProjectWriter.java | 12 +- .../tuscany/maven/plugin/eclipse/Messages.java | 2 +- .../maven/plugin/eclipse/messages.properties | 91 +-- 8 files changed, 941 insertions(+), 518 deletions(-) diff --git a/maven-plugins/trunk/maven-bundle-plugin/pom.xml b/maven-plugins/trunk/maven-bundle-plugin/pom.xml index d145eac38c..b07852887b 100644 --- a/maven-plugins/trunk/maven-bundle-plugin/pom.xml +++ b/maven-plugins/trunk/maven-bundle-plugin/pom.xml @@ -156,7 +156,7 @@ maven-plugin-api 2.0.8 - + org.apache.maven maven-project @@ -168,44 +168,44 @@ - + org.apache.maven maven-settings 2.0.8 - + org.apache.maven maven-artifact 2.0.8 - + org.apache.maven maven-model 2.0.8 - + org.apache.maven.shared maven-dependency-tree 1.1 - + org.apache.maven.plugins maven-eclipse-plugin - 2.5.1 + 2.6 - + org.eclipse osgi 3.3.0-v20070530 compile - + diff --git a/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/plugin/eclipse/AbstractIdeSupportMojo.java b/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/plugin/eclipse/AbstractIdeSupportMojo.java index afa356f440..54200de166 100644 --- a/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/plugin/eclipse/AbstractIdeSupportMojo.java +++ b/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/plugin/eclipse/AbstractIdeSupportMojo.java @@ -20,7 +20,6 @@ package org.apache.tuscany.maven.plugin.eclipse; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; @@ -30,7 +29,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Properties; import java.util.Set; import java.util.TreeSet; import java.util.jar.Attributes; @@ -52,8 +50,10 @@ import org.apache.maven.artifact.resolver.ResolutionNode; import org.apache.maven.artifact.resolver.WarningResolutionListener; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter; +import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.execution.RuntimeInformation; import org.apache.maven.model.Dependency; import org.apache.maven.model.DependencyManagement; import org.apache.maven.model.Exclusion; @@ -61,18 +61,18 @@ import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.eclipse.Constants; +import org.apache.maven.plugin.eclipse.Messages; import org.apache.maven.plugin.ide.IdeDependency; import org.apache.maven.plugin.ide.IdeUtils; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.logging.LogEnabled; import org.codehaus.plexus.logging.Logger; -import org.codehaus.plexus.util.IOUtil; /** * Abstract base plugin which takes care of the common stuff usually needed by maven IDE plugins. A plugin extending - * AbstractIdeSupportMojo should implement the setup() and writeConfiguration() methods, - * plus the getters needed to get the various configuration flags and required components. The lifecycle: - * + * AbstractIdeSupportMojo should implement the setup() and writeConfiguration() methods, plus + * the getters needed to get the various configuration flags and required components. The lifecycle: + * *
  *       *** calls setup() where you can configure your specific stuff and stop the mojo from execute if appropriate ***
  *       - manually resolve project dependencies, NOT failing if a dependency is missing
@@ -81,9 +81,9 @@ import org.codehaus.plexus.util.IOUtil;
  *       *** calls writeConfiguration(), passing the list of resolved referenced dependencies ***
  *       - report the list of missing sources or just tell how to turn this feature on if the flag was disabled
  * 
- * + * * @author Fabrizio Giustina - * @version $Id: AbstractIdeSupportMojo.java 628794 2008-02-18 16:09:11Z aheritier $ + * @version $Id: AbstractIdeSupportMojo.java 727620 2008-12-18 02:35:18Z baerrach $ */ public abstract class AbstractIdeSupportMojo extends AbstractMojo @@ -94,24 +94,23 @@ public abstract class AbstractIdeSupportMojo * Additionally it copies all libraries to a project local directory and references them instead of referencing the * files in the local Maven repository. It also ensured that the "Bundle-Classpath" in META-INF/MANIFEST.MF is * synchronized. - * + * * @parameter expression="${eclipse.pde}" default-value="true" */ protected boolean pde; - + /** * The project whose project files to create. - * + * * @parameter expression="${project}" * @required * @readonly */ protected MavenProject project; - // [rfeng] Change it to use the current project /** * The currently executed project (can be a reactor project). - * + * * @parameter expression="${executedProject}" * @readonly */ @@ -119,14 +118,14 @@ public abstract class AbstractIdeSupportMojo /** * The project packaging. - * + * * @parameter expression="${project.packaging}" */ protected String packaging; /** * Artifact factory, needed to download source jars for inclusion in classpath. - * + * * @component role="org.apache.maven.artifact.factory.ArtifactFactory" * @required * @readonly @@ -135,7 +134,7 @@ public abstract class AbstractIdeSupportMojo /** * Artifact resolver, needed to download source jars for inclusion in classpath. - * + * * @component role="org.apache.maven.artifact.resolver.ArtifactResolver" * @required * @readonly @@ -144,7 +143,7 @@ public abstract class AbstractIdeSupportMojo /** * Artifact collector, needed to resolve dependencies. - * + * * @component role="org.apache.maven.artifact.resolver.ArtifactCollector" * @required * @readonly @@ -156,9 +155,16 @@ public abstract class AbstractIdeSupportMojo */ protected ArtifactMetadataSource artifactMetadataSource; + /** + * The runtime information for Maven, used to retrieve Maven's version number. + * + * @component + */ + private RuntimeInformation runtimeInformation; + /** * Remote repositories which will be searched for source attachments. - * + * * @parameter expression="${project.remoteArtifactRepositories}" * @required * @readonly @@ -167,7 +173,7 @@ public abstract class AbstractIdeSupportMojo /** * Local maven repository. - * + * * @parameter expression="${localRepository}" * @required * @readonly @@ -176,7 +182,7 @@ public abstract class AbstractIdeSupportMojo /** * If the executed project is a reactor project, this will contains the full list of projects in the reactor. - * + * * @parameter expression="${reactorProjects}" * @required * @readonly @@ -185,7 +191,7 @@ public abstract class AbstractIdeSupportMojo /** * Skip the operation when true. - * + * * @parameter expression="${eclipse.skip}" default-value="false" */ private boolean skip; @@ -193,9 +199,9 @@ public abstract class AbstractIdeSupportMojo /** * Enables/disables the downloading of source attachments. Defaults to false. When this flag is true * remote repositories are checked for sources: in order to avoid repeated check for unavailable source archives, a - * status cache is mantained into the target dir of the root project. Run mvn:clean or delete the - * file mvn-eclipse-cache.properties in order to reset this cache. - * + * status cache is mantained. To reset this cache run mvn eclipse:remove-cache, or use the + * forceRecheck option. + * * @parameter expression="${downloadSources}" */ protected boolean downloadSources; @@ -203,13 +209,23 @@ public abstract class AbstractIdeSupportMojo /** * Enables/disables the downloading of javadoc attachments. Defaults to false. When this flag is true * remote repositories are checked for javadocs: in order to avoid repeated check for unavailable javadoc archives, - * a status cache is mantained into the target dir of the root project. Run mvn:clean or delete the - * file mvn-eclipse-cache.properties in order to reset this cache. - * + * a status cache is mantained. To reset this cache run mvn eclipse:remove-cache, or use the + * forceRecheck option. + * * @parameter expression="${downloadJavadocs}" */ protected boolean downloadJavadocs; + /** + * Enables/disables the rechecking of the remote repository for downloading source/javadoc attachments. Defaults to + * false. When this flag is true and the source or javadoc attachment has a status cache to indicate + * that it is not available, then the remote repository will be rechecked for a source or javadoc attachment and the + * status cache updated to reflect the new state. + * + * @parameter expression="${forceRecheck}" + */ + protected boolean forceRecheck; + /** * Plexus logger needed for debugging manual artifact resolution. */ @@ -217,7 +233,7 @@ public abstract class AbstractIdeSupportMojo /** * Getter for artifactMetadataSource. - * + * * @return Returns the artifactMetadataSource. */ public ArtifactMetadataSource getArtifactMetadataSource() @@ -227,7 +243,7 @@ public abstract class AbstractIdeSupportMojo /** * Setter for artifactMetadataSource. - * + * * @param artifactMetadataSource The artifactMetadataSource to set. */ public void setArtifactMetadataSource( ArtifactMetadataSource artifactMetadataSource ) @@ -237,7 +253,7 @@ public abstract class AbstractIdeSupportMojo /** * Getter for project. - * + * * @return Returns the project. */ public MavenProject getProject() @@ -247,7 +263,7 @@ public abstract class AbstractIdeSupportMojo /** * Setter for project. - * + * * @param project The project to set. */ public void setProject( MavenProject project ) @@ -257,7 +273,7 @@ public abstract class AbstractIdeSupportMojo /** * Getter for reactorProjects. - * + * * @return Returns the reactorProjects. */ public List getReactorProjects() @@ -267,7 +283,7 @@ public abstract class AbstractIdeSupportMojo /** * Setter for reactorProjects. - * + * * @param reactorProjects The reactorProjects to set. */ public void setReactorProjects( List reactorProjects ) @@ -277,7 +293,7 @@ public abstract class AbstractIdeSupportMojo /** * Getter for remoteArtifactRepositories. - * + * * @return Returns the remoteArtifactRepositories. */ public List getRemoteArtifactRepositories() @@ -287,7 +303,7 @@ public abstract class AbstractIdeSupportMojo /** * Setter for remoteArtifactRepositories. - * + * * @param remoteArtifactRepositories The remoteArtifactRepositories to set. */ public void setRemoteArtifactRepositories( List remoteArtifactRepositories ) @@ -297,7 +313,7 @@ public abstract class AbstractIdeSupportMojo /** * Getter for artifactFactory. - * + * * @return Returns the artifactFactory. */ public ArtifactFactory getArtifactFactory() @@ -307,7 +323,7 @@ public abstract class AbstractIdeSupportMojo /** * Setter for artifactFactory. - * + * * @param artifactFactory The artifactFactory to set. */ public void setArtifactFactory( ArtifactFactory artifactFactory ) @@ -317,7 +333,7 @@ public abstract class AbstractIdeSupportMojo /** * Getter for artifactResolver. - * + * * @return Returns the artifactResolver. */ public ArtifactResolver getArtifactResolver() @@ -327,7 +343,7 @@ public abstract class AbstractIdeSupportMojo /** * Setter for artifactResolver. - * + * * @param artifactResolver The artifactResolver to set. */ public void setArtifactResolver( ArtifactResolver artifactResolver ) @@ -337,7 +353,7 @@ public abstract class AbstractIdeSupportMojo /** * Getter for executedProject. - * + * * @return Returns the executedProject. */ public MavenProject getExecutedProject() @@ -347,7 +363,7 @@ public abstract class AbstractIdeSupportMojo /** * Setter for executedProject. - * + * * @param executedProject The executedProject to set. */ public void setExecutedProject( MavenProject executedProject ) @@ -357,7 +373,7 @@ public abstract class AbstractIdeSupportMojo /** * Getter for localRepository. - * + * * @return Returns the localRepository. */ public ArtifactRepository getLocalRepository() @@ -367,7 +383,7 @@ public abstract class AbstractIdeSupportMojo /** * Setter for localRepository. - * + * * @param localRepository The localRepository to set. */ public void setLocalRepository( ArtifactRepository localRepository ) @@ -377,7 +393,7 @@ public abstract class AbstractIdeSupportMojo /** * Getter for downloadJavadocs. - * + * * @return Returns the downloadJavadocs. */ public boolean getDownloadJavadocs() @@ -387,8 +403,8 @@ public abstract class AbstractIdeSupportMojo /** * Setter for downloadJavadocs. - * - * @param downloadJavadocs The downloadJavadocs to set. + * + * @param downloadJavadoc The downloadJavadocs to set. */ public void setDownloadJavadocs( boolean downloadJavadoc ) { @@ -397,7 +413,7 @@ public abstract class AbstractIdeSupportMojo /** * Getter for downloadSources. - * + * * @return Returns the downloadSources. */ public boolean getDownloadSources() @@ -407,7 +423,7 @@ public abstract class AbstractIdeSupportMojo /** * Setter for downloadSources. - * + * * @param downloadSources The downloadSources to set. */ public void setDownloadSources( boolean downloadSources ) @@ -428,14 +444,14 @@ public abstract class AbstractIdeSupportMojo /** * return false if projects available in a reactor build should be considered normal dependencies, * true if referenced project will be linked and not need artifact resolution. - * + * * @return true if referenced project will be linked and not need artifact resolution */ protected abstract boolean getUseProjectReferences(); /** * Hook for preparation steps before the actual plugin execution. - * + * * @return true if execution should continue or false if not. * @throws MojoExecutionException generic mojo exception */ @@ -444,7 +460,7 @@ public abstract class AbstractIdeSupportMojo /** * Main plugin method where dependencies should be processed in order to generate IDE configuration files. - * + * * @param deps list of IdeDependency objects, with artifacts, sources and javadocs already resolved * @throws MojoExecutionException generic mojo exception */ @@ -513,7 +529,7 @@ public abstract class AbstractIdeSupportMojo * Resolve project dependencies. Manual resolution is needed in order to avoid resolution of multiproject artifacts * (if projects will be linked each other an installed jar is not needed) and to avoid a failure when a jar is * missing. - * + * * @throws MojoExecutionException if dependencies can't be resolved * @return resolved IDE dependencies, with attached jars for non-reactor dependencies */ @@ -561,7 +577,7 @@ public abstract class AbstractIdeSupportMojo { getLog().debug( e.getMessage(), e ); getLog().error( - Messages.getString( "artifactresolution", new Object[] { //$NON-NLS-1$ + Messages.getString( "AbstractIdeSupportMojo.artifactresolution", new Object[] { //$NON-NLS-1$ e.getGroupId(), e.getArtifactId(), e.getVersion(), e.getMessage() } ) ); @@ -592,7 +608,7 @@ public abstract class AbstractIdeSupportMojo { getLog().debug( e.getMessage(), e ); getLog().warn( - Messages.getString( "artifactdownload", new Object[] { //$NON-NLS-1$ + Messages.getString( "AbstractIdeSupportMojo.artifactdownload", new Object[] { //$NON-NLS-1$ e.getGroupId(), e.getArtifactId(), e.getVersion(), e.getMessage() } ) ); } @@ -600,7 +616,7 @@ public abstract class AbstractIdeSupportMojo { getLog().debug( e.getMessage(), e ); getLog().warn( - Messages.getString( "artifactresolution", new Object[] { //$NON-NLS-1$ + Messages.getString( "AbstractIdeSupportMojo.artifactresolution", new Object[] { //$NON-NLS-1$ e.getGroupId(), e.getArtifactId(), e.getVersion(), e.getMessage() } ) ); } @@ -617,9 +633,9 @@ public abstract class AbstractIdeSupportMojo } } - if ( includeArtifact && - ( !( getUseProjectReferences() && isAvailableAsAReactorProject( art ) ) || emittedReactorProjectId.add( art.getGroupId() + - '-' + art.getArtifactId() ) ) ) + if ( includeArtifact + && ( !( getUseProjectReferences() && isAvailableAsAReactorProject( art ) ) || emittedReactorProjectId.add( art.getGroupId() + + '-' + art.getArtifactId() ) ) ) { // the following doesn't work: art.getArtifactHandler().getPackaging() always returns "jar" @@ -715,7 +731,7 @@ public abstract class AbstractIdeSupportMojo /** * Find the name of the project as used in eclipse. - * + * * @param artifact The artifact to find the eclipse name for. * @return The name os the eclipse project. */ @@ -724,7 +740,7 @@ public abstract class AbstractIdeSupportMojo /** * Returns the list of project artifacts. Also artifacts generated from referenced projects will be added, but with * the resolved property set to true. - * + * * @return list of projects artifacts * @throws MojoExecutionException if unable to parse dependency versions */ @@ -749,7 +765,7 @@ public abstract class AbstractIdeSupportMojo { throw new MojoExecutionException( Messages.getString( - "unabletoparseversion", new Object[] { //$NON-NLS-1$ + "AbstractIdeSupportMojo.unabletoparseversion", new Object[] { //$NON-NLS-1$ dependency.getArtifactId(), dependency.getVersion(), dependency.getManagementKey(), e.getMessage() } ), @@ -797,37 +813,47 @@ public abstract class AbstractIdeSupportMojo /** * Utility method that locates a project producing the given artifact. - * + * * @param artifact the artifact a project should produce. * @return true if the artifact is produced by a reactor projectart. */ protected boolean isAvailableAsAReactorProject( Artifact artifact ) { + return getReactorProject( artifact ) != null; + } + + /** + * Checks the list of reactor projects to see if the artifact is included. + * + * @param artifact the artifact to check if it is in the reactor + * @return the reactor project or null if it is not in the reactor + */ + protected MavenProject getReactorProject( Artifact artifact ) { if ( reactorProjects != null ) { for ( Iterator iter = reactorProjects.iterator(); iter.hasNext(); ) { MavenProject reactorProject = (MavenProject) iter.next(); - if ( reactorProject.getGroupId().equals( artifact.getGroupId() ) && - reactorProject.getArtifactId().equals( artifact.getArtifactId() ) ) + if ( reactorProject.getGroupId().equals( artifact.getGroupId() ) + && reactorProject.getArtifactId().equals( artifact.getArtifactId() ) ) { if ( reactorProject.getVersion().equals( artifact.getVersion() ) ) { - return true; + return reactorProject; } else { getLog().info( - "Artifact " + - artifact.getId() + - " already available as a reactor project, but with different version. Expected: " + - artifact.getVersion() + ", found: " + reactorProject.getVersion() ); + "Artifact " + + artifact.getId() + + " already available as a reactor project, but with different version. Expected: " + + artifact.getVersion() + ", found: " + reactorProject.getVersion() ); } } } } - return false; + return null; } /** @@ -861,7 +887,7 @@ public abstract class AbstractIdeSupportMojo } catch ( InvalidVersionSpecificationException e ) { - throw new MojoExecutionException( Messages.getString( "unabletoparseversion", new Object[] { //$NON-NLS-1$ + throw new MojoExecutionException( Messages.getString( "AbstractIdeSupportMojo.unabletoparseversion", new Object[] { //$NON-NLS-1$ projectId, d.getVersion(), d.getManagementKey(), e.getMessage() } ), e ); @@ -875,105 +901,36 @@ public abstract class AbstractIdeSupportMojo return map; } - /** - * Find the reactor target dir. executedProject doesn't have the multiproject root dir set, and the only way to - * extract it is iterating on parent projects. - * - * @param prj current project - * @return the parent target dir. - */ - private File getReactorTargetDir( MavenProject prj ) - { - if ( prj.getParent() != null ) - { - if ( prj.getParent().getBasedir() != null && prj.getParent().getBasedir().exists() ) - { - return getReactorTargetDir( prj.getParent() ); - } - } - return new File( prj.getBuild().getDirectory() ); - } - /** * Resolve source artifacts and download them if downloadSources is true. Source and * javadocs artifacts will be attached to the IdeDependency Resolve source and javadoc artifacts. The - * resolved artifacts will be downloaded based on the downloadSources and - * downloadJavadocs attributes. Source and - * + * resolved artifacts will be downloaded based on the downloadSources and downloadJavadocs + * attributes. Source and + * * @param deps resolved dependencies */ private void resolveSourceAndJavadocArtifacts( IdeDependency[] deps ) { - - File reactorTargetDir = getReactorTargetDir( project ); - File unavailableArtifactsTmpFile = new File( reactorTargetDir, "mvn-eclipse-cache.properties" ); - - getLog().info( "Using source status cache: " + unavailableArtifactsTmpFile.getAbsolutePath() ); - - // create target dir if missing - if ( !unavailableArtifactsTmpFile.getParentFile().exists() ) - { - unavailableArtifactsTmpFile.getParentFile().mkdirs(); - } - - Properties unavailableArtifactsCache = new Properties(); - if ( unavailableArtifactsTmpFile.exists() ) - { - InputStream is = null; - try - { - is = new FileInputStream( unavailableArtifactsTmpFile ); - unavailableArtifactsCache.load( is ); - } - catch ( IOException e ) - { - getLog().warn( "Unable to read source status for reactor projects" ); - } - finally - { - IOUtil.close( is ); - } - - } - final List missingSources = - resolveDependenciesWithClassifier( deps, "sources", getDownloadSources(), unavailableArtifactsCache ); + resolveDependenciesWithClassifier( deps, "sources", getDownloadSources() ); missingSourceDependencies.addAll( missingSources ); final List missingJavadocs = - resolveDependenciesWithClassifier( deps, "javadoc", getDownloadJavadocs(), unavailableArtifactsCache ); + resolveDependenciesWithClassifier( deps, "javadoc", getDownloadJavadocs() ); missingJavadocDependencies.addAll( missingJavadocs ); - - FileOutputStream fos = null; - try - { - fos = new FileOutputStream( unavailableArtifactsTmpFile ); - unavailableArtifactsCache.store( fos, "Temporary index for unavailable sources and javadocs" ); - } - catch ( IOException e ) - { - getLog().warn( "Unable to cache source status for reactor projects" ); - } - finally - { - IOUtil.close( fos ); - } - } /** - * Resolve the required artifacts for each of the dependency. sources or javadoc - * artifacts (depending on the classifier) are attached to the dependency. - * + * Resolve the required artifacts for each of the dependency. sources or javadoc artifacts + * (depending on the classifier) are attached to the dependency. + * * @param deps resolved dependencies * @param inClassifier the classifier we are looking for (either sources or javadoc) * @param includeRemoteRepositories flag whether we should search remote repositories for the artifacts or not - * @param unavailableArtifactsCache cache of unavailable artifacts * @return the list of dependencies for which the required artifact was not found */ private List resolveDependenciesWithClassifier( IdeDependency[] deps, String inClassifier, - boolean includeRemoteRepositories, - Properties unavailableArtifactsCache ) + boolean includeRemoteRepositories ) { List missingClassifierDependencies = new ArrayList(); @@ -994,21 +951,37 @@ public abstract class AbstractIdeSupportMojo if ( getLog().isDebugEnabled() ) { getLog().debug( - "Searching for sources for " + dependency.getId() + ":" + dependency.getClassifier() + - " at " + dependency.getId() + ":" + inClassifier ); + "Searching for sources for " + dependency.getId() + ":" + dependency.getClassifier() + + " at " + dependency.getId() + ":" + inClassifier ); } - String key = - dependency.getClassifier() == null ? dependency.getId() + ":" + inClassifier : dependency.getId() + - ":" + inClassifier + ":" + dependency.getClassifier(); + Artifact baseArtifact = + artifactFactory.createArtifactWithClassifier( dependency.getGroupId(), dependency.getArtifactId(), + dependency.getVersion(), dependency.getType(), + dependency.getClassifier() ); + baseArtifact = + IdeUtils.resolveArtifact( artifactResolver, baseArtifact, remoteRepos, localRepository, getLog() ); + if (!baseArtifact.isResolved()) { + // base artifact does not exist - no point checking for javadoc/sources + continue; + } + + Artifact artifact = + IdeUtils.createArtifactWithClassifier( dependency.getGroupId(), dependency.getArtifactId(), + dependency.getVersion(), dependency.getClassifier(), + inClassifier, artifactFactory ); + File notAvailableMarkerFile = IdeUtils.getNotAvailableMarkerFile( localRepository, artifact ); + + if (forceRecheck && notAvailableMarkerFile.exists()) { + if (!notAvailableMarkerFile.delete()) { + getLog().warn( Messages.getString( "AbstractIdeSupportMojo.unabletodeletenotavailablemarkerfile", notAvailableMarkerFile ) ); + } + } - if ( !unavailableArtifactsCache.containsKey( key ) ) + if ( !notAvailableMarkerFile.exists() ) { - Artifact artifact = - IdeUtils.resolveArtifactWithClassifier( dependency.getGroupId(), dependency.getArtifactId(), - dependency.getVersion(), dependency.getClassifier(), - inClassifier, localRepository, artifactResolver, - artifactFactory, remoteRepos, getLog() ); + artifact = + IdeUtils.resolveArtifact( artifactResolver, artifact, remoteRepos, localRepository, getLog() ); if ( artifact.isResolved() ) { if ( "sources".equals( inClassifier ) ) @@ -1022,7 +995,19 @@ public abstract class AbstractIdeSupportMojo } else { - unavailableArtifactsCache.put( key, Boolean.TRUE.toString() ); + if ( includeRemoteRepositories ) + { + try + { + notAvailableMarkerFile.createNewFile(); + getLog().debug( Messages.getString( "AbstractIdeSupportMojo.creatednotavailablemarkerfile", notAvailableMarkerFile ) ); + } + catch ( IOException e ) + { + getLog().warn( Messages.getString( "AbstractIdeSupportMojo.failedtocreatenotavailablemarkerfile", + notAvailableMarkerFile ) ); + } + } // add the dependencies to the list // of those lacking the required // artifact @@ -1048,17 +1033,17 @@ public abstract class AbstractIdeSupportMojo { if ( getDownloadSources() ) { - msg.append( Messages.getString( "sourcesnotavailable" ) ); //$NON-NLS-1$ + msg.append( Messages.getString( "AbstractIdeSupportMojo.sourcesnotavailable" ) ); //$NON-NLS-1$ } else { - msg.append( Messages.getString( "sourcesnotdownloaded" ) ); //$NON-NLS-1$ + msg.append( Messages.getString( "AbstractIdeSupportMojo.sourcesnotdownloaded" ) ); //$NON-NLS-1$ } for ( Iterator it = missingSourceDependencies.iterator(); it.hasNext(); ) { IdeDependency art = (IdeDependency) it.next(); - msg.append( Messages.getString( "sourcesmissingitem", art.getId() ) ); //$NON-NLS-1$ + msg.append( Messages.getString( "AbstractIdeSupportMojo.sourcesmissingitem", art.getId() ) ); //$NON-NLS-1$ } msg.append( "\n" ); //$NON-NLS-1$ } @@ -1067,17 +1052,17 @@ public abstract class AbstractIdeSupportMojo { if ( getDownloadJavadocs() ) { - msg.append( Messages.getString( "javadocnotavailable" ) ); //$NON-NLS-1$ + msg.append( Messages.getString( "AbstractIdeSupportMojo.javadocnotavailable" ) ); //$NON-NLS-1$ } else { - msg.append( Messages.getString( "javadocnotdownloaded" ) ); //$NON-NLS-1$ + msg.append( Messages.getString( "AbstractIdeSupportMojo.javadocnotdownloaded" ) ); //$NON-NLS-1$ } for ( Iterator it = missingJavadocDependencies.iterator(); it.hasNext(); ) { IdeDependency art = (IdeDependency) it.next(); - msg.append( Messages.getString( "javadocmissingitem", art.getId() ) ); //$NON-NLS-1$ + msg.append( Messages.getString( "AbstractIdeSupportMojo.javadocmissingitem", art.getId() ) ); //$NON-NLS-1$ } msg.append( "\n" ); //$NON-NLS-1$ } @@ -1092,7 +1077,7 @@ public abstract class AbstractIdeSupportMojo /** * Checks if jar has to be resolved for the given artifact - * + * * @param art the artifact to check * @return true if resolution should happen */ @@ -1103,7 +1088,7 @@ public abstract class AbstractIdeSupportMojo /** * Checks if a projects reference has to be used for the given artifact - * + * * @param art the artifact to check * @return true if a project reference has to be used. */ @@ -1111,7 +1096,29 @@ public abstract class AbstractIdeSupportMojo { return getUseProjectReferences() && isAvailableAsAReactorProject( art ); } - + + /** + * Checks whether the currently running Maven satisfies the specified version (range). + * + * @param version The version range to test for, must not be null. + * @return true if the current Maven version matches the specified version range, false + * otherwise. + */ + protected boolean isMavenVersion( String version ) + { + try + { + VersionRange versionRange = VersionRange.createFromVersionSpec( version ); + ArtifactVersion mavenVersion = runtimeInformation.getApplicationVersion(); + return versionRange.containsVersion( mavenVersion ); + } + catch ( InvalidVersionSpecificationException e ) + { + throw new IllegalArgumentException( e.getMessage() ); + } + } + + // [rfeng] protected boolean isOSGiBundle() { File base = project.getBasedir(); File mf = new File(base, "META-INF/MANIFEST.MF"); @@ -1133,4 +1140,5 @@ public abstract class AbstractIdeSupportMojo } return false; } + } diff --git a/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/plugin/eclipse/EclipseClasspathWriter.java b/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/plugin/eclipse/EclipseClasspathWriter.java index aae1b607ab..abdf75ae96 100644 --- a/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/plugin/eclipse/EclipseClasspathWriter.java +++ b/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/plugin/eclipse/EclipseClasspathWriter.java @@ -32,9 +32,13 @@ import java.util.Map; import java.util.Set; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.eclipse.BuildCommand; import org.apache.maven.plugin.eclipse.Constants; import org.apache.maven.plugin.eclipse.EclipseSourceDir; +import org.apache.maven.plugin.eclipse.Messages; import org.apache.maven.plugin.eclipse.writers.AbstractEclipseWriter; +import org.apache.maven.plugin.eclipse.writers.EclipseAntExternalLaunchConfigurationWriter; +import org.apache.maven.plugin.eclipse.writers.EclipseLaunchConfigurationWriter; import org.apache.maven.plugin.ide.IdeDependency; import org.apache.maven.plugin.ide.IdeUtils; import org.codehaus.plexus.util.IOUtil; @@ -44,20 +48,50 @@ import org.codehaus.plexus.util.xml.XMLWriter; /** * Writes eclipse .classpath file. - * + * * @author Trygve Laugstøl * @author Kenney Westerhof * @author Fabrizio Giustina - * @version $Id: EclipseClasspathWriter.java 636955 2008-03-14 02:10:42Z aheritier $ + * @version $Id: EclipseClasspathWriter.java 750073 2009-03-04 16:55:01Z aheritier $ */ public class EclipseClasspathWriter extends AbstractEclipseWriter { + /** + * + */ + private static final String ORG_ECLIPSE_AJDT_INPATH = "org.eclipse.ajdt.inpath"; + + /** + * + */ + private static final String ORG_ECLIPSE_AJDT_ASPECTPATH = "org.eclipse.ajdt.aspectpath"; + + /** + * + */ + private static final String NAME = "name"; + + /** + * + */ + private static final String VALUE = "value"; + + /** + * + */ + private static final String ATTRIBUTE = "attribute"; + + /** + * + */ + private static final String ATTRIBUTES = "attributes"; + /** * Eclipse build path variable M2_REPO */ - private static final String M2_REPO = "M2_REPO"; //$NON-NLS-1$ + protected static final String M2_REPO = "M2_REPO"; //$NON-NLS-1$ /** * Attribute for sourcepath. @@ -120,7 +154,7 @@ public class EclipseClasspathWriter private static final String FILE_DOT_CLASSPATH = ".classpath"; //$NON-NLS-1$ /** - * @see org.apache.tuscany.sca.maven.plugin.eclipse.writers.EclipseWriter#write() + * @see org.apache.maven.plugin.eclipse.writers.EclipseWriter#write() */ public void write() throws MojoExecutionException @@ -175,8 +209,8 @@ public class EclipseClasspathWriter { EclipseSourceDir dir = config.getSourceDirs()[j]; - log.debug( "Processing " + ( dir.isResource() ? "re" : "" ) + "source " + dir.getPath() + ": output=" + - dir.getOutput() + "; default output=" + defaultOutput ); + log.debug( "Processing " + ( dir.isResource() ? "re" : "" ) + "source " + dir.getPath() + ": output=" + + dir.getOutput() + "; default output=" + defaultOutput ); boolean isSpecial = false; @@ -187,8 +221,7 @@ public class EclipseClasspathWriter // and if the default output has any sources that copy there. if ( dir.getOutput() != null // resource output dir is set - && - !dir.getOutput().equals( defaultOutput ) // output dir is not default target/classes + && !dir.getOutput().equals( defaultOutput ) // output dir is not default target/classes && dir.getOutput().startsWith( defaultOutput ) // ... but is nested && byOutputDir.get( defaultOutput ) != null // ??? && !( (List) byOutputDir.get( defaultOutput ) ).isEmpty() // ??? @@ -197,8 +230,8 @@ public class EclipseClasspathWriter // do not specify as source since the output will be nested. Instead, mark // it as a todo, and handle it with a custom build.xml file later. - log.debug( "Marking as special to prevent output folder nesting: " + dir.getPath() + " (output=" + - dir.getOutput() + ")" ); + log.debug( "Marking as special to prevent output folder nesting: " + dir.getPath() + " (output=" + + dir.getOutput() + ")" ); isSpecial = true; specialSources.add( dir ); @@ -215,9 +248,18 @@ public class EclipseClasspathWriter writer.addAttribute( ATTR_OUTPUT, dir.getOutput() ); } - if ( StringUtils.isNotEmpty( dir.getInclude() ) ) + String includes = dir.getInclude(); + + if ( !dir.isResource() ) + { + // automatically include java files only: eclipse doesn't have the concept of a source only directory so it + // will try to include non-java files found in maven source dirs + includes = StringUtils.isEmpty( includes ) ? "**/*.java" : includes + "|**/*.java"; + } + + if ( StringUtils.isNotEmpty( includes ) ) { - writer.addAttribute( ATTR_INCLUDING, dir.getInclude() ); + writer.addAttribute( ATTR_INCLUDING, includes ); } String excludes = dir.getExclude(); @@ -255,12 +297,12 @@ public class EclipseClasspathWriter buildXmlPrinter.addAttribute( "default", "copy-resources" ); buildXmlPrinter.startElement( "target" ); - buildXmlPrinter.addAttribute( "name", "init" ); + buildXmlPrinter.addAttribute( NAME, "init" ); // initialize filtering tokens here buildXmlPrinter.endElement(); buildXmlPrinter.startElement( "target" ); - buildXmlPrinter.addAttribute( "name", "copy-resources" ); + buildXmlPrinter.addAttribute( NAME, "copy-resources" ); buildXmlPrinter.addAttribute( "depends", "init" ); for ( Iterator it = specialSources.iterator(); it.hasNext(); ) @@ -295,8 +337,8 @@ public class EclipseClasspathWriter } catch ( IOException e ) { - throw new MojoExecutionException( "Cannot create " + config.getEclipseProjectDirectory() + - "/maven-eclipse.xml", e ); + throw new MojoExecutionException( "Cannot create " + config.getEclipseProjectDirectory() + + "/maven-eclipse.xml", e ); } log.info( "Creating external launcher file" ); @@ -310,9 +352,9 @@ public class EclipseClasspathWriter new BuildCommand( "org.eclipse.ui.externaltools.ExternalToolBuilder", "LaunchConfigHandle", - "/" + - EclipseLaunchConfigurationWriter.FILE_DOT_EXTERNAL_TOOL_BUILDERS + - "Maven_Ant_Builder.launch" ) ); + "/" + + EclipseLaunchConfigurationWriter.FILE_DOT_EXTERNAL_TOOL_BUILDERS + + "Maven_Ant_Builder.launch" ) ); } */ @@ -325,33 +367,39 @@ public class EclipseClasspathWriter writer.addAttribute( ATTR_PATH, defaultOutput ); writer.endElement(); + Set addedDependencies = new HashSet(); + // TODO if (..magic property equals orderDependencies..) + // ---------------------------------------------------------------------- - // Container classpath entries + // Java API dependencies that may complete the classpath container so must + // be declared BEFORE so that container access rules don't fail // ---------------------------------------------------------------------- - - for ( Iterator it = config.getClasspathContainers().iterator(); it.hasNext(); ) + IdeDependency[] depsToWrite = config.getDepsOrdered(); + for ( int j = 0; j < depsToWrite.length; j++ ) { - writer.startElement( ELT_CLASSPATHENTRY ); - writer.addAttribute( ATTR_KIND, "con" ); //$NON-NLS-1$ - writer.addAttribute( ATTR_PATH, (String) it.next() ); - writer.endElement(); // name + IdeDependency dep = depsToWrite[j]; + if ( dep.isJavaApi() ) + { + String depId = getDependencyId( dep ); + if ( !addedDependencies.contains( depId ) ) + { + addDependency( writer, dep ); + addedDependencies.add( depId ); + } + } } // ---------------------------------------------------------------------- // The dependencies // ---------------------------------------------------------------------- - Set addedDependencies = new HashSet(); - // TODO if (..magic property equals orderDependencies..) - IdeDependency[] depsToWrite = config.getDepsOrdered(); for ( int j = 0; j < depsToWrite.length; j++ ) { IdeDependency dep = depsToWrite[j]; if ( dep.isAddedToClasspath() ) { - String depId = - dep.getGroupId() + ":" + dep.getArtifactId() + ":" + dep.getClassifier() + ":" + dep.getVersion(); - /* avoid duplicates in the classpath for artifacts with different types (like ejbs) */ + String depId = getDependencyId( dep ); + /* avoid duplicates in the classpath for artifacts with different types (like ejbs or test-jars) */ if ( !addedDependencies.contains( depId ) ) { addDependency( writer, dep ); @@ -360,12 +408,37 @@ public class EclipseClasspathWriter } } + // ---------------------------------------------------------------------- + // Container classpath entries + // ---------------------------------------------------------------------- + + for ( Iterator it = config.getClasspathContainers().iterator(); it.hasNext(); ) + { + writer.startElement( ELT_CLASSPATHENTRY ); + writer.addAttribute( ATTR_KIND, "con" ); //$NON-NLS-1$ + writer.addAttribute( ATTR_PATH, (String) it.next() ); + writer.endElement(); // name + } + writer.endElement(); IOUtil.close( w ); } + private String getDependencyId( IdeDependency dep ) + { + String depId = + dep.getGroupId() + ":" + dep.getArtifactId() + ":" + dep.getClassifier() + ":" + dep.getVersion(); + + if ( dep.isReferencedProject() ) + { + // This dependency will be refered as an eclipse project + depId = dep.getEclipseProjectName(); + } + return depId; + } + protected void addDependency( XMLWriter writer, IdeDependency dep ) throws MojoExecutionException { @@ -452,11 +525,10 @@ public class EclipseClasspathWriter if ( ATTR_VAR.equals( kind ) ) { sourcepath = - M2_REPO + - "/" //$NON-NLS-1$ - + - IdeUtils.toRelativeAndFixSeparator( localRepositoryFile, dep.getSourceAttachment(), - false ); + M2_REPO + + "/" //$NON-NLS-1$ + + IdeUtils.toRelativeAndFixSeparator( localRepositoryFile, dep.getSourceAttachment(), + false ); } else { @@ -477,6 +549,12 @@ public class EclipseClasspathWriter } + // Skip aspectj libraries since they are in the container. + if ( ( config.getAjdtVersion() != 0 ) && dep.getArtifactId().toLowerCase().startsWith( "aspectj" ) ) + { + return; + } + writer.startElement( ELT_CLASSPATHENTRY ); writer.addAttribute( ATTR_KIND, kind ); writer.addAttribute( ATTR_PATH, path ); @@ -492,30 +570,60 @@ public class EclipseClasspathWriter { if ( !attributeElemOpen ) { - writer.startElement( "attributes" ); //$NON-NLS-1$ + writer.startElement( ATTRIBUTES ); //$NON-NLS-1$ + attributeElemOpen = true; + } + + writer.startElement( ATTRIBUTE ); //$NON-NLS-1$ + writer.addAttribute( VALUE, "jar:" + new File( javadocpath ).toURI() + "!/" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + writer.addAttribute( NAME, "javadoc_location" ); //$NON-NLS-1$ //$NON-NLS-2$ + writer.endElement(); + + } + + if ( Constants.PROJECT_PACKAGING_WAR.equals( this.config.getPackaging() ) && config.getWtpapplicationxml() + && kind.equals( ATTR_VAR ) && !dep.isTestDependency() && !dep.isProvided() + && !dep.isSystemScopedOutsideProject( this.config.getProject() ) ) + { + if ( !attributeElemOpen ) + { + writer.startElement( ATTRIBUTES ); //$NON-NLS-1$ + attributeElemOpen = true; + } + + writer.startElement( ATTRIBUTE ); //$NON-NLS-1$ + writer.addAttribute( VALUE, "/WEB-INF/lib" ); //$NON-NLS-1$ //$NON-NLS-2$ + writer.addAttribute( NAME, "org.eclipse.jst.component.dependency" ); //$NON-NLS-1$ //$NON-NLS-2$ + writer.endElement(); + + } + + if ( dep.isAjdtDependency() && ( config.getAjdtVersion() >= 1.5 ) ) + { + if ( !attributeElemOpen ) + { + writer.startElement( ATTRIBUTES ); //$NON-NLS-1$ attributeElemOpen = true; } - writer.startElement( "attribute" ); //$NON-NLS-1$ - writer.addAttribute( "value", "jar:" + new File( javadocpath ).toURI() + "!/" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - writer.addAttribute( "name", "javadoc_location" ); //$NON-NLS-1$ //$NON-NLS-2$ + writer.startElement( ATTRIBUTE ); //$NON-NLS-1$ + writer.addAttribute( NAME, ORG_ECLIPSE_AJDT_ASPECTPATH ); //$NON-NLS-1$ //$NON-NLS-2$ + writer.addAttribute( VALUE, Boolean.TRUE.toString() ); //$NON-NLS-1$ //$NON-NLS-2$ writer.endElement(); } - if ( Constants.PROJECT_PACKAGING_WAR.equals( this.config.getPackaging() ) && config.getWtpapplicationxml() && - kind.equals( ATTR_VAR ) && !dep.isTestDependency() && !dep.isProvided() && - !dep.isSystemScopedOutsideProject( this.config.getProject() ) ) + if ( dep.isAjdtWeaveDependency() && ( config.getAjdtVersion() >= 1.5 ) ) { if ( !attributeElemOpen ) { - writer.startElement( "attributes" ); //$NON-NLS-1$ + writer.startElement( ATTRIBUTES ); //$NON-NLS-1$ attributeElemOpen = true; } - writer.startElement( "attribute" ); //$NON-NLS-1$ - writer.addAttribute( "value", "/WEB-INF/lib" ); //$NON-NLS-1$ //$NON-NLS-2$ - writer.addAttribute( "name", "org.eclipse.jst.component.dependency" ); //$NON-NLS-1$ //$NON-NLS-2$ + writer.startElement( ATTRIBUTE ); //$NON-NLS-1$ + writer.addAttribute( NAME, ORG_ECLIPSE_AJDT_INPATH ); //$NON-NLS-1$ //$NON-NLS-2$ + writer.addAttribute( VALUE, Boolean.TRUE.toString() ); //$NON-NLS-1$ //$NON-NLS-2$ writer.endElement(); } diff --git a/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/plugin/eclipse/EclipseCleanMojo.java b/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/plugin/eclipse/EclipseCleanMojo.java index 93e189bc3d..397f5e34d6 100644 --- a/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/plugin/eclipse/EclipseCleanMojo.java +++ b/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/plugin/eclipse/EclipseCleanMojo.java @@ -19,17 +19,16 @@ package org.apache.tuscany.maven.plugin.eclipse; import java.io.File; -import java.io.IOException; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.eclipse.Constants; import org.apache.maven.plugin.eclipse.EclipseConfigFile; -import org.codehaus.plexus.util.FileUtils; +import org.apache.maven.plugin.ide.IdeUtils; /** * Deletes the .project, .classpath, .wtpmodules files and .settings folder used by Eclipse. - * + * * @goal clean */ public class EclipseCleanMojo @@ -76,30 +75,35 @@ public class EclipseCleanMojo */ private static final String FILE_ECLIPSE_JDT_CORE_PREFS = ".settings/org.eclipse.jdt.core.prefs"; //$NON-NLS-1$ + /** + * AJDT preferences. + */ + private static final String FILE_AJDT_PREFS = ".settings/org.eclipse.ajdt.ui.prefs"; //$NON-NLS-1$ + /** * Packaging for the current project. - * + * * @parameter expression="${project.packaging}" */ private String packaging; /** * The root directory of the project - * + * * @parameter expression="${basedir}" */ private File basedir; /** * Skip the operation when true. - * + * * @parameter expression="${eclipse.skip}" default-value="false" */ private boolean skip; /** * additional generic configuration files for eclipse - * + * * @parameter */ private EclipseConfigFile[] additionalConfig; @@ -128,6 +132,7 @@ public class EclipseCleanMojo delete( new File( basedir, FILE_DOT_COMPONENT_15 ) ); delete( new File( basedir, FILE_FACET_CORE_XML ) ); delete( new File( basedir, FILE_ECLIPSE_JDT_CORE_PREFS ) ); + delete( new File( basedir, FILE_AJDT_PREFS ) ); File settingsDir = new File( basedir, DIR_DOT_SETTINGS ); if ( settingsDir.exists() && settingsDir.isDirectory() && settingsDir.list().length == 0 ) @@ -154,47 +159,19 @@ public class EclipseCleanMojo /** * Delete a file, handling log messages and exceptions - * + * * @param f File to be deleted * @throws MojoExecutionException only if a file exists and can't be deleted */ protected void delete( File f ) throws MojoExecutionException { - if ( f.isDirectory() ) - { - getLog().info( Messages.getString( "EclipseCleanMojo.deletingDirectory", f.getName() ) ); //$NON-NLS-1$ - } - else - { - getLog().info( Messages.getString( "EclipseCleanMojo.deletingFile", f.getName() ) ); //$NON-NLS-1$ - } - - if ( f.exists() ) - { - if ( !f.delete() ) - { - try - { - FileUtils.forceDelete( f ); - } - catch ( IOException e ) - { - throw new MojoExecutionException( Messages.getString( "EclipseCleanMojo.failedtodelete", //$NON-NLS-1$ - new Object[] { f.getName(), - f.getAbsolutePath() } ) ); - } - } - } - else - { - getLog().debug( Messages.getString( "EclipseCleanMojo.nofilefound", f.getName() ) ); //$NON-NLS-1$ - } + IdeUtils.delete( f, getLog() ); } /** * Getter for basedir. - * + * * @return Returns the basedir. */ public File getBasedir() @@ -204,7 +181,7 @@ public class EclipseCleanMojo /** * Setter for basedir. - * + * * @param basedir The basedir to set. */ public void setBasedir( File basedir ) diff --git a/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/plugin/eclipse/EclipsePlugin.java b/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/plugin/eclipse/EclipsePlugin.java index 38a906570e..781bc130d9 100644 --- a/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/plugin/eclipse/EclipsePlugin.java +++ b/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/plugin/eclipse/EclipsePlugin.java @@ -32,10 +32,11 @@ import java.util.List; import java.util.ListIterator; import java.util.Map; import java.util.Set; -import java.util.TreeSet; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.model.Build; +import org.apache.maven.model.Plugin; import org.apache.maven.model.Resource; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.eclipse.BuildCommand; @@ -44,6 +45,7 @@ import org.apache.maven.plugin.eclipse.EclipseConfigFile; import org.apache.maven.plugin.eclipse.EclipseSourceDir; import org.apache.maven.plugin.eclipse.WorkspaceConfiguration; import org.apache.maven.plugin.eclipse.reader.ReadWorkspaceLocations; +import org.apache.maven.plugin.eclipse.writers.EclipseAjdtWriter; import org.apache.maven.plugin.eclipse.writers.EclipseManifestWriter; import org.apache.maven.plugin.eclipse.writers.EclipseSettingsWriter; import org.apache.maven.plugin.eclipse.writers.EclipseWriterConfig; @@ -74,16 +76,35 @@ import org.codehaus.plexus.util.xml.Xpp3Dom; * * If this goal is run on a multiproject root, dependencies between modules will be configured as direct project * dependencies in Eclipse (unless useProjectReferences is set to false). - * + * * @author Trygve Laugstøl * @author Fabrizio Giustina - * @version $Id: EclipsePlugin.java 641616 2008-03-26 22:42:42Z aheritier $ + * @version $Id: EclipsePlugin.java 756392 2009-03-20 09:46:09Z baerrach $ * @goal eclipse * @execute phase="generate-resources" */ public class EclipsePlugin extends AbstractIdeSupportMojo { + private static final String WEAVE_DEPENDENCY = "weaveDependency"; + + private static final String WEAVE_DEPENDENCIES = "weaveDependencies"; + + private static final String ASPECT_LIBRARY = "aspectLibrary"; + + private static final String ASPECT_LIBRARIES = "aspectLibraries"; + + private static final String ASPECT_DIRECTORY = "aspectDirectory"; + + private static final String TEST_ASPECT_DIRECTORY = "testAspectDirectory"; + + private static final String ASPECTJ_MAVEN_PLUGIN = "aspectj-maven-plugin"; + + private static final String ORG_CODEHAUS_MOJO = "org.codehaus.mojo"; + + private static final String DEFAULT_TEST_ASPECT_DIRECTORY = "src/test/aspect"; + + private static final String DEFAULT_ASPECT_DIRECTORY = "src/main/aspect"; private static final String NATURE_WST_FACET_CORE_NATURE = "org.eclipse.wst.common.project.facet.core.nature"; //$NON-NLS-1$ @@ -103,6 +124,8 @@ public class EclipsePlugin private static final String BUILDER_PDE_SCHEMA = "org.eclipse.pde.SchemaBuilder"; //$NON-NLS-1$ + private static final String BUILDER_AJDT_CORE_JAVA = "org.eclipse.ajdt.core.ajbuilder"; //$NON-NLS-1$ + private static final String NATURE_WST_MODULE_CORE_NATURE = "org.eclipse.wst.common.modulecore.ModuleCoreNature"; //$NON-NLS-1$ private static final String NATURE_JDT_CORE_JAVA = "org.eclipse.jdt.core.javanature"; //$NON-NLS-1$ @@ -111,8 +134,12 @@ public class EclipsePlugin private static final String NATURE_PDE_PLUGIN = "org.eclipse.pde.PluginNature"; //$NON-NLS-1$ + private static final String NATURE_AJDT_CORE_JAVA = "org.eclipse.ajdt.ui.ajnature"; //$NON-NLS-1$ + protected static final String COMMON_PATH_JDT_LAUNCHING_JRE_CONTAINER = "org.eclipse.jdt.launching.JRE_CONTAINER"; //$NON-NLS-1$ + protected static final String ASPECTJ_RT_CONTAINER = "org.eclipse.ajdt.core.ASPECTJRT_CONTAINER"; //$NON-NLS-1$ + protected static final String REQUIRED_PLUGINS_CONTAINER = "org.eclipse.pde.core.requiredPlugins"; //$NON-NLS-1$ // warning, order is important for binary search @@ -131,14 +158,14 @@ public class EclipsePlugin /** * List of eclipse project natures. By default the org.eclipse.jdt.core.javanature nature plus the * needed WTP natures are added. Natures added using this property replace the default list. - * + * *
      * <projectnatures>
      *    <projectnature>org.eclipse.jdt.core.javanature</projectnature>
      *    <projectnature>org.eclipse.wst.common.modulecore.ModuleCoreNature</projectnature>
      * </projectnatures>
      * 
- * + * * @parameter */ private List projectnatures; @@ -146,7 +173,7 @@ public class EclipsePlugin /** * List of artifact to exclude from eclipse classpath, beeing provided by some eclipse classPathContainer * [MECLIPSE-79] - * + * * @since 2.5 * @parameter */ @@ -154,26 +181,26 @@ public class EclipsePlugin /** * List of eclipse project natures to be added to the default ones. - * + * *
      * <additionalProjectnatures>
      *    <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
      * </additionalProjectnatures>
      * 
- * + * * @parameter */ private List additionalProjectnatures; /** * List of eclipse project facets to be added to the default ones. - * + * *
      * <additionalProjectFacets>
      *    <jst.jsf>1.1<jst.jsf/>
      * </additionalProjectFacets>
      * 
- * + * * @parameter */ private Map additionalProjectFacets; @@ -183,7 +210,7 @@ public class EclipsePlugin * needed WTP builders are added. If you specify any configuration for this parameter, only those buildcommands * specified will be used; the defaults won't be added. Use the additionalBuildCommands parameter for * that. Configuration example: Old style: - * + * *
      * <buildcommands>
      *    <buildcommand>org.eclipse.wst.common.modulecore.ComponentStructuralBuilder</buildcommand>
@@ -191,24 +218,24 @@ public class EclipsePlugin
      *    <buildcommand>org.eclipse.wst.common.modulecore.ComponentStructuralBuilderDependencyResolver</buildcommand>
      * </buildcommands>
      * 
- * + * * For new style, see additionalBuildCommands. - * + * * @parameter */ private List buildcommands; /** * List of eclipse build commands to be added to the default ones. Old style: - * + * *
      * <additionalBuildcommands>
      *    <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
      * </additionalBuildcommands>
      * 
- * + * * New style: - * + * *
      * <additionalBuildcommands>
      *    <buildCommand>
@@ -220,10 +247,10 @@ public class EclipsePlugin
      *    </buildCommand>
      * </additionalBuildcommands>
      * 
- * + * * Note the difference between buildcommand and * buildCommand. You can mix and match old and new-style configuration entries. - * + * * @parameter */ private List additionalBuildcommands; @@ -231,7 +258,7 @@ public class EclipsePlugin /** * List of container classpath entries. By default the org.eclipse.jdt.launching.JRE_CONTAINER * classpath container is added. Configuration example: - * + * *
      * <classpathContainers>
      *    <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
@@ -239,14 +266,14 @@ public class EclipsePlugin
      *    <classpathContainer>org.eclipse.jst.j2ee.internal.web.container/artifact</classpathContainer>
      * </classpathContainers>
      * 
- * + * * @parameter */ private List classpathContainers; /** * Enables/disables the downloading of source attachments. Defaults to false. DEPRECATED - use downloadSources - * + * * @parameter expression="${eclipse.downloadSources}" * @deprecated use downloadSources */ @@ -254,7 +281,7 @@ public class EclipsePlugin /** * Eclipse workspace directory. - * + * * @parameter expression="${eclipse.projectDir}" alias="outputDir" */ private File eclipseProjectDir; @@ -262,7 +289,7 @@ public class EclipsePlugin /** * When set to false, the plugin will not create sub-projects and instead reference those sub-projects using the * installed package in the local repository - * + * * @parameter expression="${eclipse.useProjectReferences}" default-value="true" * @required */ @@ -270,7 +297,7 @@ public class EclipsePlugin /** * The default output directory - * + * * @parameter expression="${outputDirectory}" alias="outputDirectory" * default-value="${project.build.outputDirectory}" * @required @@ -280,21 +307,26 @@ public class EclipsePlugin /** * The version of WTP for which configuration files will be generated. The default value is "none" (don't generate * WTP configuration), supported versions are "R7", "1.0", and "1.5" - * + * * @parameter expression="${wtpversion}" default-value="none" */ private String wtpversion; /** * JEE context name of the WTP module. ( ex. WEB context name ). - * + * * @parameter expression="${wtpContextName}" */ private String wtpContextName; + /** + * Is it an AJDT project? If yes, the plugin adds the necessary natures and build commands to the .project file. + */ + private boolean ajdt; + /** * The relative path of the manifest file - * + * * @parameter expression="${eclipse.manifest}" default-value="${basedir}/META-INF/MANIFEST.MF" */ private File manifest; @@ -302,7 +334,7 @@ public class EclipsePlugin /** * Allow to configure additional generic configuration files for eclipse that will be written out to disk when * running eclipse:eclipse. FOr each file you can specify the name and the text content. - * + * *
      * <plugin>
      *  <groupId>org.apache.maven.plugins</groupId>
@@ -324,9 +356,9 @@ public class EclipsePlugin
      *  </configuration>
      * </plugin>
      * 
- * + * * Instead of the content you can also define (from version 2.5) an url to download the file : - * + * *
      * <plugin>
      *  <groupId>org.apache.maven.plugins</groupId>
@@ -340,9 +372,9 @@ public class EclipsePlugin
      *   </additionalConfig>
      *  </configuration>
      * 
- * + * * or a location : - * + * *
      * <plugin>
      *  <groupId>org.apache.maven.plugins</groupId>
@@ -365,15 +397,15 @@ public class EclipsePlugin
      *  </dependencies>
      * </plugin>
      * 
- * + * * @parameter */ private EclipseConfigFile[] additionalConfig; /** - * If set to true, the version number of the artifact is appended to the name of the generated - * Eclipse project. See projectNameTemplate for other options. - * + * If set to true, the version number of the artifact is appended to the name of the generated Eclipse + * project. See projectNameTemplate for other options. + * * @parameter expression="${eclipse.addVersionToProjectName}" default-value="false" */ private boolean addVersionToProjectName; @@ -381,16 +413,16 @@ public class EclipsePlugin /** * If set to true, the groupId of the artifact is appended to the name of the generated Eclipse * project. See projectNameTemplate for other options. - * + * * @parameter expression="${eclipse.addGroupIdToProjectName}" default-value="false" */ private boolean addGroupIdToProjectName; /** * Allows configuring the name of the eclipse projects. This property if set wins over addVersionToProjectName and - * addGroupIdToProjectName You can use [groupId], [artifactId] and - * [version] variables. eg. [groupId].[artifactId]-[version] - * + * addGroupIdToProjectName You can use [groupId], [artifactId] and [version] + * variables. eg. [groupId].[artifactId]-[version] + * * @parameter expression="${eclipse.projectNameTemplate}" */ private String projectNameTemplate; @@ -407,21 +439,21 @@ public class EclipsePlugin /** * Must the manifest files be written for java projects so that that the jee classpath for wtp is correct. - * + * * @parameter expression="${eclipse.wtpmanifest}" default-value="false" */ private boolean wtpmanifest; /** * Must the application files be written for ear projects in a separate directory. - * + * * @parameter expression="${eclipse.wtpapplicationxml}" default-value="false" */ private boolean wtpapplicationxml; /** * What WTP defined server to use for deployment informations. - * + * * @parameter expression="${eclipse.wtpdefaultserver}" */ private String wtpdefaultserver; @@ -430,7 +462,7 @@ public class EclipsePlugin /** * ResourceManager for getting additonalConfig files from resources - * + * * @component * @required * @readonly @@ -442,206 +474,216 @@ public class EclipsePlugin * not be linked to the jars in the local repository. Requirement is that it was created with the similar wtp * settings as the reactor projects, but the project name template my differ. The pom's in the workspace projects * may not contain variables in the artefactId, groupId and version tags. - * + * + * If workspace is not defined, then an attempt to locate it by checking up the directory hierarchy will be made. + * * @since 2.5 * @parameter expression="${eclipse.workspace}" */ - protected String workspace; + protected File workspace; /** * Limit the use of project references to the current workspace. No project references will be created to projects * in the reactor when they are not available in the workspace. - * + * * @parameter expression="${eclipse.limitProjectReferencesToWorkspace}" default-value="false" */ protected boolean limitProjectReferencesToWorkspace; - protected boolean isJavaProject() + /** + * The version of AJDT for which configuration files will be generated. The default value is "1.5", supported + * versions are "none", "1.4", and "1.5". + * + * @parameter expression="${eclipse.ajdtVersion}" default-value="1.5" + */ + private String ajdtVersion; + + protected final boolean isJavaProject() { return isJavaProject; } - protected boolean isPdeProject() + protected final boolean isPdeProject() { return pde; } /** * Getter for buildcommands. - * + * * @return Returns the buildcommands. */ - public List getBuildcommands() + public final List getBuildcommands() { return buildcommands; } /** * Setter for buildcommands. - * + * * @param buildcommands The buildcommands to set. */ - public void setBuildcommands( List buildcommands ) + public final void setBuildcommands( List buildcommands ) { this.buildcommands = buildcommands; } /** * Getter for buildOutputDirectory. - * + * * @return Returns the buildOutputDirectory. */ - public File getBuildOutputDirectory() + public final File getBuildOutputDirectory() { return buildOutputDirectory; } /** * Setter for buildOutputDirectory. - * + * * @param buildOutputDirectory The buildOutputDirectory to set. */ - public void setBuildOutputDirectory( File buildOutputDirectory ) + public final void setBuildOutputDirectory( File buildOutputDirectory ) { this.buildOutputDirectory = buildOutputDirectory; } /** * Getter for classpathContainers. - * + * * @return Returns the classpathContainers. */ - public List getClasspathContainers() + public final List getClasspathContainers() { return classpathContainers; } /** * Setter for classpathContainers. - * + * * @param classpathContainers The classpathContainers to set. */ - public void setClasspathContainers( List classpathContainers ) + public final void setClasspathContainers( List classpathContainers ) { this.classpathContainers = classpathContainers; } /** * Getter for eclipseProjectDir. - * + * * @return Returns the eclipseProjectDir. */ - public File getEclipseProjectDir() + public final File getEclipseProjectDir() { return eclipseProjectDir; } /** * Setter for eclipseProjectDir. - * + * * @param eclipseProjectDir The eclipseProjectDir to set. */ - public void setEclipseProjectDir( File eclipseProjectDir ) + public final void setEclipseProjectDir( File eclipseProjectDir ) { this.eclipseProjectDir = eclipseProjectDir; } /** * Getter for projectnatures. - * + * * @return Returns the projectnatures. */ - public List getProjectnatures() + public final List getProjectnatures() { return projectnatures; } /** * Setter for projectnatures. - * + * * @param projectnatures The projectnatures to set. */ - public void setProjectnatures( List projectnatures ) + public final void setProjectnatures( List projectnatures ) { this.projectnatures = projectnatures; } /** * Getter for useProjectReferences. - * + * * @return Returns the useProjectReferences. */ - public boolean getUseProjectReferences() + public final boolean getUseProjectReferences() { return useProjectReferences; } /** * Setter for useProjectReferences. - * + * * @param useProjectReferences The useProjectReferences to set. */ - public void setUseProjectReferences( boolean useProjectReferences ) + public final void setUseProjectReferences( boolean useProjectReferences ) { this.useProjectReferences = useProjectReferences; } /** * Getter for wtpversion. - * + * * @return Returns the wtpversion. */ - public String getWtpversion() + public final String getWtpversion() { return wtpversion; } /** * Setter for wtpversion. - * + * * @param wtpversion The wtpversion to set. */ - public void setWtpversion( String wtpversion ) + public final void setWtpversion( String wtpversion ) { this.wtpversion = wtpversion; } /** * Getter for additionalBuildcommands. - * + * * @return Returns the additionalBuildcommands. */ - public List getAdditionalBuildcommands() + public final List getAdditionalBuildcommands() { return additionalBuildcommands; } /** * Setter for additionalBuildcommands. - * + * * @param additionalBuildcommands The additionalBuildcommands to set. */ - public void setAdditionalBuildcommands( List additionalBuildcommands ) + public final void setAdditionalBuildcommands( List additionalBuildcommands ) { this.additionalBuildcommands = additionalBuildcommands; } /** * Getter for additionalProjectnatures. - * + * * @return Returns the additionalProjectnatures. */ - public List getAdditionalProjectnatures() + public final List getAdditionalProjectnatures() { return additionalProjectnatures; } /** * Setter for additionalProjectnatures. - * + * * @param additionalProjectnatures The additionalProjectnatures to set. */ - public void setAdditionalProjectnatures( List additionalProjectnatures ) + public final void setAdditionalProjectnatures( List additionalProjectnatures ) { this.additionalProjectnatures = additionalProjectnatures; } @@ -649,7 +691,7 @@ public class EclipsePlugin /** * Getter for addVersionToProjectName. */ - public boolean isAddVersionToProjectName() + public final boolean isAddVersionToProjectName() { return addVersionToProjectName; } @@ -657,7 +699,7 @@ public class EclipsePlugin /** * Setter for addVersionToProjectName. */ - public void setAddVersionToProjectName( boolean addVersionToProjectName ) + public final void setAddVersionToProjectName( boolean addVersionToProjectName ) { this.addVersionToProjectName = addVersionToProjectName; } @@ -665,7 +707,7 @@ public class EclipsePlugin /** * Getter for addGroupIdToProjectName. */ - public boolean isAddGroupIdToProjectName() + public final boolean isAddGroupIdToProjectName() { return addGroupIdToProjectName; } @@ -673,17 +715,27 @@ public class EclipsePlugin /** * Setter for addGroupIdToProjectName. */ - public void setAddGroupIdToProjectName( boolean addGroupIdToProjectName ) + public final void setAddGroupIdToProjectName( boolean addGroupIdToProjectName ) { this.addGroupIdToProjectName = addGroupIdToProjectName; } - public String getProjectNameTemplate() + /** + * Getter for projectNameTemplate + * + * @return projectNameTemplate + */ + public final String getProjectNameTemplate() { return projectNameTemplate; } - public void setProjectNameTemplate( String projectNameTemplate ) + /** + * Setter for projectNameTemplate. + * + * @param projectNameTemplate projectNameTemplate + */ + public final void setProjectNameTemplate( String projectNameTemplate ) { this.projectNameTemplate = projectNameTemplate; } @@ -691,13 +743,15 @@ public class EclipsePlugin /** * @see org.apache.maven.plugin.Mojo#execute() */ - public boolean setup() + public final boolean setup() throws MojoExecutionException { boolean ready = true; checkDeprecations(); - + setProjectNameTemplate( IdeUtils.calculateProjectNameTemplate( getProjectNameTemplate(), isAddVersionToProjectName(), + isAddGroupIdToProjectName(), getLog() ) ); + ajdt = enableAjdt( executedProject ) && !ajdtVersion.equals( "none" ); ready = validate(); // TODO: Why are we using project in some places, and executedProject in others?? @@ -706,8 +760,8 @@ public class EclipsePlugin // ear projects don't contain java sources // pde projects are always java projects isJavaProject = - pde || - ( Constants.LANGUAGE_JAVA.equals( artifactHandler.getLanguage() ) && !Constants.PROJECT_PACKAGING_EAR.equals( packaging ) ); + pde + || ( Constants.LANGUAGE_JAVA.equals( artifactHandler.getLanguage() ) && !Constants.PROJECT_PACKAGING_EAR.equals( packaging ) ); setupExtras(); @@ -754,7 +808,13 @@ public class EclipsePlugin return ready; } - protected void convertBuildCommandList( List commands ) + /** + * Convert any Strings in the commands List to BuildCommands. The conversion happens + * in situ. + * + * @param commands a list of commands to convert into BuildCommand + */ + protected final void convertBuildCommandList( List commands ) { if ( commands != null ) { @@ -795,13 +855,20 @@ public class EclipsePlugin } } + /** + * Extension point for subclasses. + *

+ * Called during setup. + * + * @throws MojoExecutionException mojo failures. + */ protected void setupExtras() throws MojoExecutionException { // extension point. } - protected void verifyClasspathContainerListIsComplete() + private void verifyClasspathContainerListIsComplete() { boolean containsJREContainer = false; // Check if classpathContainer contains a JRE (default, alternate or @@ -809,8 +876,8 @@ public class EclipsePlugin for ( Iterator iter = classpathContainers.iterator(); iter.hasNext(); ) { Object classPathContainer = iter.next(); - if ( classPathContainer != null && - classPathContainer.toString().startsWith( COMMON_PATH_JDT_LAUNCHING_JRE_CONTAINER ) ) + if ( classPathContainer != null + && classPathContainer.toString().startsWith( COMMON_PATH_JDT_LAUNCHING_JRE_CONTAINER ) ) { containsJREContainer = true; break; @@ -853,7 +920,7 @@ public class EclipsePlugin { pde = true; } - + // [rfeng] Set PDE to false if the project is not a bundle if(!isOSGiBundle()) { pde = false; @@ -887,7 +954,14 @@ public class EclipsePlugin return true; } - protected void validateExtras() + /** + * Extension point for subclasses. + *

+ * Called during setup and used to validate that the configuration is sane. + * + * @throws MojoExecutionException mojo failures. + */ + protected void validateExtras() throws MojoExecutionException { // provided for extension. } @@ -903,15 +977,20 @@ public class EclipsePlugin downloadSources = true; } - checkExtraDeprecations(); + checkDeprecationsExtras(); } - protected void checkExtraDeprecations() + /** + * Extension point for subclasses. + *

+ * Check for any extra deprecations and log warnings. Called during setup + */ + protected void checkDeprecationsExtras() { // provided for extension. } - public void writeConfiguration( IdeDependency[] deps ) + public final void writeConfiguration( IdeDependency[] deps ) throws MojoExecutionException { EclipseWriterConfig config = createEclipseWriterConfig( deps ); @@ -921,7 +1000,7 @@ public class EclipsePlugin EclipseManifestWriter.addManifestResource( getLog(), config ); } // NOTE: This could change the config! - writeExtraConfiguration( config ); + writeConfigurationExtras( config ); if ( wtpVersionFloat == 0.7f ) { @@ -946,6 +1025,10 @@ public class EclipsePlugin if ( isJavaProject ) { new EclipseClasspathWriter().init( getLog(), config ).write(); + if ( ajdt && ajdtVersion.equals( "1.4" ) ) + { + new EclipseAjdtWriter().init( getLog(), config ).write(); + } } if ( wtpapplicationxml ) @@ -975,7 +1058,7 @@ public class EclipsePlugin config.getEclipseProjectName(), eclipseProjectDir.getAbsolutePath() } ) ); } - protected void writeAdditionalConfig() + private void writeAdditionalConfig() throws MojoExecutionException { if ( additionalConfig != null ) @@ -1036,7 +1119,14 @@ public class EclipsePlugin } } - protected EclipseWriterConfig createEclipseWriterConfig( IdeDependency[] deps ) + /** + * Create the EclipseWriterConfig for the specified dependencies. + * + * @param deps the project dependencies + * @return a configured EclipseWriterConfig + * @throws MojoExecutionException mojo failures. + */ + protected final EclipseWriterConfig createEclipseWriterConfig( IdeDependency[] deps ) throws MojoExecutionException { File projectBaseDir = executedProject.getFile().getParentFile(); @@ -1049,7 +1139,7 @@ public class EclipsePlugin config.setWorkspaceConfiguration( getWorkspaceConfiguration() ); - config.setProjectNameTemplate( calculateProjectNameTemplate() ); + config.setProjectNameTemplate( getProjectNameTemplate() ); String projectName = IdeUtils.getProjectName( config.getProjectNameTemplate(), project ); @@ -1059,6 +1149,18 @@ public class EclipsePlugin config.setWtpVersion( wtpVersionFloat ); + float ajdtVersionFloat; + try + { + ajdtVersionFloat = Float.parseFloat( ajdtVersion ); + } + catch ( NumberFormatException e ) + { + ajdtVersionFloat = 0.0f; + } + + config.setAjdtVersion( ajdtVersionFloat ); + Set convertedBuildCommands = new LinkedHashSet(); if ( buildcommands != null ) @@ -1078,6 +1180,12 @@ public class EclipsePlugin } } + if ( ajdt ) + { + buildAjdtWeaveDeps( deps ); + buildAspectjDeps( deps ); + } + config.setBuildCommands( new LinkedList( convertedBuildCommands ) ); config.setBuildOutputDirectory( buildOutputDirectory ); @@ -1103,13 +1211,13 @@ public class EclipsePlugin /** * If this is a war module peek into the reactor an search for an ear module that defines the context root of this * module. - * + * * @param config config to save the context root. */ private void collectWarContextRootsFromReactorEarConfiguration( EclipseWriterConfig config ) { - if ( reactorProjects != null && wtpContextName == null && - Constants.PROJECT_PACKAGING_WAR.equals( project.getPackaging() ) ) + if ( reactorProjects != null && wtpContextName == null + && Constants.PROJECT_PACKAGING_WAR.equals( project.getPackaging() ) ) { for ( Iterator iter = reactorProjects.iterator(); iter.hasNext(); ) { @@ -1125,15 +1233,14 @@ public class EclipsePlugin Xpp3Dom groupId = warDefinitions[index].getChild( "groupId" ); Xpp3Dom artifactId = warDefinitions[index].getChild( "artifactId" ); Xpp3Dom contextRoot = warDefinitions[index].getChild( "contextRoot" ); - if ( groupId != null && artifactId != null && contextRoot != null && - groupId.getValue() != null && artifactId.getValue() != null && - contextRoot.getValue() != null ) + if ( groupId != null && artifactId != null && contextRoot != null && groupId.getValue() != null + && artifactId.getValue() != null && contextRoot.getValue() != null ) { getLog().info( - "Found context root definition for " + groupId.getValue() + ":" + - artifactId.getValue() + " " + contextRoot.getValue() ); - if ( project.getArtifactId().equals( artifactId.getValue() ) && - project.getGroupId().equals( groupId.getValue() ) ) + "Found context root definition for " + groupId.getValue() + ":" + + artifactId.getValue() + " " + contextRoot.getValue() ); + if ( project.getArtifactId().equals( artifactId.getValue() ) + && project.getGroupId().equals( groupId.getValue() ) ) { config.setContextName( contextRoot.getValue() ); } @@ -1141,9 +1248,9 @@ public class EclipsePlugin else { getLog().info( - "Found incomplete ear configuration in " + reactorProject.getGroupId() + - ":" + reactorProject.getGroupId() + " found " + - warDefinitions[index].toString() ); + "Found incomplete ear configuration in " + reactorProject.getGroupId() + ":" + + reactorProject.getGroupId() + " found " + + warDefinitions[index].toString() ); } } } @@ -1165,11 +1272,11 @@ public class EclipsePlugin /** * Write any extra configuration information for the Eclipse project. This is an extension point, called before the * main configurations are written.
NOTE: This could change the config! - * + * * @param config * @throws MojoExecutionException */ - protected void writeExtraConfiguration( EclipseWriterConfig config ) + protected void writeConfigurationExtras( EclipseWriterConfig config ) throws MojoExecutionException { // extension point. @@ -1184,6 +1291,14 @@ public class EclipsePlugin } } + /** + * Fill getProjectnatures() with values. + *

+ * Subclasses should call super and then calculate their own additions and insert them via + * getProjectnatures().addAll(). + * + * @param packaging the pom's packaging + */ protected void fillDefaultNatures( String packaging ) { projectnatures = new ArrayList(); @@ -1195,6 +1310,11 @@ public class EclipsePlugin if ( isJavaProject ) { + if ( ajdt ) + { + projectnatures.add( NATURE_AJDT_CORE_JAVA ); + } + projectnatures.add( NATURE_JDT_CORE_JAVA ); } @@ -1215,6 +1335,14 @@ public class EclipsePlugin } + /** + * Fill getClasspathContainers() with values. + *

+ * Subclasses should call super and then calculate their own additions and insert them via + * getClasspathContainers().addAll(). + * + * @param packaging the pom's packaging + */ protected void fillDefaultClasspathContainers( String packaging ) { classpathContainers = new ArrayList(); @@ -1222,16 +1350,29 @@ public class EclipsePlugin if ( getWorkspaceConfiguration().getDefaultClasspathContainer() != null ) { getLog().info( - "Adding default classpath contaigner: " + - getWorkspaceConfiguration().getDefaultClasspathContainer() ); + "Adding default classpath container: " + + getWorkspaceConfiguration().getDefaultClasspathContainer() ); classpathContainers.add( getWorkspaceConfiguration().getDefaultClasspathContainer() ); } if ( pde ) { classpathContainers.add( REQUIRED_PLUGINS_CONTAINER ); } + + if ( ajdt ) + { + classpathContainers.add( ASPECTJ_RT_CONTAINER ); + } } + /** + * Fill getBuildcommands() with values. + *

+ * Subclasses should call super and then calculate their own additions and insert them via + * getBuildcommands().addAll(). + * + * @param packaging the pom's packaging + */ protected void fillDefaultBuilders( String packaging ) { buildcommands = new ArrayList(); @@ -1243,7 +1384,14 @@ public class EclipsePlugin if ( isJavaProject ) { - buildcommands.add( new BuildCommand( BUILDER_JDT_CORE_JAVA ) ); + if ( ajdt ) + { + buildcommands.add( new BuildCommand( BUILDER_AJDT_CORE_JAVA ) ); + } + else + { + buildcommands.add( new BuildCommand( BUILDER_JDT_CORE_JAVA ) ); + } } if ( wtpVersionFloat >= 1.5f ) @@ -1269,20 +1417,12 @@ public class EclipsePlugin } } - public EclipseSourceDir[] buildDirectoryList( MavenProject project, File basedir, File buildOutputDirectory ) + public final EclipseSourceDir[] buildDirectoryList( MavenProject project, File basedir, File buildOutputDirectory ) throws MojoExecutionException { File projectBaseDir = project.getFile().getParentFile(); - // avoid duplicated entries - Set directories = new TreeSet(); - - extractSourceDirs( directories, project.getCompileSourceRoots(), basedir, projectBaseDir, false, null ); - - String relativeOutput = IdeUtils.toRelativeAndFixSeparator( projectBaseDir, buildOutputDirectory, false ); - - extractResourceDirs( directories, project.getBuild().getResources(), project, basedir, projectBaseDir, false, - relativeOutput ); + String mainOutput = IdeUtils.toRelativeAndFixSeparator( projectBaseDir, buildOutputDirectory, false ); // If using the standard output location, don't mix the test output into it. String testOutput = null; @@ -1291,19 +1431,48 @@ public class EclipsePlugin if ( useStandardOutputDir ) { getLog().debug( - "testOutput toRelativeAndFixSeparator " + projectBaseDir + " , " + - project.getBuild().getTestOutputDirectory() ); + "testOutput toRelativeAndFixSeparator " + projectBaseDir + " , " + + project.getBuild().getTestOutputDirectory() ); testOutput = IdeUtils.toRelativeAndFixSeparator( projectBaseDir, new File( project.getBuild().getTestOutputDirectory() ), false ); getLog().debug( "testOutput after toRelative : " + testOutput ); } - extractSourceDirs( directories, project.getTestCompileSourceRoots(), basedir, projectBaseDir, true, testOutput ); + Set mainDirectories = new LinkedHashSet(); + + extractSourceDirs( mainDirectories, project.getCompileSourceRoots(), basedir, projectBaseDir, false, null ); + + extractResourceDirs( mainDirectories, project.getBuild().getResources(), basedir, projectBaseDir, false, + mainOutput ); + + Set testDirectories = new LinkedHashSet(); + + extractSourceDirs( testDirectories, project.getTestCompileSourceRoots(), basedir, projectBaseDir, true, + testOutput ); - extractResourceDirs( directories, project.getBuild().getTestResources(), project, basedir, projectBaseDir, - true, testOutput ); + extractResourceDirs( testDirectories, project.getBuild().getTestResources(), basedir, projectBaseDir, true, + testOutput ); + // avoid duplicated entries + Set directories = new LinkedHashSet(); + + // NOTE: Since MNG-3118, test classes come before main classes + boolean testBeforeMain = isMavenVersion( "[2.0.8,)" ); + + if ( testBeforeMain ) + { + directories.addAll( testDirectories ); + directories.removeAll( mainDirectories ); + directories.addAll( mainDirectories ); + } + else + { + directories.addAll( mainDirectories ); + directories.addAll( testDirectories ); + } + if ( ajdt ) + extractAspectDirs( directories, project, basedir, projectBaseDir, testOutput ); return (EclipseSourceDir[]) directories.toArray( new EclipseSourceDir[directories.size()] ); } @@ -1315,7 +1484,6 @@ public class EclipsePlugin { File sourceRootFile = new File( (String) it.next() ); - getLog().debug( "Processing source dir: " + sourceRootFile ); if ( sourceRootFile.isDirectory() ) { @@ -1328,8 +1496,8 @@ public class EclipsePlugin } } - void extractResourceDirs( Set directories, List resources, MavenProject project, File basedir, - File workspaceProjectBaseDir, boolean test, final String output ) + final void extractResourceDirs( Set directories, List resources, File basedir, File workspaceProjectBaseDir, + boolean test, final String output ) throws MojoExecutionException { for ( Iterator it = resources.iterator(); it.hasNext(); ) @@ -1385,51 +1553,155 @@ public class EclipsePlugin } getLog().debug( - "Making relative and fixing separator: { " + workspaceProjectBaseDir + ", " + - outputFile + ", false }." ); + "Making relative and fixing separator: { " + workspaceProjectBaseDir + ", " + + outputFile + ", false }." ); thisOutput = IdeUtils.toRelativeAndFixSeparator( workspaceProjectBaseDir, outputFile, false ); } getLog().debug( - "Adding eclipse source dir: { " + resourceDir + ", " + thisOutput + ", true, " + test + - ", " + includePattern + ", " + excludePattern + " }." ); + "Adding eclipse source dir: { " + resourceDir + ", " + thisOutput + ", true, " + test + + ", " + includePattern + ", " + excludePattern + " }." ); directories.add( new EclipseSourceDir( resourceDir, thisOutput, true, test, includePattern, excludePattern, resource.isFiltering() ) ); } } - /** - * Calculate the project name template from the fields {@link #projectNameTemplate}, - * {@link #addVersionToProjectName} and {@link #addGroupIdToProjectName} - * - * @return the project name template that should be used after considering the plugin configuration - */ - private String calculateProjectNameTemplate() + private void extractAspectDirs( Set directories, MavenProject project, File basedir, File projectBaseDir, + String testOutput ) + throws MojoExecutionException { - if ( getProjectNameTemplate() != null ) + Xpp3Dom configuration = getAspectjConfiguration( project ); + if ( configuration != null ) { - if ( isAddVersionToProjectName() || isAddGroupIdToProjectName() ) + String aspectDirectory = DEFAULT_ASPECT_DIRECTORY; + Xpp3Dom aspectDirectoryElement = configuration.getChild( ASPECT_DIRECTORY ); + if ( aspectDirectoryElement != null ) { - getLog().warn( - "projectNameTemplate definition overrides " - + "addVersionToProjectName or addGroupIdToProjectName" ); + aspectDirectory = aspectDirectoryElement.getValue(); + } + + File aspectDirectoryFile = new File( basedir, aspectDirectory ); + if ( aspectDirectoryFile.exists() && aspectDirectoryFile.isDirectory() ) + { + String sourceRoot = + IdeUtils.toRelativeAndFixSeparator( projectBaseDir, aspectDirectoryFile, + !projectBaseDir.equals( basedir ) ); + + directories.add( new EclipseSourceDir( sourceRoot, null, false, false, null, null, false ) ); + } + + String testAspectDirectory = DEFAULT_TEST_ASPECT_DIRECTORY; + Xpp3Dom testAspectDirectoryElement = configuration.getChild( TEST_ASPECT_DIRECTORY ); + if ( testAspectDirectoryElement != null ) + { + testAspectDirectory = testAspectDirectoryElement.getValue(); + } + + File testAspectDirectoryFile = new File( basedir, testAspectDirectory ); + if ( testAspectDirectoryFile.exists() && testAspectDirectoryFile.isDirectory() ) + { + String sourceRoot = + IdeUtils.toRelativeAndFixSeparator( projectBaseDir, testAspectDirectoryFile, + !projectBaseDir.equals( basedir ) ); + + directories.add( new EclipseSourceDir( sourceRoot, testOutput, false, true, null, null, false ) ); } - return getProjectNameTemplate(); } - else if ( isAddVersionToProjectName() && isAddGroupIdToProjectName() ) + } + + private boolean enableAjdt( MavenProject project ) + { + boolean enable = false; + List buildPlugins = project.getBuildPlugins(); + for ( Iterator it = buildPlugins.iterator(); it.hasNext(); ) { - return IdeUtils.PROJECT_NAME_WITH_GROUP_AND_VERSION_TEMPLATE; + Plugin plugin = (Plugin) it.next(); + if ( plugin.getGroupId().equals( ORG_CODEHAUS_MOJO ) + && plugin.getArtifactId().equals( ASPECTJ_MAVEN_PLUGIN ) ) + { + enable = true; + break; + } } - else if ( isAddVersionToProjectName() ) + + return enable; + } + + private Xpp3Dom getAspectjConfiguration( MavenProject project ) + { + Xpp3Dom configuration = null; + List buildPlugins = project.getBuildPlugins(); + for ( Iterator it = buildPlugins.iterator(); it.hasNext(); ) { - return IdeUtils.PROJECT_NAME_WITH_VERSION_TEMPLATE; + Plugin plugin = (Plugin) it.next(); + if ( plugin.getGroupId().equals( ORG_CODEHAUS_MOJO ) + && plugin.getArtifactId().equals( ASPECTJ_MAVEN_PLUGIN ) ) + { + configuration = (Xpp3Dom) plugin.getConfiguration(); + break; + } } - else if ( isAddGroupIdToProjectName() ) + + return configuration; + } + + private void buildAspectjDeps( IdeDependency[] deps ) + throws MojoExecutionException + { + Xpp3Dom configuration = getAspectjConfiguration( executedProject ); + if ( configuration != null ) { - return IdeUtils.PROJECT_NAME_WITH_GROUP_TEMPLATE; + Xpp3Dom aspectLibrariesParent = configuration.getChild( ASPECT_LIBRARIES ); + if ( aspectLibrariesParent != null ) + { + Xpp3Dom[] aspectLibraries = aspectLibrariesParent.getChildren( ASPECT_LIBRARY ); + outerLoop: for ( int i = 0; i < aspectLibraries.length; i++ ) + { + String artifactId = aspectLibraries[i].getChild( POM_ELT_ARTIFACT_ID ).getValue(); + String groupId = aspectLibraries[i].getChild( POM_ELT_GROUP_ID ).getValue(); + for ( int j = 0; j < deps.length; j++ ) + { + if ( deps[j].getArtifactId().equals( artifactId ) && deps[j].getGroupId().equals( groupId ) ) + { + deps[j].setAjdtDependency( true ); + continue outerLoop; + } + } + + throw new MojoExecutionException( "AspectLibrary is not a dependency of project" ); + } + } + } + } + + private void buildAjdtWeaveDeps( IdeDependency[] deps ) + throws MojoExecutionException + { + Xpp3Dom configuration = getAspectjConfiguration( executedProject ); + if ( configuration != null ) + { + Xpp3Dom weaveDependenciesParent = configuration.getChild( WEAVE_DEPENDENCIES ); + if ( weaveDependenciesParent != null ) + { + Xpp3Dom[] weaveDependencies = weaveDependenciesParent.getChildren( WEAVE_DEPENDENCY ); + outerLoop: for ( int i = 0; i < weaveDependencies.length; i++ ) + { + String artifactId = weaveDependencies[i].getChild( POM_ELT_ARTIFACT_ID ).getValue(); + String groupId = weaveDependencies[i].getChild( POM_ELT_GROUP_ID ).getValue(); + for ( int j = 0; j < deps.length; j++ ) + { + if ( deps[j].getArtifactId().equals( artifactId ) && deps[j].getGroupId().equals( groupId ) ) + { + deps[j].setAjdtWeaveDependency( true ); + continue outerLoop; + } + } + + throw new MojoExecutionException( "WeaveDependency is not a dependency of project" ); + } + } } - return IdeUtils.PROJECT_NAME_DEFAULT_TEMPLATE; } /** @@ -1441,9 +1713,9 @@ public class EclipsePlugin for ( int index = 0; workspaceArtefacts != null && index < workspaceArtefacts.length; index++ ) { IdeDependency workspaceArtefact = workspaceArtefacts[index]; - if ( workspaceArtefact.isAddedToClasspath() && - workspaceArtefact.getGroupId().equals( artifact.getGroupId() ) && - workspaceArtefact.getArtifactId().equals( artifact.getArtifactId() ) ) + if ( workspaceArtefact.isAddedToClasspath() + && workspaceArtefact.getGroupId().equals( artifact.getGroupId() ) + && workspaceArtefact.getArtifactId().equals( artifact.getArtifactId() ) ) { if ( workspaceArtefact.getVersion().equals( artifact.getVersion() ) ) { @@ -1451,39 +1723,100 @@ public class EclipsePlugin } } } - return IdeUtils.getProjectName( calculateProjectNameTemplate(), artifact ); + MavenProject reactorProject = getReactorProject( artifact ); + if ( reactorProject != null ) { + return IdeUtils.getProjectName( getProjectNameTemplateForMavenProject( reactorProject ), artifact ); + } + return IdeUtils.getProjectName( getProjectNameTemplate(), artifact ); + } + + /** + * @param mavenProject the project to get the projectNameTemplate configuration from + * @return the projectNameTemplate configuration from the specified MavenProject + */ + private String getProjectNameTemplateForMavenProject( MavenProject mavenProject ) + { + String projectNameTemplate = null; + boolean addVersionToProjectName = false; + boolean addGroupIdToProjectName = false; + + Build build = mavenProject.getBuild(); + if ( build != null ) + { + Plugin plugin = (Plugin) build.getPluginsAsMap().get( "org.apache.maven.plugins:maven-eclipse-plugin" ); + if ( plugin != null ) + { + Xpp3Dom config = (Xpp3Dom) plugin.getConfiguration(); + if ( config != null ) + { + Xpp3Dom projectNameTemplateNode = config.getChild( "projectNameTemplate" ); + if ( projectNameTemplateNode != null ) + { + projectNameTemplate = projectNameTemplateNode.getValue(); + } + Xpp3Dom addVersionToProjectNameNode = config.getChild( "addVersionToProjectName" ); + addVersionToProjectName = addVersionToProjectNameNode != null; + Xpp3Dom addGroupIdToProjectNameNode = config.getChild( "addGroupIdToProjectName" ); + addGroupIdToProjectName = addGroupIdToProjectNameNode != null; + } + } + } + return IdeUtils.calculateProjectNameTemplate(projectNameTemplate, addVersionToProjectName, addGroupIdToProjectName, getLog()); } /** * {@inheritDoc} */ - protected IdeDependency[] getWorkspaceArtefacts() + protected final IdeDependency[] getWorkspaceArtefacts() { return getWorkspaceConfiguration().getWorkspaceArtefacts(); } - public WorkspaceConfiguration getWorkspaceConfiguration() + public final WorkspaceConfiguration getWorkspaceConfiguration() { if ( workspaceConfiguration == null ) { workspaceConfiguration = new WorkspaceConfiguration(); - if ( workspace != null ) - { - workspaceConfiguration.setWorkspaceDirectory( new File( workspace ) ); - } + locateWorkspace(); + getLog().info( Messages.getString( "EclipsePlugin.workspace", workspace ) ); + workspaceConfiguration.setWorkspaceDirectory( workspace ); + new ReadWorkspaceLocations().init( getLog(), workspaceConfiguration, project, wtpdefaultserver ); } return workspaceConfiguration; } - public List getExcludes() + /** + * If workspace is not defined, then attempt to locate it by checking up the directory hierarchy. + */ + private void locateWorkspace() + { + if ( workspace == null ) + { + File currentWorkingDirectory = new File( "." ).getAbsoluteFile(); + while ( currentWorkingDirectory != null ) + { + File metadataDirectory = new File( currentWorkingDirectory, ".metadata" ); + logger.debug( "Checking for eclipse workspace at " + currentWorkingDirectory ); + if ( metadataDirectory.exists() && metadataDirectory.isDirectory() ) + { + logger.debug( " Found workspace at " + currentWorkingDirectory ); + workspace = currentWorkingDirectory; + return; + } + currentWorkingDirectory = currentWorkingDirectory.getParentFile(); + } + } + } + + public final List getExcludes() { return excludes; } /** * Utility method that locates a project in the workspace for the given artifact. - * + * * @param artifact the artifact a project should produce. * @return true if the artifact is produced by a reactor projectart. */ @@ -1493,8 +1826,8 @@ public class EclipsePlugin for ( int index = 0; workspaceArtefacts != null && index < workspaceArtefacts.length; index++ ) { IdeDependency workspaceArtefact = workspaceArtefacts[index]; - if ( workspaceArtefact.getGroupId().equals( artifact.getGroupId() ) && - workspaceArtefact.getArtifactId().equals( artifact.getArtifactId() ) ) + if ( workspaceArtefact.getGroupId().equals( artifact.getGroupId() ) + && workspaceArtefact.getArtifactId().equals( artifact.getArtifactId() ) ) { if ( workspaceArtefact.getVersion().equals( artifact.getVersion() ) ) { @@ -1505,47 +1838,35 @@ public class EclipsePlugin else { getLog().info( - "Artifact " + - artifact.getId() + - " already available as a workspace project, but with different version. Expected: " + - artifact.getVersion() + ", found: " + workspaceArtefact.getVersion() ); + "Artifact " + + artifact.getId() + + " already available as a workspace project, but with different version. Expected: " + + artifact.getVersion() + ", found: " + workspaceArtefact.getVersion() ); } } } return false; } - /* - * (non-Javadoc) - * - * @see org.apache.maven.plugin.ide.AbstractIdeSupportMojo#doDependencyResolution() - */ - protected IdeDependency[] doDependencyResolution() - throws MojoExecutionException - { - - return super.doDependencyResolution(); - } - /** * Checks if jar has to be resolved for the given artifact - * + * * @param art the artifact to check * @return true if resolution should happen */ - protected boolean hasToResolveJar( Artifact art ) + protected final boolean hasToResolveJar( Artifact art ) { - return !( getUseProjectReferences() && isAvailableAsAReactorProject( art ) ) || - ( limitProjectReferencesToWorkspace && !( getUseProjectReferences() && isAvailableAsAWorkspaceProject( art ) ) ); + return !( getUseProjectReferences() && isAvailableAsAReactorProject( art ) ) + || ( limitProjectReferencesToWorkspace && !( getUseProjectReferences() && isAvailableAsAWorkspaceProject( art ) ) ); } /** * Checks if a projects reference has to be used for the given artifact - * + * * @param art the artifact to check * @return true if a project reference has to be used. */ - protected boolean useProjectReference( Artifact art ) + protected final boolean useProjectReference( Artifact art ) { boolean isReactorProject = getUseProjectReferences() && isAvailableAsAReactorProject( art ); boolean isWorkspaceProject = getUseProjectReferences() && isAvailableAsAWorkspaceProject( art ); diff --git a/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/plugin/eclipse/EclipseProjectWriter.java b/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/plugin/eclipse/EclipseProjectWriter.java index 95e02f38ec..14d8a8becd 100644 --- a/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/plugin/eclipse/EclipseProjectWriter.java +++ b/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/plugin/eclipse/EclipseProjectWriter.java @@ -26,6 +26,7 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; +import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; @@ -34,6 +35,7 @@ import java.util.Set; import org.apache.maven.model.Resource; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.eclipse.BuildCommand; +import org.apache.maven.plugin.eclipse.Messages; import org.apache.maven.plugin.eclipse.writers.AbstractEclipseWriter; import org.apache.maven.plugin.ide.IdeDependency; import org.apache.maven.plugin.ide.IdeUtils; @@ -46,11 +48,11 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException; /** * Writes eclipse .project file. - * + * * @author Trygve Laugstøl * @author Kenney Westerhof * @author Fabrizio Giustina - * @version $Id: EclipseProjectWriter.java 616816 2008-01-30 17:23:08Z aheritier $ + * @version $Id: EclipseProjectWriter.java 728546 2008-12-21 22:56:51Z bentmann $ */ public class EclipseProjectWriter extends AbstractEclipseWriter @@ -187,14 +189,18 @@ public class EclipseProjectWriter // referenced projects should not be added for plugins if ( !config.isPde() ) { + List duplicates = new ArrayList(); for ( int j = 0; j < config.getDepsOrdered().length; j++ ) { IdeDependency dep = config.getDepsOrdered()[j]; - if ( dep.isReferencedProject() ) + // Avoid duplicates entries when same project is refered using multiple types + // (ejb, test-jar ...) + if ( dep.isReferencedProject() && !duplicates.contains( dep.getEclipseProjectName() ) ) { writer.startElement( "project" ); //$NON-NLS-1$ writer.writeText( dep.getEclipseProjectName() ); writer.endElement(); + duplicates.add( dep.getEclipseProjectName() ); } } } diff --git a/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/plugin/eclipse/Messages.java b/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/plugin/eclipse/Messages.java index 7e23faa233..5916f50f80 100644 --- a/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/plugin/eclipse/Messages.java +++ b/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/plugin/eclipse/Messages.java @@ -24,7 +24,7 @@ import java.util.ResourceBundle; /** * @author Fabrizio Giustina - * @version $Id: Messages.java 485864 2006-12-11 20:41:36Z fgiust $ + * @version $Id: Messages.java 728546 2008-12-21 22:56:51Z bentmann $ */ public class Messages { diff --git a/maven-plugins/trunk/maven-bundle-plugin/src/main/resources/org/apache/tuscany/maven/plugin/eclipse/messages.properties b/maven-plugins/trunk/maven-bundle-plugin/src/main/resources/org/apache/tuscany/maven/plugin/eclipse/messages.properties index b016c69065..35332a2058 100644 --- a/maven-plugins/trunk/maven-bundle-plugin/src/main/resources/org/apache/tuscany/maven/plugin/eclipse/messages.properties +++ b/maven-plugins/trunk/maven-bundle-plugin/src/main/resources/org/apache/tuscany/maven/plugin/eclipse/messages.properties @@ -1,55 +1,32 @@ -# -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -# EclipsePlugin.missingpom=There must be a POM in the current working directory for the Eclipse plugin to work. EclipsePlugin.pompackaging=Not running eclipse plugin goal for pom project EclipsePlugin.notadir=Not a directory: "{0}" -EclipsePlugin.cantcreatedir=Can''t create directory "{0}" +EclipsePlugin.cantcreatedir=Can't create directory "{0}" EclipsePlugin.erroropeningfile=Exception while opening file. EclipsePlugin.cantwritetofile=Unable to write to file: {0} EclipsePlugin.cantfindresource=Unable to resolve resource location: {0} EclipsePlugin.cantreadfile=Unable to read file: {0} EclipsePlugin.keepexisting=File {0} already exists.\n Additional settings will be preserved, run mvn eclipse:clean if you want old settings to be removed. EclipsePlugin.cantparseexisting=Unable to parse existing file: {0}. Settings will not be preserved. -EclipsePlugin.cantresolvesources=Cannot resolve source artifact. Artifact id: {0} (Message: {1}) EclipsePlugin.wrote=Wrote Eclipse project for "{0}" to {1}. EclipsePlugin.missingelement=Missing element from the project descriptor: "{0}" -EclipsePlugin.includenotsupported=This plugin currently doesn't support include patterns for resources. Adding the entire directory. -EclipsePlugin.excludenotsupported=This plugin currently doesn't support exclude patterns for resources. Adding the entire directory. EclipsePlugin.artifactpathisnull=The artifact path was null. Artifact id: {0} -EclipsePlugin.artifactissystemscoped=The artifact has scope ''system''. Artifact id: {0}. System path: {1} +EclipsePlugin.artifactissystemscoped=The artifact has scope 'system'. Artifact id: {0}. System path: {1} EclipsePlugin.unsupportedwtp=Unsupported WTP version: {0}. This plugin currently supports only the following versions: {1}. EclipsePlugin.wtpversion=Adding support for WTP version {0}. EclipsePlugin.missingjrecontainer=You did specify a list of classpath containers without the base org.eclipse.jdt.launching.JRE_CONTAINER.\n If you specify custom classpath containers you should also add org.eclipse.jdt.launching.JRE_CONTAINER to the list EclipsePlugin.deprecatedpar=Plugin parameter "{0}" is deprecated, please use "{1}" -EclipsePlugin.cantcopyartifact=Can''t copy artifact "{0}". EclipsePlugin.foundadir={0} is a directory, ignoring. +EclipsePlugin.workspace=Using Eclipse Workspace: {0} +EclipsePlugin.cantcanonicalize=Can't canonicalize system path: {0} +EclipsePlugin.unchangedmanifest=Not writing Manifest file as it is unchanged: {0} +EclipsePlugin.invalidvminworkspace=Workspace defines a VM that does not contain a valid jre/lib/rt.jar: {0} EclipseSettingsWriter.wrotesettings=Wrote settings to {0} EclipseSettingsWriter.cannotcreatesettings=Cannot create settings file EclipseSettingsWriter.errorwritingsettings=Error writing settings file EclipseSettingsWriter.usingdefaults=Not writing settings - defaults suffice -EclipseClasspathWriter.lookingforsources=Looking for source archive for artifact {0} -EclipseClasspathWriter.sourcesavailable=Sources attachment for artifact {0} set to {1} - EclipseProjectWriter.notafile=Not adding a file link to {0}; it is not a file EclipseCleanMojo.failedtodelete=Failed to delete {0} file: {0} @@ -57,22 +34,48 @@ EclipseCleanMojo.nofilefound=No {0} file found EclipseCleanMojo.deletingFile=Deleting file: {0} EclipseCleanMojo.deletingDirectory=Deleting directory: {0} -EclipseOSGiManifestWriter.nomanifestfile=The references manifest file doesn''t exist, plugin dependencies will not be updated: {0} - -IdeDependency.cantreadfile=Unable to read file: {0} +EclipseOSGiManifestWriter.nomanifestfile=The references manifest file doesn't exist, plugin dependencies will not be updated: {0} Rad6LibCopier.cantdeletefile=Failed to delete file: {0} -MyEclipseSpringBeansWriter.springVersionNotFound=Spring must be declared in the project's dependencies to generate .springBeans file. +MyEclipseSpringBeansWriter.baseDirDoesNotExist=The (basedir) path declared in the project's dependencies doesn't exist: {0} + +EclipseToMavenMojo.eclipseDirectoryPrompt=Eclipse directory? +EclipseToMavenMojo.errorreadingfromstandardinput=Unable to read from standard input +EclipseToMavenMojo.directoydoesnotexist=Directory {0} doesn't exists +EclipseToMavenMojo.plugindirectorydoesnotexist=Plugin directory {0} doesn't exists +EclipseToMavenMojo.remoterepositorydeployto=Will deploy artifacts to remote repository {0} +EclipseToMavenMojo.processingfile=Processing file {0} +EclipseToMavenMojo.processingplugin=Processing {0} of {1} +EclipseToMavenMojo.skippingfile=Skipping file {0} +EclipseToMavenMojo.unabletoresolveversionrange=Unable to resolve version range for dependency {0} in project {1} +EclipseToMavenMojo.unabletoaccessjar=Unable to access jar {0} +EclipseToMavenMojo.plugindoesnothavemanifest=Plugin {0} does not have a manifest; skipping.. +EclipseToMavenMojo.unabletoreadbundlefrommanifest=Unable to read bundle name/version from manifest, skipping... +EclipseToMavenMojo.errorprocessingplugin=Error processing plugin {0} +EclipseToMavenMojo.errorwritingtemporarypom=Error writing temporary pom file: {0} +EclipseToMavenMojo.errordeployartifacttorepository=Unable to deploy artifact to repository. +EclipseToMavenMojo.errorinstallartifacttorepository=Unable to install artifact to repository. +EclipseToMavenMojo.errorgettingjarfileforplugin=Error getting the jar file for plugin {0} +EclipseToMavenMojo.invalidsyntaxforrepository=Invalid syntax for repository. +EclipseToMavenMojo.invalidremoterepositorysyntax=Invalid syntax for remote repository. Use "id::layout::url". +EclipseToMavenMojo.cannotfindrepositorylayout=Cannot find repository layout: {0} +EclipseToMavenMojo.missingversionforbundle=Missing version for bundle {0}, assuming any version > 0 + +AbstractIdeSupportMojo.sourcesnotavailable=\n Sources for some artifacts are not available.\n List of artifacts without a source archive: +AbstractIdeSupportMojo.sourcesnotdownloaded=\n Sources for some artifacts are not available.\n Please run the same goal with the -DdownloadSources=true parameter in order to check remote repositories for sources.\n List of artifacts without a source archive: +AbstractIdeSupportMojo.sourcesmissingitem=\n o {0} +AbstractIdeSupportMojo.javadocnotavailable=\n Javadoc for some artifacts is not available.\n List of artifacts without a javadoc archive: +AbstractIdeSupportMojo.javadocnotdownloaded=\n Javadoc for some artifacts is not available.\n Please run the same goal with the -DdownloadJavadocs=true parameter in order to check remote repositories for javadoc.\n List of artifacts without a javadoc archive: +AbstractIdeSupportMojo.javadocmissingitem=\n o {0} +AbstractIdeSupportMojo.artifactresolution=An error occurred during dependency resolution of the following artifact:\n {0}:{1}:{2}\nCaused by: {3} +AbstractIdeSupportMojo.artifactdownload=An error occurred during dependency resolution.\n Failed to retrieve {0}:{1}-{2}\nCaused by: {3} +AbstractIdeSupportMojo.unabletoparseversion={0}: unable to parse version '{1}' for dependency '{2}': {3} +AbstractIdeSupportMojo.failedtocreatenotavailablemarkerfile=Error creating not available file {0} +AbstractIdeSupportMojo.creatednotavailablemarkerfile=Not available marker file created: {0} +AbstractIdeSupportMojo.unabletodeletenotavailablemarkerfile=Unable to delete marker file: {0} + +IdeUtils.errorresolving=Error resolving {0} artifact. Artifact id: {1} (Message: {2}) -sourcesnotavailable=\n Sources for some artifacts are not available.\n List of artifacts without a source archive: -sourcesnotdownloaded=\n Sources for some artifacts are not available.\n Please run the same goal with the -DdownloadSources=true parameter in order to check remote repositories for sources.\n List of artifacts without a source archive: -sourcesmissingitem=\n o {0} -javadocnotavailable=\n Javadoc for some artifacts is not available.\n List of artifacts without a javadoc archive: -javadocnotdownloaded=\n Javadoc for some artifacts is not available.\n Please run the same goal with the -DdownloadJavadocs=true parameter in order to check remote repositories for javadoc.\n List of artifacts without a javadoc archive: -javadocmissingitem=\n o {0} -errorresolving=Error resolving {0} artifact. Artifact id: {1} (Message: {2}) -artifactresolution=An error occurred during dependency resolution of the following artifact:\n {0}:{1}:{2}\nCaused by: {3} -artifactdownload=An error occurred during dependency resolution.\n Failed to retrieve {0}:{1}-{2}\nCaused by: {3} -cantcanonicalize=Can''t canonicalize system path: {0} -unabletoparseversion={0}: unable to parse version ''{1}'' for dependency ''{2}'': {3} +RemoveCacheMojo.checking=Checking cache for not available markers +RemoveCacheMojo.complete=Done -- cgit v1.2.3