Index: C:/dev/ws/openaw/maven-1.1-mx/src/java/org/apache/maven/MavenUtils.java =================================================================== --- C:/dev/ws/openaw/maven-1.1-mx/src/java/org/apache/maven/MavenUtils.java (revision 345138) +++ C:/dev/ws/openaw/maven-1.1-mx/src/java/org/apache/maven/MavenUtils.java (working copy) @@ -17,22 +17,6 @@ * ==================================================================== */ -import com.werken.forehead.ForeheadClassLoader; -import org.apache.commons.jelly.JellyContext; -import org.apache.commons.jelly.expression.CompositeExpression; -import org.apache.commons.jelly.expression.Expression; -import org.apache.commons.jelly.expression.jexl.JexlExpressionFactory; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.maven.jelly.JellyUtils; -import org.apache.maven.jelly.MavenJellyContext; -import org.apache.maven.project.Project; -import org.apache.tools.ant.DirectoryScanner; -import org.xml.sax.SAXException; -import org.codehaus.plexus.util.StringUtils; -import org.codehaus.plexus.util.CollectionUtils; - -import javax.xml.parsers.ParserConfigurationException; import java.beans.IntrospectionException; import java.io.File; import java.io.FileInputStream; @@ -55,6 +39,27 @@ import java.util.Set; import java.util.StringTokenizer; +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.commons.jelly.JellyContext; +import org.apache.commons.jelly.expression.CompositeExpression; +import org.apache.commons.jelly.expression.Expression; +import org.apache.commons.jelly.expression.jexl.JexlExpressionFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.maven.jelly.JellyUtils; +import org.apache.maven.jelly.MavenJellyContext; +import org.apache.maven.project.Dependency; +import org.apache.maven.project.Project; +import org.apache.maven.repository.GenericArtifact; +import org.apache.maven.verifier.DependencyVerifier; +import org.apache.tools.ant.DirectoryScanner; +import org.codehaus.plexus.util.CollectionUtils; +import org.codehaus.plexus.util.StringUtils; +import org.xml.sax.SAXException; + +import com.werken.forehead.ForeheadClassLoader; + /** * Utilities for reading maven project descriptors, profile descriptors and * workspace descriptors. @@ -207,9 +212,13 @@ File parentPom = new File( pomToExtend ); parentPom = parentPom.getCanonicalFile(); - if ( !parentPom.exists() ) + if ( !parentPom.exists() || pomToExtend.trim().endsWith("-SNAPSHOT.pom")) { - throw new FileNotFoundException( "Parent POM not found: " + parentPom ); + parentPom = tryToDownloadPOM(parentContext, project, pomToExtend); + if (parentPom == null || !parentPom.exists() ) + { + throw new FileNotFoundException( "Parent POM not found: " + parentPom ); + } } String parentPomPath = parentPom.getPath(); @@ -245,7 +254,49 @@ return project; } - /** + private static File tryToDownloadPOM(MavenJellyContext parentContext, Project project, String pomToExtend) { + //extract pattern from extend : ${maven.repo.local}/maven/poms/maven-1.0.1.pom + String POMS_SEP = File.separator+"poms"+File.separator; + pomToExtend = pomToExtend.trim(); + log.debug("Extending POM: "+pomToExtend); + int index = pomToExtend.lastIndexOf(POMS_SEP); + Dependency pomDep = new Dependency(); + if (index>0){ + String pomId = pomToExtend.substring(index+POMS_SEP.length(), pomToExtend.length()-".pom".length()); + String[] parts = pomId.split("-[0-9]+.*$"); + if (parts.length!=1){ + return null; + } + String pomArtifactId = parts[0]; + String pomVersion = pomId.substring(parts[0].length()+1); + + String groupId = pomToExtend.substring(0, index); + int startIndex = groupId.lastIndexOf(File.separator); + groupId = groupId.substring(startIndex+1); + pomDep.setId(groupId+":"+pomArtifactId); + pomDep.setArtifactId(pomArtifactId); + pomDep.setVersion(pomVersion); + pomDep.setGroupId(groupId); + pomDep.setType("pom"); + } else { + return null; + } + GenericArtifact artifact = new GenericArtifact(pomDep); + artifact.setPath(pomToExtend); + //create dir to download pom to + new File(pomToExtend).getParentFile().mkdirs(); + //download pom + String pomDesc = pomDep.getGroupId()+"/"+pomDep.getTypeDirectory()+"/"+pomDep.getArtifact(); + log.info("Trying to download parent POM: "+pomDesc); + boolean success = DependencyVerifier.getRemoteArtifact(parentContext, project, artifact); + if (!success){ + log.error("Download of parent POM failed: "+pomDesc); + return null; + } + return new File(pomToExtend); + } + + /** * This is currently used for the reactor but may be generally useful. * * @param directory the directory to scan for maven projects Index: C:/dev/ws/openaw/maven-1.1-mx/src/java/org/apache/maven/verifier/DependencyVerifier.java =================================================================== --- C:/dev/ws/openaw/maven-1.1-mx/src/java/org/apache/maven/verifier/DependencyVerifier.java (revision 345138) +++ C:/dev/ws/openaw/maven-1.1-mx/src/java/org/apache/maven/verifier/DependencyVerifier.java (working copy) @@ -17,6 +17,13 @@ * ==================================================================== */ +import java.io.File; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.maven.AbstractMavenComponent; @@ -36,14 +43,6 @@ import org.apache.maven.wagon.repository.Repository; import org.codehaus.plexus.util.StringUtils; -import java.io.File; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.HashSet; - /** * Make sure that everything that is required for the project to build * successfully is present. We will start by looking at the dependencies @@ -312,18 +311,21 @@ } } + public boolean getRemoteArtifact(Artifact artifact ){ + return getRemoteArtifact(getProject().getContext(), getProject(), artifact); + } + /** * Retrieve a remoteFile from the maven remote repositories * and store it at localFile + * @param context * @param artifact the artifact to retrieve from the repositories. * @return true if the retrieval succeeds, false otherwise. */ - private boolean getRemoteArtifact( Artifact artifact ) + public static boolean getRemoteArtifact(MavenJellyContext context, Project project, Artifact artifact ) { boolean artifactFound = false; - MavenJellyContext context = getProject().getContext(); - ProxyInfo proxyInfo = null; if ( context.getProxyHost() != null ) {