o Added (pom|project)? to the eval pattern in the regex param extractor, to trim ${project.artifactid} to mean the same as ${artifactId} within the pom.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163490 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-03-08 06:06:22 +00:00
parent ba74921b31
commit 77d3e6c5f5
16 changed files with 440 additions and 19 deletions

View File

@ -7,3 +7,4 @@ maven-component.i*
.settings
mboot.jar
dummy
build.ajproperties

View File

@ -31,6 +31,11 @@
<artifactId>maven-model</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>maven</groupId>
<artifactId>maven-user-model</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>maven</groupId>
<artifactId>maven-artifact</artifactId>

View File

@ -267,6 +267,7 @@ public class DefaultMaven
{
return new MavenSession( container,
pluginManager,
request.getUserModel(),
request.getLocalRepository(),
request.getEventDispatcher(),
request.getLog(),

View File

@ -33,11 +33,13 @@ 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.UserModel;
import org.apache.maven.monitor.event.DefaultEventDispatcher;
import org.apache.maven.monitor.event.DefaultEventMonitor;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.logging.DefaultLog;
import org.apache.maven.plugin.Plugin;
import org.apache.maven.util.UserModelUtils;
import org.codehaus.classworlds.ClassWorld;
import org.codehaus.plexus.embed.ArtifactEnabledEmbedder;
import org.codehaus.plexus.logging.Logger;
@ -118,6 +120,8 @@ public class MavenCli
EventDispatcher eventDispatcher = new DefaultEventDispatcher();
UserModel userModel = UserModelUtils.getUserModel();
if ( projectFile.exists() )
{
if ( commandLine.hasOption( CLIManager.REACTOR ) )
@ -127,6 +131,7 @@ public class MavenCli
String excludes = System.getProperty( "maven.reactor.excludes", POMv4 );
request = new MavenReactorExecutionRequest( localRepository,
userModel,
eventDispatcher,
mavenProperties,
commandLine.getArgList(),
@ -137,6 +142,7 @@ public class MavenCli
else
{
request = new MavenProjectExecutionRequest( localRepository,
userModel,
eventDispatcher,
mavenProperties,
commandLine.getArgList(),
@ -145,7 +151,7 @@ public class MavenCli
}
else
{
request = new MavenInitializingExecutionRequest( localRepository, eventDispatcher, mavenProperties, commandLine.getArgList() );
request = new MavenInitializingExecutionRequest( localRepository, userModel, eventDispatcher, mavenProperties, commandLine.getArgList() );
}
// ----------------------------------------------------------------------

View File

@ -18,7 +18,7 @@ package org.apache.maven.execution;
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.monitor.event.DefaultEventDispatcher;
import org.apache.maven.model.user.UserModel;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.EventMonitor;
import org.apache.maven.monitor.logging.Log;
@ -48,10 +48,14 @@ implements MavenExecutionRequest
private EventDispatcher eventDispatcher;
public AbstractMavenExecutionRequest( ArtifactRepository localRepository, EventDispatcher eventDispatcher, Properties parameters, List goals )
private final UserModel userModel;
public AbstractMavenExecutionRequest( ArtifactRepository localRepository, UserModel userModel, EventDispatcher eventDispatcher, Properties parameters, List goals )
{
this.localRepository = localRepository;
this.userModel = userModel;
this.parameters = parameters;
this.goals = goals;
@ -59,6 +63,11 @@ implements MavenExecutionRequest
this.eventDispatcher = eventDispatcher;
}
public UserModel getUserModel()
{
return userModel;
}
public ArtifactRepository getLocalRepository()
{
return localRepository;

View File

@ -18,6 +18,7 @@ package org.apache.maven.execution;
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.user.UserModel;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.EventMonitor;
import org.apache.maven.monitor.logging.Log;
@ -52,4 +53,6 @@ public interface MavenExecutionRequest
void addEventMonitor( EventMonitor monitor );
EventDispatcher getEventDispatcher();
UserModel getUserModel();
}

View File

@ -18,6 +18,7 @@ package org.apache.maven.execution;
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.user.UserModel;
import org.apache.maven.monitor.event.EventDispatcher;
import java.util.List;
@ -30,9 +31,9 @@ import java.util.Properties;
public class MavenInitializingExecutionRequest
extends AbstractMavenExecutionRequest
{
public MavenInitializingExecutionRequest( ArtifactRepository localRepository, EventDispatcher eventDispatcher, Properties properties, List goals )
public MavenInitializingExecutionRequest( ArtifactRepository localRepository, UserModel userModel, EventDispatcher eventDispatcher, Properties properties, List goals )
{
super( localRepository, eventDispatcher, properties, goals );
super( localRepository, userModel, eventDispatcher, properties, goals );
type = "initializing";
}

View File

@ -18,6 +18,7 @@ package org.apache.maven.execution;
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.user.UserModel;
import org.apache.maven.monitor.event.EventDispatcher;
import java.io.File;
@ -35,12 +36,13 @@ extends AbstractMavenExecutionRequest
private File pom;
public MavenProjectExecutionRequest( ArtifactRepository localRepository,
UserModel userModel,
EventDispatcher eventDispatcher,
Properties properties,
List goals,
File pom )
{
super( localRepository, eventDispatcher, properties, goals );
super( localRepository, userModel, eventDispatcher, properties, goals );
this.pom = pom;

View File

@ -18,6 +18,7 @@ package org.apache.maven.execution;
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.user.UserModel;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.FileUtils;
@ -40,11 +41,11 @@ extends AbstractMavenExecutionRequest
private File baseDirectory;
public MavenReactorExecutionRequest( ArtifactRepository localRepository, EventDispatcher eventDispatcher,
public MavenReactorExecutionRequest( ArtifactRepository localRepository, UserModel userModel, EventDispatcher eventDispatcher,
Properties properties, List goals, String includes,
String excludes, File baseDirectory )
{
super( localRepository, eventDispatcher, properties, goals );
super( localRepository, userModel, eventDispatcher, properties, goals );
this.includes = includes;
@ -78,6 +79,6 @@ extends AbstractMavenExecutionRequest
public MavenProjectExecutionRequest createProjectExecutionRequest( MavenProject project )
{
return new MavenProjectExecutionRequest( localRepository, getEventDispatcher(), parameters, goals, project.getFile() );
return new MavenProjectExecutionRequest( localRepository, getUserModel(), getEventDispatcher(), parameters, goals, project.getFile() );
}
}

View File

@ -18,6 +18,7 @@ package org.apache.maven.execution;
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.user.UserModel;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.logging.Log;
import org.apache.maven.plugin.PluginManager;
@ -62,13 +63,17 @@ public class MavenSession
private Log log;
public MavenSession( PlexusContainer container, PluginManager pluginManager, ArtifactRepository localRepository,
private final UserModel userModel;
public MavenSession( PlexusContainer container, PluginManager pluginManager, UserModel userModel, ArtifactRepository localRepository,
EventDispatcher eventDispatcher, Log log, List goals )
{
this.container = container;
this.pluginManager = pluginManager;
this.userModel = userModel;
this.localRepository = localRepository;
this.eventDispatcher = eventDispatcher;
@ -144,6 +149,11 @@ public class MavenSession
return log;
}
public UserModel getUserModel()
{
return userModel;
}
public void addImpliedExecution( String goal, String implied ) throws CycleDetectedException
{
dag.addEdge( goal, implied );

View File

@ -38,7 +38,7 @@ public class RegexBasedModelInterpolator
implements ModelInterpolator
{
private static final Pattern EXPRESSION_PATTERN = Pattern.compile( "\\$\\{([^}]+)\\}" );
private static final Pattern EXPRESSION_PATTERN = Pattern.compile( "\\$\\{(pom|project\\.)?([^}]+)\\}" );
/**
* Added: Feb 3, 2005 by jdcasey
@ -87,7 +87,7 @@ public class RegexBasedModelInterpolator
while ( matcher.find() )
{
String wholeExpr = matcher.group( 0 );
String realExpr = matcher.group( 1 );
String realExpr = matcher.group( 2 );
String value = null;
try

View File

@ -0,0 +1,193 @@
package org.apache.maven.util;
import org.apache.maven.model.user.JdkProfile;
import org.apache.maven.model.user.MavenProfile;
import org.apache.maven.model.user.ServerProfile;
import org.apache.maven.model.user.UserModel;
import org.apache.maven.model.user.io.xpp3.MavenUserModelXpp3Reader;
import org.apache.maven.model.user.io.xpp3.MavenUserModelXpp3Writer;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
/**
* @author jdcasey
*/
public final class UserModelUtils
{
public static final String JDK_PROFILE_ENVAR = "maven.jdkVersion";
public static final String MAVEN_PROFILE_ENVAR = "maven.mavenProfileId";
public static final String SERVER_PROFILE_ENVAR = "maven.serverProfileId";
private static final String USER_MODEL_LOCATION = "/.m2/user.xml";
private UserModelUtils()
{
}
public static ServerProfile getActiveServer( UserModel userModel )
{
List servers = userModel.getServerProfiles();
String serverId = System.getProperty( SERVER_PROFILE_ENVAR );
if ( serverId == null || serverId.trim().length() < 1 )
{
serverId = userModel.getDefaultProfiles().getServerProfileId();
}
ServerProfile active = null;
for ( Iterator it = servers.iterator(); it.hasNext(); )
{
ServerProfile server = (ServerProfile) it.next();
if ( serverId.equals( server.getId() ) )
{
active = server;
break;
}
}
return active;
}
public static JdkProfile getActiveJdk( UserModel userModel )
{
List jdks = userModel.getJdkProfiles();
String jdkId = System.getProperty( JDK_PROFILE_ENVAR );
if ( jdkId == null || jdkId.trim().length() < 1 )
{
jdkId = userModel.getDefaultProfiles().getJdkVersion();
}
JdkProfile active = null;
for ( Iterator it = jdks.iterator(); it.hasNext(); )
{
JdkProfile jdk = (JdkProfile) it.next();
if ( jdkId.equals( jdk.getVersion() ) )
{
active = jdk;
break;
}
}
return active;
}
public static MavenProfile getActiveRuntimeProfile( UserModel userModel )
{
List mavenProfiles = userModel.getMavenProfiles();
String mavenProfileId = System.getProperty( MAVEN_PROFILE_ENVAR );
if ( mavenProfileId == null || mavenProfileId.trim().length() < 1 )
{
mavenProfileId = userModel.getDefaultProfiles().getMavenProfileId();
}
MavenProfile active = null;
for ( Iterator it = mavenProfiles.iterator(); it.hasNext(); )
{
MavenProfile mavenProfile = (MavenProfile) it.next();
if ( mavenProfileId.equals( mavenProfile.getId() ) )
{
active = mavenProfile;
break;
}
}
return active;
}
// TODO: don't throw Exception.
public static UserModel getUserModel() throws Exception
{
UserModel model = null;
File modelFile = getUserModelFile();
if ( modelFile.exists() && modelFile.isFile() )
{
MavenUserModelXpp3Reader modelReader = new MavenUserModelXpp3Reader();
FileReader reader = null;
try
{
reader = new FileReader( modelFile );
model = modelReader.read( reader );
}
finally
{
if ( reader != null )
{
try
{
reader.close();
}
catch ( IOException e )
{
}
}
}
}
return model;
}
// TODO: don't throw Exception.
public static void setUserModel( UserModel userModel ) throws Exception
{
File modelFile = getUserModelFile();
File modelDir = modelFile.getParentFile();
if ( !modelDir.exists() )
{
modelDir.mkdirs();
}
MavenUserModelXpp3Writer modelWriter = new MavenUserModelXpp3Writer();
FileWriter writer = null;
try
{
writer = new FileWriter( modelFile );
modelWriter.write( writer, userModel );
writer.flush();
}
finally
{
if ( writer != null )
{
try
{
writer.close();
}
catch ( IOException e )
{
}
}
}
}
private static File getUserModelFile()
{
String userDir = System.getProperty( "user.home" );
String modelPath = userDir + USER_MODEL_LOCATION;
modelPath = modelPath.replaceAll( "\\\\", "/" );
modelPath = modelPath.replaceAll( "//", "/" );
File userModelFile = new File( modelPath );
return userModelFile;
}
}

View File

@ -5,6 +5,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Build;
import org.apache.maven.model.Model;
import org.apache.maven.model.user.UserModel;
import org.apache.maven.monitor.event.DefaultEventDispatcher;
import org.apache.maven.monitor.logging.DefaultLog;
import org.apache.maven.project.MavenProject;
@ -41,7 +42,7 @@ public class PluginParameterExpressionEvaluatorTest
PluginManager mgr = (PluginManager)lookup(PluginManager.ROLE);
PlexusContainer container = getContainer();
MavenSession session = new MavenSession(container, mgr, repo, new DefaultEventDispatcher(), new DefaultLog(container.getLogger()), Collections.EMPTY_LIST);
MavenSession session = new MavenSession(container, mgr, new UserModel(), repo, new DefaultEventDispatcher(), new DefaultLog(container.getLogger()), Collections.EMPTY_LIST);
Build build = new Build();
build.setDirectory(expected.substring(0, expected.length() - "/classes".length()));
@ -73,7 +74,7 @@ public class PluginParameterExpressionEvaluatorTest
PluginManager mgr = (PluginManager)lookup(PluginManager.ROLE);
PlexusContainer container = getContainer();
MavenSession session = new MavenSession(container, mgr, repo, new DefaultEventDispatcher(), new DefaultLog(container.getLogger()), Collections.EMPTY_LIST);
MavenSession session = new MavenSession(container, mgr, new UserModel(), repo, new DefaultEventDispatcher(), new DefaultLog(container.getLogger()), Collections.EMPTY_LIST);
Object value = PluginParameterExpressionEvaluator.evaluate( role, session );
assertNotNull( value );
@ -86,7 +87,7 @@ public class PluginParameterExpressionEvaluatorTest
PluginManager mgr = (PluginManager)lookup(PluginManager.ROLE);
PlexusContainer container = getContainer();
MavenSession session = new MavenSession(container, mgr, repo, new DefaultEventDispatcher(), new DefaultLog(container.getLogger()), Collections.EMPTY_LIST);
MavenSession session = new MavenSession(container, mgr, new UserModel(), repo, new DefaultEventDispatcher(), new DefaultLog(container.getLogger()), Collections.EMPTY_LIST);
Object value = PluginParameterExpressionEvaluator.evaluate( "#localRepository", session );

View File

@ -79,6 +79,7 @@ public class MBoot
String[] builds = new String[] {
"maven-model",
"maven-user-model",
"maven-monitor",
"maven-plugin",
"maven-artifact",
@ -477,9 +478,21 @@ public class MBoot
// Generating sources
// ----------------------------------------------------------------------
File model = new File( basedir, "maven.mdo" );
File base = new File(basedir);
if ( model.exists() )
String[] basedirFiles = base.list();
File model = null;
for ( int i = 0; i < basedirFiles.length; i++ )
{
if(basedirFiles[i].endsWith(".mdo"))
{
model = new File(base, basedirFiles[i]);
break;
}
}
if ( model != null && model.exists() )
{
System.out.println( "Model exists!" );

View File

@ -0,0 +1,165 @@
<model>
<id>mavenUserModel</id>
<name>MavenUserModel</name>
<description><![CDATA[Maven's user-config model for Java project.]]></description>
<defaults>
<default>
<key>package</key>
<value>org.apache.maven.model.user</value>
</default>
</defaults>
<classes>
<class rootElement="true">
<name>UserModel</name>
<version>4.0.0</version>
<fields>
<field>
<name>jdkProfiles</name>
<version>4.0.0</version>
<description><![CDATA[Configuration for different java environment profiles.]]></description>
<association>
<type>JdkProfile</type>
<multiplicity>*</multiplicity>
</association>
</field>
<field>
<name>serverProfiles</name>
<version>4.0.0</version>
<description><![CDATA[Server-access profiles.]]></description>
<association>
<type>ServerProfile</type>
<multiplicity>*</multiplicity>
</association>
</field>
<field>
<name>mavenProfiles</name>
<version>4.0.0</version>
<description><![CDATA[Collection of runtime configurations for local repo, etc.]]></description>
<association>
<type>MavenProfile</type>
<multiplicity>*</multiplicity>
</association>
</field>
<field>
<name>defaultProfiles</name>
<version>4.0.0</version>
<association>
<type>DefaultProfiles</type>
</association>
</field>
</fields>
<codeSegments/>
</class>
<!-- @todo: is any of this too CVS specific? Investigate other SCMs -->
<class>
<name>JdkProfile</name>
<version>4.0.0</version>
<description><![CDATA[Describes one Java environment]]></description>
<fields>
<field>
<name>version</name>
<version>4.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>
<required>true</required>
<description><![CDATA[The JDK home.]]></description>
<type>String</type>
</field>
</fields>
</class>
<class>
<name>ServerProfile</name>
<version>4.0.0</version>
<fields>
<field>
<name>id</name>
<version>4.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>
<required>true</required>
<description><![CDATA[The hostname for this configuration.]]></description>
<type>String</type>
</field>
<field>
<name>username</name>
<version>4.0.0</version>
<description><![CDATA[The username used to access this server with this config.]]></description>
<type>String</type>
</field>
<field>
<name>passphrase</name>
<version>4.0.0</version>
<description><![CDATA[The passphrase used to access this server with this config.]]></description>
<type>String</type>
</field>
<field>
<name>privateKey</name>
<version>4.0.0</version>
<description><![CDATA[The private key location used to access this server with this config.]]></description>
<type>String</type>
</field>
</fields>
</class>
<class>
<name>MavenProfile</name>
<version>4.0.0</version>
<fields>
<field>
<name>id</name>
<version>4.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>
<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>
<required>true</required>
<description><![CDATA[The keystore used to store passwords for this runtime profile.]]></description>
<type>String</type>
</field>
</fields>
</class>
<class>
<name>DefaultProfiles</name>
<version>4.0.0</version>
<fields>
<field>
<name>serverProfileId</name>
<version>4.0.0</version>
<required>false</required>
<type>String</type>
</field>
<field>
<name>mavenProfileId</name>
<version>4.0.0</version>
<required>true</required>
<type>String</type>
</field>
<field>
<name>jdkVersion</name>
<version>4.0.0</version>
<required>false</required>
<type>String</type>
</field>
</fields>
</class>
</classes>
</model>

10
maven-user-model/pom.xml Normal file
View File

@ -0,0 +1,10 @@
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>maven</groupId>
<artifactId>maven-component</artifactId>
<version>2.0-SNAPSHOT</version>
</parent>
<artifactId>maven-user-model</artifactId>
</project>