maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sisb...@apache.org
Subject svn commit: r672338 [1/3] - in /maven/sandbox/branches/maven-2.1: ./ maven-project/ maven-project/src/main/java/org/apache/maven/project/ maven-project/src/main/java/org/apache/maven/project/artifact/ maven-project/src/main/java/org/apache/maven/projec...
Date Fri, 27 Jun 2008 17:35:03 GMT
Author: sisbell
Date: Fri Jun 27 10:35:03 2008
New Revision: 672338

URL: http://svn.apache.org/viewvc?rev=672338&view=rev
Log:
Initial import of builder code.

Added:
    maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/
    maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java
    maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/IdModelContainerFactory.java
    maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/PomArtifactResolver.java
    maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java
    maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java
    maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java
    maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/ProjectUri.java
    maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/impl/
    maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java
Modified:
    maven/sandbox/branches/maven-2.1/maven-project/pom.xml
    maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
    maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
    maven/sandbox/branches/maven-2.1/maven-project/src/main/resources/META-INF/plexus/components.xml
    maven/sandbox/branches/maven-2.1/pom.xml

Modified: maven/sandbox/branches/maven-2.1/maven-project/pom.xml
URL: http://svn.apache.org/viewvc/maven/sandbox/branches/maven-2.1/maven-project/pom.xml?rev=672338&r1=672337&r2=672338&view=diff
==============================================================================
--- maven/sandbox/branches/maven-2.1/maven-project/pom.xml (original)
+++ maven/sandbox/branches/maven-2.1/maven-project/pom.xml Fri Jun 27 10:35:03 2008
@@ -21,70 +21,87 @@
 
 <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>2.1-SNAPSHOT</version>
-  </parent>
-  <modelVersion>4.0.0</modelVersion>
-  <artifactId>maven-project</artifactId>
-  <name>Maven Project Builder</name>
-  <description>This library is used to not only read Maven project object model files,
but to assemble inheritence
-    and to retrieve remote models as required.</description>
-  <dependencies>
-    <dependency>
-      <groupId>org.apache.maven</groupId>
-      <artifactId>maven-workspace</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.maven</groupId>
-      <artifactId>maven-profile</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.maven</groupId>
-      <artifactId>maven-model</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.codehaus.plexus</groupId>
-      <artifactId>plexus-utils</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.codehaus.plexus</groupId>
-      <artifactId>plexus-interpolation</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.maven.artifact</groupId>
-      <artifactId>maven-artifact</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.codehaus.plexus</groupId>
-      <artifactId>plexus-container-default</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>aspectj</groupId>
-      <artifactId>aspectjrt</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.maven.wagon</groupId>
-      <artifactId>wagon-file</artifactId>
-      <scope>test</scope>
-    </dependency>    
-  </dependencies>
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>aspectj-maven-plugin</artifactId>
-        <executions>
-          <execution>
-            <id>compile-aspects</id>
-            <phase>compile</phase>
-            <goals>
-              <goal>compile</goal>
-            </goals>
-          </execution>
-        </executions>
-      </plugin>
-    </plugins>
-  </build>
+    <parent>
+        <artifactId>maven</artifactId>
+        <groupId>org.apache.maven</groupId>
+        <version>2.1-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>maven-project</artifactId>
+    <name>Maven Project Builder</name>
+    <description>This library is used to not only read Maven project object model files,
but to assemble inheritence
+        and to retrieve remote models as required.
+    </description>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-workspace</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-profile</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-model</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.codehaus.plexus</groupId>
+            <artifactId>plexus-utils</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.codehaus.plexus</groupId>
+            <artifactId>plexus-interpolation</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven.artifact</groupId>
+            <artifactId>maven-artifact</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.codehaus.plexus</groupId>
+            <artifactId>plexus-container-default</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>aspectj</groupId>
+            <artifactId>aspectjrt</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven.wagon</groupId>
+            <artifactId>wagon-file</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven.shared</groupId>
+            <artifactId>maven-shared-model</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
+    </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+            </plugin>
+         
+            <!--
+            <plugin>
+              <groupId>org.codehaus.mojo</groupId>
+              <artifactId>aspectj-maven-plugin</artifactId>
+              <executions>
+                <execution>
+                  <id>compile-aspects</id>
+                  <phase>compile</phase>
+                  <goals>
+                    <goal>compile</goal>
+                  </goals>
+                </execution>
+              </executions>
+            </plugin>
+            -->
+        </plugins>
+    </build>
 </project>

Modified: maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
URL: http://svn.apache.org/viewvc/maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java?rev=672338&r1=672337&r2=672338&view=diff
==============================================================================
--- maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
(original)
+++ maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
Fri Jun 27 10:35:03 2008
@@ -67,6 +67,8 @@
 import org.apache.maven.project.validation.ModelValidationResult;
 import org.apache.maven.project.validation.ModelValidator;
 import org.apache.maven.project.workspace.ProjectWorkspace;
+import org.apache.maven.project.builder.ProjectBuilder;
+import org.apache.maven.project.builder.PomArtifactResolver;
 import org.codehaus.plexus.logging.LogEnabled;
 import org.codehaus.plexus.logging.Logger;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
@@ -75,11 +77,7 @@
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
+import java.io.*;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -164,6 +162,8 @@
 
     private ProjectWorkspace projectWorkspace;
 
+    private ProjectBuilder projectBuilder;
+
     //DO NOT USE, it is here only for backward compatibility reasons. The existing
     // maven-assembly-plugin (2.2-beta-1) is accessing it via reflection.
 
@@ -554,7 +554,7 @@
 
             File file = projectArtifact.getFile();
 
-            model = readModel( projectId, file, STRICT_MODEL_PARSING );
+            model = readModel( projectId, file, new PomArtifactResolver(localRepository,
remoteArtifactRepositories, artifactResolver) );
 
             String downloadUrl = null;
 
@@ -1232,6 +1232,25 @@
     }
 
     private Model readModel( String projectId,
+                            File projectDescriptor,
+                            PomArtifactResolver resolver )
+       throws ProjectBuildingException
+   {
+       System.out.println(projectDescriptor.getAbsolutePath());
+
+       MavenProject mavenProject;
+       try {
+           mavenProject = projectBuilder.buildFromStream(new FileInputStream(projectDescriptor),
null, resolver);
+       } catch (IOException e) {
+           e.printStackTrace();
+           throw new ProjectBuildingException(projectId, "File = " + projectDescriptor.getAbsolutePath()
, e);
+       }
+
+      return mavenProject.getModel();
+
+   }
+
+    private Model readModel( String projectId,
                              File file,
                              boolean strict )
         throws ProjectBuildingException

Modified: maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
URL: http://svn.apache.org/viewvc/maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java?rev=672338&r1=672337&r2=672338&view=diff
==============================================================================
--- maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
(original)
+++ maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
Fri Jun 27 10:35:03 2008
@@ -442,8 +442,8 @@
         return projectArtifacts;
     }
 
-    public List<ArtifactVersion> retrieveAvailableVersions( Artifact artifact, ArtifactRepository
localRepository,
-                                                            List<ArtifactRepository>
remoteRepositories )
+    public List retrieveAvailableVersions( Artifact artifact, ArtifactRepository localRepository,
+                                                            List remoteRepositories )
         throws ArtifactMetadataRetrievalException
     {
         RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
@@ -459,7 +459,7 @@
         return retrieveAvailableVersionsFromMetadata( metadata.getMetadata() );
     }
 
-    public List<ArtifactVersion> retrieveAvailableVersionsFromDeploymentRepository(
+    public List retrieveAvailableVersionsFromDeploymentRepository(
                                                                                     Artifact
artifact,
                                                                                     ArtifactRepository
localRepository,
                                                                                     ArtifactRepository
deploymentRepository )
@@ -478,7 +478,7 @@
         return retrieveAvailableVersionsFromMetadata( metadata.getMetadata() );
     }
 
-    private List<ArtifactVersion> retrieveAvailableVersionsFromMetadata( Metadata repoMetadata
)
+    private List retrieveAvailableVersionsFromMetadata( Metadata repoMetadata )
     {
         List<ArtifactVersion> versions;
         if ( ( repoMetadata != null ) && ( repoMetadata.getVersioning() != null )
)
@@ -492,7 +492,7 @@
         }
         else
         {
-            versions = Collections.<ArtifactVersion> emptyList();
+            versions = Collections.EMPTY_LIST;
         }
 
         return versions;

Added: maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java
URL: http://svn.apache.org/viewvc/maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java?rev=672338&view=auto
==============================================================================
--- maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java
(added)
+++ maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java
Fri Jun 27 10:35:03 2008
@@ -0,0 +1,99 @@
+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.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 String toString() {
+            return "Group ID = " + groupId + ", Artifact ID = " + artifactId + ", Version
= " + version;
+        }
+    }
+  }

Added: maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/IdModelContainerFactory.java
URL: http://svn.apache.org/viewvc/maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/IdModelContainerFactory.java?rev=672338&view=auto
==============================================================================
--- maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/IdModelContainerFactory.java
(added)
+++ maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/IdModelContainerFactory.java
Fri Jun 27 10:35:03 2008
@@ -0,0 +1,77 @@
+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 List<ModelProperty> getProperties() {
+            return properties;
+        }
+
+        public String toString() {
+            return "ID = " + id;
+        }
+    }
+}

Added: maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/PomArtifactResolver.java
URL: http://svn.apache.org/viewvc/maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/PomArtifactResolver.java?rev=672338&view=auto
==============================================================================
--- maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/PomArtifactResolver.java
(added)
+++ maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/PomArtifactResolver.java
Fri Jun 27 10:35:03 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/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java
URL: http://svn.apache.org/viewvc/maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java?rev=672338&view=auto
==============================================================================
--- maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java
(added)
+++ maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java
Fri Jun 27 10:35:03 2008
@@ -0,0 +1,77 @@
+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;
+
+    /**
+     * 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 = baos.toByteArray();
+    }
+
+    public PomClassicDomainModel(InputStream inputStream) throws IOException {
+        if (inputStream == null) {
+            throw new IllegalArgumentException("inputStream: null");
+        }
+        this.inputStream = IOUtil.toByteArray(inputStream);
+    }
+
+    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));
+    }
+}

Added: maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java
URL: http://svn.apache.org/viewvc/maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java?rev=672338&view=auto
==============================================================================
--- maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java
(added)
+++ maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java
Fri Jun 27 10:35:03 2008
@@ -0,0 +1,141 @@
+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"
+        ));
+    }
+
+    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 + sb.toString());
+        }
+    }
+
+    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 groupId, use parent one
+            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);
+        }
+        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/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java
URL: http://svn.apache.org/viewvc/maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java?rev=672338&view=auto
==============================================================================
--- maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java
(added)
+++ maven/sandbox/branches/maven-2.1/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java
Fri Jun 27 10:35:03 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)
+            throws IOException;
+}



Mime
View raw message