2005-03-09 20:35:25 -05:00
|
|
|
import compile.CompilerConfiguration;
|
|
|
|
import compile.JavacCompiler;
|
|
|
|
import download.ArtifactDownloader;
|
|
|
|
import jar.JarMojo;
|
2005-04-03 21:36:58 -04:00
|
|
|
import model.Dependency;
|
|
|
|
import model.ModelReader;
|
2005-04-04 01:08:45 -04:00
|
|
|
import model.Repository;
|
2004-07-25 23:53:12 -04:00
|
|
|
import org.xml.sax.Attributes;
|
|
|
|
import org.xml.sax.SAXException;
|
2004-12-04 23:12:25 -05:00
|
|
|
import test.SurefirePlugin;
|
2005-04-03 21:36:58 -04:00
|
|
|
import util.AbstractReader;
|
2004-12-04 23:12:25 -05:00
|
|
|
import util.Commandline;
|
|
|
|
import util.FileUtils;
|
2005-03-31 05:54:32 -05:00
|
|
|
import util.IOUtil;
|
2004-12-04 23:12:25 -05:00
|
|
|
import util.IsolatedClassLoader;
|
|
|
|
import util.Os;
|
2004-07-25 23:53:12 -04:00
|
|
|
|
|
|
|
import java.io.File;
|
2004-08-15 00:30:20 -04:00
|
|
|
import java.io.FileNotFoundException;
|
2005-06-27 13:22:54 -04:00
|
|
|
import java.io.FileOutputStream;
|
2005-03-31 05:54:32 -05:00
|
|
|
import java.io.FileWriter;
|
2005-04-04 01:08:45 -04:00
|
|
|
import java.io.IOException;
|
2005-06-27 13:22:54 -04:00
|
|
|
import java.io.OutputStream;
|
2005-03-31 05:54:32 -05:00
|
|
|
import java.io.StringReader;
|
2005-03-07 14:03:19 -05:00
|
|
|
import java.lang.reflect.InvocationTargetException;
|
2004-07-25 23:53:12 -04:00
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
2005-04-04 10:35:06 -04:00
|
|
|
import java.util.Collection;
|
2005-03-09 17:13:07 -05:00
|
|
|
import java.util.Collections;
|
2004-10-23 09:31:15 -04:00
|
|
|
import java.util.Date;
|
2004-07-25 23:53:12 -04:00
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
2005-03-09 17:13:07 -05:00
|
|
|
import java.util.Map;
|
2005-06-27 13:22:54 -04:00
|
|
|
import java.util.Properties;
|
2005-03-09 17:13:07 -05:00
|
|
|
import java.util.TreeMap;
|
2004-07-25 23:53:12 -04:00
|
|
|
|
|
|
|
public class MBoot
|
|
|
|
{
|
2005-06-21 06:13:27 -04:00
|
|
|
String[] builds = new String[]{"maven-model", "maven-settings", "maven-monitor", "maven-plugin-api",
|
2005-07-15 15:04:20 -04:00
|
|
|
"maven-artifact", "maven-plugin-descriptor", "maven-artifact-manager", "maven-artifact-test",
|
2005-07-06 20:17:37 -04:00
|
|
|
"maven-plugin-mapping",
|
2005-08-16 12:31:02 -04:00
|
|
|
"maven-script/maven-script-beanshell", "maven-script/maven-script-marmalade", "maven-profile", "maven-project",
|
2005-07-21 02:54:21 -04:00
|
|
|
"maven-plugin-registry", "maven-reporting/maven-reporting-api", "maven-reporting/maven-reporting-impl", "maven-core", "maven-archiver",
|
2005-06-21 02:49:49 -04:00
|
|
|
"maven-plugin-tools/maven-plugin-tools-api", "maven-plugin-tools/maven-plugin-tools-java",
|
|
|
|
"maven-plugin-tools/maven-plugin-tools-beanshell", "maven-plugin-tools/maven-plugin-tools-pluggy",
|
2005-06-23 04:08:51 -04:00
|
|
|
"maven-plugin-tools/maven-plugin-tools-marmalade", "maven-core-it-verifier"};
|
2005-03-09 20:35:25 -05:00
|
|
|
|
2005-03-31 23:44:33 -05:00
|
|
|
String[] pluginBuilds = new String[]{"maven-plugins/maven-clean-plugin", "maven-plugins/maven-compiler-plugin",
|
2005-06-21 02:49:49 -04:00
|
|
|
"maven-plugins/maven-install-plugin", "maven-plugins/maven-jar-plugin", "maven-plugins/maven-plugin-plugin",
|
2005-06-23 12:23:07 -04:00
|
|
|
"maven-plugins/maven-resources-plugin", "maven-plugins/maven-surefire-plugin"};
|
2005-04-03 20:12:56 -04:00
|
|
|
|
2005-03-09 17:13:07 -05:00
|
|
|
private static final Map MODELLO_TARGET_VERSIONS;
|
2005-03-09 20:35:25 -05:00
|
|
|
|
2005-03-09 17:13:07 -05:00
|
|
|
private static final Map MODELLO_MODEL_FILES;
|
2005-03-09 20:35:25 -05:00
|
|
|
|
2005-06-21 02:49:49 -04:00
|
|
|
static {
|
2005-03-09 17:13:07 -05:00
|
|
|
Map targetVersions = new TreeMap();
|
|
|
|
targetVersions.put( "maven-model", "4.0.0" );
|
2005-03-16 01:29:35 -05:00
|
|
|
targetVersions.put( "maven-settings", "1.0.0" );
|
2005-05-31 12:24:34 -04:00
|
|
|
targetVersions.put( "maven-profile", "1.0.0" );
|
Working on issue: MNG-379
Added specified stop-gap patch for issue: MNG-473 (affects settings-builder and registry-builder)
Today I've made the following progress on this so far:
- Added a new project, called maven-plugin-registry, to house the model for this new file.
- Developed/debugged/tested PluginVersionManager/DefaultPluginVersionManager to isolate the plugin-version checks/management code away from the PluginManager
- Added interactiveMode (<interactiveMode>true|false</interactiveMode> directly under the root element of settings.xml, or -B short CLI option or --batch-mode CLI option, where the CLI options turn OFF interactiveMode). This will allow things like the maven-plugins build to register new plugins (and, for now, new versions of plugins) automatically.
- Added user input handler for when interactiveMode = true, to get a yes/no on whether to use the discovered version over the installed version and/or no version at all. If there is no installed version, and the user selects 'n', then the discovered version is used FOR THAT SESSION ONLY, and won't be recorded in the registry.
- Added checks/recording rejected versions against the registry, before attempting to use the discovered version.
Pending:
- Still need to add update-policies, to determine two things:
1. how often to check for updates
2. what to do when updates are found (autoUpdate, etc.)
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@190854 13f79535-47bb-0310-9956-ffa450edef68
2005-06-15 21:50:28 -04:00
|
|
|
targetVersions.put( "maven-plugin-registry", "1.0.0" );
|
2005-06-20 00:28:52 -04:00
|
|
|
targetVersions.put( "maven-plugin-descriptor", "1.0.0" );
|
2005-07-06 20:17:37 -04:00
|
|
|
targetVersions.put( "maven-plugin-mapping", "1.0.0" );
|
2005-03-09 20:35:25 -05:00
|
|
|
|
2005-03-09 17:13:07 -05:00
|
|
|
MODELLO_TARGET_VERSIONS = Collections.unmodifiableMap( targetVersions );
|
2005-03-09 20:35:25 -05:00
|
|
|
|
2005-03-09 17:13:07 -05:00
|
|
|
Map modelFiles = new TreeMap();
|
|
|
|
modelFiles.put( "maven-model", "maven.mdo" );
|
2005-03-16 01:29:35 -05:00
|
|
|
modelFiles.put( "maven-settings", "settings.mdo" );
|
2005-05-31 12:24:34 -04:00
|
|
|
modelFiles.put( "maven-profile", "profiles.mdo" );
|
Working on issue: MNG-379
Added specified stop-gap patch for issue: MNG-473 (affects settings-builder and registry-builder)
Today I've made the following progress on this so far:
- Added a new project, called maven-plugin-registry, to house the model for this new file.
- Developed/debugged/tested PluginVersionManager/DefaultPluginVersionManager to isolate the plugin-version checks/management code away from the PluginManager
- Added interactiveMode (<interactiveMode>true|false</interactiveMode> directly under the root element of settings.xml, or -B short CLI option or --batch-mode CLI option, where the CLI options turn OFF interactiveMode). This will allow things like the maven-plugins build to register new plugins (and, for now, new versions of plugins) automatically.
- Added user input handler for when interactiveMode = true, to get a yes/no on whether to use the discovered version over the installed version and/or no version at all. If there is no installed version, and the user selects 'n', then the discovered version is used FOR THAT SESSION ONLY, and won't be recorded in the registry.
- Added checks/recording rejected versions against the registry, before attempting to use the discovered version.
Pending:
- Still need to add update-policies, to determine two things:
1. how often to check for updates
2. what to do when updates are found (autoUpdate, etc.)
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@190854 13f79535-47bb-0310-9956-ffa450edef68
2005-06-15 21:50:28 -04:00
|
|
|
modelFiles.put( "maven-plugin-registry", "plugin-registry.mdo" );
|
2005-06-20 00:28:52 -04:00
|
|
|
modelFiles.put( "maven-plugin-descriptor", "src/main/mdo/lifecycle.mdo" );
|
2005-07-06 20:17:37 -04:00
|
|
|
modelFiles.put( "maven-plugin-mapping", "src/main/mdo/plugins.mdo" );
|
2005-03-09 20:35:25 -05:00
|
|
|
|
2005-03-09 17:13:07 -05:00
|
|
|
MODELLO_MODEL_FILES = Collections.unmodifiableMap( modelFiles );
|
|
|
|
}
|
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
|
|
|
|
2004-09-27 08:49:54 -04:00
|
|
|
private static final String GENERATED_DOCS = BUILD_DIR + "/generated-docs";
|
|
|
|
|
2004-07-25 23:53:12 -04:00
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Per-session entities which we can reuse while building many projects.
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
private ArtifactDownloader downloader;
|
|
|
|
|
2004-07-27 12:59:04 -04:00
|
|
|
private boolean online = true;
|
|
|
|
|
2004-07-25 23:53:12 -04:00
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
2005-03-09 20:35:25 -05:00
|
|
|
public static void main( String[] args )
|
|
|
|
throws Exception
|
2004-07-25 23:53:12 -04:00
|
|
|
{
|
2005-03-07 14:03:19 -05:00
|
|
|
try
|
|
|
|
{
|
|
|
|
MBoot mboot = new MBoot();
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2005-03-07 14:03:19 -05:00
|
|
|
mboot.run( args );
|
|
|
|
}
|
|
|
|
catch ( InvocationTargetException e )
|
|
|
|
{
|
|
|
|
Throwable target = e.getTargetException();
|
2005-03-09 17:13:07 -05:00
|
|
|
|
|
|
|
if ( target instanceof RuntimeException )
|
2005-03-07 14:03:19 -05:00
|
|
|
{
|
2005-03-09 17:13:07 -05:00
|
|
|
throw (RuntimeException) target;
|
2005-03-07 14:03:19 -05:00
|
|
|
}
|
2005-03-09 17:13:07 -05:00
|
|
|
else if ( target instanceof Exception )
|
2005-03-07 14:03:19 -05:00
|
|
|
{
|
2005-03-09 17:13:07 -05:00
|
|
|
throw (Exception) target;
|
2005-03-07 14:03:19 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-03-09 17:13:07 -05:00
|
|
|
throw new RuntimeException( target );
|
2005-03-07 14:03:19 -05:00
|
|
|
}
|
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
|
2005-03-09 20:35:25 -05:00
|
|
|
public void run( String[] args )
|
|
|
|
throws Exception
|
2004-07-25 23:53:12 -04:00
|
|
|
{
|
2004-12-23 18:46:42 -05:00
|
|
|
String mavenRepoLocal = System.getProperty( "maven.repo.local" );
|
|
|
|
|
2005-03-17 15:20:49 -05:00
|
|
|
SettingsReader userModelReader = new SettingsReader();
|
2005-03-17 01:11:17 -05:00
|
|
|
|
2005-05-05 03:45:42 -04:00
|
|
|
String userHome = System.getProperty( "user.home" );
|
2004-09-02 08:50:46 -04:00
|
|
|
|
2005-05-05 03:45:42 -04:00
|
|
|
File settingsXml = new File( userHome, ".m2/settings.xml" );
|
2005-03-09 20:35:25 -05:00
|
|
|
|
2005-05-05 03:45:42 -04:00
|
|
|
if ( settingsXml.exists() )
|
|
|
|
{
|
|
|
|
userModelReader.parse( settingsXml );
|
2004-12-23 18:46:42 -05:00
|
|
|
|
2005-08-04 05:42:09 -04:00
|
|
|
if ( mavenRepoLocal == null )
|
2005-08-04 02:30:13 -04:00
|
|
|
{
|
|
|
|
// user don't override mavenRepoLocal with maven.repo.local system property
|
|
|
|
mavenRepoLocal = userModelReader.getLocalRepository();
|
|
|
|
}
|
2004-12-23 18:46:42 -05:00
|
|
|
}
|
2004-09-02 08:50:46 -04:00
|
|
|
|
|
|
|
if ( mavenRepoLocal == null )
|
2004-07-26 21:19:41 -04:00
|
|
|
{
|
2005-03-10 11:35:04 -05:00
|
|
|
String m2LocalRepoPath = "/.m2/repository";
|
|
|
|
|
|
|
|
File repoDir = new File( userHome, m2LocalRepoPath );
|
|
|
|
if ( !repoDir.exists() )
|
|
|
|
{
|
|
|
|
repoDir.mkdirs();
|
|
|
|
}
|
|
|
|
|
|
|
|
mavenRepoLocal = repoDir.getAbsolutePath();
|
|
|
|
|
2005-03-17 18:59:07 -05:00
|
|
|
System.out.println(
|
|
|
|
"You SHOULD have a ~/.m2/settings.xml file and must contain at least the following information:" );
|
|
|
|
System.out.println();
|
2005-03-10 11:35:04 -05:00
|
|
|
|
2005-03-17 18:59:07 -05:00
|
|
|
System.out.println( "<settings>" );
|
2005-05-31 12:24:34 -04:00
|
|
|
System.out.println( " <localRepository>/path/to/your/repository</localRepository>" );
|
2005-03-17 18:59:07 -05:00
|
|
|
System.out.println( "</settings>" );
|
2004-12-23 18:46:42 -05:00
|
|
|
|
2004-09-02 08:50:46 -04:00
|
|
|
System.out.println();
|
2004-12-23 18:46:42 -05:00
|
|
|
|
2004-09-02 08:50:46 -04:00
|
|
|
System.out.println( "Alternatively, you can specify -Dmaven.repo.local=/path/to/m2/repository" );
|
2004-07-26 21:19:41 -04:00
|
|
|
|
2005-03-10 11:35:04 -05:00
|
|
|
System.out.println();
|
|
|
|
|
2005-06-21 02:49:49 -04:00
|
|
|
System.out.println(
|
|
|
|
"HOWEVER, since you did not specify a repository path, maven will use: " + repoDir.getAbsolutePath() +
|
|
|
|
" to store artifacts locally." );
|
2004-07-26 21:19:41 -04:00
|
|
|
}
|
2005-04-04 01:08:45 -04:00
|
|
|
|
|
|
|
File repoLocalFile = new File( mavenRepoLocal );
|
|
|
|
repoLocalFile.mkdirs();
|
|
|
|
|
|
|
|
if ( !repoLocalFile.canWrite() )
|
|
|
|
{
|
|
|
|
System.err.println( "Can't write to " + mavenRepoLocal );
|
|
|
|
|
|
|
|
System.exit( 1 );
|
|
|
|
}
|
2004-07-26 21:19:41 -04:00
|
|
|
|
2004-09-02 08:34:19 -04:00
|
|
|
String mavenHome = null;
|
2004-07-26 18:45:09 -04:00
|
|
|
|
2004-09-02 08:34:19 -04:00
|
|
|
if ( args.length == 1 )
|
|
|
|
{
|
|
|
|
mavenHome = args[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mavenHome = System.getProperty( "maven.home" );
|
|
|
|
|
|
|
|
if ( mavenHome == null )
|
|
|
|
{
|
|
|
|
mavenHome = new File( System.getProperty( "user.home" ), "m2" ).getAbsolutePath();
|
|
|
|
}
|
|
|
|
}
|
2004-07-26 18:45:09 -04:00
|
|
|
|
2004-09-02 08:34:19 -04:00
|
|
|
File dist = new File( mavenHome );
|
2004-07-26 21:19:41 -04:00
|
|
|
|
2004-09-02 08:34:19 -04:00
|
|
|
System.out.println( "Maven installation directory: " + dist );
|
2004-08-14 16:46:24 -04:00
|
|
|
|
2005-06-10 00:10:29 -04:00
|
|
|
if ( dist.exists() )
|
|
|
|
{
|
|
|
|
if ( !new File( dist, "bin/m2.conf" ).exists() )
|
|
|
|
{
|
2005-06-21 02:49:49 -04:00
|
|
|
System.err.println(
|
|
|
|
"The directory given to install Maven in already exists, but does not contain a Maven installation" );
|
2005-06-10 00:10:29 -04:00
|
|
|
System.err.println();
|
|
|
|
System.err.println( "\t" + dist );
|
|
|
|
System.err.println();
|
2005-06-21 02:49:49 -04:00
|
|
|
System.err.println(
|
|
|
|
"If you really mean to install Maven to this location, please delete the directory first" );
|
2005-06-10 00:10:29 -04:00
|
|
|
System.exit( 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-02 08:34:19 -04:00
|
|
|
Date fullStop;
|
2004-07-26 21:19:41 -04:00
|
|
|
|
2004-09-02 08:34:19 -04:00
|
|
|
Date fullStart = new Date();
|
2004-07-27 12:59:04 -04:00
|
|
|
|
2004-12-23 18:46:42 -05:00
|
|
|
String onlineProperty = System.getProperty( "maven.online" );
|
2004-07-27 12:59:04 -04:00
|
|
|
|
|
|
|
if ( onlineProperty != null && onlineProperty.equals( "false" ) )
|
|
|
|
{
|
|
|
|
online = false;
|
2004-07-26 21:19:41 -04:00
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2005-08-01 04:23:33 -04:00
|
|
|
Repository localRepository = new Repository( "local", mavenRepoLocal, Repository.LAYOUT_DEFAULT, false, false );
|
2005-04-04 01:08:45 -04:00
|
|
|
|
2005-04-03 21:36:58 -04:00
|
|
|
if ( online )
|
2005-03-17 01:11:17 -05:00
|
|
|
{
|
2005-05-05 02:24:07 -04:00
|
|
|
downloader = new ArtifactDownloader( localRepository );
|
2005-04-03 21:36:58 -04:00
|
|
|
if ( userModelReader.getActiveProxy() != null )
|
|
|
|
{
|
|
|
|
Proxy proxy = userModelReader.getActiveProxy();
|
|
|
|
downloader.setProxy( proxy.getHost(), proxy.getPort(), proxy.getUserName(), proxy.getPassword() );
|
|
|
|
}
|
2005-05-05 02:24:07 -04:00
|
|
|
|
|
|
|
List remoteRepos = downloader.getRemoteRepositories();
|
|
|
|
List newRemoteRepos = new ArrayList();
|
|
|
|
|
|
|
|
for ( Iterator i = remoteRepos.iterator(); i.hasNext(); )
|
|
|
|
{
|
|
|
|
Repository repo = (Repository) i.next();
|
|
|
|
|
|
|
|
boolean foundMirror = false;
|
|
|
|
for ( Iterator j = userModelReader.getMirrors().iterator(); j.hasNext() && !foundMirror; )
|
|
|
|
{
|
|
|
|
Mirror m = (Mirror) j.next();
|
|
|
|
if ( m.getMirrorOf().equals( repo.getId() ) )
|
|
|
|
{
|
2005-08-01 04:23:33 -04:00
|
|
|
newRemoteRepos.add( new Repository( m.getId(), m.getUrl(), repo.getLayout(), repo.isSnapshots(), repo.isReleases() ) );
|
2005-05-05 02:24:07 -04:00
|
|
|
foundMirror = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !foundMirror )
|
|
|
|
{
|
|
|
|
newRemoteRepos.add( repo );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
downloader.setRemoteRepositories( newRemoteRepos );
|
|
|
|
|
|
|
|
System.out.println( "Using the following for your local repository: " + localRepository );
|
|
|
|
System.out.println( "Using the following for your remote repository: " + newRemoteRepos );
|
2005-03-17 01:11:17 -05:00
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
|
|
|
|
String basedir = System.getProperty( "user.dir" );
|
|
|
|
|
2004-07-26 21:19:41 -04:00
|
|
|
// Install maven-components POM
|
2005-04-04 01:08:45 -04:00
|
|
|
installPomFile( localRepository, 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
|
2005-04-04 01:08:45 -04:00
|
|
|
installPomFile( localRepository, new File( basedir, "maven-plugins/pom.xml" ) );
|
2004-07-26 18:45:09 -04:00
|
|
|
|
2005-03-10 02:35:38 -05:00
|
|
|
// Install plugin-tools-parent POM
|
2005-04-04 01:08:45 -04:00
|
|
|
installPomFile( localRepository, new File( basedir, "maven-plugin-tools/pom.xml" ) );
|
2005-02-20 12:50:05 -05:00
|
|
|
|
2005-03-10 02:35:38 -05:00
|
|
|
// Install maven-script-parent POM
|
2005-04-04 01:08:45 -04:00
|
|
|
installPomFile( localRepository, new File( basedir, "maven-script/pom.xml" ) );
|
2005-03-10 02:35:38 -05:00
|
|
|
|
2005-05-13 03:01:57 -04:00
|
|
|
// Install maven-reporting parent POM
|
|
|
|
installPomFile( localRepository, new File( basedir, "maven-reporting/pom.xml" ) );
|
|
|
|
|
2005-04-04 10:35:06 -04:00
|
|
|
ModelReader reader = new ModelReader( downloader, true );
|
2005-04-04 01:23:01 -04:00
|
|
|
|
|
|
|
reader.parse( new File( basedir, "maven-mboot2/pom.xml" ) );
|
|
|
|
|
|
|
|
ClassLoader bootstrapClassLoader = createClassloaderFromDependencies( reader.getDependencies(), null,
|
|
|
|
localRepository );
|
|
|
|
|
2005-04-04 11:02:03 -04:00
|
|
|
reader = new ModelReader( downloader, false );
|
2005-04-04 01:23:01 -04:00
|
|
|
reader.parse( new File( basedir, "maven-plugins/maven-surefire-plugin/pom.xml" ) );
|
2005-04-04 01:31:29 -04:00
|
|
|
List surefireDependencies = new ArrayList();
|
|
|
|
|
|
|
|
// TODO: while we have maven-artifact in there, it needs to be filtered...
|
|
|
|
for ( Iterator i = reader.getDependencies().iterator(); i.hasNext(); )
|
|
|
|
{
|
|
|
|
Dependency d = (Dependency) i.next();
|
2005-04-04 01:41:57 -04:00
|
|
|
if ( d.getGroupId().equals( "surefire" ) || d.getGroupId().equals( "junit" ) )
|
2005-04-04 01:31:29 -04:00
|
|
|
{
|
|
|
|
surefireDependencies.add( d );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( online )
|
|
|
|
{
|
|
|
|
downloader.downloadDependencies( surefireDependencies );
|
|
|
|
}
|
2005-04-04 01:23:01 -04:00
|
|
|
|
2005-04-04 10:35:06 -04:00
|
|
|
reader = new ModelReader( downloader, true );
|
2005-04-04 01:23:01 -04:00
|
|
|
|
2005-04-04 10:35:06 -04:00
|
|
|
Collection coreDeps = null;
|
2005-04-04 01:08:45 -04:00
|
|
|
Dependency corePom = null;
|
2005-03-15 16:35:06 -05:00
|
|
|
|
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
|
|
|
|
2005-04-04 01:08:45 -04:00
|
|
|
reader = buildProject( directory, builds[i], bootstrapClassLoader, surefireDependencies, localRepository );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2005-04-03 21:36:58 -04:00
|
|
|
if ( reader.getArtifactId().equals( "maven-core" ) )
|
2004-07-26 18:02:58 -04:00
|
|
|
{
|
|
|
|
coreDeps = reader.getDependencies();
|
2005-04-04 01:08:45 -04:00
|
|
|
corePom = new Dependency( reader.getGroupId(), reader.getArtifactId(), reader.getVersion(),
|
|
|
|
reader.getPackaging() );
|
2004-07-26 18:02:58 -04:00
|
|
|
}
|
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
|
|
|
|
2005-04-04 10:35:06 -04:00
|
|
|
reader = new ModelReader( downloader, true );
|
2005-04-03 22:31:56 -04:00
|
|
|
reader.parse( new File( basedir, "maven-plugin-tools/maven-plugin-tools-pluggy/pom.xml" ) );
|
|
|
|
List dependencies = new ArrayList( reader.getDependencies() );
|
2005-04-04 01:08:45 -04:00
|
|
|
dependencies.add(
|
|
|
|
new Dependency( reader.getGroupId(), reader.getArtifactId(), reader.getVersion(), reader.getPackaging() ) );
|
|
|
|
IsolatedClassLoader cl = createClassloaderFromDependencies( dependencies, bootstrapClassLoader,
|
|
|
|
localRepository );
|
2005-02-24 00:12:30 -05:00
|
|
|
|
2004-08-09 14:57:50 -04:00
|
|
|
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 );
|
|
|
|
|
2005-04-04 01:08:45 -04:00
|
|
|
reader = buildProject( directory, pluginBuilds[i], cl, surefireDependencies, localRepository );
|
2004-08-09 14:57:50 -04:00
|
|
|
|
|
|
|
System.out.println( "--------------------------------------------------------------------" );
|
|
|
|
}
|
|
|
|
|
2004-07-26 18:02:58 -04:00
|
|
|
// build the installation
|
|
|
|
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-12-04 23:12:25 -05:00
|
|
|
FileUtils.copyFileToDirectory( new File( basedir, "maven-core/src/bin/m2.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
|
|
|
|
2005-04-04 17:26:20 -04:00
|
|
|
cli.execute().waitFor();
|
2004-07-26 18:02:58 -04:00
|
|
|
}
|
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
|
|
|
|
2005-04-03 21:36:58 -04:00
|
|
|
File core = new File( dist, "core" );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2005-04-03 21:36:58 -04:00
|
|
|
core.mkdirs();
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2005-04-03 21:36:58 -04:00
|
|
|
File boot = new File( dist, "core/boot" );
|
2004-10-23 09:31:15 -04:00
|
|
|
|
2005-04-03 21:36:58 -04:00
|
|
|
boot.mkdirs();
|
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
|
|
|
|
2005-04-03 21:36:58 -04:00
|
|
|
File lib = new File( dist, "lib" );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2005-04-03 21:36:58 -04:00
|
|
|
lib.mkdirs();
|
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
|
|
|
|
2005-04-04 01:08:45 -04:00
|
|
|
File source = localRepository.getArtifactFile( d );
|
2005-04-03 21:36:58 -04:00
|
|
|
if ( d.getArtifactId().equals( "classworlds" ) )
|
2004-07-25 23:53:12 -04:00
|
|
|
{
|
2005-04-03 21:36:58 -04:00
|
|
|
FileUtils.copyFileToDirectory( source, boot );
|
|
|
|
}
|
2005-06-21 02:49:49 -04:00
|
|
|
else if ( d.getArtifactId().equals( "plexus-container-default" ) ||
|
|
|
|
d.getArtifactId().equals( "plexus-utils" ) )
|
2005-04-03 21:36:58 -04:00
|
|
|
{
|
|
|
|
FileUtils.copyFileToDirectory( source, core );
|
|
|
|
}
|
2005-06-16 11:02:07 -04:00
|
|
|
else if ( !d.getScope().equals( Dependency.SCOPE_TEST ) )
|
2005-04-03 21:36:58 -04:00
|
|
|
{
|
2005-04-04 10:35:06 -04:00
|
|
|
// only compile and runtime
|
2005-04-03 21:36:58 -04:00
|
|
|
FileUtils.copyFileToDirectory( source, lib );
|
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
|
|
|
// Copy maven itself
|
2005-04-04 01:08:45 -04:00
|
|
|
FileUtils.copyFileToDirectory( localRepository.getArtifactFile( corePom ), lib );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-09-07 08:08:48 -04:00
|
|
|
System.out.println();
|
|
|
|
|
|
|
|
System.out.println( "Maven2 is installed in " + dist.getAbsolutePath() );
|
|
|
|
|
|
|
|
System.out.println( "--------------------------------------------------------------------" );
|
|
|
|
|
|
|
|
System.out.println();
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2005-04-04 01:08:45 -04:00
|
|
|
private ModelReader buildProject( String basedir, String projectId, ClassLoader classLoader,
|
|
|
|
List surefireDependencies, Repository localRepository )
|
2005-03-09 20:35:25 -05:00
|
|
|
throws Exception
|
2004-07-25 23:53:12 -04:00
|
|
|
{
|
|
|
|
System.out.println( "Building project in " + basedir );
|
|
|
|
|
2005-04-04 10:35:06 -04:00
|
|
|
ModelReader reader = new ModelReader( downloader, true );
|
2005-03-23 01:52:55 -05:00
|
|
|
|
2005-04-04 01:23:01 -04:00
|
|
|
reader.parse( new File( basedir, "pom.xml" ) );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
|
|
|
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:50:39 -04:00
|
|
|
FileUtils.forceDelete( buildDirFile );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-07-27 12:59:04 -04:00
|
|
|
if ( online )
|
|
|
|
{
|
2005-04-03 22:01:49 -04:00
|
|
|
System.out.println( "Downloading project dependencies ..." );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2005-04-03 21:36:58 -04:00
|
|
|
downloader.downloadDependencies( reader.getDependencies() );
|
2004-07-27 12:59:04 -04:00
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Generating sources
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
2005-03-09 17:13:07 -05:00
|
|
|
File base = new File( basedir );
|
2005-03-09 20:35:25 -05:00
|
|
|
|
|
|
|
String modelFileName = (String) MODELLO_MODEL_FILES.get( projectId );
|
|
|
|
|
2005-03-08 01:06:22 -05:00
|
|
|
File model = null;
|
2005-03-09 20:35:25 -05:00
|
|
|
if ( modelFileName != null && modelFileName.trim().length() > 0 )
|
2005-03-08 01:06:22 -05:00
|
|
|
{
|
2005-03-09 20:35:25 -05:00
|
|
|
model = new File( base, modelFileName );
|
2005-03-08 01:06:22 -05:00
|
|
|
}
|
2005-03-09 20:35:25 -05:00
|
|
|
|
2005-03-08 01:06:22 -05:00
|
|
|
if ( model != null && model.exists() )
|
2004-07-25 23:53:12 -04:00
|
|
|
{
|
|
|
|
System.out.println( "Model exists!" );
|
|
|
|
|
2005-03-09 20:35:25 -05:00
|
|
|
String modelVersion = (String) MODELLO_TARGET_VERSIONS.get( projectId );
|
|
|
|
if ( modelVersion == null || modelVersion.trim().length() < 1 )
|
2005-03-09 17:13:07 -05:00
|
|
|
{
|
2005-03-09 20:35:25 -05:00
|
|
|
System.out.println( "No model version configured. Using \'1.0.0\'..." );
|
2005-03-09 17:13:07 -05:00
|
|
|
modelVersion = "1.0.0";
|
|
|
|
}
|
2005-03-09 20:35:25 -05:00
|
|
|
|
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-09-27 08:49:54 -04:00
|
|
|
File generatedDocsDirectory = new File( basedir, GENERATED_DOCS );
|
|
|
|
|
|
|
|
if ( !generatedDocsDirectory.exists() )
|
|
|
|
{
|
|
|
|
generatedDocsDirectory.mkdirs();
|
|
|
|
}
|
2005-03-09 20:35:25 -05:00
|
|
|
|
|
|
|
System.out.println(
|
|
|
|
"Generating model bindings for version \'" + modelVersion + "\' in project: " + projectId );
|
|
|
|
|
2005-04-03 22:31:56 -04:00
|
|
|
generateSources( model.getAbsolutePath(), "java", generatedSources, modelVersion, "false", classLoader );
|
2005-04-03 21:36:58 -04:00
|
|
|
generateSources( model.getAbsolutePath(), "xpp3-reader", generatedSources, modelVersion, "false",
|
2005-04-03 22:31:56 -04:00
|
|
|
classLoader );
|
2005-04-03 21:36:58 -04:00
|
|
|
generateSources( model.getAbsolutePath(), "xpp3-writer", generatedSources, modelVersion, "false",
|
2005-04-03 22:31:56 -04:00
|
|
|
classLoader );
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Standard compile
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
System.out.println( "Compiling sources ..." );
|
|
|
|
|
|
|
|
if ( new File( generatedSources ).exists() )
|
|
|
|
{
|
2005-06-16 11:02:07 -04:00
|
|
|
compile( reader.getDependencies(), sources, classes, null, generatedSources, Dependency.SCOPE_COMPILE,
|
2005-04-04 01:08:45 -04:00
|
|
|
localRepository );
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-21 02:49:49 -04:00
|
|
|
compile( reader.getDependencies(), sources, classes, null, null, Dependency.SCOPE_COMPILE,
|
|
|
|
localRepository );
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Plugin descriptor generation
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
2005-04-03 21:36:58 -04:00
|
|
|
if ( reader.getPackaging().equals( "maven-plugin" ) )
|
2004-07-25 23:53:12 -04:00
|
|
|
{
|
|
|
|
System.out.println( "Generating maven plugin descriptor ..." );
|
|
|
|
|
2005-03-09 17:13:07 -05:00
|
|
|
generatePluginDescriptor( sources, new File( classes, "META-INF/maven" ).getAbsolutePath(),
|
2005-04-04 01:08:45 -04:00
|
|
|
new File( basedir, "pom.xml" ).getAbsolutePath(), classLoader, localRepository );
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Standard resources
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
System.out.println( "Packaging resources ..." );
|
|
|
|
|
|
|
|
copyResources( resources, classes );
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Test compile
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
System.out.println( "Compiling test sources ..." );
|
|
|
|
|
2005-04-05 00:11:03 -04:00
|
|
|
Collection testDependencies = new ArrayList( reader.getDependencies() );
|
2004-07-27 07:13:06 -04:00
|
|
|
|
2005-06-16 11:02:07 -04:00
|
|
|
compile( testDependencies, testSources, testClasses, classes, null, Dependency.SCOPE_TEST, localRepository );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Test resources
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
System.out.println( "Packaging test resources ..." );
|
|
|
|
|
|
|
|
copyResources( testResources, testClasses );
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Run tests
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
2005-04-04 01:08:45 -04:00
|
|
|
runTests( basedir, classes, testClasses, reader, surefireDependencies, localRepository );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Create JAR
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
2005-07-19 19:27:24 -04:00
|
|
|
createJar( new File( basedir, "pom.xml" ), classes, buildDir, reader );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2005-04-04 01:08:45 -04:00
|
|
|
installPom( basedir, localRepository, reader );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2005-04-13 01:11:49 -04:00
|
|
|
install( basedir, localRepository, reader, reader.getPackaging() );
|
2005-03-23 01:52:55 -05:00
|
|
|
|
|
|
|
return reader;
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
|
2005-04-04 01:08:45 -04:00
|
|
|
private void generatePluginDescriptor( String sourceDirectory, String outputDirectory, String pom, ClassLoader cl,
|
|
|
|
Repository localRepository )
|
2005-02-20 11:25:22 -05:00
|
|
|
throws Exception
|
|
|
|
{
|
2005-02-24 00:12:30 -05:00
|
|
|
Class cls = cl.loadClass( "org.apache.maven.tools.plugin.pluggy.Main" );
|
|
|
|
|
2005-03-09 20:35:25 -05:00
|
|
|
Method m = cls.getMethod( "main", new Class[]{String[].class} );
|
2005-02-24 00:12:30 -05:00
|
|
|
|
2005-04-04 01:08:45 -04:00
|
|
|
// Can pluggy really cope with the layout?
|
|
|
|
String[] args = {"descriptor", sourceDirectory, outputDirectory, pom, localRepository.getBasedir()};
|
2005-02-24 00:12:30 -05:00
|
|
|
|
2005-03-09 20:35:25 -05:00
|
|
|
m.invoke( null, new Object[]{args} );
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
|
2005-06-21 02:49:49 -04:00
|
|
|
private void generateSources( String model, String mode, String dir, String modelVersion, String packageWithVersion,
|
|
|
|
ClassLoader modelloClassLoader )
|
2004-07-25 23:53:12 -04:00
|
|
|
throws Exception
|
|
|
|
{
|
2004-09-26 09:29:06 -04:00
|
|
|
Class c = modelloClassLoader.loadClass( "org.codehaus.modello.ModelloCli" );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
|
|
|
Object generator = c.newInstance();
|
|
|
|
|
2005-03-09 20:35:25 -05:00
|
|
|
Method m = c.getMethod( "main", new Class[]{String[].class} );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2005-03-09 20:35:25 -05:00
|
|
|
String[] args = new String[]{model, mode, dir, modelVersion, packageWithVersion};
|
2004-07-25 23:53:12 -04:00
|
|
|
|
|
|
|
ClassLoader old = Thread.currentThread().getContextClassLoader();
|
|
|
|
|
2004-09-26 09:29:06 -04:00
|
|
|
Thread.currentThread().setContextClassLoader( modelloClassLoader );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2005-03-09 20:35:25 -05:00
|
|
|
m.invoke( generator, new Object[]{args} );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
|
|
|
Thread.currentThread().setContextClassLoader( old );
|
|
|
|
}
|
|
|
|
|
2005-04-04 10:35:06 -04:00
|
|
|
private IsolatedClassLoader createClassloaderFromDependencies( Collection dependencies, ClassLoader parent,
|
2005-04-04 01:08:45 -04:00
|
|
|
Repository localRepository )
|
2005-03-09 20:35:25 -05:00
|
|
|
throws Exception
|
2004-07-25 23:53:12 -04:00
|
|
|
{
|
2005-04-03 21:36:58 -04:00
|
|
|
if ( online )
|
|
|
|
{
|
|
|
|
System.out.println( "Checking for dependencies ..." );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2005-04-03 21:36:58 -04:00
|
|
|
downloader.downloadDependencies( dependencies );
|
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2005-04-03 22:31:56 -04:00
|
|
|
IsolatedClassLoader cl;
|
|
|
|
if ( parent == null )
|
|
|
|
{
|
|
|
|
cl = new IsolatedClassLoader();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cl = new IsolatedClassLoader( parent );
|
|
|
|
}
|
2005-04-03 21:36:58 -04:00
|
|
|
|
|
|
|
for ( Iterator i = dependencies.iterator(); i.hasNext(); )
|
|
|
|
{
|
|
|
|
Dependency dependency = (Dependency) i.next();
|
|
|
|
|
2005-04-04 01:08:45 -04:00
|
|
|
File f = localRepository.getArtifactFile( dependency );
|
2005-04-03 21:36:58 -04:00
|
|
|
if ( !f.exists() )
|
|
|
|
{
|
|
|
|
String msg = ( !online ? "; run again online" : "; there was a problem downloading it earlier" );
|
|
|
|
throw new FileNotFoundException( "Missing dependency: " + dependency + msg );
|
|
|
|
}
|
2005-03-09 00:48:31 -05:00
|
|
|
|
2005-04-03 22:01:49 -04:00
|
|
|
cl.addURL( f.toURL() );
|
2005-04-03 21:36:58 -04:00
|
|
|
}
|
|
|
|
|
2005-04-03 22:01:49 -04:00
|
|
|
return cl;
|
2005-03-09 00:48:31 -05:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:27:24 -04:00
|
|
|
private void createJar( File pomFile, String classes, String buildDir, ModelReader reader )
|
2005-03-09 20:35:25 -05:00
|
|
|
throws Exception
|
2004-07-25 23:53:12 -04:00
|
|
|
{
|
|
|
|
JarMojo jarMojo = new JarMojo();
|
|
|
|
|
2005-04-03 21:36:58 -04:00
|
|
|
String artifactId = reader.getArtifactId();
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2005-04-03 21:36:58 -04:00
|
|
|
String version = reader.getVersion();
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2005-06-27 13:22:54 -04:00
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Create pom.properties file
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
Properties p = new Properties();
|
|
|
|
|
|
|
|
p.setProperty( "groupId", reader.getGroupId() );
|
|
|
|
|
|
|
|
p.setProperty( "artifactId", reader.getArtifactId() );
|
|
|
|
|
|
|
|
p.setProperty( "version", reader.getVersion() );
|
|
|
|
|
|
|
|
File pomPropertiesDir = new File( new File( classes ),
|
|
|
|
"META-INF/maven/" + reader.getGroupId() + "/" + reader.getArtifactId() );
|
|
|
|
|
|
|
|
pomPropertiesDir.mkdirs();
|
|
|
|
|
|
|
|
File pomPropertiesFile = new File( pomPropertiesDir, "pom.properties" );
|
|
|
|
|
|
|
|
OutputStream os = new FileOutputStream( pomPropertiesFile );
|
|
|
|
|
|
|
|
p.store( os, "Generated by Maven" );
|
|
|
|
|
|
|
|
os.close(); // stream is flushed but not closed by Properties.store()
|
2005-07-19 19:27:24 -04:00
|
|
|
|
|
|
|
FileUtils.copyFile( pomFile, new File( pomPropertiesDir, "pom.xml" ) );
|
2005-06-27 13:22:54 -04:00
|
|
|
|
2004-07-25 23:53:12 -04:00
|
|
|
jarMojo.execute( new File( classes ), buildDir, artifactId + "-" + version );
|
|
|
|
}
|
|
|
|
|
2005-04-04 01:08:45 -04:00
|
|
|
private void installPomFile( Repository localRepository, File pomIn )
|
2005-03-09 20:35:25 -05:00
|
|
|
throws Exception
|
2004-07-26 21:19:41 -04:00
|
|
|
{
|
2005-04-04 10:35:06 -04:00
|
|
|
ModelReader reader = new ModelReader( downloader, false );
|
2005-03-23 01:52:55 -05:00
|
|
|
|
2005-04-04 01:23:01 -04:00
|
|
|
reader.parse( pomIn );
|
2004-07-26 21:19:41 -04:00
|
|
|
|
2005-04-04 01:08:45 -04:00
|
|
|
installPomFile( reader, localRepository, pomIn );
|
|
|
|
}
|
2004-07-26 21:19:41 -04:00
|
|
|
|
2005-04-04 01:08:45 -04:00
|
|
|
private void installPom( String basedir, Repository localRepository, ModelReader reader )
|
|
|
|
throws Exception
|
|
|
|
{
|
|
|
|
installPomFile( reader, localRepository, new File( basedir, "pom.xml" ) );
|
2004-07-26 21:19:41 -04:00
|
|
|
}
|
|
|
|
|
2005-04-04 01:08:45 -04:00
|
|
|
private void installPomFile( ModelReader reader, Repository localRepository, File source )
|
|
|
|
throws IOException
|
2004-07-25 23:53:12 -04:00
|
|
|
{
|
2005-04-03 21:36:58 -04:00
|
|
|
String artifactId = reader.getArtifactId();
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2005-04-03 21:36:58 -04:00
|
|
|
String version = reader.getVersion();
|
2005-03-23 01:52:55 -05:00
|
|
|
|
2005-04-03 21:36:58 -04:00
|
|
|
String groupId = reader.getGroupId();
|
2005-03-23 01:52:55 -05:00
|
|
|
|
2005-04-23 02:24:08 -04:00
|
|
|
File pom = localRepository.getMetadataFile( groupId, artifactId, version, reader.getPackaging(),
|
|
|
|
artifactId + "-" + version + ".pom" );
|
2004-07-26 18:45:09 -04:00
|
|
|
|
|
|
|
System.out.println( "Installing POM: " + pom );
|
|
|
|
|
2005-04-04 01:08:45 -04:00
|
|
|
FileUtils.copyFile( source, pom );
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
|
2005-04-04 01:08:45 -04:00
|
|
|
private void install( String basedir, Repository localRepository, ModelReader reader, String type )
|
2005-03-09 20:35:25 -05:00
|
|
|
throws Exception
|
2004-07-25 23:53:12 -04:00
|
|
|
{
|
2005-04-03 21:36:58 -04:00
|
|
|
String artifactId = reader.getArtifactId();
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2005-04-03 21:36:58 -04:00
|
|
|
String version = reader.getVersion();
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2005-04-03 21:36:58 -04:00
|
|
|
String groupId = reader.getGroupId();
|
2005-03-23 01:52:55 -05:00
|
|
|
|
2005-03-31 05:54:32 -05:00
|
|
|
String finalName = artifactId + "-" + version;
|
2004-07-26 21:19:41 -04:00
|
|
|
|
2005-04-04 01:08:45 -04:00
|
|
|
File file = localRepository.getArtifactFile( groupId, artifactId, version, type );
|
2004-07-26 21:19:41 -04:00
|
|
|
|
2005-03-31 05:54:32 -05:00
|
|
|
System.out.println( "Installing: " + file );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2005-03-31 05:54:32 -05:00
|
|
|
if ( version.indexOf( "SNAPSHOT" ) >= 0 )
|
2005-03-23 01:52:55 -05:00
|
|
|
{
|
2005-04-04 01:08:45 -04:00
|
|
|
File metadata = localRepository.getMetadataFile( groupId, artifactId, version, type,
|
|
|
|
finalName + ".version.txt" );
|
2005-03-23 01:52:55 -05:00
|
|
|
|
2005-04-23 02:24:08 -04:00
|
|
|
metadata.getParentFile().mkdirs();
|
|
|
|
|
2005-03-31 05:54:32 -05:00
|
|
|
IOUtil.copy( new StringReader( version ), new FileWriter( metadata ) );
|
2005-03-23 01:52:55 -05:00
|
|
|
}
|
2005-04-04 01:08:45 -04:00
|
|
|
|
|
|
|
FileUtils.copyFile( new File( basedir, BUILD_DIR + "/" + finalName + ".jar" ), file );
|
|
|
|
|
2005-05-10 11:04:06 -04:00
|
|
|
file = localRepository.getMetadataFile( groupId, artifactId, null, type, artifactId + "-RELEASE.version.txt" );
|
|
|
|
IOUtil.copy( new StringReader( version ), new FileWriter( file ) );
|
2004-08-09 14:57:50 -04:00
|
|
|
}
|
|
|
|
|
2005-04-03 22:57:27 -04:00
|
|
|
private void runTests( String basedir, String classes, String testClasses, ModelReader reader,
|
2005-04-04 01:08:45 -04:00
|
|
|
List surefireDependencies, Repository localRepository )
|
2005-03-09 20:35:25 -05:00
|
|
|
throws Exception
|
2004-07-25 23:53:12 -04:00
|
|
|
{
|
|
|
|
SurefirePlugin testRunner = new SurefirePlugin();
|
|
|
|
|
|
|
|
List includes;
|
|
|
|
|
|
|
|
List excludes;
|
|
|
|
|
2005-03-09 20:35:25 -05:00
|
|
|
includes = new ArrayList();
|
2004-07-27 07:24:04 -04:00
|
|
|
|
2005-03-09 20:35:25 -05:00
|
|
|
includes.add( "**/*Test.java" );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2005-03-09 20:35:25 -05:00
|
|
|
excludes = new ArrayList();
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2005-05-10 11:04:06 -04:00
|
|
|
excludes.add( "**/Abstract*Test.java" );
|
2005-03-17 18:59:07 -05:00
|
|
|
|
2005-03-23 01:52:55 -05:00
|
|
|
String reportsDir = new File( basedir, "target/surefire-reports" ).getAbsolutePath();
|
2005-03-17 18:59:07 -05:00
|
|
|
|
2005-04-03 22:57:27 -04:00
|
|
|
List depList = new ArrayList( reader.getDependencies() );
|
|
|
|
depList.addAll( surefireDependencies );
|
|
|
|
|
2005-06-16 11:02:07 -04:00
|
|
|
List classpath = classpath( depList, null, Dependency.SCOPE_TEST, localRepository );
|
2005-04-03 22:57:27 -04:00
|
|
|
classpath.add( classes );
|
|
|
|
classpath.add( testClasses );
|
2005-04-05 00:11:03 -04:00
|
|
|
|
2005-04-03 22:57:27 -04:00
|
|
|
boolean success = testRunner.execute( basedir, includes, excludes, classpath, reportsDir );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2004-08-11 02:21:13 -04:00
|
|
|
if ( !success )
|
|
|
|
{
|
2004-10-25 10:22:51 -04:00
|
|
|
throw new Exception( "Tests error" );
|
2004-08-11 02:21:13 -04:00
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Compile
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
2005-04-04 10:35:06 -04:00
|
|
|
private List classpath( Collection dependencies, String extraClasspath, String scope, Repository localRepository )
|
2004-07-25 23:53:12 -04:00
|
|
|
{
|
2005-04-03 22:01:49 -04:00
|
|
|
List classpath = new ArrayList( dependencies.size() + 1 );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2005-04-04 10:35:06 -04:00
|
|
|
for ( Iterator i = dependencies.iterator(); i.hasNext(); )
|
2004-07-25 23:53:12 -04:00
|
|
|
{
|
2005-04-04 10:35:06 -04:00
|
|
|
Dependency d = (Dependency) i.next();
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2005-04-04 01:08:45 -04:00
|
|
|
String element = localRepository.getArtifactFile( d ).getAbsolutePath();
|
2005-04-03 22:01:49 -04:00
|
|
|
|
2005-06-16 11:02:07 -04:00
|
|
|
if ( Dependency.SCOPE_COMPILE.equals( scope ) )
|
2005-04-03 22:01:49 -04:00
|
|
|
{
|
2005-06-16 11:02:07 -04:00
|
|
|
if ( d.getScope().equals( Dependency.SCOPE_COMPILE ) )
|
2005-04-03 22:01:49 -04:00
|
|
|
{
|
|
|
|
classpath.add( element );
|
|
|
|
}
|
|
|
|
}
|
2005-06-16 11:02:07 -04:00
|
|
|
else if ( Dependency.SCOPE_RUNTIME.equals( scope ) )
|
2005-04-03 22:01:49 -04:00
|
|
|
{
|
2005-06-21 02:49:49 -04:00
|
|
|
if ( d.getScope().equals( Dependency.SCOPE_COMPILE ) ||
|
|
|
|
d.getScope().equals( Dependency.SCOPE_RUNTIME ) )
|
2005-04-03 22:01:49 -04:00
|
|
|
{
|
|
|
|
classpath.add( element );
|
|
|
|
}
|
|
|
|
}
|
2005-06-16 11:02:07 -04:00
|
|
|
else if ( Dependency.SCOPE_TEST.equals( scope ) )
|
2005-04-03 22:01:49 -04:00
|
|
|
{
|
|
|
|
classpath.add( element );
|
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
|
2005-04-05 00:11:03 -04:00
|
|
|
if ( extraClasspath != null )
|
|
|
|
{
|
|
|
|
classpath.add( extraClasspath );
|
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
|
|
|
|
return classpath;
|
|
|
|
}
|
|
|
|
|
2005-04-04 10:35:06 -04:00
|
|
|
private void compile( Collection dependencies, String sourceDirectory, String outputDirectory,
|
|
|
|
String extraClasspath, String generatedSources, String scope, Repository localRepository )
|
2005-03-09 20:35:25 -05:00
|
|
|
throws Exception
|
2004-07-25 23:53:12 -04:00
|
|
|
{
|
|
|
|
JavacCompiler compiler = new JavacCompiler();
|
|
|
|
|
|
|
|
String[] sourceDirectories = null;
|
|
|
|
|
|
|
|
if ( generatedSources != null )
|
|
|
|
{
|
|
|
|
// We might only have generated sources
|
|
|
|
|
|
|
|
if ( new File( sourceDirectory ).exists() )
|
|
|
|
{
|
2005-03-09 20:35:25 -05:00
|
|
|
sourceDirectories = new String[]{sourceDirectory, generatedSources};
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-03-09 20:35:25 -05:00
|
|
|
sourceDirectories = new String[]{generatedSources};
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( new File( sourceDirectory ).exists() )
|
|
|
|
{
|
2005-03-09 20:35:25 -05:00
|
|
|
sourceDirectories = new String[]{sourceDirectory};
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( sourceDirectories != null )
|
|
|
|
{
|
2005-01-09 17:38:43 -05:00
|
|
|
CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
|
2005-02-24 00:12:30 -05:00
|
|
|
compilerConfiguration.setOutputLocation( outputDirectory );
|
2005-04-05 00:11:03 -04:00
|
|
|
List classpathEntries = classpath( dependencies, extraClasspath, scope, localRepository );
|
2005-04-12 17:13:24 -04:00
|
|
|
compilerConfiguration.setNoWarn( true );
|
2005-04-05 00:11:03 -04:00
|
|
|
compilerConfiguration.setClasspathEntries( classpathEntries );
|
2005-02-24 00:12:30 -05:00
|
|
|
compilerConfiguration.setSourceLocations( Arrays.asList( sourceDirectories ) );
|
|
|
|
|
2005-01-09 17:38:43 -05:00
|
|
|
/* Compile with debugging info */
|
2005-04-26 00:31:47 -04:00
|
|
|
String debugAsString = System.getProperty( "maven.compiler.debug", "true" );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
2005-04-26 00:31:47 -04:00
|
|
|
if ( !Boolean.valueOf( debugAsString ).booleanValue() )
|
2005-01-09 17:38:43 -05:00
|
|
|
{
|
2005-04-26 00:31:47 -04:00
|
|
|
compilerConfiguration.setDebug( false );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
compilerConfiguration.setDebug( true );
|
2005-01-09 17:38:43 -05:00
|
|
|
}
|
|
|
|
|
2005-02-24 00:12:30 -05:00
|
|
|
List messages = compiler.compile( compilerConfiguration );
|
2005-01-09 17:38:43 -05:00
|
|
|
|
|
|
|
for ( Iterator i = messages.iterator(); i.hasNext(); )
|
2004-07-25 23:53:12 -04:00
|
|
|
{
|
|
|
|
System.out.println( i.next() );
|
|
|
|
}
|
2004-08-11 02:21:13 -04:00
|
|
|
|
2005-01-09 17:38:43 -05:00
|
|
|
if ( messages.size() > 0 )
|
2004-08-11 02:21:13 -04:00
|
|
|
{
|
|
|
|
throw new Exception( "Compilation error." );
|
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
2005-04-03 21:36:58 -04:00
|
|
|
// model.Resource copying
|
2004-07-25 23:53:12 -04:00
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
2005-03-09 20:35:25 -05:00
|
|
|
private void copyResources( String sourceDirectory, String destinationDirectory )
|
|
|
|
throws Exception
|
2004-07-25 23:53:12 -04:00
|
|
|
{
|
|
|
|
File sd = new File( sourceDirectory );
|
|
|
|
|
|
|
|
if ( !sd.exists() )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-04-26 00:31:47 -04:00
|
|
|
List files = FileUtils.getFiles( sd, "**/**", "**/CVS/**,**/.svn/**", false );
|
2004-07-25 23:53:12 -04:00
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-16 01:29:35 -05:00
|
|
|
class SettingsReader
|
2005-03-09 17:13:07 -05:00
|
|
|
extends AbstractReader
|
|
|
|
{
|
2005-05-05 02:24:07 -04:00
|
|
|
private List mirrors = new ArrayList();
|
|
|
|
|
2005-03-17 01:11:17 -05:00
|
|
|
private List proxies = new ArrayList();
|
|
|
|
|
|
|
|
private Proxy currentProxy = null;
|
|
|
|
|
2005-03-09 17:13:07 -05:00
|
|
|
private StringBuffer currentBody = new StringBuffer();
|
|
|
|
|
2005-03-17 01:11:17 -05:00
|
|
|
private Proxy activeProxy = null;
|
|
|
|
|
2005-05-05 02:24:07 -04:00
|
|
|
private Mirror currentMirror;
|
2005-06-21 02:49:49 -04:00
|
|
|
|
2005-05-31 12:24:34 -04:00
|
|
|
private String localRepository;
|
2005-06-21 02:49:49 -04:00
|
|
|
|
2005-05-31 12:24:34 -04:00
|
|
|
public String getLocalRepository()
|
2004-07-25 23:53:12 -04:00
|
|
|
{
|
2005-05-31 12:24:34 -04:00
|
|
|
return localRepository;
|
2005-03-17 01:11:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public Proxy getActiveProxy()
|
|
|
|
{
|
|
|
|
return activeProxy;
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
|
2005-03-09 20:35:25 -05:00
|
|
|
public void characters( char[] ch, int start, int length )
|
|
|
|
throws SAXException
|
2004-07-25 23:53:12 -04:00
|
|
|
{
|
2005-03-09 17:13:07 -05:00
|
|
|
currentBody.append( ch, start, length );
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
|
2005-03-09 20:35:25 -05:00
|
|
|
public void endElement( String uri, String localName, String rawName )
|
|
|
|
throws SAXException
|
2004-07-25 23:53:12 -04:00
|
|
|
{
|
2005-05-31 12:24:34 -04:00
|
|
|
if ( "localRepository".equals( rawName ) )
|
2005-03-09 17:13:07 -05:00
|
|
|
{
|
2005-05-31 12:24:34 -04:00
|
|
|
if ( notEmpty( currentBody.toString() ) )
|
2005-03-09 17:13:07 -05:00
|
|
|
{
|
2005-05-31 12:24:34 -04:00
|
|
|
localRepository = currentBody.toString().trim();
|
2005-03-09 17:13:07 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-21 02:49:49 -04:00
|
|
|
throw new SAXException(
|
|
|
|
"Invalid profile entry. Missing one or more " + "fields: {localRepository}." );
|
2005-03-09 17:13:07 -05:00
|
|
|
}
|
|
|
|
}
|
2005-03-17 01:11:17 -05:00
|
|
|
else if ( "proxy".equals( rawName ) )
|
|
|
|
{
|
|
|
|
if ( notEmpty( currentProxy.getHost() ) && notEmpty( currentProxy.getPort() ) )
|
|
|
|
{
|
|
|
|
proxies.add( currentProxy );
|
|
|
|
currentProxy = null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-05-05 02:24:07 -04:00
|
|
|
throw new SAXException( "Invalid proxy entry. Missing one or more fields: {host, port}." );
|
2005-03-17 01:11:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( currentProxy != null )
|
|
|
|
{
|
|
|
|
if ( "active".equals( rawName ) )
|
|
|
|
{
|
2005-03-17 18:59:07 -05:00
|
|
|
currentProxy.setActive( Boolean.valueOf( currentBody.toString().trim() ).booleanValue() );
|
2005-03-17 01:11:17 -05:00
|
|
|
}
|
|
|
|
else if ( "host".equals( rawName ) )
|
|
|
|
{
|
|
|
|
currentProxy.setHost( currentBody.toString().trim() );
|
|
|
|
}
|
|
|
|
else if ( "port".equals( rawName ) )
|
|
|
|
{
|
|
|
|
currentProxy.setPort( currentBody.toString().trim() );
|
|
|
|
}
|
|
|
|
else if ( "username".equals( rawName ) )
|
|
|
|
{
|
|
|
|
currentProxy.setUserName( currentBody.toString().trim() );
|
|
|
|
}
|
|
|
|
else if ( "password".equals( rawName ) )
|
|
|
|
{
|
|
|
|
currentProxy.setPassword( currentBody.toString().trim() );
|
|
|
|
}
|
|
|
|
else if ( "protocol".equals( rawName ) )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else if ( "nonProxyHosts".equals( rawName ) )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new SAXException( "Illegal element inside proxy: \'" + rawName + "\'" );
|
|
|
|
}
|
|
|
|
}
|
2005-05-05 02:24:07 -04:00
|
|
|
else if ( "mirror".equals( rawName ) )
|
|
|
|
{
|
|
|
|
if ( notEmpty( currentMirror.getId() ) && notEmpty( currentMirror.getMirrorOf() ) &&
|
|
|
|
notEmpty( currentMirror.getUrl() ) )
|
|
|
|
{
|
|
|
|
mirrors.add( currentMirror );
|
|
|
|
currentMirror = null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new SAXException( "Invalid mirror entry. Missing one or more fields: {id, mirrorOf, url}." );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( currentMirror != null )
|
|
|
|
{
|
|
|
|
if ( "id".equals( rawName ) )
|
|
|
|
{
|
|
|
|
currentMirror.setId( currentBody.toString().trim() );
|
|
|
|
}
|
|
|
|
else if ( "mirrorOf".equals( rawName ) )
|
|
|
|
{
|
|
|
|
currentMirror.setMirrorOf( currentBody.toString().trim() );
|
|
|
|
}
|
|
|
|
else if ( "url".equals( rawName ) )
|
|
|
|
{
|
|
|
|
currentMirror.setUrl( currentBody.toString().trim() );
|
|
|
|
}
|
|
|
|
else if ( "name".equals( rawName ) )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new SAXException( "Illegal element inside proxy: \'" + rawName + "\'" );
|
|
|
|
}
|
|
|
|
}
|
2005-03-16 01:29:35 -05:00
|
|
|
else if ( "settings".equals( rawName ) )
|
2005-03-09 17:13:07 -05:00
|
|
|
{
|
2005-03-17 01:11:17 -05:00
|
|
|
if ( proxies.size() != 0 )
|
|
|
|
{
|
|
|
|
for ( Iterator it = proxies.iterator(); it.hasNext(); )
|
|
|
|
{
|
|
|
|
Proxy proxy = (Proxy) it.next();
|
2005-03-17 18:59:07 -05:00
|
|
|
if ( proxy.isActive() )
|
2005-03-16 01:29:35 -05:00
|
|
|
{
|
2005-03-17 01:11:17 -05:00
|
|
|
activeProxy = proxy;
|
2005-03-16 01:29:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-03-09 17:13:07 -05:00
|
|
|
}
|
2005-03-09 20:35:25 -05:00
|
|
|
|
2005-03-09 17:13:07 -05:00
|
|
|
currentBody = new StringBuffer();
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
|
2005-03-09 17:13:07 -05:00
|
|
|
private boolean notEmpty( String test )
|
2004-07-25 23:53:12 -04:00
|
|
|
{
|
2005-03-09 17:13:07 -05:00
|
|
|
return test != null && test.trim().length() > 0;
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
2005-03-09 17:13:07 -05:00
|
|
|
|
|
|
|
public void startElement( String uri, String localName, String rawName, Attributes attributes )
|
|
|
|
throws SAXException
|
|
|
|
{
|
2005-05-31 12:24:34 -04:00
|
|
|
if ( "proxy".equals( rawName ) )
|
2005-03-17 01:11:17 -05:00
|
|
|
{
|
|
|
|
currentProxy = new Proxy();
|
|
|
|
}
|
2005-05-05 02:24:07 -04:00
|
|
|
else if ( "mirror".equals( rawName ) )
|
|
|
|
{
|
|
|
|
currentMirror = new Mirror();
|
|
|
|
}
|
2005-03-09 17:13:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public void reset()
|
|
|
|
{
|
|
|
|
this.currentBody = null;
|
2005-03-17 01:11:17 -05:00
|
|
|
this.activeProxy = null;
|
2005-05-05 02:24:07 -04:00
|
|
|
this.currentMirror = null;
|
2005-05-31 12:24:34 -04:00
|
|
|
this.localRepository = null;
|
2005-03-17 01:11:17 -05:00
|
|
|
this.proxies.clear();
|
2005-05-05 02:24:07 -04:00
|
|
|
this.mirrors.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
public List getMirrors()
|
|
|
|
{
|
|
|
|
return mirrors;
|
2005-03-09 17:13:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-05 02:24:07 -04:00
|
|
|
public static class Proxy
|
2005-03-17 01:11:17 -05:00
|
|
|
{
|
|
|
|
private boolean active;
|
|
|
|
|
|
|
|
private String host;
|
|
|
|
|
|
|
|
private String port;
|
|
|
|
|
|
|
|
private String userName;
|
|
|
|
|
|
|
|
private String password;
|
|
|
|
|
|
|
|
public boolean isActive()
|
|
|
|
{
|
|
|
|
return active;
|
|
|
|
}
|
2005-03-09 17:13:07 -05:00
|
|
|
|
2005-03-17 01:11:17 -05:00
|
|
|
public void setActive( boolean active )
|
|
|
|
{
|
|
|
|
this.active = active;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setHost( String host )
|
|
|
|
{
|
|
|
|
this.host = host;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getHost()
|
|
|
|
{
|
|
|
|
return host;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPort( String port )
|
|
|
|
{
|
|
|
|
this.port = port;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getPort()
|
|
|
|
{
|
|
|
|
return port;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setUserName( String userName )
|
|
|
|
{
|
|
|
|
this.userName = userName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getUserName()
|
|
|
|
{
|
|
|
|
return userName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPassword( String password )
|
|
|
|
{
|
|
|
|
this.password = password;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getPassword()
|
|
|
|
{
|
|
|
|
return password;
|
|
|
|
}
|
2004-07-25 23:53:12 -04:00
|
|
|
}
|
|
|
|
|
2005-05-05 02:24:07 -04:00
|
|
|
public static class Mirror
|
|
|
|
{
|
|
|
|
private String id;
|
|
|
|
|
|
|
|
private String mirrorOf;
|
|
|
|
|
|
|
|
private String url;
|
|
|
|
|
|
|
|
public String getId()
|
|
|
|
{
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setId( String id )
|
|
|
|
{
|
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMirrorOf( String mirrorOf )
|
|
|
|
{
|
|
|
|
this.mirrorOf = mirrorOf;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setUrl( String url )
|
|
|
|
{
|
|
|
|
this.url = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getMirrorOf()
|
|
|
|
{
|
|
|
|
return mirrorOf;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getUrl()
|
|
|
|
{
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
}
|
2005-03-16 01:55:36 -05:00
|
|
|
}
|