jvanzyl 2002/12/30 23:01:38
Modified: src/java/org/apache/maven MavenUtils.java
Log:
refactoring
Revision Changes Path
1.80 +44 -28 jakarta-turbine-maven/src/java/org/apache/maven/MavenUtils.java
Index: MavenUtils.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/MavenUtils.java,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -r1.79 -r1.80
--- MavenUtils.java 18 Dec 2002 17:13:37 -0000 1.79
+++ MavenUtils.java 31 Dec 2002 07:01:38 -0000 1.80
@@ -26,12 +26,12 @@
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
- * "Apache Maven" must not be used to endorse or promote products
+ * "Apache MavenSession" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
- * "Apache Maven", nor may "Apache" appear in their name, without
+ * "Apache MavenSession", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
@@ -60,8 +60,8 @@
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.collections.BeanMap;
import org.apache.commons.digester.ExtendedBaseRules;
import org.apache.commons.digester.Rule;
import org.apache.commons.jelly.JellyContext;
@@ -96,12 +96,12 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-import java.util.Locale;
import java.util.Map;
-import java.util.MissingResourceException;
import java.util.Properties;
-import java.util.ResourceBundle;
import java.util.Set;
+import java.util.ResourceBundle;
+import java.util.MissingResourceException;
+import java.util.Locale;
/**
* Utilities for reading maven project descriptors, profile descriptors and
@@ -133,28 +133,27 @@
/** Project Bean Reader */
private static BeanReader projectBeanReader;
- /**
+ /**
* 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
+ * @return the MavenSession project object for the given project descriptor
* @throws Exception when any errors occur
*/
public static Project getProject( File projectDescriptor )
throws Exception
{
- return getProject( projectDescriptor, new File( "." ) );
+ return getProject( projectDescriptor, null );
}
/**
* Create a Project object given a file descriptor.
*
* @param projectDescriptor a maven project.xml {@link File}
- * @param dir the base directory to find related files
- * @return the Maven project object for the given project descriptor
+ * @return the MavenSession project object for the given project descriptor
* @throws Exception when any errors occur
*/
- public static Project getProject( File projectDescriptor, File dir )
+ public static Project getProject( File projectDescriptor, MavenJellyContext
parentContext )
throws Exception
{
BeanReader projectBeanReader = getProjectBeanReader();
@@ -163,15 +162,22 @@
String pomToExtend = project.getExtend();
if ( pomToExtend != null )
{
- Project parent = (Project)
- projectBeanReader.parse( new File( dir, pomToExtend ) );
-
+ Project parent = (Project) projectBeanReader.parse( new File(
pomToExtend ) );
project = (Project) mergeBeans( project, parent );
}
project = getJellyProject( project );
project.setFile( projectDescriptor );
+ MavenJellyContext context = MavenUtils.createContext(
projectDescriptor.getParentFile(),
+ parentContext );
+
+ context.setProject( project );
+ project.setContext( context );
+
+ // Fully initialize the project.
+ project.initialize();
+
return project;
}
@@ -237,7 +243,7 @@
/**
* Create an XML string from a project.
*
- * @param project Maven project to turn into an XML representation.
+ * @param project MavenSession project to turn into an XML representation.
* @return XML representation of the project
* @throws Exception when anything goes wrong. FIXME this is bad
*/
@@ -396,10 +402,10 @@
* @return a {link List} of {@link Project}s
* @throws Exception when anything goes wrong. FIXME this is bad
*/
- public static List getProjects( File directory, String includes )
+ public static List getProjects( File directory, String includes,
MavenJellyContext context )
throws Exception
{
- return getProjects( directory, includes, null );
+ return getProjects( directory, includes, null, context );
}
/**
@@ -411,7 +417,10 @@
* @return a {link List} of {@link Project}s
* @throws Exception when anything goes wrong. FIXME this is bad
*/
- public static List getProjects( File directory, String includes, String
excludes )
+ public static List getProjects( File directory,
+ String includes,
+ String excludes,
+ MavenJellyContext context )
throws Exception
{
String[] files = getFiles( directory, includes, excludes );
@@ -420,8 +429,7 @@
for ( int i = 0; i < files.length; i++ )
{
- projects.add( getProject( new File( files[i] ),
- new File( files[i] ).getParentFile() ) );
+ projects.add( getProject( new File( files[i] ), context ) );
}
return projects;
@@ -452,7 +460,7 @@
/**
* If caching is enabled then this method will return a pooled introspector
*
- * @return XMLIntrospector used for processing the Maven xml-based POM.
+ * @return XMLIntrospector used for processing the MavenSession xml-based POM.
*/
public static XMLIntrospector getXMLIntrospector()
{
@@ -468,7 +476,7 @@
}
/**
- * Create the type of XMLIntrospector that is used to read all Maven style
+ * Create the type of XMLIntrospector that is used to read all MavenSession
style
* XML files.
*
* @return Betwixt XMLIntrospector
@@ -479,7 +487,7 @@
introspector.setAttributesForPrimitives( false );
introspector.setCachingEnabled( true );
- introspector.setNameMapper( new DecapitalizeNameMapper() );
+ introspector.setElementNameMapper( new DecapitalizeNameMapper() );
return introspector;
}
@@ -663,7 +671,6 @@
logger.debug( "Using projectPropertiesFile: " +
projectPropertiesFile.getAbsolutePath() );
Properties projectProperties = loadProperties( projectPropertiesFile );
- // driver properties
Properties driverProperties = loadProperties(
MavenUtils.class.getClassLoader().getResourceAsStream(
MavenConstants.DRIVER_PROPERTIES ) );
@@ -679,10 +686,16 @@
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( true );
+ context.setInherit( false );
}
else
{
@@ -691,6 +704,9 @@
MavenUtils.integrateMapInContext( result, context );
+ // Turn inheritance back on to make the parent's values visible;
+ context.setInherit( true );
+
return context;
}
@@ -850,7 +866,7 @@
private static ResourceBundle messages;
/**
- * Load Maven user messages from a resource bundle given the
+ * Load MavenSession user messages from a resource bundle given the
* user's locale.
* @todo Move locale tools into their own class.
*/
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>