You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by ad...@apache.org on 2002/04/07 08:51:40 UTC
cvs commit: jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/frontends CLIMain.java EmbeddedAnt.java Resources.properties
adammurdoch 02/04/06 22:51:40
Modified: proposal/myrmidon/src/java/org/apache/myrmidon/components/builder
ConvertingProjectBuilder.java
DefaultProjectBuilder.java
proposal/myrmidon/src/java/org/apache/myrmidon/frontends
CLIMain.java EmbeddedAnt.java Resources.properties
Log:
* Added --type command-line option, which specifies which ProjectBuilder to use.
* Use ConvertingProjectBuilder for .ant files as well as .xml files.
Revision Changes Path
1.3 +36 -33 jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/ConvertingProjectBuilder.java
Index: ConvertingProjectBuilder.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/ConvertingProjectBuilder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ConvertingProjectBuilder.java 1 Apr 2002 09:56:25 -0000 1.2
+++ ConvertingProjectBuilder.java 7 Apr 2002 06:51:40 -0000 1.3
@@ -18,9 +18,11 @@
* configuration into a Myrmidon one.
*
* @author <a href="mailto:darrell@apache.org">Darrell DeBoer</a>
- * @version $Revision: 1.2 $ $Date: 2002/04/01 09:56:25 $
+ * @version $Revision: 1.3 $ $Date: 2002/04/07 06:51:40 $
*
* @ant.type type="project-builder" name="xml"
+ * @ant.type type="project-builder" name="ant"
+ * @ant.type type="project-builder" name="default"
*/
public class ConvertingProjectBuilder
extends DefaultProjectBuilder
@@ -34,10 +36,10 @@
* @return the configured project
* @throws ProjectException if an error occurs parsing the project file
*/
- protected Configuration parseProject( String systemID )
+ protected Configuration parseProject( final String systemID )
throws ProjectException
{
- Configuration originalConfig = super.parseProject( systemID );
+ final Configuration originalConfig = super.parseProject( systemID );
// Check the version, if it's present, just use this config.
// TODO: check for version < 2.0
@@ -48,21 +50,21 @@
// Convert the config by prepending "ant1." on tasks,
// and using <if> tasks instead of target 'if=' and 'unless='
- DefaultConfiguration newConfig = copyConfiguration( originalConfig );
+ final DefaultConfiguration newConfig = copyConfiguration( originalConfig );
// Put a new version attribute.
newConfig.setAttribute( VERSION_ATTRIBUTE, "2.0" );
// Copy the remaining attributes.
- Set omitAttributes = new HashSet();
+ final Set omitAttributes = new HashSet();
omitAttributes.add( VERSION_ATTRIBUTE );
copyAttributes( originalConfig, newConfig, omitAttributes );
// Now copy/convert the children
- Configuration[] children = originalConfig.getChildren();
+ final Configuration[] children = originalConfig.getChildren();
for( int i = 0; i < children.length; i++ )
{
- Configuration child = children[ i ];
+ final Configuration child = children[ i ];
if( child.getName().equals( "target" ) )
{
@@ -82,12 +84,12 @@
* @param originalTarget The Ant1 Target
* @return the converted target
*/
- private Configuration convertTarget( Configuration originalTarget )
+ private Configuration convertTarget( final Configuration originalTarget )
{
- DefaultConfiguration newTarget = copyConfiguration( originalTarget );
+ final DefaultConfiguration newTarget = copyConfiguration( originalTarget );
// Copy all attributes except 'if' and 'unless'
- Set omitAttributes = new HashSet();
+ final Set omitAttributes = new HashSet();
omitAttributes.add( "if" );
omitAttributes.add( "unless" );
copyAttributes( originalTarget, newTarget, omitAttributes );
@@ -95,10 +97,10 @@
DefaultConfiguration containerElement = newTarget;
// For 'if="prop-name"', replace with <if> task.
- String ifAttrib = originalTarget.getAttribute( "if", null );
+ final String ifAttrib = originalTarget.getAttribute( "if", null );
if ( ifAttrib != null )
{
- DefaultConfiguration ifElement =
+ final DefaultConfiguration ifElement =
buildIfElement( ifAttrib, false, originalTarget.getLocation() );
containerElement.addChild( ifElement );
// Treat the ifElement as the enclosing target.
@@ -106,10 +108,10 @@
}
// For 'unless="prop-name"', replace with <if> task (negated).
- String unlessAttrib = originalTarget.getAttribute( "unless", null );
+ final String unlessAttrib = originalTarget.getAttribute( "unless", null );
if ( unlessAttrib != null )
{
- DefaultConfiguration unlessElement =
+ final DefaultConfiguration unlessElement =
buildIfElement( unlessAttrib, true, originalTarget.getLocation() );
containerElement.addChild( unlessElement );
// Treat the unlessElement as the enclosing target.
@@ -117,7 +119,7 @@
}
// Now copy in converted tasks.
- Configuration[] tasks = originalTarget.getChildren();
+ final Configuration[] tasks = originalTarget.getChildren();
for( int i = 0; i < tasks.length; i++ )
{
containerElement.addChild( convertTask( tasks[ i ] ) );
@@ -134,8 +136,8 @@
* @param location the configuration location to use
* @return The configuration for an <if> task
*/
- private DefaultConfiguration buildIfElement( String ifProperty,
- boolean unless,
+ private DefaultConfiguration buildIfElement( final String ifProperty,
+ final boolean unless,
final String location )
{
// <if>
@@ -144,17 +146,17 @@
// </condition>
// .. tasks
// </if>
- DefaultConfiguration isSetElement =
+ final DefaultConfiguration isSetElement =
new DefaultConfiguration( "is-set", location );
isSetElement.setAttribute( "property", ifProperty );
- DefaultConfiguration conditionElement =
+ final DefaultConfiguration conditionElement =
new DefaultConfiguration( "condition", location );
if ( unless )
{
// Surround <is-set> with <not>
- DefaultConfiguration notElement =
+ final DefaultConfiguration notElement =
new DefaultConfiguration( "not", location );
notElement.addChild( isSetElement );
conditionElement.addChild( notElement );
@@ -165,7 +167,7 @@
}
- DefaultConfiguration ifElement =
+ final DefaultConfiguration ifElement =
new DefaultConfiguration( "if", location );
ifElement.addChild( conditionElement );
@@ -177,11 +179,11 @@
* @param originalTask The Ant1 Task
* @return the converted task
*/
- private Configuration convertTask( Configuration originalTask )
+ private Configuration convertTask( final Configuration originalTask )
{
// Create a new configuration with the "ant1." prefix.
- String newTaskName = "ant1." + originalTask.getName();
- DefaultConfiguration newTask =
+ final String newTaskName = "ant1." + originalTask.getName();
+ final DefaultConfiguration newTask =
new DefaultConfiguration( newTaskName, originalTask.getLocation() );
// Copy all attributes and elements of the task.
@@ -196,9 +198,10 @@
* @param from Configuration to copy from
* @param to Configuration to copy to
*/
- private void copyChildren( Configuration from, DefaultConfiguration to )
+ private void copyChildren( final Configuration from,
+ final DefaultConfiguration to )
{
- Configuration[] children = from.getChildren();
+ final Configuration[] children = from.getChildren();
for( int i = 0; i < children.length; i++ )
{
to.addChild( children[ i ] );
@@ -212,20 +215,20 @@
* @param to Configuration to copy to
* @param omitAttributes a Set of attribute names to exclude
*/
- private void copyAttributes( Configuration from,
- DefaultConfiguration to,
- Set omitAttributes )
+ private void copyAttributes( final Configuration from,
+ final DefaultConfiguration to,
+ final Set omitAttributes )
{
// Copy other attributes
- String[] attribs = from.getAttributeNames();
+ final String[] attribs = from.getAttributeNames();
for( int i = 0; i < attribs.length; i++ )
{
- String name = attribs[ i ];
+ final String name = attribs[ i ];
if( omitAttributes.contains( name ) )
{
continue;
}
- String value = from.getAttribute( name, "" );
+ final String value = from.getAttribute( name, "" );
to.setAttribute( name, value );
}
}
@@ -236,7 +239,7 @@
* @param originalConfig the COnfiguration to copy.
* @return the new Configuration
*/
- private DefaultConfiguration copyConfiguration( Configuration originalConfig )
+ private DefaultConfiguration copyConfiguration( final Configuration originalConfig )
{
return new DefaultConfiguration( originalConfig.getName(),
originalConfig.getLocation() );
1.43 +2 -2 jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/DefaultProjectBuilder.java
Index: DefaultProjectBuilder.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/DefaultProjectBuilder.java,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- DefaultProjectBuilder.java 1 Apr 2002 09:56:25 -0000 1.42
+++ DefaultProjectBuilder.java 7 Apr 2002 06:51:40 -0000 1.43
@@ -34,9 +34,9 @@
* Default implementation to construct project from a build file.
*
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
- * @version $Revision: 1.42 $ $Date: 2002/04/01 09:56:25 $
+ * @version $Revision: 1.43 $ $Date: 2002/04/07 06:51:40 $
*
- * @ant.type type="project-builder" name="ant"
+ * @ant.type type="project-builder" name="ant2"
*/
public class DefaultProjectBuilder
extends AbstractLogEnabled
1.38 +12 -3 jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/frontends/CLIMain.java
Index: CLIMain.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/frontends/CLIMain.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- CLIMain.java 3 Apr 2002 10:58:19 -0000 1.37
+++ CLIMain.java 7 Apr 2002 06:51:40 -0000 1.38
@@ -32,7 +32,7 @@
* to run project.
*
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
- * @version $Revision: 1.37 $ $Date: 2002/04/03 10:58:19 $
+ * @version $Revision: 1.38 $ $Date: 2002/04/07 06:51:40 $
*/
public class CLIMain
{
@@ -55,6 +55,7 @@
private static final int HOME_DIR_OPT = 7;
private static final int DRY_RUN_OPT = 8;
private static final int DEBUG_OPT = 9;
+ private static final int TYPE_OPT = 10;
//incompatable options for info options
private static final int[] INFO_OPT_INCOMPAT = new int[]
@@ -62,7 +63,7 @@
HELP_OPT, QUIET_OPT, VERBOSE_OPT, FILE_OPT,
LOG_LEVEL_OPT, BUILDER_PARAM_OPT, NO_PREFIX_OPT,
VERSION_OPT, LISTENER_OPT, TASKLIB_DIR_OPT,
- INCREMENTAL_OPT, HOME_DIR_OPT, DRY_RUN_OPT
+ INCREMENTAL_OPT, HOME_DIR_OPT, DRY_RUN_OPT, TYPE_OPT
};
//incompatable options for other logging options
@@ -214,7 +215,11 @@
new CLOptionDescriptor( "dry-run",
CLOptionDescriptor.ARGUMENT_DISALLOWED,
DRY_RUN_OPT,
- REZ.getString( "dry-run.opt" ) )
+ REZ.getString( "dry-run.opt" ) ),
+ new CLOptionDescriptor( "type",
+ CLOptionDescriptor.ARGUMENT_REQUIRED,
+ TYPE_OPT,
+ REZ.getString( "type.opt" ) )
};
return options;
@@ -293,6 +298,10 @@
case DRY_RUN_OPT:
m_dryRun = true;
+ break;
+
+ case TYPE_OPT:
+ m_embedded.setProjectType( option.getArgument( 0 ) );
break;
case 0:
1.7 +12 -3 jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/frontends/EmbeddedAnt.java
Index: EmbeddedAnt.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/frontends/EmbeddedAnt.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- EmbeddedAnt.java 3 Apr 2002 10:58:19 -0000 1.6
+++ EmbeddedAnt.java 7 Apr 2002 06:51:40 -0000 1.7
@@ -35,7 +35,7 @@
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
- * @version $Revision: 1.6 $ $Date: 2002/04/03 10:58:19 $
+ * @version $Revision: 1.7 $ $Date: 2002/04/07 06:51:40 $
*/
public class EmbeddedAnt
extends AbstractLogEnabled
@@ -56,6 +56,7 @@
private ClassLoader m_sharedClassLoader;
private Embeddor m_embeddor;
private File m_homeDir;
+ private String m_projectType;
/**
* Sets the Myrmidon home directory. Default is to use the current
@@ -79,6 +80,15 @@
}
/**
+ * Sets the project file type. Ignored if {@link #setProject} is used.
+ * Set to null to use the default project type.
+ */
+ public void setProjectType( final String projectType )
+ {
+ m_projectType = projectType;
+ }
+
+ /**
* Sets the project to execute. This method can be used instead of
* {@link #setProjectFile}, for projects models that are built
* programmatically.
@@ -312,7 +322,7 @@
if( m_project == null )
{
final File buildFile = getProjectFile();
- m_project = embeddor.createProject( buildFile.toString(), null, m_builderProps );
+ m_project = embeddor.createProject( buildFile.toString(), m_projectType, m_builderProps );
}
return m_project;
}
@@ -368,5 +378,4 @@
throw new Exception( message );
}
}
-
}
1.9 +1 -0 jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/frontends/Resources.properties
Index: Resources.properties
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/frontends/Resources.properties,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Resources.properties 3 Apr 2002 10:58:19 -0000 1.8
+++ Resources.properties 7 Apr 2002 06:51:40 -0000 1.9
@@ -15,6 +15,7 @@
define.opt=Define a property (ie -Dfoo=var).
build.opt=Define a builder parameter (ie -Bfoo=var).
dry-run.opt=Do not execute tasks - just print them out.
+type.opt=Specify the project file type.
file-no-exist.error={0} {1} does not exist.
file-not-dir.error={0} {1} is not a directory.
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>