michal 2003/08/02 06:52:36
Modified: core/src/java/org/apache/maven/artifact/layout
RepositoryLayout.java DefaultRepositoryLayout.java
core/src/test/org/apache/maven/artifact/layout
DefaultRepositoryLayoutTest.java
core/src/test/org/apache/maven/artifact/processor
DefaultArtifactProcessorTest.java
core project.xml
core/src/test/org/apache/maven/artifact/handlers
JarHandlerTest.java
Added: core/src/conf layout_windows.properties
layout_unix.properties
Log:
Added possibility to differentiate paths per OS. So path types like "native"
can e.g. have extensions ".dll" (Windows) or ".so" (Unix)
Revision Changes Path
1.4 +12 -1
maven-new/core/src/java/org/apache/maven/artifact/layout/RepositoryLayout.java
Index: RepositoryLayout.java
===================================================================
RCS file:
/home/cvs/maven-new/core/src/java/org/apache/maven/artifact/layout/RepositoryLayout.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- RepositoryLayout.java 29 May 2003 20:26:23 -0000 1.3
+++ RepositoryLayout.java 2 Aug 2003 13:52:35 -0000 1.4
@@ -83,6 +83,17 @@
*/
public String generatePath(Artifact artifact) throws Exception;
+
+ /**
+ * Returns the relative path for an artifact in local repository.
+ *
+ * @param artifact
+ * @param type
+ * @return
+ * @throws Exception
+ */
+ public String generatePath(Artifact artifact, String type) throws Exception;
+
/**
* Returns the relative path for an artifact in local repository.
*
1.7 +80 -49
maven-new/core/src/java/org/apache/maven/artifact/layout/DefaultRepositoryLayout.java
Index: DefaultRepositoryLayout.java
===================================================================
RCS file:
/home/cvs/maven-new/core/src/java/org/apache/maven/artifact/layout/DefaultRepositoryLayout.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DefaultRepositoryLayout.java 29 May 2003 20:26:23 -0000 1.6
+++ DefaultRepositoryLayout.java 2 Aug 2003 13:52:35 -0000 1.7
@@ -56,16 +56,14 @@
* ====================================================================
*/
+import java.io.InputStream;
+import java.util.Properties;
+
import org.apache.avalon.framework.activity.Initializable;
-import org.apache.maven.MavenConstants;
import org.apache.maven.MavenException;
import org.apache.maven.artifact.Artifact;
import org.apache.plexus.util.StringUtils;
-import java.io.File;
-import java.io.InputStream;
-import java.util.Properties;
-
/**
* The standard [EMAIL PROTECTED] org.apache.maven.repository.RepositoryLayout}
* implementation.
@@ -93,46 +91,55 @@
/**
* List of cachedGlobalLayouts.
*/
- private Properties globalLayouts = new Properties();
+ private Properties layouts = null;
/**
* see org.apache.maven.artifact.RepositoryLayout#generatePath(Artifact)
*/
public String generatePath(Artifact artifact) throws Exception
{
- String layout = null;
- String groupId = artifact.getDependency().getGroupId();
- String artifactId = artifact.getDependency().getArtifactId();
String type = artifact.getDependency().getType();
-
- // Use overriden vesrion if provided
- String version = artifact.getOverriddenVersion();
- if ( version == null )
- {
- version = artifact.getDependency().getVersion();
- }
-
- String artifactFile = null;
- if (artifact.getDependency() != null)
- {
- artifactFile = artifact.getDependency().getArtifact();
- }
- // it means that user is requesting to use a given artifact name
- // so path is: "{group directories}/{type}s/[user provided artifact]"
- //in such case we will use special layout <<nameless>>
- // ( find a better name for this)
-
- if (artifactFile != null)
- {
- layout = getLayout("nameless") + artifactFile;
- }
- else
- {
- // see if we have layout for this artifact type alredy in the cache
- layout = getLayout(type);
- }
- return interpolateLayout( groupId, artifactId, type, version, layout );
+ return generatePath(artifact, type);
}
+
+
+ /**
+ * see org.apache.maven.artifact.RepositoryLayout#generatePath(Artifact)
+ */
+ public String generatePath(Artifact artifact, String type) throws Exception
+ {
+ String layout = null;
+ String groupId = artifact.getDependency().getGroupId();
+ String artifactId = artifact.getDependency().getArtifactId();
+
+ // Use overriden vesrion if provided
+ String version = artifact.getOverriddenVersion();
+ if (version == null)
+ {
+ version = artifact.getDependency().getVersion();
+ }
+
+ String artifactFile = null;
+ if (artifact.getDependency() != null)
+ {
+ artifactFile = artifact.getDependency().getArtifact();
+ }
+ // it means that user is requesting to use a given artifact name
+ // so path is: "{group directories}/{type}s/[user provided artifact]"
+ //in such case we will use special layout <<nameless>>
+ // ( find a better name for this)
+ // @todo get rid of this sh...
+ if (artifactFile != null)
+ {
+ layout = getLayout("nameless") + artifactFile;
+ }
+ else
+ {
+ // see if we have layout for this artifact type alredy in the cache
+ layout = getLayout(type);
+ }
+ return interpolateLayout(groupId, artifactId, type, version, layout);
+ }
/**
* @see
org.apache.maven.artifact.layout.RepositoryLayout#generatePath(java.lang.String,
java.lang.String, java.lang.String, java.lang.String)
@@ -144,8 +151,8 @@
String version)
throws Exception
{
- String layout = getLayout( type );
- return interpolateLayout( groupId, artifactId, type, version, layout );
+ String layout = getLayout(type);
+ return interpolateLayout(groupId, artifactId, type, version, layout);
}
/**
@@ -165,9 +172,9 @@
String layout)
{
layout = StringUtils.replace(layout, "${groupId}", groupId);
- layout = StringUtils.replace(layout, "${artifactId}", artifactId);
+ layout = StringUtils.replace(layout, "${artifactId}", artifactId);
layout = StringUtils.replace(layout, "${type}", type);
- layout = StringUtils.replace(layout, "${version}", version);
+ layout = StringUtils.replace(layout, "${version}", version);
return layout;
}
@@ -182,18 +189,18 @@
*/
private String getLayout(String type)
{
- String layout = (String) globalLayouts.get(type);
+ String layout = (String) layouts.get(type);
if (layout == null)
{
- layout = (String) globalLayouts.get(DEFAULT_LAYOUT_KEY);
+ layout = (String) layouts.get(DEFAULT_LAYOUT_KEY);
if (layout == null)
{
layout = DEFAULT_LAYOUT;
}
- globalLayouts.put(type, layout);
+ layouts.put(type, layout);
}
return layout;
@@ -208,14 +215,38 @@
*/
public void initialize() throws Exception
{
+ layouts = loadLayout("/layout.properties");
+
+ String osName = System.getProperty("os.name");
+ String suffix = null;
+ if (osName.toLowerCase().startsWith("windows"))
+ {
+ suffix = "windows";
+ }
+ else
+ {
+ suffix = "unix";
+ }
+ layouts.putAll(loadLayout("/layout_" + suffix + ".properties"));
+ }
+
+ /**
+ * Load layouts from given properties file
+ * @param filename
+ * @return
+ * @throws MavenException
+ */
+ private Properties loadLayout(String filename) throws MavenException
+ {
+ System.out.println( "Loading: " + filename);
InputStream inputStream = null;
- File configFile = null;
try
{
inputStream =
- DefaultRepositoryLayout.class.getResourceAsStream(
- MavenConstants.LAYOUT_PROPERTIES);
- globalLayouts.load(inputStream);
+ DefaultRepositoryLayout.class.getResourceAsStream(filename);
+ Properties properties = new Properties();
+ properties.load(inputStream);
+ return properties;
}
catch (Exception e)
{
1.6 +51 -24
maven-new/core/src/test/org/apache/maven/artifact/layout/DefaultRepositoryLayoutTest.java
Index: DefaultRepositoryLayoutTest.java
===================================================================
RCS file:
/home/cvs/maven-new/core/src/test/org/apache/maven/artifact/layout/DefaultRepositoryLayoutTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DefaultRepositoryLayoutTest.java 29 May 2003 20:26:24 -0000 1.5
+++ DefaultRepositoryLayoutTest.java 2 Aug 2003 13:52:36 -0000 1.6
@@ -84,7 +84,7 @@
super.setUp();
repositoryLayout = (RepositoryLayout) lookup(RepositoryLayout.ROLE);
}
-
+
public void testGeneratePath()
{
String msg = "Expected path in repository is different than actual.";
@@ -94,45 +94,72 @@
d.setGroupId("mm_group_id");
d.setVersion("1.0.0");
d.setType("a");
- Artifact a = new DefaultArtifact( d );
-
-
- String expectedPath1 = "mm_group_id/as/mm_id-1.0.0.a";
- String actualPath1 = null;
+ Artifact a = new DefaultArtifact(d);
+
+ String expectedPathD = "mm_group_id/as/mm_id-1.0.0.a";
+ String actualPathD = null;
try
{
- actualPath1 = repositoryLayout.generatePath(a);
+ actualPathD = repositoryLayout.generatePath(a);
}
catch (Exception e)
{
- String msg2 =
- "Cannot bulid repository layout for: " + a + ".";
+ String msg2 = "Cannot bulid repository layout for: " + a + ".";
fail(msg2);
}
- assertEquals(msg, expectedPath1, actualPath1);
+ assertEquals(msg, expectedPathD, actualPathD);
+
+ Dependency ejb = new Dependency();
+ ejb.setGroupId("boo");
+ ejb.setArtifactId("foo");
+ ejb.setVersion("1.1.1");
+ ejb.setType("ejb");
+ Artifact ejbA = new DefaultArtifact(ejb);
- Dependency ejbD = new Dependency();
- ejbD.setGroupId("boo");
- ejbD.setArtifactId("foo");
- ejbD.setVersion("1.1.1");
- ejbD.setType("ejb");
- Artifact ejbA = new DefaultArtifact( ejbD );
-
- String expectedPath2 = "boo/ejbs/foo-1.1.1.jar";
- String actualPath2 = null;
+ String expectedPathEjb = "boo/ejbs/foo-1.1.1.jar";
+ String actualPathEjb = null;
try
{
- actualPath2 = repositoryLayout.generatePath( ejbA );
+ actualPathEjb = repositoryLayout.generatePath(ejbA);
}
catch (Exception e)
{
- String msg2 =
- "Cannot bulid repository layout for: " + ejbA + ".";
+ String msg2 = "Cannot bulid repository layout for: " + ejbA + ".";
fail(msg2);
}
- assertEquals(msg, expectedPath2, actualPath2);
+ assertEquals(msg, expectedPathEjb, actualPathEjb);
+
+ Dependency nativeD = new Dependency();
+ nativeD.setGroupId("boo");
+ nativeD.setArtifactId("foo");
+ nativeD.setVersion("1.1.1");
+ nativeD.setType("native");
+ Artifact nativeA = new DefaultArtifact(nativeD);
+
+ String expectedPathNative = null;
+
+ String osName = System.getProperty("os.name");
+ if ( osName.toLowerCase().startsWith("windows"))
+ {
+ expectedPathNative = "boo/native/foo-1.1.1.dll";
+ }
+ else
+ {
+ expectedPathNative = "boo/native/foo-1.1.1.so";
+ }
+ String actualPathNative = null;
+ try
+ {
+ actualPathNative = repositoryLayout.generatePath(nativeA);
+ }
+ catch (Exception e)
+ {
+ String msg2 = "Cannot bulid repository layout for: " + nativeA + ".";
+ fail(msg2);
+ }
+ assertEquals(msg, expectedPathNative, actualPathNative);
}
}
1.5 +1 -3
maven-new/core/src/test/org/apache/maven/artifact/processor/DefaultArtifactProcessorTest.java
Index: DefaultArtifactProcessorTest.java
===================================================================
RCS file:
/home/cvs/maven-new/core/src/test/org/apache/maven/artifact/processor/DefaultArtifactProcessorTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DefaultArtifactProcessorTest.java 26 May 2003 16:24:36 -0000 1.4
+++ DefaultArtifactProcessorTest.java 2 Aug 2003 13:52:36 -0000 1.5
@@ -58,8 +58,6 @@
import java.io.File;
-import org.apache.maven.artifact.handlers.ArtifactHandlerManager;
-import org.apache.maven.artifact.handlers.MockArtifactHandler;
import org.apache.maven.project.Project;
import org.apache.maven.project.builder.ProjectBuilder;
import org.apache.plexus.PlexusTestCase;
1.12 +1 -1 maven-new/core/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/maven-new/core/project.xml,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- project.xml 23 May 2003 16:00:46 -0000 1.11
+++ project.xml 2 Aug 2003 13:52:36 -0000 1.12
@@ -161,7 +161,7 @@
<include>log4j.properties</include>
<include>driver.jelly</include>
<include>driver.properties</include>
- <include>layout.properties</include>
+ <include>layout*.properties</include>
<include>artifact-handler.properties</include>
</includes>
</resource>
1.1 maven-new/core/src/conf/layout_windows.properties
Index: layout_windows.properties
===================================================================
native=${groupId}/native/${artifactId}-${version}.dll
1.1 maven-new/core/src/conf/layout_unix.properties
Index: layout_unix.properties
===================================================================
native=${groupId}/native/${artifactId}-${version}.so
1.4 +5 -3
maven-new/core/src/test/org/apache/maven/artifact/handlers/JarHandlerTest.java
Index: JarHandlerTest.java
===================================================================
RCS file:
/home/cvs/maven-new/core/src/test/org/apache/maven/artifact/handlers/JarHandlerTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JarHandlerTest.java 30 May 2003 15:13:43 -0000 1.3
+++ JarHandlerTest.java 2 Aug 2003 13:52:36 -0000 1.4
@@ -143,10 +143,12 @@
Artifact testA = (Artifact) project.getArtifacts().get(0);
Artifact testB = (Artifact) project.getArtifacts().get(1);
+ ArtifactHandlerChain
+ chain = new DefaultArtifactHandlerChain();
JarHandler jarHandler = new JarHandler();
- jarHandler.process(testA, project);
- jarHandler.process(testB, project);
+ jarHandler.process(testA, project,chain);
+ jarHandler.process(testB, project,chain);
String classpath =
project.getClassPath(MavenConstants.GLOBAL_DEPENDENCY_CLASSPATH);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]