You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ju...@apache.org on 2011/11/03 22:49:04 UTC

svn commit: r1197323 - in /sling/trunk/maven/maven-launchpad-plugin/src/main: java/org/apache/sling/maven/projectsupport/ resources/META-INF/plexus/

Author: justin
Date: Thu Nov  3 21:49:04 2011
New Revision: 1197323

URL: http://svn.apache.org/viewvc?rev=1197323&view=rev
Log:
SLING-2263 - validating partial bundle lists during their lifecycle

Added:
    sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/ValidateBundleListMojo.java
Modified:
    sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java
    sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java
    sling/trunk/maven/maven-launchpad-plugin/src/main/resources/META-INF/plexus/components.xml

Modified: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java?rev=1197323&r1=1197322&r2=1197323&view=diff
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java (original)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java Thu Nov  3 21:49:04 2011
@@ -19,14 +19,38 @@ package org.apache.sling.maven.projectsu
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.util.Arrays;
 import java.util.List;
+import java.util.Properties;
 
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.artifact.versioning.ArtifactVersion;
+import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.execution.MavenSession;
 import org.apache.maven.model.Dependency;
 import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.MavenProjectHelper;
+import org.apache.maven.settings.Settings;
+import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle;
 import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList;
+import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel;
 import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.io.xpp3.BundleListXpp3Reader;
+import org.codehaus.plexus.interpolation.InterpolationException;
+import org.codehaus.plexus.interpolation.Interpolator;
+import org.codehaus.plexus.interpolation.PrefixedObjectValueSource;
+import org.codehaus.plexus.interpolation.PropertiesBasedValueSource;
+import org.codehaus.plexus.interpolation.StringSearchInterpolator;
+import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 public abstract class AbstractBundleListMojo extends AbstractMojo {
@@ -104,12 +128,58 @@ public abstract class AbstractBundleList
     protected boolean ignoreBundleListConfig;
 
     /**
+     * @parameter expression="${session}
+     * @required
+     * @readonly
+     */
+    protected MavenSession mavenSession;
+
+    /**
      * The start level to be used when generating the bundle list.
      * 
      * @parameter default-value="-1"
      */
     private int dependencyStartLevel;
 
+    /**
+     * Used to look up Artifacts in the remote repository.
+     *
+     * @component
+     */
+    private ArtifactFactory factory;
+
+    /**
+     * Used to look up Artifacts in the remote repository.
+     *
+     * @component hint="maven"
+     */
+    private ArtifactMetadataSource metadataSource;
+
+    /**
+     * Location of the local repository.
+     *
+     * @parameter expression="${localRepository}"
+     * @readonly
+     * @required
+     */
+    private ArtifactRepository local;
+
+    /**
+     * List of Remote Repositories used by the resolver.
+     *
+     * @parameter expression="${project.remoteArtifactRepositories}"
+     * @readonly
+     * @required
+     */
+    private List<?> remoteRepos;
+
+    /**
+     * Used to look up Artifacts in the remote repository.
+     *
+     * @component
+     */
+    private ArtifactResolver resolver;
+
     protected File getConfigDirectory() {
         return this.configDirectory;
     }
@@ -135,4 +205,105 @@ public abstract class AbstractBundleList
             }
         }
     }
+
+    protected void interpolateProperties(BundleList bundleList) throws MojoExecutionException {
+        Interpolator interpolator = createInterpolator();
+        for (final StartLevel sl : bundleList.getStartLevels()) {
+            for (final Bundle bndl : sl.getBundles()) {
+                try {
+                    bndl.setArtifactId(interpolator.interpolate(bndl.getArtifactId()));
+                    bndl.setGroupId(interpolator.interpolate(bndl.getGroupId()));
+                    bndl.setVersion(interpolator.interpolate(bndl.getVersion()));
+                    bndl.setClassifier(interpolator.interpolate(bndl.getClassifier()));
+                    bndl.setType(interpolator.interpolate(bndl.getType()));
+                } catch (InterpolationException e) {
+                    throw new MojoExecutionException("Unable to interpolate properties for bundle " + bndl.toString(), e);
+                }
+            }
+        }
+
+    }
+
+    private Interpolator createInterpolator() {
+        StringSearchInterpolator interpolator = new StringSearchInterpolator();
+
+        final Properties props = new Properties();
+        props.putAll(project.getProperties());
+        props.putAll(mavenSession.getExecutionProperties());
+
+        interpolator.addValueSource(new PropertiesBasedValueSource(props));
+
+        // add ${project.foo}
+        interpolator.addValueSource(new PrefixedObjectValueSource(Arrays.asList("project", "pom"), project, true));
+
+        // add ${session.foo}
+        interpolator.addValueSource(new PrefixedObjectValueSource("session", mavenSession));
+
+        // add ${settings.foo}
+        final Settings settings = mavenSession.getSettings();
+        if (settings != null) {
+            interpolator.addValueSource(new PrefixedObjectValueSource("settings", settings));
+        }
+
+        return interpolator;
+    }
+
+    /**
+     * Get a resolved Artifact from the coordinates found in the artifact
+     * definition.
+     *
+     * @param def the artifact definition
+     * @return the artifact, which has been resolved
+     * @throws MojoExecutionException
+     */
+    protected Artifact getArtifact(ArtifactDefinition def) throws MojoExecutionException {
+        return getArtifact(def.getGroupId(), def.getArtifactId(), def.getVersion(), def.getType(), def.getClassifier());
+    }
+
+    /**
+     * Get a resolved Artifact from the coordinates provided
+     *
+     * @return the artifact, which has been resolved.
+     * @throws MojoExecutionException
+     */
+    protected Artifact getArtifact(String groupId, String artifactId, String version, String type, String classifier)
+            throws MojoExecutionException {
+                Artifact artifact;
+                VersionRange vr;
+            
+                try {
+                    vr = VersionRange.createFromVersionSpec(version);
+                } catch (InvalidVersionSpecificationException e) {
+                    vr = VersionRange.createFromVersion(version);
+                }
+            
+                if (StringUtils.isEmpty(classifier)) {
+                    artifact = factory.createDependencyArtifact(groupId, artifactId, vr, type, null, Artifact.SCOPE_COMPILE);
+                } else {
+                    artifact = factory.createDependencyArtifact(groupId, artifactId, vr, type, classifier,
+                            Artifact.SCOPE_COMPILE);
+                }
+            
+                // This code kicks in when the version specifier is a range.
+                if (vr.getRecommendedVersion() == null) {
+                    try {
+                        List<?> availVersions = metadataSource.retrieveAvailableVersions(artifact, local, remoteRepos);
+                        ArtifactVersion resolvedVersion = vr.matchVersion(availVersions);
+                        artifact.setVersion(resolvedVersion.toString());
+                    } catch (ArtifactMetadataRetrievalException e) {
+                        throw new MojoExecutionException("Unable to find version for artifact", e);
+                    }
+            
+                }
+            
+                try {
+                    resolver.resolve(artifact, remoteRepos, local);
+                } catch (ArtifactResolutionException e) {
+                    throw new MojoExecutionException("Unable to resolve artifact.", e);
+                } catch (ArtifactNotFoundException e) {
+                    throw new MojoExecutionException("Unable to find artifact.", e);
+                }
+                return artifact;
+            }
+
 }

Modified: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java?rev=1197323&r1=1197322&r2=1197323&view=diff
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java (original)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java Thu Nov  3 21:49:04 2011
@@ -20,42 +20,20 @@ import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.Reader;
-import java.util.Arrays;
 import java.util.Enumeration;
-import java.util.List;
 import java.util.Properties;
 import java.util.Set;
 
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
-import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
-import org.apache.maven.artifact.resolver.ArtifactResolutionException;
-import org.apache.maven.artifact.resolver.ArtifactResolver;
-import org.apache.maven.artifact.versioning.ArtifactVersion;
-import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
-import org.apache.maven.artifact.versioning.VersionRange;
-import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.settings.Settings;
 import org.apache.maven.shared.filtering.MavenFileFilter;
 import org.apache.maven.shared.filtering.MavenFilteringException;
 import org.apache.maven.shared.filtering.PropertyUtils;
-import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle;
 import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList;
-import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel;
 import org.codehaus.plexus.archiver.ArchiverException;
 import org.codehaus.plexus.archiver.zip.ZipUnArchiver;
-import org.codehaus.plexus.interpolation.InterpolationException;
-import org.codehaus.plexus.interpolation.Interpolator;
-import org.codehaus.plexus.interpolation.PrefixedObjectValueSource;
-import org.codehaus.plexus.interpolation.PropertiesBasedValueSource;
-import org.codehaus.plexus.interpolation.StringSearchInterpolator;
 import org.codehaus.plexus.util.FileUtils;
-import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 import org.drools.KnowledgeBase;
 import org.drools.KnowledgeBaseFactory;
@@ -113,20 +91,6 @@ public abstract class AbstractUsingBundl
     private ArtifactDefinition[] bundleExclusions;
 
     /**
-     * Used to look up Artifacts in the remote repository.
-     *
-     * @component
-     */
-    private ArtifactFactory factory;
-
-    /**
-     * Used to look up Artifacts in the remote repository.
-     *
-     * @component hint="maven"
-     */
-    private ArtifactMetadataSource metadataSource;
-
-    /**
      * If true, include the default bundles.
      *
      * @parameter default-value="true"
@@ -134,43 +98,11 @@ public abstract class AbstractUsingBundl
     private boolean includeDefaultBundles;
 
     /**
-     * Location of the local repository.
-     *
-     * @parameter expression="${localRepository}"
-     * @readonly
-     * @required
-     */
-    private ArtifactRepository local;
-
-    /**
-     * List of Remote Repositories used by the resolver.
-     *
-     * @parameter expression="${project.remoteArtifactRepositories}"
-     * @readonly
-     * @required
-     */
-    private List<?> remoteRepos;
-
-    /**
-     * Used to look up Artifacts in the remote repository.
-     *
-     * @component
-     */
-    private ArtifactResolver resolver;
-
-    /**
      * @parameter
      */
     private File[] rewriteRuleFiles;
 
     /**
-     * @parameter expression="${session}
-     * @required
-     * @readonly
-     */
-    protected MavenSession mavenSession;
-
-    /**
      * @component
      */
     protected MavenFileFilter mavenFileFilter;
@@ -232,64 +164,6 @@ public abstract class AbstractUsingBundl
      */
     protected abstract void executeWithArtifacts() throws MojoExecutionException, MojoFailureException;
 
-    /**
-     * Get a resolved Artifact from the coordinates found in the artifact
-     * definition.
-     *
-     * @param def the artifact definition
-     * @return the artifact, which has been resolved
-     * @throws MojoExecutionException
-     */
-    protected Artifact getArtifact(ArtifactDefinition def) throws MojoExecutionException {
-        return getArtifact(def.getGroupId(), def.getArtifactId(), def.getVersion(), def.getType(), def.getClassifier());
-    }
-
-    /**
-     * Get a resolved Artifact from the coordinates provided
-     *
-     * @return the artifact, which has been resolved.
-     * @throws MojoExecutionException
-     */
-    protected Artifact getArtifact(String groupId, String artifactId, String version, String type, String classifier)
-            throws MojoExecutionException {
-        Artifact artifact;
-        VersionRange vr;
-
-        try {
-            vr = VersionRange.createFromVersionSpec(version);
-        } catch (InvalidVersionSpecificationException e) {
-            vr = VersionRange.createFromVersion(version);
-        }
-
-        if (StringUtils.isEmpty(classifier)) {
-            artifact = factory.createDependencyArtifact(groupId, artifactId, vr, type, null, Artifact.SCOPE_COMPILE);
-        } else {
-            artifact = factory.createDependencyArtifact(groupId, artifactId, vr, type, classifier,
-                    Artifact.SCOPE_COMPILE);
-        }
-
-        // This code kicks in when the version specifier is a range.
-        if (vr.getRecommendedVersion() == null) {
-            try {
-                List<?> availVersions = metadataSource.retrieveAvailableVersions(artifact, local, remoteRepos);
-                ArtifactVersion resolvedVersion = vr.matchVersion(availVersions);
-                artifact.setVersion(resolvedVersion.toString());
-            } catch (ArtifactMetadataRetrievalException e) {
-                throw new MojoExecutionException("Unable to find version for artifact", e);
-            }
-
-        }
-
-        try {
-            resolver.resolve(artifact, remoteRepos, local);
-        } catch (ArtifactResolutionException e) {
-            throw new MojoExecutionException("Unable to resolve artifact.", e);
-        } catch (ArtifactNotFoundException e) {
-            throw new MojoExecutionException("Unable to find artifact.", e);
-        }
-        return artifact;
-    }
-
     protected BundleList getBundleList() {
         return bundleList;
     }
@@ -434,49 +308,7 @@ public abstract class AbstractUsingBundl
 
         rewriteBundleList(bundleList);
     }
-
-    private void interpolateProperties(BundleList bundleList) throws MojoExecutionException {
-        Interpolator interpolator = createInterpolator();
-        for (final StartLevel sl : bundleList.getStartLevels()) {
-            for (final Bundle bndl : sl.getBundles()) {
-                try {
-                    bndl.setArtifactId(interpolator.interpolate(bndl.getArtifactId()));
-                    bndl.setGroupId(interpolator.interpolate(bndl.getGroupId()));
-                    bndl.setVersion(interpolator.interpolate(bndl.getVersion()));
-                    bndl.setClassifier(interpolator.interpolate(bndl.getClassifier()));
-                    bndl.setType(interpolator.interpolate(bndl.getType()));
-                } catch (InterpolationException e) {
-                    throw new MojoExecutionException("Unable to interpolate properties for bundle " + bndl.toString(), e);
-                }
-            }
-        }
-
-    }
-
-    private Interpolator createInterpolator() {
-        StringSearchInterpolator interpolator = new StringSearchInterpolator();
-
-        final Properties props = new Properties();
-        props.putAll(project.getProperties());
-        props.putAll(mavenSession.getExecutionProperties());
-
-        interpolator.addValueSource(new PropertiesBasedValueSource(props));
-
-        // add ${project.foo}
-        interpolator.addValueSource(new PrefixedObjectValueSource(Arrays.asList("project", "pom"), project, true));
-
-        // add ${session.foo}
-        interpolator.addValueSource(new PrefixedObjectValueSource("session", mavenSession));
-
-        // add ${settings.foo}
-        final Settings settings = mavenSession.getSettings();
-        if (settings != null) {
-            interpolator.addValueSource(new PrefixedObjectValueSource("settings", settings));
-        }
-
-        return interpolator;
-    }
-
+    
     private void rewriteBundleList(BundleList bundleList) throws MojoExecutionException {
         if (rewriteRuleFiles != null) {
             KnowledgeBase knowledgeBase = createKnowledgeBase(rewriteRuleFiles);

Added: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/ValidateBundleListMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/ValidateBundleListMojo.java?rev=1197323&view=auto
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/ValidateBundleListMojo.java (added)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/ValidateBundleListMojo.java Thu Nov  3 21:49:04 2011
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ */
+package org.apache.sling.maven.projectsupport;
+
+import java.io.IOException;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle;
+import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList;
+import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+/**
+ * Validate that the artifacts listed in a bundle list are valid
+ *
+ * @goal validate-bundle-list
+ * @phase validate
+ * @requiresDependencyResolution test
+ * @description validate that the artifacts listed in a bundle list are valid
+ */
+public class ValidateBundleListMojo extends AbstractBundleListMojo {
+   
+    public void execute() throws MojoExecutionException, MojoFailureException {
+        final BundleList bundleList;
+        if (bundleListFile.exists()) {
+            try {
+                bundleList = readBundleList(bundleListFile);
+            } catch (IOException e) {
+                throw new MojoExecutionException("Unable to read bundle list file", e);
+            } catch (XmlPullParserException e) {
+                throw new MojoExecutionException("Unable to read bundle list file", e);
+            }
+        } else {
+            bundleList = new BundleList();
+        }
+        
+        addDependencies(bundleList);
+
+        interpolateProperties(bundleList);
+        
+        for (StartLevel sl : bundleList.getStartLevels()) {
+            for (Bundle bundle : sl.getBundles()) {
+                getArtifact(new ArtifactDefinition(bundle, -1));
+            }
+        }
+    }
+}

Modified: sling/trunk/maven/maven-launchpad-plugin/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/resources/META-INF/plexus/components.xml?rev=1197323&r1=1197322&r2=1197323&view=diff
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/resources/META-INF/plexus/components.xml (original)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/resources/META-INF/plexus/components.xml Thu Nov  3 21:49:04 2011
@@ -28,6 +28,7 @@
             <id>default</id>
             <!-- START SNIPPET: bundle-lifecycle -->
             <phases>
+              <validate>org.apache.sling:maven-launchpad-plugin:validate-bundle-list</validate>
               <package>org.apache.sling:maven-launchpad-plugin:attach-partial-bundle-list</package>
               <install>org.apache.maven.plugins:maven-install-plugin:install</install>
               <deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>