donaldp 2002/07/03 18:53:16
Modified: container/src/test/org/apache/myrmidon/components/embeddor/test
DefaultEmbeddorTest.java
container/src/test/org/apache/myrmidon/components/builder/test
DefaultProjectBuilderTestCase.java
container/src/java/org/apache/myrmidon/components/workspace
DefaultWorkspace.java ProjectEntry.java
Resources.properties
container/src/java/org/apache/myrmidon/interfaces/model
Project.java
framework/src/java/org/apache/myrmidon/framework/project
Resources.properties TargetTask.java
container/src/java/org/apache/myrmidon/interfaces/workspace
TargetSet.java
Log:
Made TargetSet a class rather than interrface.
Moved responsibility for validation out to TargetTask
Revision Changes Path
1.42 +2 -2
jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/embeddor/test/DefaultEmbeddorTest.java
Index: DefaultEmbeddorTest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/embeddor/test/DefaultEmbeddorTest.java,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- DefaultEmbeddorTest.java 2 Jul 2002 07:52:24 -0000 1.41
+++ DefaultEmbeddorTest.java 4 Jul 2002 01:53:16 -0000 1.42
@@ -87,7 +87,7 @@
final Project project = getEmbeddor().createProject( descriptor,
null );
// Verify the project.
- assertEquals( "test-project", project.getProjectName() );
+ assertEquals( "test-project", project.getName() );
//assertEquals( project.getTarget( "main-target" ),
project.getDefaultTarget() );
assertEquals( projectFile.getParentFile(),
project.getBaseDirectory() );
//assertEquals( 0, project.getProjectNames().length );
1.27 +2 -2
jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/builder/test/DefaultProjectBuilderTestCase.java
Index: DefaultProjectBuilderTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/builder/test/DefaultProjectBuilderTestCase.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- DefaultProjectBuilderTestCase.java 30 Jun 2002 09:58:15 -0000
1.26
+++ DefaultProjectBuilderTestCase.java 4 Jul 2002 01:53:16 -0000
1.27
@@ -323,7 +323,7 @@
final Project project )
throws Exception
{
- assertEquals( expected.getProjectName(), project.getProjectName() );
+ assertEquals( expected.getName(), project.getName() );
assertEquals( expected.getBaseDirectory(),
project.getBaseDirectory() );
assertEquals( expected.getDefaultTargetName(),
project.getDefaultTargetName() );
}
1.114 +6 -4
jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java
Index: DefaultWorkspace.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java,v
retrieving revision 1.113
retrieving revision 1.114
diff -u -r1.113 -r1.114
--- DefaultWorkspace.java 4 Jul 2002 01:18:13 -0000 1.113
+++ DefaultWorkspace.java 4 Jul 2002 01:53:16 -0000 1.114
@@ -143,10 +143,12 @@
* @return the Target object
* @throws TaskException if unable to locate target
*/
- private Target getTarget( final ProjectEntry entry, final String
targetName )
+ private Target getTarget( final ProjectEntry entry,
+ final String targetName )
throws TaskException
{
- final Target target = entry.getTarget( targetName );
+ final TargetSet targetSet = entry.getTargetSet();
+ final Target target = targetSet.getTarget( targetName );
if( null == target )
{
final String message =
@@ -270,7 +272,7 @@
(PropertyStore)projectContext.getService( PropertyStore.class );
propertyStore.setProperty( Project.KEY, project );
propertyStore.setProperty( ProjectRefSet.KEY,
entry.getProjectRefSet() );
- propertyStore.setProperty( TargetSet.KEY, entry );
+ propertyStore.setProperty( TargetSet.KEY, entry.getTargetSet() );
return entry;
}
1.24 +11 -66
jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/workspace/ProjectEntry.java
Index: ProjectEntry.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/workspace/ProjectEntry.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- ProjectEntry.java 4 Jul 2002 01:18:13 -0000 1.23
+++ ProjectEntry.java 4 Jul 2002 01:53:16 -0000 1.24
@@ -8,7 +8,6 @@
package org.apache.myrmidon.components.workspace;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
@@ -30,7 +29,6 @@
* @version $Revision$ $Date$
*/
public class ProjectEntry
- implements TargetSet
{
private static final Resources REZ =
ResourceManager.getPackageResources( ProjectEntry.class );
@@ -39,13 +37,11 @@
private final Project m_project;
private final NameValidator m_projectValidator;
- private final NameValidator m_targetValidator;
/** Map from Target -> TargetState for that target. */
private final Map m_targetState = new HashMap();
- /** Map from target name -> Target. */
- private final Map m_targets = new HashMap();
+ private final TargetSet m_targetSet = new TargetSet();
/** Map from project ref name -> ProjectRef. */
private final ProjectRefSet m_projectRefSet;
@@ -65,7 +61,6 @@
final NameValidatorManager validatorManager =
(NameValidatorManager)m_taskContext.getService(
NameValidatorManager.class );
m_projectValidator = validatorManager.getValidator(
NameValidatorManager.PROJECT_STYLE );
- m_targetValidator = validatorManager.getValidator(
NameValidatorManager.TARGET_STYLE );
}
catch( final Exception e )
{
@@ -84,10 +79,11 @@
}
// Add the targets. This validates them
- for( Iterator iterator = project.getTargets().values().iterator();
iterator.hasNext(); )
+ final Target[] targets = project.getTargets();
+ for( int i = 0; i < targets.length; i++ )
{
- final Target target = (Target)iterator.next();
- addTarget( target );
+ final Target target = targets[ i ];
+ m_targetSet.addTarget( target );
}
// Add a reference to self
@@ -101,62 +97,6 @@
return m_project;
}
- /**
- * Returns all the targets of the current project.
- *
- * @return A map from target name to [EMAIL PROTECTED] Target}.
- *
- * @todo Return an unmodifiable wrapper. For some reason JXPath won't
- * introspect the wrapper returned by
Collections.unmodifiableMap().
- * Need to investigate more.
- */
- public Map getTargets()
- {
- return m_targets;
- }
-
- /**
- * Returns a target.
- */
- public Target getTarget( final String targetName )
- {
- return (Target)m_targets.get( targetName );
- }
-
- /**
- * Adds a target to this project.
- */
- public void addTarget( final Target target )
- throws TaskException
- {
- // Validate target
- final String name = target.getName();
- if( name == null )
- {
- final String message = REZ.getString( "no-target-name.error" );
- throw new TaskException( message );
- }
- if( !name.equals( Project.IMPLICIT_TARGET_NAME ) )
- {
- try
- {
- m_targetValidator.validate( name );
- }
- catch( final Exception e )
- {
- final String message = REZ.getString(
"bad-target-name.error", name );
- throw new TaskException( message, e );
- }
- }
- if( m_targets.containsKey( name ) )
- {
- final String message = REZ.getString( "duplicate-targets.error",
name );
- throw new TaskException( message );
- }
-
- m_targets.put( target.getName(), target );
- }
-
public TaskContext getContext()
{
return m_taskContext;
@@ -180,5 +120,10 @@
public ProjectRefSet getProjectRefSet()
{
return m_projectRefSet;
+ }
+
+ public TargetSet getTargetSet()
+ {
+ return m_targetSet;
}
}
1.20 +0 -5
jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/workspace/Resources.properties
Index: Resources.properties
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/workspace/Resources.properties,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- Resources.properties 2 Jul 2002 12:32:35 -0000 1.19
+++ Resources.properties 4 Jul 2002 01:53:16 -0000 1.20
@@ -9,13 +9,8 @@
workspace.missing-target.error=No target named "{1}" in project "{0}".
invalid-project-name.error=Invalid project name "{0}".
-no-projectref-name.error=No name specified for project reference.
-duplicate-projectrefs.error=Multiple project references with name "{0}".
-bad-projectref-name.error=Invalid project reference name "{0}".
no-projectref-location.error=No project location specified for project
reference.
-no-target-name.error=No target name specified.
bad-target-name.error=Invalid target name "{0}".
-duplicate-targets.error=Multiple targets with name "{0}".
#DefaultTaskContext
unknown-prop.error=Unknown property {0}.
1.15 +5 -13
jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/model/Project.java
Index: Project.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/model/Project.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- Project.java 27 Jun 2002 11:13:08 -0000 1.14
+++ Project.java 4 Jul 2002 01:53:16 -0000 1.15
@@ -11,6 +11,7 @@
import java.util.Map;
import java.util.HashMap;
import java.util.Collections;
+import java.util.Collection;
import org.apache.myrmidon.interfaces.workspace.ProjectDescriptor;
/**
@@ -97,16 +98,6 @@
}
/**
- * Return the name of the project.
- *
- * @return the name of the project.
- */
- public String getProjectName()
- {
- return getName();
- }
-
- /**
* Returns the descriptor for this project.
*
* @return the descriptor for this project.
@@ -141,9 +132,10 @@
*
* @return A map from target name to [EMAIL PROTECTED] Target}.
*/
- public Map getTargets()
+ public Target[] getTargets()
{
- return m_targets;
+ final Collection targets = m_targets.values();
+ return (Target[])targets.toArray( new Target[ targets.size() ]);
}
/**
1.4 +5 -1
jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/project/Resources.properties
Index: Resources.properties
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/project/Resources.properties,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Resources.properties 2 Jul 2002 14:41:07 -0000 1.3
+++ Resources.properties 4 Jul 2002 01:53:16 -0000 1.4
@@ -3,4 +3,8 @@
target.task-exec.notice=Executing task: "{0}".
workspace.exec-depends.notice=Executing dependency: {0}
-workspace.missing-ref.error=Unable to locate project "{0}".
\ No newline at end of file
+workspace.missing-ref.error=Unable to locate project "{0}".
+
+target.bad-target-name.error=Invalid target name "{0}".
+target.duplicate-target.error=Multiple targets with name "{0}".
+target.no-target-name.error=No target name specified.
\ No newline at end of file
1.5 +43 -2
jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/project/TargetTask.java
Index: TargetTask.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/project/TargetTask.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TargetTask.java 2 Jul 2002 12:32:34 -0000 1.4
+++ TargetTask.java 4 Jul 2002 01:53:16 -0000 1.5
@@ -14,7 +14,12 @@
import org.apache.myrmidon.api.metadata.ModelException;
import org.apache.myrmidon.framework.ModelElementUtil;
import org.apache.myrmidon.interfaces.model.Target;
+import org.apache.myrmidon.interfaces.model.Project;
import org.apache.myrmidon.interfaces.workspace.TargetSet;
+import org.apache.myrmidon.interfaces.property.NameValidatorManager;
+import org.apache.myrmidon.interfaces.property.NameValidator;
+import org.apache.avalon.excalibur.i18n.Resources;
+import org.apache.avalon.excalibur.i18n.ResourceManager;
/**
* Adds a target to the current project.
@@ -28,6 +33,9 @@
extends AbstractTask
implements Modeller
{
+ private final static Resources REZ =
+ ResourceManager.getPackageResources( TargetTask.class );
+
private ModelElement m_model;
/**
@@ -51,17 +59,50 @@
public void execute()
throws TaskException
{
+ final TargetSet targetSet = (TargetSet)getContext().getProperty(
TargetSet.KEY );
+
// Transform the model, to replace the name
final ModelElement targetModel = new ModelElement( "target-impl",
m_model.getLocation() );
ModelElementUtil.copyModel( m_model, targetModel );
// Build the target
final String name = targetModel.getAttribute( "name" );
+ if( null == name )
+ {
+ final String message =
+ REZ.getString( "target.no-target-name.error" );
+ throw new TaskException( message );
+ }
+
final String description = targetModel.getAttribute( "description",
"" );
final Target target = new Target( name, description, targetModel );
+ if( null != targetSet.getTarget( name ) )
+ {
+ final String message =
+ REZ.getString( "target.duplicate-target.error",
+ name );
+ throw new TaskException( message );
+ }
+
+ if( !name.equals( Project.IMPLICIT_TARGET_NAME ) )
+ {
+ try
+ {
+ final NameValidatorManager validatorManager =
+ (NameValidatorManager)getService(
NameValidatorManager.class );
+ final NameValidator validator =
validatorManager.getValidator( NameValidatorManager.TARGET_STYLE );
+ validator.validate( name );
+ }
+ catch( final Exception e )
+ {
+ final String message =
+ REZ.getString( "target.bad-target-name.error", name );
+ throw new TaskException( message, e );
+ }
+ }
+
// Add the target
- final TargetSet targetSet = (TargetSet)getContext().getProperty(
TargetSet.KEY );
targetSet.addTarget( target );
}
}
1.2 +24 -6
jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/workspace/TargetSet.java
Index: TargetSet.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/workspace/TargetSet.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TargetSet.java 2 Jul 2002 10:48:38 -0000 1.1
+++ TargetSet.java 4 Jul 2002 01:53:16 -0000 1.2
@@ -7,6 +7,7 @@
*/
package org.apache.myrmidon.interfaces.workspace;
+import java.util.HashMap;
import java.util.Map;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.interfaces.model.Target;
@@ -18,26 +19,43 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision$ $Date$
*/
-public interface TargetSet
+public final class TargetSet
{
- String KEY = "myrmidon.targets";
+ public static final String KEY = "myrmidon.targets";
+
+ /** Map from target name -> Target. */
+ private final Map m_targets = new HashMap();
/**
* Returns all the targets of the current project.
*
* @return A read-only map from target name to [EMAIL PROTECTED] Target}.
+ *
+ * @todo Return an unmodifiable wrapper. For some reason JXPath won't
+ * introspect the wrapper returned by
Collections.unmodifiableMap().
+ * Need to investigate more.
*/
- Map getTargets();
+ public Map getTargets()
+ {
+ return m_targets;
+ }
/**
* Retrieve a target by name.
*
* @param name The name of the target to get.
*/
- Target getTarget( final String name );
+ public Target getTarget( final String name )
+ {
+ return (Target)m_targets.get( name );
+ }
/**
* Adds a target to the current project.
*/
- void addTarget( final Target target ) throws TaskException;
+ public void addTarget( final Target target )
+ throws TaskException
+ {
+ m_targets.put( target.getName(), target );
+ }
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>