Author: fgiust Date: Tue Jul 25 13:19:05 2006 New Revision: 425511 URL: http://svn.apache.org/viewvc?rev=425511&view=rev Log: handle dependencies for plugin projects using links, instead of copying jars. Drop the pdeLibDir plugin parameter.
Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseCleanMojo.java 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/eclipse/writers/EclipseClasspathWriter.java maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseOSGiManifestWriter.java maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseProjectWriter.java maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWriterConfig.java maven/plugins/trunk/maven-eclipse-plugin/src/site/site.xml maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-22/classpath maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-22/pom.xml maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-22/project Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseCleanMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseCleanMojo.java?rev=425511&r1=425510&r2=425511&view=diff ============================================================================== --- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseCleanMojo.java (original) +++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseCleanMojo.java Tue Jul 25 13:19:05 2006 @@ -17,7 +17,6 @@ */ import java.io.File; -import java.io.FilenameFilter; import java.io.IOException; import org.apache.maven.plugin.AbstractMojo; @@ -91,13 +90,6 @@ private boolean pde; /** - * The directory of local libraries - * - * @parameter expression="${eclipse.pdeLibDir}" default-value="${basedir}/lib" - */ - private File pdeLibDir; - - /** * @see org.apache.maven.plugin.AbstractMojo#execute() */ public void execute() @@ -125,32 +117,6 @@ delete( settingsDir ); } - if ( pde && pdeLibDir.isDirectory() ) - { - - // delete all the jars in this directory, they have been copied here by the eclipse plugin - File[] localArtifacts = pdeLibDir.listFiles( new FilenameFilter() - { - - public boolean accept( File dir, String name ) - { - return name.endsWith( ".jar" ); - } - } ); - - for ( int j = 0; j < localArtifacts.length; j++ ) - { - File file = localArtifacts[j]; - delete( file ); - } - - // only if the dir is empty, delete it. Don't delete it is there is still something there (for example the - // directory could have been stored in svn and deleting the .svn control dir could cause problems - if ( pdeLibDir.list().length == 0 ) - { - delete( pdeLibDir ); - } - } } /** 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?rev=425511&r1=425510&r2=425511&view=diff ============================================================================== --- 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 Jul 25 13:19:05 2006 @@ -236,13 +236,6 @@ private File manifest; /** - * The directory of local libraries - * - * @parameter expression="${eclipse.pdeLibDir}" default-value="${basedir}/lib" - */ - private File pdeLibDir; - - /** * Parsed wtp version. */ private float wtpVersionFloat; @@ -552,7 +545,6 @@ config.setLocalRepository( localRepository ); config.setManifestFile( manifest ); config.setPde( pde ); - config.setPdeLibDir( pdeLibDir ); config.setProject( project ); config.setProjectBaseDir( projectBaseDir ); config.setProjectnatures( projectnatures ); Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java?rev=425511&r1=425510&r2=425511&view=diff ============================================================================== --- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java (original) +++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java Tue Jul 25 13:19:05 2006 @@ -21,13 +21,11 @@ import java.io.IOException; import java.util.Iterator; -import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.eclipse.EclipseSourceDir; import org.apache.maven.plugin.eclipse.Messages; import org.apache.maven.plugin.ide.IdeDependency; import org.apache.maven.plugin.ide.IdeUtils; -import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; @@ -187,8 +185,7 @@ if ( dep.isAddedToClasspath() ) { - addDependency( writer, dep, config.getLocalRepository(), config.getEclipseProjectDirectory(), config - .isPde(), config.getPdeLibDir() ); + addDependency( writer, dep ); } } @@ -198,8 +195,7 @@ } - private void addDependency( XMLWriter writer, IdeDependency dep, ArtifactRepository localRepository, - File projectBaseDir, boolean inPdeMode, File pdeLibDir ) + private void addDependency( XMLWriter writer, IdeDependency dep ) throws MojoExecutionException { @@ -208,7 +204,7 @@ String sourcepath = null; String javadocpath = null; - if ( dep.isReferencedProject() && !inPdeMode ) + if ( dep.isReferencedProject() && !config.isPde() ) { path = "/" + dep.getArtifactId(); //$NON-NLS-1$ kind = ATTR_SRC; @@ -237,34 +233,21 @@ } else { - File localRepositoryFile = new File( localRepository.getBasedir() ); + File localRepositoryFile = new File( config.getLocalRepository().getBasedir() ); // if the dependency is not provided and the plugin runs in "pde mode", the dependency is // added to the Bundle-Classpath: - if ( inPdeMode && !dep.isProvided() && !dep.isTestDependency() ) + if ( config.isPde() && !dep.isProvided() && !dep.isTestDependency() ) { - try - { - if ( !pdeLibDir.exists() ) - { - pdeLibDir.mkdirs(); - } - FileUtils.copyFileToDirectory( dep.getFile(), pdeLibDir ); - } - catch ( IOException e ) - { - throw new MojoExecutionException( Messages.getString( "EclipsePlugin.cantcopyartifact", dep - .getArtifactId() ), e ); - } - File artifactFile = new File( pdeLibDir, dep.getFile().getName() ); - path = IdeUtils.toRelativeAndFixSeparator( config.getProjectBaseDir(), artifactFile, false ); + // path for link created in .project, not to the actual file + path = dep.getFile().getName(); kind = ATTR_LIB; } // running in PDE mode and the dependency is provided means, that it is provided by // the target platform. This case is covered by adding the plugin container - else if ( inPdeMode && dep.isProvided() ) + else if ( config.isPde() && dep.isProvided() ) { return; } Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseOSGiManifestWriter.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseOSGiManifestWriter.java?rev=425511&r1=425510&r2=425511&view=diff ============================================================================== --- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseOSGiManifestWriter.java (original) +++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseOSGiManifestWriter.java Tue Jul 25 13:19:05 2006 @@ -25,7 +25,6 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.eclipse.Messages; import org.apache.maven.plugin.ide.IdeDependency; -import org.apache.maven.plugin.ide.IdeUtils; import org.codehaus.plexus.util.IOUtil; /** @@ -82,7 +81,7 @@ return; } - StringBuffer manifestSb = rewriteManifest( config.getManifestFile(), config.getPdeLibDir() ); + StringBuffer manifestSb = rewriteManifest( config.getManifestFile() ); FileWriter fos = null; try { @@ -105,7 +104,7 @@ } } - protected StringBuffer rewriteManifest( File manifestFile, File libdir ) + protected StringBuffer rewriteManifest( File manifestFile ) throws MojoExecutionException { @@ -173,7 +172,7 @@ { throw new MojoExecutionException( Messages.getString( "cantreadfile", manifestFile.getAbsolutePath() ) ); } - manifestSb.append( addBundleClasspathEntries( libdir ) ); + manifestSb.append( addBundleClasspathEntries() ); // OSGi manifest headers need to end with a line break manifestSb.append( NEWLINE ); @@ -184,7 +183,7 @@ * Add all libraries that don't have the scope "provided" to the "Bundle-Classpath". * @throws MojoExecutionException */ - protected String addBundleClasspathEntries( File libdir ) + protected String addBundleClasspathEntries() throws MojoExecutionException { StringBuffer bundleClasspathSb = new StringBuffer( ENTRY_BUNDLE_CLASSPATH ); @@ -202,10 +201,7 @@ log.debug( "Adding artifact to manifest: " + dep.getArtifactId() ); - File artifactFile = new File( libdir, dep.getFile().getName() ); - - bundleClasspathSb.append( " " - + IdeUtils.toRelativeAndFixSeparator( config.getEclipseProjectDirectory(), artifactFile, false ) ); + bundleClasspathSb.append( " " + dep.getFile().getName() ); } } // only insert the name of the property if there are local libraries Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseProjectWriter.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseProjectWriter.java?rev=425511&r1=425510&r2=425511&view=diff ============================================================================== --- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseProjectWriter.java (original) +++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseProjectWriter.java Tue Jul 25 13:19:05 2006 @@ -64,6 +64,16 @@ private static final String FILE_DOT_PROJECT = ".project"; //$NON-NLS-1$ /** + * Constant for links to files. + */ + private static final int LINK_TYPE_FILE = 1; + + /** + * Constant for links to directories. + */ + private static final int LINK_TYPE_DIRECTORY = 2; + + /** * @see org.apache.maven.plugin.eclipse.writers.EclipseWriter#write() */ public void write() @@ -232,6 +242,21 @@ writer.endElement(); // linedResources } + if ( config.isPde() ) + { + for ( int j = 0; j < config.getDeps().length; j++ ) + { + IdeDependency dep = config.getDeps()[j]; + + if ( dep.isAddedToClasspath() && !dep.isProvided() && !dep.isReferencedProject() + && !dep.isTestDependency() ) + { + String name = dep.getFile().getName(); + addLink( writer, name, name, LINK_TYPE_FILE ); + } + } + } + writer.endElement(); // projectDescription IOUtil.close( w ); @@ -242,23 +267,10 @@ { if ( file.isFile() ) { - writer.startElement( "link" ); //$NON-NLS-1$ - - writer.startElement( ELT_NAME ); - writer.writeText( IdeUtils.toRelativeAndFixSeparator( projectBaseDir, file, true ) ); - writer.endElement(); // name - - writer.startElement( "type" ); //$NON-NLS-1$ - writer.writeText( "1" ); //$NON-NLS-1$ - writer.endElement(); // type - - writer.startElement( "location" ); //$NON-NLS-1$ + String name = IdeUtils.toRelativeAndFixSeparator( projectBaseDir, file, true ); + String location = IdeUtils.getCanonicalPath( file ).replaceAll( "\\\\", "/" ); //$NON-NLS-1$ //$NON-NLS-2$ - writer.writeText( IdeUtils.getCanonicalPath( file ).replaceAll( "\\\\", "/" ) ); //$NON-NLS-1$ //$NON-NLS-2$ - - writer.endElement(); // location - - writer.endElement(); // link + addLink( writer, name, location, LINK_TYPE_FILE ); } else { @@ -276,23 +288,10 @@ if ( sourceRoot.isDirectory() ) { - writer.startElement( "link" ); //$NON-NLS-1$ - - writer.startElement( ELT_NAME ); - writer.writeText( IdeUtils.toRelativeAndFixSeparator( projectBaseDir, sourceRoot, true ) ); - writer.endElement(); // name - - writer.startElement( "type" ); //$NON-NLS-1$ - writer.writeText( "2" ); //$NON-NLS-1$ - writer.endElement(); // type - - writer.startElement( "location" ); //$NON-NLS-1$ + String name = IdeUtils.toRelativeAndFixSeparator( projectBaseDir, sourceRoot, true ); + String location = IdeUtils.getCanonicalPath( sourceRoot ).replaceAll( "\\\\", "/" ); //$NON-NLS-1$ //$NON-NLS-2$ - writer.writeText( IdeUtils.getCanonicalPath( sourceRoot ).replaceAll( "\\\\", "/" ) ); //$NON-NLS-1$ //$NON-NLS-2$ - - writer.endElement(); // location - - writer.endElement(); // link + addLink( writer, name, location, LINK_TYPE_DIRECTORY ); } } } @@ -307,25 +306,37 @@ if ( resourceDir.isDirectory() ) { - writer.startElement( "link" ); //$NON-NLS-1$ + String name = IdeUtils.toRelativeAndFixSeparator( projectBaseDir, resourceDir, true ); + String location = IdeUtils.getCanonicalPath( resourceDir ).replaceAll( "\\\\", "/" ); //$NON-NLS-1$ //$NON-NLS-2$ + + addLink( writer, name, location, LINK_TYPE_DIRECTORY ); + } + } + } - writer.startElement( ELT_NAME ); - writer.writeText( IdeUtils.toRelativeAndFixSeparator( projectBaseDir, resourceDir, true ) ); - writer.endElement(); // name + /** + * @param writer + * @param name + * @param location + */ + private void addLink( XMLWriter writer, String name, String location, int type ) + { + writer.startElement( "link" ); //$NON-NLS-1$ - writer.startElement( "type" ); //$NON-NLS-1$ - writer.writeText( "2" ); //$NON-NLS-1$ - writer.endElement(); // type + writer.startElement( ELT_NAME ); + writer.writeText( name ); + writer.endElement(); // name - writer.startElement( "location" ); //$NON-NLS-1$ + writer.startElement( "type" ); //$NON-NLS-1$ + writer.writeText( Integer.toString( type ) ); + writer.endElement(); // type - writer.writeText( IdeUtils.getCanonicalPath( resourceDir ).replaceAll( "\\\\", "/" ) ); //$NON-NLS-1$ //$NON-NLS-2$ + writer.startElement( "location" ); //$NON-NLS-1$ - writer.endElement(); // location + writer.writeText( location ); - writer.endElement(); // link - } - } - } + writer.endElement(); // location + writer.endElement(); // link + } } Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWriterConfig.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWriterConfig.java?rev=425511&r1=425510&r2=425511&view=diff ============================================================================== --- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWriterConfig.java (original) +++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWriterConfig.java Tue Jul 25 13:19:05 2006 @@ -76,11 +76,6 @@ private boolean pde; /** - * PDE lib dir. - */ - private File pdeLibDir; - - /** * Project natures. */ private List projectnatures; @@ -219,24 +214,6 @@ public void setManifestFile( File manifestFile ) { this.manifestFile = manifestFile; - } - - /** - * Getter for <code>pdeLibDir</code>. - * @return Returns the pdeLibDir. - */ - public File getPdeLibDir() - { - return this.pdeLibDir; - } - - /** - * Setter for <code>pdeLibDir</code>. - * @param pdeLibDir The pdeLibDir to set. - */ - public void setPdeLibDir( File pdeLibDir ) - { - this.pdeLibDir = pdeLibDir; } /** Modified: maven/plugins/trunk/maven-eclipse-plugin/src/site/site.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/site/site.xml?rev=425511&r1=425510&r2=425511&view=diff ============================================================================== --- maven/plugins/trunk/maven-eclipse-plugin/src/site/site.xml (original) +++ maven/plugins/trunk/maven-eclipse-plugin/src/site/site.xml Tue Jul 25 13:19:05 2006 @@ -1,6 +1,6 @@ <project name="Maven Compiler Plugin"> <bannerLeft> - <name>Maven Compiler Plugin</name> + <name>Maven Eclipse Plugin</name> <src>http://maven.apache.org/images/apache-maven-project.png</src> <href>http://maven.apache.org/</href> </bannerLeft> Modified: maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-22/classpath URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-22/classpath?rev=425511&r1=425510&r2=425511&view=diff ============================================================================== --- maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-22/classpath (original) +++ maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-22/classpath Tue Jul 25 13:19:05 2006 @@ -1,5 +1,6 @@ -<classpath> - <classpathentry kind="output" path="target/classes"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> - <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> +<classpath> + <classpathentry kind="output" path="target/classes"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="lib" exported="true" path="junit-3.8.1.jar"/> </classpath> Modified: maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-22/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-22/pom.xml?rev=425511&r1=425510&r2=425511&view=diff ============================================================================== --- maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-22/pom.xml (original) +++ maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-22/pom.xml Tue Jul 25 13:19:05 2006 @@ -6,4 +6,11 @@ <packaging>eclipse-plugin</packaging> <version>22</version> <name>maven-eclipse-plugin-test-project-22</name> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + </dependency> + </dependencies> </project> Modified: maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-22/project URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-22/project?rev=425511&r1=425510&r2=425511&view=diff ============================================================================== --- maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-22/project (original) +++ maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-22/project Tue Jul 25 13:19:05 2006 @@ -1,23 +1,28 @@ -<projectDescription> - <name>maven-eclipse-plugin-test-project-22</name> - <comment/> - <projects/> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments/> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.ManifestBuilder</name> - <arguments/> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.SchemaBuilder</name> - <arguments/> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.jdt.core.javanature</nature> - <nature>org.eclipse.pde.PluginNature</nature> - </natures> +<projectDescription> + <name>maven-eclipse-plugin-test-project-22</name> + <comment/> + <projects/> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments/> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments/> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments/> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + <nature>org.eclipse.pde.PluginNature</nature> + </natures> + <link> + <name>junit-3.8.1.jar</name> + <type>1</type> + <location>junit-3.8.1.jar</location> + </link> </projectDescription>