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 2022/11/06 22:41:08 UTC
[ws-axiom] branch master updated: Generate proper dependency-reduced POMs
This is an automated email from the ASF dual-hosted git repository.
veithen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ws-axiom.git
The following commit(s) were added to refs/heads/master by this push:
new bb8aba084 Generate proper dependency-reduced POMs
bb8aba084 is described below
commit bb8aba08467596760b08d610999eb61071d84f0e
Author: Andreas Veithen <an...@gmail.com>
AuthorDate: Sun Nov 6 22:40:59 2022 +0000
Generate proper dependency-reduced POMs
---
axiom-api/pom.xml | 14 +++-
.../pom/CreateDependencyReducedPomMojo.java | 79 ++++++++++++++++++++++
implementations/axiom-dom/pom.xml | 21 +++++-
implementations/axiom-impl/pom.xml | 19 +++++-
4 files changed, 128 insertions(+), 5 deletions(-)
diff --git a/axiom-api/pom.xml b/axiom-api/pom.xml
index 1d91f1bfc..ebc4a3f7c 100644
--- a/axiom-api/pom.xml
+++ b/axiom-api/pom.xml
@@ -38,13 +38,11 @@
<groupId>${project.groupId}</groupId>
<artifactId>base64-utils</artifactId>
<version>${project.version}</version>
- <optional>true</optional>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>blob</artifactId>
<version>${project.version}</version>
- <optional>true</optional>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
@@ -152,6 +150,18 @@
<goal>post-process-sources-jar</goal>
</goals>
</execution>
+ <execution>
+ <id>create-dependency-reduced-pom</id>
+ <goals>
+ <goal>create-dependency-reduced-pom</goal>
+ </goals>
+ <configuration>
+ <excludedArtifacts>
+ <excludedArtifact>base64-utils</excludedArtifact>
+ <excludedArtifact>blob</excludedArtifact>
+ </excludedArtifacts>
+ </configuration>
+ </execution>
</executions>
</plugin>
<plugin>
diff --git a/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/pom/CreateDependencyReducedPomMojo.java b/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/pom/CreateDependencyReducedPomMojo.java
new file mode 100644
index 000000000..50ca55de4
--- /dev/null
+++ b/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/pom/CreateDependencyReducedPomMojo.java
@@ -0,0 +1,79 @@
+/*
+ * 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.pom;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+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.project.MavenProject;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+@Mojo(name = "create-dependency-reduced-pom", defaultPhase = LifecyclePhase.PACKAGE)
+public class CreateDependencyReducedPomMojo extends AbstractMojo {
+ @Parameter(defaultValue = "${project}", readonly = true, required = true)
+ private MavenProject project;
+
+ @Parameter private Set<String> excludedArtifacts;
+
+ @Parameter(defaultValue = "${project.build.directory}/dependency-reduced-pom.xml")
+ private File dependencyReducedPomLocation;
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ if (excludedArtifacts == null || excludedArtifacts.isEmpty()) {
+ return;
+ }
+ Model model;
+ try (InputStream in = new FileInputStream(project.getFile())) {
+ model = new MavenXpp3Reader().read(in);
+ } catch (IOException | XmlPullParserException ex) {
+ throw new MojoExecutionException("Error reading POM", ex);
+ }
+ for (Iterator<Dependency> it = model.getDependencies().iterator(); it.hasNext(); ) {
+ Dependency dependency = it.next();
+ if (excludedArtifacts.contains(dependency.getArtifactId())) {
+ it.remove();
+ }
+ }
+ dependencyReducedPomLocation.getParentFile().mkdirs();
+ MavenXpp3Writer pomWriter = new MavenXpp3Writer();
+ try (OutputStream out = new FileOutputStream(dependencyReducedPomLocation)) {
+ pomWriter.write(out, model);
+ } catch (IOException ex) {
+ throw new MojoExecutionException("Error writing dependency-reduced POM", ex);
+ }
+ project.setPomFile(dependencyReducedPomLocation);
+ }
+}
diff --git a/implementations/axiom-dom/pom.xml b/implementations/axiom-dom/pom.xml
index ab58e2ad9..e1e43fd85 100644
--- a/implementations/axiom-dom/pom.xml
+++ b/implementations/axiom-dom/pom.xml
@@ -42,13 +42,11 @@
<groupId>${project.groupId}</groupId>
<artifactId>om-mixins</artifactId>
<version>${project.version}</version>
- <optional>true</optional>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>dom-mixins</artifactId>
<version>${project.version}</version>
- <optional>true</optional>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
@@ -259,6 +257,25 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>buildutils-maven-plugin</artifactId>
+ <version>${project.version}</version>
+ <executions>
+ <execution>
+ <id>create-dependency-reduced-pom</id>
+ <goals>
+ <goal>create-dependency-reduced-pom</goal>
+ </goals>
+ <configuration>
+ <excludedArtifacts>
+ <excludedArtifact>om-mixins</excludedArtifact>
+ <excludedArtifact>dom-mixins</excludedArtifact>
+ </excludedArtifacts>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
diff --git a/implementations/axiom-impl/pom.xml b/implementations/axiom-impl/pom.xml
index bbee686ad..dda4afd09 100644
--- a/implementations/axiom-impl/pom.xml
+++ b/implementations/axiom-impl/pom.xml
@@ -42,7 +42,6 @@
<groupId>${project.groupId}</groupId>
<artifactId>om-mixins</artifactId>
<version>${project.version}</version>
- <optional>true</optional>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
@@ -224,6 +223,24 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>buildutils-maven-plugin</artifactId>
+ <version>${project.version}</version>
+ <executions>
+ <execution>
+ <id>create-dependency-reduced-pom</id>
+ <goals>
+ <goal>create-dependency-reduced-pom</goal>
+ </goals>
+ <configuration>
+ <excludedArtifacts>
+ <excludedArtifact>om-mixins</excludedArtifact>
+ </excludedArtifacts>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>