This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag maven-launchpad-plugin-2.1.2 in repository https://gitbox.apache.org/repos/asf/sling-maven-launchpad-plugin.git
commit c2c4f2fecb167c80f17393bbfd13dc246673a48c Author: Justin Edelson <[email protected]> AuthorDate: Thu Nov 3 21:49:04 2011 +0000 SLING-2263 - validating partial bundle lists during their lifecycle git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/maven/maven-launchpad-plugin@1197323 13f79535-47bb-0310-9956-ffa450edef68 --- .../projectsupport/AbstractBundleListMojo.java | 171 +++++++++++++++++++++ .../AbstractUsingBundleListMojo.java | 170 +------------------- .../projectsupport/ValidateBundleListMojo.java | 62 ++++++++ src/main/resources/META-INF/plexus/components.xml | 1 + 4 files changed, 235 insertions(+), 169 deletions(-) diff --git a/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java b/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java index 226e5fb..bd5e788 100644 --- a/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java +++ b/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java @@ -19,14 +19,38 @@ package org.apache.sling.maven.projectsupport; 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 AbstractBundleListMojo extends AbstractMojo { 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 AbstractBundleListMojo extends AbstractMojo { } } } + + 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; + } + } diff --git a/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java b/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java index 6117498..56cc6c9 100644 --- a/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java +++ b/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java @@ -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 AbstractUsingBundleListMojo extends AbstractBundleListMojo 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 AbstractUsingBundleListMojo extends AbstractBundleListMojo 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 AbstractUsingBundleListMojo extends AbstractBundleListMojo */ 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 AbstractUsingBundleListMojo extends AbstractBundleListMojo 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); diff --git a/src/main/java/org/apache/sling/maven/projectsupport/ValidateBundleListMojo.java b/src/main/java/org/apache/sling/maven/projectsupport/ValidateBundleListMojo.java new file mode 100644 index 0000000..4cdd931 --- /dev/null +++ b/src/main/java/org/apache/sling/maven/projectsupport/ValidateBundleListMojo.java @@ -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)); + } + } + } +} diff --git a/src/main/resources/META-INF/plexus/components.xml b/src/main/resources/META-INF/plexus/components.xml index d6fd19c..572d1ef 100644 --- a/src/main/resources/META-INF/plexus/components.xml +++ b/src/main/resources/META-INF/plexus/components.xml @@ -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> -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
