You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by br...@apache.org on 2004/01/06 05:58:52 UTC
cvs commit: maven-components/maven-model/src/test/org/apache/maven/model ModelTest.java
brett 2004/01/05 20:58:52
Modified: maven-model/src/java/org/apache/maven/model Model.java
maven-model/src/test/org/apache/maven/model ModelTest.java
Log:
add more legacy to model.
Revision Changes Path
1.16 +74 -4 maven-components/maven-model/src/java/org/apache/maven/model/Model.java
Index: Model.java
===================================================================
RCS file: /home/cvs/maven-components/maven-model/src/java/org/apache/maven/model/Model.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- Model.java 7 Dec 2003 15:03:18 -0000 1.15
+++ Model.java 6 Jan 2004 04:58:52 -0000 1.16
@@ -58,18 +58,22 @@
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
/**
* @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
* @author <a href="mailto:dion@apache.org">dIon Gillard</a>
* @author <a href="mailto:glennm@apache.org">Glenn McAllister</a>
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
*
* @version $Id$
*
- * @todo Change the file reference for the source POM to an URL.
* @todo turn this into a pure model.
+ * @todo can we add :type to getId() and then share all that code with dependency?
*/
public class Model
implements Serializable
@@ -143,11 +147,14 @@
private String distributionDirectory;
/** Version of the project model. */
- private String modelVersion;
+ private String modelVersion = "1";
/** Versions associated with this project. */
private List versions;
+ /** Versions associated with this project in a keyed map. */
+ private Map versionMap;
+
/** Branches associated with this project. */
private List branches;
@@ -162,7 +169,7 @@
/**
* Reports to be generated for a project for a project. This is a list of the
- * plugin ids which have a goal of the form <plugin-id>:report.
+ * plugin ids which have a goal of the form <plugin-id>:report.
*/
private List reports;
@@ -175,6 +182,9 @@
/** Name */
private String name;
+ /** Gump repository id. */
+ private String gumpRepositoryId;
+
/**
* Default constructor.
*/
@@ -829,6 +839,10 @@
public void addVersion( Version version )
{
getVersions().add( version );
+ if ( versionMap != null )
+ {
+ versionMap.put( version.getId(), version );
+ }
}
/**
@@ -839,6 +853,8 @@
public void setVersions( List versions )
{
this.versions = versions;
+ // clear map, will lazy initialize it on first use
+ this.versionMap = null;
}
/**
@@ -857,6 +873,29 @@
}
/**
+ * Return a distribution for this project.
+ *
+ * @param versionId the id of the version to return
+ * @return given version or null if not found
+ */
+ public Version getVersionById( String versionId )
+ {
+ if ( versionMap == null )
+ {
+ // lazy initialise it
+ versionMap = new HashMap();
+
+ for ( Iterator i = versions.iterator(); i.hasNext(); )
+ {
+ Version version = ( Version ) i.next();
+ versionMap.put( version.getId(), version );
+ }
+ }
+
+ return ( Version ) versionMap.get( versionId );
+ }
+
+ /**
* Set the project logo image URL.
*
* @param logo the url for the project logo image.
@@ -938,5 +977,36 @@
public void addBranch( Branch b )
{
getBranches().add( b );
+ }
+
+ /**
+ * Set the gump repository descriptor.
+ *
+ * @param gumpRepositoryId Gump repository id.
+ */
+ public void setGumpRepositoryId( String gumpRepositoryId )
+ {
+ this.gumpRepositoryId = gumpRepositoryId;
+ }
+
+ /**
+ * Get the gump repository descriptor.
+ *
+ * @return Gump repository id.
+ */
+ public String getGumpRepositoryId()
+ {
+ return gumpRepositoryId;
+ }
+
+ /**
+ * Get flag to indicate the presence of a source repository.
+ *
+ * @return <code>true</code> if the project is part of a repository,
+ * <code>false</code> otherwise
+ */
+ public boolean hasRepository()
+ {
+ return ( repository != null );
}
}
1.4 +64 -15 maven-components/maven-model/src/test/org/apache/maven/model/ModelTest.java
Index: ModelTest.java
===================================================================
RCS file: /home/cvs/maven-components/maven-model/src/test/org/apache/maven/model/ModelTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ModelTest.java 4 Jan 2004 21:58:08 -0000 1.3
+++ ModelTest.java 6 Jan 2004 04:58:52 -0000 1.4
@@ -62,46 +62,88 @@
import java.util.ArrayList;
/**
+ * Unit test for model element.
*
* @author <a href="mailto:jvanzyl@maven.org">Jason van Zyl</a>
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
*
* @version $Id$
*/
public class ModelTest
extends TestCase
{
+ private Model model;
+
public ModelTest( String name )
{
super( name );
}
- public void testVersion()
- throws Exception
+ public void setUp()
{
- Model model = new Model();
-
- // Values to be found before anything is added
+ model = new Model();
+ }
+ public void testDefaults()
+ {
assertNotNull( model.getMailingLists() );
-
+ assertEquals( 0, model.getMailingLists().size() );
assertNotNull( model.getBranches() );
-
+ assertEquals( 0, model.getBranches().size() );
assertNotNull( model.getVersions() );
-
+ assertEquals( 0, model.getVersions().size() );
assertNotNull( model.getDevelopers() );
-
+ assertEquals( 0, model.getDevelopers().size() );
assertNotNull( model.getContributors() );
-
+ assertEquals( 0, model.getContributors().size() );
assertNotNull( model.getReports() );
-
+ assertEquals( 0, model.getReports().size() );
assertNotNull( model.getDependencies() );
-
+ assertEquals( 0, model.getDependencies().size() );
assertNotNull( model.getPackageGroups() );
-
+ assertEquals( 0, model.getPackageGroups().size() );
assertNotNull( model.getLicenses() );
+ assertEquals( 0, model.getLicenses().size() );
- // Test set values
+ assertEquals( "check default model version", "1", model.getModelVersion() );
+ assertFalse( "check no repository", model.hasRepository() );
+ }
+
+ public void testGetVersionById()
+ {
+ Version version = new Version();
+ version.setId( "id" );
+ model.addVersion( version );
+ assertSame( "check version", version, model.getVersionById( "id" ) );
+ }
+ public void testGetVersionByIdBySetVersions()
+ {
+ Version version = new Version();
+ version.setId( "id" );
+ List versions = new ArrayList();
+ versions.add( version );
+ model.setVersions( versions );
+ assertSame( "check version", version, model.getVersionById( "id" ) );
+ }
+
+ public void testAddVersionAfterGetById()
+ {
+ Version v1 = model.getVersionById( "x" );
+
+ Version version = new Version();
+ version.setId( "id" );
+ model.addVersion( version );
+ assertSame( "check version", version, model.getVersionById( "id" ) );
+ }
+
+ public void testGetVersionByIdNotThere()
+ {
+ assertNull( model.getVersionById( "notyet" ));
+ }
+
+ public void testGetSetters()
+ {
model.setName( "name" );
assertEquals( "name", model.getName() );
@@ -126,6 +168,10 @@
assertEquals( "issueTrackingUrl", model.getIssueTrackingUrl() );
+ model.setGumpRepositoryId( "gumpRepositoryId" );
+
+ assertEquals( "gumpRepositoryId", model.getGumpRepositoryId() );
+
model.setVersion( "version" );
assertEquals( "version", model.getVersion() );
@@ -282,6 +328,8 @@
assertEquals( repo, model.getRepository() );
+ assertTrue( "check has repository", model.hasRepository() );
+
Organization org = new Organization();
model.setOrganization( org );
@@ -289,3 +337,4 @@
assertEquals( org, model.getOrganization() );
}
}
+
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org