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/08 03:25:13 UTC
svn commit: r554290 - in /maven/plugins/trunk/maven-eclipse-plugin/src:
main/java/org/apache/maven/plugin/eclipse/
main/java/org/apache/maven/plugin/ide/
main/resources/org/apache/maven/plugin/ide/ site/apt/examples/ site/fml/
test/java/org/apache/mave...
Author: brianf
Date: Sat Jul 7 18:25:12 2007
New Revision: 554290
URL: http://svn.apache.org/viewvc?view=rev&rev=554290
Log:
Applied patches for MECLIPSE-292 to allow javadocs to be downloaded
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/main/resources/org/apache/maven/plugin/ide/messages.properties
maven/plugins/trunk/maven-eclipse-plugin/src/site/apt/examples/attach-library-sources.apt
maven/plugins/trunk/maven-eclipse-plugin/src/site/fml/faq.fml
maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginTest.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=554290&r1=554289&r2=554290
==============================================================================
--- 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 Sat Jul 7 18:25:12 2007
@@ -226,7 +226,7 @@
private List classpathContainers;
/**
- * Enables/disables the downloading of source attachments. Defaults to false.
+ * Enables/disables the downloading of source attachments. Defaults to false. DEPRECATED - use downloadSources
*
* @parameter expression="${eclipse.downloadSources}"
* @deprecated use downloadSources
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=554290&r1=554289&r2=554290
==============================================================================
--- 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 Sat Jul 7 18:25:12 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="${downloadJavadocs}"
+ */
+ protected boolean downloadJavadocs;
+
+ /**
* Plexus logger needed for debugging manual artifact resolution.
*/
private Logger logger;
@@ -331,7 +346,28 @@
}
/**
+ * Getter for <code>downloadJavadocs</code>.
+ *
+ * @return Returns the downloadJavadocs.
+ */
+ public boolean getDownloadJavadocs()
+ {
+ return this.downloadJavadocs;
+ }
+
+ /**
+ * Setter for <code>downloadJavadocs</code>.
+ *
+ * @param downloadJavadocs The downloadJavadocs to set.
+ */
+ public void setDownloadJavadocs( boolean downloadJavadoc )
+ {
+ this.downloadJavadocs = 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", getDownloadJavadocs(),
+ 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 ( getDownloadJavadocs() )
+ {
+ 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/trunk/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/ide/messages.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/ide/messages.properties?view=diff&rev=554290&r1=554289&r2=554290
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/ide/messages.properties (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/ide/messages.properties Sat Jul 7 18:25:12 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}
Modified: maven/plugins/trunk/maven-eclipse-plugin/src/site/apt/examples/attach-library-sources.apt
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/site/apt/examples/attach-library-sources.apt?view=diff&rev=554290&r1=554289&r2=554290
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/site/apt/examples/attach-library-sources.apt (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/site/apt/examples/attach-library-sources.apt Sat Jul 7 18:25:12 2007
@@ -3,20 +3,20 @@
------
Edwin Punzalan
------
- 14 July 2006
+ 7 July 2007
------
-Attach Library Sources
+Attach Library Sources and Javadocs
Artifacts with sources deployed can be attached to Eclipse libraries using
- <<<downloadSources>>>. The sources of the libraries <must> exist in the
+ <<<downloadSources>>>. Javadocs may be attached using <<<downloadJavadocs>>> The sources and javadocs of the libraries <must> exist in the
repository so that the plugin can download it and attach it.
The following example shows how to do this in the command-line:
+-----
-mvn eclipse:eclipse -DdownloadSources=true
+mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true
+-----
or in your pom.xml:
@@ -33,6 +33,7 @@
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<downloadSources>true</downloadSources>
+ <downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
[...]
Modified: maven/plugins/trunk/maven-eclipse-plugin/src/site/fml/faq.fml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/site/fml/faq.fml?view=diff&rev=554290&r1=554289&r2=554290
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/site/fml/faq.fml (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/site/fml/faq.fml Sat Jul 7 18:25:12 2007
@@ -20,25 +20,9 @@
</answer>
</faq>
<faq id="import-javadoc">
- <question>Can I make the Eclipse plugin to download and to attach javadocs to my libraries?</question>
+ <question>Can I make the Eclipse plugin download and attach javadocs to my libraries?</question>
<answer>
- <p>Quoting what Fabrizio said in the mailing list...</p>
- <i>
- <p>"The current revision in svn of the Eclipse plugin (which is expected
- to be released as soon as an usable wtp 1.0.1 build will be out) has
- support for javadoc attachments, as an alternative to source jars."</p>
-
- <p>"When using the downloadSources flag if a source jar is not found the
- plugin will look for a javadoc jar. This is expecially useful for non
- open source projects and when used with Eclipse 3.2 (in Eclipse 3.2 M4
- javadoc view and editor tooltips also work with javadoc archives)."</p>
-
- <p>"I didn't find useful to have both sources and javadocs attached, since
- javadocs are automatically extracted by Eclipse: if you think this
- should be needed please post an enhancement request in Jira with the
- reasons... "</p>
- </i>
- <p>To go the the mailing list thread of this topic, click <a href="http://www.nabble.com/forum/ViewPost.jtp?post=2370602&framed=y">here</a></p>
+ <p>As of version 2.4, there is a new flag, downloadJavadocs that behaves exactly like downloadSources except for javadocs. See more information here: <a href="examples/attach-library-sources.html">Attach Library Sources</a>. </p>
</answer>
</faq>
</part>
Modified: maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginTest.java?view=diff&rev=554290&r1=554289&r2=554290
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginTest.java (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginTest.java Sat Jul 7 18:25:12 2007
@@ -358,4 +358,12 @@
{
testProject( "project-33" );
}*/
+
+
+ /*TODO: Add a test for downloadJavadocs. Currently, eclipse doesn't support having variables in the javadoc
+ * path. This means that the expected .classpath can't match the final result as the result will
+ * have the absolute path to the user's local repo.
+ */
+
+
}