You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2007/07/07 16:49:47 UTC
svn commit: r554214 - in
/maven/plugins/branches/maven-eclipse-plugin-MECLIPSE-292/src/main:
java/org/apache/maven/plugin/ide/AbstractIdeSupportMojo.java
resources/org/apache/maven/plugin/ide/messages.properties
Author: brianf
Date: Sat Jul 7 07:49:46 2007
New Revision: 554214
URL: http://svn.apache.org/viewvc?view=rev&rev=554214
Log:
Applied/Refactored MECLIPSE-292 patch
Modified:
maven/plugins/branches/maven-eclipse-plugin-MECLIPSE-292/src/main/java/org/apache/maven/plugin/ide/AbstractIdeSupportMojo.java
maven/plugins/branches/maven-eclipse-plugin-MECLIPSE-292/src/main/resources/org/apache/maven/plugin/ide/messages.properties
Modified: maven/plugins/branches/maven-eclipse-plugin-MECLIPSE-292/src/main/java/org/apache/maven/plugin/ide/AbstractIdeSupportMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-eclipse-plugin-MECLIPSE-292/src/main/java/org/apache/maven/plugin/ide/AbstractIdeSupportMojo.java?view=diff&rev=554214&r1=554213&r2=554214
==============================================================================
--- maven/plugins/branches/maven-eclipse-plugin-MECLIPSE-292/src/main/java/org/apache/maven/plugin/ide/AbstractIdeSupportMojo.java (original)
+++ maven/plugins/branches/maven-eclipse-plugin-MECLIPSE-292/src/main/java/org/apache/maven/plugin/ide/AbstractIdeSupportMojo.java Sat Jul 7 07:49:46 2007
@@ -182,6 +182,21 @@
protected boolean downloadSources;
/**
+ * Enables/disables the downloading of javadoc
+ * attachments. Defaults to false. When this flag is
+ * <code>true</code> 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 <code>mvn:clean</code> or delete the file
+ * <code>mvn-eclipse-cache.properties</code> in order
+ * to reset this cache.
+ *
+ * @parameter expression="${downloadJavadoc}"
+ */
+ protected boolean downloadJavadoc;
+
+ /**
* Plexus logger needed for debugging manual artifact resolution.
*/
private Logger logger;
@@ -331,7 +346,28 @@
}
/**
+ * Getter for <code>downloadJavadoc</code>.
+ *
+ * @return Returns the downloadJavadoc.
+ */
+ public boolean getDownloadJavadoc()
+ {
+ return this.downloadJavadoc;
+ }
+
+ /**
+ * Setter for <code>downloadJavadoc</code>.
+ *
+ * @param downloadJavadoc The downloadJavadoc to set.
+ */
+ public void setDownloadJavadoc( boolean downloadJavadoc )
+ {
+ this.downloadJavadoc = downloadJavadoc;
+ }
+
+ /**
* Getter for <code>downloadSources</code>.
+ *
* @return Returns the downloadSources.
*/
public boolean getDownloadSources()
@@ -387,6 +423,12 @@
private List missingSourceDependencies = new ArrayList();
/**
+ * Not a plugin parameter. Collect the list of dependencies with a missing javadoc artifact for the final report.
+ */
+ // TODO merge this with the missingSourceDependencies in a classifier based map?
+ private List missingJavadocDependencies = new ArrayList();
+
+ /**
* Cached array of resolved dependencies.
*/
private IdeDependency[] ideDeps;
@@ -425,11 +467,11 @@
// resolve artifacts
IdeDependency[] deps = doDependencyResolution();
- resolveSourceArtifacts( deps );
+ resolveSourceAndJavadocArtifacts( deps );
writeConfiguration( deps );
- reportMissingSources();
+ reportMissingArtifacts();
}
@@ -474,10 +516,10 @@
listeners.add( new WarningResolutionListener( logger ) );
- artifactResolutionResult = artifactCollector.collect( getProjectArtifacts(), project.getArtifact(),
- managedVersions, localRepo, project
- .getRemoteArtifactRepositories(),
- getArtifactMetadataSource(), null, listeners );
+ artifactResolutionResult = artifactCollector.collect( getProjectArtifacts(), project
+ .getArtifact(), managedVersions, localRepo, project.getRemoteArtifactRepositories(),
+ getArtifactMetadataSource(), null,
+ listeners );
}
catch ( ArtifactResolutionException e )
{
@@ -587,21 +629,20 @@
isOsgiBundle = osgiSymbolicName != null;
- IdeDependency dep = new IdeDependency( art.getGroupId(), art.getArtifactId(), art.getVersion(),
- art.getClassifier(),
- 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(), art.getClassifier(), 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 );
}
}
- //@todo a final report with the list of missingArtifacts?
+ // @todo a final report with the list of
+ // missingArtifacts?
}
@@ -617,10 +658,14 @@
}
/**
- * Returns the list of project artifacts. Also artifacts generated from referenced projects will be added, but with
- * the <code>resolved</code> property set to true.
+ * Returns the list of project artifacts. Also artifacts
+ * generated from referenced projects will be added, but
+ * with the <code>resolved</code> property set to
+ * true.
+ *
* @return list of projects artifacts
- * @throws MojoExecutionException if unable to parse dependency versions
+ * @throws MojoExecutionException if unable to parse
+ * dependency versions
*/
private Set getProjectArtifacts()
throws MojoExecutionException
@@ -780,30 +825,32 @@
/**
* Resolve source artifacts and download them if <code>downloadSources</code> is <code>true</code>. Source and
* javadocs artifacts will be attached to the <code>IdeDependency</code>
+ * Resolve source and javadoc artifacts. The resolved artifacts will be downloaded based on the
+ * <code>downloadSources</code> and <code>downloadJavadocs</code> attributes. Source and
* @param deps resolved dependencies
*/
- private void resolveSourceArtifacts( IdeDependency[] deps )
+ private void resolveSourceAndJavadocArtifacts( IdeDependency[] deps )
{
File reactorTargetDir = getReactorTargetDir( project );
- File unavailableSourcesTmpFile = new File( reactorTargetDir, "mvn-eclipse-cache.properties" );
+ File unavailableArtifactsTmpFile = new File( reactorTargetDir, "mvn-eclipse-cache.properties" );
- getLog().info( "Using source status cache: " + unavailableSourcesTmpFile.getAbsolutePath() );
+ getLog().info( "Using source status cache: " + unavailableArtifactsTmpFile.getAbsolutePath() );
// create target dir if missing
- if ( !unavailableSourcesTmpFile.getParentFile().exists() )
+ if ( !unavailableArtifactsTmpFile.getParentFile().exists() )
{
- unavailableSourcesTmpFile.getParentFile().mkdirs();
+ unavailableArtifactsTmpFile.getParentFile().mkdirs();
}
- Properties unavailableSourcesCache = new Properties();
- if ( unavailableSourcesTmpFile.exists() )
+ Properties unavailableArtifactsCache = new Properties();
+ if ( unavailableArtifactsTmpFile.exists() )
{
InputStream is = null;
try
{
- is = new FileInputStream( unavailableSourcesTmpFile );
- unavailableSourcesCache.load( is );
+ is = new FileInputStream( unavailableArtifactsTmpFile );
+ unavailableArtifactsCache.load( is );
}
catch ( IOException e )
{
@@ -816,12 +863,59 @@
}
- ArtifactRepository localRepository = getLocalRepository();
- ArtifactResolver artifactResolver = getArtifactResolver();
- ArtifactFactory artifactFactory = getArtifactFactory();
+ final List missingSources = resolveDependenciesWithClassifier( deps, "sources", getDownloadSources(),
+ unavailableArtifactsCache );
+ missingSourceDependencies.addAll( missingSources );
+
+ final List missingJavadocs = resolveDependenciesWithClassifier( deps, "javadoc", getDownloadJavadoc(),
+ unavailableArtifactsCache );
+ missingJavadocDependencies.addAll( missingJavadocs );
- // if downloadSources is off, just check local repository for reporting missing jars
- List remoteRepos = getDownloadSources() ? getRemoteArtifactRepositories() : Collections.EMPTY_LIST;
+ 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. <code>sources</code> or
+ * <code>javadoc</code> artifacts (depending on the
+ * <code>classifier</code>) are attached to the
+ * dependency.
+ *
+ * @param deps resolved dependencies
+ * @param classifier the classifier we are looking for
+ * (either <code>sources</code> or
+ * <code>javadoc</code>)
+ * @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 )
+ {
+ List missingClassifierDependencies = new ArrayList();
+
+ // if downloadSources is off, just check
+ // local repository for reporting missing source jars
+ List remoteRepos = includeRemoteRepositories ? getRemoteArtifactRepositories() : Collections.EMPTY_LIST;
for ( int j = 0; j < deps.length; j++ )
{
@@ -829,111 +923,99 @@
if ( dependency.isReferencedProject() || dependency.isSystemScoped() )
{
- // source artifact not needed
+ //artifact not needed
continue;
}
-
- String classifier = "sources";
- if("tests".equals(dependency.getClassifier()))
+
+ //MECLIPSE-151 - if the dependency is a test, get the correct classifier for it. (ignore for javadocs)
+ String classifier = inClassifier;
+ if("sources".equals( classifier ) && "tests".equals(dependency.getClassifier()))
{
classifier = "test-sources";
}
+
if(getLog().isDebugEnabled())
{
getLog().debug("Searching for sources for "+dependency.getId()+":"+dependency.getClassifier()+" at "+dependency.getId() + ":" + classifier);
}
-
- if ( !unavailableSourcesCache.containsKey( dependency.getId() + ":" + classifier ) )
+
+ if ( !unavailableArtifactsCache.containsKey( dependency.getId() + ":" + classifier ) )
{
- // source artifact: use the "sources" classifier added by the source plugin
- Artifact sourceArtifact = IdeUtils.resolveArtifactWithClassifier( dependency.getGroupId(), dependency
+ Artifact artifact = IdeUtils.resolveArtifactWithClassifier( dependency.getGroupId(), dependency
.getArtifactId(), dependency.getVersion(), classifier, localRepository, artifactResolver, //$NON-NLS-1$
- artifactFactory, remoteRepos,
- getLog() );
- if ( sourceArtifact.isResolved() )
- {
- dependency.setSourceAttachment( sourceArtifact.getFile() );
- }
- else
- {
- unavailableSourcesCache.put( dependency.getId() + ":" + classifier, Boolean.TRUE.toString() );
- // @todo also report deps without a source attachment but with a javadoc one?
- missingSourceDependencies.add( dependency );
- }
-
- }
-
- // @todo we should probably not make source/javadocs exclusive
- if ( dependency.getSourceAttachment() == null )
- {
- if ( !unavailableSourcesCache.containsKey( dependency.getId() + ":javadoc" ) )
+ artifactFactory, remoteRepos, getLog() );
+ if ( artifact.isResolved() )
{
- // try using a plain javadoc jar if the source jar is not available
- Artifact javadocArtifact = IdeUtils
- .resolveArtifactWithClassifier( dependency.getGroupId(), dependency.getArtifactId(), dependency
- .getVersion(), "javadoc", localRepository, artifactResolver, //$NON-NLS-1$
- artifactFactory, remoteRepos, getLog() );
-
- if ( javadocArtifact.isResolved() )
+ if ( "sources".equals( classifier ) )
{
- dependency.setJavadocAttachment( javadocArtifact.getFile() );
+ dependency.setSourceAttachment( artifact.getFile() );
+ }
+ else if ( "javadoc".equals( classifier ) )
+ {
+ dependency.setJavadocAttachment( artifact.getFile() );
}
else
{
- unavailableSourcesCache.put( dependency.getId() + ":javadoc", Boolean.TRUE.toString() );
+ unavailableArtifactsCache.put( dependency.getId() + ":" + classifier, Boolean.TRUE.toString() );
+ // add the dependencies to the list
+ // of those lacking the required
+ // artifact
+ missingClassifierDependencies.add( dependency );
}
}
}
}
- FileOutputStream fos = null;
- try
- {
- fos = new FileOutputStream( unavailableSourcesTmpFile );
- unavailableSourcesCache.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 );
- }
+ // return the list of dependencies missing the required artifact
+ return missingClassifierDependencies;
}
/**
* Output a message with the list of missing dependencies and info on how turn download on if it was disabled.
*/
- private void reportMissingSources()
+ private void reportMissingArtifacts()
{
- if ( missingSourceDependencies.isEmpty() )
- {
- return;
- }
-
StringBuffer msg = new StringBuffer();
- if ( getDownloadSources() )
+ if ( !missingSourceDependencies.isEmpty() )
{
- msg.append( Messages.getString( "sourcesnotavailable" ) ); //$NON-NLS-1$
- }
- else
- {
- msg.append( Messages.getString( "sourcesnotdownloaded" ) ); //$NON-NLS-1$
+ if ( getDownloadSources() )
+ {
+ msg.append( Messages.getString( "sourcesnotavailable" ) ); //$NON-NLS-1$
+ }
+ else
+ {
+ msg.append( Messages.getString( "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( "\n" ); //$NON-NLS-1$
}
- for ( Iterator it = missingSourceDependencies.iterator(); it.hasNext(); )
+ if ( !missingJavadocDependencies.isEmpty() )
{
- IdeDependency art = (IdeDependency) it.next();
- msg.append( Messages.getString( "sourcesmissingitem", art.getId() ) ); //$NON-NLS-1$
- }
- msg.append( "\n" ); //$NON-NLS-1$
+ if ( getDownloadJavadoc() )
+ {
+ msg.append( Messages.getString( "javadocnotavailable" ) ); //$NON-NLS-1$
+ }
+ else
+ {
+ msg.append( Messages.getString( "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( "\n" ); //$NON-NLS-1$
+ }
getLog().info( msg ); //$NON-NLS-1$
-
}
-
}
Modified: maven/plugins/branches/maven-eclipse-plugin-MECLIPSE-292/src/main/resources/org/apache/maven/plugin/ide/messages.properties
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-eclipse-plugin-MECLIPSE-292/src/main/resources/org/apache/maven/plugin/ide/messages.properties?view=diff&rev=554214&r1=554213&r2=554214
==============================================================================
--- maven/plugins/branches/maven-eclipse-plugin-MECLIPSE-292/src/main/resources/org/apache/maven/plugin/ide/messages.properties (original)
+++ maven/plugins/branches/maven-eclipse-plugin-MECLIPSE-292/src/main/resources/org/apache/maven/plugin/ide/messages.properties Sat Jul 7 07:49:46 2007
@@ -1,6 +1,9 @@
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 -DdownloadJavadoc=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}