o Added user.xml as the central point of config for local repository, both in MBoot2 and maven proper.

o Added proxy-profile support to user.xml


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163510 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-03-09 22:13:07 +00:00
parent 758a822cc2
commit 8d74f0acc4
10 changed files with 501 additions and 230 deletions

View File

@ -26,6 +26,8 @@ import org.apache.maven.execution.MavenReactorExecutionRequest;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.GoalNotFoundException;
import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.model.user.ProxyProfile;
import org.apache.maven.model.user.UserModel;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents;
import org.apache.maven.plugin.PluginManager;
@ -33,6 +35,7 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.reactor.ReactorException;
import org.apache.maven.util.UserModelUtils;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
@ -265,13 +268,8 @@ public class DefaultMaven
protected MavenSession createSession( MavenExecutionRequest request )
{
return new MavenSession( container,
pluginManager,
request.getUserModel(),
request.getLocalRepository(),
request.getEventDispatcher(),
request.getLog(),
request.getGoals() );
return new MavenSession( container, pluginManager, request.getUserModel(), request.getLocalRepository(),
request.getEventDispatcher(), request.getLog(), request.getGoals() );
}
/**
@ -282,28 +280,17 @@ public class DefaultMaven
{
WagonManager wagonManager = (WagonManager) container.lookup( WagonManager.ROLE );
if ( request.getParameter( "maven.proxy.http.host" ) != null )
UserModel userModel = request.getUserModel();
ProxyProfile proxyProfile = UserModelUtils.getActiveProxyProfile( userModel );
if ( proxyProfile != null )
{
String p = request.getParameter( "maven.proxy.http.port" );
int port = 8080;
if ( p != null )
{
try
{
port = Integer.valueOf( p ).intValue();
}
catch ( NumberFormatException e )
{
getLogger().warn( "maven.proxy.http.port was not valid" );
}
}
wagonManager.setProxy( "http",
request.getParameter( "maven.proxy.http.host" ),
port,
request.getParameter( "maven.proxy.http.username" ),
request.getParameter( "maven.proxy.http.password" ),
request.getParameter( "maven.proxy.http.nonProxyHosts" ) );
wagonManager.setProxy( proxyProfile.getProtocol(), proxyProfile.getHost(), proxyProfile.getPort(),
proxyProfile.getUsername(), proxyProfile.getPassword(),
proxyProfile.getNonProxyHosts() );
}
}
// ----------------------------------------------------------------------
@ -384,8 +371,9 @@ public class DefaultMaven
Runtime r = Runtime.getRuntime();
getLogger().info( "Final Memory: " + ((r.totalMemory() - r.freeMemory()) / mb) + "M/" + (r.totalMemory() / mb)
+ "M" );
getLogger().info(
"Final Memory: " + ( ( r.totalMemory() - r.freeMemory() ) / mb ) + "M/"
+ ( r.totalMemory() / mb ) + "M" );
}
protected void line()

View File

@ -33,6 +33,7 @@ import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.execution.MavenInitializingExecutionRequest;
import org.apache.maven.execution.MavenProjectExecutionRequest;
import org.apache.maven.execution.MavenReactorExecutionRequest;
import org.apache.maven.model.user.MavenProfile;
import org.apache.maven.model.user.UserModel;
import org.apache.maven.monitor.event.DefaultEventDispatcher;
import org.apache.maven.monitor.event.DefaultEventMonitor;
@ -62,8 +63,7 @@ public class MavenCli
public static File userDir = new File( System.getProperty( "user.dir" ) );
public static int main( String[] args, ClassWorld classWorld )
throws Exception
public static int main( String[] args, ClassWorld classWorld ) throws Exception
{
// ----------------------------------------------------------------------
// Setup the command line parser
@ -81,11 +81,11 @@ public class MavenCli
//
// ----------------------------------------------------------------------
File userConfigurationDirectory = getUserConfigurationDirectory();
// File userConfigurationDirectory = getUserConfigurationDirectory();
Properties mavenProperties = getMavenProperties( userConfigurationDirectory );
// Properties mavenProperties = getMavenProperties( userConfigurationDirectory );
ArtifactRepository localRepository = getLocalRepository( mavenProperties, userConfigurationDirectory );
ArtifactRepository localRepository = getLocalRepository();
// ----------------------------------------------------------------------
//
@ -117,11 +117,11 @@ public class MavenCli
MavenExecutionRequest request = null;
File projectFile = new File( userDir, POMv4 );
EventDispatcher eventDispatcher = new DefaultEventDispatcher();
UserModel userModel = UserModelUtils.getUserModel();
if ( projectFile.exists() )
{
if ( commandLine.hasOption( CLIManager.REACTOR ) )
@ -130,28 +130,19 @@ public class MavenCli
String excludes = System.getProperty( "maven.reactor.excludes", POMv4 );
request = new MavenReactorExecutionRequest( localRepository,
userModel,
eventDispatcher,
mavenProperties,
commandLine.getArgList(),
includes,
excludes,
userDir );
request = new MavenReactorExecutionRequest( localRepository, userModel, eventDispatcher,
commandLine.getArgList(), includes, excludes, userDir );
}
else
{
request = new MavenProjectExecutionRequest( localRepository,
userModel,
eventDispatcher,
mavenProperties,
commandLine.getArgList(),
projectFile );
request = new MavenProjectExecutionRequest( localRepository, userModel, eventDispatcher,
commandLine.getArgList(), projectFile );
}
}
else
{
request = new MavenInitializingExecutionRequest( localRepository, userModel, eventDispatcher, mavenProperties, commandLine.getArgList() );
request = new MavenInitializingExecutionRequest( localRepository, userModel, eventDispatcher,
commandLine.getArgList() );
}
// ----------------------------------------------------------------------
@ -174,10 +165,10 @@ public class MavenCli
if ( logger != null )
{
request.setLog( new DefaultLog( logger ) );
request.addEventMonitor( new DefaultEventMonitor( logger ) );
}
// TODO [BP]: doing this here as it is CLI specific, though it doesn't feel like the right place (likewise logger).
WagonManager wagonManager = (WagonManager) embedder.lookup( WagonManager.ROLE );
wagonManager.setDownloadMonitor( new ConsoleDownloadMonitor() );
@ -273,48 +264,30 @@ public class MavenCli
public CLIManager()
{
options = new Options();
options.addOption( OptionBuilder
.withLongOpt( "nobanner" )
.withDescription( "Suppress logo banner" )
.create( NO_BANNER ) );
options.addOption( OptionBuilder
.withLongOpt( "define" )
.hasArg()
.withDescription( "Define a system property" )
.create( SET_SYSTEM_PROPERTY ) );
options.addOption( OptionBuilder
.withLongOpt( "offline" )
.hasArg()
.withDescription( "Work offline" )
.create( WORK_OFFLINE ) );
options.addOption( OptionBuilder
.withLongOpt( "mojoDescriptors" )
.withDescription( "Display available mojoDescriptors" )
.create( LIST_GOALS ) );
options.addOption( OptionBuilder
.withLongOpt( "help" )
.withDescription( "Display help information" )
.create( HELP ) );
options.addOption( OptionBuilder
.withLongOpt( "offline" )
.withDescription( "Build is happening offline" )
.create( WORK_OFFLINE ) );
options.addOption( OptionBuilder
.withLongOpt( "version" )
.withDescription( "Display version information" )
.create( VERSION ) );
options.addOption( OptionBuilder
.withLongOpt( "debug" )
.withDescription( "Produce execution debug output" )
.create( DEBUG ) );
options.addOption( OptionBuilder
.withLongOpt( "reactor" )
.withDescription( "Execute goals for project found in the reactor" )
.create( REACTOR ) );
options.addOption( OptionBuilder.withLongOpt( "nobanner" ).withDescription( "Suppress logo banner" )
.create( NO_BANNER ) );
options
.addOption( OptionBuilder.withLongOpt( "define" ).hasArg()
.withDescription( "Define a system property" ).create( SET_SYSTEM_PROPERTY ) );
options.addOption( OptionBuilder.withLongOpt( "offline" ).hasArg().withDescription( "Work offline" )
.create( WORK_OFFLINE ) );
options
.addOption( OptionBuilder.withLongOpt( "mojoDescriptors" )
.withDescription( "Display available mojoDescriptors" ).create( LIST_GOALS ) );
options.addOption( OptionBuilder.withLongOpt( "help" ).withDescription( "Display help information" )
.create( HELP ) );
options.addOption( OptionBuilder.withLongOpt( "offline" ).withDescription( "Build is happening offline" )
.create( WORK_OFFLINE ) );
options.addOption( OptionBuilder.withLongOpt( "version" ).withDescription( "Display version information" )
.create( VERSION ) );
options.addOption( OptionBuilder.withLongOpt( "debug" ).withDescription( "Produce execution debug output" )
.create( DEBUG ) );
options.addOption( OptionBuilder.withLongOpt( "reactor" )
.withDescription( "Execute goals for project found in the reactor" )
.create( REACTOR ) );
}
public CommandLine parse( String[] args )
throws ParseException
public CommandLine parse( String[] args ) throws ParseException
{
CommandLineParser parser = new PosixParser();
return parser.parse( options, args );
@ -359,12 +332,20 @@ public class MavenCli
return mavenProperties;
}
protected static ArtifactRepository getLocalRepository( Properties mavenProperties,
File userConfigurationDirectory )
protected static ArtifactRepository getLocalRepository() throws Exception
{
String localRepository = mavenProperties.getProperty( MavenConstants.MAVEN_REPO_LOCAL );
UserModel userModel = UserModelUtils.getUserModel();
MavenProfile mavenProfile = UserModelUtils.getActiveMavenProfile( userModel );
String localRepository = null;
if ( mavenProfile != null )
{
localRepository = mavenProfile.getLocalRepository();
}
if ( localRepository == null )
{
String userConfigurationDirectory = System.getProperty( "user.home" );
localRepository = new File( userConfigurationDirectory, MavenConstants.MAVEN_REPOSITORY ).getAbsolutePath();
}
@ -372,4 +353,4 @@ public class MavenCli
System.setProperty( MavenConstants.MAVEN_REPO_LOCAL, localRepository );
return new ArtifactRepository( "local", "file://" + localRepository );
}
}
}

View File

@ -36,8 +36,6 @@ implements MavenExecutionRequest
/** @todo [BP] is this required? This hands off to MavenSession, but could be passed through the handler.handle function (+ createSession). */
protected ArtifactRepository localRepository;
protected final Properties parameters;
protected List goals;
protected String type;
@ -50,14 +48,12 @@ implements MavenExecutionRequest
private final UserModel userModel;
public AbstractMavenExecutionRequest( ArtifactRepository localRepository, UserModel userModel, EventDispatcher eventDispatcher, Properties parameters, List goals )
public AbstractMavenExecutionRequest( ArtifactRepository localRepository, UserModel userModel, EventDispatcher eventDispatcher, List goals )
{
this.localRepository = localRepository;
this.userModel = userModel;
this.parameters = parameters;
this.goals = goals;
this.eventDispatcher = eventDispatcher;
@ -83,11 +79,6 @@ implements MavenExecutionRequest
return type;
}
public String getParameter( String name )
{
return parameters.getProperty( name );
}
// ----------------------------------------------------------------------
// Putting the session here but it can probably be folded right in here.
// ----------------------------------------------------------------------

View File

@ -34,8 +34,6 @@ public interface MavenExecutionRequest
{
ArtifactRepository getLocalRepository();
String getParameter( String name );
List getGoals();
String getType();

View File

@ -22,7 +22,6 @@ import org.apache.maven.model.user.UserModel;
import org.apache.maven.monitor.event.EventDispatcher;
import java.util.List;
import java.util.Properties;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@ -31,9 +30,9 @@ import java.util.Properties;
public class MavenInitializingExecutionRequest
extends AbstractMavenExecutionRequest
{
public MavenInitializingExecutionRequest( ArtifactRepository localRepository, UserModel userModel, EventDispatcher eventDispatcher, Properties properties, List goals )
public MavenInitializingExecutionRequest( ArtifactRepository localRepository, UserModel userModel, EventDispatcher eventDispatcher, List goals )
{
super( localRepository, userModel, eventDispatcher, properties, goals );
super( localRepository, userModel, eventDispatcher, goals );
type = "initializing";
}

View File

@ -24,7 +24,6 @@ import org.apache.maven.monitor.event.EventDispatcher;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@ -38,11 +37,10 @@ extends AbstractMavenExecutionRequest
public MavenProjectExecutionRequest( ArtifactRepository localRepository,
UserModel userModel,
EventDispatcher eventDispatcher,
Properties properties,
List goals,
File pom )
{
super( localRepository, userModel, eventDispatcher, properties, goals );
super( localRepository, userModel, eventDispatcher, goals );
this.pom = pom;

View File

@ -42,10 +42,10 @@ extends AbstractMavenExecutionRequest
private File baseDirectory;
public MavenReactorExecutionRequest( ArtifactRepository localRepository, UserModel userModel, EventDispatcher eventDispatcher,
Properties properties, List goals, String includes,
List goals, String includes,
String excludes, File baseDirectory )
{
super( localRepository, userModel, eventDispatcher, properties, goals );
super( localRepository, userModel, eventDispatcher, goals );
this.includes = includes;
@ -79,6 +79,6 @@ extends AbstractMavenExecutionRequest
public MavenProjectExecutionRequest createProjectExecutionRequest( MavenProject project )
{
return new MavenProjectExecutionRequest( localRepository, getUserModel(), getEventDispatcher(), parameters, goals, project.getFile() );
return new MavenProjectExecutionRequest( localRepository, getUserModel(), getEventDispatcher(), goals, project.getFile() );
}
}

View File

@ -1,5 +1,8 @@
package org.apache.maven.util;
import org.apache.maven.model.user.DefaultProfiles;
import org.apache.maven.model.user.MavenProfile;
import org.apache.maven.model.user.ProxyProfile;
import org.apache.maven.model.user.ServerProfile;
import org.apache.maven.model.user.UserModel;
import org.apache.maven.model.user.io.xpp3.MavenUserModelXpp3Reader;
@ -20,10 +23,98 @@ public final class UserModelUtils
private static final String USER_MODEL_LOCATION = "/.m2/user.xml";
private static final String ACTIVE_MAVEN_PROFILE_ID_ENVAR = "maven.profile";
private UserModelUtils()
{
}
public static MavenProfile getActiveMavenProfile( UserModel userModel )
{
String activeProfileId = System.getProperty( ACTIVE_MAVEN_PROFILE_ID_ENVAR );
if ( activeProfileId == null || activeProfileId.trim().length() < 1 )
{
DefaultProfiles defaults = userModel.getDefaultProfiles();
if ( defaults != null )
{
activeProfileId = defaults.getMavenProfileId();
}
}
MavenProfile activeProfile = null;
if ( activeProfileId != null && activeProfileId.trim().length() > 0 )
{
activeProfile = UserModelUtils.getMavenProfile( userModel, activeProfileId );
}
return activeProfile;
}
public static ProxyProfile getActiveProxyProfile( UserModel userModel )
{
String activeProfileId = System.getProperty( ACTIVE_MAVEN_PROFILE_ID_ENVAR );
if ( activeProfileId == null || activeProfileId.trim().length() < 1 )
{
DefaultProfiles defaults = userModel.getDefaultProfiles();
if ( defaults != null )
{
activeProfileId = defaults.getProxyProfileId();
}
}
ProxyProfile activeProfile = null;
if ( activeProfileId != null && activeProfileId.trim().length() > 0 )
{
activeProfile = UserModelUtils.getProxyProfile( userModel, activeProfileId );
}
return activeProfile;
}
public static MavenProfile getMavenProfile( UserModel userModel, String mavenProfileId )
{
MavenProfile result = null;
List mavenProfiles = userModel.getMavenProfiles();
if ( mavenProfiles != null )
{
for ( Iterator it = mavenProfiles.iterator(); it.hasNext(); )
{
MavenProfile profile = (MavenProfile) it.next();
if ( mavenProfileId.equals( profile.getId() ) )
{
result = profile;
break;
}
}
}
return result;
}
public static ProxyProfile getProxyProfile( UserModel userModel, String proxyProfileId )
{
ProxyProfile result = null;
List proxyProfile = userModel.getProxyProfiles();
if ( proxyProfile != null )
{
for ( Iterator it = proxyProfile.iterator(); it.hasNext(); )
{
ProxyProfile profile = (ProxyProfile) it.next();
if ( proxyProfileId.equals( profile.getId() ) )
{
result = profile;
break;
}
}
}
return result;
}
public static ServerProfile getServerProfile( UserModel userModel, String serverProfileId )
{
ServerProfile result = null;

View File

@ -1,21 +1,25 @@
import compile.CompilerConfiguration;
import compile.JavacCompiler;
import download.ArtifactDownloader;
import jar.JarMojo;
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 test.SurefirePlugin;
import util.Commandline;
import util.FileUtils;
import util.IsolatedClassLoader;
import util.Os;
import compile.CompilerConfiguration;
import compile.JavacCompiler;
import download.ArtifactDownloader;
import jar.JarMojo;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@ -24,10 +28,12 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Map;
import java.util.TreeMap;
public class MBoot
{
@ -103,6 +109,25 @@ public class MBoot
"maven-plugins/maven-resources-plugin",
"maven-plugins/maven-surefire-plugin",
"maven-plugins/maven-war-plugin" };
private static final Map MODELLO_TARGET_VERSIONS;
private static final Map MODELLO_MODEL_FILES;
static
{
Map targetVersions = new TreeMap();
targetVersions.put( "maven-model", "4.0.0" );
targetVersions.put( "maven-user-model", "1.0.0" );
MODELLO_TARGET_VERSIONS = Collections.unmodifiableMap( targetVersions );
Map modelFiles = new TreeMap();
modelFiles.put( "maven-model", "maven.mdo" );
modelFiles.put( "maven-user-model", "maven-user.mdo" );
MODELLO_MODEL_FILES = Collections.unmodifiableMap( modelFiles );
}
// ----------------------------------------------------------------------
// Standard locations for resources in Maven projects.
@ -133,7 +158,7 @@ public class MBoot
private ArtifactDownloader downloader;
private ModelReader reader;
private String repoLocal;
private List mbootDependencies;
@ -157,18 +182,18 @@ public class MBoot
catch ( InvocationTargetException e )
{
Throwable target = e.getTargetException();
if(target instanceof RuntimeException)
if ( target instanceof RuntimeException )
{
throw (RuntimeException)target;
throw (RuntimeException) target;
}
else if(target instanceof Exception)
else if ( target instanceof Exception )
{
throw (Exception)target;
throw (Exception) target;
}
else
{
throw new RuntimeException(target);
throw new RuntimeException( target );
}
}
}
@ -181,26 +206,41 @@ public class MBoot
if ( mavenRepoLocal == null )
{
Properties p = new Properties();
UserModelReader userModelReader = new UserModelReader();
try
{
String userHome = System.getProperty( "user.home" );
p.load( new FileInputStream( new File( userHome, ".m2/maven.properties" ) ) );
userModelReader.parse( new File( userHome, ".m2/user.xml" ) );
MavenProfile activeProfile = userModelReader.getActiveMavenProfile();
mavenRepoLocal = new File( p.getProperty( "maven.repo.local" ) ).getAbsolutePath();
mavenRepoLocal = new File( activeProfile.getLocalRepo() ).getAbsolutePath();
}
catch ( Exception e )
{
e.printStackTrace();
}
}
if ( mavenRepoLocal == null )
{
System.out.println( "You must have a ~/.m2/maven.properties file and must contain the following entries:" );
System.out.println( "You must have a ~/.m2/user.xml file and must contain at least the following information:\n" );
System.out.println( "maven.repo.local = /path/to/your/repository" );
System.out.println( "<userModel>\n " +
"<mavenProfiles>\n " +
"<mavenProfile>\n " +
"<id>someId</id>\n " +
"<localRepository>/path/to/your/repository</localRepository>\n " +
"</mavenProfile>\n " +
"</mavenProfiles>\n " +
"<defaultProfiles>\n " +
"<mavenProfileId>someId</mavenProfileId>\n " +
"</defaultProfiles>\n" +
"</userModel>\n" );
System.out.println("where \'someId\' is just an id for matching within the file.");
System.out.println();
@ -277,7 +317,7 @@ public class MBoot
System.setProperty( "basedir", directory );
buildProject( directory );
buildProject( directory, builds[i] );
if ( reader.artifactId.equals( "maven-core" ) )
{
@ -301,7 +341,7 @@ public class MBoot
System.setProperty( "basedir", directory );
buildProject( directory );
buildProject( directory, pluginBuilds[i] );
reader.reset();
@ -430,7 +470,7 @@ public class MBoot
System.out.println( "Finished at: " + fullStop );
}
public void buildProject( String basedir ) throws Exception
public void buildProject( String basedir, String projectId ) throws Exception
{
System.out.println( "Building project in " + basedir );
@ -479,24 +519,27 @@ public class MBoot
// Generating sources
// ----------------------------------------------------------------------
File base = new File(basedir);
File base = new File( basedir );
String[] basedirFiles = base.list();
String modelFileName = (String)MODELLO_MODEL_FILES.get( projectId );
File model = null;
for ( int i = 0; i < basedirFiles.length; i++ )
if(modelFileName != null && modelFileName.trim().length() > 0)
{
if(basedirFiles[i].endsWith(".mdo"))
{
model = new File(base, basedirFiles[i]);
break;
}
model = new File(base, modelFileName);
}
if ( model != null && model.exists() )
{
System.out.println( "Model exists!" );
String modelVersion = (String)MODELLO_TARGET_VERSIONS.get( projectId );
if(modelVersion == null || modelVersion.trim().length() < 1)
{
System.out.println("No model version configured. Using \'1.0.0\'...");
modelVersion = "1.0.0";
}
File generatedSourcesDirectory = new File( basedir, GENERATED_SOURCES );
if ( !generatedSourcesDirectory.exists() )
@ -510,23 +553,25 @@ public class MBoot
{
generatedDocsDirectory.mkdirs();
}
generateSources( model.getAbsolutePath(), "java", generatedSources, "4.0.0", "false" );
System.out.println("Generating model bindings for version \'" + modelVersion + "\' in project: " + projectId);
generateSources( model.getAbsolutePath(), "java", generatedSources, modelVersion, "false" );
//generateSources( model.getAbsolutePath(), "java",
// generatedSources, "3.0.0", "true" );
generateSources( model.getAbsolutePath(), "xpp3-reader", generatedSources, "4.0.0", "false" );
generateSources( model.getAbsolutePath(), "xpp3-reader", generatedSources, modelVersion, "false" );
//generateSources( model.getAbsolutePath(), "xpp3-reader",
// generatedSources, "3.0.0", "true" );
generateSources( model.getAbsolutePath(), "xpp3-writer", generatedSources, "4.0.0", "false" );
generateSources( model.getAbsolutePath(), "xpp3-writer", generatedSources, modelVersion, "false" );
//generateSources( model.getAbsolutePath(), "xpp3-writer",
// generatedSources, "3.0.0", "true" );
generateSources( model.getAbsolutePath(), "xdoc", generatedDocs, "4.0.0", "false" );
generateSources( model.getAbsolutePath(), "xdoc", generatedDocs, modelVersion, "false" );
//generateSources( model.getAbsolutePath(), "xdoc", generatedDocs,
// "3.0.0", "true" );
@ -555,8 +600,7 @@ public class MBoot
{
System.out.println( "Generating maven plugin descriptor ..." );
generatePluginDescriptor( sources,
new File( classes, "META-INF/maven" ).getAbsolutePath(),
generatePluginDescriptor( sources, new File( classes, "META-INF/maven" ).getAbsolutePath(),
new File( basedir, "pom.xml" ).getAbsolutePath() );
}
@ -634,7 +678,7 @@ public class MBoot
if ( !f.exists() )
{
throw new FileNotFoundException( "Missing dependency: " + dependency
+ (!online ? "; run again online" : "; there was a problem downloading it earlier") );
+ ( !online ? "; run again online" : "; there was a problem downloading it earlier" ) );
}
cl.addURL( f.toURL() );
@ -651,7 +695,7 @@ public class MBoot
if ( !f.exists() )
{
throw new FileNotFoundException( "Missing dependency: " + dependency
+ (!online ? "; run again online" : "; there was a problem downloading it earlier") );
+ ( !online ? "; run again online" : "; there was a problem downloading it earlier" ) );
}
cl.addURL( f.toURL() );
@ -683,7 +727,7 @@ public class MBoot
if ( !f.exists() )
{
throw new FileNotFoundException( "Missing dependency: " + dependency
+ (!online ? "; run again online" : "; there was a problem downloading it earlier") );
+ ( !online ? "; run again online" : "; there was a problem downloading it earlier" ) );
}
modelloClassLoader.addURL( f.toURL() );
@ -834,12 +878,7 @@ public class MBoot
excludes.add( "**/*Abstract*.java" );
}
boolean success = testRunner.execute( repoLocal,
basedir,
classes,
testClasses,
includes,
excludes,
boolean success = testRunner.execute( repoLocal, basedir, classes, testClasses, includes, excludes,
classpath( reader.getDependencies(), null ) );
if ( !success )
@ -887,7 +926,7 @@ public class MBoot
}
private void compile( List dependencies, String sourceDirectory, String outputDirectory, String extraClasspath,
String generatedSources ) throws Exception
String generatedSources ) throws Exception
{
JavacCompiler compiler = new JavacCompiler();
@ -984,9 +1023,62 @@ public class MBoot
{
return d.getArtifactDirectory() + pathSeparator + d.getType() + "s" + pathSeparator + d.getArtifact();
}
abstract class AbstractReader extends DefaultHandler
{
private File file;
private SAXParserFactory saxFactory;
public abstract void reset();
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 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() );
}
}
class ModelReader
extends DefaultHandler
extends AbstractReader
{
int depth = 0;
@ -1016,8 +1108,6 @@ public class MBoot
private Resource currentResource;
private SAXParserFactory saxFactory;
private boolean insideParent = false;
private boolean insideDependency = false;
@ -1030,8 +1120,6 @@ public class MBoot
private StringBuffer bodyText = new StringBuffer();
private File file;
public void reset()
{
dependencies = new ArrayList();
@ -1057,30 +1145,6 @@ public class MBoot
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" ) )
@ -1109,7 +1173,7 @@ public class MBoot
insideResource = true;
}
depth ++;
depth++;
}
public void characters( char buffer[], int start, int length )
@ -1290,29 +1354,127 @@ public class MBoot
bodyText = new StringBuffer();
depth --;
depth--;
}
}
class UserModelReader
extends AbstractReader
{
private Map mavenProfiles = new TreeMap();
private MavenProfile currentProfile = null;
private StringBuffer currentBody = new StringBuffer();
private String activeProfileId = null;
private MavenProfile activeMavenProfile = null;
public MavenProfile getActiveMavenProfile()
{
return activeMavenProfile;
}
public void warning( SAXParseException spe )
public void characters( char[] ch, int start, int length ) throws SAXException
{
printParseError( "Warning", spe );
currentBody.append( ch, start, length );
}
public void error( SAXParseException spe )
public void endElement( String uri, String localName, String rawName ) throws SAXException
{
printParseError( "Error", spe );
if ( "mavenProfile".equals( rawName ) )
{
if ( notEmpty( currentProfile.getId() ) && notEmpty( currentProfile.getLocalRepo() ) )
{
mavenProfiles.put( currentProfile.getId(), currentProfile );
currentProfile = null;
}
else
{
throw new SAXException( "Invalid mavenProfile entry. Missing one or more "
+ "fields: {id,localRepository}." );
}
}
else if ( currentProfile != null )
{
if ( "id".equals( rawName ) )
{
currentProfile.setId( currentBody.toString().trim() );
}
else if ( "localRepository".equals( rawName ) )
{
currentProfile.setLocalRepo( currentBody.toString().trim() );
}
else
{
throw new SAXException( "Illegal element inside mavenProfile: \'" + rawName + "\'" );
}
}
else if ( "userModel".equals( rawName ) )
{
this.activeMavenProfile = (MavenProfile) mavenProfiles.get( activeProfileId );
}
else if ( "mavenProfileId".equals( rawName ) )
{
this.activeProfileId = currentBody.toString().trim();
}
currentBody = new StringBuffer();
}
public void fatalError( SAXParseException spe )
private boolean notEmpty( String test )
{
printParseError( "Fatal Error", spe );
return test != null && test.trim().length() > 0;
}
private final void printParseError( String type, SAXParseException spe )
public void startElement( String uri, String localName, String rawName, Attributes attributes )
throws SAXException
{
System.err.println( type + " [line " + spe.getLineNumber() + ", row " + spe.getColumnNumber() + "]: "
+ spe.getMessage() );
if ( "mavenProfile".equals( rawName ) )
{
currentProfile = new MavenProfile();
}
}
public void reset()
{
this.currentBody = null;
this.activeMavenProfile = null;
this.activeProfileId = null;
this.currentProfile = null;
this.mavenProfiles.clear();
}
}
public static class MavenProfile
{
private String localRepo;
private String id;
public void setLocalRepo( String localRepo )
{
this.localRepo = localRepo;
}
public String getLocalRepo()
{
return localRepo;
}
public void setId( String id )
{
this.id = id;
}
public String getId()
{
return id;
}
}
public static class Dependency
@ -1585,4 +1747,4 @@ public class MBoot
this.filtering = filtering;
}
}
}
}

View File

@ -11,20 +11,29 @@
<classes>
<class rootElement="true">
<name>UserModel</name>
<version>4.0.0</version>
<version>1.0.0</version>
<fields>
<field>
<name>jdkProfiles</name>
<version>4.0.0</version>
<version>1.0.0</version>
<description><![CDATA[Configuration for different java environment profiles.]]></description>
<association>
<type>JdkProfile</type>
<multiplicity>*</multiplicity>
</association>
</field>
<field>
<name>proxyProfiles</name>
<version>1.0.0</version>
<description><![CDATA[Configuration for different proxy profiles.]]></description>
<association>
<type>ProxyProfile</type>
<multiplicity>*</multiplicity>
</association>
</field>
<field>
<name>serverProfiles</name>
<version>4.0.0</version>
<version>1.0.0</version>
<description><![CDATA[Server-access profiles.]]></description>
<association>
<type>ServerProfile</type>
@ -33,7 +42,7 @@
</field>
<field>
<name>mavenProfiles</name>
<version>4.0.0</version>
<version>1.0.0</version>
<description><![CDATA[Collection of runtime configurations for local repo, etc.]]></description>
<association>
<type>MavenProfile</type>
@ -42,7 +51,7 @@
</field>
<field>
<name>defaultProfiles</name>
<version>4.0.0</version>
<version>1.0.0</version>
<association>
<type>DefaultProfiles</type>
</association>
@ -53,19 +62,19 @@
<!-- @todo: is any of this too CVS specific? Investigate other SCMs -->
<class>
<name>JdkProfile</name>
<version>4.0.0</version>
<version>1.0.0</version>
<description><![CDATA[Describes one Java environment]]></description>
<fields>
<field>
<name>version</name>
<version>4.0.0</version>
<version>1.0.0</version>
<required>true</required>
<description><![CDATA[The JDK major version (eg. '1.4').]]></description>
<type>String</type>
</field>
<field>
<name>javaHome</name>
<version>4.0.0</version>
<version>1.0.0</version>
<required>true</required>
<description><![CDATA[The JDK home.]]></description>
<type>String</type>
@ -73,44 +82,92 @@
</fields>
</class>
<class>
<name>ServerProfile</name>
<version>4.0.0</version>
<name>ProxyProfile</name>
<version>1.0.0</version>
<fields>
<field>
<name>id</name>
<version>4.0.0</version>
<version>1.0.0</version>
<description><![CDATA[The unique id for a proxy configuration.]]></description>
<type>String</type>
</field>
<field>
<name>protocol</name>
<version>1.0.0</version>
<description><![CDATA[The proxy protocol.]]></description>
<type>String</type>
</field>
<field>
<name>username</name>
<version>1.0.0</version>
<description><![CDATA[The proxy user.]]></description>
<type>String</type>
</field>
<field>
<name>password</name>
<version>1.0.0</version>
<description><![CDATA[The proxy password.]]></description>
<type>String</type>
</field>
<field>
<name>port</name>
<version>1.0.0</version>
<description><![CDATA[The proxy port.]]></description>
<type>int</type>
</field>
<field>
<name>host</name>
<version>1.0.0</version>
<description><![CDATA[The proxy host.]]></description>
<type>String</type>
</field>
<field>
<name>nonProxyHosts</name>
<version>1.0.0</version>
<description><![CDATA[The non-proxied hosts.]]></description>
<type>String</type>
</field>
</fields>
</class>
<class>
<name>ServerProfile</name>
<version>1.0.0</version>
<fields>
<field>
<name>id</name>
<version>1.0.0</version>
<required>true</required>
<description><![CDATA[The ID of this configuration for external reference.]]></description>
<type>String</type>
</field>
<field>
<name>host</name>
<version>4.0.0</version>
<version>1.0.0</version>
<required>true</required>
<description><![CDATA[The hostname for this configuration.]]></description>
<type>String</type>
</field>
<field>
<name>username</name>
<version>4.0.0</version>
<version>1.0.0</version>
<description><![CDATA[The username used to access this server with this config.]]></description>
<type>String</type>
</field>
<field>
<name>password</name>
<version>4.0.0</version>
<version>1.0.0</version>
<description><![CDATA[The password used to access this server with this config.]]></description>
<type>String</type>
</field>
<field>
<name>privateKey</name>
<version>4.0.0</version>
<version>1.0.0</version>
<description><![CDATA[The private key location used to access this server with this config.]]></description>
<type>String</type>
</field>
<field>
<name>passphrase</name>
<version>4.0.0</version>
<version>1.0.0</version>
<description><![CDATA[The passphrase used to access this server with a private key in this config.]]></description>
<type>String</type>
</field>
@ -118,25 +175,25 @@
</class>
<class>
<name>MavenProfile</name>
<version>4.0.0</version>
<version>1.0.0</version>
<fields>
<field>
<name>id</name>
<version>4.0.0</version>
<version>1.0.0</version>
<required>true</required>
<description><![CDATA[The ID of this configuration for external reference.]]></description>
<type>String</type>
</field>
<field>
<name>localRepository</name>
<version>4.0.0</version>
<version>1.0.0</version>
<required>true</required>
<description><![CDATA[The local repository to use for this runtime profile.]]></description>
<type>String</type>
</field>
<field>
<name>passwordStore</name>
<version>4.0.0</version>
<version>1.0.0</version>
<required>true</required>
<description><![CDATA[The keystore used to store passwords for this runtime profile.]]></description>
<type>String</type>
@ -145,23 +202,29 @@
</class>
<class>
<name>DefaultProfiles</name>
<version>4.0.0</version>
<version>1.0.0</version>
<fields>
<field>
<name>serverProfileId</name>
<version>4.0.0</version>
<version>1.0.0</version>
<required>false</required>
<type>String</type>
</field>
<field>
<name>mavenProfileId</name>
<version>4.0.0</version>
<version>1.0.0</version>
<required>true</required>
<type>String</type>
</field>
<field>
<name>jdkVersion</name>
<version>4.0.0</version>
<version>1.0.0</version>
<required>false</required>
<type>String</type>
</field>
<field>
<name>proxyProfileId</name>
<version>1.0.0</version>
<required>false</required>
<type>String</type>
</field>