Index: src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java =================================================================== --- src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java (revision 463128) +++ src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java (working copy) @@ -81,6 +81,8 @@ private static final String BUILDER_PDE_SCHEMA = "org.eclipse.pde.SchemaBuilder"; //$NON-NLS-1$ + private static final String BUILDER_M2ECLIPSE = "org.maven.ide.eclipse.maven2Builder"; //$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$ @@ -89,6 +91,8 @@ private static final String NATURE_PDE_PLUGIN = "org.eclipse.pde.PluginNature"; //$NON-NLS-1$ + private static final String NATURE_M2ECLIPSE = "org.maven.ide.eclipse.maven2Nature"; //$NON-NLS-1$ + private 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$ @@ -205,6 +209,17 @@ private boolean useProjectReferences; /** + * When set to true, the plugin will add the a classpath container for the + * the Maven dependencies and will NOT write out the classpaths that are + * part of the dependency. The appropriate nature and builder will also be added + * to the .project file. + * + * @parameter expression="${m2eclipse}" default-value="false" + * @required + */ + private boolean m2eclipse; + + /** * The default output directory * * @parameter expression="${outputDirectory}" alias="outputDirectory" default-value="${project.build.outputDirectory}" @@ -380,6 +395,24 @@ } /** + * Getter for m2eclipse. + * @return Returns the m2eclipse. + */ + public boolean getM2eclipse() + { + return this.m2eclipse; + } + + /** + * Setter for useProjectReferences. + * @param useProjectReferences The useProjectReferences to set. + */ + public void setM2eclipse( boolean m2eclipse ) + { + this.m2eclipse = m2eclipse; + } + + /** * Getter for wtpversion. * @return Returns the wtpversion. */ @@ -449,6 +482,11 @@ downloadSources = true; } + if ( m2eclipse ) + { + getLog().info( Messages.getString( "EclipsePlugin.m2eclipse" ) ); + } + if ( Arrays.binarySearch( WTP_SUPPORTED_VERSIONS, wtpversion ) < 0 ) { throw new MojoExecutionException( Messages @@ -569,6 +607,7 @@ config.setDeps( deps ); config.setEclipseProjectDirectory( eclipseProjectDir ); config.setLocalRepository( localRepository ); + config.setM2eclipse( m2eclipse ); config.setManifestFile( manifest ); config.setPde( pde ); config.setProject( project ); @@ -652,6 +691,11 @@ { projectnatures = new ArrayList(); + if ( m2eclipse ) + { + projectnatures.add( NATURE_M2ECLIPSE ); + } + if ( wtpVersionFloat >= 1.0f ) { projectnatures.add( NATURE_WST_FACET_CORE_NATURE ); // WTP 1.0 nature @@ -694,6 +738,11 @@ { buildcommands = new ArrayList(); + if ( m2eclipse ) + { + buildcommands.add( BUILDER_M2ECLIPSE ); + } + if ( wtpVersionFloat == 0.7f ) { buildcommands.add( BUILDER_WST_COMPONENT_STRUCTURAL ); // WTP 0.7 builder Index: src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java =================================================================== --- src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java (revision 463128) +++ src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java (working copy) @@ -114,6 +114,11 @@ private static final String FILE_DOT_CLASSPATH = ".classpath"; //$NON-NLS-1$ /** + * Classpath container used when setting up m2eclipse readiness. + */ + private static final String M2ECLIPSE_DEPENDENCY_CONTAINER = "org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"; //$NON-NLS-1$ + + /** * @see org.apache.maven.plugin.eclipse.writers.EclipseWriter#write() */ public void write() @@ -199,6 +204,16 @@ } } + // if we are setting it up to be m2eclipse ready then the container for dependencies + // needs to come after the dependency list above since we could have projects referenced + // by source that need to be above this + if ( config.isM2eclipse() ) { + writer.startElement( ELT_CLASSPATHENTRY ); + writer.addAttribute( ATTR_KIND, "con" ); //$NON-NLS-1$ + writer.addAttribute( ATTR_PATH, M2ECLIPSE_DEPENDENCY_CONTAINER ); + writer.endElement(); // name + } + writer.endElement(); IOUtil.close( w ); @@ -244,6 +259,7 @@ else { File localRepositoryFile = new File( config.getLocalRepository().getBasedir() ); + boolean isM2RepositoryItem = false; // if the dependency is not provided and the plugin runs in "pde mode", the dependency is // added to the Bundle-Classpath: @@ -264,6 +280,7 @@ else { String fullPath = artifactPath.getPath(); + isM2RepositoryItem = true; path = M2_REPO + "/" //$NON-NLS-1$ + IdeUtils.toRelativeAndFixSeparator( localRepositoryFile, new File( fullPath ), false ); @@ -274,6 +291,7 @@ { if ( ATTR_VAR.equals( kind ) ) { + isM2RepositoryItem = true; sourcepath = M2_REPO + "/" //$NON-NLS-1$ + IdeUtils @@ -283,9 +301,16 @@ { // source archive must be referenced with the full path, we can't mix a lib with a variable sourcepath = IdeUtils.getCanonicalPath( dep.getSourceAttachment() ); + // we are no longer referencing the M2_REPO + isM2RepositoryItem = false; } } + // if using m2eclipse and the item is marked with the M2_REPO then no need add it in + if ( config.isM2eclipse() && isM2RepositoryItem ) { + return; + } + if ( dep.getJavadocAttachment() != null ) { // NB eclipse (3.1) doesn't support variables in javadoc paths, so we need to add the Index: src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWriterConfig.java =================================================================== --- src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWriterConfig.java (revision 463128) +++ src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWriterConfig.java (working copy) @@ -71,6 +71,11 @@ private File manifestFile; /** + * M2eclipse ready. + */ + private boolean m2eclipse; + + /** * PDE mode. */ private boolean pde; @@ -253,6 +258,24 @@ } /** + * Getter for m2eclipse. + * @return Returns the m2eclipse. + */ + public boolean isM2eclipse() + { + return this.m2eclipse; + } + + /** + * Setter for m2eclipse. + * @param m2eclipse The m2eclipse to set. + */ + public void setM2eclipse( boolean m2eclipse ) + { + this.m2eclipse = m2eclipse; + } + + /** * Getter for buildCommands. * @return Returns the buildCommands. */ Index: src/main/resources/org/apache/maven/plugin/eclipse/messages.properties =================================================================== --- src/main/resources/org/apache/maven/plugin/eclipse/messages.properties (revision 463128) +++ src/main/resources/org/apache/maven/plugin/eclipse/messages.properties (working copy) @@ -16,6 +16,7 @@ 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.m2eclipse=Adding support for m2eclipse plugin. 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}".