You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2017/06/05 19:34:37 UTC
svn commit: r1797687 - in /webservices/axiom/trunk: axiom-api/
buildutils/buildutils-maven-plugin/
buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/sources/
implementations/
Author: veithen
Date: Mon Jun 5 19:34:37 2017
New Revision: 1797687
URL: http://svn.apache.org/viewvc?rev=1797687&view=rev
Log:
Ensure completeness of source JARs.
Added:
webservices/axiom/trunk/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/sources/
webservices/axiom/trunk/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/sources/PostProcessMojo.java (with props)
webservices/axiom/trunk/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/sources/SourceExtractor.java (with props)
Modified:
webservices/axiom/trunk/axiom-api/pom.xml
webservices/axiom/trunk/buildutils/buildutils-maven-plugin/pom.xml
webservices/axiom/trunk/implementations/pom.xml
Modified: webservices/axiom/trunk/axiom-api/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/pom.xml?rev=1797687&r1=1797686&r2=1797687&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/pom.xml (original)
+++ webservices/axiom/trunk/axiom-api/pom.xml Mon Jun 5 19:34:37 2017
@@ -262,6 +262,18 @@
</configuration>
</plugin>
<plugin>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>buildutils-maven-plugin</artifactId>
+ <version>${project.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>post-process-sources-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
<groupId>com.github.veithen.phos</groupId>
<artifactId>enforcer-maven-plugin</artifactId>
<executions>
Modified: webservices/axiom/trunk/buildutils/buildutils-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/buildutils/buildutils-maven-plugin/pom.xml?rev=1797687&r1=1797686&r2=1797687&view=diff
==============================================================================
--- webservices/axiom/trunk/buildutils/buildutils-maven-plugin/pom.xml (original)
+++ webservices/axiom/trunk/buildutils/buildutils-maven-plugin/pom.xml Mon Jun 5 19:34:37 2017
@@ -59,6 +59,11 @@
<artifactId>maven-core</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-artifact-transfer</artifactId>
+ <version>0.9.1</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-integration-tools</artifactId>
<version>${doxia.version}</version>
Added: webservices/axiom/trunk/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/sources/PostProcessMojo.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/sources/PostProcessMojo.java?rev=1797687&view=auto
==============================================================================
--- webservices/axiom/trunk/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/sources/PostProcessMojo.java (added)
+++ webservices/axiom/trunk/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/sources/PostProcessMojo.java Mon Jun 5 19:34:37 2017
@@ -0,0 +1,133 @@
+/*
+ * 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.axiom.buildutils.sources;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
+import java.util.jar.JarOutputStream;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.shared.artifact.DefaultArtifactCoordinate;
+import org.apache.maven.shared.artifact.resolve.ArtifactResolver;
+import org.apache.maven.shared.artifact.resolve.ArtifactResolverException;
+import org.apache.maven.shared.utils.io.IOUtil;
+import org.objectweb.asm.ClassReader;
+
+@Mojo(name="post-process-sources-jar", defaultPhase=LifecyclePhase.PACKAGE, requiresDependencyResolution=ResolutionScope.COMPILE_PLUS_RUNTIME)
+public class PostProcessMojo extends AbstractMojo {
+ @Parameter(defaultValue="${project}", readonly=true, required=true)
+ private MavenProject project;
+
+ @Parameter(defaultValue="${session}", readonly=true, required=true)
+ private MavenSession session;
+
+ @Parameter(defaultValue="${project.build.directory}", readonly=true, required=true)
+ private File outputDirectory;
+
+ @Parameter(defaultValue="${project.build.finalName}", readonly=true, required=true)
+ private String finalName;
+
+ @Component
+ private ArtifactResolver artifactResolver;
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ if (project.getPackaging().equals("pom")) {
+ return;
+ }
+ Set<String> sources = new HashSet<>();
+ try (JarInputStream in = new JarInputStream(new FileInputStream(project.getArtifact().getFile()))) {
+ JarEntry entry;
+ while ((entry = in.getNextJarEntry()) != null) {
+ String name = entry.getName();
+ if (name.endsWith(".class")) {
+ new ClassReader(in).accept(new SourceExtractor(sources, name.substring(0, name.lastIndexOf('/')+1)), ClassReader.SKIP_CODE);
+ }
+ }
+ } catch (IOException ex) {
+ throw new MojoExecutionException("Error reading jar: " + ex.getMessage(), ex);
+ }
+ File sourcesJar = new File(outputDirectory, finalName + "-sources.jar");
+ File postProcessedSourcesJar = new File(outputDirectory, finalName + "-post-processed-sources.jar");
+ try (JarOutputStream out = new JarOutputStream(new FileOutputStream(postProcessedSourcesJar))) {
+ processSourceJar(sourcesJar, sources, true, out);
+ ArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
+ for (Artifact artifact : project.getArtifacts()) {
+ if (sources.isEmpty()) {
+ break;
+ }
+ if (filter.include(artifact)) {
+ DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
+ coordinate.setGroupId(artifact.getGroupId());
+ coordinate.setArtifactId(artifact.getArtifactId());
+ coordinate.setVersion(artifact.getVersion());
+ coordinate.setExtension("jar");
+ coordinate.setClassifier("sources");
+ Artifact resolvedArtifact;
+ try {
+ resolvedArtifact = artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), coordinate).getArtifact();
+ } catch (ArtifactResolverException ex) {
+ getLog().warn("Could not get sources for " + artifact);
+ continue;
+ }
+ if (resolvedArtifact.isResolved()) {
+ processSourceJar(resolvedArtifact.getFile(), sources, false, out);
+ }
+ }
+ }
+ } catch (IOException ex) {
+ throw new MojoExecutionException("Error writing jar: " + ex.getMessage(), ex);
+ }
+ sourcesJar.delete();
+ postProcessedSourcesJar.renameTo(sourcesJar);
+ }
+
+ private void processSourceJar(File file, Set<String> sources, boolean includeAll, JarOutputStream out) throws MojoExecutionException {
+ try (JarInputStream in = new JarInputStream(new FileInputStream(file))) {
+ JarEntry entry;
+ while ((entry = in.getNextJarEntry()) != null) {
+ String name = entry.getName();
+ if (sources.remove(name) || includeAll) {
+ out.putNextEntry(entry);
+ IOUtil.copy(in, out);
+ }
+ }
+ } catch (IOException ex) {
+ throw new MojoExecutionException("Error reading " + file + ": " + ex.getMessage(), ex);
+ }
+ }
+}
Propchange: webservices/axiom/trunk/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/sources/PostProcessMojo.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axiom/trunk/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/sources/SourceExtractor.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/sources/SourceExtractor.java?rev=1797687&view=auto
==============================================================================
--- webservices/axiom/trunk/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/sources/SourceExtractor.java (added)
+++ webservices/axiom/trunk/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/sources/SourceExtractor.java Mon Jun 5 19:34:37 2017
@@ -0,0 +1,40 @@
+/*
+ * 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.axiom.buildutils.sources;
+
+import java.util.Set;
+
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.Opcodes;
+
+final class SourceExtractor extends ClassVisitor {
+ private final Set<String> sources;
+ private final String parentPath;
+
+ SourceExtractor(Set<String> sources, String parentPath) {
+ super(Opcodes.ASM5);
+ this.sources = sources;
+ this.parentPath = parentPath;
+ }
+
+ @Override
+ public void visitSource(String source, String debug) {
+ sources.add(parentPath + source);
+ }
+}
Propchange: webservices/axiom/trunk/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/sources/SourceExtractor.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/axiom/trunk/implementations/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/pom.xml?rev=1797687&r1=1797686&r2=1797687&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/pom.xml (original)
+++ webservices/axiom/trunk/implementations/pom.xml Mon Jun 5 19:34:37 2017
@@ -88,6 +88,18 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>buildutils-maven-plugin</artifactId>
+ <version>${project.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>post-process-sources-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>