Browse Source

* Added --type command-line option, which specifies which ProjectBuilder to use.

* Use ConvertingProjectBuilder for .ant files as well as .xml files.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272265 13f79535-47bb-0310-9956-ffa450edef68
master
adammurdoch 23 years ago
parent
commit
bf9414c704
5 changed files with 59 additions and 37 deletions
  1. +35
    -32
      proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/ConvertingProjectBuilder.java
  2. +1
    -1
      proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/DefaultProjectBuilder.java
  3. +11
    -2
      proposal/myrmidon/src/java/org/apache/myrmidon/frontends/CLIMain.java
  4. +11
    -2
      proposal/myrmidon/src/java/org/apache/myrmidon/frontends/EmbeddedAnt.java
  5. +1
    -0
      proposal/myrmidon/src/java/org/apache/myrmidon/frontends/Resources.properties

+ 35
- 32
proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/ConvertingProjectBuilder.java View File

@@ -21,6 +21,8 @@ import org.apache.myrmidon.interfaces.builder.ProjectException;
* @version $Revision$ $Date$ * @version $Revision$ $Date$
* *
* @ant.type type="project-builder" name="xml" * @ant.type type="project-builder" name="xml"
* @ant.type type="project-builder" name="ant"
* @ant.type type="project-builder" name="default"
*/ */
public class ConvertingProjectBuilder public class ConvertingProjectBuilder
extends DefaultProjectBuilder extends DefaultProjectBuilder
@@ -34,10 +36,10 @@ public class ConvertingProjectBuilder
* @return the configured project * @return the configured project
* @throws ProjectException if an error occurs parsing the project file * @throws ProjectException if an error occurs parsing the project file
*/ */
protected Configuration parseProject( String systemID )
protected Configuration parseProject( final String systemID )
throws ProjectException throws ProjectException
{ {
Configuration originalConfig = super.parseProject( systemID );
final Configuration originalConfig = super.parseProject( systemID );


// Check the version, if it's present, just use this config. // Check the version, if it's present, just use this config.
// TODO: check for version < 2.0 // TODO: check for version < 2.0
@@ -48,21 +50,21 @@ public class ConvertingProjectBuilder


// Convert the config by prepending "ant1." on tasks, // Convert the config by prepending "ant1." on tasks,
// and using <if> tasks instead of target 'if=' and 'unless=' // and using <if> tasks instead of target 'if=' and 'unless='
DefaultConfiguration newConfig = copyConfiguration( originalConfig );
final DefaultConfiguration newConfig = copyConfiguration( originalConfig );


// Put a new version attribute. // Put a new version attribute.
newConfig.setAttribute( VERSION_ATTRIBUTE, "2.0" ); newConfig.setAttribute( VERSION_ATTRIBUTE, "2.0" );


// Copy the remaining attributes. // Copy the remaining attributes.
Set omitAttributes = new HashSet();
final Set omitAttributes = new HashSet();
omitAttributes.add( VERSION_ATTRIBUTE ); omitAttributes.add( VERSION_ATTRIBUTE );
copyAttributes( originalConfig, newConfig, omitAttributes ); copyAttributes( originalConfig, newConfig, omitAttributes );


// Now copy/convert the children // Now copy/convert the children
Configuration[] children = originalConfig.getChildren();
final Configuration[] children = originalConfig.getChildren();
for( int i = 0; i < children.length; i++ ) for( int i = 0; i < children.length; i++ )
{ {
Configuration child = children[ i ];
final Configuration child = children[ i ];


if( child.getName().equals( "target" ) ) if( child.getName().equals( "target" ) )
{ {
@@ -82,12 +84,12 @@ public class ConvertingProjectBuilder
* @param originalTarget The Ant1 Target * @param originalTarget The Ant1 Target
* @return the converted 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' // Copy all attributes except 'if' and 'unless'
Set omitAttributes = new HashSet();
final Set omitAttributes = new HashSet();
omitAttributes.add( "if" ); omitAttributes.add( "if" );
omitAttributes.add( "unless" ); omitAttributes.add( "unless" );
copyAttributes( originalTarget, newTarget, omitAttributes ); copyAttributes( originalTarget, newTarget, omitAttributes );
@@ -95,10 +97,10 @@ public class ConvertingProjectBuilder
DefaultConfiguration containerElement = newTarget; DefaultConfiguration containerElement = newTarget;


// For 'if="prop-name"', replace with <if> task. // For 'if="prop-name"', replace with <if> task.
String ifAttrib = originalTarget.getAttribute( "if", null );
final String ifAttrib = originalTarget.getAttribute( "if", null );
if ( ifAttrib != null ) if ( ifAttrib != null )
{ {
DefaultConfiguration ifElement =
final DefaultConfiguration ifElement =
buildIfElement( ifAttrib, false, originalTarget.getLocation() ); buildIfElement( ifAttrib, false, originalTarget.getLocation() );
containerElement.addChild( ifElement ); containerElement.addChild( ifElement );
// Treat the ifElement as the enclosing target. // Treat the ifElement as the enclosing target.
@@ -106,10 +108,10 @@ public class ConvertingProjectBuilder
} }


// For 'unless="prop-name"', replace with <if> task (negated). // 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 ) if ( unlessAttrib != null )
{ {
DefaultConfiguration unlessElement =
final DefaultConfiguration unlessElement =
buildIfElement( unlessAttrib, true, originalTarget.getLocation() ); buildIfElement( unlessAttrib, true, originalTarget.getLocation() );
containerElement.addChild( unlessElement ); containerElement.addChild( unlessElement );
// Treat the unlessElement as the enclosing target. // Treat the unlessElement as the enclosing target.
@@ -117,7 +119,7 @@ public class ConvertingProjectBuilder
} }


// Now copy in converted tasks. // Now copy in converted tasks.
Configuration[] tasks = originalTarget.getChildren();
final Configuration[] tasks = originalTarget.getChildren();
for( int i = 0; i < tasks.length; i++ ) for( int i = 0; i < tasks.length; i++ )
{ {
containerElement.addChild( convertTask( tasks[ i ] ) ); containerElement.addChild( convertTask( tasks[ i ] ) );
@@ -134,8 +136,8 @@ public class ConvertingProjectBuilder
* @param location the configuration location to use * @param location the configuration location to use
* @return The configuration for an <if> task * @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 ) final String location )
{ {
// <if> // <if>
@@ -144,17 +146,17 @@ public class ConvertingProjectBuilder
// </condition> // </condition>
// .. tasks // .. tasks
// </if> // </if>
DefaultConfiguration isSetElement =
final DefaultConfiguration isSetElement =
new DefaultConfiguration( "is-set", location ); new DefaultConfiguration( "is-set", location );
isSetElement.setAttribute( "property", ifProperty ); isSetElement.setAttribute( "property", ifProperty );


DefaultConfiguration conditionElement =
final DefaultConfiguration conditionElement =
new DefaultConfiguration( "condition", location ); new DefaultConfiguration( "condition", location );


if ( unless ) if ( unless )
{ {
// Surround <is-set> with <not> // Surround <is-set> with <not>
DefaultConfiguration notElement =
final DefaultConfiguration notElement =
new DefaultConfiguration( "not", location ); new DefaultConfiguration( "not", location );
notElement.addChild( isSetElement ); notElement.addChild( isSetElement );
conditionElement.addChild( notElement ); conditionElement.addChild( notElement );
@@ -165,7 +167,7 @@ public class ConvertingProjectBuilder
} }




DefaultConfiguration ifElement =
final DefaultConfiguration ifElement =
new DefaultConfiguration( "if", location ); new DefaultConfiguration( "if", location );
ifElement.addChild( conditionElement ); ifElement.addChild( conditionElement );


@@ -177,11 +179,11 @@ public class ConvertingProjectBuilder
* @param originalTask The Ant1 Task * @param originalTask The Ant1 Task
* @return the converted task * @return the converted task
*/ */
private Configuration convertTask( Configuration originalTask )
private Configuration convertTask( final Configuration originalTask )
{ {
// Create a new configuration with the "ant1." prefix. // 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() ); new DefaultConfiguration( newTaskName, originalTask.getLocation() );


// Copy all attributes and elements of the task. // Copy all attributes and elements of the task.
@@ -196,9 +198,10 @@ public class ConvertingProjectBuilder
* @param from Configuration to copy from * @param from Configuration to copy from
* @param to Configuration to copy to * @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++ ) for( int i = 0; i < children.length; i++ )
{ {
to.addChild( children[ i ] ); to.addChild( children[ i ] );
@@ -212,20 +215,20 @@ public class ConvertingProjectBuilder
* @param to Configuration to copy to * @param to Configuration to copy to
* @param omitAttributes a Set of attribute names to exclude * @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 // Copy other attributes
String[] attribs = from.getAttributeNames();
final String[] attribs = from.getAttributeNames();
for( int i = 0; i < attribs.length; i++ ) for( int i = 0; i < attribs.length; i++ )
{ {
String name = attribs[ i ];
final String name = attribs[ i ];
if( omitAttributes.contains( name ) ) if( omitAttributes.contains( name ) )
{ {
continue; continue;
} }
String value = from.getAttribute( name, "" );
final String value = from.getAttribute( name, "" );
to.setAttribute( name, value ); to.setAttribute( name, value );
} }
} }
@@ -236,7 +239,7 @@ public class ConvertingProjectBuilder
* @param originalConfig the COnfiguration to copy. * @param originalConfig the COnfiguration to copy.
* @return the new Configuration * @return the new Configuration
*/ */
private DefaultConfiguration copyConfiguration( Configuration originalConfig )
private DefaultConfiguration copyConfiguration( final Configuration originalConfig )
{ {
return new DefaultConfiguration( originalConfig.getName(), return new DefaultConfiguration( originalConfig.getName(),
originalConfig.getLocation() ); originalConfig.getLocation() );


+ 1
- 1
proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/DefaultProjectBuilder.java View File

@@ -36,7 +36,7 @@ import org.xml.sax.XMLReader;
* @author <a href="mailto:peter@apache.org">Peter Donald</a> * @author <a href="mailto:peter@apache.org">Peter Donald</a>
* @version $Revision$ $Date$ * @version $Revision$ $Date$
* *
* @ant.type type="project-builder" name="ant"
* @ant.type type="project-builder" name="ant2"
*/ */
public class DefaultProjectBuilder public class DefaultProjectBuilder
extends AbstractLogEnabled extends AbstractLogEnabled


+ 11
- 2
proposal/myrmidon/src/java/org/apache/myrmidon/frontends/CLIMain.java View File

@@ -55,6 +55,7 @@ public class CLIMain
private static final int HOME_DIR_OPT = 7; private static final int HOME_DIR_OPT = 7;
private static final int DRY_RUN_OPT = 8; private static final int DRY_RUN_OPT = 8;
private static final int DEBUG_OPT = 9; private static final int DEBUG_OPT = 9;
private static final int TYPE_OPT = 10;


//incompatable options for info options //incompatable options for info options
private static final int[] INFO_OPT_INCOMPAT = new int[] private static final int[] INFO_OPT_INCOMPAT = new int[]
@@ -62,7 +63,7 @@ public class CLIMain
HELP_OPT, QUIET_OPT, VERBOSE_OPT, FILE_OPT, HELP_OPT, QUIET_OPT, VERBOSE_OPT, FILE_OPT,
LOG_LEVEL_OPT, BUILDER_PARAM_OPT, NO_PREFIX_OPT, LOG_LEVEL_OPT, BUILDER_PARAM_OPT, NO_PREFIX_OPT,
VERSION_OPT, LISTENER_OPT, TASKLIB_DIR_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 //incompatable options for other logging options
@@ -214,7 +215,11 @@ public class CLIMain
new CLOptionDescriptor( "dry-run", new CLOptionDescriptor( "dry-run",
CLOptionDescriptor.ARGUMENT_DISALLOWED, CLOptionDescriptor.ARGUMENT_DISALLOWED,
DRY_RUN_OPT, 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; return options;
@@ -295,6 +300,10 @@ public class CLIMain
m_dryRun = true; m_dryRun = true;
break; break;


case TYPE_OPT:
m_embedded.setProjectType( option.getArgument( 0 ) );
break;

case 0: case 0:
m_targets.add( option.getArgument() ); m_targets.add( option.getArgument() );
break; break;


+ 11
- 2
proposal/myrmidon/src/java/org/apache/myrmidon/frontends/EmbeddedAnt.java View File

@@ -56,6 +56,7 @@ public class EmbeddedAnt
private ClassLoader m_sharedClassLoader; private ClassLoader m_sharedClassLoader;
private Embeddor m_embeddor; private Embeddor m_embeddor;
private File m_homeDir; private File m_homeDir;
private String m_projectType;


/** /**
* Sets the Myrmidon home directory. Default is to use the current * Sets the Myrmidon home directory. Default is to use the current
@@ -78,6 +79,15 @@ public class EmbeddedAnt
m_project = null; m_project = null;
} }


/**
* 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 * Sets the project to execute. This method can be used instead of
* {@link #setProjectFile}, for projects models that are built * {@link #setProjectFile}, for projects models that are built
@@ -312,7 +322,7 @@ public class EmbeddedAnt
if( m_project == null ) if( m_project == null )
{ {
final File buildFile = getProjectFile(); 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; return m_project;
} }
@@ -368,5 +378,4 @@ public class EmbeddedAnt
throw new Exception( message ); throw new Exception( message );
} }
} }

} }

+ 1
- 0
proposal/myrmidon/src/java/org/apache/myrmidon/frontends/Resources.properties View File

@@ -15,6 +15,7 @@ home.opt=Specify Ant home directory.
define.opt=Define a property (ie -Dfoo=var). define.opt=Define a property (ie -Dfoo=var).
build.opt=Define a builder parameter (ie -Bfoo=var). build.opt=Define a builder parameter (ie -Bfoo=var).
dry-run.opt=Do not execute tasks - just print them out. 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-no-exist.error={0} {1} does not exist.
file-not-dir.error={0} {1} is not a directory. file-not-dir.error={0} {1} is not a directory.


Loading…
Cancel
Save