diff --git a/maven-mercury/maven-mercury.iml b/maven-mercury/maven-mercury.iml
new file mode 100644
index 0000000000..987fc02f5f
--- /dev/null
+++ b/maven-mercury/maven-mercury.iml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/maven-mercury/pom.xml b/maven-mercury/pom.xml
new file mode 100755
index 0000000000..d59cfa0b56
--- /dev/null
+++ b/maven-mercury/pom.xml
@@ -0,0 +1,53 @@
+
+
+
+
+
+
+ maven
+ org.apache.maven
+ 3.0-SNAPSHOT
+
+ 4.0.0
+ maven-mercury
+ Maven Mercury
+
+
+ org.apache.maven.mercury
+ mercury-artifact
+
+
+ org.apache.maven.mercury
+ mercury-external
+
+
+ org.apache.maven
+ maven-project-builder
+ 3.0-SNAPSHOT
+
+
+ junit
+ junit
+ 4.4
+ test
+
+
+
diff --git a/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor.java b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor.java
new file mode 100755
index 0000000000..9dd095144c
--- /dev/null
+++ b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor.java
@@ -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 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 interpolatorProperties = new ArrayList();
+ 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 domainModels = new ArrayList();
+ 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 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 getParentsOfDomainModel(MavenDomainModel domainModel, MetadataReader mdReader)
+ throws IOException, MetadataReaderException {
+ List domainModels = new ArrayList();
+ if (domainModel.hasParent()) {
+ MavenDomainModel parentDomainModel = new MavenDomainModel(mdReader.readMetadata(domainModel.getParentMetadata()));
+ domainModels.add(parentDomainModel);
+ domainModels.addAll(getParentsOfDomainModel(parentDomainModel, mdReader));
+ }
+ return domainModels;
+ }
+
+ private static List transformProfiles(List modelProperties) {
+ List properties = new ArrayList();
+ 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;
+ }
+}
diff --git a/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModel.java b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModel.java
new file mode 100755
index 0000000000..2288d4befa
--- /dev/null
+++ b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModel.java
@@ -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 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 modelProperties)
+ throws IOException {
+ if (modelProperties == null) {
+ throw new IllegalArgumentException("modelProperties: null");
+ }
+
+ this.modelProperties = new ArrayList(modelProperties);
+ }
+
+ public boolean hasParent() {
+ //TODO: Expensive call if no parent
+ return getParentMetadata() != null;
+ }
+
+ public List getDependencyMetadata() throws DataSourceException {
+ List metadatas = new ArrayList();
+
+ 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 getActiveProfileContainers(List 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 getModelProperties() {
+ return new ArrayList(modelProperties);
+ }
+
+ private ArtifactBasicMetadata transformContainerToMetadata( ModelContainer container ) throws DataSourceException
+ {
+ List 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 exclusions = new ArrayList();
+
+ 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;
+ }
+}
diff --git a/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModelFactory.java b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModelFactory.java
new file mode 100644
index 0000000000..10dbcecb7f
--- /dev/null
+++ b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModelFactory.java
@@ -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 modelProperties) throws IOException {
+ return new MavenDomainModel(modelProperties);
+ }
+}
diff --git a/maven-mercury/src/main/resources/org/apache/maven/project/pom-4.0.0.xml b/maven-mercury/src/main/resources/org/apache/maven/project/pom-4.0.0.xml
new file mode 100644
index 0000000000..990b674061
--- /dev/null
+++ b/maven-mercury/src/main/resources/org/apache/maven/project/pom-4.0.0.xml
@@ -0,0 +1,156 @@
+
+
+
+
+ 4.0.0
+ Maven Default Project
+
+
+
+ central
+ Maven Repository Switchboard
+ default
+ http://repo1.maven.org/maven2
+
+ false
+
+
+
+
+
+
+ central
+ Maven Plugin Repository
+ http://repo1.maven.org/maven2
+ default
+
+ false
+
+
+ never
+
+
+
+
+
+ ${project.basedir}/target
+ ${project.build.directory}/classes
+ ${project.artifactId}-${project.version}
+ ${project.build.directory}/test-classes
+ ${project.basedir}/src/main/java
+ src/main/scripts
+ ${project.basedir}/src/test/java
+
+
+ ${project.basedir}/src/main/resources
+
+
+
+
+ ${project.basedir}/src/test/resources
+
+
+
+
+
+ maven-antrun-plugin
+ 1.1
+
+
+ maven-assembly-plugin
+ 2.2-beta-1
+
+
+ maven-clean-plugin
+ 2.2
+
+
+ maven-compiler-plugin
+ 2.0.2
+
+
+ maven-dependency-plugin
+ 2.0
+
+
+ maven-deploy-plugin
+ 2.3
+
+
+ maven-ear-plugin
+ 2.3.1
+
+
+ maven-ejb-plugin
+ 2.1
+
+
+ maven-install-plugin
+ 2.2
+
+
+ maven-jar-plugin
+ 2.2
+
+
+ maven-javadoc-plugin
+ 2.4
+
+
+ maven-plugin-plugin
+ 2.4.2
+
+
+ maven-rar-plugin
+ 2.2
+
+
+ maven-release-plugin
+ 2.0-beta-7
+
+
+ maven-resources-plugin
+ 2.2
+
+
+ maven-site-plugin
+ 2.0-beta-7
+
+
+ maven-source-plugin
+ 2.0.4
+
+
+ maven-surefire-plugin
+ 2.4.3
+
+
+ maven-war-plugin
+ 2.1-alpha-1
+
+
+
+
+
+
+ ${project.build.directory}/site
+
+
+