Hi Stephane, Since you did this commit we cannot build the eclipse plugin.
There are several problems in your code : - MavenConstants.PROXY_LOGINHOST, MavenConstants.PROXY_LOGINDOMAIN and HttpUtils.setMeterType( meterType ) don't exist - Your package is org.apache.maven.eclipse but your directory structure is org/maven/eclipse. Personaly, I prefer org.apache.maven.plugin.eclipse - The type org.apache.maven.project.Dependency cannot be resolved. You must add maven-model in your dependencies. Can you fix these errors please ? arnaud On 1/13/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Author: snicoll > Date: Fri Jan 13 14:40:30 2006 > New Revision: 368890 > > URL: http://svn.apache.org/viewcvs?rev=368890&view=rev > Log: > MPECLIPSE-60: Now trying to download java sources archives from the remote > repositories. > > Added: > maven/maven-1/plugins/trunk/eclipse/src/main/ > maven/maven-1/plugins/trunk/eclipse/src/main/org/ > maven/maven-1/plugins/trunk/eclipse/src/main/org/maven/ > maven/maven-1/plugins/trunk/eclipse/src/main/org/maven/eclipse/ > > maven/maven-1/plugins/trunk/eclipse/src/main/org/maven/eclipse/JavaSourcesDownloader.java > (with props) > Modified: > maven/maven-1/plugins/trunk/eclipse/plugin.jelly > maven/maven-1/plugins/trunk/eclipse/plugin.properties > maven/maven-1/plugins/trunk/eclipse/project.xml > maven/maven-1/plugins/trunk/eclipse/xdocs/changes.xml > maven/maven-1/plugins/trunk/eclipse/xdocs/index.xml > maven/maven-1/plugins/trunk/eclipse/xdocs/properties.xml > > Modified: maven/maven-1/plugins/trunk/eclipse/plugin.jelly > URL: > http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/eclipse/plugin.jelly?rev=368890&r1=368889&r2=368890&view=diff > > ============================================================================== > --- maven/maven-1/plugins/trunk/eclipse/plugin.jelly (original) > +++ maven/maven-1/plugins/trunk/eclipse/plugin.jelly Fri Jan 13 14:40:30 > 2006 > @@ -17,9 +17,14 @@ > */ > --> > <project xmlns:j="jelly:core" xmlns:ant="jelly:ant" > xmlns:util="jelly:util" xmlns:define="jelly:define" > - xmlns:maven="jelly:maven"> > + xmlns:maven="jelly:maven" xmlns:eclipse="eclipse"> > + > + <define:taglib uri="eclipse"> > + <define:jellybean > + name="download-sources" > + className="org.apache.maven.eclipse.JavaSourcesDownloader" > + method="downloadJavaSources"/> > > - <define:taglib uri="eclipse"> > <define:tag name="write-classpath-entry"> > <maven:param-check value="${groupId}" fail="true" > message="'groupId' must be specified" /> > <maven:param-check value="${artifactId}" fail="true" > message="'artifactId' must be specified" /> > @@ -30,6 +35,17 @@ > <j:if test='${relativePathCheck == "X"}'> > <j:set var="relativePath" > value="${groupId}/jars/${artifactId}-${version}.jar" /> > </j:if> > + > + <!-- download the source from the remote repository if necessary > --> > + <j:if test="${maven.eclipse.src.download}"> > + <eclipse:download-sources > + project="${pom}" > + groupId="${groupId}" > + artifactId="${artifactId}" > + version="${version}" > + /> > + </j:if> > + > <!-- > should be (m1 repo layout): > ${groupId}/java-sources/${artifactId}-${version}-sources.jar > > Modified: maven/maven-1/plugins/trunk/eclipse/plugin.properties > URL: > http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/eclipse/plugin.properties?rev=368890&r1=368889&r2=368890&view=diff > > ============================================================================== > --- maven/maven-1/plugins/trunk/eclipse/plugin.properties (original) > +++ maven/maven-1/plugins/trunk/eclipse/plugin.properties Fri Jan 13 > 14:40:30 2006 > @@ -26,5 +26,6 @@ > maven.eclipse.goals = plugins > maven.gen.src=${maven.build.dir}/generated-sources > maven.eclipse.src.extension = zip > +maven.eclipse.src.download = true > maven.eclipse.resources.addtoclasspath=false > maven.eclipse.servletapilist=javax.servlet:servlet-api > ,servletapi:servletapi,geronimo-spec:geronimo-spec-servlet > > Modified: maven/maven-1/plugins/trunk/eclipse/project.xml > URL: > http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/eclipse/project.xml?rev=368890&r1=368889&r2=368890&view=diff > > ============================================================================== > --- maven/maven-1/plugins/trunk/eclipse/project.xml (original) > +++ maven/maven-1/plugins/trunk/eclipse/project.xml Fri Jan 13 14:40:30 > 2006 > @@ -116,5 +116,47 @@ > </roles> > <timezone>+1</timezone> > </developer> > + <developer> > + <name>Stephane Nicoll</name> > + <id>snicoll</id> > + <email>[EMAIL PROTECTED]</email> > + <organization>ASF</organization> > + <roles> > + <role>Java Developer</role> > + </roles> > + <timezone>+1</timezone> > + </developer> > </developers> > + <dependencies> > + <dependency> > + <groupId>maven</groupId> > + <artifactId>maven</artifactId> > + <version>1.0.2</version> > + </dependency> > + <dependency> > + <groupId>commons-logging</groupId> > + <artifactId>commons-logging</artifactId> > + <version>1.0.4</version> > + <properties> > + <comment>This library is already loaded by maven's core. Be > careful to use the same version number as in the core.</comment> > + </properties> > + </dependency> > + <dependency> > + <groupId>commons-lang</groupId> > + <artifactId>commons-lang</artifactId> > + <version>2.0</version> > + <type>jar</type> > + <properties> > + <comment>This library is already loaded by maven's core. Be > careful to use the same version number as in the core.</comment> > + </properties> > + </dependency> > + <dependency> > + <groupId>commons-jelly</groupId> > + <artifactId>commons-jelly</artifactId> > + <version>1.0</version> > + <properties> > + <comment>This library is already loaded by maven's core. Be > careful to use the same version number as in the core.</comment> > + </properties> > + </dependency> > + </dependencies> > </project> > > Added: > maven/maven-1/plugins/trunk/eclipse/src/main/org/maven/eclipse/JavaSourcesDownloader.java > URL: > http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/eclipse/src/main/org/maven/eclipse/JavaSourcesDownloader.java?rev=368890&view=auto > > ============================================================================== > --- > maven/maven-1/plugins/trunk/eclipse/src/main/org/maven/eclipse/JavaSourcesDownloader.java > (added) > +++ > maven/maven-1/plugins/trunk/eclipse/src/main/org/maven/eclipse/JavaSourcesDownloader.java > Fri Jan 13 14:40:30 2006 > @@ -0,0 +1,279 @@ > +package org.apache.maven.eclipse; > + > +import org.apache.commons.lang.StringUtils; > +import org.apache.commons.logging.Log; > +import org.apache.commons.logging.LogFactory; > +import org.apache.maven.AbstractMavenComponent; > +import org.apache.maven.MavenConstants; > +import org.apache.maven.project.Dependency; > +import org.apache.maven.project.Project; > +import org.apache.maven.util.HttpUtils; > + > +import java.io.File; > +import java.io.FileNotFoundException; > +import java.util.Iterator; > + > +/* ==================================================================== > + * Copyright 2001-2004 The Apache Software Foundation. > + * > + * Licensed under the Apache License, Version 2.0 (the "License"); > + * you may not use this file except in compliance with the License. > + * You may obtain a copy of the License at > + * > + * http://www.apache.org/licenses/LICENSE-2.0 > + * > + * Unless required by applicable law or agreed to in writing, software > + * distributed under the License is distributed on an "AS IS" BASIS, > + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or > implied. > + * See the License for the specific language governing permissions and > + * limitations under the License. > + * ==================================================================== > + */ > + > +/** > + * An helper class used to download java sources archives. > + * > + * @author <a href="[EMAIL PROTECTED]">Stephane Nicoll</a> > + * @version $Id$ > + */ > +public class JavaSourcesDownloader > + extends AbstractMavenComponent > +{ > + private static final Log log = LogFactory.getLog( > JavaSourcesDownloader.class ); > + > + private Project project; > + > + private String groupId; > + > + private String artifactId; > + > + private String version; > + > + > + public void downloadJavaSources() > + throws Exception > + { > + if (project == null) { > + throw new NullPointerException("project should be set."); > + } > + > + if (groupId == null) { > + throw new NullPointerException("groupId should be set."); > + } > + > + if (artifactId == null) { > + throw new NullPointerException("artifactId should be set."); > + } > + > + if (version == null) { > + throw new NullPointerException("version should be set."); > + } > + > + final String dependencyId = groupId + ":" + artifactId; > + Dependency dependency = project.getDependency( dependencyId ); > + if ( dependency == null ) > + { > + log.warn("Could not retrieve dependency object for[" + > dependencyId + "] - skipping" ); > + return; > + } > + > + String relativePath = buildRelativePath(); > + File localFile = new File( project.getContext().getMavenRepoLocal(), > relativePath ); > + if ( isSnapshot() ) > + { > + getRemoteArtifact( localFile, relativePath, dependency ); > + } > + else > + { > + if ( localFile.exists() ) > + { > + log.debug( "source for[" + groupId + ":" + artifactId + > ":" + version + > + "] is available in the local repository." ); > + return; > + } > + else > + { > + // download it > + getRemoteArtifact( localFile, relativePath, dependency ); > + } > + } > + } > + > + private String buildRelativePath() > + { > + StringBuffer sb = new StringBuffer(); > + sb.append( groupId ).append( "/java-sources/" ).append( > artifactId ).append( "-" ).append( version ).append( > + "-sources.jar" ); > + return sb.toString(); > + } > + > + private boolean isSnapshot() > + { > + return version.endsWith( "SNAPSHOT" ); > + } > + > + // Getters & Setters > + > + > + public Project getProject() > + { > + return project; > + } > + > + public void setProject( final Project project ) > + { > + this.project = project; > + } > + > + public String getGroupId() > + { > + return groupId; > + } > + > + public void setGroupId( final String groupId ) > + { > + this.groupId = groupId; > + } > + > + public String getArtifactId() > + { > + return artifactId; > + } > + > + public void setArtifactId( final String artifactId ) > + { > + this.artifactId = artifactId; > + } > + > + public String getVersion() > + { > + return version; > + } > + > + public void setVersion( final String version ) > + { > + this.version = version; > + } > + > + // Taken from maven core code in order to mimic the current behavior > + > + /** > + * Retrieve a <code>remoteFile</code> from the maven remote > repositories > + * and store it at <code>destinationFile</code> > + * > + * @param destinationFile the destination file in the local > repository > + * @param relativePath the relative path to the dependency > + * @return true if the retrieval succeeds, false otherwise. > + */ > + private boolean getRemoteArtifact( File destinationFile, String > relativePath, Dependency relatedDependency ) > + { > + > + // The directory structure for the project this dependency > belongs to > + // may not exists so attempt to create the project directory > structure > + // before attempting to download the dependency. > + File directory = destinationFile.getParentFile(); > + > + if ( !directory.exists() ) > + { > + directory.mkdirs(); > + } > + > + log.info( "Attempting to download sources for " + > relatedDependency.getArtifact()); > + > + boolean artifactFound = false; > + > + for ( Iterator i = > getProject().getContext().getMavenRepoRemote().iterator(); i.hasNext(); ) > + { > + String remoteRepo = (String) i.next(); > + > + if ( remoteRepo.endsWith( "/" ) ) > + { > + remoteRepo = remoteRepo.substring( 0, remoteRepo.length() > - 1 ); > + } > + > + // The username and password parameters are not being > + // used here. Those are the "" parameters you see below. > + String url = remoteRepo + "/" + relativePath; > + url = StringUtils.replace( url, "//", "/" ); > + > + if ( !url.startsWith( "file" ) ) > + { > + if ( url.startsWith( "https" ) ) > + { > + url = StringUtils.replace( url, "https:/", "https://" > ); > + } > + else > + { > + url = StringUtils.replace( url, "http:/", "http://" > ); > + } > + } > + log.debug("Trying to download source at " + url); > + > + // Attempt to retrieve the artifact and set the checksum if > retrieval > + // of the checksum file was successful. > + try > + { > + String loginHost = (String) > getProject().getContext().getVariable( MavenConstants.PROXY_LOGINHOST ); > + String loginDomain = (String) > getProject().getContext().getVariable( MavenConstants.PROXY_LOGINDOMAIN ); > + String meterType = (String) > getProject().getContext().getVariable( MavenConstants.DOWNLOAD_METER ); > + if ( meterType != null ) > + { > + HttpUtils.setMeterType( meterType ); > + } > + HttpUtils.getFile( url, destinationFile, false, true, > getProject().getContext().getProxyHost(), > + > getProject().getContext().getProxyPort(), > + > getProject().getContext().getProxyUserName(), > + > getProject().getContext().getProxyPassword(), loginHost, loginDomain, true > ); > + > + // Artifact was found, continue checking additional > remote repos (if any) > + // in case there is a newer version (i.e. snapshots) in > another repo > + artifactFound = true; > + > + if ( !isSnapshot() ) > + { > + break; > + } > + } > + catch ( FileNotFoundException e ) > + { > + // Multiple repositories may exist, and if the file is > not found > + // in just one of them, it's no problem, and we don't > want to > + // even print out an error. > + // if it's not found at all, artifactFound will be false, > and the > + // build _will_ break, and the user will get an error > message > + log.debug( "File not found on one of the repos", e ); > + } > + catch ( Exception e ) > + { > + // If there are additional remote repos, then ignore > exception > + // as artifact may be found in another remote repo. If > there > + // are no more remote repos to check and the artifact > wasn't found in > + // a previous remote repo, then artifactFound is false > indicating > + // that the artifact could not be found in any of the > remote repos > + // > + // arguably, we need to give the user better control > (another command- > + // line switch perhaps) of what to do in this case? Maven > already has > + // a command-line switch to work in offline mode, but > what about when > + // one of two or more remote repos is unavailable? There > may be multiple > + // remote repos for redundancy, in which case you > probably want the build > + // to continue. There may however be multiple remote > repos because some > + // artifacts are on one, and some are on another. In this > case, you may > + // want the build to break. > + // > + // print a warning, in any case, so user catches on to > mistyped > + // hostnames, or other snafus > + // FIXME: localize this message > + String[] parsedUrl = HttpUtils.parseUrl( url ); > + log.warn( "Error retrieving artifact from [" + > parsedUrl[2] + "]: " + e ); > + if ( parsedUrl[0] != null ) > + { > + log.debug( "Username was '" + parsedUrl[0] + "', > password hidden" ); > + } > + log.debug( "Error details", e ); > + } > + } > + > + return artifactFound; > + } > + > +} > > Propchange: > maven/maven-1/plugins/trunk/eclipse/src/main/org/maven/eclipse/JavaSourcesDownloader.java > > ------------------------------------------------------------------------------ > svn:eol-style = native > > Propchange: > maven/maven-1/plugins/trunk/eclipse/src/main/org/maven/eclipse/JavaSourcesDownloader.java > > ------------------------------------------------------------------------------ > svn:keywords = Author Date Id Revision > > Modified: maven/maven-1/plugins/trunk/eclipse/xdocs/changes.xml > URL: > http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/eclipse/xdocs/changes.xml?rev=368890&r1=368889&r2=368890&view=diff > > ============================================================================== > --- maven/maven-1/plugins/trunk/eclipse/xdocs/changes.xml (original) > +++ maven/maven-1/plugins/trunk/eclipse/xdocs/changes.xml Fri Jan 13 > 14:40:30 2006 > @@ -23,6 +23,9 @@ > <author email="[EMAIL PROTECTED]">dIon Gillard</author> > </properties> > <body> > + <release version="1.11" date="in SVN"> > + <action dev="snicoll" type="add" issue="MPECLIPSE-60">Now trying to > download java sources archives from the remote repositories.</action> > + </release> > <release version="1.10" date="2005-12-03"> > <action dev="carlos" type="fix">Moved test classpath before main so > test classpath resources override main ones</action> > <action dev="epugh" type="fix" > issue="MPECLIPSE-68">eclipse:add-maven-repo doesn't update correct Eclipse > property file for Eclipse 3.x</action> > > Modified: maven/maven-1/plugins/trunk/eclipse/xdocs/index.xml > URL: > http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/eclipse/xdocs/index.xml?rev=368890&r1=368889&r2=368890&view=diff > > ============================================================================== > --- maven/maven-1/plugins/trunk/eclipse/xdocs/index.xml (original) > +++ maven/maven-1/plugins/trunk/eclipse/xdocs/index.xml Fri Jan 13 > 14:40:30 2006 > @@ -75,14 +75,15 @@ > with debugging. > </p> > <p> > - The plugin will check if the file located at > <code>MAVEN_REPO${groupId}/java-sources/${artifactId}-${version}- > sources.jar</code> > - exists and will add it as a source attachment. > + The plugin is able to download sources archive at > <code>${groupId}/java-sources/${artifactId}-${version}-sources.jar</code> > + from the repository. This behavior can be disabled by configuring > the <code>maven.eclipse.src.download</code> property. > As an example, the source archive for the dependency > <code>MAVEN_REPO/eclipse/<em>jars</em>/eclipse-ui-3.0.0 > <em>.jar</em></code> > will be mapped to > <code>MAVEN_REPO/eclipse/<em>java-sources</em>/eclipse-ui-3.0.0<em>- > sources.jar</em></code> > </p> > <p> > For backward compatibility the plugin still accepts source archives > located at > - <code>MAVEN_REPO/${groupId}/src/${artifactId}-${version}.${ > maven.eclipse.src.extension}</code>. > + <code>MAVEN_REPO/${groupId}/src/${artifactId}-${version}.${ > maven.eclipse.src.extension}</code> but it won't > + download them from the repository. > </p> > </subsection> > <subsection name="Generated Source Code"> > > Modified: maven/maven-1/plugins/trunk/eclipse/xdocs/properties.xml > URL: > http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/eclipse/xdocs/properties.xml?rev=368890&r1=368889&r2=368890&view=diff > > ============================================================================== > --- maven/maven-1/plugins/trunk/eclipse/xdocs/properties.xml (original) > +++ maven/maven-1/plugins/trunk/eclipse/xdocs/properties.xml Fri Jan 13 > 14:40:30 2006 > @@ -135,6 +135,14 @@ > > <code>MAVEN_REPO${groupId}/java-sources/${artifactId}-${version}- > sources.jar</code> > </td> > </tr> > + <tr> > + <td>maven.eclipse.src.downlad</td> > + <td>Yes (default=<code>true</code>)</td> > + <td> > + Specify if java sources archives need to be downloaded from > the configured > + remote repositories. Defaults to true. > + </td> > + </tr> > </table> > <p> > Note that you will need to defined a <code>MAVEN_REPO</code> Java > > >
