You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by mi...@apache.org on 2003/05/24 15:00:10 UTC
cvs commit: maven-new/core/src/java/org/apache/maven MavenConstants.java
michal 2003/05/24 06:00:08
Modified: core/src/java/org/apache/maven/artifact DefaultArtifact.java
Artifact.java
core/src/test/org/apache/maven/artifact/factory
DefaultArtifactFactoryTest.java
core/src/java/org/apache/maven/artifact/factory
DefaultArtifactFactory.java
core/src/java/org/apache/maven/project Project.java
core/src/java/org/apache/maven MavenConstants.java
Added: core/src/test-input/overriding project.properties
project.xml
Log:
Artifact overrding reimplemented
Revision Changes Path
1.9 +29 -9 maven-new/core/src/java/org/apache/maven/artifact/DefaultArtifact.java
Index: DefaultArtifact.java
===================================================================
RCS file: /home/cvs/maven-new/core/src/java/org/apache/maven/artifact/DefaultArtifact.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- DefaultArtifact.java 24 May 2003 05:16:01 -0000 1.8
+++ DefaultArtifact.java 24 May 2003 13:00:06 -0000 1.9
@@ -110,9 +110,14 @@
private Dependency dependency = null;
/**
- * Overidden flag
+ * Overidden file flag
*/
- private boolean overriden;
+ private boolean fileOverriden;
+
+ /**
+ * Overidden version flag
+ */
+ private boolean versionOverriden;
/**
* Default constructor
@@ -308,17 +313,32 @@
/**
* @see org.apache.maven.artifact.Artifact#setOverriden(boolean )
*/
- public void setOveridden( boolean overriden )
+ public void setFileOveridden( boolean fileOverriden )
{
- this.overriden = overriden;
+ this.fileOverriden = fileOverriden;
}
/**
- * Gets the flag is artifact has been overriden
- * @return
+ * @see org.apache.maven.artifact.Artifact#isFileOverriden()
*/
- public boolean isOverridden()
+ public boolean isFileOverridden()
{
- return overriden;
+ return fileOverriden;
}
+ /**
+ * @see org.apache.maven.artifact.Artifact#setVersionOverriden(boolean )
+ */
+ public void setVersionOveridden( boolean versionOverriden )
+ {
+ this.versionOverriden = versionOverriden;
+ }
+
+ /**
+ * @see org.apache.maven.artifact.Artifact#isVersionOverriden()
+ */
+ public boolean isVersionOverridden()
+ {
+ return versionOverriden;
+ }
+
}
1.7 +19 -4 maven-new/core/src/java/org/apache/maven/artifact/Artifact.java
Index: Artifact.java
===================================================================
RCS file: /home/cvs/maven-new/core/src/java/org/apache/maven/artifact/Artifact.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Artifact.java 23 May 2003 23:13:44 -0000 1.6
+++ Artifact.java 24 May 2003 13:00:07 -0000 1.7
@@ -174,13 +174,28 @@
* Sets the flag which indicates
* if file override mechanism was applied to this artifact
*/
- public void setOveridden( boolean overriden );
+ public void setFileOveridden( boolean fileOverriden );
/**
- * Gets the flag is artifact has been overriden
+ * Gets the flag is artifact's file has been overriden
* @return
*/
- public boolean isOverridden();
+ public boolean isFileOverridden();
+
+
+
+ /**
+ * Sets the flag which indicates
+ * if version override mechanism was applied to this artifact
+ */
+ public void setVersionOveridden( boolean versionOverriden );
+
+ /**
+ * Gets the flag is artifact's version has been overriden
+ * @return
+ */
+ public boolean isVersionOverridden();
+
/**
* Returns id which is "groupId:artifactId"
1.1 maven-new/core/src/test-input/overriding/project.properties
Index: project.properties
===================================================================
#new
maven.override.version.g3.d3.jar=overidden
maven.override.file.g4.d4.jar=/lib/d4.jar
#legacy
maven.jar.d5=/lib/d5
maven.jar.d6=1.1
1.1 maven-new/core/src/test-input/overriding/project.xml
Index: project.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<project>
<pomVersion>3</pomVersion>
<groupId>maven</groupId>
<artifactId>maven</artifactId>
<name>Maven</name>
<currentVersion>1.0-beta-9</currentVersion>
<inceptionYear>2001</inceptionYear>
<dependencies>
<!-- File overriding in POM-->
<dependency>
<groupId>g2</groupId>
<artifactId>a2</artifactId>
<version>v1</version>
<jar>/foo/baa-1.1.jar</jar>
</dependency>
<!-- Version overriding in properties file -->
<dependency>
<groupId>g2</groupId>
<artifactId>d2</artifactId>
<version>v2</version>
</dependency>
<!-- File overriding in properties file -->
<dependency>
<groupId>g2</groupId>
<artifactId>d2</artifactId>
<version>3.0</version>
<jar>/foo/baa-1.1.jar</jar>
</dependency>
<!-- File overriding in POM and properties file.-->
<dependency>
<groupId>g3</groupId>
<artifactId>d3</artifactId>
<version>v3</version>
<jar>/foo/baa-1.1.jar</jar>
</dependency>
</dependencies>
</project>
1.6 +76 -7 maven-new/core/src/test/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java
Index: DefaultArtifactFactoryTest.java
===================================================================
RCS file: /home/cvs/maven-new/core/src/test/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DefaultArtifactFactoryTest.java 23 May 2003 22:51:54 -0000 1.5
+++ DefaultArtifactFactoryTest.java 24 May 2003 13:00:07 -0000 1.6
@@ -146,27 +146,96 @@
assertEquals( msg2,expectedPath2,actualPath2 );
//4 Check if files were set correctly
- String msg3="Artifact has incorrect path.";
+ String msg3="Artifact file has been set incorrectly.";
String repositoryPath = artifactFactory.getMavenRepoLocal( project ) ;
// a1
File expectedFile1 = new File ( repositoryPath, "g1/jars/d1-1.0.jar" ) ;
File actualFile1= artifact1.getFile();
- assertEquals( msg3,expectedPath1,actualPath1 );
+ assertEquals( msg3,expectedFile1,actualFile1 );
// a2
File expectedFile2 = new File ( repositoryPath, "g2/jars/d2-2.0.jar");
File actualFile2= artifact2.getFile();
- assertEquals( msg3,expectedPath2,actualPath2 );
+ assertEquals( msg3,expectedFile2,actualFile2 );
- //5 check if artifact's fields were set properly
-
+ //5 check if artifact's fields were set properly
assertEquals( "Group was incorrectly set." , artifact1.getGroupId() , "g1" );
assertEquals( "ArtifactId was incorrectly set." , artifact1.getArtifactId() , "d1" );
assertEquals( "Version was incorrectly set." , artifact1.getVersion() , "1.0" );
assertEquals( "Type was incorrectly set." , artifact1.getType() , "jar" );
-
+ assertFalse( "Version should not be overriden" , artifact1.isVersionOverridden() );
+ assertFalse( "File should not be overriden" , artifact1.isFileOverridden() );
+ assertFalse( "Artifact is not a SNAPHOT" , artifact1.isSnapshot() );
}
+
+
+ public void testArtifactOverrding()
+ {
+ Project project = null;
+
+ try
+ {
+ project = builder.build( new File( getTestFile( "src/test-input/overriding/project.xml" ) ) );
+ }
+ catch ( Exception e )
+ {
+ String msg = "Cannot get project sample: " + e.getMessage();
+ fail( msg );
+ }
+ List artifacts = null;
+ try
+ {
+ artifacts = artifactFactory.createArtifacts( project );
+ }
+ catch ( Exception e )
+ {
+ String msg =
+ "Failed to create list of artifacts: " + e.getMessage();
+ fail( msg );
+ }
+
+ //1 Check if we have required number of artifacts
+ int expectedNumberOfArtifacts = 4;
+ int actualNumberOfArtifacts = artifacts.size();
+ assertEquals( "Artifact list has unexpected size.", expectedNumberOfArtifacts, actualNumberOfArtifacts );
+
+
+ // 2 Check if artifacts are not null
+ Artifact artifact1 = ( Artifact ) artifacts.get( 0 );
+ Artifact artifact2 = ( Artifact ) artifacts.get( 1 );
+ Artifact artifact3 = ( Artifact ) artifacts.get( 2 );
+ Artifact artifact4 = ( Artifact ) artifacts.get( 3 );
+
+ String msg1 = "No artifact should be null.";
+ assertNotNull( msg1,artifact1 );
+ assertNotNull( msg1,artifact2 );
+ assertNotNull( msg1,artifact3 );
+ assertNotNull( msg1,artifact4 );
+
+
+ //3 Check if files were set correctly
+ String msg3="Artifact file has been set incorrectly.";
+ String repositoryPath = artifactFactory.getMavenRepoLocal( project ) ;
+ // a1
+ File expectedFile1 = new File ( repositoryPath, "g1/jars/d1-3.0.jar" ) ;
+ File actualFile1= artifact1.getFile();
+ assertEquals( msg3,expectedFile1,actualFile1 );
+ // a2
+ File expectedFile2 = new File ( "/foo/baa-1.1.jar" );
+ File actualFile2= artifact2.getFile();
+
+ assertEquals( msg3,expectedFile2,actualFile2 );
+
+ //4 check if artifact's fields were set properly
+ assertTrue( "Version was not overriden." , artifact1.isVersionOverridden() );
+ assertFalse( "File should not be overriden." , artifact1.isFileOverridden() );
+
+ assertFalse( "Version should not be overriden." , artifact2.isVersionOverridden() );
+ assertTrue( "File was not overriden." , artifact2.isFileOverridden() );
+
+ }
+
}
1.10 +123 -50 maven-new/core/src/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java
Index: DefaultArtifactFactory.java
===================================================================
RCS file: /home/cvs/maven-new/core/src/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- DefaultArtifactFactory.java 23 May 2003 22:48:59 -0000 1.9
+++ DefaultArtifactFactory.java 24 May 2003 13:00:07 -0000 1.10
@@ -56,19 +56,20 @@
* ====================================================================
*/
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
-import org.apache.maven.project.Dependency;
-import org.apache.maven.project.Project;
-import org.apache.maven.artifact.layout.RepositoryLayout;
+import org.apache.maven.MavenConstants;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import org.apache.maven.artifact.layout.RepositoryLayout;
+import org.apache.maven.project.Dependency;
+import org.apache.maven.project.Project;
/**
* Simple factory for creating Artifact implementations based on a dependency
@@ -84,7 +85,7 @@
private RepositoryLayout repositoryLayout;
/**
- * Return an appropriate Artifact implementation based on the dependency
+ * Return the list of artifact for given project
* type.
*
* @param project The base dependency.
@@ -108,9 +109,11 @@
List dependencies = project.getDependencies();
List artifacts = new ArrayList();
- boolean mavenJarOverride = project.getMavenJarOverride().booleanValue();
+ boolean mavenJarOverride = project.getMavenArtifactOverride().booleanValue();
for ( Iterator iter = dependencies.iterator(); iter.hasNext(); )
{
+ // if dependecy has no type we are assuming that it is jar
+ //
Dependency dependency = (Dependency) iter.next();
if ( dependency.getType() == null
|| dependency.getType().trim().length() == 0 )
@@ -121,46 +124,31 @@
artifact.setDependency( dependency );
artifact.setArtifactId( dependency.getArtifactId() );
artifact.setGroupId( dependency.getArtifactDirectory() );
- artifact.setType( dependency.getType() );
-
- // JAR OVERRIDING
- String mavenJarProperty = null;
- // project.getMavenJarOverride(
- // Project.standardToLegacyId( dependency.getId() ) );
-
- String path = null;
- String version = dependency.getVersion();
-
- if ( mavenJarOverride
- && mavenJarProperty != null
- && mavenJarProperty.length() > 0 )
- {
- // The jar override option has been set and we have a property
- // for the this dependency so override the path with the user
- // specified value.
- if ( Character.isDigit( mavenJarProperty.charAt( 0 ) ) )
- {
- // User is requesting a specific version of a dependency
- // be used.
- version = mavenJarProperty;
- }
- else
+ artifact.setType( dependency.getType() );
+
+ String file = getOverridenFile( artifact, project );
+ if ( file == null )
+ {
+ file = dependency.getJar();
+ }
+ if ( file != null )
+ {
+ artifact.setFile( file );
+ artifact.setFileOveridden( true );
+ }
+ else
+ {
+ String version = getOverridenVersion( artifact, project );
+ if ( version != null)
{
- // User is requesting a specific path to a dependency
- // be used.
- path = new File( mavenJarProperty ).getAbsolutePath();
- artifact.setOveridden( true );
- artifact.setFile( path );
- }
- }
- artifact.setVersion( version );
- if ( ! artifact.isOverridden() )
- {
- path = generatePath( artifact );
- artifact.setPath( path );
- File file = new File( getMavenRepoLocal( project ) , path );
- artifact.setFile( file.getAbsolutePath() );
- }
+ artifact.setVersion( version );
+ artifact.setVersionOveridden( true );
+ }
+ String path = generatePath( artifact );
+ artifact.setPath( path );
+ file = new File( getMavenRepoLocal( project ) , path ).getAbsolutePath();
+ artifact.setFile( file );
+ }
artifacts.add( artifact );
}
return artifacts;
@@ -208,6 +196,91 @@
return mavenRepoLocal;
}
+
+ /**
+ * Get the maven jar override value for a particular dependency.
+ *
+ * This is "a copy/paste" from Project class
+ *
+ * @param id Id of the project to override.
+ * @return MavenSession jar override value for a particular dependency.
+ *
+ * @deprecated this is purly for backward compatibility
+ */
+ public String getMavenJarOverride( String id, Project project )
+ {
+ return (String) project.getProperties().get( MavenConstants.JAR_OVERRIDE_PROPERTY + id );
+ }
+
+
+
+ /**
+ * Get the maven jar override value for a particular dependency.
+ *
+ * @param id Id of the project to override.
+ * @return MavenSession jar override value for a particular dependency.
+ */
+ public String getOverridenFile( Artifact artifact, Project project )
+ {
+ // startof block for backward compatibility
+ // to be removed somewhere in the future
+ String file = null;
+ file = getMavenJarOverride ( artifact.getArtifactId(), project );
+ if ( file != null)
+ {
+ if ( !Character.isDigit( file.charAt(0) ) )
+ {
+ return file;
+ }
+ else
+ {
+ return null;
+ }
+ }
+ // end of block
+
+ String key = MavenConstants.FILE_OVERRIDE_PROPERTY +
+ artifact.getGroupId() +
+ "." +
+ artifact.getArtifactId();
+
+ file = (String) project.getProperties().get( key );
+ return file;
+ }
+
+ /**
+ * Get the maven jar override value for a particular dependency.
+ *
+ * @param id Id of the project to override.
+ * @return MavenSession jar override value for a particular dependency.
+ */
+ public String getOverridenVersion( Artifact artifact, Project project )
+ {
+ // startof block for backward compatibility
+ // to be removed somewhere in the future
+ String version = null;
+ version = getMavenJarOverride ( artifact.getArtifactId(), project );
+ if ( version != null)
+ {
+ if ( Character.isDigit( version.charAt(0) ) )
+ {
+ return version;
+ }
+ else
+ {
+ return null;
+ }
+ }
+ // end of block
+
+ String key = MavenConstants.VERSION_OVERRIDE_PROPERTY +
+ artifact.getGroupId() +
+ "." +
+ artifact.getArtifactId();
+ version = (String) project.getProperties().get( key );
+ return version;
+ }
+
/**
* @param artifact
1.6 +25 -11 maven-new/core/src/java/org/apache/maven/project/Project.java
Index: Project.java
===================================================================
RCS file: /home/cvs/maven-new/core/src/java/org/apache/maven/project/Project.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Project.java 23 May 2003 02:10:29 -0000 1.5
+++ Project.java 24 May 2003 13:00:08 -0000 1.6
@@ -1566,6 +1566,8 @@
* Set the flag indicating the use of the JAR overriding facility.
*
* @param mavenJarOverride MavenSession jar override flag.
+ *
+ * @deprecated use {@link setMavenArtifactOverride(Boolean )} instead.
*/
public void setMavenJarOverride( Boolean mavenJarOverride )
{
@@ -1576,22 +1578,34 @@
* Get the flag indicating the use of the JAR overriding facility.
*
* @return MavenSession jar override flag.
+ * @deprecated use {@link getMavenArtifactOverride()} instead.
*/
public Boolean getMavenJarOverride()
{
return getBoolean( MavenConstants.JAR_OVERRIDE );
}
- /**
- * Get the maven jar override value for a particular dependency.
- *
- * @param id Id of the project to override.
- * @return MavenSession jar override value for a particular dependency.
- */
- public String getMavenJarOverride( String id )
- {
- return (String) getVariable( MavenConstants.JAR_OVERRIDE_PROPERTY + id );
- }
+
+ /**
+ * Set the flag indicating the use of the artifact overriding facility.
+ *
+ * @param mavenJarOverride MavenSession jar override flag.
+ *
+ */
+ public void setMavenArtifactOverride( Boolean mavenArtifactOverride )
+ {
+ setVariable( MavenConstants.ARTIFACT_OVERRIDE, mavenArtifactOverride );
+ }
+
+ /**
+ * Get the flag indicating the use of the artifact overriding facility.
+ *
+ * @return MavenSession jar override flag.
+ */
+ public Boolean getMavenArtifactOverride()
+ {
+ return getBoolean( MavenConstants.ARTIFACT_OVERRIDE );
+ }
private void setVariable( String key, Object value )
{
1.4 +13 -1 maven-new/core/src/java/org/apache/maven/MavenConstants.java
Index: MavenConstants.java
===================================================================
RCS file: /home/cvs/maven-new/core/src/java/org/apache/maven/MavenConstants.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MavenConstants.java 20 May 2003 04:06:53 -0000 1.3
+++ MavenConstants.java 24 May 2003 13:00:08 -0000 1.4
@@ -91,8 +91,20 @@
/** Jar Override tag. */
public static final String JAR_OVERRIDE = "maven.jar.override";
+ /** Artifact Override tag. */
+ public static final String ARTIFACT_OVERRIDE = "maven.artifact.override";
+
+
/** Jar Override property tag. */
public static final String JAR_OVERRIDE_PROPERTY = "maven.jar.";
+
+
+ /** Version Override property tag. */
+ public static final String VERSION_OVERRIDE_PROPERTY = "maven.override.version.";
+
+
+ /** Version Override property tag. */
+ public static final String FILE_OVERRIDE_PROPERTY = "maven.override.file.";
/** Local Repository tag. */
public static final String REPO_LOCAL = "maven.repo.local";
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org