mcconnell 2003/11/17 03:20:06
Modified: repository/api/src/java/org/apache/avalon/repository
Artifact.java ArtifactDescriptor.java
ArtifactReference.java
Added: repository/api/src/java/org/apache/avalon/repository
ArtifactFactory.java MavenArtifactFactory.java
repository/api/src/test/org/apache/avalon/repository
ArtifactFactoryTest.java
Log:
Update Artifact to expose named values and add a couple of artifact factories.
Revision Changes Path
1.2 +7 -2
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Artifact.java 17 Nov 2003 08:07:24 -0000 1.1
+++ Artifact.java 17 Nov 2003 11:20:05 -0000 1.2
@@ -53,7 +53,7 @@
import java.io.Serializable ;
import java.text.ParseException ;
-
+import java.util.Enumeration;
/**
* A reference to an artifact.
@@ -80,5 +80,10 @@
* @return the full URL to the artifact
*/
public abstract String getURL( final String repository );
+
+ public abstract String getProperty( String key );
+
+ public abstract Enumeration getPropertyNames();
+
}
1.4 +13 -2
avalon-sandbox/repository/api/src/java/org/apache/avalon/repository/ArtifactDescriptor.java
Index: ArtifactDescriptor.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/repository/api/src/java/org/apache/avalon/repository/ArtifactDescriptor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ArtifactDescriptor.java 17 Nov 2003 08:09:12 -0000 1.3
+++ ArtifactDescriptor.java 17 Nov 2003 11:20:05 -0000 1.4
@@ -53,6 +53,8 @@
import java.io.Serializable ;
import java.text.ParseException ;
+import java.util.Enumeration;
+import java.util.StringTokenizer;
/**
@@ -171,6 +173,15 @@
// bean accessors & mutators
// ------------------------------------------------------------------------
+ public String getProperty( String key )
+ {
+ return null; // fix me
+ }
+
+ public Enumeration getPropertyNames()
+ {
+ return new StringTokenizer(""); // fix me
+ }
/**
* @return Returns the group.
1.2 +33 -4
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ArtifactReference.java 17 Nov 2003 08:09:38 -0000 1.1
+++ ArtifactReference.java 17 Nov 2003 11:20:05 -0000 1.2
@@ -53,6 +53,8 @@
import java.io.Serializable ;
import java.text.ParseException ;
+import java.util.Properties ;
+import java.util.Enumeration ;
/**
@@ -88,11 +90,16 @@
*/
private final String m_path;
+ /**
+ * Properties associated with the artifact.
+ */
+ private Properties m_properties;
+
// ------------------------------------------------------------------------
// constructors
// ------------------------------------------------------------------------
-
+
/**
* Creation of a new artifact reference.
*
@@ -101,6 +108,17 @@
*/
public ArtifactReference( String base, String filename )
{
+ this( base, filename, new Properties() );
+ }
+
+ /**
+ * Creation of a new artifact reference.
+ *
+ * @param base the base path to the artifact
+ * @param filename the artifact filename
+ */
+ public ArtifactReference( String base, String filename, Properties properties )
+ {
if ( null == base ) throw new NullPointerException( "base" );
if ( null == filename ) throw new NullPointerException( "filename" );
@@ -112,13 +130,24 @@
}
m_filename = filename;
- m_path = m_base + SEP + m_filename;
+ m_path = m_base + SEP + m_filename;
+ m_properties = properties;
}
-
+
// ------------------------------------------------------------------------
// accessors
// ------------------------------------------------------------------------
+ public String getProperty( String key )
+ {
+ return m_properties.getProperty( key );
+ }
+
+ public Enumeration getPropertyNames()
+ {
+ return m_properties.propertyNames();
+ }
+
/**
* Return the base path to the artifact. This is equivelent to the
* containing directory without a leading or trailing seperator.
1.1
avalon-sandbox/repository/api/src/java/org/apache/avalon/repository/ArtifactFactory.java
Index: ArtifactFactory.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
"Apache Software Foundation" must not be used to endorse or promote
products derived from this software without prior written
permission. For written permission, please contact [EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.avalon.repository ;
import java.io.Serializable ;
import java.text.ParseException ;
import java.util.Properties;
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
* @author $Author: mcconnell $
* @version $Revision: 1.1 $
*/
public class ArtifactFactory
{
// ------------------------------------------------------------------------
// static
// ------------------------------------------------------------------------
public static Artifact createArtifact( String base, String filename )
{
return createArtifact( base, filename, null );
}
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 );
}
}
1.1
avalon-sandbox/repository/api/src/java/org/apache/avalon/repository/MavenArtifactFactory.java
Index: MavenArtifactFactory.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
"Apache Software Foundation" must not be used to endorse or promote
products derived from this software without prior written
permission. For written permission, please contact [EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.avalon.repository ;
import java.io.Serializable ;
import java.text.ParseException ;
import java.util.Properties ;
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
* @author $Author: mcconnell $
* @version $Revision: 1.1 $
*/
public class MavenArtifactFactory extends ArtifactFactory
{
// ------------------------------------------------------------------------
// static
// ------------------------------------------------------------------------
public static final String GROUP_KEY = "avalon.artifact.group";
public static final String NAME_KEY = "avalon.artifact.name";
public static final String VERSION_KEY = "avalon.artifact.version";
public static final String TYPE_KEY = "avalon.artifact.type";
public static Artifact createJarArtifact( String spec )
{
if ( null == spec ) throw new NullPointerException( "spec" );
String version = getVersion( spec );
String group = getGroup( spec );
String name = getName( spec );
return createJarArtifact( group, name, version );
}
public static Artifact createJarArtifact( String group, String name, String
version )
{
return createMavenArtifact( group, name, version, "jar" );
}
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 );
properties.setProperty( TYPE_KEY, type );
if( version != null ) properties.setProperty( VERSION_KEY, version );
final String base = group + Artifact.SEP + type + "s";
if( version == null )
{
final String filename = name + "." + type;
return createArtifact( base, filename, properties );
}
else
{
final String filename = name + "-" + version + "." + type;
return createArtifact( base, filename, properties );
}
}
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 );
}
private static String getGroup( String spec )
{
int semiColon = spec.indexOf( ';' ) ;
if ( -1 == semiColon )
{
int colon = spec.indexOf( ':' ) ;
if( -1 == colon ) return spec;
return spec.substring( 0, colon-1 );
}
else
{
return getGroup( spec.substring( 0, semiColon-1 ) );
}
}
private static String getName( String spec )
{
int semiColon = spec.indexOf( ';' ) ;
if ( -1 == semiColon )
{
int colon = spec.indexOf( ':' ) ;
if( -1 == colon ) return spec;
return spec.substring( colon, spec.length() );
}
else
{
return getName( spec.substring( 0, semiColon-1 ) );
}
}
private static String getVersion( String spec )
{
int semiColon = spec.indexOf( ';' ) ;
if ( -1 == semiColon )
{
return null;
}
else
{
return spec.substring( semiColon, spec.length() );
}
}
// ------------------------------------------------------------------------
// utilities
// ------------------------------------------------------------------------
/**
* @return group property of the supplied artifact.
*/
public static String getGroup( Artifact artifact )
{
return artifact.getProperty( GROUP_KEY );
}
/**
* @return Returns the name.
*/
public static String getName( Artifact artifact )
{
return artifact.getProperty( NAME_KEY );
}
/**
* @return Returns the name.
*/
public static String getType( Artifact artifact )
{
return artifact.getProperty( TYPE_KEY );
}
/**
* @return Returns the version.
*/
public static String getVersion( Artifact artifact )
{
return artifact.getProperty( VERSION_KEY );
}
/**
* Gets the artifact specification for this ArtifactDescriptor.
*
* @return the artifact specification
*/
public static String getSpecification( Artifact artifact )
{
final String group = getGroup( artifact );
final String name = getName( artifact );
if( group == null )
{
final String error =
"Undefined group property in artifact: " + artifact;
throw new IllegalArgumentException( error );
}
if( name == null )
{
final String error =
"Undefined name property in artifact: " + artifact;
throw new IllegalArgumentException( error );
}
StringBuffer buffer = new StringBuffer() ;
buffer.append( getGroup( artifact ) ) ;
if( !name.equals( group ) )
{
buffer.append( ':' ) ;
buffer.append( getName( artifact ) ) ;
}
String version = getVersion( artifact );
if( version != null )
{
buffer.append( ';' ) ;
buffer.append( version ) ;
}
return buffer.toString() ;
}
}
1.1
avalon-sandbox/repository/api/src/test/org/apache/avalon/repository/ArtifactFactoryTest.java
Index: ArtifactFactoryTest.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
"Apache Software Foundation" must not be used to endorse or promote
products derived from this software without prior written
permission. For written permission, please contact [EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.avalon.repository;
import java.util.Properties;
import junit.framework.TestCase;
/**
* @todo
* @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
* @author $Author: mcconnell $
* @version $Revision: 1.1 $
*/
public class ArtifactFactoryTest extends TestCase
{
public static void main(String[] args)
{
junit.textui.TestRunner.run( ArtifactFactoryTest.class );
}
/**
* Constructor for ArtifactFactoryTest.
* @param arg0
*/
public ArtifactFactoryTest(String arg0)
{
super(arg0);
}
public void testConstructorOne() throws Exception
{
try
{
ArtifactFactory.createArtifact( null, null );
fail( "No null pointer exception (case 1)" );
}
catch( Throwable e )
{
assertTrue( true );
}
}
public void testConstructorTwo() throws Exception
{
try
{
ArtifactFactory.createArtifact( null, "xxx" );
fail( "No null pointer exception (case 2)" );
}
catch( Throwable e )
{
assertTrue( true );
}
}
public void testConstructorThree() throws Exception
{
try
{
ArtifactFactory.createArtifact( "xxx", null );
fail( "No null pointer exception (case 3)" );
}
catch( Throwable e )
{
assertTrue( true );
}
}
public void testIntegrity() throws Exception
{
Artifact artifact = ArtifactFactory.createArtifact( "xxx", "yyy" );
assertNotNull( artifact );
assertTrue( artifact.getURL( "http://dpml.net" ).equals(
"http://dpml.net/xxx/yyy" ) );
}
public void testIntegrityTwo() throws Exception
{
Artifact artifact = ArtifactFactory.createArtifact( "xxx", "yyy" );
assertNotNull( artifact );
assertTrue( artifact.getURL( "" ).equals( "/xxx/yyy" ) );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]