From f0d674133e4e2d777639ff377cc8c7e29c3d6874 Mon Sep 17 00:00:00 2001 From: Fabrizio Giustina Date: Tue, 1 Nov 2005 16:33:39 +0000 Subject: [PATCH] When the downloadSources flag was off, also source files available in the local repository were not used. Fixed so that sources archives available in the local repository are used but no additional jars are downloaded. Added an explanation message on how to turn source downloading on (this should be on by default, but let's wait till there will be more sources archives in the m2 repo) git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@330090 13f79535-47bb-0310-9956-ffa450edef68 --- .../eclipse/EclipseClasspathWriter.java | 45 +++++++++++-------- .../maven/plugin/eclipse/messages.properties | 1 + 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseClasspathWriter.java b/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseClasspathWriter.java index 428e32549c..361a41ddec 100644 --- a/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseClasspathWriter.java +++ b/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseClasspathWriter.java @@ -19,6 +19,7 @@ package org.apache.maven.plugin.eclipse; import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Set; @@ -237,28 +238,33 @@ public class EclipseClasspathWriter path = "M2_REPO/" //$NON-NLS-1$ + EclipseUtils.toRelativeAndFixSeparator( localRepositoryFile, fullPath, false ); - if ( downloadSources ) - { - Artifact sourceArtifact = retrieveSourceArtifact( artifact, remoteArtifactRepositories, - localRepository, artifactResolver, - artifactFactory ); + Artifact sourceArtifact = retrieveSourceArtifact( artifact, remoteArtifactRepositories, + localRepository, artifactResolver, artifactFactory, + downloadSources ); - if ( !sourceArtifact.isResolved() ) + if ( !sourceArtifact.isResolved() ) + { + if ( downloadSources ) { log.info( Messages.getString( "EclipseClasspathWriter.sourcesnotavailable", //$NON-NLS-1$ - sourceArtifact.getArtifactId() ) ); + sourceArtifact.getId() ) ); } else { - log.debug( Messages.getString( "EclipseClasspathWriter.sourcesavailable", //$NON-NLS-1$ - new Object[] { - sourceArtifact.getArtifactId(), - sourceArtifact.getFile().getAbsolutePath() } ) ); - - sourcepath = "M2_REPO/" //$NON-NLS-1$ - + EclipseUtils.toRelativeAndFixSeparator( localRepositoryFile, sourceArtifact.getFile() - .getAbsolutePath(), false ); + log.info( Messages.getString( "EclipseClasspathWriter.sourcesnotdownloaded", //$NON-NLS-1$ + sourceArtifact.getId() ) ); } + } + else + { + log.debug( Messages.getString( "EclipseClasspathWriter.sourcesavailable", //$NON-NLS-1$ + new Object[] { + sourceArtifact.getId(), + sourceArtifact.getFile().getAbsolutePath() } ) ); + + sourcepath = "M2_REPO/" //$NON-NLS-1$ + + EclipseUtils.toRelativeAndFixSeparator( localRepositoryFile, sourceArtifact.getFile() + .getAbsolutePath(), false ); } @@ -281,7 +287,7 @@ public class EclipseClasspathWriter private Artifact retrieveSourceArtifact( Artifact artifact, List remoteArtifactRepositories, ArtifactRepository localRepository, ArtifactResolver artifactResolver, - ArtifactFactory artifactFactory ) + ArtifactFactory artifactFactory, boolean downloadSources ) throws MojoExecutionException { // source artifact: use the "sources" classifier added by the source plugin @@ -293,7 +299,8 @@ public class EclipseClasspathWriter log.debug( Messages.getString( "EclipseClasspathWriter.lookingforsources", //$NON-NLS-1$ sourceArtifact.getArtifactId() ) ); - artifactResolver.resolve( sourceArtifact, remoteArtifactRepositories, localRepository ); + artifactResolver.resolve( sourceArtifact, downloadSources ? remoteArtifactRepositories : new ArrayList(), + localRepository ); } catch ( ArtifactNotFoundException e ) { @@ -301,7 +308,7 @@ public class EclipseClasspathWriter if ( log.isDebugEnabled() ) { String message = Messages.getString( "EclipseClasspathWriter.cantresolvesources", //$NON-NLS-1$ - new Object[] { sourceArtifact.getArtifactId(), e.getMessage() } ); + new Object[] { sourceArtifact.getId(), e.getMessage() } ); log.debug( message, e ); } @@ -309,7 +316,7 @@ public class EclipseClasspathWriter catch ( ArtifactResolutionException e ) { String message = Messages.getString( "EclipseClasspathWriter.errorresolvingsources", //$NON-NLS-1$ - new Object[] { sourceArtifact.getArtifactId(), e.getMessage() } ); + new Object[] { sourceArtifact.getId(), e.getMessage() } ); throw new MojoExecutionException( message, e ); } diff --git a/maven-plugins/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties b/maven-plugins/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties index a95c7690cf..f972709fa3 100644 --- a/maven-plugins/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties +++ b/maven-plugins/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties @@ -22,6 +22,7 @@ EclipseSettingsWriter.usingdefaults=Not writing settings - defaults suffice EclipseClasspathWriter.lookingforsources=Looking for source archive for artifact {0} EclipseClasspathWriter.sourcesnotavailable=Sources for artifact {0} are not available +EclipseClasspathWriter.sourcesnotdownloaded=Sources for artifact {0} will not be downloaded.\n Please run "mvn -Declipse.downloadSources=true eclipse:eclipse" in order to check remote repositories for sources. EclipseClasspathWriter.sourcesavailable=Sources attachment for artifact {0} set to {1} EclipseProjectWriter.notafile=Not adding a file link to {0}; it is not a file \ No newline at end of file