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 20:30:27 UTC
cvs commit: maven-new/core/src/test-input/overriding/legacy project.properties project.xml
michal 2003/05/24 11:30:27
Modified: core/src/java/org/apache/maven/project Dependency.java
Project.java
core/src/java/org/apache/maven/project/builder
DefaultProjectUnmarshaller.java
core/src/test-input/overriding project.properties
project.xml
core/src/test/org/apache/maven/artifact/factory
DefaultArtifactFactoryTest.java
core/src/java/org/apache/maven/artifact/factory
DefaultArtifactFactory.java
Added: core/src/test-input/overriding/legacy project.properties
project.xml
Log:
Artifact overriding mechanism reimplemented
Revision Changes Path
1.3 +52 -12 maven-new/core/src/java/org/apache/maven/project/Dependency.java
Index: Dependency.java
===================================================================
RCS file: /home/cvs/maven-new/core/src/java/org/apache/maven/project/Dependency.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Dependency.java 20 May 2003 04:06:54 -0000 1.2
+++ Dependency.java 24 May 2003 18:30:26 -0000 1.3
@@ -1,5 +1,7 @@
package org.apache.maven.project;
+import org.apache.maven.DeprecationWarning;
+
/* ====================================================================
* The Apache Software License, Version 1.1
*
@@ -69,8 +71,8 @@
/** The URL to the dependency's homepage. */
private String url;
- /** Explictly set JAR name */
- private String jar;
+ /** Explictly set file name */
+ private String file;
/** Artifact name */
private String artifactId;
@@ -222,14 +224,15 @@
* facility.
*
* @return The artifact name.
+ * @deprecated I don't think we should use this (mm)
*/
public String getArtifact()
{
- // If the jar name has been explicty set then use that. This
- // is when the <jar/> element is explicity used in the POM.
- if ( jar != null )
+ // If the file name has been explicty set then use that. This
+ // is when the <file/> element is explicity used in the POM.
+ if ( file != null )
{
- return jar;
+ return file;
}
return getArtifactId() + "-" + getVersion() + "." + getType();
@@ -260,31 +263,67 @@
* version.
*
* @param jar Name of the jar
+ *
+ * @deprecated {@linh setFile } should be used instead
*/
public void setJar( String jar )
{
+ DeprecationWarning.warn(" setJar( String jar ) method is deprecated");
+ setFile( jar );
+ }
+
+
+
+
+ /**
+ * Set the name of the JAR if it cannot be synthesized from the id and
+ * version.
+ *
+ * @param jar Name of the jar
+ */
+ public void setFile( String file )
+ {
// This is a check we need because of the jelly interpolation
// process. If we don't check an empty string will be set and
// screw up getArtifact() above.
- if ( jar.trim().length() == 0 )
+ if ( file.trim().length() == 0 )
{
return;
}
- this.jar = jar;
+ this.file = file;
}
+
+
+
+
/**
* Get the name of the JAR. We will attempt to synthesize the name of the
* JAR from the id and version.
*
* @return Name of the jar
+ * @deprecated <code>getFile()</code> should be used instead
*/
public String getJar()
{
- return jar;
+ DeprecationWarning.warn(" String getJar() method is deprecated");
+ return getFile();
}
+
+ /**
+ * Get the name of the file. This is part of artifact override mechanism
+ *
+ * @return Name of the the file
+ */
+ public String getFile()
+ {
+ return file;
+ }
+
+
+
/**
* Set the name of url for the dependency.
*
@@ -334,8 +373,9 @@
public String toString()
{
return "Dep[ id:" + getId() + " pid:" + getId()
- + " ver:" + getVersion() + " ar:" + getArtifact() + " jar:"
- + getJar() + " ]";
+ + " ver:" + getVersion() + " ar:" + getArtifact() + " file:"
+ + getFile() + " ]";
}
+
}
1.7 +7 -1 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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Project.java 24 May 2003 13:00:08 -0000 1.6
+++ Project.java 24 May 2003 18:30:26 -0000 1.7
@@ -1601,9 +1601,15 @@
* Get the flag indicating the use of the artifact overriding facility.
*
* @return MavenSession jar override flag.
+ * @todo Remove legacy code when not anymore needed
*/
public Boolean getMavenArtifactOverride()
{
+
+ if (getMavenJarOverride().booleanValue())
+ {
+ return getMavenJarOverride();
+ }
return getBoolean( MavenConstants.ARTIFACT_OVERRIDE );
}
1.7 +9 -1 maven-new/core/src/java/org/apache/maven/project/builder/DefaultProjectUnmarshaller.java
Index: DefaultProjectUnmarshaller.java
===================================================================
RCS file: /home/cvs/maven-new/core/src/java/org/apache/maven/project/builder/DefaultProjectUnmarshaller.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DefaultProjectUnmarshaller.java 23 May 2003 02:09:30 -0000 1.6
+++ DefaultProjectUnmarshaller.java 24 May 2003 18:30:26 -0000 1.7
@@ -358,6 +358,14 @@
{
d.setUrl( parser.nextText() );
}
+ else if ( parser.getName().equals( "file" ) )
+ {
+ d.setFile( parser.nextText() );
+ }
+ else if ( parser.getName().equals( "jar" ) )
+ {
+ d.setFile( parser.nextText() );
+ }
else
{
parser.nextText();
1.2 +17 -9 maven-new/core/src/test-input/overriding/project.properties
Index: project.properties
===================================================================
RCS file: /home/cvs/maven-new/core/src/test-input/overriding/project.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- project.properties 24 May 2003 13:00:07 -0000 1.1
+++ project.properties 24 May 2003 18:30:26 -0000 1.2
@@ -1,14 +1,22 @@
-#new
+# ------------------------------------------------------------------------
+# M A V E N A R T I F A C T O V E R R I D E
+# ------------------------------------------------------------------------
+maven.artifact.override = on
+
+
+# ------------------------------------------------------------------------
+# Artifacts set explicity by path.
+# ------------------------------------------------------------------------
+maven.override.file.g2.d2.jar = /lib/d2.jar
+maven.override.file.g3.d3.jar = /lib/d3.jar
+
+
+# ------------------------------------------------------------------------
+# Artifacts set explicity by version.
+# ------------------------------------------------------------------------
+maven.override.version.g4.d4.jar = 1.1
-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.2 +16 -20 maven-new/core/src/test-input/overriding/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/maven-new/core/src/test-input/overriding/project.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- project.xml 24 May 2003 13:00:07 -0000 1.1
+++ project.xml 24 May 2003 18:30:26 -0000 1.2
@@ -1,29 +1,20 @@
<?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>
+ <groupId>g1</groupId>
+ <artifactId>d1</artifactId>
<version>v1</version>
- <jar>/foo/baa-1.1.jar</jar>
+ <file>/foo/baa-1.1.jar</file>
</dependency>
- <!-- Version overriding in properties file -->
- <dependency>
- <groupId>g2</groupId>
- <artifactId>d2</artifactId>
- <version>v2</version>
- </dependency>
+
<!-- File overriding in properties file -->
@@ -31,19 +22,24 @@
<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.-->
+
+ <!-- File overriding in properties file and POM. POM wins -->
<dependency>
<groupId>g3</groupId>
<artifactId>d3</artifactId>
- <version>v3</version>
- <jar>/foo/baa-1.1.jar</jar>
- </dependency>
-
+ <version>3.0</version>
+ <file>should_be_ignored</file>
+ </dependency>
+ <!-- Version overriding in properties file -->
+ <dependency>
+ <groupId>g4</groupId>
+ <artifactId>d4</artifactId>
+ <version>v2</version>
+ </dependency>
+
</dependencies>
</project>
1.7 +75 -27 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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DefaultArtifactFactoryTest.java 24 May 2003 13:00:07 -0000 1.6
+++ DefaultArtifactFactoryTest.java 24 May 2003 18:30:27 -0000 1.7
@@ -96,7 +96,7 @@
public void testCreateArtifacts()
{
- Project project = null;
+ Project project = null;
try
{
@@ -119,6 +119,8 @@
fail( msg );
}
+ String repositoryPath = artifactFactory.getMavenRepoLocal( project ) ;
+
//1 Check if we have required number of artifacts
int expectedNumberOfArtifacts = 2;
int actualNumberOfArtifacts = artifacts.size();
@@ -147,7 +149,7 @@
//4 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-1.0.jar" ) ;
File actualFile1= artifact1.getFile();
@@ -171,13 +173,29 @@
}
- public void testArtifactOverrding()
+ public void testArtifactOverrding()
+ {
+ doTestArtifact( "src/test-input/overriding/project.xml" );
+ }
+
+
+ public void testLegacyArtifactOverrding()
+ {
+ doTestArtifact( "src/test-input/overriding/legacy/project.xml" );
+ }
+
+
+ /**
+ *
+ *
+ */
+ public void doTestArtifact( String projectFile )
{
Project project = null;
-
+
try
{
- project = builder.build( new File( getTestFile( "src/test-input/overriding/project.xml" ) ) );
+ project = builder.build( new File( getTestFile( projectFile ) ) );
}
catch ( Exception e )
{
@@ -195,45 +213,75 @@
"Failed to create list of artifacts: " + e.getMessage();
fail( msg );
}
-
- //1 Check if we have required number of artifacts
+ String repositoryPath = artifactFactory.getMavenRepoLocal( project ) ;
+
+ //1 Check if overddiing is turn on
+
+ boolean isOverringOn = project.getMavenArtifactOverride().booleanValue();
+ assertTrue("Overriding is not turned on", isOverringOn );
+
+ //2 Check if we have required number of artifacts
int expectedNumberOfArtifacts = 4;
int actualNumberOfArtifacts = artifacts.size();
- assertEquals( "Artifact list has unexpected size.", expectedNumberOfArtifacts, actualNumberOfArtifacts );
+ assertEquals( "Artifact list has unexpected size.",
+ expectedNumberOfArtifacts,
+ actualNumberOfArtifacts );
+
+
- // 2 Check if artifacts are not null
+ //3 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 );
+ 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 );
+ assertNotNull( msg1,artifact4 );
- //3 Check if files were set correctly
+ //4 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" ) ;
+
+ // a1 - file overrding in POM
+ File expectedFile1 = new File ( "/foo/baa-1.1.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 );
+ assertEquals( "File overriding in POM: " + msg3,
+ expectedFile1,
+ actualFile1 );
+
+ // a2 file overring in properties file
+ File expectedFile2 = new File ( "/lib/d2.jar" );
+ File actualFile2= artifact2.getFile();
+ assertEquals( "File overrding in prop. file: " + msg3,
+ expectedFile2,
+ actualFile2 );
+
+ // a3 file overring in properties file and POM
+ File expectedFile3 = new File ( "/lib/d3.jar" );
+ File actualFile3= artifact3.getFile();
+ assertEquals( "File overrding in prop. file and POM: " + msg3,
+ expectedFile3,
+ actualFile3 );
+
+ // a4 - version overrding in POM
+ File expectedFile4 = new File (repositoryPath, "/g4/jars/d4-1.1.jar" );
+ File actualFile4= artifact4.getFile();
+ assertEquals( "Version overrding in prop. file: " + msg3 ,
+ expectedFile4,
+ actualFile4 );
+
- //4 check if artifact's fields were set properly
- assertTrue( "Version was not overriden." , artifact1.isVersionOverridden() );
- assertFalse( "File should not be overriden." , artifact1.isFileOverridden() );
+ //4 check if some choosen artifacts' fields were set properly
+ assertTrue( "Version was overriden." , artifact4.isVersionOverridden() );
+ assertFalse( "File should not be overriden." , artifact4.isFileOverridden() );
- assertFalse( "Version should not be overriden." , artifact2.isVersionOverridden() );
- assertTrue( "File was not overriden." , artifact2.isFileOverridden() );
+ assertFalse( "Version should not be overriden." , artifact1.isVersionOverridden() );
+ assertTrue( "File was not overriden." , artifact1.isFileOverridden() );
}
1.12 +37 -27 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.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- DefaultArtifactFactory.java 24 May 2003 13:10:29 -0000 1.11
+++ DefaultArtifactFactory.java 24 May 2003 18:30:27 -0000 1.12
@@ -127,27 +127,33 @@
artifact.setType( dependency.getType() );
artifact.setVersion( dependency.getVersion() );
- 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)
- {
- artifact.setVersion( version );
- artifact.setVersionOveridden( true );
- }
- String path = generatePath( artifact );
+ if (mavenJarOverride)
+ {
+ String file = getOverridenFile( artifact, project );
+ if ( file == null )
+ {
+ file = dependency.getFile();
+ }
+ if ( file != null )
+ {
+ artifact.setFile( file );
+ artifact.setFileOveridden( true );
+ }
+ else
+ {
+ String version = getOverridenVersion( artifact, project );
+ if ( version != null)
+ {
+ artifact.setVersion( version );
+ artifact.setVersionOveridden( true );
+ }
+ }
+ }
+ if ( artifact.isFileOverridden() == false )
+ {
+ String path = generatePath( artifact );
artifact.setPath( path );
- file = new File( getMavenRepoLocal( project ) , path ).getAbsolutePath();
+ String file = new File( getMavenRepoLocal( project ) , path ).getAbsolutePath();
artifact.setFile( file );
}
artifacts.add( artifact );
@@ -223,8 +229,8 @@
*/
public String getOverridenFile( Artifact artifact, Project project )
{
- // startof block for backward compatibility
- // to be removed somewhere in the future
+ // start of the block for backward compatibility
+ // this should be removed somewhere in the future
String file = null;
file = getMavenJarOverride ( artifact.getArtifactId(), project );
if ( file != null)
@@ -243,7 +249,9 @@
String key = MavenConstants.FILE_OVERRIDE_PROPERTY +
artifact.getGroupId() +
"." +
- artifact.getArtifactId();
+ artifact.getArtifactId() +
+ "." +
+ artifact.getType();
file = (String) project.getProperties().get( key );
return file;
@@ -257,8 +265,8 @@
*/
public String getOverridenVersion( Artifact artifact, Project project )
{
- // startof block for backward compatibility
- // to be removed somewhere in the future
+ // start of the block for backward compatibility
+ // this should be removed somewhere in the future
String version = null;
version = getMavenJarOverride ( artifact.getArtifactId(), project );
if ( version != null)
@@ -277,7 +285,9 @@
String key = MavenConstants.VERSION_OVERRIDE_PROPERTY +
artifact.getGroupId() +
"." +
- artifact.getArtifactId();
+ artifact.getArtifactId() +
+ "." +
+ artifact.getType();
version = (String) project.getProperties().get( key );
return version;
}
1.1 maven-new/core/src/test-input/overriding/legacy/project.properties
Index: project.properties
===================================================================
# ------------------------------------------------------------------------
# M A V E N L E G A CY J A R O V E R R I D E
# ------------------------------------------------------------------------
maven.jar.override = on
# ------------------------------------------------------------------------
# Artifacts set explicity by path.
# ------------------------------------------------------------------------
maven.jar.d2 = /lib/d2.jar
maven.jar.d3 = /lib/d3.jar
# ------------------------------------------------------------------------
# Artifacts set explicity by version.
# ------------------------------------------------------------------------
maven.jar.d4 = 1.1
1.1 maven-new/core/src/test-input/overriding/legacy/project.xml
Index: project.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<project>
<groupId>maven</groupId>
<artifactId>maven</artifactId>
<dependencies>
<!-- JAR overriding in POM-->
<dependency>
<groupId>g1</groupId>
<artifactId>d1</artifactId>
<version>v1</version>
<jar>/foo/baa-1.1.jar</jar>
</dependency>
<!-- File overriding in properties file -->
<dependency>
<groupId>g2</groupId>
<artifactId>d2</artifactId>
<version>3.0</version>
</dependency>
<!-- jar overriding in properties file and POM. POM wins -->
<dependency>
<groupId>g3</groupId>
<artifactId>d3</artifactId>
<version>3.0</version>
<jar>should_be_ignored</jar>
</dependency>
<!-- Version overriding in properties file -->
<dependency>
<groupId>g4</groupId>
<artifactId>d4</artifactId>
<version>v2</version>
</dependency>
</dependencies>
</project>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org