[ http://jira.codehaus.org/browse/MECLIPSE-221?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_86076 ]
Bulent Erdemir commented on MECLIPSE-221: ----------------------------------------- Here's a very ugly patch to fix this for the users who desparately need it. This patch also fixes the global settings.xml file not used problem in MECLIPSE-2261 by specifying a hard coded global settings.xml file (change the global settings file to the path to your installation). Regards, Bulent Erdemir Index: C:/dev/projects/maven/m2eclipse/org.maven.ide.eclipse/src/org/maven/ide/eclipse/embedder/EmbedderFactory.java =================================================================== --- C:/dev/projects/maven/m2eclipse/org.maven.ide.eclipse/src/org/maven/ide/eclipse/embedder/EmbedderFactory.java (revision 179) +++ C:/dev/projects/maven/m2eclipse/org.maven.ide.eclipse/src/org/maven/ide/eclipse/embedder/EmbedderFactory.java (working copy) @@ -20,6 +20,8 @@ * under the License. */ +import java.io.File; + import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.embedder.ContainerCustomizer; import org.apache.maven.embedder.DefaultMavenEmbedRequest; @@ -40,6 +42,10 @@ MavenEmbedRequest request = new DefaultMavenEmbedRequest(); request.setConfigurationCustomizer(customizer); + + File gsFile = new File("c:/dev/tools/maven/conf/settings.xml"); + logger.info("Hoba.Loading global settings from " + gsFile.getAbsolutePath()); + request.setGlobalSettingsFile(gsFile); ClassLoader loader = Thread.currentThread().getContextClassLoader(); Index: C:/dev/projects/maven/m2eclipse/org.maven.ide.eclipse/src/org/maven/ide/eclipse/embedder/ClassPathResolver.java =================================================================== --- C:/dev/projects/maven/m2eclipse/org.maven.ide.eclipse/src/org/maven/ide/eclipse/embedder/ClassPathResolver.java (revision 179) +++ C:/dev/projects/maven/m2eclipse/org.maven.ide.eclipse/src/org/maven/ide/eclipse/embedder/ClassPathResolver.java (working copy) @@ -145,8 +145,9 @@ Path srcPath = materializeArtifactPath(embedder, mavenProject, a, "java-source", "sources", downloadSources, monitor); IClasspathAttribute[] attributes = new IClasspathAttribute[0]; - if(srcPath == null) { // no need to search for javadoc if we have source code - Path javadocPath = materializeArtifactPath(embedder, mavenProject, a, "java-doc", "javadoc", downloadJavadoc, monitor); + //if(srcPath == null) { // no need to search for javadoc if we have source code + //Path javadocPath = materializeArtifactPath(embedder, mavenProject, a, "java-doc", "javadoc", downloadJavadoc, monitor); + Path javadocPath = materializeArtifactPathJavadoc(embedder, mavenProject, a, "javadoc", "javadoc", downloadJavadoc, monitor); String javaDocUrl = null; if(javadocPath != null) { javaDocUrl = Maven2ClasspathContainerInitializer.getJavaDocUrl(javadocPath.toString()); @@ -157,7 +158,7 @@ attributes = new IClasspathAttribute[] {JavaCore.newClasspathAttribute( IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, javaDocUrl)}; } - } + //} libraryEntries.add(JavaCore.newLibraryEntry(new Path(artifactLocation), srcPath, null, new IAccessRule[0], attributes, false /*not exported*/)); @@ -233,7 +234,37 @@ } return null; } + + // type = "javadoc" + private Path materializeArtifactPathJavadoc(MavenEmbedder embedder, MavenProject mavenProject, Artifact a, String type, + String suffix, boolean download, IProgressMonitor monitor) throws Exception { + String artifactLocation = a.getFile().getAbsolutePath(); + // artifactLocation ends on '.jar' or '.zip' + //File file = new File(artifactLocation.substring(0, artifactLocation.length() - 4) + "-" + suffix + ".jar"); + File file = new File(artifactLocation.substring(0, artifactLocation.length() - 4) + "-" + type + "." + suffix); + if(file.exists()) { + // XXX ugly hack to do not download any artifacts + return new Path(file.getAbsolutePath()); + } else if(download) { + monitor.beginTask("Resolve " + type + " " + a.getId(), IProgressMonitor.UNKNOWN); + try { + Artifact f = embedder.createArtifactWithClassifier(a.getGroupId(), a.getArtifactId(), a.getVersion(), + type, suffix); + if(f != null) { + embedder.resolve(f, mavenProject.getRemoteArtifactRepositories(), embedder.getLocalRepository()); + return new Path(f.getFile().getAbsolutePath()); + } + } catch(AbstractArtifactResolutionException ex) { + String name = ex.getGroupId() + ":" + ex.getArtifactId() + "-" + ex.getVersion() + "." + ex.getType(); + console.logError(ex.getOriginalMessage() + " " + name); + } finally { + monitor.done(); + } + } + return null; + } + private String getJavaDocUrl(String artifactLocation, IProgressMonitor monitor) throws CoreException { // guess the javadoc url from the project url in the artifact's pom.xml File file = new File(artifactLocation.substring(0, artifactLocation.length()-4) + ".pom"); @@ -278,6 +309,7 @@ request.setPomFile(pomFile.getAbsolutePath()); request.setBaseDirectory(pomFile.getParentFile()); request.setTransferListener(new TransferListenerAdapter(monitor, console, indexManager)); + request.setSettingsFile("c:/dev/tools/maven/conf/settings.xml"); MavenExecutionResult result = mavenEmbedder.readProjectWithDependencies(request); Index: C:/dev/projects/maven/m2eclipse/org.maven.ide.eclipse/META-INF/MANIFEST.MF =================================================================== --- C:/dev/projects/maven/m2eclipse/org.maven.ide.eclipse/META-INF/MANIFEST.MF (revision 179) +++ C:/dev/projects/maven/m2eclipse/org.maven.ide.eclipse/META-INF/MANIFEST.MF (working copy) @@ -2,7 +2,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: Maven 2.0 integration Bundle-SymbolicName: org.maven.ide.eclipse; singleton:=true -Bundle-Version: 0.0.10 +Bundle-Version: 0.0.10.1 Bundle-Activator: org.maven.ide.eclipse.Maven2Plugin Bundle-Vendor: maven.org Bundle-Localization: plugin > Javadoc's for dependencies are not downloaded correctly (name incorrently > specified) > ------------------------------------------------------------------------------------ > > Key: MECLIPSE-221 > URL: http://jira.codehaus.org/browse/MECLIPSE-221 > Project: Maven 2.x Eclipse Plugin > Issue Type: Bug > Reporter: Bulent Erdemir > > Hi, > Open the preferences for maven and enable "Download artifact javadoc". Then > create a basic pom.xml and add a dependency to commons-lang version 2.0. Like > below: > <?xml version="1.0" encoding="UTF-8"?> > <project xmlns="http://maven.apache.org/POM/4.0.0" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 > http://maven.apache.org/maven-v4_0_0.xsd"> > <modelVersion>4.0.0</modelVersion> > <groupId>sil1</groupId> > <artifactId>sil1</artifactId> > <version>0.0.1</version> > <dependencies> > <dependency> > <groupId>commons-lang</groupId> > <artifactId>commons-lang</artifactId> > <version>2.2</version> > </dependency> > </dependencies> > </project> > Then issue mvn compile. So that maven downloads the artifacts. > maven downloads the pom, the artifact itself. But not the javadoc. Because > the repository has the file named "commons-lang-2.2-javadoc.jar " for the > javadoc, however, maven searches for a file named > "commons-lang-2.2-javadoc.java-doc". > So, the plugin needs to be modified to search for the right file name for > javadoc retrieval. > Bulent Erdemir -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira