2004-07-25 23:53:12 -04:00
|
|
|
|
|
|
|
import org.xml.sax.Attributes;
|
|
|
|
import org.xml.sax.InputSource;
|
|
|
|
import org.xml.sax.SAXException;
|
|
|
|
import org.xml.sax.SAXParseException;
|
|
|
|
import org.xml.sax.helpers.DefaultHandler;
|
|
|
|
|
|
|
|
import javax.xml.parsers.SAXParser;
|
|
|
|
import javax.xml.parsers.SAXParserFactory;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
2004-08-15 00:30:20 -04:00
|
|
|
import java.io.FileNotFoundException;
|
2004-07-25 23:53:12 -04:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.Serializable;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Properties;
|
2004-07-26 18:45:09 -04:00
|
|
|
import java.util.Date;
|
2004-07-25 23:53:12 -04:00
|
|
|
|
|
|
|
public class MBoot
|
|
|
|
{
|
|
|
|
// I need:
|
|
|
|
// o pom install (done)
|
|
|
|
// o jar install (done)
|
|
|
|
// o bean generation - this is not entirely necessary
|
|
|
|
// o jelly generation - this is not entirely necessary
|
|
|
|
// o plugin descriptor (done)
|
|
|
|
// o xpp3/reader and writer (done)
|
|
|
|
// o compilation of generated sources in target/generated-sources (done)
|
|
|
|
// o need to run modello to generate the sources (done)
|
|
|
|
// o make this work over and over again (done)
|
|
|
|
// o hide the dependencies for mboot in the JAR (done)
|
|
|
|
|
|
|
|
// maven-core
|
|
|
|
// maven-plugin
|
|
|
|
// maven-plugins
|
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
// ----------------------------------------------------------------------
|
2004-08-09 14:57:50 -04:00
|
|
|
//
|
2004-07-26 18:02:58 -04:00
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
String[] deps = new String[]
|
|
|
|
{
|
|
|
|
"junit/jars/junit-3.8.1.jar",
|
|
|
|
"surefire/jars/surefire-booter-1.1.jar",
|
|
|
|
"surefire/jars/surefire-1.1.jar",
|
|
|
|
"modello/jars/modello-1.0-SNAPSHOT.jar",
|
|
|
|
"xpp3/jars/xpp3-1.1.3.3.jar",
|
|
|
|
"xstream/jars/xstream-1.0-SNAPSHOT.jar",
|
2004-08-09 17:48:21 -04:00
|
|
|
"qdox/jars/qdox-1.2.jar",
|
|
|
|
"maven/jars/wagon-http-lightweight-1.0-alpha-1-SNAPSHOT.jar"
|
2004-08-09 14:57:50 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
String[] plexusDeps = new String[]
|
|
|
|
{
|
|
|
|
"classworlds/jars/classworlds-1.1-SNAPSHOT.jar",
|
2004-08-26 07:47:30 -04:00
|
|
|
"plexus/jars/plexus-0.17.jar",
|
2004-08-09 14:57:50 -04:00
|
|
|
"xpp3/jars/xpp3-1.1.3.3.jar",
|
|
|
|
"xstream/jars/xstream-1.0-SNAPSHOT.jar",
|
|
|
|
"maven/jars/maven-artifact-2.0-SNAPSHOT.jar",
|
|
|
|
"maven/jars/wagon-api-1.0-alpha-1-SNAPSHOT.jar",
|
|
|
|
"maven/jars/wagon-http-lightweight-1.0-alpha-1-SNAPSHOT.jar"
|
2004-07-26 18:02:58 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
String[] builds = new String[]
|
|
|
|
{
|
|
|
|
"maven-model",
|
|
|
|
"maven-plugin",
|
2004-08-09 14:57:50 -04:00
|
|
|
"maven-plugin-tools",
|
|
|
|
"maven-artifact",
|
2004-08-10 14:58:21 -04:00
|
|
|
"maven-core",
|
|
|
|
"maven-core-it-verifier"
|
2004-08-09 14:57:50 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
String[] pluginBuilds = new String[]
|
|
|
|
{
|
2004-07-26 18:02:58 -04:00
|
|
|
"maven-plugins/maven-clean-plugin",
|
|
|
|
"maven-plugins/maven-compiler-plugin",
|
|
|
|
"maven-plugins/maven-install-plugin",
|
|
|
|
"maven-plugins/maven-jar-plugin",
|
|
|
|
"maven-plugins/maven-plugin-plugin",
|
|
|
|
"maven-plugins/maven-pom-plugin",
|
|
|
|
"maven-plugins/maven-resources-plugin",
|
|
|
|
"maven-plugins/maven-surefire-plugin"
|
|
|
|
};
|
2004-08-09 14:57:50 -04:00
|
|
|
|
|
|
|
|
2004-07-25 23:53:12 -04:00
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Standard locations for resources in Maven projects.
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
private static final String SOURCES = "src/main/java";
|
|
|
|
|
|
|
|
private static final String TEST_SOURCES = "src/test/java";
|
|
|
|
|
|
|
|
private static final String RESOURCES = "src/main/resources";
|
|
|
|
|
|
|
|
private static final String TEST_RESOURCES = "src/test/resources";
|
|
|
|
|
2004-08-20 20:14:25 -04:00
|
|
|
private static final String BUILD_DIR = "target";
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-08-20 20:14:25 -04:00
|
|
|
private static final String CLASSES = BUILD_DIR + "/classes";
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-08-20 20:14:25 -04:00
|
|
|
private static final String TEST_CLASSES = BUILD_DIR + "/test-classes";
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-08-20 20:14:25 -04:00
|
|
|
private static final String GENERATED_SOURCES = BUILD_DIR + "/generated-sources";
|
2004-07-25 23:53:12 -04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Per-session entities which we can reuse while building many projects.
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
private ArtifactDownloader downloader;
|
|
|
|
|
|
|
|
private ModelReader reader;
|
|
|
|
|
|
|
|
private Properties properties;
|
|
|
|
|
|
|
|
private String repoLocal;
|
|
|
|
|
|
|
|
private List mbootDependencies;
|
|
|
|
|
|
|
|
private List coreDeps;
|
|
|
|
|
2004-07-27 12:59:04 -04:00
|
|
|
private boolean online = true;
|
|
|
|
|
2004-07-25 23:53:12 -04:00
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
public static void main( String[] args )
|
|
|
|
throws Exception
|
|
|
|
{
|
|
|
|
MBoot mboot = new MBoot();
|
|
|
|
|
|
|
|
mboot.run( args );
|
|
|
|
}
|
|
|
|
|
|
|
|
public void run( String[] args )
|
|
|
|
throws Exception
|
|
|
|
{
|
2004-07-27 12:59:04 -04:00
|
|
|
File mavenPropertiesFile = new File( System.getProperty( "user.home" ), "maven.properties" );
|
2004-07-26 21:19:41 -04:00
|
|
|
|
|
|
|
if ( !mavenPropertiesFile.exists() )
|
|
|
|
{
|
|
|
|
System.out.println( "You must have a ~/maven.properties file and must contain the following entries:" );
|
|
|
|
|
2004-08-14 02:59:14 -04:00
|
|
|
System.out.println( "maven.home = /path/to/m2/installation" );
|
2004-07-26 21:19:41 -04:00
|
|
|
|
|
|
|
System.out.println( "maven.repo.local = /path/to/m2/repository" );
|
|
|
|
|
|
|
|
System.exit( 1 );
|
|
|
|
}
|
|
|
|
|
2004-07-26 18:45:09 -04:00
|
|
|
Date fullStop;
|
|
|
|
|
|
|
|
Date fullStart = new Date();
|
|
|
|
|
2004-07-26 21:19:41 -04:00
|
|
|
properties = loadProperties( mavenPropertiesFile );
|
|
|
|
|
2004-08-14 16:46:24 -04:00
|
|
|
// Make the system properties override maven.properties
|
|
|
|
properties.putAll( System.getProperties() );
|
|
|
|
|
2004-07-26 21:19:41 -04:00
|
|
|
for ( Iterator i = properties.keySet().iterator(); i.hasNext(); )
|
|
|
|
{
|
|
|
|
String key = (String) i.next();
|
|
|
|
|
2004-08-14 16:46:24 -04:00
|
|
|
// TODO: the namespace should be "properties" itself to support variables within the same file,
|
|
|
|
// however, StringUtils would need to support recursive replacement
|
2004-07-27 12:59:04 -04:00
|
|
|
properties.setProperty( key, StringUtils.interpolate( properties.getProperty( key ), System.getProperties() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
String onlineProperty = properties.getProperty( "maven.online" );
|
|
|
|
|
|
|
|
if ( onlineProperty != null && onlineProperty.equals( "false" ) )
|
|
|
|
{
|
|
|
|
online = false;
|
2004-07-26 21:19:41 -04:00
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
|
|
|
|
downloader = new ArtifactDownloader( properties );
|
|
|
|
|
|
|
|
repoLocal = downloader.getMavenRepoLocal().getPath();
|
|
|
|
|
|
|
|
reader = new ModelReader();
|
|
|
|
|
|
|
|
String basedir = System.getProperty( "user.dir" );
|
|
|
|
|
2004-07-27 12:59:04 -04:00
|
|
|
mbootDependencies = Arrays.asList( deps );
|
|
|
|
|
|
|
|
if ( online )
|
|
|
|
{
|
|
|
|
checkMBootDeps();
|
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 21:19:41 -04:00
|
|
|
// Install maven-components POM
|
2004-07-27 12:59:04 -04:00
|
|
|
installPomFile( repoLocal, new File( basedir, "pom.xml" ) );
|
2004-07-26 18:45:09 -04:00
|
|
|
|
2004-07-26 21:19:41 -04:00
|
|
|
// Install plugin-parent POM
|
2004-07-27 12:59:04 -04:00
|
|
|
installPomFile( repoLocal, new File( basedir, "maven-plugins/pom.xml" ) );
|
2004-07-26 18:45:09 -04:00
|
|
|
|
2004-08-09 14:57:50 -04:00
|
|
|
createToolsClassLoader();
|
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
for ( int i = 0; i < builds.length; i++ )
|
2004-07-25 23:53:12 -04:00
|
|
|
{
|
2004-07-26 18:02:58 -04:00
|
|
|
String directory = new File( basedir, builds[i] ).getAbsolutePath();
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
System.out.println( "Building project in " + directory + " ..." );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
System.out.println( "--------------------------------------------------------------------" );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
System.setProperty( "basedir", directory );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
buildProject( directory );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
if ( reader.artifactId.equals( "maven-core" ) )
|
|
|
|
{
|
|
|
|
coreDeps = reader.getDependencies();
|
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
reader.reset();
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
System.out.println( "--------------------------------------------------------------------" );
|
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-08-09 14:57:50 -04:00
|
|
|
cl.addURL( new File( repoLocal, "maven/jars/maven-plugin-2.0-SNAPSHOT.jar" ).toURL() );
|
|
|
|
|
|
|
|
cl.addURL( new File( repoLocal, "maven/jars/maven-plugin-tools-2.0-SNAPSHOT.jar" ).toURL() );
|
|
|
|
|
|
|
|
|
|
|
|
for ( int i = 0; i < pluginBuilds.length; i++ )
|
|
|
|
{
|
|
|
|
String directory = new File( basedir, pluginBuilds[i] ).getAbsolutePath();
|
|
|
|
|
|
|
|
System.out.println( "Building project in " + directory + " ..." );
|
|
|
|
|
|
|
|
System.out.println( "--------------------------------------------------------------------" );
|
|
|
|
|
|
|
|
System.setProperty( "basedir", directory );
|
|
|
|
|
|
|
|
buildProject( directory );
|
|
|
|
|
|
|
|
reader.reset();
|
|
|
|
|
|
|
|
System.out.println( "--------------------------------------------------------------------" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
// build the installation
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
String mavenHome;
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
if ( args.length == 1 )
|
|
|
|
{
|
|
|
|
mavenHome = args[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-07-26 21:19:41 -04:00
|
|
|
mavenHome = properties.getProperty( "maven.home" );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
if ( mavenHome == null )
|
2004-07-25 23:53:12 -04:00
|
|
|
{
|
2004-07-26 18:02:58 -04:00
|
|
|
mavenHome = new File( System.getProperty( "user.home" ), "m2" ).getAbsolutePath();
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
2004-07-26 18:02:58 -04:00
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
File dist = new File( mavenHome );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
FileUtils.deleteDirectory( dist );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// bin
|
|
|
|
// ----------------------------------------------------------------------
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
String bin = new File( dist, "bin" ).getAbsolutePath();
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
FileUtils.mkdir( new File( bin ).getPath() );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
FileUtils.copyFileToDirectory( new File( basedir, "maven-core/src/bin/m2" ).getAbsolutePath(), bin );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
FileUtils.copyFileToDirectory( new File( basedir, "maven-core/src/bin/m2.bat" ).getAbsolutePath(), bin );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
FileUtils.copyFileToDirectory( new File( basedir, "maven-core/src/bin/classworlds.conf" ).getAbsolutePath(), bin );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
if ( Os.isFamily( "unix" ) )
|
|
|
|
{
|
|
|
|
Commandline cli = new Commandline();
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
cli.setExecutable( "chmod" );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
cli.createArgument().setValue( "+x" );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
cli.createArgument().setValue( new File( dist, "bin/m2" ).getAbsolutePath() );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
cli.execute();
|
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// core
|
|
|
|
// ----------------------------------------------------------------------
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
String core = new File( dist, "core" ).getAbsolutePath();
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
FileUtils.mkdir( new File( core ).getPath() );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-08-09 14:57:50 -04:00
|
|
|
for ( int i = 0; i < plexusDeps.length; i++ )
|
|
|
|
{
|
|
|
|
FileUtils.copyFileToDirectory( repoLocal + "/" + plexusDeps[i], core );
|
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// lib
|
|
|
|
// ----------------------------------------------------------------------
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
String lib = new File( dist, "lib" ).getAbsolutePath();
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
FileUtils.mkdir( new File( lib ).getPath() );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
for ( Iterator i = coreDeps.iterator(); i.hasNext(); )
|
|
|
|
{
|
|
|
|
Dependency d = (Dependency) i.next();
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
if ( d.getArtifactId().equals( "classworlds" ) ||
|
|
|
|
d.artifactId.equals( "plexus" ) ||
|
|
|
|
d.artifactId.equals( "xstream" ) ||
|
2004-08-09 14:57:50 -04:00
|
|
|
d.artifactId.equals( "xpp3" ) ||
|
|
|
|
d.artifactId.equals( "junit" ) ||
|
|
|
|
d.artifactId.equals( "wagon-api" ) ||
|
|
|
|
d.artifactId.equals( "maven-artifact" ) )
|
2004-07-25 23:53:12 -04:00
|
|
|
{
|
2004-07-26 18:02:58 -04:00
|
|
|
continue;
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
FileUtils.copyFileToDirectory( repoLocal + "/" + getArtifactPath( d, "/" ), lib );
|
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
// Copy maven itself
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
FileUtils.copyFileToDirectory( repoLocal + "/maven/jars/maven-core-2.0-SNAPSHOT.jar", lib );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-26 18:45:09 -04:00
|
|
|
fullStop = new Date();
|
|
|
|
|
|
|
|
stats( fullStart, fullStop );
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static String formatTime( long ms )
|
|
|
|
{
|
|
|
|
long secs = ms / 1000;
|
|
|
|
|
|
|
|
long min = secs / 60;
|
|
|
|
secs = secs % 60;
|
|
|
|
|
|
|
|
if ( min > 0 )
|
|
|
|
{
|
|
|
|
return min + " minutes " + secs + " seconds";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return secs + " seconds";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void stats( Date fullStart, Date fullStop )
|
|
|
|
{
|
|
|
|
long fullDiff = fullStop.getTime() - fullStart.getTime();
|
|
|
|
|
|
|
|
System.out.println( "Total time: " + formatTime( fullDiff ) );
|
|
|
|
|
|
|
|
System.out.println( "Finished at: " + fullStop );
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void buildProject( String basedir )
|
|
|
|
throws Exception
|
|
|
|
{
|
|
|
|
System.out.println( "Building project in " + basedir );
|
|
|
|
|
|
|
|
if ( !reader.parse( new File( basedir, "pom.xml" ) ) )
|
|
|
|
{
|
|
|
|
System.err.println( "Could not parse pom.xml" );
|
|
|
|
|
|
|
|
System.exit( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
String sources = new File( basedir, SOURCES ).getAbsolutePath();
|
|
|
|
|
|
|
|
String resources = new File( basedir, RESOURCES ).getAbsolutePath();
|
|
|
|
|
|
|
|
String classes = new File( basedir, CLASSES ).getAbsolutePath();
|
|
|
|
|
|
|
|
String testSources = new File( basedir, TEST_SOURCES ).getAbsolutePath();
|
|
|
|
|
|
|
|
String testResources = new File( basedir, TEST_RESOURCES ).getAbsolutePath();
|
|
|
|
|
|
|
|
String testClasses = new File( basedir, TEST_CLASSES ).getAbsolutePath();
|
|
|
|
|
|
|
|
String generatedSources = new File( basedir, GENERATED_SOURCES ).getAbsolutePath();
|
|
|
|
|
2004-08-20 20:14:25 -04:00
|
|
|
File buildDirFile = new File( basedir, BUILD_DIR );
|
|
|
|
String buildDir = buildDirFile.getAbsolutePath();
|
|
|
|
|
|
|
|
// clean
|
|
|
|
System.out.println( "Cleaning " + buildDirFile + "..." );
|
2004-08-26 07:33:41 -04:00
|
|
|
if ( buildDirFile.exists() )
|
|
|
|
{
|
|
|
|
FileUtils.forceDelete( buildDirFile );
|
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Download deps
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
2004-07-27 12:59:04 -04:00
|
|
|
if ( online )
|
|
|
|
{
|
|
|
|
System.out.println( "Downloading dependencies ..." );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-27 12:59:04 -04:00
|
|
|
downloadDependencies( reader.getDependencies() );
|
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Generating sources
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
File model = new File( basedir, "maven.mdo" );
|
|
|
|
|
|
|
|
if ( model.exists() )
|
|
|
|
{
|
|
|
|
System.out.println( "Model exists!" );
|
|
|
|
|
2004-08-20 20:14:25 -04:00
|
|
|
File generatedSourcesDirectory = new File( basedir, GENERATED_SOURCES );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
|
|
|
if ( !generatedSourcesDirectory.exists() )
|
|
|
|
{
|
|
|
|
generatedSourcesDirectory.mkdirs();
|
|
|
|
}
|
|
|
|
|
2004-08-20 20:14:25 -04:00
|
|
|
generateSources( model.getAbsolutePath(), "java", generatedSources, "4.0.0", "false" );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-08-20 20:14:25 -04:00
|
|
|
generateSources( model.getAbsolutePath(), "java", generatedSources, "3.0.0", "true" );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-08-20 20:14:25 -04:00
|
|
|
generateSources( model.getAbsolutePath(), "xpp3", generatedSources, "4.0.0", "false" );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-08-20 20:14:25 -04:00
|
|
|
generateSources( model.getAbsolutePath(), "xpp3", generatedSources, "3.0.0", "true" );
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Standard compile
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
System.out.println( "Compiling sources ..." );
|
|
|
|
|
|
|
|
if ( new File( generatedSources ).exists() )
|
|
|
|
{
|
|
|
|
compile( reader.getDependencies(), sources, classes, null, generatedSources );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
compile( reader.getDependencies(), sources, classes, null, null );
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Plugin descriptor generation
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
if ( reader.type != null && reader.type.equals( "plugin" ) )
|
|
|
|
{
|
|
|
|
System.out.println( "Generating maven plugin descriptor ..." );
|
|
|
|
|
|
|
|
generatePluginDescriptor( sources,
|
|
|
|
new File( classes, "META-INF/maven" ).getAbsolutePath(),
|
|
|
|
new File( basedir, "pom.xml" ).getAbsolutePath() );
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Standard resources
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
System.out.println( "Packaging resources ..." );
|
|
|
|
|
|
|
|
copyResources( resources, classes );
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Test compile
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
System.out.println( "Compiling test sources ..." );
|
|
|
|
|
2004-07-27 07:13:06 -04:00
|
|
|
List testDependencies = reader.getDependencies();
|
|
|
|
|
|
|
|
Dependency junitDep = new Dependency();
|
|
|
|
|
|
|
|
junitDep.setGroupId( "junit" );
|
|
|
|
|
|
|
|
junitDep.setArtifactId( "junit" );
|
|
|
|
|
|
|
|
junitDep.setVersion( "3.8.1" );
|
|
|
|
|
|
|
|
testDependencies.add( junitDep );
|
|
|
|
|
2004-08-20 20:14:25 -04:00
|
|
|
compile( testDependencies, testSources, testClasses, classes, null );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Test resources
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
System.out.println( "Packaging test resources ..." );
|
|
|
|
|
|
|
|
copyResources( testResources, testClasses );
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Run tests
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
runTests( basedir, classes, testClasses );
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Create JAR
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
createJar( classes, buildDir );
|
|
|
|
|
|
|
|
installPom( basedir, repoLocal );
|
|
|
|
|
2004-08-09 14:57:50 -04:00
|
|
|
if ( !reader.artifactId.equals( "maven-plugin" ) && reader.artifactId.endsWith( "plugin" ) )
|
|
|
|
{
|
|
|
|
installPlugin( basedir, repoLocal );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
installJar( basedir, repoLocal );
|
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
|
2004-08-09 14:57:50 -04:00
|
|
|
IsolatedClassLoader cl;
|
|
|
|
|
|
|
|
private void createToolsClassLoader()
|
2004-07-25 23:53:12 -04:00
|
|
|
throws Exception
|
|
|
|
{
|
2004-08-09 14:57:50 -04:00
|
|
|
cl = new IsolatedClassLoader();
|
2004-07-25 23:53:12 -04:00
|
|
|
|
|
|
|
for ( Iterator i = mbootDependencies.iterator(); i.hasNext(); )
|
|
|
|
{
|
|
|
|
String dependency = (String) i.next();
|
|
|
|
|
|
|
|
File f = new File( repoLocal, dependency );
|
2004-08-15 00:30:20 -04:00
|
|
|
if ( !f.exists() )
|
|
|
|
{
|
|
|
|
throw new FileNotFoundException( "Missing dependency: " + dependency +
|
|
|
|
( !online ? "; run again online" : "; there was a problem downloading it earlier" ) );
|
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
|
|
|
|
cl.addURL( f.toURL() );
|
|
|
|
}
|
2004-08-09 14:57:50 -04:00
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-08-09 14:57:50 -04:00
|
|
|
private void generatePluginDescriptor( String sourceDirectory, String outputDirectory, String pom )
|
|
|
|
throws Exception
|
|
|
|
{
|
2004-07-25 23:53:12 -04:00
|
|
|
Class c = cl.loadClass( "org.apache.maven.plugin.generator.PluginDescriptorGenerator" );
|
|
|
|
|
|
|
|
Object generator = c.newInstance();
|
|
|
|
|
|
|
|
Method m = c.getMethod( "execute", new Class[]{String.class, String.class, String.class} );
|
|
|
|
|
|
|
|
m.invoke( generator, new Object[]{sourceDirectory, outputDirectory, pom} );
|
|
|
|
}
|
|
|
|
|
|
|
|
private void generateSources( String model, String mode, String dir, String modelVersion, String packageWithVersion )
|
|
|
|
throws Exception
|
|
|
|
{
|
|
|
|
Class c = cl.loadClass( "org.codehaus.modello.Modello" );
|
|
|
|
|
|
|
|
Object generator = c.newInstance();
|
|
|
|
|
|
|
|
Method m = c.getMethod( "main", new Class[]{String[].class} );
|
|
|
|
|
|
|
|
String[] args = new String[]{model, mode, dir, modelVersion, packageWithVersion};
|
|
|
|
|
|
|
|
ClassLoader old = Thread.currentThread().getContextClassLoader();
|
|
|
|
|
|
|
|
Thread.currentThread().setContextClassLoader( cl );
|
|
|
|
|
|
|
|
m.invoke( generator, new Object[]{args} );
|
|
|
|
|
|
|
|
Thread.currentThread().setContextClassLoader( old );
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkMBootDeps()
|
|
|
|
throws Exception
|
|
|
|
{
|
|
|
|
System.out.println( "Checking for MBoot's dependencies ..." );
|
|
|
|
|
|
|
|
downloader.downloadDependencies( mbootDependencies );
|
|
|
|
}
|
|
|
|
|
|
|
|
private void createJar( String classes, String buildDir )
|
|
|
|
throws Exception
|
|
|
|
{
|
|
|
|
JarMojo jarMojo = new JarMojo();
|
|
|
|
|
|
|
|
String artifactId = reader.artifactId;
|
|
|
|
|
|
|
|
String version = reader.version;
|
|
|
|
|
|
|
|
jarMojo.execute( new File( classes ), buildDir, artifactId + "-" + version );
|
|
|
|
}
|
|
|
|
|
2004-07-26 21:19:41 -04:00
|
|
|
private void installPomFile( String repoLocal, File pomIn )
|
|
|
|
throws Exception
|
|
|
|
{
|
|
|
|
if ( !reader.parse( pomIn ) )
|
|
|
|
{
|
|
|
|
System.err.println( "Could not parse pom.xml" );
|
|
|
|
|
|
|
|
System.exit( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
String artifactId = reader.artifactId;
|
|
|
|
|
|
|
|
String version = reader.version;
|
|
|
|
|
|
|
|
String groupId = reader.groupId;
|
|
|
|
|
|
|
|
File pom = new File( repoLocal, "/" + groupId + "/poms/" + artifactId + "-" + version + ".pom" );
|
|
|
|
|
|
|
|
System.out.println( "Installing POM: " + pom );
|
|
|
|
|
|
|
|
FileUtils.copyFile( pomIn, pom );
|
|
|
|
|
|
|
|
reader.reset();
|
|
|
|
}
|
|
|
|
|
2004-07-25 23:53:12 -04:00
|
|
|
private void installPom( String basedir, String repoLocal )
|
|
|
|
throws Exception
|
|
|
|
{
|
|
|
|
String artifactId = reader.artifactId;
|
|
|
|
|
|
|
|
String version = reader.version;
|
|
|
|
|
|
|
|
String groupId = reader.groupId;
|
|
|
|
|
2004-07-26 18:45:09 -04:00
|
|
|
File pom = new File( repoLocal, "/" + groupId + "/poms/" + artifactId + "-" + version + ".pom" );
|
|
|
|
|
|
|
|
System.out.println( "Installing POM: " + pom );
|
|
|
|
|
|
|
|
FileUtils.copyFile( new File( basedir, "pom.xml" ), pom );
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private void installJar( String basedir, String repoLocal )
|
|
|
|
throws Exception
|
|
|
|
{
|
|
|
|
String artifactId = reader.artifactId;
|
|
|
|
|
|
|
|
String version = reader.version;
|
|
|
|
|
|
|
|
String groupId = reader.groupId;
|
|
|
|
|
2004-07-26 21:19:41 -04:00
|
|
|
File jar = new File( repoLocal, "/" + groupId + "/jars/" + artifactId + "-" + version + ".jar" );
|
|
|
|
|
|
|
|
System.out.println( "Installing JAR: " + jar );
|
|
|
|
|
|
|
|
FileUtils.copyFile( new File( basedir, BUILD_DIR + "/" + artifactId + "-" + version + ".jar" ), jar );
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
|
2004-08-09 14:57:50 -04:00
|
|
|
private void installPlugin( String basedir, String repoLocal )
|
|
|
|
throws Exception
|
|
|
|
{
|
|
|
|
String artifactId = reader.artifactId;
|
|
|
|
|
|
|
|
String version = reader.version;
|
|
|
|
|
|
|
|
String groupId = reader.groupId;
|
|
|
|
|
|
|
|
File jar = new File( repoLocal, "/" + groupId + "/plugins/" + artifactId + "-" + version + ".jar" );
|
|
|
|
|
|
|
|
System.out.println( "Installing Plugin: " + jar );
|
|
|
|
|
|
|
|
FileUtils.copyFile( new File( basedir, BUILD_DIR + "/" + artifactId + "-" + version + ".jar" ), jar );
|
|
|
|
}
|
|
|
|
|
2004-07-25 23:53:12 -04:00
|
|
|
private void runTests( String basedir, String classes, String testClasses )
|
|
|
|
throws Exception
|
|
|
|
{
|
|
|
|
SurefirePlugin testRunner = new SurefirePlugin();
|
|
|
|
|
|
|
|
List includes;
|
|
|
|
|
|
|
|
List excludes;
|
|
|
|
|
|
|
|
if ( reader.getUnitTests() != null )
|
|
|
|
{
|
2004-07-27 07:24:04 -04:00
|
|
|
if ( reader.getUnitTests().getIncludes().size() != 0 )
|
|
|
|
{
|
|
|
|
includes = reader.getUnitTests().getIncludes();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
includes = new ArrayList();
|
|
|
|
|
|
|
|
includes.add( "**/*Test.java" );
|
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
|
|
|
|
excludes = reader.getUnitTests().getExcludes();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
includes = new ArrayList();
|
|
|
|
|
|
|
|
includes.add( "**/*Test.java" );
|
|
|
|
|
|
|
|
excludes = new ArrayList();
|
|
|
|
|
|
|
|
excludes.add( "**/*Abstract*.java" );
|
|
|
|
}
|
|
|
|
|
2004-08-11 02:21:13 -04:00
|
|
|
boolean success = testRunner.execute( repoLocal, basedir, classes, testClasses, includes, excludes, classpath( reader.getDependencies(), null ) );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-08-11 02:21:13 -04:00
|
|
|
if ( !success )
|
|
|
|
{
|
|
|
|
throw new Exception ( "Tests error" );
|
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Download dependencies
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
private void downloadDependencies( List dependencies )
|
|
|
|
throws Exception
|
|
|
|
{
|
|
|
|
List list = new ArrayList();
|
|
|
|
|
|
|
|
for ( Iterator i = dependencies.iterator(); i.hasNext(); )
|
|
|
|
{
|
|
|
|
Dependency d = (Dependency) i.next();
|
|
|
|
|
|
|
|
list.add( getArtifactPath( d, "/" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
downloader.downloadDependencies( list );
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Compile
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
private String[] classpath( List dependencies, String extraClasspath )
|
|
|
|
{
|
|
|
|
String classpath[] = new String[dependencies.size() + 1];
|
|
|
|
|
|
|
|
for ( int i = 0; i < dependencies.size(); i++ )
|
|
|
|
{
|
|
|
|
Dependency d = (Dependency) dependencies.get( i );
|
|
|
|
|
|
|
|
classpath[i] = repoLocal + "/" + getArtifactPath( d, "/" );
|
|
|
|
}
|
|
|
|
|
|
|
|
classpath[classpath.length - 1] = extraClasspath;
|
|
|
|
|
|
|
|
return classpath;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void compile( List dependencies,
|
|
|
|
String sourceDirectory,
|
|
|
|
String outputDirectory,
|
|
|
|
String extraClasspath,
|
|
|
|
String generatedSources )
|
|
|
|
throws Exception
|
|
|
|
{
|
|
|
|
JavacCompiler compiler = new JavacCompiler();
|
|
|
|
|
|
|
|
String[] sourceDirectories = null;
|
|
|
|
|
|
|
|
if ( generatedSources != null )
|
|
|
|
{
|
|
|
|
// We might only have generated sources
|
|
|
|
|
|
|
|
if ( new File( sourceDirectory ).exists() )
|
|
|
|
{
|
|
|
|
sourceDirectories = new String[]{sourceDirectory, generatedSources};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sourceDirectories = new String[]{generatedSources};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( new File( sourceDirectory ).exists() )
|
|
|
|
{
|
|
|
|
|
|
|
|
sourceDirectories = new String[]{sourceDirectory};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( sourceDirectories != null )
|
|
|
|
{
|
|
|
|
List errors = compiler.compile( classpath( dependencies, extraClasspath ), sourceDirectories, outputDirectory );
|
|
|
|
|
|
|
|
for ( Iterator i = errors.iterator(); i.hasNext(); )
|
|
|
|
{
|
|
|
|
System.out.println( i.next() );
|
|
|
|
}
|
2004-08-11 02:21:13 -04:00
|
|
|
|
|
|
|
if ( errors.size() > 0 )
|
|
|
|
{
|
|
|
|
throw new Exception( "Compilation error." );
|
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Resource copying
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
private void copyResources( String sourceDirectory, String destinationDirectory )
|
|
|
|
throws Exception
|
|
|
|
{
|
|
|
|
File sd = new File( sourceDirectory );
|
|
|
|
|
|
|
|
if ( !sd.exists() )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
List files = FileUtils.getFiles( sd, "**/**", "**/CVS/**", false );
|
|
|
|
|
|
|
|
for ( Iterator i = files.iterator(); i.hasNext(); )
|
|
|
|
{
|
|
|
|
File f = (File) i.next();
|
|
|
|
|
|
|
|
File source = new File( sourceDirectory, f.getPath() );
|
|
|
|
|
|
|
|
File dest = new File( destinationDirectory, f.getPath() );
|
|
|
|
|
|
|
|
if ( !dest.getParentFile().exists() )
|
|
|
|
{
|
|
|
|
dest.getParentFile().mkdirs();
|
|
|
|
}
|
|
|
|
|
|
|
|
FileUtils.copyFile( source, dest );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getArtifactPath( Dependency d, String pathSeparator )
|
|
|
|
{
|
|
|
|
return d.getArtifactDirectory() + pathSeparator + "jars" + pathSeparator + d.getArtifact();
|
|
|
|
}
|
|
|
|
|
|
|
|
private Properties loadProperties( File file )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return loadProperties( new FileInputStream( file ) );
|
|
|
|
}
|
|
|
|
catch ( Exception e )
|
|
|
|
{
|
|
|
|
// ignore
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Properties();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static Properties loadProperties( InputStream is )
|
|
|
|
{
|
|
|
|
Properties properties = new Properties();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if ( is != null )
|
|
|
|
{
|
|
|
|
properties.load( is );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch ( IOException e )
|
|
|
|
{
|
|
|
|
// ignore
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if ( is != null )
|
|
|
|
{
|
|
|
|
is.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch ( IOException e )
|
|
|
|
{
|
|
|
|
// ignore
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
|
|
|
|
class ModelReader
|
|
|
|
extends DefaultHandler
|
|
|
|
{
|
|
|
|
String artifactId;
|
|
|
|
|
|
|
|
String version;
|
|
|
|
|
|
|
|
String groupId;
|
|
|
|
|
|
|
|
String type;
|
|
|
|
|
|
|
|
private String parentGroupId;
|
|
|
|
|
|
|
|
private String parentArtifactId;
|
|
|
|
|
|
|
|
private String parentVersion;
|
|
|
|
|
|
|
|
private List dependencies = new ArrayList();
|
|
|
|
|
|
|
|
private UnitTests unitTests;
|
|
|
|
|
|
|
|
private List resources = new ArrayList();
|
|
|
|
|
|
|
|
private Dependency currentDependency;
|
|
|
|
|
|
|
|
private Resource currentResource;
|
|
|
|
|
|
|
|
private SAXParserFactory saxFactory;
|
|
|
|
|
|
|
|
private boolean insideParent = false;
|
|
|
|
|
|
|
|
private boolean insideDependency = false;
|
|
|
|
|
|
|
|
private boolean insideUnitTest = false;
|
|
|
|
|
|
|
|
private boolean insideResource = false;
|
|
|
|
|
|
|
|
private StringBuffer bodyText = new StringBuffer();
|
|
|
|
|
|
|
|
private File file;
|
|
|
|
|
|
|
|
public void reset()
|
|
|
|
{
|
|
|
|
dependencies = new ArrayList();
|
|
|
|
}
|
|
|
|
|
|
|
|
public List getDependencies()
|
|
|
|
{
|
|
|
|
return dependencies;
|
|
|
|
}
|
|
|
|
|
|
|
|
public UnitTests getUnitTests()
|
|
|
|
{
|
|
|
|
return unitTests;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List getResources()
|
|
|
|
{
|
|
|
|
return resources;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean parse( File file )
|
|
|
|
{
|
|
|
|
this.file = file;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
saxFactory = SAXParserFactory.newInstance();
|
|
|
|
|
|
|
|
SAXParser parser = saxFactory.newSAXParser();
|
|
|
|
|
|
|
|
InputSource is = new InputSource( new FileInputStream( file ) );
|
|
|
|
|
|
|
|
parser.parse( is, this );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch ( Exception e )
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void startElement( String uri, String localName, String rawName, Attributes attributes )
|
|
|
|
{
|
|
|
|
if ( rawName.equals( "parent" ) )
|
|
|
|
{
|
|
|
|
insideParent = true;
|
|
|
|
}
|
|
|
|
else if ( rawName.equals( "unitTest" ) )
|
|
|
|
{
|
|
|
|
unitTests = new UnitTests();
|
|
|
|
|
|
|
|
insideUnitTest = true;
|
|
|
|
}
|
|
|
|
else if ( rawName.equals( "dependency" ) )
|
|
|
|
{
|
|
|
|
currentDependency = new Dependency();
|
|
|
|
|
|
|
|
insideDependency = true;
|
|
|
|
}
|
|
|
|
else if ( rawName.equals( "resource" ) )
|
|
|
|
{
|
|
|
|
currentResource = new Resource();
|
|
|
|
|
|
|
|
insideResource = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void characters( char buffer[], int start, int length )
|
|
|
|
{
|
|
|
|
bodyText.append( buffer, start, length );
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getBodyText()
|
|
|
|
{
|
|
|
|
return bodyText.toString().trim();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void endElement( String uri, String localName, String rawName )
|
|
|
|
throws SAXException
|
|
|
|
{
|
|
|
|
// support both v3 <extend> and v4 <parent>
|
|
|
|
if ( rawName.equals( "parent" ) )
|
|
|
|
{
|
|
|
|
File f;
|
|
|
|
|
|
|
|
if ( parentArtifactId == null || parentArtifactId.trim().length() == 0 )
|
|
|
|
{
|
|
|
|
throw new SAXException( "Missing required element in <parent>: artifactId." );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( parentGroupId == null || parentGroupId.trim().length() == 0 )
|
|
|
|
{
|
|
|
|
throw new SAXException( "Missing required element in <parent>: groupId." );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( parentVersion == null || parentVersion.trim().length() == 0 )
|
|
|
|
{
|
|
|
|
throw new SAXException( "Missing required element in <parent>: version." );
|
|
|
|
}
|
|
|
|
|
|
|
|
f = new File( downloader.getMavenRepoLocal(), parentGroupId + "/poms/" + parentArtifactId + "-" + parentVersion + ".pom" );
|
|
|
|
|
|
|
|
ModelReader p = new ModelReader();
|
|
|
|
|
|
|
|
if ( !p.parse( f ) )
|
|
|
|
{
|
|
|
|
throw new SAXException( "Could not parse parent pom.xml" );
|
|
|
|
}
|
|
|
|
|
|
|
|
dependencies.addAll( p.getDependencies() );
|
|
|
|
|
|
|
|
unitTests = p.getUnitTests();
|
|
|
|
|
|
|
|
resources.addAll( p.getResources() );
|
|
|
|
|
|
|
|
insideParent = false;
|
|
|
|
}
|
|
|
|
else if ( rawName.equals( "unitTest" ) )
|
|
|
|
{
|
|
|
|
insideUnitTest = false;
|
|
|
|
}
|
|
|
|
else if ( rawName.equals( "dependency" ) )
|
|
|
|
{
|
|
|
|
dependencies.add( currentDependency );
|
|
|
|
|
|
|
|
insideDependency = false;
|
|
|
|
}
|
|
|
|
else if ( rawName.equals( "resource" ) )
|
|
|
|
{
|
|
|
|
if ( insideUnitTest )
|
|
|
|
{
|
|
|
|
unitTests.addResource( currentResource );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
resources.add( currentResource );
|
|
|
|
}
|
|
|
|
|
|
|
|
insideResource = false;
|
|
|
|
}
|
|
|
|
else if ( insideParent )
|
|
|
|
{
|
|
|
|
if ( rawName.equals( "groupId" ) )
|
|
|
|
{
|
|
|
|
parentGroupId = getBodyText();
|
|
|
|
}
|
|
|
|
else if ( rawName.equals( "artifactId" ) )
|
|
|
|
{
|
|
|
|
parentArtifactId = getBodyText();
|
|
|
|
}
|
|
|
|
else if ( rawName.equals( "version" ) )
|
|
|
|
{
|
|
|
|
parentVersion = getBodyText();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( insideDependency )
|
|
|
|
{
|
|
|
|
if ( rawName.equals( "id" ) )
|
|
|
|
{
|
|
|
|
currentDependency.setId( getBodyText() );
|
|
|
|
}
|
|
|
|
else if ( rawName.equals( "version" ) )
|
|
|
|
{
|
|
|
|
currentDependency.setVersion( getBodyText() );
|
|
|
|
}
|
|
|
|
else if ( rawName.equals( "jar" ) )
|
|
|
|
{
|
|
|
|
currentDependency.setJar( getBodyText() );
|
|
|
|
}
|
|
|
|
else if ( rawName.equals( "type" ) )
|
|
|
|
{
|
|
|
|
currentDependency.setType( getBodyText() );
|
|
|
|
}
|
|
|
|
else if ( rawName.equals( "groupId" ) )
|
|
|
|
{
|
|
|
|
currentDependency.setGroupId( getBodyText() );
|
|
|
|
}
|
|
|
|
else if ( rawName.equals( "artifactId" ) )
|
|
|
|
{
|
|
|
|
currentDependency.setArtifactId( getBodyText() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( insideResource )
|
|
|
|
{
|
|
|
|
if ( rawName.equals( "directory" ) )
|
|
|
|
{
|
|
|
|
currentResource.setDirectory( getBodyText() );
|
|
|
|
}
|
|
|
|
else if ( rawName.equals( "targetPath" ) )
|
|
|
|
{
|
|
|
|
currentResource.setTargetPath( getBodyText() );
|
|
|
|
}
|
|
|
|
else if ( rawName.equals( "include" ) )
|
|
|
|
{
|
|
|
|
currentResource.addInclude( getBodyText() );
|
|
|
|
}
|
|
|
|
else if ( rawName.equals( "exclude" ) )
|
|
|
|
{
|
|
|
|
currentResource.addExclude( getBodyText() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( !insideResource && insideUnitTest )
|
|
|
|
{
|
|
|
|
if ( rawName.equals( "include" ) )
|
|
|
|
{
|
|
|
|
unitTests.addInclude( getBodyText() );
|
|
|
|
}
|
|
|
|
else if ( rawName.equals( "exclude" ) )
|
|
|
|
{
|
|
|
|
unitTests.addExclude( getBodyText() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( rawName.equals( "artifactId" ) )
|
|
|
|
{
|
|
|
|
artifactId = getBodyText();
|
|
|
|
}
|
|
|
|
else if ( rawName.equals( "version" ) )
|
|
|
|
{
|
|
|
|
version = getBodyText();
|
|
|
|
}
|
|
|
|
else if ( rawName.equals( "groupId" ) )
|
|
|
|
{
|
|
|
|
groupId = getBodyText();
|
|
|
|
}
|
|
|
|
else if ( rawName.equals( "type" ) )
|
|
|
|
{
|
|
|
|
type = getBodyText();
|
|
|
|
}
|
|
|
|
|
|
|
|
bodyText = new StringBuffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void warning( SAXParseException spe )
|
|
|
|
{
|
|
|
|
printParseError( "Warning", spe );
|
|
|
|
}
|
|
|
|
|
|
|
|
public void error( SAXParseException spe )
|
|
|
|
{
|
|
|
|
printParseError( "Error", spe );
|
|
|
|
}
|
|
|
|
|
|
|
|
public void fatalError( SAXParseException spe )
|
|
|
|
{
|
|
|
|
printParseError( "Fatal Error", spe );
|
|
|
|
}
|
|
|
|
|
|
|
|
private final void printParseError( String type, SAXParseException spe )
|
|
|
|
{
|
|
|
|
System.err.println( type + " [line " + spe.getLineNumber() +
|
|
|
|
", row " + spe.getColumnNumber() + "]: " +
|
|
|
|
spe.getMessage() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class Dependency
|
|
|
|
{
|
|
|
|
private String id;
|
|
|
|
|
|
|
|
private String version;
|
|
|
|
|
|
|
|
private String url;
|
|
|
|
|
|
|
|
private String jar;
|
|
|
|
|
|
|
|
private String artifactId;
|
|
|
|
|
|
|
|
private String groupId;
|
|
|
|
|
|
|
|
private String type = "jar";
|
|
|
|
|
|
|
|
public Dependency()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setId( String id )
|
|
|
|
{
|
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getId()
|
|
|
|
{
|
|
|
|
if ( isValid( getGroupId() )
|
|
|
|
&& isValid( getArtifactId() ) )
|
|
|
|
{
|
|
|
|
return getGroupId() + ":" + getArtifactId();
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setGroupId( String groupId )
|
|
|
|
{
|
|
|
|
this.groupId = groupId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getGroupId()
|
|
|
|
{
|
|
|
|
return groupId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getArtifactDirectory()
|
|
|
|
{
|
|
|
|
if ( isValid( getGroupId() ) )
|
|
|
|
{
|
|
|
|
return getGroupId();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
// is when the <jar/> element is explicity used in the POM.
|
|
|
|
if ( jar != null )
|
|
|
|
{
|
|
|
|
return jar;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( isValid( getArtifactId() ) )
|
|
|
|
{
|
|
|
|
return getArtifactId() + "-" + getVersion() + "." + getType();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return getId() + "-" + getVersion() + "." + getType();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
// process. If we don't check an empty string will be set and
|
|
|
|
// screw up getArtifact() above.
|
|
|
|
if ( jar.trim().length() == 0 )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.jar = jar;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getJar()
|
|
|
|
{
|
|
|
|
return jar;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setUrl( String url )
|
|
|
|
{
|
|
|
|
this.url = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getUrl()
|
|
|
|
{
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getType()
|
|
|
|
{
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setType( String type )
|
|
|
|
{
|
|
|
|
this.type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isValid( String value )
|
|
|
|
{
|
|
|
|
if ( value != null
|
|
|
|
&& value.trim().equals( "" ) == false )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class UnitTests
|
|
|
|
implements Serializable
|
|
|
|
{
|
|
|
|
private String directory;
|
|
|
|
|
|
|
|
private List unitTestIncludes = new ArrayList();
|
|
|
|
|
|
|
|
private List unitTestExcludes = new ArrayList();
|
|
|
|
|
|
|
|
private List unitTestResources = new ArrayList();
|
|
|
|
|
|
|
|
public void addInclude( String pattern )
|
|
|
|
{
|
|
|
|
unitTestIncludes.add( pattern );
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addExclude( String pattern )
|
|
|
|
{
|
|
|
|
unitTestExcludes.add( pattern );
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addResource( Resource resource )
|
|
|
|
{
|
|
|
|
unitTestResources.add( resource );
|
|
|
|
}
|
|
|
|
|
|
|
|
public List getIncludes()
|
|
|
|
{
|
|
|
|
return unitTestIncludes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List getExcludes()
|
|
|
|
{
|
|
|
|
return unitTestExcludes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List getResources()
|
|
|
|
{
|
|
|
|
return unitTestResources;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDirectory( String directory )
|
|
|
|
{
|
|
|
|
this.directory = directory;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getDirectory()
|
|
|
|
{
|
|
|
|
return this.directory;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class Resource
|
|
|
|
implements Serializable
|
|
|
|
{
|
|
|
|
private String directory;
|
|
|
|
|
|
|
|
private String targetPath;
|
|
|
|
|
|
|
|
private List includes = new ArrayList();
|
|
|
|
|
|
|
|
private List excludes = new ArrayList();
|
|
|
|
|
|
|
|
private boolean filtering;
|
|
|
|
|
|
|
|
public void addInclude( String pattern )
|
|
|
|
{
|
|
|
|
this.includes.add( pattern );
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addExclude( String pattern )
|
|
|
|
{
|
|
|
|
this.excludes.add( pattern );
|
|
|
|
}
|
|
|
|
|
|
|
|
public List getIncludes()
|
|
|
|
{
|
|
|
|
return this.includes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List getExcludes()
|
|
|
|
{
|
|
|
|
return this.excludes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDirectory( String directory )
|
|
|
|
{
|
|
|
|
this.directory = directory;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getDirectory()
|
|
|
|
{
|
|
|
|
return this.directory;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTargetPath( String targetPath )
|
|
|
|
{
|
|
|
|
this.targetPath = targetPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getTargetPath()
|
|
|
|
{
|
|
|
|
return targetPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean getFiltering()
|
|
|
|
{
|
|
|
|
return filtering;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setFiltering( boolean filtering )
|
|
|
|
{
|
|
|
|
this.filtering = filtering;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|