maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sisb...@apache.org
Subject svn commit: r674921 [1/2] - in /maven/sandbox/branches/SI_MAVEN_2_1: ./ maven-project/src/main/java/org/apache/maven/project/builder/ maven-project/src/main/java/org/apache/maven/project/builder/impl/
Date Tue, 08 Jul 2008 19:21:59 GMT
Author: sisbell
Date: Tue Jul  8 12:21:59 2008
New Revision: 674921

URL: http://svn.apache.org/viewvc?rev=674921&view=rev
Log:
Builder code.

Added:
    maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java
    maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/IdModelContainerFactory.java
    maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/PomArtifactResolver.java
    maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java
    maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java
    maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java
    maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/ProjectUri.java
    maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java
Modified:
    maven/sandbox/branches/SI_MAVEN_2_1/pom.xml

Added: maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java
URL: http://svn.apache.org/viewvc/maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java?rev=674921&view=auto
==============================================================================
--- maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java
(added)
+++ maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java
Tue Jul  8 12:21:59 2008
@@ -0,0 +1,117 @@
+package org.apache.maven.project.builder;
+
+import org.apache.maven.shared.model.*;
+
+import java.util.*;
+
+public final class ArtifactModelContainerFactory implements ModelContainerFactory {
+
+    private static final Collection<String> uris = Collections.unmodifiableList(Arrays.asList(
+
+            ProjectUri.DependencyManagement.Dependencies.Dependency.xUri,
+            ProjectUri.Dependencies.Dependency.xUri,
+
+       //     ProjectUri.Profiles.Profile.DependencyManagement.Dependencies.Dependency.xUri,
+       //     ProjectUri.Profiles.Profile.Dependencies.Dependency.xUri,
+           // ProjectUri.Profiles.Profile.Build.Plugins.Plugin.xUri,
+           // ProjectUri.Profiles.Profile.Build.PluginManagement.Plugins.Plugin.xUri,
+           // ProjectUri.Profiles.Profile.Build.PluginManagement.Plugins.Plugin.Dependencies.Dependency.xUri,
+
+
+            ProjectUri.Build.PluginManagement.Plugins.Plugin.xUri,
+            ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.Dependency.xUri,
+
+            ProjectUri.Build.Plugins.Plugin.xUri,
+            ProjectUri.Build.Plugins.Plugin.Dependencies.Dependency.xUri,
+            ProjectUri.Build.Plugins.Plugin.Dependencies.Dependency.Exclusions.Exclusion.xUri
+    ));
+
+    public Collection<String> getUris() {
+        return uris;
+    }
+
+    public ModelContainer create(List<ModelProperty> modelProperties) {
+        if (modelProperties == null || modelProperties.size() == 0) {
+            throw new IllegalArgumentException("modelProperties: null or empty");
+        }
+        return new ArtifactModelContainer(modelProperties);
+    }
+
+    private static class ArtifactModelContainer implements ModelContainer {
+
+        private String groupId;
+
+        private String artifactId;
+
+        private String version;
+
+        private List<ModelProperty> properties;
+
+        private ArtifactModelContainer(List<ModelProperty> properties) {
+            this.properties = new ArrayList<ModelProperty>(properties);
+            //Collections.sort(this.properties, new ModelPropertyComparator());
+            this.properties = Collections.unmodifiableList(this.properties);
+
+            for (ModelProperty mp : properties) {
+                if (mp.getUri().endsWith("version")) {
+                    this.version = mp.getValue();
+                } else if (mp.getUri().endsWith("artifactId")) {
+                    this.artifactId = mp.getValue();
+                } else if (mp.getUri().endsWith("groupId")) {
+                    this.groupId = mp.getValue();
+                }
+            }
+            if (groupId == null) {
+                groupId = "org.apache.maven.plugins";
+                //  throw new IllegalArgumentException("properties does not contain group
id. Artifact ID = "
+                //          + artifactId + ", Version = " + version);
+            }
+
+            if (artifactId == null) {
+                throw new IllegalArgumentException("properties does not contain artifact
id. Group ID = " + groupId +
+                        ", Version = " + version);
+            }
+        }
+
+        public ModelContainerAction containerAction(ModelContainer modelContainer) {
+            if (modelContainer == null) {
+                throw new IllegalArgumentException("modelContainer: null");
+            }
+
+            if (!(modelContainer instanceof ArtifactModelContainer)) {
+                throw new IllegalArgumentException("modelContainer: wrong type");
+            }
+
+            ArtifactModelContainer c = (ArtifactModelContainer) modelContainer;
+            if (c.groupId.equals(groupId) && c.artifactId.equals(artifactId)) {
+                if (c.version == null) {
+                    return ModelContainerAction.NOP;
+                }
+                return (c.version.equals(version)) ? ModelContainerAction.JOIN : ModelContainerAction.DELETE;
+            } else {
+                return ModelContainerAction.NOP;
+            }
+        }
+
+        public ModelContainer createNewInstance(List<ModelProperty> modelProperties)
{
+            return new ArtifactModelContainer(modelProperties);
+        }
+
+        public List<ModelProperty> getProperties() {
+            return properties;
+        }
+
+        public void sort(List<ModelProperty> modelProperties) {
+        }
+
+        public String toString() {
+            StringBuffer sb = new StringBuffer();
+            sb.append("Group ID = ").append(groupId).append(", Artifact ID = ").append(artifactId)
+                    .append(", Version").append(version).append("\r\n");
+            for(ModelProperty mp : properties) {
+                sb.append(mp).append("\r\n");
+            }
+            return sb.toString();
+        }
+    }
+}

Added: maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/IdModelContainerFactory.java
URL: http://svn.apache.org/viewvc/maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/IdModelContainerFactory.java?rev=674921&view=auto
==============================================================================
--- maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/IdModelContainerFactory.java
(added)
+++ maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/IdModelContainerFactory.java
Tue Jul  8 12:21:59 2008
@@ -0,0 +1,101 @@
+package org.apache.maven.project.builder;
+
+import org.apache.maven.shared.model.*;
+
+import java.util.*;
+
+public class IdModelContainerFactory implements ModelContainerFactory {
+
+    private static final Collection<String> uris = Collections.unmodifiableList(Arrays.asList(
+            //ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri,
+            //ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.xUri,
+            ProjectUri.PluginRepositories.PluginRepository.xUri,
+            ProjectUri.Repositories.Repository.xUri,
+            ProjectUri.Reporting.Plugins.Plugin.ReportSets.ReportSet.xUri,
+            ProjectUri.Profiles.Profile.xUri
+    ));
+
+    public Collection<String> getUris() {
+        return uris;
+    }
+
+    public ModelContainer create(List<ModelProperty> modelProperties) {
+        if (modelProperties == null || modelProperties.size() == 0) {
+            throw new IllegalArgumentException("modelProperties: null or empty");
+        }
+        return new IdModelContainer(modelProperties);
+    }
+
+    private static class IdModelContainer implements ModelContainer {
+
+        private String id;
+
+        private List<ModelProperty> properties;
+
+        private IdModelContainer(List<ModelProperty> properties) {
+            this.properties = new ArrayList<ModelProperty>(properties);
+            this.properties = Collections.unmodifiableList(this.properties);
+
+            for (ModelProperty mp : properties) {
+                if (mp.getUri().endsWith("/id")) {
+                    this.id = mp.getValue();
+                }
+            }
+
+            //   if (id == null) {
+            //       throw new IllegalArgumentException("properties does not contain id");
+            //   }
+        }
+
+        public ModelContainerAction containerAction(ModelContainer modelContainer) {
+            if (modelContainer == null) {
+                throw new IllegalArgumentException("modelContainer: null");
+            }
+
+            if (!(modelContainer instanceof IdModelContainer)) {
+                throw new IllegalArgumentException("modelContainer: wrong type");
+            }
+
+            IdModelContainer c = (IdModelContainer) modelContainer;
+            if (c.id == null || id == null) {
+                return ModelContainerAction.NOP;
+            }
+            return (c.id.equals(id)) ? ModelContainerAction.JOIN : ModelContainerAction.NOP;
+        }
+
+        public ModelContainer createNewInstance(List<ModelProperty> modelProperties)
{
+            return new IdModelContainer(modelProperties);
+        }
+
+        public void sort(List<ModelProperty> modelProperties) {
+            //Collections.sort(modelProperties, new IdModelComparator());
+         /*   System.out.println("END SORT");
+            for(ModelProperty mp : modelProperties) {
+                System.out.println(mp);
+            }
+            */
+        }
+
+        public List<ModelProperty> getProperties() {
+            return properties;
+        }
+
+        public String toString() {
+            return "ID = " + id;
+        }
+    }
+
+    private static class IdModelComparator implements Comparator {
+        public int compare(Object o1, Object o2) {
+            ModelProperty a = (ModelProperty) o1;
+            ModelProperty b = (ModelProperty) o2;
+            System.out.println(a + " : " + b);
+            if (a.isParentOf(b)) {
+                System.out.println("IS PARENT ABOVE:");
+                return -1;
+            }
+
+            return 0;
+        }
+    }
+}

Added: maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/PomArtifactResolver.java
URL: http://svn.apache.org/viewvc/maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/PomArtifactResolver.java?rev=674921&view=auto
==============================================================================
--- maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/PomArtifactResolver.java
(added)
+++ maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/PomArtifactResolver.java
Tue Jul  8 12:21:59 2008
@@ -0,0 +1,54 @@
+package org.apache.maven.project.builder;
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
+import org.apache.maven.artifact.ArtifactStatus;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+
+import java.util.List;
+import java.util.Date;
+import java.io.IOException;
+import java.io.File;
+
+public class PomArtifactResolver {
+
+    private ArtifactRepository localRepository;
+
+    private List<ArtifactRepository> remoteRepositories;
+
+    private ArtifactResolver resolver;
+
+    public PomArtifactResolver(ArtifactRepository localRepository, List<ArtifactRepository>
remoteRepositories, ArtifactResolver resolver) {
+        this.localRepository = localRepository;
+        this.remoteRepositories = remoteRepositories;
+        this.resolver = resolver;
+    }
+
+    /**
+     * State change: sets file.
+     *
+     * @param artifact
+     */
+    public void resolve(Artifact artifact) throws IOException {
+        File artifactFile = new File(localRepository.getBasedir(), localRepository.pathOf(artifact));
+        artifact.setFile(artifactFile);
+
+        if (!artifact.isSnapshot() && (ArtifactStatus.NONE.compareTo(ArtifactStatus.DEPLOYED)
< 0)) {
+            ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy();
+            policy.setUpdatePolicy(ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER);
+            try {
+                if (policy.checkOutOfDate(new Date(artifact.getFile().lastModified()))) {
+                    artifact.setResolved(false);
+                    resolver.resolveAlways(artifact, remoteRepositories, localRepository);
+                }
+            } catch (ArtifactNotFoundException e) {
+                throw new IOException("Parent pom not found: File = " + artifactFile.getAbsolutePath(),
e);
+            } catch (ArtifactResolutionException e) {
+                throw new IOException("Parent pom not found: File = " + artifactFile.getAbsolutePath(),
e);
+            }
+        }
+    }
+}

Added: maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java
URL: http://svn.apache.org/viewvc/maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java?rev=674921&view=auto
==============================================================================
--- maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java
(added)
+++ maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java
Tue Jul  8 12:21:59 2008
@@ -0,0 +1,92 @@
+package org.apache.maven.project.builder;
+
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Parent;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
+import org.apache.maven.shared.model.InputStreamDomainModel;
+import org.apache.maven.artifact.Artifact;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+
+import java.io.*;
+import java.util.Arrays;
+
+/**
+ * Provides a wrapper for the maven model.
+ */
+public final class PomClassicDomainModel implements InputStreamDomainModel {
+
+    private byte[] inputStream;
+
+    private String eventHistory;
+
+    /**
+     * Constructor
+     *
+     * @param model maven model
+     */
+    public PomClassicDomainModel(Model model) throws IOException {
+        if (model == null) {
+            throw new IllegalArgumentException("model: null");
+        }
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        MavenXpp3Writer writer = new MavenXpp3Writer();
+        writer.write(new OutputStreamWriter(baos), model);
+        inputStream = removeIllegalCharacters(baos.toByteArray());
+    }
+
+    public PomClassicDomainModel(InputStream inputStream) throws IOException {
+        if (inputStream == null) {
+            throw new IllegalArgumentException("inputStream: null");
+        }
+        this.inputStream = removeIllegalCharacters(IOUtil.toByteArray(inputStream));
+    }
+
+    //TODO: Workaround
+    private byte[] removeIllegalCharacters(byte[] bytes) {
+        return new String(bytes).replaceAll("&oslash;", "").getBytes();
+    }
+
+    public boolean matchesParent(Parent parent) {
+        Model model;
+        try {
+            model = getModel();
+        } catch (IOException e) {
+            return false;
+        }
+        return (parent.getGroupId().equals(model.getGroupId()) && parent.getArtifactId().equals(model.getArtifactId())
+                && parent.getVersion().equals(model.getVersion()));
+    }
+
+    public String asString() {
+        return new String(inputStream);
+    }
+
+    /**
+     * Returns maven model
+     *
+     * @return maven model
+     */
+    public Model getModel() throws IOException {
+        try {                                                                
+            return new MavenXpp3Reader().read(new StringReader(new String(inputStream)));
+        }
+        catch (XmlPullParserException e) {
+            throw new IOException(e);
+        }
+    }
+
+    public InputStream getInputStream() {
+        return new ByteArrayInputStream(Arrays.copyOf(inputStream, inputStream.length));
+    }
+
+    public String getEventHistory() {
+        return eventHistory;
+    }
+
+    public void setEventHistory(String eventHistory) {
+        this.eventHistory = eventHistory;
+    }
+}

Added: maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java
URL: http://svn.apache.org/viewvc/maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java?rev=674921&view=auto
==============================================================================
--- maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java
(added)
+++ maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java
Tue Jul  8 12:21:59 2008
@@ -0,0 +1,180 @@
+package org.apache.maven.project.builder;
+
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+
+import org.apache.maven.shared.model.*;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.*;
+
+/**
+ * Provides methods for transforming model properties into a domain model for the pom classic
format and vice versa.
+ */
+public final class PomClassicTransformer implements ModelTransformer {
+
+    private Set<String> uris;
+
+    public PomClassicTransformer() {
+
+    }
+
+    public String getBaseUri() {
+        return ProjectUri.baseUri;
+    }
+
+    public PomClassicTransformer(Set<String> uris) {
+        this.uris = new HashSet<String>(Arrays.asList(
+                "http://apache.org/maven/project/build/resources#collection",
+                "http://apache.org/maven/project/build/plugins/plugin/dependencies/dependency/exclusions#collection",
+                "http://apache.org/maven/project/profiles/profile/build/pluginManagement/plugins#collection",
+                "http://apache.org/maven/project/profiles/profile/build/plugins/plugin/dependencies/dependency/exclusions#collection",
+                "http://apache.org/maven/project/profiles/profile/reporting/plugins#collection",
+                "http://apache.org/maven/project/dependencyManagement/dependencies/dependency/exclusions#collection",
+                "http://apache.org/maven/project/profiles/profile/build/testResources#collection",
+                "http://apache.org/maven/project/reporting/plugins/plugin/reportSets#collection",
+                "http://apache.org/maven/project/pluginRepositories#collection",
+                "http://apache.org/maven/project/profiles/profile/build/pluginManagement/plugins/plugin/dependencies#collection",
+                "http://apache.org/maven/project/profiles/profile/build/resources#collection",
+                "http://apache.org/maven/project/profiles/profile/build/pluginManagement/plugins/plugin/dependencies/dependency/exclusions#collection",
+                "http://apache.org/maven/project/licenses#collection",
+                "http://apache.org/maven/project/build/plugins/plugin/dependencies#collection",
+                "http://apache.org/maven/project/profiles/profile/dependencyManagement/dependencies/dependency/exclusions#collection",
+                "http://apache.org/maven/project/dependencies/dependency/exclusions#collection",
+                "http://apache.org/maven/project/profiles/profile/build/plugins/plugin/dependencies#collection",
+                "http://apache.org/maven/project/build/testResources#collection",
+                "http://apache.org/maven/project/profiles/profile/pluginRepositories#collection",
+                "http://apache.org/maven/project/build/pluginManagement/plugins#collection",
+                "http://apache.org/maven/project/profiles#collection",
+                "http://apache.org/maven/project/reporting/plugins#collection",
+                "http://apache.org/maven/project/build/pluginManagement/plugins/plugin/dependencies/dependency/exclusions#collection",
+                "http://apache.org/maven/project/build/pluginManagement/plugins/plugin/executions#collection",
+                "http://apache.org/maven/project/profiles/profile/dependencies/dependency/exclusions#collection",
+                "http://apache.org/maven/project/dependencies#collection",
+                "http://apache.org/maven/project/contributors#collection",
+                "http://apache.org/maven/project/developers#collection",
+                "http://apache.org/maven/project/build/plugins#collection",
+                "http://apache.org/maven/project/profiles/profile/build/pluginManagement/plugins/plugin/executions#collection",
+                "http://apache.org/maven/project/profiles/profile/dependencies#collection",
+                "http://apache.org/maven/project/mailingLists#collection",
+                "http://apache.org/maven/project/profiles/profile/dependencyManagement/dependencies#collection",
+                "http://apache.org/maven/project/profiles/profile/repositories#collection",
+                "http://apache.org/maven/project/build/extensions#collection",
+                "http://apache.org/maven/project/build/plugins/plugin/executions#collection",
+                "http://apache.org/maven/project/repositories#collection",
+                "http://apache.org/maven/project/ciManagement/notifiers#collection",
+                "http://apache.org/maven/project/dependencyManagement/dependencies#collection",
+                "http://apache.org/maven/project/build/pluginManagement/plugins/plugin/dependencies#collection",
+                "http://apache.org/maven/project/profiles/profile/reporting/plugins/plugin/reportSets#collection",
+                "http://apache.org/maven/project/profiles/profile/build/plugins#collection",
+                "http://apache.org/maven/project/profiles/profile/build/plugins/plugin/executions#collection",
+                "http://apache.org/maven/project/modules#collection"
+        ));
+    }
+
+    public DomainModel transformToDomainModel(List<ModelProperty> properties) throws
IOException {
+        if (properties == null) {
+            throw new IllegalArgumentException("properties: null");
+        }
+        String xml = null;
+        try {
+            xml = ModelMarshaller.unmarshalModelPropertiesToXml(properties, ProjectUri.baseUri);
+            return new PomClassicDomainModel(new MavenXpp3Reader().read(new StringReader(xml)));
+        } catch (XmlPullParserException e) {
+            /*
+            StringBuffer sb = new StringBuffer("\r\n");
+            for (ModelProperty mp : properties) {
+                sb.append(mp).append("\r\n");
+            }
+            */
+            throw new IOException(e + ":\r\n" + xml);
+        }
+    }
+
+    public List<ModelProperty> transformToModelProperties(List<DomainModel> domainModels)
throws IOException {
+        if (domainModels == null || domainModels.isEmpty()) {
+            throw new IllegalArgumentException("domainModels: null or empty");
+        }
+
+        List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
+        List<String> projectNames = new ArrayList<String>();
+        StringBuffer scmUrl = new StringBuffer();
+
+        for (DomainModel domainModel : domainModels) {
+            if (!(domainModel instanceof PomClassicDomainModel)) {
+                throw new IllegalArgumentException("domainModels: Invalid domain model");
+            }
+
+            List<ModelProperty> tmp = ModelMarshaller.marshallXmlToModelProperties(
+                    ((PomClassicDomainModel) domainModel).getInputStream(), ProjectUri.baseUri,
uris);
+
+            //Missing Version Rule
+            if (getPropertyFor(ProjectUri.version, tmp) == null) {
+                ModelProperty parentVersion = getPropertyFor(ProjectUri.Parent.version, tmp);
+                tmp.add(new ModelProperty(ProjectUri.version, parentVersion.getValue()));
+            }
+
+            //Modules Not Inherited Rule
+            if (domainModels.indexOf(domainModel) != 0) {
+                ModelProperty modulesProperty = getPropertyFor(ProjectUri.Modules.xUri, tmp);
+                if(modulesProperty != null) {
+                    tmp.remove(modulesProperty);
+                    tmp.removeAll(getPropertiesFor(ProjectUri.Modules.module, tmp));
+                }
+            }
+
+            //Missing groupId, use parent one Rule
+            if (getPropertyFor(ProjectUri.groupId, tmp) == null) {
+                ModelProperty parentGroupId = getPropertyFor(ProjectUri.Parent.groupId, tmp);
+                tmp.add(new ModelProperty(ProjectUri.groupId, parentGroupId.getValue()));
+            }
+
+
+            //SCM Rule
+            ModelProperty scmUrlProperty = getPropertyFor(ProjectUri.Scm.url, tmp);
+            if (scmUrl.length() == 0 && scmUrlProperty != null) {
+                scmUrl.append(scmUrlProperty.getValue());
+                for (String projectName : projectNames) {
+                    scmUrl.append("/").append(projectName);
+                }
+                int index = tmp.indexOf(scmUrlProperty);
+                tmp.remove(index);
+                tmp.add(index, new ModelProperty(ProjectUri.Scm.url, scmUrl.toString()));
+            }
+            projectNames.add(0, getPropertyFor(ProjectUri.artifactId, tmp).getValue());
+
+            modelProperties.addAll(tmp);
+
+            //Remove Parent Info
+            for(ModelProperty mp : tmp) {
+                if(mp.getUri().startsWith(ProjectUri.Parent.xUri)) {
+                    modelProperties.remove(mp);
+                }
+            }
+        }
+        return modelProperties;
+    }
+
+    private static List<ModelProperty> getPropertiesFor(String uri, List<ModelProperty>
properties) {
+        List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
+        for (ModelProperty mp : properties) {
+            if (uri.equals(mp.getUri())) {
+                modelProperties.add(mp);
+            }
+        }
+        return modelProperties;
+    }
+
+    private static ModelProperty getPropertyFor(String uri, List<ModelProperty> properties)
{
+        for (ModelProperty mp : properties) {
+            if (uri.equals(mp.getUri())) {
+                return mp;
+            }
+        }
+        return null;
+    }
+
+
+}
+

Added: maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java
URL: http://svn.apache.org/viewvc/maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java?rev=674921&view=auto
==============================================================================
--- maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java
(added)
+++ maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java
Tue Jul  8 12:21:59 2008
@@ -0,0 +1,24 @@
+package org.apache.maven.project.builder;
+
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.shared.model.InterpolatorProperty;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.Artifact;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.File;
+import java.util.Collection;
+
+public interface ProjectBuilder {
+
+    String ROLE = ProjectBuilder.class.getName();
+
+    MavenProject buildFromArtifact(Artifact artifact, Collection<InterpolatorProperty>
interpolatorProperties,
+                                   PomArtifactResolver resolver)
+            throws IOException;
+
+    MavenProject buildFromStream(InputStream pom, Collection<InterpolatorProperty>
interpolatorProperties,
+                                 PomArtifactResolver resolver, File projectDirectory)
+            throws IOException;
+}



Mime
View raw message