Fixed interpolation in maven-mercury.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@768140 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Britton Isbell 2009-04-24 03:18:51 +00:00
parent 674acfb0d3
commit 5988d021d1
2 changed files with 64 additions and 50 deletions

View File

@ -21,6 +21,7 @@ package org.apache.maven.mercury;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -30,6 +31,7 @@ import org.apache.maven.mercury.builder.api.DependencyProcessorException;
import org.apache.maven.mercury.builder.api.MetadataReader;
import org.apache.maven.mercury.builder.api.MetadataReaderException;
import org.apache.maven.model.DomainModel;
import org.apache.maven.model.PomClassicDomainModel;
import org.apache.maven.model.ProcessorContext;
import org.apache.maven.model.interpolator.DefaultInterpolator;
import org.apache.maven.model.interpolator.InterpolatorProperty;
@ -68,7 +70,7 @@ public class MavenDependencyProcessor
List<InterpolatorProperty> interpolatorProperties = createInterpolatorProperties(system, user);
List<DomainModel> domainModels = new ArrayList<DomainModel>();
List<PomClassicDomainModel> domainModels = new ArrayList<PomClassicDomainModel>();
try
{
// MavenDomainModel superPom =
@ -93,7 +95,7 @@ public class MavenDependencyProcessor
domainModels.add( new MavenDomainModel( transformProfiles( mc.getProperties() ) ) );
}
*/
List<DomainModel> parentModels = getParentsOfDomainModel( domainModel, mdReader );
List<PomClassicDomainModel> parentModels = getParentsOfDomainModel( domainModel, mdReader );
if ( parentModels == null )
{
@ -107,11 +109,19 @@ public class MavenDependencyProcessor
throw new MetadataReaderException( "Failed to create domain model. Message = " + e.getMessage(), e );
}
List<DomainModel> iModels = new ArrayList<DomainModel>();
try {
return new MavenDomainModel(new DefaultInterpolator().interpolateDomainModel(ProcessorContext.build(domainModels, null),
interpolatorProperties)).getDependencyMetadata();
for(PomClassicDomainModel m : domainModels)
{
iModels.add(new DefaultInterpolator().interpolateDomainModel(m, interpolatorProperties));
}
iModels.get(0).setMostSpecialized(true);
return new MavenDomainModel(ProcessorContext.build(iModels, null)).getDependencyMetadata();
} catch (IOException e) {
throw new DependencyProcessorException();
throw new DependencyProcessorException(e);
}
}
@ -135,10 +145,10 @@ public class MavenDependencyProcessor
return interpolatorProperties;
}
protected final List<DomainModel> getParentsOfDomainModel( MavenDomainModel domainModel, MetadataReader mdReader )
protected final List<PomClassicDomainModel> getParentsOfDomainModel( MavenDomainModel domainModel, MetadataReader mdReader )
throws IOException, MetadataReaderException, DependencyProcessorException
{
List<DomainModel> domainModels = new ArrayList<DomainModel>();
List<PomClassicDomainModel> domainModels = new ArrayList<PomClassicDomainModel>();
if ( domainModel.hasParent() )
{
byte[] b = mdReader.readMetadata( domainModel.getParentMetadata() );

View File

@ -1,5 +1,6 @@
package org.apache.maven.mercury;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@ -43,9 +44,9 @@ public class MavenDependencyProcessorTest
File _remoteRepoFile;
static final String _remoteRepoUrlPrefix = "http://localhost:";
static String _remoteRepoUrlPrefix = "http://localhost:";
static final String _remoteRepoUrlSufix = "/maven2";
static String _remoteRepoUrlSufix = "/maven2";
// HttpTestServer _jetty;
@ -74,6 +75,11 @@ public class MavenDependencyProcessorTest
// _jetty.start();
// _port = _jetty.getPort();
// Server server = new Server( "testRemote", new URL(_remoteRepoUrlPrefix + _port + _remoteRepoUrlSufix) );
_remoteRepoUrlPrefix = "http://repo2.maven.org:";
_port = 80;
_remoteRepoUrlSufix = "/maven2";
Server server = new Server( "testRemote", new URL(_remoteRepoUrlPrefix + _port + _remoteRepoUrlSufix) );
_remoteRepo = new RemoteRepositoryM2( server, dp );
@ -112,12 +118,14 @@ public class MavenDependencyProcessorTest
/**
* Test method for {@link org.apache.maven.mercury.MavenDependencyProcessor#getDependencies(org.apache.maven.mercury.artifact.ArtifactMetadata, org.apache.maven.mercury.builder.api.MetadataReader, java.util.Map, java.util.Map)}.
*/
@Test
public void testMavenVersion()
throws Exception
{
RepositoryReader rr = _remoteRepo.getReader();
String gav = "org.apache.maven.plugins:maven-dependency-plugin:2.0";
// String gav = "org.apache.maven.plugins:maven-dependency-plugin:2.0";
String gav = "asm:asm-xml:3.0";
ArtifactMetadata bmd = new ArtifactMetadata( gav );
ArrayList<ArtifactMetadata> query = new ArrayList<ArtifactMetadata>(1);
@ -136,12 +144,8 @@ public class MavenDependencyProcessorTest
assertNotNull( deps );
assertFalse( deps.isEmpty() );
assertEquals("3.0", deps.get(0).getVersion());
System.out.println(deps);
for( ArtifactMetadata md : deps )
if( "${maven.version}".equals( md.getVersion() ) )
fail( "dependency has unresolved variable: "+md.toString() );
}
}