dion 2002/11/05 07:37:37
Modified: src/java/org/apache/maven MavenUtils.java
Log:
Fix project extends not working.
Revision Changes Path
1.54 +69 -69 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.53
retrieving revision 1.54
diff -u -r1.53 -r1.54
--- MavenUtils.java 4 Nov 2002 14:59:37 -0000 1.53
+++ MavenUtils.java 5 Nov 2002 15:37:37 -0000 1.54
@@ -57,7 +57,7 @@
*/
import com.bluecast.xml.JAXPSAXParserFactory;
-
+
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -113,22 +113,22 @@
/** Internal encoding used for Jelly interpolation. */
private final static String INTERNAL_ENCODING = "ISO-8859-1";
- /**
- * A thread pool to avoid the startup overhead of the XML parser each
+ /**
+ * A thread pool to avoid the startup overhead of the XML parser each
* time we want to parse something
*/
private static final ThreadLocal xmlReaderPool = new ThreadLocal();
/**
* Should we cache and reuse the introspector
- */
- private static boolean cacheIntrospector = true;
+ */
+ private static boolean cacheIntrospector = true;
/**
* The singleton introspector if caching is enabled
*/
private static XMLIntrospector singletonIntrospector;
-
+
/** Project Bean Reader */
private static BeanReader projectBeanReader;
@@ -146,11 +146,11 @@
}
/*
-
+
project.xml [ISO-8859-1]
|
v
-
+
*/
/**
@@ -160,12 +160,12 @@
* @param parentContext a context to resolve variables
* @throws Exception when anything goes wrong. FIXME this is bad
*/
- public static Project getProject(File projectDescriptor,
+ public static Project getProject(File projectDescriptor,
MavenJellyContext parentContext) throws Exception
{
return getProject(projectDescriptor, new File("."), parentContext);
}
-
+
/**
* @return the POM from the given file in the given directory, with no
* parent context
@@ -188,9 +188,9 @@
* @return the Maven project object for the given project descriptor
* @throws Exception when any errors occur
*/
- public static Project getProject(File projectDescriptor,
+ public static Project getProject(File projectDescriptor,
File dir,
- MavenJellyContext parentContext)
+ MavenJellyContext parentContext)
throws Exception
{
BeanReader projectBeanReader = getProjectBeanReader();
@@ -202,7 +202,7 @@
if (pomToExtend.startsWith("template:"))
{
JellyContext context = null;
-
+
if (parentContext != null)
{
context = new JellyContext(parentContext);
@@ -230,23 +230,23 @@
// parent = (Project) projectBeanReader.parse(
// new File(dir, pomToExtend));
// }
-
- Project parent = (Project)
- projectBeanReader.parse( new File( pomToExtend ) );
-
+
+ Project parent = (Project)
+ projectBeanReader.parse( new File(dir, pomToExtend ) );
+
project = (Project) mergeBeans(project, parent);
}
-
+
project = getJellyProject(project, parentContext);
project.setFile(projectDescriptor);
-
+
return project;
}
/**
* Create a project bean reader. We use it more than once so we don't
* want to create it more than once.
- *
+ *
* @return a {@link BeanReader} capable of reading {@link Project projects}
* @throws Exception when anything goes wrong. FIXME this is bad
*/
@@ -256,8 +256,8 @@
if (projectBeanReader == null)
{
projectBeanReader = createBeanReader(Project.class);
- }
-
+ }
+
return projectBeanReader;
}
@@ -269,12 +269,12 @@
* @return Jelly interpolated project.
* @throws Exception when anything goes wrong. FIXME this is bad
*/
- private static Project getJellyProject(Project project,
- MavenJellyContext parentContext)
+ private static Project getJellyProject(Project project,
+ MavenJellyContext parentContext)
throws Exception
{
JellyContext context = null;
-
+
if (parentContext != null)
{
context = new JellyContext(parentContext);
@@ -285,23 +285,23 @@
context = new JellyContext();
}
context.setVariable("pom", project);
-
- Script script = JellyUtils.compileScript(getProjectInputStream(project),
+
+ Script script = JellyUtils.compileScript(getProjectInputStream(project),
context,
INTERNAL_ENCODING);
-
+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Writer writer = new BufferedWriter(new OutputStreamWriter(baos));
XMLOutput output = XMLOutput.createXMLOutput(writer);
script.run(context, output);
writer.close();
-
+
BeanReader projectBeanReader = getProjectBeanReader();
-
+
return (Project) projectBeanReader.parse(
new StringReader(baos.toString()));
}
-
+
/**
* @return an {@link InputStream} for the given project
* @param project a {@link Project maven project}
@@ -328,11 +328,11 @@
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);
}
@@ -341,7 +341,7 @@
*
* I would like to use BeanUtils but it doesn't quite work the
* way I need. So I will patch it later.
- *
+ *
* @param child child object
* @param parent the maven project
* @return the child after project properties have been copied
@@ -356,7 +356,7 @@
/**
* 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
@@ -365,7 +365,7 @@
{
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
@@ -373,12 +373,12 @@
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);
@@ -396,7 +396,7 @@
}
return child;
}
-
+
/**
* Test if a value is a primitive or not
* @param o the value to test
@@ -404,19 +404,19 @@
*/
private static boolean valuePrimitive(Object o)
{
- if (o instanceof Boolean || o instanceof String
+ 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
*/
@@ -433,7 +433,7 @@
else
{
return false;
- }
+ }
}
/**
@@ -462,7 +462,7 @@
BeanReader reader = createBeanReader(Profile.class);
Profile profile = (Profile) reader.parse(
new FileInputStream(profileDescriptor));
-
+
return profile;
}
@@ -504,13 +504,13 @@
BeanReader workspaceReader = createBeanReader(Workspace.class);
Workspace workspace = (Workspace) workspaceReader.parse(
new FileInputStream(workspaceDescriptor));
-
+
// Create our profile.
Profile profile = getProfile(profileDescriptor);
-
+
// Set the workspace profile.
workspace.setProfile(profile);
-
+
// Create our set of project.
for (Iterator i = profile.getProjectIds().iterator(); i.hasNext();)
{
@@ -518,13 +518,13 @@
// This should take care of any trailing slashes, or the directory
// formatted in any arbitrary fashion. I don't want to expect a
// particular format because people do everything different.
- File baseDir = new File(new File(mavenLocalRepo, "project"),
+ File baseDir = new File(new File(mavenLocalRepo, "project"),
projectId);
File projectDescriptor = new File(baseDir, "project.xml");
// Map the project descriptors and add them to the profile.
Project project = getProject(projectDescriptor);
-
+
profile.addProject(project);
}
@@ -570,11 +570,11 @@
return files;
}
-
+
/**
* This is currently used for the reactor but may be
* generally useful.
- *
+ *
* @param directory the directory to scan for maven projects
* @param includes the pattern that matches a project
* @return a {link List} of {@link Project}s
@@ -584,20 +584,20 @@
throws Exception
{
String[] files = getFiles(directory, includes);
-
+
List projects = new ArrayList();
-
+
for (int i = 0; i < files.length; i++)
{
- projects.add(getProject(new File(files[i]),
+ projects.add(getProject(new File(files[i]),
new File(files[i]).getParentFile()));
}
-
+
return projects;
}
- /**
- * Creates a new instance of BeanReader
+ /**
+ * Creates a new instance of BeanReader
*
* @param clazz the class to register with the reader
* @return a {@link BeanReader bean reader}
@@ -605,27 +605,27 @@
* properties of the class provided
* @throws Exception when anything goes wrong. FIXME this is bad
*/
- public static BeanReader createBeanReader(Class clazz)
+ public static BeanReader createBeanReader(Class clazz)
throws Exception
{
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
- */
+ */
public static XMLIntrospector getXMLIntrospector()
{
- if (cacheIntrospector)
+ if (cacheIntrospector)
{
- if (singletonIntrospector == null)
+ if (singletonIntrospector == null)
{
singletonIntrospector = createXMLIntrospector();
}
@@ -633,7 +633,7 @@
}
return createXMLIntrospector();
}
-
+
/**
* Create the type of XMLIntrospector that is used to read
@@ -648,14 +648,14 @@
introspector.setAttributesForPrimitives(false);
introspector.setCachingEnabled(true);
introspector.setNameMapper(new DecapitalizeNameMapper());
-
+
return introspector;
}
/**
* @return an XMLReader which is pooled per thread
*/
- public static XMLReader getXMLReader() throws Exception
+ public static XMLReader getXMLReader() throws Exception
{
XMLReader parser = (XMLReader) xmlReaderPool.get();
if (parser == null)
@@ -670,7 +670,7 @@
/**
* Creates a new XMLReader instance
*/
- private static XMLReader createXMLReader() throws Exception
+ private static XMLReader createXMLReader() throws Exception
{
SAXParserFactory factory = new JAXPSAXParserFactory();
--
To unsubscribe, e-mail: <mailto:turbine-maven-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:turbine-maven-dev-help@;jakarta.apache.org>