You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jd...@apache.org on 2007/02/20 20:21:21 UTC
svn commit: r509714 - in /maven/plugins/trunk/maven-eclipse-plugin/src:
main/java/org/apache/maven/plugin/eclipse/
main/java/org/apache/maven/plugin/ide/
test/java/org/apache/maven/plugin/eclipse/
Author: jdcasey
Date: Tue Feb 20 11:21:20 2007
New Revision: 509714
URL: http://svn.apache.org/viewvc?view=rev&rev=509714
Log:
Adding convenience mojo to add bindings for the m2eclipse project instead of normal project bindings.
Added:
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/M2EclipseMojo.java (with props)
Modified:
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/AbstractIdeSupportMojo.java
maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/AbstractEclipsePluginTestCase.java
Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java?view=diff&rev=509714&r1=509713&r2=509714
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java Tue Feb 20 11:21:20 2007
@@ -94,9 +94,9 @@
private static final String NATURE_PDE_PLUGIN = "org.eclipse.pde.PluginNature"; //$NON-NLS-1$
- private static final String COMMON_PATH_JDT_LAUNCHING_JRE_CONTAINER = "org.eclipse.jdt.launching.JRE_CONTAINER"; //$NON-NLS-1$
+ protected static final String COMMON_PATH_JDT_LAUNCHING_JRE_CONTAINER = "org.eclipse.jdt.launching.JRE_CONTAINER"; //$NON-NLS-1$
- private static final String REQUIRED_PLUGINS_CONTAINER = "org.eclipse.pde.core.requiredPlugins"; //$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
public static final String[] WTP_SUPPORTED_VERSIONS = new String[] { "1.0", "1.5", "R7", "none" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@@ -279,6 +279,11 @@
protected boolean isJavaProject()
{
return isJavaProject;
+ }
+
+ protected boolean isPdeProject()
+ {
+ return pde;
}
/**
Added: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/M2EclipseMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/M2EclipseMojo.java?view=auto&rev=509714
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/M2EclipseMojo.java (added)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/M2EclipseMojo.java Tue Feb 20 11:21:20 2007
@@ -0,0 +1,48 @@
+package org.apache.maven.plugin.eclipse;
+
+import org.apache.maven.plugin.MojoExecutionException;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @goal m2eclipse
+ * @execute phase="generate-resources"
+ */
+public class M2EclipseMojo
+ extends EclipsePlugin
+{
+
+ protected static final String M2ECLIPSE_NATURE = "org.maven.ide.eclipse.maven2Nature";
+ protected static final String M2ECLIPSE_BUILD_COMMAND = "org.maven.ide.eclipse.maven2Builder";
+ protected static final String M2ECLIPSE_CLASSPATH_CONTAINER = "org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER";
+
+ protected void setupExtras()
+ throws MojoExecutionException
+ {
+ // disable normal dependency resolution; the m2eclipse plugin will handle it.
+ setResolveDependencies( false );
+
+ setAdditionalProjectnatures( new ArrayList( Collections.singletonList( M2ECLIPSE_NATURE ) ) );
+ setAdditionalBuildcommands( new ArrayList( Collections.singletonList( M2ECLIPSE_BUILD_COMMAND ) ) );
+
+ List classpathContainers = getClasspathContainers();
+ if ( classpathContainers == null )
+ {
+ classpathContainers = new ArrayList();
+
+ classpathContainers.add( COMMON_PATH_JDT_LAUNCHING_JRE_CONTAINER );
+
+ if ( isPdeProject() )
+ {
+ classpathContainers.add( REQUIRED_PLUGINS_CONTAINER );
+ }
+ }
+
+ classpathContainers.add( M2ECLIPSE_CLASSPATH_CONTAINER );
+
+ setClasspathContainers( classpathContainers );
+ }
+
+}
Propchange: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/M2EclipseMojo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/M2EclipseMojo.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/AbstractIdeSupportMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/AbstractIdeSupportMojo.java?view=diff&rev=509714&r1=509713&r2=509714
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/AbstractIdeSupportMojo.java (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/AbstractIdeSupportMojo.java Tue Feb 20 11:21:20 2007
@@ -340,6 +340,16 @@
{
this.downloadSources = downloadSources;
}
+
+ protected void setResolveDependencies( boolean resolveDependencies )
+ {
+ this.resolveDependencies = resolveDependencies;
+ }
+
+ protected boolean isResolveDependencies()
+ {
+ return resolveDependencies;
+ }
/**
* return <code>false</code> if projects available in a reactor build should be considered normal dependencies,
@@ -373,6 +383,12 @@
* Cached array of resolved dependencies.
*/
private IdeDependency[] ideDeps;
+
+ /**
+ * Flag for mojo implementations to control whether normal maven dependencies should be resolved.
+ * Default value is true.
+ */
+ private boolean resolveDependencies = true;
/**
* @see org.codehaus.plexus.logging.LogEnabled#enableLogging(org.codehaus.plexus.logging.Logger)
@@ -417,163 +433,170 @@
{
if ( ideDeps == null )
{
- MavenProject project = getProject();
- ArtifactRepository localRepo = getLocalRepository();
-
- List deps = getProject().getDependencies();
-
- // Collect the list of resolved IdeDependencies.
- List dependencies = new ArrayList();
-
- if ( deps != null )
+ if ( resolveDependencies )
{
- Map managedVersions = createManagedVersionMap( getArtifactFactory(), project.getId(), project
- .getDependencyManagement() );
+ MavenProject project = getProject();
+ ArtifactRepository localRepo = getLocalRepository();
+
+ List deps = getProject().getDependencies();
- ArtifactResolutionResult artifactResolutionResult = null;
+ // Collect the list of resolved IdeDependencies.
+ List dependencies = new ArrayList();
- try
+ if ( deps != null )
{
+ Map managedVersions = createManagedVersionMap( getArtifactFactory(), project.getId(), project
+ .getDependencyManagement() );
- List listeners = new ArrayList();
+ ArtifactResolutionResult artifactResolutionResult = null;
- if ( logger.isDebugEnabled() )
+ try
{
- listeners.add( new DebugResolutionListener( logger ) );
- }
- listeners.add( new WarningResolutionListener( logger ) );
+ List listeners = new ArrayList();
- artifactResolutionResult = artifactCollector.collect( getProjectArtifacts(), project.getArtifact(),
- managedVersions, localRepo, project
- .getRemoteArtifactRepositories(),
- getArtifactMetadataSource(), null, listeners );
- }
- catch ( ArtifactResolutionException e )
- {
- getLog().debug( e.getMessage(), e );
- getLog().error(
- Messages.getString( "artifactresolution", new Object[] { //$NON-NLS-1$
- e.getGroupId(),
- e.getArtifactId(),
- e.getVersion(),
- e.getMessage() } ) );
-
- // if we are here artifactResolutionResult is null, create a project without dependencies but don't fail
- // (this could be a reactor projects, we don't want to fail everything)
- return new IdeDependency[0];
- }
-
- // keep track of added reactor projects in order to avoid duplicates
- Set emittedReactorProjectId = new HashSet();
-
- for ( Iterator i = artifactResolutionResult.getArtifactResolutionNodes().iterator(); i.hasNext(); )
- {
+ if ( logger.isDebugEnabled() )
+ {
+ listeners.add( new DebugResolutionListener( logger ) );
+ }
- ResolutionNode node = (ResolutionNode) i.next();
- int dependencyDepth = node.getDepth();
- Artifact art = node.getArtifact();
- boolean isReactorProject = getUseProjectReferences() && isAvailableAsAReactorProject( art );
+ listeners.add( new WarningResolutionListener( logger ) );
- // don't resolve jars for reactor projects
- if ( !isReactorProject )
+ artifactResolutionResult = artifactCollector.collect( getProjectArtifacts(), project.getArtifact(),
+ managedVersions, localRepo, project
+ .getRemoteArtifactRepositories(),
+ getArtifactMetadataSource(), null, listeners );
+ }
+ catch ( ArtifactResolutionException e )
{
- try
- {
- artifactResolver.resolve( art, node.getRemoteRepositories(), localRepository );
- }
- catch ( ArtifactNotFoundException e )
- {
- getLog().debug( e.getMessage(), e );
- getLog().warn(
- Messages.getString( "artifactdownload", new Object[] { //$NON-NLS-1$
- e.getGroupId(),
- e.getArtifactId(),
- e.getVersion(),
- e.getMessage() } ) );
- }
- catch ( ArtifactResolutionException e )
- {
- getLog().debug( e.getMessage(), e );
- getLog().warn(
- Messages.getString( "artifactresolution", new Object[] { //$NON-NLS-1$
- e.getGroupId(),
- e.getArtifactId(),
- e.getVersion(),
- e.getMessage() } ) );
- }
+ getLog().debug( e.getMessage(), e );
+ getLog().error(
+ Messages.getString( "artifactresolution", new Object[] { //$NON-NLS-1$
+ e.getGroupId(),
+ e.getArtifactId(),
+ e.getVersion(),
+ e.getMessage() } ) );
+
+ // if we are here artifactResolutionResult is null, create a project without dependencies but don't fail
+ // (this could be a reactor projects, we don't want to fail everything)
+ return new IdeDependency[0];
}
- if ( !isReactorProject
- || emittedReactorProjectId.add( art.getGroupId() + '-' + art.getArtifactId() ) )
+ // keep track of added reactor projects in order to avoid duplicates
+ Set emittedReactorProjectId = new HashSet();
+
+ for ( Iterator i = artifactResolutionResult.getArtifactResolutionNodes().iterator(); i.hasNext(); )
{
- // the following doesn't work: art.getArtifactHandler().getPackaging() always returns "jar" also
- // if the packaging specified in pom.xml is different.
+ ResolutionNode node = (ResolutionNode) i.next();
+ int dependencyDepth = node.getDepth();
+ Artifact art = node.getArtifact();
+ boolean isReactorProject = getUseProjectReferences() && isAvailableAsAReactorProject( art );
- // osgi-bundle packaging is provided by the felix osgi plugin
- // eclipse-plugin packaging is provided by this eclipse plugin
- // String packaging = art.getArtifactHandler().getPackaging();
- // boolean isOsgiBundle = "osgi-bundle".equals( packaging ) || "eclipse-plugin".equals( packaging );
-
- // we need to check the manifest, if "Bundle-SymbolicName" is there the artifact can be considered
- // an osgi bundle
- boolean isOsgiBundle = false;
- String osgiSymbolicName = null;
- if ( art.getFile() != null )
+ // don't resolve jars for reactor projects
+ if ( !isReactorProject )
{
- JarFile jarFile = null;
try
{
- jarFile = new JarFile( art.getFile(), false, ZipFile.OPEN_READ );
-
- Manifest manifest = jarFile.getManifest();
- if ( manifest != null )
- {
- osgiSymbolicName = manifest.getMainAttributes()
- .getValue( new Attributes.Name( "Bundle-SymbolicName" ) );
- }
+ artifactResolver.resolve( art, node.getRemoteRepositories(), localRepository );
}
- catch ( IOException e )
+ catch ( ArtifactNotFoundException e )
{
- getLog().info( "Unable to read jar manifest from " + art.getFile() );
+ getLog().debug( e.getMessage(), e );
+ getLog().warn(
+ Messages.getString( "artifactdownload", new Object[] { //$NON-NLS-1$
+ e.getGroupId(),
+ e.getArtifactId(),
+ e.getVersion(),
+ e.getMessage() } ) );
}
- finally
+ catch ( ArtifactResolutionException e )
{
- if ( jarFile != null )
+ getLog().debug( e.getMessage(), e );
+ getLog().warn(
+ Messages.getString( "artifactresolution", new Object[] { //$NON-NLS-1$
+ e.getGroupId(),
+ e.getArtifactId(),
+ e.getVersion(),
+ e.getMessage() } ) );
+ }
+ }
+
+ if ( !isReactorProject
+ || emittedReactorProjectId.add( art.getGroupId() + '-' + art.getArtifactId() ) )
+ {
+
+ // the following doesn't work: art.getArtifactHandler().getPackaging() always returns "jar" also
+ // if the packaging specified in pom.xml is different.
+
+ // osgi-bundle packaging is provided by the felix osgi plugin
+ // eclipse-plugin packaging is provided by this eclipse plugin
+ // String packaging = art.getArtifactHandler().getPackaging();
+ // boolean isOsgiBundle = "osgi-bundle".equals( packaging ) || "eclipse-plugin".equals( packaging );
+
+ // we need to check the manifest, if "Bundle-SymbolicName" is there the artifact can be considered
+ // an osgi bundle
+ boolean isOsgiBundle = false;
+ String osgiSymbolicName = null;
+ if ( art.getFile() != null )
+ {
+ JarFile jarFile = null;
+ try
{
- try
+ jarFile = new JarFile( art.getFile(), false, ZipFile.OPEN_READ );
+
+ Manifest manifest = jarFile.getManifest();
+ if ( manifest != null )
{
- jarFile.close();
+ osgiSymbolicName = manifest.getMainAttributes()
+ .getValue( new Attributes.Name( "Bundle-SymbolicName" ) );
}
- catch ( IOException e )
+ }
+ catch ( IOException e )
+ {
+ getLog().info( "Unable to read jar manifest from " + art.getFile() );
+ }
+ finally
+ {
+ if ( jarFile != null )
{
- // ignore
+ try
+ {
+ jarFile.close();
+ }
+ catch ( IOException e )
+ {
+ // ignore
+ }
}
}
}
- }
- isOsgiBundle = osgiSymbolicName != null;
+ isOsgiBundle = osgiSymbolicName != null;
+
+ IdeDependency dep = new IdeDependency( art.getGroupId(), art.getArtifactId(), art.getVersion(),
+ isReactorProject, Artifact.SCOPE_TEST.equals( art
+ .getScope() ), Artifact.SCOPE_SYSTEM.equals( art
+ .getScope() ), Artifact.SCOPE_PROVIDED.equals( art
+ .getScope() ), art.getArtifactHandler()
+ .isAddedToClasspath(), art.getFile(), art.getType(),
+ isOsgiBundle, osgiSymbolicName, dependencyDepth );
- IdeDependency dep = new IdeDependency( art.getGroupId(), art.getArtifactId(), art.getVersion(),
- isReactorProject, Artifact.SCOPE_TEST.equals( art
- .getScope() ), Artifact.SCOPE_SYSTEM.equals( art
- .getScope() ), Artifact.SCOPE_PROVIDED.equals( art
- .getScope() ), art.getArtifactHandler()
- .isAddedToClasspath(), art.getFile(), art.getType(),
- isOsgiBundle, osgiSymbolicName, dependencyDepth );
+ dependencies.add( dep );
+ }
- dependencies.add( dep );
}
- }
+ //@todo a final report with the list of missingArtifacts?
- //@todo a final report with the list of missingArtifacts?
+ }
+ ideDeps = (IdeDependency[]) dependencies.toArray( new IdeDependency[dependencies.size()] );
+ }
+ else
+ {
+ ideDeps = new IdeDependency[0];
}
-
- ideDeps = (IdeDependency[]) dependencies.toArray( new IdeDependency[dependencies.size()] );
}
return ideDeps;
Modified: maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/AbstractEclipsePluginTestCase.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/AbstractEclipsePluginTestCase.java?view=diff&rev=509714&r1=509713&r2=509714
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/AbstractEclipsePluginTestCase.java (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/AbstractEclipsePluginTestCase.java Tue Feb 20 11:21:20 2007
@@ -113,9 +113,9 @@
for ( int j = 0; j < paths.length; j++ )
{
String pt = paths[j];
- if ( new File( pt, "m2" ).exists() )
+ if ( new File( pt, "mvn" ).exists() )
{
- System.setProperty( "maven.home", new File( pt ).getParent() );
+ System.setProperty( "maven.home", new File( pt ).getAbsoluteFile().getParent() );
break;
}