mirror of https://github.com/apache/maven.git
Refactored the bootstrapper to use a proper Model
and inheritance/dependency chains so repositories defined in models are used for metadata too. Previously they got lost because of all the cloning. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@420408 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9d9bfefdfa
commit
c7c6b5d7c7
|
@ -18,7 +18,7 @@ package org.apache.maven.bootstrap.installer;
|
|||
|
||||
import org.apache.maven.bootstrap.Bootstrap;
|
||||
import org.apache.maven.bootstrap.model.Dependency;
|
||||
import org.apache.maven.bootstrap.model.ModelReader;
|
||||
import org.apache.maven.bootstrap.model.Model;
|
||||
import org.apache.maven.bootstrap.util.FileUtils;
|
||||
import org.apache.maven.bootstrap.util.SimpleArgumentParser;
|
||||
import org.codehaus.plexus.util.Expand;
|
||||
|
@ -29,15 +29,11 @@ import org.codehaus.plexus.util.cli.Commandline;
|
|||
import org.codehaus.plexus.util.cli.WriterStreamConsumer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Main class for bootstrap module.
|
||||
|
@ -121,7 +117,7 @@ public class BootstrapInstaller
|
|||
|
||||
bootstrapper.buildProject( new File( basedir ), true );
|
||||
|
||||
ModelReader mavenCliModel = bootstrapper.getCachedModel( "org.apache.maven", "maven-cli" );
|
||||
Model mavenCliModel = bootstrapper.getCachedModel( "org.apache.maven", "maven-cli" );
|
||||
|
||||
File installation = new File( basedir, "bootstrap/target/installation" );
|
||||
createInstallation( installation, mavenCliModel );
|
||||
|
@ -225,7 +221,7 @@ public class BootstrapInstaller
|
|||
}
|
||||
}
|
||||
|
||||
private void createInstallation( File dir, ModelReader mavenCliModel )
|
||||
private void createInstallation( File dir, Model mavenCliModel )
|
||||
throws IOException, CommandLineException, InterruptedException
|
||||
{
|
||||
FileUtils.deleteDirectory( dir );
|
||||
|
@ -243,7 +239,7 @@ public class BootstrapInstaller
|
|||
File bootDirectory = new File( coreDirectory, "boot" );
|
||||
bootDirectory.mkdir();
|
||||
|
||||
for ( Iterator i = mavenCliModel.getDependencies().iterator(); i.hasNext(); )
|
||||
for ( Iterator i = mavenCliModel.getAllDependencies().iterator(); i.hasNext(); )
|
||||
{
|
||||
Dependency dep = (Dependency) i.next();
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.maven.bootstrap.download.OfflineArtifactResolver;
|
|||
import org.apache.maven.bootstrap.download.OnlineArtifactDownloader;
|
||||
import org.apache.maven.bootstrap.download.RepositoryMetadata;
|
||||
import org.apache.maven.bootstrap.model.Dependency;
|
||||
import org.apache.maven.bootstrap.model.Model;
|
||||
import org.apache.maven.bootstrap.model.ModelReader;
|
||||
import org.apache.maven.bootstrap.model.Plugin;
|
||||
import org.apache.maven.bootstrap.model.Repository;
|
||||
|
@ -35,7 +36,6 @@ import org.apache.maven.bootstrap.util.JarMojo;
|
|||
import org.apache.maven.bootstrap.util.SimpleArgumentParser;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
|
@ -58,6 +58,8 @@ import java.util.Properties;
|
|||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
/**
|
||||
* Main class for bootstrap module.
|
||||
*
|
||||
|
@ -136,7 +138,7 @@ public class Bootstrap
|
|||
String basedir = System.getProperty( "user.dir" );
|
||||
|
||||
File pom = new File( basedir, "pom.xml" );
|
||||
ModelReader reader = readModel( resolver, pom, true );
|
||||
Model reader = readModel( resolver, pom, true );
|
||||
File jar = buildProject( reader );
|
||||
|
||||
if ( "install".equals( goal ) )
|
||||
|
@ -144,7 +146,7 @@ public class Bootstrap
|
|||
install( reader, pom, jar );
|
||||
}
|
||||
|
||||
for ( Iterator i = reader.getDependencies().iterator(); i.hasNext(); )
|
||||
for ( Iterator i = reader.getAllDependencies().iterator(); i.hasNext(); )
|
||||
{
|
||||
Dependency dep = (Dependency) i.next();
|
||||
|
||||
|
@ -154,16 +156,16 @@ public class Bootstrap
|
|||
stats( fullStart, new Date() );
|
||||
}
|
||||
|
||||
private void install( ModelReader reader, File pom, File jar )
|
||||
private void install( Model model, File pom, File jar )
|
||||
throws Exception
|
||||
{
|
||||
String artifactId = reader.getArtifactId();
|
||||
String artifactId = model.getArtifactId();
|
||||
|
||||
String version = reader.getVersion();
|
||||
String version = model.getVersion();
|
||||
|
||||
String groupId = reader.getGroupId();
|
||||
String groupId = model.getGroupId();
|
||||
|
||||
String type = reader.getPackaging();
|
||||
String type = model.getPackaging();
|
||||
|
||||
Repository localRepository = resolver.getLocalRepository();
|
||||
File file = localRepository.getArtifactFile(
|
||||
|
@ -173,7 +175,7 @@ public class Bootstrap
|
|||
|
||||
FileUtils.copyFile( jar, file );
|
||||
|
||||
installPomFile( reader, pom );
|
||||
installPomFile( model, pom );
|
||||
|
||||
RepositoryMetadata metadata = new RepositoryMetadata();
|
||||
metadata.setReleaseVersion( version );
|
||||
|
@ -188,17 +190,17 @@ public class Bootstrap
|
|||
metadata.write( file );
|
||||
}
|
||||
|
||||
private void installPomFile( ModelReader reader, File source )
|
||||
private void installPomFile( Model model, File source )
|
||||
throws IOException
|
||||
{
|
||||
String artifactId = reader.getArtifactId();
|
||||
String artifactId = model.getArtifactId();
|
||||
|
||||
String version = reader.getVersion();
|
||||
String version = model.getVersion();
|
||||
|
||||
String groupId = reader.getGroupId();
|
||||
String groupId = model.getGroupId();
|
||||
|
||||
Repository localRepository = resolver.getLocalRepository();
|
||||
File pom = localRepository.getMetadataFile( groupId, artifactId, version, reader.getPackaging(),
|
||||
File pom = localRepository.getMetadataFile( groupId, artifactId, version, model.getPackaging(),
|
||||
artifactId + "-" + version + ".pom" );
|
||||
|
||||
System.out.println( "Installing POM: " + pom );
|
||||
|
@ -209,9 +211,9 @@ public class Bootstrap
|
|||
private void cacheModels( File basedir, ArtifactResolver resolver )
|
||||
throws IOException, ParserConfigurationException, SAXException
|
||||
{
|
||||
ModelReader reader = readModel( resolver, new File( basedir, "pom.xml" ), false );
|
||||
Model model = readModel( resolver, new File( basedir, "pom.xml" ), false );
|
||||
|
||||
for ( Iterator i = reader.getModules().iterator(); i.hasNext(); )
|
||||
for ( Iterator i = model.getModules().iterator(); i.hasNext(); )
|
||||
{
|
||||
String module = (String) i.next();
|
||||
|
||||
|
@ -232,19 +234,19 @@ public class Bootstrap
|
|||
|
||||
File file = new File( basedir, "pom.xml" );
|
||||
|
||||
ModelReader reader = readModel( resolver, file, true );
|
||||
Model model = readModel( resolver, file, true );
|
||||
|
||||
String key = reader.getGroupId() + ":" + reader.getArtifactId() + ":" + reader.getPackaging();
|
||||
String key = model.getGroupId() + ":" + model.getArtifactId() + ":" + model.getPackaging();
|
||||
if ( inProgress.contains( key ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( reader.getPackaging().equals( "pom" ) )
|
||||
if ( model.getPackaging().equals( "pom" ) )
|
||||
{
|
||||
if ( buildModules )
|
||||
{
|
||||
for ( Iterator i = reader.getModules().iterator(); i.hasNext(); )
|
||||
for ( Iterator i = model.getModules().iterator(); i.hasNext(); )
|
||||
{
|
||||
String module = (String) i.next();
|
||||
|
||||
|
@ -262,15 +264,15 @@ public class Bootstrap
|
|||
return;
|
||||
}
|
||||
|
||||
buildProject( reader );
|
||||
buildProject( model );
|
||||
|
||||
inProgress.remove( key );
|
||||
}
|
||||
|
||||
private File buildProject( ModelReader reader )
|
||||
private File buildProject( Model model )
|
||||
throws Exception
|
||||
{
|
||||
File basedir = reader.getProjectFile().getParentFile();
|
||||
File basedir = model.getProjectFile().getParentFile();
|
||||
|
||||
String sources = new File( basedir, "src/main/java" ).getAbsolutePath();
|
||||
|
||||
|
@ -283,11 +285,11 @@ public class Bootstrap
|
|||
|
||||
System.out.println( "Analysing dependencies ..." );
|
||||
|
||||
for ( Iterator i = reader.getDependencies().iterator(); i.hasNext(); )
|
||||
for ( Iterator i = model.getAllDependencies().iterator(); i.hasNext(); )
|
||||
{
|
||||
Dependency dep = (Dependency) i.next();
|
||||
|
||||
dep.getRepositories().addAll( reader.getRemoteRepositories() );
|
||||
dep.getRepositories().addAll( model.getRepositories() );
|
||||
|
||||
if ( modelFileCache.containsKey( dep.getId() ) )
|
||||
{
|
||||
|
@ -295,7 +297,7 @@ public class Bootstrap
|
|||
}
|
||||
}
|
||||
|
||||
resolver.downloadDependencies( reader.getDependencies() );
|
||||
resolver.downloadDependencies( model.getAllDependencies() );
|
||||
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
|
@ -312,11 +314,11 @@ public class Bootstrap
|
|||
// ----------------------------------------------------------------------
|
||||
|
||||
File generatedSourcesDirectory = null;
|
||||
if ( reader.getPlugins().containsKey( MODELLO_PLUGIN_ID ) )
|
||||
if ( model.getPlugins().containsKey( MODELLO_PLUGIN_ID ) )
|
||||
{
|
||||
Plugin plugin = (Plugin) reader.getPlugins().get( MODELLO_PLUGIN_ID );
|
||||
Plugin plugin = (Plugin) model.getPlugins().get( MODELLO_PLUGIN_ID );
|
||||
|
||||
File model = new File( basedir, (String) plugin.getConfiguration().get( "model" ) );
|
||||
File modelFile = new File( basedir, (String) plugin.getConfiguration().get( "model" ) );
|
||||
|
||||
System.out.println( "Model exists!" );
|
||||
|
||||
|
@ -337,10 +339,10 @@ public class Bootstrap
|
|||
Dependency dependency = plugin.asDependencyPom();
|
||||
resolver.downloadDependencies( Collections.singletonList( dependency ) );
|
||||
File artifactFile = resolver.getArtifactFile( dependency );
|
||||
ModelReader pluginReader = readModel( resolver, artifactFile, true );
|
||||
Model pluginReader = readModel( resolver, artifactFile, true );
|
||||
|
||||
List dependencies = new ArrayList();
|
||||
for ( Iterator i = pluginReader.getDependencies().iterator(); i.hasNext(); )
|
||||
for ( Iterator i = pluginReader.getAllDependencies().iterator(); i.hasNext(); )
|
||||
{
|
||||
Dependency d = (Dependency) i.next();
|
||||
if ( !d.getGroupId().equals( "org.apache.maven" ) )
|
||||
|
@ -353,11 +355,11 @@ public class Bootstrap
|
|||
|
||||
System.out.println( "Generating model bindings for version \'" + modelVersion + "\' from '" + model + "'" );
|
||||
|
||||
generateModelloSources( model.getAbsolutePath(), "java", generatedSourcesDirectory, modelVersion, "false",
|
||||
generateModelloSources( modelFile.getAbsolutePath(), "java", generatedSourcesDirectory, modelVersion, "false",
|
||||
classLoader );
|
||||
generateModelloSources( model.getAbsolutePath(), "xpp3-reader", generatedSourcesDirectory, modelVersion,
|
||||
generateModelloSources( modelFile.getAbsolutePath(), "xpp3-reader", generatedSourcesDirectory, modelVersion,
|
||||
"false", classLoader );
|
||||
generateModelloSources( model.getAbsolutePath(), "xpp3-writer", generatedSourcesDirectory, modelVersion,
|
||||
generateModelloSources( modelFile.getAbsolutePath(), "xpp3-writer", generatedSourcesDirectory, modelVersion,
|
||||
"false", classLoader );
|
||||
}
|
||||
|
||||
|
@ -367,7 +369,7 @@ public class Bootstrap
|
|||
|
||||
System.out.println( "Compiling sources ..." );
|
||||
|
||||
compile( reader.getDependencies(), sources, classes, null, generatedSourcesDirectory, Dependency.SCOPE_COMPILE,
|
||||
compile( model.getAllDependencies(), sources, classes, null, generatedSourcesDirectory, Dependency.SCOPE_COMPILE,
|
||||
resolver );
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -382,32 +384,32 @@ public class Bootstrap
|
|||
// Create JAR
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
File jarFile = createJar( new File( basedir, "pom.xml" ), classes, buildDir, reader );
|
||||
File jarFile = createJar( new File( basedir, "pom.xml" ), classes, buildDir, model );
|
||||
|
||||
System.out.println( "Packaging " + jarFile + " ..." );
|
||||
|
||||
resolver.addBuiltArtifact( reader.getGroupId(), reader.getArtifactId(), "jar", jarFile );
|
||||
resolver.addBuiltArtifact( model.getGroupId(), model.getArtifactId(), "jar", jarFile );
|
||||
|
||||
line();
|
||||
|
||||
return jarFile;
|
||||
}
|
||||
|
||||
private ModelReader readModel( ArtifactResolver resolver, File file, boolean resolveTransitiveDependencies )
|
||||
private Model readModel( ArtifactResolver resolver, File file, boolean resolveTransitiveDependencies )
|
||||
throws ParserConfigurationException, SAXException, IOException
|
||||
{
|
||||
ModelReader reader = new ModelReader( resolver, resolveTransitiveDependencies );
|
||||
|
||||
reader.parse( file );
|
||||
Model model = reader.parseModel( file, Collections.EMPTY_LIST );
|
||||
|
||||
resolver.addBuiltArtifact( reader.getGroupId(), reader.getArtifactId(), "pom", file );
|
||||
resolver.addBuiltArtifact( model.getGroupId(), model.getArtifactId(), "pom", file );
|
||||
|
||||
String id = reader.getGroupId() + ":" + reader.getArtifactId();
|
||||
String id = model.getGroupId() + ":" + model.getArtifactId();
|
||||
modelFileCache.put( id, file );
|
||||
|
||||
modelCache.put( id, reader );
|
||||
modelCache.put( id, model );
|
||||
|
||||
return reader;
|
||||
return model;
|
||||
}
|
||||
|
||||
private void line()
|
||||
|
@ -415,7 +417,7 @@ public class Bootstrap
|
|||
System.out.println( "------------------------------------------------------------------" );
|
||||
}
|
||||
|
||||
private File createJar( File pomFile, String classes, String buildDir, ModelReader reader )
|
||||
private File createJar( File pomFile, String classes, String buildDir, Model reader )
|
||||
throws Exception
|
||||
{
|
||||
JarMojo jarMojo = new JarMojo();
|
||||
|
@ -753,9 +755,9 @@ public class Bootstrap
|
|||
return cl;
|
||||
}
|
||||
|
||||
public ModelReader getCachedModel( String groupId, String artifactId )
|
||||
public Model getCachedModel( String groupId, String artifactId )
|
||||
{
|
||||
return (ModelReader) modelCache.get( groupId + ":" + artifactId );
|
||||
return (Model) modelCache.get( groupId + ":" + artifactId );
|
||||
}
|
||||
|
||||
public File getArtifactFile( Dependency dep )
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
|
||||
import org.apache.maven.bootstrap.model.Dependency;
|
||||
import org.apache.maven.bootstrap.model.Model;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2005 The Apache Software Foundation.
|
||||
|
@ -49,7 +50,7 @@ public class DownloadFailedException
|
|||
|
||||
for ( Iterator it = dep.getChain().iterator(); it.hasNext(); )
|
||||
{
|
||||
Dependency chainDep = (Dependency) it.next();
|
||||
Model chainDep = (Model) it.next();
|
||||
msg += "\n\t" + chainDep;
|
||||
repos.addAll( chainDep.getRepositories() );
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ package org.apache.maven.bootstrap.download;
|
|||
*/
|
||||
|
||||
import org.apache.maven.bootstrap.model.Dependency;
|
||||
import org.apache.maven.bootstrap.model.Model;
|
||||
import org.apache.maven.bootstrap.model.Repository;
|
||||
import org.apache.maven.bootstrap.util.FileUtils;
|
||||
import org.apache.maven.bootstrap.util.StringUtils;
|
||||
|
@ -129,7 +130,7 @@ public class OnlineArtifactDownloader
|
|||
|
||||
for ( Iterator i = dep.getChain().iterator(); i.hasNext(); )
|
||||
{
|
||||
repositories.addAll( ( (Dependency) i.next() ).getRepositories() );
|
||||
repositories.addAll( ( (Model) i.next() ).getRepositories() );
|
||||
}
|
||||
|
||||
for ( Iterator i = repositories.iterator(); i.hasNext(); )
|
||||
|
|
|
@ -16,8 +16,6 @@ package org.apache.maven.bootstrap.model;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -27,22 +25,14 @@ import java.util.Set;
|
|||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Dependency
|
||||
public class Dependency extends Model
|
||||
{
|
||||
private String id;
|
||||
|
||||
private String version;
|
||||
|
||||
private String url;
|
||||
|
||||
private String jar;
|
||||
|
||||
private String artifactId;
|
||||
|
||||
private String groupId;
|
||||
|
||||
private String type = "jar";
|
||||
|
||||
private String scope = SCOPE_COMPILE;
|
||||
|
||||
private String resolvedVersion;
|
||||
|
@ -57,23 +47,18 @@ public class Dependency
|
|||
|
||||
private Set exclusions = new HashSet();
|
||||
|
||||
private List chain;
|
||||
|
||||
private Collection repositories;
|
||||
|
||||
public Dependency( List chain )
|
||||
{
|
||||
this.chain = new ArrayList( chain );
|
||||
this.chain.add( this );
|
||||
super(chain);
|
||||
}
|
||||
|
||||
public Dependency( String groupId, String artifactId, String version, String type, List chain )
|
||||
{
|
||||
this( chain );
|
||||
this.version = version;
|
||||
this.artifactId = artifactId;
|
||||
this.groupId = groupId;
|
||||
this.type = type;
|
||||
setVersion( version );
|
||||
setArtifactId( artifactId );
|
||||
setGroupId( groupId );
|
||||
setType( type );
|
||||
}
|
||||
|
||||
public void setId( String id )
|
||||
|
@ -91,16 +76,6 @@ public class Dependency
|
|||
return id;
|
||||
}
|
||||
|
||||
public void setGroupId( String groupId )
|
||||
{
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public String getGroupId()
|
||||
{
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public String getArtifactDirectory()
|
||||
{
|
||||
if ( isValid( getGroupId() ) )
|
||||
|
@ -111,16 +86,6 @@ public class Dependency
|
|||
return getId();
|
||||
}
|
||||
|
||||
public String getArtifactId()
|
||||
{
|
||||
return artifactId;
|
||||
}
|
||||
|
||||
public void setArtifactId( String artifactId )
|
||||
{
|
||||
this.artifactId = artifactId;
|
||||
}
|
||||
|
||||
public String getArtifact()
|
||||
{
|
||||
// If the jar name has been explicty set then use that. This
|
||||
|
@ -152,16 +117,6 @@ public class Dependency
|
|||
return artifact;
|
||||
}
|
||||
|
||||
public void setVersion( String version )
|
||||
{
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getVersion()
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setJar( String jar )
|
||||
{
|
||||
// This is a check we need because of the jelly interpolation
|
||||
|
@ -202,12 +157,12 @@ public class Dependency
|
|||
|
||||
public String getType()
|
||||
{
|
||||
return type;
|
||||
return getPackaging();
|
||||
}
|
||||
|
||||
public void setType( String type )
|
||||
{
|
||||
this.type = type;
|
||||
setPackaging( type );
|
||||
}
|
||||
|
||||
private boolean isValid( String value )
|
||||
|
@ -216,61 +171,11 @@ public class Dependency
|
|||
|
||||
}
|
||||
|
||||
public Collection getRepositories()
|
||||
{
|
||||
if ( repositories == null )
|
||||
repositories = new ArrayList();
|
||||
|
||||
return repositories;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return getId() + ":" + getVersion() + ":" + getType();
|
||||
return "Dependency[" + getId() + ":" + getVersion() + ":" + getType() + "]";
|
||||
}
|
||||
|
||||
public int hashCode()
|
||||
{
|
||||
int result = 17;
|
||||
result = 37 * result + groupId.hashCode();
|
||||
result = 37 * result + artifactId.hashCode();
|
||||
result = 37 * result + type.hashCode();
|
||||
result = 37 * result + version.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean equals( Object o )
|
||||
{
|
||||
if ( o == this )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( !( o instanceof Dependency ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Dependency d = (Dependency) o;
|
||||
|
||||
if ( !d.getGroupId().equals( groupId ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ( !d.getArtifactId().equals( artifactId ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ( !d.getVersion().equals( version ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ( !d.getType().equals( type ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getConflictId()
|
||||
{
|
||||
|
@ -306,15 +211,10 @@ public class Dependency
|
|||
return exclusions;
|
||||
}
|
||||
|
||||
public List getChain()
|
||||
{
|
||||
return chain;
|
||||
}
|
||||
|
||||
public Dependency getPomDependency()
|
||||
{
|
||||
Dependency dep = new Dependency( groupId, artifactId, version, "pom", chain );
|
||||
dep.repositories = repositories;
|
||||
Dependency dep = new Dependency( getGroupId(), getArtifactId(), getVersion(), "pom", getChain() );
|
||||
dep.getRepositories().addAll( getRepositories() );
|
||||
return dep;
|
||||
}
|
||||
|
||||
|
@ -327,4 +227,16 @@ public class Dependency
|
|||
{
|
||||
return optional;
|
||||
}
|
||||
|
||||
public boolean equals( Object o )
|
||||
{
|
||||
if ( o instanceof Dependency )
|
||||
{
|
||||
return super.equals( o );
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,260 @@
|
|||
package org.apache.maven.bootstrap.model;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2005 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.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Represents a Model.
|
||||
*
|
||||
* @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a>
|
||||
*
|
||||
*/
|
||||
public class Model
|
||||
{
|
||||
private Map dependencies = new HashMap();
|
||||
|
||||
Map parentDependencies = new HashMap();
|
||||
|
||||
Map transitiveDependencies = new HashMap();
|
||||
|
||||
private Map plugins = new HashMap();
|
||||
|
||||
private String artifactId;
|
||||
|
||||
private String version;
|
||||
|
||||
private String groupId;
|
||||
|
||||
private String parentGroupId;
|
||||
|
||||
private String parentArtifactId;
|
||||
|
||||
private String parentVersion;
|
||||
|
||||
private String packaging = "jar";
|
||||
|
||||
private File pomFile;
|
||||
|
||||
private List modules = new ArrayList();
|
||||
|
||||
private List resources = new ArrayList();
|
||||
|
||||
private Set repositories = new HashSet();
|
||||
|
||||
Map managedDependencies = new HashMap();
|
||||
|
||||
private List chain;
|
||||
|
||||
public Model()
|
||||
{
|
||||
this.chain = new ArrayList();
|
||||
}
|
||||
|
||||
public Model( List chain )
|
||||
{
|
||||
this.chain = new ArrayList( chain );
|
||||
this.chain.add( this );
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return groupId + ":" + artifactId + ":" + packaging + ":" + version;
|
||||
}
|
||||
|
||||
public String getArtifactId()
|
||||
{
|
||||
return artifactId;
|
||||
}
|
||||
|
||||
public void setArtifactId( String artifactId )
|
||||
{
|
||||
this.artifactId = artifactId;
|
||||
}
|
||||
|
||||
public String getVersion()
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion( String version )
|
||||
{
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getGroupId()
|
||||
{
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId( String groupId )
|
||||
{
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public String getPackaging()
|
||||
{
|
||||
return packaging;
|
||||
}
|
||||
|
||||
public String getParentArtifactId()
|
||||
{
|
||||
return parentArtifactId;
|
||||
}
|
||||
|
||||
public void setParentArtifactId( String artifactId )
|
||||
{
|
||||
this.parentArtifactId = artifactId;
|
||||
}
|
||||
|
||||
public void setPackaging( String packaging )
|
||||
{
|
||||
this.packaging = packaging;
|
||||
}
|
||||
|
||||
public String getParentGroupId()
|
||||
{
|
||||
return parentGroupId;
|
||||
}
|
||||
|
||||
public void setParentGroupId( String groupId )
|
||||
{
|
||||
this.parentGroupId = groupId;
|
||||
}
|
||||
|
||||
public String getParentVersion()
|
||||
{
|
||||
return parentVersion;
|
||||
}
|
||||
|
||||
public void setParentVersion( String version )
|
||||
{
|
||||
this.parentVersion = version;
|
||||
}
|
||||
|
||||
public Map getPlugins()
|
||||
{
|
||||
return plugins;
|
||||
}
|
||||
|
||||
public List getModules()
|
||||
{
|
||||
return modules;
|
||||
}
|
||||
|
||||
public List getResources()
|
||||
{
|
||||
return resources;
|
||||
}
|
||||
|
||||
public File getProjectFile()
|
||||
{
|
||||
return pomFile;
|
||||
}
|
||||
|
||||
public void setPomFile( File file )
|
||||
{
|
||||
this.pomFile = file;
|
||||
}
|
||||
|
||||
public Set getRepositories()
|
||||
{
|
||||
return repositories;
|
||||
}
|
||||
|
||||
public Collection getManagedDependencies()
|
||||
{
|
||||
Map m = new HashMap();
|
||||
m.putAll( managedDependencies );
|
||||
return m.values();
|
||||
}
|
||||
|
||||
public Collection getAllDependencies()
|
||||
{
|
||||
Map m = new HashMap();
|
||||
m.putAll( transitiveDependencies );
|
||||
m.putAll( parentDependencies );
|
||||
m.putAll( dependencies );
|
||||
return m.values();
|
||||
}
|
||||
|
||||
public List getChain()
|
||||
{
|
||||
return chain;
|
||||
}
|
||||
|
||||
public Map getDependencies()
|
||||
{
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "Model[" + getId() + "]";
|
||||
}
|
||||
|
||||
public int hashCode()
|
||||
{
|
||||
int result = 17;
|
||||
result = 37 * result + groupId.hashCode();
|
||||
result = 37 * result + artifactId.hashCode();
|
||||
result = 37 * result + packaging.hashCode();
|
||||
result = 37 * result + version.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean equals( Object o )
|
||||
{
|
||||
if ( o == this )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( !( o instanceof Model ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Model d = (Model) o;
|
||||
|
||||
if ( !d.getGroupId().equals( groupId ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ( !d.getArtifactId().equals( artifactId ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ( !d.getVersion().equals( version ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ( !d.getPackaging().equals( packaging ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -17,22 +17,16 @@ package org.apache.maven.bootstrap.model;
|
|||
*/
|
||||
|
||||
import org.apache.maven.bootstrap.download.ArtifactResolver;
|
||||
import org.apache.maven.bootstrap.download.DownloadFailedException;
|
||||
import org.apache.maven.bootstrap.util.AbstractReader;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
|
@ -45,27 +39,7 @@ public class ModelReader
|
|||
{
|
||||
private int depth = 0;
|
||||
|
||||
private String artifactId;
|
||||
|
||||
private String version;
|
||||
|
||||
private String groupId;
|
||||
|
||||
private String packaging = "jar";
|
||||
|
||||
private String parentGroupId;
|
||||
|
||||
private String parentArtifactId;
|
||||
|
||||
private String parentVersion;
|
||||
|
||||
private Map dependencies = new HashMap();
|
||||
|
||||
private List repositories = new ArrayList();
|
||||
|
||||
private List resources = new ArrayList();
|
||||
|
||||
private Map managedDependencies = new HashMap();
|
||||
private Model model;
|
||||
|
||||
private Dependency currentDependency;
|
||||
|
||||
|
@ -87,12 +61,6 @@ public class ModelReader
|
|||
|
||||
private final ArtifactResolver resolver;
|
||||
|
||||
private static Set inProgress = new HashSet();
|
||||
|
||||
private Map parentDependencies = new HashMap();
|
||||
|
||||
private Map transitiveDependencies = new HashMap();
|
||||
|
||||
private boolean insideDependencyManagement = false;
|
||||
|
||||
private boolean insideReleases;
|
||||
|
@ -105,12 +73,8 @@ public class ModelReader
|
|||
|
||||
private final Set excluded;
|
||||
|
||||
private final List chain;
|
||||
|
||||
private final String inheritedScope;
|
||||
|
||||
private Map plugins = new HashMap();
|
||||
|
||||
private boolean insideConfiguration;
|
||||
|
||||
private boolean insideBuild;
|
||||
|
@ -119,15 +83,13 @@ public class ModelReader
|
|||
|
||||
private boolean insidePlugin;
|
||||
|
||||
private List modules = new ArrayList();
|
||||
|
||||
public ModelReader( ArtifactResolver resolver, boolean resolveTransitiveDependencies )
|
||||
{
|
||||
this( resolver, null, resolveTransitiveDependencies, Collections.EMPTY_SET, Collections.EMPTY_LIST );
|
||||
this( resolver, null, resolveTransitiveDependencies, Collections.EMPTY_SET );
|
||||
}
|
||||
|
||||
public ModelReader( ArtifactResolver resolver, String inheritedScope, boolean resolveTransitiveDependencies,
|
||||
Set excluded, List chain )
|
||||
Set excluded )
|
||||
{
|
||||
this.resolver = resolver;
|
||||
|
||||
|
@ -136,34 +98,17 @@ public class ModelReader
|
|||
this.excluded = excluded;
|
||||
|
||||
this.inheritedScope = inheritedScope;
|
||||
|
||||
this.chain = chain;
|
||||
}
|
||||
|
||||
public List getRemoteRepositories()
|
||||
public Model parseModel( File file, List chain )
|
||||
throws ParserConfigurationException, SAXException, IOException
|
||||
{
|
||||
return repositories;
|
||||
}
|
||||
this.model = new Model( chain );
|
||||
model.setPomFile( file );
|
||||
|
||||
public Collection getDependencies()
|
||||
{
|
||||
Map m = new HashMap();
|
||||
m.putAll( transitiveDependencies );
|
||||
m.putAll( parentDependencies );
|
||||
m.putAll( dependencies );
|
||||
return m.values();
|
||||
}
|
||||
super.parse( file );
|
||||
|
||||
public Collection getManagedDependencies()
|
||||
{
|
||||
Map m = new HashMap();
|
||||
m.putAll( managedDependencies );
|
||||
return m.values();
|
||||
}
|
||||
|
||||
public List getResources()
|
||||
{
|
||||
return resources;
|
||||
return model;
|
||||
}
|
||||
|
||||
public void startElement( String uri, String localName, String rawName, Attributes attributes )
|
||||
|
@ -180,9 +125,9 @@ public class ModelReader
|
|||
}
|
||||
else if ( rawName.equals( "dependency" ) )
|
||||
{
|
||||
List newChain =
|
||||
Collections.singletonList( new Dependency( groupId, artifactId, version, packaging, this.chain ) );
|
||||
currentDependency = new Dependency( newChain );
|
||||
// List newChain = Collections.singletonList( new Dependency( model.getGroupId(), model.getArtifactId(), model
|
||||
// .getVersion(), model.getPackaging(), this.chain ) );
|
||||
currentDependency = new Dependency( model.getChain() );
|
||||
|
||||
insideDependency = true;
|
||||
}
|
||||
|
@ -249,42 +194,42 @@ public class ModelReader
|
|||
// support both v3 <extend> and v4 <parent>
|
||||
if ( rawName.equals( "parent" ) )
|
||||
{
|
||||
if ( parentArtifactId == null || parentArtifactId.trim().length() == 0 )
|
||||
if ( model.getParentArtifactId() == null || model.getParentArtifactId().trim().length() == 0 )
|
||||
{
|
||||
throw new SAXException( "Missing required element in <parent>: artifactId." );
|
||||
}
|
||||
|
||||
if ( parentGroupId == null || parentGroupId.trim().length() == 0 )
|
||||
if ( model.getParentGroupId() == null || model.getParentGroupId().trim().length() == 0 )
|
||||
{
|
||||
throw new SAXException( "Missing required element in <parent>: groupId." );
|
||||
}
|
||||
|
||||
if ( parentVersion == null || parentVersion.trim().length() == 0 )
|
||||
if ( model.getParentVersion() == null || model.getParentVersion().trim().length() == 0 )
|
||||
{
|
||||
throw new SAXException( "Missing required element in <parent>: version." );
|
||||
}
|
||||
|
||||
if ( groupId == null )
|
||||
if ( model.getGroupId() == null )
|
||||
{
|
||||
groupId = parentGroupId;
|
||||
model.setGroupId( model.getParentGroupId() );
|
||||
}
|
||||
|
||||
if ( version == null )
|
||||
if ( model.getVersion() == null )
|
||||
{
|
||||
version = parentVersion;
|
||||
model.setVersion( model.getParentVersion() );
|
||||
}
|
||||
|
||||
// actually, these should be transtive (see MNG-77) - but some projects have circular deps that way
|
||||
ModelReader p = retrievePom( parentGroupId, parentArtifactId, parentVersion, inheritedScope, false,
|
||||
excluded, Collections.EMPTY_LIST );
|
||||
Model p = ProjectResolver.retrievePom( resolver, model.getParentGroupId(), model.getParentArtifactId(),
|
||||
model.getParentVersion(), inheritedScope, false, excluded, model.getChain() );//Collections.singletonList( model ) );
|
||||
|
||||
addDependencies( p.getDependencies(), parentDependencies, inheritedScope, excluded );
|
||||
ProjectResolver.addDependencies( p.getAllDependencies(), model.parentDependencies, inheritedScope, excluded );
|
||||
|
||||
addDependencies( p.getManagedDependencies(), managedDependencies, inheritedScope, Collections.EMPTY_SET );
|
||||
ProjectResolver.addDependencies( p.getManagedDependencies(), model.managedDependencies, inheritedScope, Collections.EMPTY_SET );
|
||||
|
||||
repositories.addAll( p.getRemoteRepositories() );
|
||||
model.getRepositories().addAll( p.getRepositories() );
|
||||
|
||||
resources.addAll( p.getResources() );
|
||||
model.getResources().addAll( p.getResources() );
|
||||
|
||||
insideParent = false;
|
||||
}
|
||||
|
@ -294,11 +239,11 @@ public class ModelReader
|
|||
|
||||
if ( insideDependencyManagement )
|
||||
{
|
||||
managedDependencies.put( currentDependency.getConflictId(), currentDependency );
|
||||
model.managedDependencies.put( currentDependency.getConflictId(), currentDependency );
|
||||
}
|
||||
else
|
||||
{
|
||||
dependencies.put( currentDependency.getConflictId(), currentDependency );
|
||||
model.getDependencies().put( currentDependency.getConflictId(), currentDependency );
|
||||
}
|
||||
}
|
||||
else if ( rawName.equals( "exclusion" ) )
|
||||
|
@ -312,19 +257,19 @@ public class ModelReader
|
|||
}
|
||||
else if ( rawName.equals( "resource" ) )
|
||||
{
|
||||
resources.add( currentResource );
|
||||
model.getResources().add( currentResource );
|
||||
|
||||
insideResource = false;
|
||||
}
|
||||
else if ( rawName.equals( "repository" ) )
|
||||
{
|
||||
repositories.add( currentRepository );
|
||||
model.getRepositories().add( currentRepository );
|
||||
|
||||
insideRepository = false;
|
||||
}
|
||||
else if ( rawName.equals( "plugin" ) )
|
||||
{
|
||||
plugins.put( currentPlugin.getId(), currentPlugin );
|
||||
model.getPlugins().put( currentPlugin.getId(), currentPlugin );
|
||||
|
||||
insidePlugin = false;
|
||||
}
|
||||
|
@ -334,21 +279,21 @@ public class ModelReader
|
|||
}
|
||||
else if ( rawName.equals( "module" ) )
|
||||
{
|
||||
modules.add( getBodyText() );
|
||||
model.getModules().add( getBodyText() );
|
||||
}
|
||||
else if ( insideParent )
|
||||
{
|
||||
if ( rawName.equals( "groupId" ) )
|
||||
{
|
||||
parentGroupId = getBodyText();
|
||||
model.setParentGroupId( getBodyText() );
|
||||
}
|
||||
else if ( rawName.equals( "artifactId" ) )
|
||||
{
|
||||
parentArtifactId = getBodyText();
|
||||
model.setParentArtifactId( getBodyText() );
|
||||
}
|
||||
else if ( rawName.equals( "version" ) )
|
||||
{
|
||||
parentVersion = getBodyText();
|
||||
model.setParentVersion( getBodyText() );
|
||||
}
|
||||
}
|
||||
else if ( insideDependency )
|
||||
|
@ -476,27 +421,27 @@ public class ModelReader
|
|||
{
|
||||
if ( rawName.equals( "artifactId" ) )
|
||||
{
|
||||
artifactId = getBodyText();
|
||||
model.setArtifactId( getBodyText() );
|
||||
}
|
||||
else if ( rawName.equals( "version" ) )
|
||||
{
|
||||
version = getBodyText();
|
||||
model.setVersion( getBodyText() );
|
||||
}
|
||||
else if ( rawName.equals( "groupId" ) )
|
||||
{
|
||||
groupId = getBodyText();
|
||||
model.setGroupId( getBodyText() );
|
||||
}
|
||||
else if ( rawName.equals( "packaging" ) )
|
||||
{
|
||||
packaging = getBodyText();
|
||||
model.setPackaging( getBodyText() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( depth == 1 ) // model / project
|
||||
{
|
||||
resolver.addBuiltArtifact( groupId, artifactId, "pom", pomFile );
|
||||
resolver.addBuiltArtifact( model.getGroupId(), model.getArtifactId(), "pom", model.getProjectFile() );
|
||||
|
||||
resolveDependencies();
|
||||
ProjectResolver.resolveDependencies( resolver, model, resolveTransitiveDependencies, inheritedScope, excluded );
|
||||
}
|
||||
|
||||
bodyText = new StringBuffer();
|
||||
|
@ -504,170 +449,4 @@ public class ModelReader
|
|||
depth--;
|
||||
}
|
||||
|
||||
private void resolveDependencies()
|
||||
throws SAXException
|
||||
{
|
||||
for ( Iterator it = dependencies.values().iterator(); it.hasNext(); )
|
||||
{
|
||||
Dependency dependency = (Dependency) it.next();
|
||||
|
||||
if ( !excluded.contains( dependency.getConflictId() ) && !dependency.isOptional() )
|
||||
{
|
||||
if ( !dependency.getScope().equals( Dependency.SCOPE_TEST ) || inheritedScope == null )
|
||||
{
|
||||
if ( dependency.getVersion() == null )
|
||||
{
|
||||
Dependency managedDependency =
|
||||
(Dependency) managedDependencies.get( dependency.getConflictId() );
|
||||
if ( managedDependency == null )
|
||||
{
|
||||
throw new NullPointerException( "[" + groupId + ":" + artifactId + ":" + packaging + ":" +
|
||||
version + "] " + "Dependency " + dependency.getConflictId() +
|
||||
" is missing a version, and nothing is found in dependencyManagement. " );
|
||||
}
|
||||
dependency.setVersion( managedDependency.getVersion() );
|
||||
}
|
||||
|
||||
if ( resolveTransitiveDependencies )
|
||||
{
|
||||
Set excluded = new HashSet( this.excluded );
|
||||
excluded.addAll( dependency.getExclusions() );
|
||||
|
||||
ModelReader p = retrievePom( dependency.getGroupId(), dependency.getArtifactId(),
|
||||
dependency.getVersion(), dependency.getScope(),
|
||||
resolveTransitiveDependencies, excluded, dependency.getChain() );
|
||||
|
||||
addDependencies( p.getDependencies(), transitiveDependencies, dependency.getScope(), excluded );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addDependencies( Collection dependencies, Map target, String inheritedScope, Set excluded )
|
||||
{
|
||||
for ( Iterator i = dependencies.iterator(); i.hasNext(); )
|
||||
{
|
||||
Dependency d = (Dependency) i.next();
|
||||
|
||||
// skip test deps
|
||||
if ( !Dependency.SCOPE_TEST.equals( d.getScope() ) )
|
||||
{
|
||||
// Do we care about runtime here?
|
||||
if ( Dependency.SCOPE_TEST.equals( inheritedScope ) )
|
||||
{
|
||||
d.setScope( Dependency.SCOPE_TEST );
|
||||
}
|
||||
|
||||
if ( !hasDependency( d, target ) && !excluded.contains( d.getConflictId() ) && !d.isOptional() )
|
||||
{
|
||||
if ( !"plexus".equals( d.getGroupId() ) || ( !"plexus-utils".equals( d.getArtifactId() ) &&
|
||||
!"plexus-container-default".equals( d.getArtifactId() ) ) )
|
||||
{
|
||||
target.put( d.getConflictId(), d );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasDependency( Dependency d, Map dependencies )
|
||||
{
|
||||
String conflictId = d.getConflictId();
|
||||
if ( dependencies.containsKey( conflictId ) )
|
||||
{
|
||||
// We only care about pushing in compile scope dependencies I think
|
||||
// if not, we'll need to be able to get the original and pick the appropriate scope
|
||||
if ( d.getScope().equals( Dependency.SCOPE_COMPILE ) )
|
||||
{
|
||||
dependencies.remove( conflictId );
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private ModelReader retrievePom( String groupId, String artifactId, String version, String inheritedScope,
|
||||
boolean resolveTransitiveDependencies, Set excluded, List chain )
|
||||
throws SAXException
|
||||
{
|
||||
String key = groupId + ":" + artifactId + ":" + version;
|
||||
|
||||
if ( inProgress.contains( key ) )
|
||||
{
|
||||
throw new SAXException( "Circular dependency found, looking for " + key + "\nIn progress:" + inProgress );
|
||||
}
|
||||
|
||||
inProgress.add( key );
|
||||
|
||||
ModelReader p = new ModelReader( resolver, inheritedScope, resolveTransitiveDependencies, excluded, chain );
|
||||
|
||||
try
|
||||
{
|
||||
Dependency pom = new Dependency( groupId, artifactId, version, "pom", chain );
|
||||
pom.getRepositories().addAll( repositories );
|
||||
for ( Iterator it = chain.iterator(); it.hasNext(); )
|
||||
{
|
||||
pom.getRepositories().addAll( ( (Dependency) it.next() ).getRepositories() );
|
||||
}
|
||||
|
||||
resolver.downloadDependencies( Collections.singletonList( pom ) );
|
||||
|
||||
p.parse( resolver.getArtifactFile( pom ) );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new SAXException( "Error getting parent POM", e );
|
||||
}
|
||||
catch ( ParserConfigurationException e )
|
||||
{
|
||||
throw new SAXException( "Error getting parent POM", e );
|
||||
}
|
||||
catch ( DownloadFailedException e )
|
||||
{
|
||||
throw new SAXException( "Error getting parent POM", e );
|
||||
}
|
||||
|
||||
inProgress.remove( key );
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
public String getArtifactId()
|
||||
{
|
||||
return artifactId;
|
||||
}
|
||||
|
||||
public String getVersion()
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
public String getGroupId()
|
||||
{
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public String getPackaging()
|
||||
{
|
||||
return packaging;
|
||||
}
|
||||
|
||||
public Map getPlugins()
|
||||
{
|
||||
return plugins;
|
||||
}
|
||||
|
||||
public List getModules()
|
||||
{
|
||||
return modules;
|
||||
}
|
||||
|
||||
public File getProjectFile()
|
||||
{
|
||||
return pomFile;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,181 @@
|
|||
package org.apache.maven.bootstrap.model;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2005 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.
|
||||
*/
|
||||
|
||||
import org.apache.maven.bootstrap.download.ArtifactResolver;
|
||||
import org.apache.maven.bootstrap.download.DownloadFailedException;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* Utility class for resolving Model dependencies.
|
||||
*
|
||||
*/
|
||||
public final class ProjectResolver
|
||||
{
|
||||
private static Set inProgress = new HashSet();
|
||||
|
||||
private ProjectResolver()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static void resolveDependencies( ArtifactResolver resolver, Model model,
|
||||
boolean resolveTransitiveDependencies, String inheritedScope, Set excluded )
|
||||
throws SAXException
|
||||
{
|
||||
for ( Iterator it = model.getDependencies().values().iterator(); it.hasNext(); )
|
||||
{
|
||||
Dependency dependency = (Dependency) it.next();
|
||||
|
||||
if ( !excluded.contains( dependency.getConflictId() ) && !dependency.isOptional() )
|
||||
{
|
||||
if ( !dependency.getScope().equals( Dependency.SCOPE_TEST ) || inheritedScope == null )
|
||||
{
|
||||
if ( dependency.getVersion() == null )
|
||||
{
|
||||
Dependency managedDependency = (Dependency) model.managedDependencies.get( dependency
|
||||
.getConflictId() );
|
||||
|
||||
if ( managedDependency == null )
|
||||
{
|
||||
throw new NullPointerException( "[" + model.getId() + "] " + "Dependency "
|
||||
+ dependency.getConflictId()
|
||||
+ " is missing a version, and nothing is found in dependencyManagement. " );
|
||||
}
|
||||
dependency.setVersion( managedDependency.getVersion() );
|
||||
}
|
||||
|
||||
if ( resolveTransitiveDependencies )
|
||||
{
|
||||
Set excluded2 = new HashSet( excluded );
|
||||
excluded2.addAll( dependency.getExclusions() );
|
||||
|
||||
Model p = retrievePom( resolver, dependency.getGroupId(), dependency.getArtifactId(),
|
||||
dependency.getVersion(), dependency.getScope(),
|
||||
resolveTransitiveDependencies, excluded2, dependency.getChain() );
|
||||
|
||||
addDependencies( p.getAllDependencies(), model.transitiveDependencies, dependency.getScope(),
|
||||
excluded2 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void addDependencies( Collection dependencies, Map target, String inheritedScope, Set excluded )
|
||||
{
|
||||
for ( Iterator i = dependencies.iterator(); i.hasNext(); )
|
||||
{
|
||||
Dependency d = (Dependency) i.next();
|
||||
|
||||
// skip test deps
|
||||
if ( !Dependency.SCOPE_TEST.equals( d.getScope() ) )
|
||||
{
|
||||
// Do we care about runtime here?
|
||||
if ( Dependency.SCOPE_TEST.equals( inheritedScope ) )
|
||||
{
|
||||
d.setScope( Dependency.SCOPE_TEST );
|
||||
}
|
||||
|
||||
if ( !hasDependency( d, target ) && !excluded.contains( d.getConflictId() ) && !d.isOptional() )
|
||||
{
|
||||
if ( !"plexus".equals( d.getGroupId() )
|
||||
|| ( !"plexus-utils".equals( d.getArtifactId() ) && !"plexus-container-default".equals( d
|
||||
.getArtifactId() ) ) )
|
||||
{
|
||||
target.put( d.getConflictId(), d );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasDependency( Dependency d, Map dependencies )
|
||||
{
|
||||
String conflictId = d.getConflictId();
|
||||
if ( dependencies.containsKey( conflictId ) )
|
||||
{
|
||||
// We only care about pushing in compile scope dependencies I think
|
||||
// if not, we'll need to be able to get the original and pick the appropriate scope
|
||||
if ( d.getScope().equals( Dependency.SCOPE_COMPILE ) )
|
||||
{
|
||||
dependencies.remove( conflictId );
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Model retrievePom( ArtifactResolver resolver, String groupId, String artifactId, String version,
|
||||
String inheritedScope, boolean resolveTransitiveDependencies, Set excluded,
|
||||
List chain )
|
||||
throws SAXException
|
||||
{
|
||||
String key = groupId + ":" + artifactId + ":" + version;
|
||||
|
||||
if ( inProgress.contains( key ) )
|
||||
{
|
||||
throw new SAXException( "Circular dependency found, looking for " + key + "\nIn progress:" + inProgress );
|
||||
}
|
||||
|
||||
inProgress.add( key );
|
||||
|
||||
ModelReader p = new ModelReader( resolver, inheritedScope, resolveTransitiveDependencies, excluded );
|
||||
|
||||
try
|
||||
{
|
||||
// download the POM
|
||||
Dependency pom = new Dependency( groupId, artifactId, version, "pom", chain );
|
||||
|
||||
resolver.downloadDependencies( Collections.singletonList( pom ) );
|
||||
|
||||
// Parse the POM from the local repository into a model
|
||||
Model model = p.parseModel( resolver.getArtifactFile( pom ), chain );
|
||||
|
||||
inProgress.remove( key );
|
||||
|
||||
return model;
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new SAXException( "Error getting parent POM", e );
|
||||
}
|
||||
catch ( ParserConfigurationException e )
|
||||
{
|
||||
throw new SAXException( "Error getting parent POM", e );
|
||||
}
|
||||
catch ( DownloadFailedException e )
|
||||
{
|
||||
throw new SAXException( "Error getting parent POM", e );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -40,13 +40,9 @@ public abstract class AbstractReader
|
|||
{
|
||||
private SAXParserFactory saxFactory;
|
||||
|
||||
protected File pomFile;
|
||||
|
||||
public void parse( File file )
|
||||
throws ParserConfigurationException, SAXException, IOException
|
||||
{
|
||||
pomFile = file;
|
||||
|
||||
saxFactory = SAXParserFactory.newInstance();
|
||||
|
||||
SAXParser parser = saxFactory.newSAXParser();
|
||||
|
|
Loading…
Reference in New Issue