Browse Source

Remove if/unless checking from target. It was insanity to have it there in the first place and has been the cause of much confusion.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270196 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 23 years ago
parent
commit
961d431384
2 changed files with 18 additions and 118 deletions
  1. +9
    -59
      proposal/myrmidon/src/main/org/apache/tools/ant/Target.java
  2. +9
    -59
      proposal/myrmidon/src/todo/org/apache/tools/ant/Target.java

+ 9
- 59
proposal/myrmidon/src/main/org/apache/tools/ant/Target.java View File

@@ -17,11 +17,8 @@ import org.apache.myrmidon.api.TaskException;
* *
* @author James Davidson <a href="mailto:duncan@x180.com">duncan@x180.com</a> * @author James Davidson <a href="mailto:duncan@x180.com">duncan@x180.com</a>
*/ */

public class Target public class Target
{ {
private String ifCondition = "";
private String unlessCondition = "";
private Vector dependencies = new Vector( 2 ); private Vector dependencies = new Vector( 2 );
private Vector children = new Vector( 5 ); private Vector children = new Vector( 5 );
private String description = null; private String description = null;
@@ -71,11 +68,6 @@ public class Target
this.description = description; this.description = description;
} }


public void setIf( String property )
{
this.ifCondition = ( property == null ) ? "" : property;
}

public void setName( String name ) public void setName( String name )
{ {
this.name = name; this.name = name;
@@ -86,11 +78,6 @@ public class Target
this.project = project; this.project = project;
} }


public void setUnless( String property )
{
this.unlessCondition = ( property == null ) ? "" : property;
}

public Enumeration getDependencies() public Enumeration getDependencies()
{ {
return dependencies.elements(); return dependencies.elements();
@@ -166,31 +153,18 @@ public class Target
public void execute() public void execute()
throws TaskException throws TaskException
{ {
if( testIfCondition() && testUnlessCondition() )
Enumeration enum = children.elements();
while( enum.hasMoreElements() )
{ {
Enumeration enum = children.elements();
while( enum.hasMoreElements() )
Object o = enum.nextElement();
if( o instanceof Task )
{
Task task = (Task)o;
task.perform();
}
else
{ {
Object o = enum.nextElement();
if( o instanceof Task )
{
Task task = (Task)o;
task.perform();
}
else
{
}
} }
}
else if( !testIfCondition() )
{
project.log( this, "Skipped because property '" + this.ifCondition + "' not set.",
Project.MSG_VERBOSE );
}
else
{
project.log( this, "Skipped because property '" + this.unlessCondition + "' set.",
Project.MSG_VERBOSE );
} }
} }


@@ -207,28 +181,4 @@ public class Target
children.setElementAt( o, index ); children.setElementAt( o, index );
} }
} }

private boolean testIfCondition()
throws TaskException
{
if( "".equals( ifCondition ) )
{
return true;
}

String test = project.replaceProperties( ifCondition );
return project.getProperty( test ) != null;
}

private boolean testUnlessCondition()
throws TaskException
{
if( "".equals( unlessCondition ) )
{
return true;
}
String test = project.replaceProperties( unlessCondition );
return project.getProperty( test ) == null;
}

} }

+ 9
- 59
proposal/myrmidon/src/todo/org/apache/tools/ant/Target.java View File

@@ -17,11 +17,8 @@ import org.apache.myrmidon.api.TaskException;
* *
* @author James Davidson <a href="mailto:duncan@x180.com">duncan@x180.com</a> * @author James Davidson <a href="mailto:duncan@x180.com">duncan@x180.com</a>
*/ */

public class Target public class Target
{ {
private String ifCondition = "";
private String unlessCondition = "";
private Vector dependencies = new Vector( 2 ); private Vector dependencies = new Vector( 2 );
private Vector children = new Vector( 5 ); private Vector children = new Vector( 5 );
private String description = null; private String description = null;
@@ -71,11 +68,6 @@ public class Target
this.description = description; this.description = description;
} }


public void setIf( String property )
{
this.ifCondition = ( property == null ) ? "" : property;
}

public void setName( String name ) public void setName( String name )
{ {
this.name = name; this.name = name;
@@ -86,11 +78,6 @@ public class Target
this.project = project; this.project = project;
} }


public void setUnless( String property )
{
this.unlessCondition = ( property == null ) ? "" : property;
}

public Enumeration getDependencies() public Enumeration getDependencies()
{ {
return dependencies.elements(); return dependencies.elements();
@@ -166,31 +153,18 @@ public class Target
public void execute() public void execute()
throws TaskException throws TaskException
{ {
if( testIfCondition() && testUnlessCondition() )
Enumeration enum = children.elements();
while( enum.hasMoreElements() )
{ {
Enumeration enum = children.elements();
while( enum.hasMoreElements() )
Object o = enum.nextElement();
if( o instanceof Task )
{
Task task = (Task)o;
task.perform();
}
else
{ {
Object o = enum.nextElement();
if( o instanceof Task )
{
Task task = (Task)o;
task.perform();
}
else
{
}
} }
}
else if( !testIfCondition() )
{
project.log( this, "Skipped because property '" + this.ifCondition + "' not set.",
Project.MSG_VERBOSE );
}
else
{
project.log( this, "Skipped because property '" + this.unlessCondition + "' set.",
Project.MSG_VERBOSE );
} }
} }


@@ -207,28 +181,4 @@ public class Target
children.setElementAt( o, index ); children.setElementAt( o, index );
} }
} }

private boolean testIfCondition()
throws TaskException
{
if( "".equals( ifCondition ) )
{
return true;
}

String test = project.replaceProperties( ifCondition );
return project.getProperty( test ) != null;
}

private boolean testUnlessCondition()
throws TaskException
{
if( "".equals( unlessCondition ) )
{
return true;
}
String test = project.replaceProperties( unlessCondition );
return project.getProperty( test ) == null;
}

} }

Loading…
Cancel
Save