maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sisb...@apache.org
Subject svn commit: r738893 - in /maven/components/sisbell-plugin-manager: maven-project-builder/src/main/java/org/apache/maven/project/builder/ maven-project/src/main/java/org/apache/maven/project/builder/ maven-project/src/main/java/org/apache/maven/project/...
Date Thu, 29 Jan 2009 15:26:31 GMT
Author: sisbell
Date: Thu Jan 29 15:26:30 2009
New Revision: 738893

URL: http://svn.apache.org/viewvc?rev=738893&view=rev
Log:
Added in support for mixins, specifically plugin mixins.

Added:
    maven/components/sisbell-plugin-manager/maven-project/src/main/java/org/apache/maven/project/builder/Mixer.java
    maven/components/sisbell-plugin-manager/maven-project/src/main/java/org/apache/maven/project/builder/PluginMixin.java
    maven/components/sisbell-plugin-manager/maven-project/src/test/java/org/apache/maven/project/builder/PluginBuilderTest.java
    maven/components/sisbell-plugin-manager/maven-project/src/test/resources-mixins/
    maven/components/sisbell-plugin-manager/maven-project/src/test/resources-mixins/plugins/
    maven/components/sisbell-plugin-manager/maven-project/src/test/resources-mixins/plugins/simple/
    maven/components/sisbell-plugin-manager/maven-project/src/test/resources-mixins/plugins/simple/mixin.xml
    maven/components/sisbell-plugin-manager/maven-project/src/test/resources-project-builder/plugin-merge-simple/
    maven/components/sisbell-plugin-manager/maven-project/src/test/resources-project-builder/plugin-merge-simple/pom.xml
Modified:
    maven/components/sisbell-plugin-manager/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java
    maven/components/sisbell-plugin-manager/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java
    maven/components/sisbell-plugin-manager/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java
    maven/components/sisbell-plugin-manager/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java

Modified: maven/components/sisbell-plugin-manager/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java
URL: http://svn.apache.org/viewvc/maven/components/sisbell-plugin-manager/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java?rev=738893&r1=738892&r2=738893&view=diff
==============================================================================
--- maven/components/sisbell-plugin-manager/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java
(original)
+++ maven/components/sisbell-plugin-manager/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java
Thu Jan 29 15:26:30 2009
@@ -162,8 +162,7 @@
                                                                          ProjectUri.Build.Resources.Resource.directory,
                                                                          ProjectUri.Build.TestResources.TestResource.directory,
                                                                          ProjectUri.Build.Filters.filter,
-                                                                         ProjectUri.Reporting.outputDirectory
) ) );
-
+                                                                         ProjectUri.Reporting.outputDirectory
) ) );   
     /**
      * @see ModelTransformer#transformToDomainModel(java.util.List, java.util.List)
      */

Added: maven/components/sisbell-plugin-manager/maven-project/src/main/java/org/apache/maven/project/builder/Mixer.java
URL: http://svn.apache.org/viewvc/maven/components/sisbell-plugin-manager/maven-project/src/main/java/org/apache/maven/project/builder/Mixer.java?rev=738893&view=auto
==============================================================================
--- maven/components/sisbell-plugin-manager/maven-project/src/main/java/org/apache/maven/project/builder/Mixer.java
(added)
+++ maven/components/sisbell-plugin-manager/maven-project/src/main/java/org/apache/maven/project/builder/Mixer.java
Thu Jan 29 15:26:30 2009
@@ -0,0 +1,14 @@
+package org.apache.maven.project.builder;
+
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.Model;
+
+import java.io.IOException;
+
+
+public interface Mixer 
+{
+
+    Model mixPlugin(Plugin plugin, Model model) throws IOException;
+}

Added: maven/components/sisbell-plugin-manager/maven-project/src/main/java/org/apache/maven/project/builder/PluginMixin.java
URL: http://svn.apache.org/viewvc/maven/components/sisbell-plugin-manager/maven-project/src/main/java/org/apache/maven/project/builder/PluginMixin.java?rev=738893&view=auto
==============================================================================
--- maven/components/sisbell-plugin-manager/maven-project/src/main/java/org/apache/maven/project/builder/PluginMixin.java
(added)
+++ maven/components/sisbell-plugin-manager/maven-project/src/main/java/org/apache/maven/project/builder/PluginMixin.java
Thu Jan 29 15:26:30 2009
@@ -0,0 +1,112 @@
+package org.apache.maven.project.builder;
+
+import org.apache.maven.shared.model.InputStreamDomainModel;
+import org.apache.maven.shared.model.ModelProperty;
+import org.apache.maven.shared.model.ModelMarshaller;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Build;
+import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
+import org.codehaus.plexus.util.WriterFactory;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.ReaderFactory;
+
+import java.io.*;
+import java.util.List;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.ArrayList;
+
+
+public class PluginMixin implements InputStreamDomainModel {
+
+
+    /**
+     * Bytes containing the underlying model
+     */
+    private byte[] inputBytes;
+
+    /**
+     * History of joins and deletes of model properties
+     */
+    private String eventHistory;
+
+    private List<ModelProperty> modelProperties;    
+
+    public PluginMixin(Plugin plugin)
+        throws IOException
+    {
+        Model model = new Model();
+        Build build = new Build();
+        build.addPlugin(plugin);
+        model.setBuild(build);
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        Writer out = null;
+        MavenXpp3Writer writer = new MavenXpp3Writer();
+        try
+        {
+            out = WriterFactory.newXmlWriter( baos );
+            writer.write( out, model );
+        }
+        finally
+        {
+            if ( out != null )
+            {
+                out.close();
+            }
+        }
+        inputBytes = baos.toByteArray();
+    }
+
+    public InputStream getInputStream() {
+        byte[] copy = new byte[inputBytes.length];
+        System.arraycopy( inputBytes, 0, copy, 0, inputBytes.length );
+        return new ByteArrayInputStream( copy );
+    }
+
+    public List<ModelProperty> getModelProperties() throws IOException {
+        if(modelProperties == null)
+        {
+            Set<String> s = new HashSet<String>();
+            //TODO: Should add all collections from ProjectUri
+            s.addAll(PomTransformer.URIS);
+            s.add(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.xUri);
+            s.add(ProjectUri.DependencyManagement.Dependencies.Dependency.Exclusions.xUri);
+            s.add(ProjectUri.Dependencies.Dependency.Exclusions.xUri);
+            s.add(ProjectUri.Build.Plugins.Plugin.Executions.xUri);
+            s.add(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.xURI);
+            s.add(ProjectUri.Reporting.Plugins.Plugin.ReportSets.xUri);
+            s.add(ProjectUri.Reporting.Plugins.Plugin.ReportSets.ReportSet.configuration);
+            s.add(ProjectUri.Build.Plugins.Plugin.Executions.Execution.configuration);
+            modelProperties = ModelMarshaller.marshallXmlToModelProperties(
+                getInputStream(), ProjectUri.baseUri, s );
+        }
+        return new ArrayList<ModelProperty>(modelProperties);
+    }
+
+    public String getEventHistory() {
+        return eventHistory;
+    }
+
+    public void setEventHistory(String eventHistory) {
+        this.eventHistory = eventHistory;
+    }
+
+    /**
+     * Returns XML model as string
+     *
+     * @return XML model as string
+     */
+    public String asString()
+    {
+        try
+        {
+            return IOUtil.toString( ReaderFactory.newXmlReader( new ByteArrayInputStream(
inputBytes ) ) );
+        }
+        catch ( IOException ioe )
+        {
+            // should not occur: everything is in-memory
+            return "";
+        }
+    }
+}

Modified: maven/components/sisbell-plugin-manager/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java
URL: http://svn.apache.org/viewvc/maven/components/sisbell-plugin-manager/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java?rev=738893&r1=738892&r2=738893&view=diff
==============================================================================
--- maven/components/sisbell-plugin-manager/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java
(original)
+++ maven/components/sisbell-plugin-manager/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java
Thu Jan 29 15:26:30 2009
@@ -44,6 +44,10 @@
                                            DomainModel domainModel)
             throws IOException
     {
+        if(! ( domainModel instanceof PomClassicDomainModel ) )
+        {
+            return;    
+        }
         Interpolator.interpolateModelProperties( modelProperties, interpolatorProperties,
(PomClassicDomainModel) domainModel);
     }
 }

Modified: maven/components/sisbell-plugin-manager/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/sisbell-plugin-manager/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java?rev=738893&r1=738892&r2=738893&view=diff
==============================================================================
--- maven/components/sisbell-plugin-manager/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java
(original)
+++ maven/components/sisbell-plugin-manager/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java
Thu Jan 29 15:26:30 2009
@@ -23,7 +23,6 @@
 import java.io.IOException;
 import java.io.Reader;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
@@ -34,21 +33,12 @@
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.Parent;
+import org.apache.maven.model.Plugin;
 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.ProjectBuilderConfiguration;
-import org.apache.maven.project.builder.ArtifactModelContainerFactory;
-import org.apache.maven.project.builder.IdModelContainerFactory;
-import org.apache.maven.project.builder.PomArtifactResolver;
-import org.apache.maven.project.builder.PomClassicDomainModel;
-import org.apache.maven.project.builder.PomClassicDomainModelFactory;
-import org.apache.maven.project.builder.PomClassicTransformer;
-import org.apache.maven.project.builder.PomTransformer;
-import org.apache.maven.project.builder.ProjectBuilder;
-import org.apache.maven.shared.model.DomainModel;
-import org.apache.maven.shared.model.InterpolatorProperty;
-import org.apache.maven.shared.model.ModelEventListener;
-import org.apache.maven.shared.model.ModelTransformerContext;
+import org.apache.maven.project.builder.*;
+import org.apache.maven.shared.model.*;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
 import org.codehaus.plexus.logging.LogEnabled;
@@ -61,7 +51,7 @@
  */
 @Component(role = ProjectBuilder.class)
 public class DefaultProjectBuilder
-    implements ProjectBuilder, LogEnabled
+    implements ProjectBuilder, Mixer, LogEnabled
 {
     @Requirement
     private ArtifactFactory artifactFactory;
@@ -371,5 +361,28 @@
         }
         
         return superModel;        
-    }        
+    }
+
+    public Model mixPlugin(Plugin plugin, Model model) throws IOException
+    {
+        //TODO - interpolation
+        List<DomainModel> domainModels = new ArrayList<DomainModel>();
+        domainModels.add( new PluginMixin(plugin) );
+        domainModels.add( new PomClassicDomainModel(model) );
+
+        PomClassicTransformer transformer = new PomClassicTransformer( new PomClassicDomainModelFactory()
);
+
+        ModelTransformerContext ctx = new ModelTransformerContext(PomTransformer.MODEL_CONTAINER_INFOS
);
+
+        PomClassicDomainModel transformedDomainModel = ( (PomClassicDomainModel) ctx.transform(
domainModels,
+                                                                                        
       transformer,
+                                                                                        
       transformer,
+                                                                                        
       Collections.EMPTY_LIST,
+                                                                                        
       null,
+                                                                                        
       listeners ) );
+        return transformedDomainModel.getModel();
+      //  List<ModelProperty> pluginProperties = ModelMarshaller.marshallXmlToModelProperties(
+      //          (new PluginMixin(plugin)).getInputStream(), ProjectUri.Build.Plugins.xUri,
null);
+        
+    }
 }

Added: maven/components/sisbell-plugin-manager/maven-project/src/test/java/org/apache/maven/project/builder/PluginBuilderTest.java
URL: http://svn.apache.org/viewvc/maven/components/sisbell-plugin-manager/maven-project/src/test/java/org/apache/maven/project/builder/PluginBuilderTest.java?rev=738893&view=auto
==============================================================================
--- maven/components/sisbell-plugin-manager/maven-project/src/test/java/org/apache/maven/project/builder/PluginBuilderTest.java
(added)
+++ maven/components/sisbell-plugin-manager/maven-project/src/test/java/org/apache/maven/project/builder/PluginBuilderTest.java
Thu Jan 29 15:26:30 2009
@@ -0,0 +1,4 @@
+package org.apache.maven.project.builder;
+
+public class PluginBuilderTest {
+}

Modified: maven/components/sisbell-plugin-manager/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java
URL: http://svn.apache.org/viewvc/maven/components/sisbell-plugin-manager/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java?rev=738893&r1=738892&r2=738893&view=diff
==============================================================================
--- maven/components/sisbell-plugin-manager/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java
(original)
+++ maven/components/sisbell-plugin-manager/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java
Thu Jan 29 15:26:30 2009
@@ -21,14 +21,19 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.io.FileInputStream;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.maven.MavenTools;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.project.harness.PomTestWrapper;
 import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 public class PomConstructionTest
     extends PlexusTestCase
@@ -36,19 +41,27 @@
 
     private static String BASE_POM_DIR = "src/test/resources-project-builder";
 
+    private static String BASE_MIXIN_DIR = "src/test/resources-mixins";
+
     private ProjectBuilder projectBuilder;
 
+    private Mixer mixer;
+
     private MavenTools mavenTools;
 
     private PomArtifactResolver pomArtifactResolver;
 
     private File testDirectory;
 
+    private File testMixinDirectory;
+
     protected void setUp()
         throws Exception
     {
         testDirectory = new File( getBasedir(), BASE_POM_DIR );
+        testMixinDirectory = new File( getBasedir(), BASE_MIXIN_DIR );
         projectBuilder = lookup( ProjectBuilder.class );
+        mixer = (Mixer) projectBuilder;
         mavenTools = lookup( MavenTools.class );
         pomArtifactResolver = new PomArtifactResolver()
         {
@@ -62,6 +75,18 @@
         };
     }
 
+    public void testPluginMergeSimple()
+        throws Exception
+    {
+        Model model = buildPom( "plugin-merge-simple" ).getDomainModel().getModel();
+        Model plugin = buildMixin("plugins/simple");
+
+        model = mixer.mixPlugin((Plugin) plugin.getBuild().getPlugins().get(0), model);
+
+        PomTestWrapper pom = new PomTestWrapper( model );
+        assertEquals( "FAILED", pom.getValue( "build/plugins[1]/configuration[1]/propertiesFile"
) );
+    }
+
     // Some better conventions for the test poms needs to be created and each of these tests
     // that represent a verification of a specification item needs to be a couple lines at
most.
     // The expressions help a lot, but we need a clean to pick up a directory of POMs, automatically
load
@@ -731,11 +756,24 @@
         return new PomTestWrapper( pomFile, projectBuilder.buildModel( pomFile, null, pomArtifactResolver
) );
     }
 
+    private Model buildMixin( String mixinPath )
+        throws IOException, XmlPullParserException
+    {
+        File mixinFile = new File( testMixinDirectory , mixinPath );
+        if ( mixinFile.isDirectory() )
+        {
+            mixinFile = new File( mixinFile, "mixin.xml" );
+        }
+        FileInputStream pluginStream = new FileInputStream( mixinFile );
+        MavenXpp3Reader reader = new MavenXpp3Reader();
+        return reader.read(pluginStream, false);
+    }
+
     protected void assertModelEquals( PomTestWrapper pom, Object expected, String expression
)
     {
         assertEquals( expected, pom.getValue( expression ) );        
     }
-    
+
     // Need to get this to walk around a directory and automatically build up the artifact
set. If we
     // follow some standard conventions this can be simple.
     class FileBasedPomArtifactResolver

Added: maven/components/sisbell-plugin-manager/maven-project/src/test/resources-mixins/plugins/simple/mixin.xml
URL: http://svn.apache.org/viewvc/maven/components/sisbell-plugin-manager/maven-project/src/test/resources-mixins/plugins/simple/mixin.xml?rev=738893&view=auto
==============================================================================
--- maven/components/sisbell-plugin-manager/maven-project/src/test/resources-mixins/plugins/simple/mixin.xml
(added)
+++ maven/components/sisbell-plugin-manager/maven-project/src/test/resources-mixins/plugins/simple/mixin.xml
Thu Jan 29 15:26:30 2009
@@ -0,0 +1,14 @@
+<project>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.its.plugins</groupId>
+                <artifactId>maven-it-plugin-configuration</artifactId>
+                <version>2.1-SNAPSHOT</version>
+                <configuration>
+                    <propertiesFile>FAILED</propertiesFile>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

Added: maven/components/sisbell-plugin-manager/maven-project/src/test/resources-project-builder/plugin-merge-simple/pom.xml
URL: http://svn.apache.org/viewvc/maven/components/sisbell-plugin-manager/maven-project/src/test/resources-project-builder/plugin-merge-simple/pom.xml?rev=738893&view=auto
==============================================================================
--- maven/components/sisbell-plugin-manager/maven-project/src/test/resources-project-builder/plugin-merge-simple/pom.xml
(added)
+++ maven/components/sisbell-plugin-manager/maven-project/src/test/resources-project-builder/plugin-merge-simple/pom.xml
Thu Jan 29 15:26:30 2009
@@ -0,0 +1,17 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.sonatype.nexus</groupId>
+  <artifactId>nexus-indexer</artifactId>
+  <version>1.1.3-SNAPSHOT</version>
+
+  <build>
+    <plugins>
+        <plugin>
+            <groupId>org.apache.maven.its.plugins</groupId>
+            <artifactId>maven-it-plugin-configuration</artifactId>
+            <version>2.1-SNAPSHOT</version>
+        </plugin>
+      </plugins>
+  </build>
+</project>
\ No newline at end of file



Mime
View raw message