Import of maven mercury project.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@719473 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Britton Isbell 2008-11-21 04:50:50 +00:00
parent c26b2d69cd
commit 1f9bf0c917
6 changed files with 589 additions and 0 deletions

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<module relativePaths="true" MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="maven-shared-model" />
<orderEntry type="module" module-name="maven-project-builder" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/maven/mercury/mercury-external/1.0.0-alpha-2-SNAPSHOT/mercury-external-1.0.0-alpha-2-SNAPSHOT.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/maven/mercury/mercury-artifact/1.0.0-alpha-2-SNAPSHOT/mercury-artifact-1.0.0-alpha-2-SNAPSHOT.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

53
maven-mercury/pom.xml Executable file
View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>maven</artifactId>
<groupId>org.apache.maven</groupId>
<version>3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-mercury</artifactId>
<name>Maven Mercury</name>
<dependencies>
<dependency>
<groupId>org.apache.maven.mercury</groupId>
<artifactId>mercury-artifact</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.mercury</groupId>
<artifactId>mercury-external</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project-builder</artifactId>
<version>3.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,110 @@
package org.apache.maven.mercury;
import java.io.IOException;
import java.util.*;
import org.apache.maven.mercury.artifact.ArtifactBasicMetadata;
import org.apache.maven.mercury.builder.api.DependencyProcessor;
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.project.builder.*;
import org.apache.maven.shared.model.*;
public final class MavenDependencyProcessor implements DependencyProcessor {
public MavenDependencyProcessor() {
}
public List<ArtifactBasicMetadata> getDependencies(ArtifactBasicMetadata bmd, MetadataReader mdReader, Map system, Map user)
throws MetadataReaderException, DependencyProcessorException
{
if (bmd == null) {
throw new IllegalArgumentException("bmd: null");
}
if (mdReader == null) {
throw new IllegalArgumentException("mdReader: null");
}
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
interpolatorProperties.add(new InterpolatorProperty("${mavenVersion}", "3.0-SNAPSHOT", PomInterpolatorTag.SYSTEM_PROPERTIES.name()));
interpolatorProperties.add(new InterpolatorProperty("${maven.version}", "3.0-SNAPSHOT", PomInterpolatorTag.SYSTEM_PROPERTIES.name()));
if(system != null) {
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( system,
PomInterpolatorTag.SYSTEM_PROPERTIES.name()));
}
if(user != null) {
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( user,
PomInterpolatorTag.USER_PROPERTIES.name()));
}
List<DomainModel> domainModels = new ArrayList<DomainModel>();
try {
// MavenDomainModel superPom =
// new MavenDomainModel(MavenDependencyProcessor.class.getResourceAsStream( "pom-4.0.0.xml" ));
// domainModels.add(superPom);
byte [] superBytes = mdReader.readMetadata( bmd );
if( superBytes == null || superBytes.length < 1 )
throw new DependencyProcessorException("cannot read metadata for " + bmd.getGAV() );
MavenDomainModel domainModel = new MavenDomainModel( superBytes );
domainModels.add(domainModel);
Collection<ModelContainer> activeProfiles = domainModel.getActiveProfileContainers(interpolatorProperties);
for(ModelContainer mc : activeProfiles) {
domainModels.add(new MavenDomainModel(transformProfiles(mc.getProperties())));
}
domainModels.addAll(getParentsOfDomainModel(domainModel, mdReader));
} catch (IOException e) {
throw new MetadataReaderException("Failed to create domain model. Message = " + e.getMessage());
}
PomTransformer transformer = new PomTransformer(new MavenDomainModelFactory());
ModelTransformerContext ctx = new ModelTransformerContext(
Arrays.asList(new ArtifactModelContainerFactory(), new IdModelContainerFactory()));
try {
MavenDomainModel model = ((MavenDomainModel) ctx.transform(domainModels,
transformer,
transformer,
null,
interpolatorProperties,
null));
return model.getDependencyMetadata();
} catch (IOException e) {
throw new MetadataReaderException("Unable to transform model");
}
}
private static List<DomainModel> getParentsOfDomainModel(MavenDomainModel domainModel, MetadataReader mdReader)
throws IOException, MetadataReaderException {
List<DomainModel> domainModels = new ArrayList<DomainModel>();
if (domainModel.hasParent()) {
MavenDomainModel parentDomainModel = new MavenDomainModel(mdReader.readMetadata(domainModel.getParentMetadata()));
domainModels.add(parentDomainModel);
domainModels.addAll(getParentsOfDomainModel(parentDomainModel, mdReader));
}
return domainModels;
}
private static List<ModelProperty> transformProfiles(List<ModelProperty> modelProperties) {
List<ModelProperty> properties = new ArrayList<ModelProperty>();
for(ModelProperty mp : modelProperties) {
if(mp.getUri().startsWith(ProjectUri.Profiles.Profile.xUri)
&& !mp.getUri().equals(ProjectUri.Profiles.Profile.id)
&& !mp.getUri().startsWith(ProjectUri.Profiles.Profile.Activation.xUri)) {
properties.add(new ModelProperty(mp.getUri().replace( ProjectUri.Profiles.Profile.xUri, ProjectUri.xUri ),
mp.getResolvedValue() ));
}
}
return properties;
}
}

View File

@ -0,0 +1,220 @@
package org.apache.maven.mercury;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.shared.model.*;
import org.apache.maven.shared.model.impl.DefaultModelDataSource;
import org.apache.maven.project.builder.*;
import org.apache.maven.project.builder.profile.ProfileContext;
import org.apache.maven.mercury.artifact.ArtifactBasicMetadata;
import java.io.IOException;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
/**
* Provides a wrapper for the maven model.
*/
public final class MavenDomainModel implements DomainModel {
/**
* Bytes containing the underlying model
*/
private final List<ModelProperty> modelProperties;
/**
* History of joins and deletes of model properties
*/
private String eventHistory;
private ArtifactBasicMetadata parentMetadata;
/**
* Constructor
*
* @throws IOException if there is a problem constructing the model
*/
public MavenDomainModel( byte[] bytes )
throws IOException
{
this( new ByteArrayInputStream(bytes) );
}
/**
* Constructor
*
* @throws IOException if there is a problem constructing the model
*/
public MavenDomainModel(InputStream inputStream)
throws IOException {
this(ModelMarshaller.marshallXmlToModelProperties(inputStream, ProjectUri.baseUri, PomTransformer.URIS));
}
/**
* Constructor
*
* @throws IOException if there is a problem constructing the model
*/
public MavenDomainModel(List<ModelProperty> modelProperties)
throws IOException {
if (modelProperties == null) {
throw new IllegalArgumentException("modelProperties: null");
}
this.modelProperties = new ArrayList<ModelProperty>(modelProperties);
}
public boolean hasParent() {
//TODO: Expensive call if no parent
return getParentMetadata() != null;
}
public List<ArtifactBasicMetadata> getDependencyMetadata() throws DataSourceException {
List<ArtifactBasicMetadata> metadatas = new ArrayList<ArtifactBasicMetadata>();
ModelDataSource source = new DefaultModelDataSource();
source.init(modelProperties, Arrays.asList(new ArtifactModelContainerFactory(), new IdModelContainerFactory()));
for(ModelContainer modelContainer: source.queryFor(ProjectUri.Dependencies.Dependency.xUri)) {
metadatas.add(transformContainerToMetadata(modelContainer));
}
return metadatas;
}
public Collection<ModelContainer> getActiveProfileContainers(List<InterpolatorProperty> properties) throws DataSourceException {
ModelDataSource dataSource = new DefaultModelDataSource();
dataSource.init(modelProperties, Arrays.asList( new ArtifactModelContainerFactory(), new IdModelContainerFactory() ) );
return new ProfileContext(dataSource, properties).getActiveProfiles();
}
public ArtifactBasicMetadata getParentMetadata() {
if (parentMetadata != null) {
return copyArtifactBasicMetadata(parentMetadata);
}
String groupId = null, artifactId = null, version = null;
for (ModelProperty mp : modelProperties) {
if (mp.getUri().equals(ProjectUri.Parent.version)) {
version = mp.getValue();
} else if (mp.getUri().equals(ProjectUri.Parent.artifactId)) {
artifactId = mp.getValue();
} else if (mp.getUri().equals(ProjectUri.Parent.groupId)) {
groupId = mp.getValue();
}
if (groupId != null && artifactId != null && version != null) {
break;
}
}
if (groupId == null || artifactId == null || version == null) {
return null;
}
parentMetadata = new ArtifactBasicMetadata();
parentMetadata.setArtifactId(artifactId);
parentMetadata.setVersion(version);
parentMetadata.setGroupId(groupId);
return copyArtifactBasicMetadata(parentMetadata);
}
private ArtifactBasicMetadata copyArtifactBasicMetadata(ArtifactBasicMetadata metadata) {
ArtifactBasicMetadata amd = new ArtifactBasicMetadata();
amd.setArtifactId(metadata.getArtifactId());
amd.setGroupId(metadata.getGroupId());
amd.setVersion(metadata.getVersion());
return amd;
}
/**
* @see org.apache.maven.shared.model.DomainModel#getEventHistory()
*/
public String getEventHistory() {
return eventHistory;
}
/**
* @see org.apache.maven.shared.model.DomainModel#setEventHistory(String)
*/
public void setEventHistory(String eventHistory) {
if (eventHistory == null) {
throw new IllegalArgumentException("eventHistory: null");
}
this.eventHistory = eventHistory;
}
public List<ModelProperty> getModelProperties() {
return new ArrayList<ModelProperty>(modelProperties);
}
private ArtifactBasicMetadata transformContainerToMetadata( ModelContainer container ) throws DataSourceException
{
List<ModelProperty> modelProperties = container.getProperties();
ArtifactBasicMetadata metadata = new ArtifactBasicMetadata();
for ( ModelProperty mp : modelProperties )
{
if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.groupId)) {
metadata.setGroupId(mp.getValue());
} else if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.artifactId)) {
metadata.setArtifactId(mp.getValue());
} else if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.version)) {
metadata.setVersion(mp.getValue());
} else if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.classifier)) {
metadata.setClassifier(mp.getValue());
} else if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.scope)) {
metadata.setScope(mp.getValue());
} else if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.type)) {
metadata.setType(mp.getValue());
} else if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.optional)) {
metadata.setOptional(mp.getValue());
}
}
if(metadata.getScope() == null) {
metadata.setScope("runtime");
}
ModelDataSource dataSource = new DefaultModelDataSource();
dataSource.init(container.getProperties(), Arrays.asList(new ArtifactModelContainerFactory(), new ExclusionModelContainerFactory()) );
List<ArtifactBasicMetadata> exclusions = new ArrayList<ArtifactBasicMetadata>();
for(ModelContainer exclusion : dataSource.queryFor(ProjectUri.Dependencies.Dependency.Exclusions.Exclusion.xUri)) {
ArtifactBasicMetadata meta = new ArtifactBasicMetadata();
exclusions.add(meta);
for(ModelProperty mp : exclusion.getProperties()) {
if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.Exclusions.Exclusion.artifactId)) {
meta.setArtifactId(mp.getValue());
} else if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.Exclusions.Exclusion.groupId)) {
meta.setGroupId(mp.getValue());
}
}
}
metadata.setExclusions(exclusions);
return metadata;
}
}

View File

@ -0,0 +1,15 @@
package org.apache.maven.mercury;
import org.apache.maven.shared.model.DomainModelFactory;
import org.apache.maven.shared.model.DomainModel;
import org.apache.maven.shared.model.ModelProperty;
import java.util.List;
import java.io.IOException;
public class MavenDomainModelFactory implements DomainModelFactory {
public DomainModel createDomainModel(List<ModelProperty> modelProperties) throws IOException {
return new MavenDomainModel(modelProperties);
}
}

View File

@ -0,0 +1,156 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!-- START SNIPPET: superpom -->
<project>
<modelVersion>4.0.0</modelVersion>
<name>Maven Default Project</name>
<repositories>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Maven Plugin Repository</name>
<url>http://repo1.maven.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
<build>
<directory>${project.basedir}/target</directory>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<finalName>${project.artifactId}-${project.version}</finalName>
<testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-1</version>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.0</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.3</version>
</plugin>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.3.1</version>
</plugin>
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.1</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<version>2.4.2</version>
</plugin>
<plugin>
<artifactId>maven-rar-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.0-beta-7</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>2.0-beta-7</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.0.4</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.3</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-alpha-1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<reporting>
<outputDirectory>${project.build.directory}/site</outputDirectory>
</reporting>
</project>
<!-- END SNIPPET: superpom -->