dion 2003/08/18 21:31:38
Modified: src/java/org/apache/maven/verifier DependencyVerifier.java
LocalSettingsVerifier.java
src/java/org/apache/maven/util StringTool.java
DVSLFormatter.java Expand.java DVSLPathTool.java
src/java/org/apache/maven MavenUtils.java
ArtifactListBuilder.java
AbstractMavenComponent.java MavenConstants.java
DefaultProjectMarshaller.java
DefaultProjectUnmarshaller.java
NoGoalException.java
src/java/org/apache/maven/repository
DefaultArtifactFactory.java
Added: src/java/org/apache/maven MavenSession.java
DependencyClasspathBuilder.java
AntProjectBuilder.java
Removed: src/java/org/apache/maven Maven.java
Log:
Switch stable branch back to HEAD
Revision Changes Path
1.30 +28 -14 maven/src/java/org/apache/maven/verifier/DependencyVerifier.java
Index: DependencyVerifier.java
===================================================================
RCS file:
/home/cvs/maven/src/java/org/apache/maven/verifier/DependencyVerifier.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- DependencyVerifier.java 5 Aug 2003 07:50:49 -0000 1.29
+++ DependencyVerifier.java 19 Aug 2003 04:31:38 -0000 1.30
@@ -3,7 +3,7 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2002 The Apache Software Foundation. All rights
+ * Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -58,12 +58,11 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.commons.lang.StringUtils;
import org.apache.maven.AbstractMavenComponent;
-import org.apache.maven.MavenConstants;
import org.apache.maven.project.Project;
import org.apache.maven.repository.Artifact;
import org.apache.maven.util.HttpUtils;
-import org.apache.plexus.util.StringUtils;
import java.io.File;
import java.io.FileNotFoundException;
@@ -155,10 +154,10 @@
throws UnsatisfiedDependencyException
{
// Is the remote repository enabled?
- boolean remoteRepoEnabled = getProject().getRemoteRepositoryEnabled();
+ boolean remoteRepoEnabled =
getProject().getContext().getRemoteRepositoryEnabled().booleanValue();
// Is the user online?
- boolean online = getProject().getBoolean( MavenConstants.ONLINE );
+ boolean online = getProject().getContext().getOnline().booleanValue();
if ( remoteRepoEnabled == false )
{
@@ -240,7 +239,22 @@
for ( Iterator i = failedDependencies.iterator(); i.hasNext(); )
{
Artifact artifact = (Artifact) i.next();
- message.append( artifact.getName() ).append( "\n" );
+ message.append( artifact.getName() );
+ String url = artifact.getDependency().getUrl();
+ if (StringUtils.isNotEmpty(url))
+ {
+ // FIXME: internationalize
+ message.append( " (")
+ .append("try downloading from ")
+ .append( url )
+ .append( ")");
+ }
+ else
+ {
+ // FIXME: internationalize
+ message.append( " (no download url specified)");
+ }
+ message.append( "\n" );
}
return message.toString();
@@ -274,7 +288,7 @@
directory.mkdirs();
}
- System.out.println( getMessage( "download.message", artifact.getName()
) );
+ log.info( getMessage( "download.message", artifact.getName() ) );
if ( getRemoteArtifact( artifact ) )
{
@@ -311,8 +325,8 @@
{
boolean artifactFound = false;
- for ( Iterator i = getProject().getMavenRepoRemote().iterator();
i.hasNext(); )
- {
+ for ( Iterator i =
getProject().getContext().getMavenRepoRemote().iterator(); i.hasNext(); )
+ {
String remoteRepo = (String) i.next();
// The username and password parameters are not being
@@ -329,10 +343,10 @@
artifact.getFile(),
ignoreErrors,
useTimestamp,
- getProject().getProjectProperty(
MavenConstants.PROXY_HOST ),
- getProject().getProjectProperty(
MavenConstants.PROXY_PORT ),
- getProject().getProjectProperty(
MavenConstants.PROXY_USERNAME ),
- getProject().getProjectProperty(
MavenConstants.PROXY_PASSWORD ),
+ getProject().getContext().getProxyHost(),
+ getProject().getContext().getProxyPort(),
+ getProject().getContext().getProxyUserName(),
+ getProject().getContext().getProxyPassword(),
true );
// Artifact was found, continue checking additional remote repos
(if any)
1.6 +1 -1
maven/src/java/org/apache/maven/verifier/LocalSettingsVerifier.java
Index: LocalSettingsVerifier.java
===================================================================
RCS file:
/home/cvs/maven/src/java/org/apache/maven/verifier/LocalSettingsVerifier.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- LocalSettingsVerifier.java 27 Jul 2003 23:33:59 -0000 1.5
+++ LocalSettingsVerifier.java 19 Aug 2003 04:31:38 -0000 1.6
@@ -86,7 +86,7 @@
throws RepoConfigException
{
// Get local repo property.
- String localRepoProp = getProject().getMavenRepoLocal();
+ String localRepoProp = getProject().getContext().getMavenRepoLocal();
if ( localRepoProp == null )
{
1.2 +1 -1 maven/src/java/org/apache/maven/util/StringTool.java
Index: StringTool.java
===================================================================
RCS file: /home/cvs/maven/src/java/org/apache/maven/util/StringTool.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
1.2 +1 -1 maven/src/java/org/apache/maven/util/DVSLFormatter.java
Index: DVSLFormatter.java
===================================================================
RCS file: /home/cvs/maven/src/java/org/apache/maven/util/DVSLFormatter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
1.13 +2 -2 maven/src/java/org/apache/maven/util/Expand.java
Index: Expand.java
===================================================================
RCS file: /home/cvs/maven/src/java/org/apache/maven/util/Expand.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Expand.java 28 Jul 2003 05:09:19 -0000 1.12
+++ Expand.java 19 Aug 2003 04:31:38 -0000 1.13
@@ -126,7 +126,7 @@
ze.isDirectory() );
}
- log.info("expand complete");
+ log.debug("expand complete");
}
finally
{
@@ -168,7 +168,7 @@
return;
}
- log.info("expanding " + entryName + " to " + f);
+ log.debug("expanding " + entryName + " to " + f);
// create intermediary directories - sometimes zip don't add them
File dirF = f.getParentFile();
//File dirF = fileUtils.getParentFile(f);
1.2 +1 -1 maven/src/java/org/apache/maven/util/DVSLPathTool.java
Index: DVSLPathTool.java
===================================================================
RCS file: /home/cvs/maven/src/java/org/apache/maven/util/DVSLPathTool.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
1.99 +624 -206 maven/src/java/org/apache/maven/MavenUtils.java
Index: MavenUtils.java
===================================================================
RCS file: /home/cvs/maven/src/java/org/apache/maven/MavenUtils.java,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -r1.98 -r1.99
--- MavenUtils.java 6 Aug 2003 05:05:23 -0000 1.98
+++ MavenUtils.java 19 Aug 2003 04:31:38 -0000 1.99
@@ -56,13 +56,42 @@
* ====================================================================
*/
+import org.apache.commons.betwixt.XMLIntrospector;
+import org.apache.commons.betwixt.io.BeanReader;
+import org.apache.commons.betwixt.io.BeanWriter;
+import org.apache.commons.betwixt.strategy.DecapitalizeNameMapper;
+import org.apache.commons.collections.BeanMap;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.digester.ExtendedBaseRules;
+import org.apache.commons.digester.Rule;
+import org.apache.commons.jelly.JellyContext;
+import org.apache.commons.jelly.Script;
+import org.apache.commons.jelly.XMLOutput;
+import org.apache.commons.jelly.expression.CompositeExpression;
+import org.apache.commons.jelly.expression.Expression;
+import org.apache.commons.jelly.expression.jexl.JexlExpressionFactory;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.maven.jelly.JellyUtils;
+import org.apache.maven.jelly.MavenExpressionFactory;
+import org.apache.maven.jelly.MavenJellyContext;
+import org.apache.maven.project.BaseObject;
+import org.apache.maven.project.Project;
+import org.apache.maven.util.StringInputStream;
+import org.apache.tools.ant.DirectoryScanner;
+import org.xml.sax.XMLReader;
+
+import javax.xml.parsers.SAXParserFactory;
+import java.io.BufferedWriter;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStreamWriter;
import java.io.StringReader;
-import java.io.StringWriter;
+import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -75,117 +104,142 @@
import java.util.ResourceBundle;
import java.util.Set;
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.maven.project.Project;
-import org.apache.maven.util.StringInputStream;
-import org.apache.plexus.util.DirectoryScanner;
-import org.apache.plexus.util.StringUtils;
-import org.xmlpull.v1.XmlPullParserException;
-
/**
* Utilities for reading maven project descriptors, profile descriptors and
* workspace descriptors.
*
- * NOTE:
- * I need to make this class not-visible from outside this package.
- *
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @version $Id$
+ *
+ * @todo Remove all the context creation code and make a ContextBuilder class.
*/
public class MavenUtils
{
- /** Map of loaded POMs. */
- private static HashMap parentPoms = new HashMap();
+ /** Log. */
+ private static final Log logger = LogFactory.getLog( MavenUtils.class );
- /** Project marshaller. */
- private DefaultProjectMarshaller marshaller;
+ /** Internal encoding used for Jelly interpolation. */
+ private static final String INTERNAL_ENCODING = "ISO-8859-1";
- /** Project unmarshaller. */
- private DefaultProjectUnmarshaller unmarshaller;
+ /** we want to parse something */
+ private static final ThreadLocal xmlReaderPool = new ThreadLocal();
- public MavenUtils()
+ /** Should we cache and reuse the introspector */
+ private static boolean cacheIntrospector = true;
+
+ /** The singleton introspector if caching is enabled */
+ private static XMLIntrospector singletonIntrospector;
+
+ /** Project Bean Reader */
+ private static BeanReader projectBeanReader;
+
+ /** Maven Expression Factory. */
+ private static MavenExpressionFactory mavenExpressionFactory = new
MavenExpressionFactory();
+
+ /** Map of loaded POMs. */
+ private static HashMap parentPoms = new HashMap();
+
+ /**
+ * Create a Project object given a name a file descriptor.
+ *
+ * @param projectDescriptor a maven project.xml
+ * @return the Maven project object for the given project descriptor
+ * @throws Exception when any errors occur
+ */
+ public static Project getProject( File projectDescriptor )
throws Exception
{
- marshaller = new DefaultProjectMarshaller();
- unmarshaller = new DefaultProjectUnmarshaller();
+ return getProject( projectDescriptor, null );
}
- // ----------------------------------------------------------------------
- // Protected methods to be used by the Maven facade.
- // ----------------------------------------------------------------------
-
- Project getProject( File project, Maven maven )
+ public static Project getProject( File projectDescriptor, MavenJellyContext
parentContext )
throws Exception
{
- return getProject( project, true, maven );
+ return getProject( projectDescriptor, parentContext, true );
}
- Project getProject( File projectDescriptor, boolean useParentPom, Maven maven )
+ /**
+ * Create a Project object given a file descriptor and optionally a parent Jelly
+ * context. We are doing several things when creating a POM object, the phases
+ * are outlined here:
+ *
+ * 1) The project.xml file is read in using betwixt which creates for us a
+ * Project object that, at this point, has not been run through Jelly i.e.
+ * no interpolation has occured yet.
+ *
+ * 2) The context for the project is created and set. So each project manages
its
+ * own context. See the createContext() method for the details context
creation
+ * process.
+ *
+ * 3) We check to see if the <extend> tag is being employed. If so, the parent
+ * project.xml file is read in. At this point we have a child and parent POM
+ * and the values are merged where the child's values override those of the
+ * parent.
+ *
+ * 4) The POM we have at this point is then processed through Jelly.
+ *
+ * 5) The project is handed the reference to the File that was used to create
+ * the project itself.
+ *
+ * @param projectDescriptor a maven project.xml [EMAIL PROTECTED] File}
+ * @return the MavenSession project object for the given project descriptor
+ * @throws Exception when any errors occur
+ */
+ public static Project getProject( File projectDescriptor,
+ MavenJellyContext parentContext,
+ boolean useParentPom )
throws Exception
{
+ //if ( pom.get())
+
// 1)
- FileReader pfr = new FileReader( projectDescriptor );
- Project project = null;
- try
- {
- project = unmarshaller.parse( pfr );
- }
- catch (XmlPullParserException e)
- {
- System.err.println("Error reading file: " + projectDescriptor);
- throw e;
- }
- pfr.close();
+ BeanReader projectBeanReader = getProjectBeanReader();
+ Project project = (Project) projectBeanReader.parse( projectDescriptor );
// 2)
- Map properties = createProjectProperties( projectDescriptor.getParentFile()
);
-
- // We do not want to do POM interpolation in properties files but
maven.final.name is
- // baked into the driver.properties file. So we'll leave its default value
but we will
- // place the real value in here because we are not interpolating the POM
into properties.
- String mavenFinalName = (String) properties.get( "maven.final.name" );
-
- if ( mavenFinalName.indexOf( "${" ) >= 0 )
- {
- project.getId();
- properties.put( "maven.final.name", project.getArtifactId() + "-" +
project.getCurrentVersion() );
- }
-
+ MavenJellyContext context = MavenUtils.createContext(
projectDescriptor.getParentFile(),
+ parentContext );
// 3)
String pomToExtend = project.getExtend();
if ( pomToExtend != null && useParentPom )
{
- pomToExtend = StringUtils.interpolate( pomToExtend, properties );
+ // We must look in the <extend/> element for expressions that may be
present as
+ // we encourage the use of ${basedir} using extension:
+ //
+ // <extend>${basedir}/../project.xml</extend>
+ Expression e = JellyUtils.decomposeExpression( pomToExtend,
mavenExpressionFactory, context );
+ pomToExtend = e.evaluateAsString( context );
+ pomToExtend = MavenUtils.makeAbsolutePath(
projectDescriptor.getParentFile(), pomToExtend );
+
File parentPom = new File( pomToExtend );
Project parent = (Project) parentPoms.get( parentPom.getCanonicalPath()
);
if ( parent == null )
{
- FileReader fr = new FileReader( parentPom );
- parent = unmarshaller.parse( fr );
- fr.close();
+ parent = (Project) projectBeanReader.parse( parentPom );
if ( parent != null )
{
parentPoms.put( parentPom.getCanonicalPath(), parent );
}
-
- project.setParent( parent );
}
- project = setupInheritance( project, parent );
- }
+ // This is very slow. A BCEL solution would be very nice here.
+ project = (Project) mergeBeans( project, parent );
- // We need to do the interpolation after the merging so that ${basedir} is
- // expanded correctly.
- project = interpolateProject( project, properties );
+ // Now let's do some magic with dependencies. We take all
+ // the parent's dependencies and put them in with the childs.
+ project.addParentDependencies( parent.getDependencies() );
+ }
- // Set the standard properties.
- project.setProjectProperties( properties );
+ // Set the created context, and put the project itself in the context. This
+ // is how we get the ${pom} reference in the project.xml file to work.
+ project.setContext( context );
+ context.setProject( project );
- // Set a reference to the maven session.
- project.setMaven( maven );
+ // 4)
+ project = getJellyProject( project );
// 5)
project.setFile( projectDescriptor );
@@ -196,118 +250,6 @@
return project;
}
- private Project setupInheritance( Project child, Project parent )
- {
- // Id
- if ( child.getId() == null )
- {
- child.setId( parent.getId() );
- }
-
- // Group id
- if ( child.getGroupId() == null )
- {
- child.setGroupId( parent.getGroupId() );
- }
-
- // Short description
- if ( child.getShortDescription() == null )
- {
- child.setShortDescription( parent.getShortDescription() );
- }
-
- // Organization
- if ( child.getOrganization() == null )
- {
- child.setOrganization( parent.getOrganization() );
- }
-
- // Build
- if ( child.getBuild() == null )
- {
- child.setBuild( parent.getBuild() );
- }
-
- // Dependencies :: aggregate
- child.addParentDependencies( parent.getDependencies() );
-
- return child;
- }
-
- /**
- * Create a jelly context given a descriptor directory and parent
- * jelly context.
- *
- * @param descriptorDirectory The directory from which to pull the standard
maven
- * properties files from.
- * @return The generated maven based on the contents of the standard maven
- * properties files.
- */
- Map createProjectProperties( File descriptorDirectory )
- {
- // System properties
- Properties systemProperties = System.getProperties();
-
- // User build properties
- File userBuildPropertiesFile =
- new File( System.getProperty( "user.home" ), "build.properties" );
-
- Properties userBuildProperties = loadProperties( userBuildPropertiesFile );
-
- // project build properties
- File projectBuildPropertiesFile =
- new File( descriptorDirectory, "build.properties" );
-
- Properties projectBuildProperties = loadProperties(
projectBuildPropertiesFile );
-
- // project properties
- File projectPropertiesFile =
- new File( descriptorDirectory, "project.properties" );
-
- Properties projectProperties = loadProperties( projectPropertiesFile );
-
- Properties driverProperties = loadProperties(
- MavenUtils.class.getClassLoader().getResourceAsStream(
- MavenConstants.DRIVER_PROPERTIES ) );
-
- Properties defaultProperties = loadProperties(
- MavenUtils.class.getClassLoader().getResourceAsStream(
- MavenConstants.DEFAULTS_PROPERTIES ) );
-
- Map result = MavenUtils.mergeMaps( new Map[]
- {
- systemProperties,
- userBuildProperties,
- projectBuildProperties,
- projectProperties,
- defaultProperties,
- driverProperties
- } );
-
- // project build properties
- File pluginPropertiesFile =
- new File( descriptorDirectory, "plugin.properties" );
-
- Properties pluginProperties = loadProperties( pluginPropertiesFile );
-
- if ( pluginProperties != null )
- {
- result = mergeMaps( result, pluginProperties );
- }
-
- // Set the basedir value in the context.
- result.put( "basedir", descriptorDirectory.getPath() );
-
- for ( Iterator i = result.keySet().iterator(); i.hasNext(); )
- {
- String key = (String) i.next();
- String value = (String) result.get( key );
- result.put( key, StringUtils.interpolate( value, result ) );
- }
-
- return result;
- }
-
/**
* This is currently used for the reactor but may be generally useful.
*
@@ -316,10 +258,10 @@
* @return a {link List} of [EMAIL PROTECTED] Project}s
* @throws Exception when anything goes wrong. FIXME this is bad
*/
- List getProjects( File directory, String includes, Maven maven )
+ public static List getProjects( File directory, String includes,
MavenJellyContext context )
throws Exception
{
- return getProjects( directory, includes, null, maven );
+ return getProjects( directory, includes, null, context );
}
/**
@@ -331,10 +273,10 @@
* @return a {link List} of [EMAIL PROTECTED] Project}s
* @throws Exception when anything goes wrong. FIXME this is bad
*/
- List getProjects( File directory,
- String includes,
- String excludes,
- Maven maven )
+ public static List getProjects( File directory,
+ String includes,
+ String excludes,
+ MavenJellyContext context )
throws Exception
{
String[] files = getFiles( directory, includes, excludes );
@@ -343,7 +285,7 @@
for ( int i = 0; i < files.length; i++ )
{
- Project p = getProject( new File( files[i] ), maven );
+ Project p = getProject( new File( files[i] ), context );
projects.add( p );
}
@@ -351,11 +293,76 @@
}
/**
+ * Create a project bean reader. We use it more than once so we don't want
+ * to create it more than once.
+ *
+ * @return a [EMAIL PROTECTED] BeanReader} capable of reading [EMAIL PROTECTED]
Project projects}
+ * @throws Exception when anything goes wrong. FIXME this is bad
+ */
+ private static BeanReader getProjectBeanReader()
+ throws Exception
+ {
+ if ( projectBeanReader == null )
+ {
+ projectBeanReader = createBeanReader( Project.class );
+ }
+
+ return projectBeanReader;
+ }
+
+ /**
+ * Take the POM and interpolate the value of the project's context to create
+ * a new version of the POM with expanded context values.
+ *
+ * @param project the maven POM
+ * @return Jelly interpolated project.
+ * @throws Exception when anything goes wrong. FIXME this is bad
+ */
+ private static Project getJellyProject( Project project )
+ throws Exception
+ {
+ // Save the original context because we null it temporarly
+ // while we funnel it through betwixt.
+ MavenJellyContext originalContext = project.getContext();
+
+ // We don't want any taglib references in the context or Jelly
+ // gets confused. All we want are the variables for interpolation. We
+ // can change this but I think we would like to avoid general Jelly
+ // idiom in the POM anyway.
+ JellyContext context = new JellyContext();
+ context.setVariables( originalContext.getVariables() );
+
+ // We don't want the context being written out into the XML which
+ // is the interpolated POM.
+ project.setContext( null );
+ Script script = JellyUtils.compileScript( getProjectInputStream( project ),
+ context,
+ INTERNAL_ENCODING );
+
+ // Now run the script against the fully populated context so all the
+ // values are filled in correctly.
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ Writer writer = new BufferedWriter( new OutputStreamWriter( baos,
INTERNAL_ENCODING ) );
+ XMLOutput output = XMLOutput.createXMLOutput( writer );
+ script.run( context, output );
+ writer.close();
+
+ // Read in the the project.xml contents with the interpolated values and
+ // put back the original context with all the values that have been
populated
+ // but change the project in the context to the newly interpolated version.
+ project = (Project) getProjectBeanReader().parse( new StringReader(
baos.toString() ) );
+ project.setContext( originalContext );
+ project.getContext().setProject( project );
+
+ return project;
+ }
+
+ /**
* @return an [EMAIL PROTECTED] InputStream} for the given project
* @param project a [EMAIL PROTECTED] Project maven project}
* @throws Exception when anything goes wrong. FIXME this is bad
*/
- public InputStream getProjectInputStream( Project project )
+ public static InputStream getProjectInputStream( Project project )
throws Exception
{
return new StringInputStream( getProjectString( project ) );
@@ -368,12 +375,102 @@
* @return XML representation of the project
* @throws Exception when anything goes wrong. FIXME this is bad
*/
- public String getProjectString( Project project )
+ public static String getProjectString( Project project )
throws Exception
{
- StringWriter writer = new StringWriter();
- marshaller.marshall( writer, project );
- return writer.toString();
+ ByteArrayOutputStream projectStream = new ByteArrayOutputStream();
+ BeanWriter beanWriter = new BeanWriter( projectStream );
+ beanWriter.setXMLIntrospector( createXMLIntrospector() );
+
+ beanWriter.setWriteIDs( true );
+ beanWriter.write( project );
+
+ // We do not care what the original encoding was originally. This
+ // is all completely internal. Our StringInputStream requires
+ // everything to be encoded in "ISO-8859-1".
+ return projectStream.toString( INTERNAL_ENCODING );
+ }
+
+ /**
+ * Merge a child and parent Project object.
+ *
+ * @param child child object
+ * @param parent the maven project
+ * @return the child after properties from the parent are merged
+ */
+ private static Object mergeBeans( Object child, Object parent )
+ {
+ BeanMap parentBeanMap = new BeanMap( parent );
+ BeanMap childBeanMap = new BeanMap( child );
+
+ for ( Iterator i = parentBeanMap.keySet().iterator(); i.hasNext(); )
+ {
+ // Take the property for the parent and insert it
+ // into the child bean map.
+ String property = (String) i.next();
+
+ try
+ {
+ // If the childs property is null then take it from
+ // the parent.
+ Object c = childBeanMap.get( property );
+ Object p = parentBeanMap.get( property );
+
+ if ( valueNeedsPopulating( c ) )
+ {
+ childBeanMap.put( property, p );
+ }
+ else if ( c != null && p != null && !valuePrimitive( c ) )
+ {
+ Object mergedBean = mergeBeans( c, p );
+ childBeanMap.put( property, mergedBean );
+ }
+ }
+ catch ( IllegalArgumentException e )
+ {
+ // There is no write method for this property.
+ }
+ }
+ return child;
+ }
+
+ /**
+ * Test if a value is a primitive or not
+ *
+ * @param o the value to test
+ * @return true if o is a Boolean, String, Class or Integer.
+ */
+ private static boolean valuePrimitive( Object o )
+ {
+ if ( o instanceof Boolean || o instanceof String
+ || o instanceof Class || o instanceof Integer )
+ {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Check a child value to see if it needs populating with the parent value.
+ * The constructor sets List values to [] so we have to check those.
+ *
+ * @param o a child value
+ * @return true if the child value is an empty collection or null
+ */
+ private static boolean valueNeedsPopulating( Object o )
+ {
+ if ( o instanceof Collection && ( (Collection) o ).size() == 0 )
+ {
+ return true;
+ }
+ else if ( o == null )
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
}
/**
@@ -383,7 +480,7 @@
* @param includes Comma separated list of includes.
* @return files
*/
- public String[] getFiles( File directory, String includes )
+ public static String[] getFiles( File directory, String includes )
{
return getFiles( directory, includes, null );
}
@@ -396,7 +493,7 @@
* @param excludes Comma separated list of excludes.
* @return files
*/
- public String[] getFiles( File directory, String includes, String excludes )
+ public static String[] getFiles( File directory, String includes, String
excludes )
{
String[] includePatterns = null;
if ( includes != null )
@@ -425,20 +522,96 @@
return files;
}
- // ----------------------------------------------------------------------
- // private
- // ----------------------------------------------------------------------
- private Project interpolateProject( Project p, Map map )
+ /**
+ * Creates a new instance of BeanReader
+ *
+ * @param clazz the class to register with the reader
+ * @return a [EMAIL PROTECTED] BeanReader bean reader}
+ * @throws Exception when an error occurs trying to determine
+ * properties of the class provided
+ * @throws Exception when anything goes wrong. FIXME this is bad
+ */
+ public static BeanReader createBeanReader( Class clazz )
throws Exception
{
- return unmarshaller.parse(
- new StringReader( StringUtils.interpolate( getProjectString( p ), map )
) );
+ BeanReader beanReader = new BeanReader( getXMLReader() );
+ beanReader.setRules( new ExtendedBaseRules() );
+ beanReader.addRule( "*/properties/?", new MetaPropertiesRule() );
+
+ beanReader.setXMLIntrospector( getXMLIntrospector() );
+ beanReader.registerBeanClass( clazz );
+
+ return beanReader;
+ }
+
+ /**
+ * If caching is enabled then this method will return a pooled introspector
+ *
+ * @return XMLIntrospector used for processing the MavenSession xml-based POM.
+ */
+ public static XMLIntrospector getXMLIntrospector()
+ {
+ if ( cacheIntrospector )
+ {
+ if ( singletonIntrospector == null )
+ {
+ singletonIntrospector = createXMLIntrospector();
+ }
+ return singletonIntrospector;
+ }
+ return createXMLIntrospector();
+ }
+
+ /**
+ * Create the type of XMLIntrospector that is used to read all MavenSession
style
+ * XML files.
+ *
+ * @return Betwixt XMLIntrospector
+ */
+ private static XMLIntrospector createXMLIntrospector()
+ {
+ XMLIntrospector introspector = new XMLIntrospector();
+
+ introspector.setAttributesForPrimitives( false );
+ introspector.setElementNameMapper( new DecapitalizeNameMapper() );
+
+ return introspector;
+ }
+
+ /**
+ * Get the XMLReader to use for processing XML related resources.
+ *
+ * @return an XMLReader which is pooled per thread
+ * @throws Exception If an error occurs while creating the XMLReader.
+ */
+ public static XMLReader getXMLReader()
+ throws Exception
+ {
+ XMLReader parser = (XMLReader) xmlReaderPool.get();
+ if ( parser == null )
+ {
+ parser = createXMLReader();
+ xmlReaderPool.set( parser );
+ }
+ return parser;
}
- // ----------------------------------------------------------------------
- // Static methods that can probably be moved to a real util class.
- // ----------------------------------------------------------------------
+ /**
+ * Creates a new XMLReader instance
+ *
+ * @return XMLReader used for parsing XML related maven resource.
+ * @throws Exception If an error occurs while creating the reader.
+ */
+ private static XMLReader createXMLReader()
+ throws Exception
+ {
+ SAXParserFactory factory = SAXParserFactory.newInstance();
+
+ factory.setNamespaceAware( true );
+
+ return factory.newSAXParser().getXMLReader();
+ }
/**
* Take a dominant and recessive Map and merge the key:value
@@ -535,6 +708,163 @@
return result;
}
+ /**
+ * Create a jelly context given a descriptor directory.
+ *
+ * @param descriptorDirectory The directory from which to pull the standard
maven
+ * properties files from.
+ * @return The generated maven based on the contents of the standard maven
+ * properties files.
+ */
+ public static MavenJellyContext createContext( File descriptorDirectory )
+ {
+ return createContext( descriptorDirectory, null );
+ }
+
+ /**
+ * Create a jelly context given a descriptor directory and parent
+ * jelly context.
+ *
+ * @param descriptorDirectory The directory from which to pull the standard
maven
+ * properties files from.
+ * @param parentContext The parent jelly context.
+ * @return The generated maven based on the contents of the standard maven
+ * properties files.
+ */
+ public static MavenJellyContext createContext( File descriptorDirectory,
+ MavenJellyContext parentContext )
+ {
+ // System properties
+ Properties systemProperties = System.getProperties();
+
+ // User build properties
+ File userBuildPropertiesFile =
+ new File( System.getProperty( "user.home" ), "build.properties" );
+
+ logger.debug( "Using userBuildPropertiesFile: " +
userBuildPropertiesFile.getAbsolutePath() );
+ Properties userBuildProperties = loadProperties( userBuildPropertiesFile );
+
+ // project build properties
+ File projectBuildPropertiesFile =
+ new File( descriptorDirectory, "build.properties" );
+
+ logger.debug( "Using projectBuildPropertiesFile: " +
projectBuildPropertiesFile.getAbsolutePath() );
+ Properties projectBuildProperties = loadProperties(
projectBuildPropertiesFile );
+
+ // project properties
+ File projectPropertiesFile =
+ new File( descriptorDirectory, "project.properties" );
+
+ logger.debug( "Using projectPropertiesFile: " +
projectPropertiesFile.getAbsolutePath() );
+ Properties projectProperties = loadProperties( projectPropertiesFile );
+
+ Properties driverProperties = loadProperties(
+ MavenUtils.class.getClassLoader().getResourceAsStream(
+ MavenConstants.DRIVER_PROPERTIES ) );
+
+ Properties defaultProperties = loadProperties(
+ MavenUtils.class.getClassLoader().getResourceAsStream(
+ MavenConstants.DEFAULTS_PROPERTIES ) );
+
+ Map result = MavenUtils.mergeMaps( new Map[]
+ {
+ systemProperties,
+ userBuildProperties,
+ projectBuildProperties,
+ projectProperties,
+ driverProperties
+ } );
+
+ MavenJellyContext context;
+
+ // If we have a parent we eventually want what values it can provide but
+ // we turn inheritance off momentarily until we finish integrating the
+ // child's context values into the jelly context because we want the
+ // child values to win and only use the parent in the event the
+ // child cannot provide the value.
+
+ if ( parentContext != null )
+ {
+ context = new MavenJellyContext( parentContext );
+ context.setInherit( false );
+
+ MavenUtils.integrateMapInContext( result, context );
+
+ // Turn inheritance back on to make the parent's values visible.
+ context.setInherit( true );
+
+ //add in the driver.properties with defaults, but in inheritance mode.
+ MavenUtils.integrateMapInContext( defaultProperties, context );
+ }
+ else
+ {
+ context = new MavenJellyContext();
+
+ //integrate everything else...
+ MavenUtils.integrateMapInContext( result, context );
+
+ //integrate defaults...
+ MavenUtils.integrateMapInContext( defaultProperties, context );
+
+ // Turn inheritance back on to make the parent's values visible.
+ context.setInherit( true );
+ }
+
+
+ // Set the basedir value in the context.
+ context.setVariable( "basedir", descriptorDirectory.getPath() );
+
+ return context;
+ }
+
+ /**
+ * Integrate a Map of key:value pairs into a <code>MavenJellyContext</code>.
+ * The values in the Map may be <code>CompositeExpression</code>s that need
+ * to be evaluated before being placed into the context.
+ *
+ * @param map Map to integrate into the provided jelly context.
+ * @param context Jelly context to integrate the map into.
+ */
+ public static void integrateMapInContext( Map map, MavenJellyContext context )
+ {
+ if ( map == null )
+ {
+ return;
+ }
+
+ JexlExpressionFactory factory = new JexlExpressionFactory();
+
+ for ( Iterator i = map.keySet().iterator(); i.hasNext(); )
+ {
+ String key = (String) i.next();
+ Object value;
+
+ if ( context.getVariable( key ) == null )
+ {
+ String literalValue = (String) map.get( key );
+
+ try
+ {
+ Expression expr = CompositeExpression.parse( literalValue,
factory );
+
+ if ( expr != null )
+ {
+ value = expr;
+ }
+ else
+ {
+ value = literalValue;
+ }
+
+ context.setVariable( key, value );
+ }
+ catch ( Exception e )
+ {
+ // do nothing.
+ }
+ }
+ }
+ }
/**
* Load properties from a <code>File</code>.
@@ -542,7 +872,7 @@
* @param file Propertie file to load.
* @return The loaded Properties.
*/
- public static Properties loadProperties( File file )
+ private static Properties loadProperties( File file )
{
try
{
@@ -562,7 +892,7 @@
* @param is InputStream from which load properties.
* @return The loaded Properties.
*/
- public static Properties loadProperties( InputStream is )
+ private static Properties loadProperties( InputStream is )
{
try
{
@@ -592,6 +922,55 @@
return null;
}
+ // ------------------------------------------------------------
+ // M E T A P R O P E R T I E S R U L E C L A S S
+ // ------------------------------------------------------------
+
+ /**
+ * A simple digester rule for populating an object in the POM
+ * with meta properties.
+ */
+ static class MetaPropertiesRule
+ extends Rule
+ {
+ /** The body of the found property. */
+ private String value;
+
+ /**
+ * Constructor for the InfoRule object
+ */
+ public MetaPropertiesRule()
+ {
+ }
+
+ /**
+ * Process the body of this element.
+ *
+ * @param namespace the namespace
+ * @param name the tag name
+ * @param text the body text
+ * @throws Exception when any errors occur
+ */
+ public void body(String namespace, String name, String text)
+ throws Exception
+ {
+ this.value = text;
+ }
+
+ /**
+ * Finish off this element.
+ *
+ * @throws Exception when any errors occur
+ */
+ public void end(String namespace, String elementName)
+ throws Exception
+ {
+ BaseObject baseObject = (BaseObject) getDigester().peek();
+ String name = getDigester().getCurrentElementName();
+ baseObject.addProperty( name + ":" + value );
+ }
+ }
+
/** Resource bundle with user messages. */
private static ResourceBundle messages;
@@ -651,5 +1030,44 @@
"${1}",
variable.toString() );
}
+ }
+
+ /**
+ * Resolve directory against a base directory if it is not already absolute.
+ * @param basedir the base directory for relative paths
+ * @param dir the directory to resolve
+ * @throws IOException if canonical path fails
+ */
+ public static String makeAbsolutePath( File basedir, String dir ) throws
IOException
+ {
+ if ( new File( dir ).isAbsolute() == false )
+ {
+ return new File( basedir, dir ).getCanonicalPath();
+ }
+ return dir;
+ }
+
+ /**
+ * Convert an absolute path to a relative path if it is under a given base
directory.
+ * @param basedir the base directory for relative paths
+ * @param path the directory to resolve
+ * @throws IOException if canonical path fails
+ */
+ public static String makeRelativePath( File basedir, String path ) throws
IOException
+ {
+ String canonicalBasedir = basedir.getCanonicalPath();
+ String canonicalPath = new File( path ).getCanonicalPath();
+ if ( canonicalPath.startsWith( canonicalBasedir ) )
+ {
+ if ( canonicalPath.charAt( canonicalBasedir.length() ) ==
File.separatorChar )
+ {
+ canonicalPath = canonicalPath.substring( canonicalBasedir.length()
+ 1 );
+ }
+ else
+ {
+ canonicalPath = canonicalPath.substring( canonicalBasedir.length()
);
+ }
+ }
+ return canonicalPath;
}
}
1.14 +7 -6 maven/src/java/org/apache/maven/ArtifactListBuilder.java
Index: ArtifactListBuilder.java
===================================================================
RCS file: /home/cvs/maven/src/java/org/apache/maven/ArtifactListBuilder.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- ArtifactListBuilder.java 4 Aug 2003 01:11:13 -0000 1.13
+++ ArtifactListBuilder.java 19 Aug 2003 04:31:38 -0000 1.14
@@ -56,7 +56,7 @@
* ====================================================================
*/
-import org.apache.plexus.util.StringUtils;
+import org.apache.commons.lang.StringUtils;
import org.apache.maven.project.Dependency;
import org.apache.maven.project.Project;
import org.apache.maven.repository.Artifact;
@@ -89,12 +89,12 @@
public static List build( final Project project )
{
List projectArtifacts = new ArrayList();
- boolean mavenJarOverride = project.getMavenJarOverride();
+ boolean mavenJarOverride =
project.getContext().getMavenJarOverride().booleanValue();
for ( Iterator i = project.getDependencies().iterator(); i.hasNext(); )
{
Dependency d = (Dependency) i.next();
- String mavenJarProperty = project.getMavenJarOverride(
Project.standardToLegacyId( d.getId() ) );
+ String mavenJarProperty = project.getContext().getMavenJarOverride(
Project.standardToLegacyId( d.getId() ) );
Artifact artifact = DefaultArtifactFactory.createArtifact( d );
if ( mavenJarOverride && StringUtils.isNotEmpty(mavenJarProperty) )
@@ -107,7 +107,7 @@
// User is requesting a specific version of a dependency
// be used.
d.setVersion( mavenJarProperty );
- artifact.setPath( project.getMavenRepoLocal() +
artifact.generatePath() );
+ artifact.setPath( project.getContext().getMavenRepoLocal() +
artifact.generatePath() );
}
else
{
@@ -118,8 +118,9 @@
}
else
{
- artifact.setPath( project.getMavenRepoLocal() +
artifact.generatePath() );
+ artifact.setPath( project.getContext().getMavenRepoLocal() +
artifact.generatePath() );
}
+
projectArtifacts.add( artifact );
}
1.12 +1 -1 maven/src/java/org/apache/maven/AbstractMavenComponent.java
Index: AbstractMavenComponent.java
===================================================================
RCS file: /home/cvs/maven/src/java/org/apache/maven/AbstractMavenComponent.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
1.29 +0 -7 maven/src/java/org/apache/maven/MavenConstants.java
Index: MavenConstants.java
===================================================================
RCS file: /home/cvs/maven/src/java/org/apache/maven/MavenConstants.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- MavenConstants.java 27 Jul 2003 23:33:56 -0000 1.28
+++ MavenConstants.java 19 Aug 2003 04:31:38 -0000 1.29
@@ -181,11 +181,4 @@
/** Dependency classpath tag. */
public static final String SESSION = "maven.session";
-
- /** Maven compile sourceroots. */
- public static final String COMPILE_SOURCEROOTS = "compile.sourceroots";
-
- /** Maven test compile sourceroots. */
- public static final String TEST_COMPILE_SOURCEROOTS =
"test.compile.sourceroots";
-
}
1.7 +2 -2 maven/src/java/org/apache/maven/DefaultProjectMarshaller.java
Index: DefaultProjectMarshaller.java
===================================================================
RCS file: /home/cvs/maven/src/java/org/apache/maven/DefaultProjectMarshaller.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DefaultProjectMarshaller.java 5 Aug 2003 15:05:57 -0000 1.6
+++ DefaultProjectMarshaller.java 19 Aug 2003 04:31:38 -0000 1.7
@@ -168,7 +168,7 @@
marshallBuild( project );
marshallReports( project );
- marshallProperties( project.getProperties() );
+ //marshallProperties( project.getProperties() );
serializer.endTag( NAMESPACE, "project" );
serializer.endDocument();
@@ -453,7 +453,7 @@
marshallString( dependency.getType(), "type" );
marshallString( dependency.getUrl(), "url" );
- marshallProperties( dependency.getProperties() );
+ //marshallProperties( dependency.getProperties() );
serializer.endTag( NAMESPACE, "dependency" );
}
1.8 +13 -13 maven/src/java/org/apache/maven/DefaultProjectUnmarshaller.java
Index: DefaultProjectUnmarshaller.java
===================================================================
RCS file: /home/cvs/maven/src/java/org/apache/maven/DefaultProjectUnmarshaller.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DefaultProjectUnmarshaller.java 5 Aug 2003 15:05:57 -0000 1.7
+++ DefaultProjectUnmarshaller.java 19 Aug 2003 04:31:38 -0000 1.8
@@ -61,6 +61,7 @@
import org.apache.maven.project.Contributor;
import org.apache.maven.project.Dependency;
import org.apache.maven.project.Developer;
+import org.apache.maven.project.License;
import org.apache.maven.project.MailingList;
import org.apache.maven.project.Organization;
import org.apache.maven.project.Project;
@@ -69,7 +70,6 @@
import org.apache.maven.project.UnitTest;
import org.apache.maven.project.Version;
import org.apache.maven.project.SourceModification;
-import org.apache.maven.project.License;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
@@ -496,7 +496,7 @@
}
else if ( parser.getName().equals( "properties" ) )
{
- d.setProperties( unmarshallProperties( parser )
);
+ //d.setProperties( unmarshallProperties( parser
) );
}
else
{
@@ -512,31 +512,31 @@
}
else if ( parser.getName().equals( "build" ) )
{
- Build build = new Build();
- project.setBuild( build );
+ Build b = new Build();
+ project.setBuild( b );
while ( parser.nextTag() == XmlPullParser.START_TAG )
{
if ( parser.getName().equals( "nagEmailAddress" ) )
{
- build.setNagEmailAddress( parser.nextText() );
+ b.setNagEmailAddress( parser.nextText() );
}
else if ( parser.getName().equals( "sourceDirectory" ) )
{
- build.setSourceDirectory( parser.nextText() );
+ b.setSourceDirectory( parser.nextText() );
}
else if ( parser.getName().equals(
"unitTestSourceDirectory" ) )
{
- build.setUnitTestSourceDirectory( parser.nextText() );
+ b.setUnitTestSourceDirectory( parser.nextText() );
}
else if ( parser.getName().equals( "aspectSourceDirectory"
) )
{
- build.setAspectSourceDirectory( parser.nextText() );
+ b.setAspectSourceDirectory( parser.nextText() );
}
else if ( parser.getName().equals( "unitTest" ) )
{
UnitTest ut = new UnitTest();
- build.setUnitTest( ut );
+ b.setUnitTest( ut );
while ( parser.nextTag() == XmlPullParser.START_TAG )
{
@@ -595,7 +595,7 @@
{
if ( parser.getName().equals( "resource" ) )
{
- build.addResource( unmarshalResource( parser )
);
+ b.addResource( unmarshalResource( parser ) );
}
else
{
@@ -610,7 +610,7 @@
if ( parser.getName().equals( "sourceModification"
) )
{
SourceModification sm = new
SourceModification();
- build.addSourceModification( sm );
+ b.addSourceModification( sm );
while ( parser.nextTag() ==
XmlPullParser.START_TAG )
{
@@ -678,7 +678,7 @@
}
else if ( parser.getName().equals( "properties" ) )
{
- project.setProperties( unmarshallProperties( parser ) );
+ //project.setProperties( unmarshallProperties( parser ) );
}
}
1.4 +1 -1 maven/src/java/org/apache/maven/NoGoalException.java
Index: NoGoalException.java
===================================================================
RCS file: /home/cvs/maven/src/java/org/apache/maven/NoGoalException.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
1.17 +0 -0 maven/src/java/org/apache/maven/MavenSession.java
1.13 +2 -2 maven/src/java/org/apache/maven/DependencyClasspathBuilder.java
1.6 +0 -0 maven/src/java/org/apache/maven/AntProjectBuilder.java
1.14 +2 -1
maven/src/java/org/apache/maven/repository/DefaultArtifactFactory.java
Index: DefaultArtifactFactory.java
===================================================================
RCS file:
/home/cvs/maven/src/java/org/apache/maven/repository/DefaultArtifactFactory.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- DefaultArtifactFactory.java 11 Apr 2003 23:45:33 -0000 1.13
+++ DefaultArtifactFactory.java 19 Aug 2003 04:31:38 -0000 1.14
@@ -76,6 +76,7 @@
* type.
*
* @param dependency The base dependency.
+ * @todo not the intended usage of test type
* @return The appropriate artifact based on the dependency type.
*/
public static Artifact createArtifact( Dependency dependency )
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]