refactoring:

- use an expression in the suport POM to set up finalName
- have interpolator and injector deal only with model


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163380 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-02-23 03:27:00 +00:00
parent c903684688
commit 4465e49559
11 changed files with 64 additions and 96 deletions

View File

@ -31,8 +31,8 @@ import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.project.inheritance.ModelInheritanceAssembler;
import org.apache.maven.project.injection.ProjectDefaultsInjector;
import org.apache.maven.project.interpolation.ProjectInterpolator;
import org.apache.maven.project.injection.ModelDefaultsInjector;
import org.apache.maven.project.interpolation.ModelInterpolator;
import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.project.validation.ModelValidationResult;
import org.apache.maven.project.validation.ModelValidator;
@ -73,9 +73,9 @@ public class DefaultMavenProjectBuilder
private PathTranslator pathTranslator;
private ProjectDefaultsInjector projectDefaultsInjector;
private ModelDefaultsInjector modelDefaultsInjector;
private ProjectInterpolator projectInterpolator;
private ModelInterpolator modelInterpolator;
public void initialize()
throws Exception
@ -117,15 +117,18 @@ public class DefaultMavenProjectBuilder
previous = current;
}
project = projectInterpolator.interpolate( project );
Model model = modelInterpolator.interpolate( project.getModel() );
projectDefaultsInjector.injectDefaults( project );
// interpolation is before injection, because interpolation is off-limits in the injected variables
modelDefaultsInjector.injectDefaults( model );
MavenProject parentProject = project.getParent();
project = new MavenProject( model );
project.setFile( projectDescriptor );
project.setParent( parentProject );
project.setArtifacts( artifactFactory.createArtifacts( project.getDependencies(), localRepository ) );
// @todo this should be in the super POM when interpolation works
setupMavenFinalName( project );
// ----------------------------------------------------------------------
// Typically when the project builder is being used from maven proper
// the transitive dependencies will not be resolved here because this
@ -220,14 +223,6 @@ public class DefaultMavenProjectBuilder
return project;
}
private void setupMavenFinalName( MavenProject project )
{
if ( project.getModel().getBuild().getFinalName() == null )
{
project.getModel().getBuild().setFinalName( project.getArtifactId() + "-" + project.getVersion() );
}
}
private Model readModel( File projectDescriptor )
throws ProjectBuildingException
{

View File

@ -233,6 +233,11 @@ public class DefaultModelInheritanceAssembler
child.getBuild().setTestOutput( parent.getBuild().getTestOutput() );
}
if ( child.getBuild().getFinalName() == null )
{
child.getBuild().setFinalName( parent.getBuild().getFinalName() );
}
List resources = child.getBuild().getResources();
if ( resources == null || resources.isEmpty() )
{

View File

@ -18,7 +18,7 @@ package org.apache.maven.project.injection;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.project.MavenProject;
import org.apache.maven.model.Model;
import java.util.Iterator;
import java.util.List;
@ -29,13 +29,13 @@ import java.util.TreeMap;
/**
* @author jdcasey Created on Feb 1, 2005
*/
public class DefaultProjectDefaultsInjector
implements ProjectDefaultsInjector
public class DefaultModelDefaultsInjector
implements ModelDefaultsInjector
{
public void injectDefaults( MavenProject project )
public void injectDefaults( Model model )
{
injectDependencyDefaults( project.getDependencies(), project.getDependencyManagement() );
injectDependencyDefaults( model.getDependencies(), model.getDependencyManagement() );
}
/**

View File

@ -16,14 +16,14 @@ package org.apache.maven.project.injection;
* limitations under the License.
*/
import org.apache.maven.project.MavenProject;
import org.apache.maven.model.Model;
/**
* @author jdcasey Created on Feb 1, 2005
*/
public interface ProjectDefaultsInjector
public interface ModelDefaultsInjector
{
String ROLE = ProjectDefaultsInjector.class.getName();
String ROLE = ModelDefaultsInjector.class.getName();
void injectDefaults( MavenProject project );
void injectDefaults( Model model );
}

View File

@ -22,13 +22,13 @@ package org.apache.maven.project.interpolation;
*
* Created on Feb 2, 2005
*/
public class ProjectInterpolationException
public class ModelInterpolationException
extends Exception
{
/** Added: Feb 2, 2005 by jdcasey
*/
public ProjectInterpolationException( String expression, Throwable cause )
public ModelInterpolationException( String expression, Throwable cause )
{
super( "The POM expression: " + expression + " could not be evaluated.", cause );

View File

@ -17,18 +17,18 @@ package org.apache.maven.project.interpolation;
* ====================================================================
*/
import org.apache.maven.project.MavenProject;
import org.apache.maven.model.Model;
/**
* @author jdcasey
*
* Created on Feb 2, 2005
*/
public interface ProjectInterpolator
public interface ModelInterpolator
{
String ROLE = ProjectInterpolator.class.getName();
String ROLE = ModelInterpolator.class.getName();
MavenProject interpolate( MavenProject project ) throws ProjectInterpolationException;
Model interpolate( Model project ) throws ModelInterpolationException;
}

View File

@ -20,7 +20,6 @@ package org.apache.maven.project.interpolation;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.project.MavenProject;
import org.apache.maven.util.introspection.ReflectionValueExtractor;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
@ -33,20 +32,19 @@ import java.util.regex.Pattern;
/**
* @author jdcasey Created on Feb 3, 2005
*/
public class RegexBasedProjectInterpolator
public class RegexBasedModelInterpolator
extends AbstractLogEnabled
implements ProjectInterpolator
implements ModelInterpolator
{
private static final Pattern EXPRESSION_PATTERN = Pattern.compile( "#([.A-Za-z]+)" );
private static final Pattern EXPRESSION_PATTERN = Pattern.compile( "#([A-Za-z.]+)" );
/**
* Added: Feb 3, 2005 by jdcasey
*/
public MavenProject interpolate( MavenProject project ) throws ProjectInterpolationException
public Model interpolate( Model model ) throws ModelInterpolationException
{
StringWriter sWriter = new StringWriter();
Model model = project.getModel();
MavenXpp3Writer writer = new MavenXpp3Writer();
try
@ -55,7 +53,7 @@ public class RegexBasedProjectInterpolator
}
catch( Exception e )
{
throw new ProjectInterpolationException(
throw new ModelInterpolationException(
"Cannot serialize project model for interpolation.", e );
}
@ -71,22 +69,15 @@ public class RegexBasedProjectInterpolator
}
catch( Exception e )
{
throw new ProjectInterpolationException(
throw new ModelInterpolationException(
"Cannot read project model from interpolating filter of serialized version.", e );
}
MavenProject newProject = new MavenProject( model );
newProject.setParent( project.getParent() );
newProject.setFile( project.getFile() );
newProject.setArtifacts( project.getArtifacts() );
return new MavenProject( model );
return model;
}
/**
* Added: Feb 3, 2005 by jdcasey
*
* @throws Exception
*/
private String interpolateInternal( String src, Model model )
{

View File

@ -77,8 +77,8 @@
|
-->
<component>
<role>org.apache.maven.project.interpolation.ProjectInterpolator</role>
<implementation>org.apache.maven.project.interpolation.RegexBasedProjectInterpolator</implementation>
<role>org.apache.maven.project.interpolation.ModelInterpolator</role>
<implementation>org.apache.maven.project.interpolation.RegexBasedModelInterpolator</implementation>
</component>
<!--
|
@ -86,8 +86,8 @@
|
-->
<component>
<role>org.apache.maven.project.injection.ProjectDefaultsInjector</role>
<implementation>org.apache.maven.project.injection.DefaultProjectDefaultsInjector</implementation>
<role>org.apache.maven.project.injection.ModelDefaultsInjector</role>
<implementation>org.apache.maven.project.injection.DefaultModelDefaultsInjector</implementation>
</component>
<!--
|
@ -99,10 +99,10 @@
<implementation>org.apache.maven.project.DefaultMavenProjectBuilder</implementation>
<requirements>
<requirement>
<role>org.apache.maven.project.injection.ProjectDefaultsInjector</role>
<role>org.apache.maven.project.injection.ModelDefaultsInjector</role>
</requirement>
<requirement>
<role>org.apache.maven.project.interpolation.ProjectInterpolator</role>
<role>org.apache.maven.project.interpolation.ModelInterpolator</role>
</requirement>
<requirement>
<role>org.apache.maven.project.inheritance.ModelInheritanceAssembler</role>

View File

@ -20,14 +20,6 @@
</pluginRepositories>
-->
<!-- TODO: should be the maven local home -->
<!-- TODO: substitution not working -->
<!--
<local>
<repository>${user.home}/.m2/repository</repository>
</local>
-->
<!-- Default plugins
<plugins>
<plugin>
@ -40,6 +32,7 @@
<!-- This all may just fold into plugin parameters -->
<directory>target</directory>
<output>target/classes</output>
<finalName>#artifactId-#version</finalName>
<testOutput>target/test-classes</testOutput>
<sourceDirectory>src/main/java</sourceDirectory>
<unitTestSourceDirectory>src/test/java</unitTestSourceDirectory>

View File

@ -20,7 +20,7 @@ import junit.framework.TestCase;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Model;
import org.apache.maven.project.injection.DefaultProjectDefaultsInjector;
import org.apache.maven.project.injection.DefaultModelDefaultsInjector;
import java.util.List;
import java.util.Properties;
@ -36,7 +36,7 @@ extends TestCase
public void testShouldConstructWithNoParams()
{
new DefaultProjectDefaultsInjector();
new DefaultModelDefaultsInjector();
}
public void testShouldSucceedInMergingDependencyWithDependency()
@ -60,11 +60,9 @@ extends TestCase
model.setDependencyManagement( depMgmt );
MavenProject project = new MavenProject( model );
new DefaultModelDefaultsInjector().injectDefaults( model );
new DefaultProjectDefaultsInjector().injectDefaults( project );
List deps = project.getDependencies();
List deps = model.getDependencies();
assertEquals( 1, deps.size() );
Dependency result = (Dependency) deps.get( 0 );
@ -92,11 +90,9 @@ extends TestCase
model.setDependencyManagement( depMgmt );
MavenProject project = new MavenProject( model );
new DefaultModelDefaultsInjector().injectDefaults( model );
new DefaultProjectDefaultsInjector().injectDefaults( project );
List deps = project.getDependencies();
List deps = model.getDependencies();
assertEquals( 1, deps.size() );
Dependency result = (Dependency) deps.get( 0 );
@ -124,11 +120,9 @@ extends TestCase
model.setDependencyManagement( depMgmt );
MavenProject project = new MavenProject( model );
new DefaultModelDefaultsInjector().injectDefaults( model );
new DefaultProjectDefaultsInjector().injectDefaults( project );
List deps = project.getDependencies();
List deps = model.getDependencies();
assertEquals( 1, deps.size() );
Dependency result = (Dependency) deps.get( 0 );
@ -161,11 +155,9 @@ extends TestCase
model.setDependencyManagement( depMgmt );
MavenProject project = new MavenProject( model );
new DefaultModelDefaultsInjector().injectDefaults( model );
new DefaultProjectDefaultsInjector().injectDefaults( project );
List deps = project.getDependencies();
List deps = model.getDependencies();
assertEquals( 1, deps.size() );
Dependency result = (Dependency) deps.get( 0 );
@ -204,11 +196,9 @@ extends TestCase
model.setDependencyManagement( depMgmt );
MavenProject project = new MavenProject( model );
new DefaultModelDefaultsInjector().injectDefaults( model );
new DefaultProjectDefaultsInjector().injectDefaults( project );
List deps = project.getDependencies();
List deps = model.getDependencies();
assertEquals( 1, deps.size() );
Dependency result = (Dependency) deps.get( 0 );
@ -235,12 +225,10 @@ extends TestCase
model.setDependencyManagement( depMgmt );
MavenProject project = new MavenProject( model );
// try
// {
new DefaultProjectDefaultsInjector().injectDefaults( project );
Dependency dependency = (Dependency) project.getDependencies().get( 0 );
new DefaultModelDefaultsInjector().injectDefaults( model );
Dependency dependency = (Dependency) model.getDependencies().get( 0 );
assertNull( "check version is null", dependency.getVersion() );
// fail("Should fail to validate dependency without a version.");
// }

View File

@ -18,10 +18,8 @@ package org.apache.maven.project.interpolation;
*/
import junit.framework.TestCase;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.project.MavenProject;
/**
* @author jdcasey
@ -33,7 +31,7 @@ public class RegexBasedProjectInterpolatorTest
{
public void testShouldInterpolateDependencyVersionToSetSameAsProjectVersion()
throws ProjectInterpolationException
throws ModelInterpolationException
{
Model model = new Model();
model.setVersion( "3.8.1" );
@ -43,14 +41,13 @@ public class RegexBasedProjectInterpolatorTest
model.addDependency( dep );
MavenProject in = new MavenProject( model );
MavenProject out = new RegexBasedProjectInterpolator().interpolate( in );
Model out = new RegexBasedModelInterpolator().interpolate( model );
assertEquals( "3.8.1", ((Dependency) out.getDependencies().get( 0 )).getVersion() );
}
public void testShouldNotInterpolateDependencyVersionWithInvalidReference()
throws ProjectInterpolationException
throws ModelInterpolationException
{
Model model = new Model();
model.setVersion( "3.8.1" );
@ -60,8 +57,7 @@ public class RegexBasedProjectInterpolatorTest
model.addDependency( dep );
MavenProject in = new MavenProject( model );
MavenProject out = new RegexBasedProjectInterpolator().interpolate( in );
Model out = new RegexBasedModelInterpolator().interpolate( model );
assertEquals( "#something", ((Dependency) out.getDependencies().get( 0 )).getVersion() );
}