mcconnell 2003/11/17 05:23:03
Modified: repository/api/src/java/org/apache/avalon/repository
Artifact.java ArtifactFactory.java
ArtifactReference.java MavenArtifactFactory.java
Log:
Fix some string manipulation bugs and add complete test coverage for the
MavenArtifactFactory.
Revision Changes Path
1.3 +5 -3
avalon-sandbox/repository/api/src/java/org/apache/avalon/repository/Artifact.java
Index: Artifact.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/repository/api/src/java/org/apache/avalon/repository/Artifact.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Artifact.java 17 Nov 2003 11:20:05 -0000 1.2
+++ Artifact.java 17 Nov 2003 13:23:02 -0000 1.3
@@ -56,8 +56,10 @@
import java.util.Enumeration;
/**
- * A reference to an artifact.
- *
+ * Defintion of a minimal artifact that maintains a relative url
+ * to some nominally remote file together with a set of assigned
+ * properties.
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
* @version $Revision$
*/
1.2 +29 -3
avalon-sandbox/repository/api/src/java/org/apache/avalon/repository/ArtifactFactory.java
Index: ArtifactFactory.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/repository/api/src/java/org/apache/avalon/repository/ArtifactFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ArtifactFactory.java 17 Nov 2003 11:20:05 -0000 1.1
+++ ArtifactFactory.java 17 Nov 2003 13:23:02 -0000 1.2
@@ -56,9 +56,12 @@
import java.util.Properties;
/**
- *
+ * The ArtifactFactory is a factory for domain independent artifacts. The
+ * factory makes no assumptions about a repository layout beyond the notions
+ * a directory and filename.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
- * @author $Author$
* @version $Revision$
*/
public class ArtifactFactory
@@ -67,11 +70,34 @@
// static
// ------------------------------------------------------------------------
+ /**
+ * Creation of a new Artifact relative to a supplied base directory
+ * and filename. The argument supplied to the path is a nominal relative
+ * reference anchored relative to a repository root. The filename
+ * when appended to the base path forms a logical relative root path.
+ *
+ * @param base the base directory path
+ * @param filename the artifact filename
+ * @return the artifact reference
+ */
public static Artifact createArtifact( String base, String filename )
{
return createArtifact( base, filename, null );
}
+ /**
+ * Creation of a new Artifact relative to a supplied base directory
+ * and filename. The argument supplied to the path is a nominal relative
+ * reference anchored relative to a repository root. The filename
+ * when appended to the base path forms a logical relative root path.
+ * The supplied properties argument may be used to attribute domain
+ * specific information to the artifact.
+ *
+ * @param base the base directory path
+ * @param filename the artifact filename
+ * @param properties a properties set to attribute to the artifact
+ * @return the artifact reference
+ */
public static Artifact createArtifact( String base, String filename, Properties
properties )
{
if( base == null ) throw new NullPointerException( base );
1.4 +10 -3
avalon-sandbox/repository/api/src/java/org/apache/avalon/repository/ArtifactReference.java
Index: ArtifactReference.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/repository/api/src/java/org/apache/avalon/repository/ArtifactReference.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ArtifactReference.java 17 Nov 2003 11:41:27 -0000 1.3
+++ ArtifactReference.java 17 Nov 2003 13:23:02 -0000 1.4
@@ -94,7 +94,6 @@
* Properties associated with the artifact.
*/
private Properties m_properties;
-
// ------------------------------------------------------------------------
// constructors
@@ -131,7 +130,15 @@
m_filename = filename;
m_path = m_base + SEP + m_filename;
- m_properties = properties;
+
+ if( properties != null )
+ {
+ m_properties = properties;
+ }
+ else
+ {
+ m_properties = new Properties();
+ }
}
// ------------------------------------------------------------------------
1.2 +65 -31
avalon-sandbox/repository/api/src/java/org/apache/avalon/repository/MavenArtifactFactory.java
Index: MavenArtifactFactory.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/repository/api/src/java/org/apache/avalon/repository/MavenArtifactFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MavenArtifactFactory.java 17 Nov 2003 11:20:05 -0000 1.1
+++ MavenArtifactFactory.java 17 Nov 2003 13:23:02 -0000 1.2
@@ -57,9 +57,13 @@
/**
- *
+ * A factory suppporting the creation of artifacts based on structural
+ * assumptions associated with the Maven repository layout. This includes
+ * the notion of a path derived from of a <group>/[<type>s"] association
+ * and a filename derived from <artifact-name>[-<version>][.<type>].
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
- * @author $Author$
* @version $Revision$
*/
public class MavenArtifactFactory extends ArtifactFactory
@@ -73,6 +77,41 @@
public static final String VERSION_KEY = "avalon.artifact.version";
public static final String TYPE_KEY = "avalon.artifact.type";
+
+ /**
+ * Creation of an untyped versionless artifact relative to a supplied
+ * group identifier and artifact name.
+ *
+ * @param group the artifact group id
+ * @param name the artifact name
+ * @return the artifact reference
+ */
+ public static Artifact createMavenArtifact( String group, String name )
+ {
+ return createMavenArtifact( group, name, null, null );
+ }
+
+ public static Artifact createMavenArtifact( String group, String name, String
version )
+ {
+ return createMavenArtifact( group, name, version, null );
+ }
+
+ public static Artifact createMavenArtifact( String group, String name, String
version, String type )
+ {
+ if( group == null ) throw new NullPointerException( "group" );
+ if( name == null ) throw new NullPointerException( "name" );
+
+ Properties properties = new Properties();
+ properties.setProperty( GROUP_KEY, group );
+ properties.setProperty( NAME_KEY, name );
+ if( version != null ) properties.setProperty( VERSION_KEY, version );
+ if( type != null ) properties.setProperty( TYPE_KEY, type );
+
+ String base = createBase( group, type );
+ String filename = createFilename( name, version, type );
+ return createArtifact( base, filename, properties );
+ }
+
public static Artifact createJarArtifact( String spec )
{
if ( null == spec ) throw new NullPointerException( "spec" );
@@ -82,7 +121,6 @@
String name = getName( spec );
return createJarArtifact( group, name, version );
-
}
public static Artifact createJarArtifact( String group, String name, String
version )
@@ -90,36 +128,32 @@
return createMavenArtifact( group, name, version, "jar" );
}
- public static Artifact createMavenArtifact( String group, String name, String
version, String type )
+ //----------------------------------------------------------------------
+ // internal utilities
+ //----------------------------------------------------------------------
+
+ private static String createBase( String group, String type )
{
- if( group == null ) throw new NullPointerException( "group" );
- if( name == null ) throw new NullPointerException( "name" );
+ if( type == null ) return group;
+ return group + Artifact.SEP + type + "s";
+ }
- Properties properties = new Properties();
- properties.setProperty( GROUP_KEY, group );
- properties.setProperty( NAME_KEY, name );
- properties.setProperty( TYPE_KEY, type );
- if( version != null ) properties.setProperty( VERSION_KEY, version );
+ private static String createFilename( String name, String version, String type )
+ {
+ if( name == null ) throw new NullPointerException( "name" );
- final String base = group + Artifact.SEP + type + "s";
- if( version == null )
+ StringBuffer buffer = new StringBuffer( name );
+ if( version != null )
{
- final String filename = name + "." + type;
- return createArtifact( base, filename, properties );
+ buffer.append( "-" );
+ buffer.append( version );
}
- else
+ if( type != null )
{
- final String filename = name + "-" + version + "." + type;
- return createArtifact( base, filename, properties );
+ buffer.append( "." );
+ buffer.append( type );
}
- }
-
- public static Artifact createArtifact( String base, String filename, Properties
properties )
- {
- if( base == null ) throw new NullPointerException( base );
- if( filename == null ) throw new NullPointerException( filename );
-
- return new ArtifactReference( base, filename, properties );
+ return buffer.toString();
}
private static String getGroup( String spec )
@@ -129,7 +163,7 @@
{
int colon = spec.indexOf( ':' ) ;
if( -1 == colon ) return spec;
- return spec.substring( 0, colon-1 );
+ return spec.substring( 0, colon );
}
else
{
@@ -144,11 +178,11 @@
{
int colon = spec.indexOf( ':' ) ;
if( -1 == colon ) return spec;
- return spec.substring( colon, spec.length() );
+ return spec.substring( colon+1, spec.length() );
}
else
{
- return getName( spec.substring( 0, semiColon-1 ) );
+ return getName( spec.substring( 0, semiColon ) );
}
}
@@ -161,7 +195,7 @@
}
else
{
- return spec.substring( semiColon, spec.length() );
+ return spec.substring( semiColon+1, spec.length() );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]