Skip to content

Commit

Permalink
[MARTIFACT-62] Drop deprecated classes and artifacts (#31)
Browse files Browse the repository at this point in the history
* Drop deprecated classes

* Fix merge issue

* Declare deps if used
  • Loading branch information
cstamas authored Apr 21, 2024
1 parent 856f707 commit c9d385e
Show file tree
Hide file tree
Showing 13 changed files with 273 additions and 216 deletions.
30 changes: 30 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# 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.
#
version: 2
updates:

- package-ecosystem: maven
directory: "/"
schedule:
interval: daily
time: '04:00'
open-pull-requests-limit: 10

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
2 changes: 1 addition & 1 deletion .github/workflows/maven-verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ on:
jobs:
build:
name: Verify
uses: apache/maven-gh-actions-shared/.github/workflows/maven-verify.yml@v2
uses: apache/maven-gh-actions-shared/.github/workflows/maven-verify.yml@v4
14 changes: 9 additions & 5 deletions pgp-keys-map.list
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@
# specific language governing permissions and limitations
# under the License.

commons-codec:commons-codec = 0xBC87A3FD0A54480F0BADBEBD21939FF0CA2A6567
com.github.luben:zstd-jni = 0x9AC5712CABE9635B65663AB0711C0A9A896FE336
commons-codec:commons-codec = 0x2DB4F1EF0FA761ECC4EA935C86FDC7E2A11262CB
commons-io:commons-io = 0x2DB4F1EF0FA761ECC4EA935C86FDC7E2A11262CB
javax.inject:javax.inject = noSig
junit:junit = 0xFF6E2C001948C5F2F38B0CC385911F425EC61B51
org.apache.maven.* = 0xB920D295BF0E61CB4CF0896C33CD6733AF5EC452
org.apache.maven:maven-archiver = 0x29BEA2A645F2D6CED7FB12E02B172E3E156466E8
org.apache.maven:maven-archiver = 0x84789D24DF77A32433CE1F079EB80E92EB2135B1
org.apache.maven.resolver = 0x29BEA2A645F2D6CED7FB12E02B172E3E156466E8
org.apache.maven.shared:maven-shared-utils = 0x84789D24DF77A32433CE1F079EB80E92EB2135B1
org.codehaus.plexus:plexus-archiver = 0x29BEA2A645F2D6CED7FB12E02B172E3E156466E8
org.codehaus.plexus:plexus-interpolation = 0x47063E8BA7A6450E4A52E7AE466CAED6E0747D50
org.codehaus.plexus:plexus-io = 0xF254B35617DC255D9344BCFA873A8E86B4372146
org.codehaus.plexus:plexus-archiver = 0x84789D24DF77A32433CE1F079EB80E92EB2135B1
org.codehaus.plexus:plexus-interpolation = 0xF254B35617DC255D9344BCFA873A8E86B4372146
org.codehaus.plexus:plexus-io = 0x09A808E1930F779CC6C54807E4C753D85335E876
org.codehaus.plexus:plexus-utils = 0xEA23DB1360D9029481E7F2EFECDFEA3CB4493B94
org.codehaus.plexus:plexus-xml = 0xFA77DCFEF2EE6EB2DEBEDD2C012579464D01C06A
org.hamcrest = 0xE3A9F95079E84CE201F7CF60BEDE11EAF1164480
org.slf4j:slf4j-api = 0x475F3B8E59E6E63AA78067482C7B12F2A511E325
48 changes: 41 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<description>Plugin to manage artifacts tasks</description>

<prerequisites>
<maven>${mavenVersion}</maven>
<maven>3.2.5</maven>
</prerequisites>

<scm>
Expand All @@ -60,7 +60,8 @@
</distributionManagement>

<properties>
<mavenVersion>3.2.5</mavenVersion>
<mavenVersion>3.9.6</mavenVersion>
<resolverVersion>1.9.18</resolverVersion>
<javaVersion>8</javaVersion>
<project.build.outputTimestamp>2024-03-29T06:57:38Z</project.build.outputTimestamp>
</properties>
Expand Down Expand Up @@ -91,16 +92,24 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-api</artifactId>
<version>1.0.0.v20140518</version>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-api</artifactId>
<version>${resolverVersion}</version>
<scope>provided</scope>
</dependency>
<!-- Scope: compile to support pre-3.9 -->
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-util</artifactId>
<version>${resolverVersion}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-xml</artifactId>
<version>3.0.0</version>
</dependency>
<!-- ONLY: MessageUtil -->
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-shared-utils</artifactId>
Expand All @@ -109,7 +118,7 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-archiver</artifactId>
<version>3.6.0</version>
<version>3.6.1</version>
<exclusions>
<exclusion>
<groupId>org.tukaani</groupId>
Expand All @@ -128,18 +137,43 @@
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.15</version>
<version>1.16.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.15.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<proc>none</proc>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.simplify4u.plugins</groupId>
<artifactId>pgpverify-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
Expand All @@ -42,9 +40,9 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.rtinfo.RuntimeInformation;
import org.apache.maven.shared.utils.io.FileUtils;
import org.apache.maven.toolchain.Toolchain;
import org.apache.maven.toolchain.ToolchainManager;
import org.eclipse.aether.artifact.Artifact;

/**
* Base buildinfo-generating class, for goals related to Reproducible Builds {@code .buildinfo} files.
Expand Down Expand Up @@ -126,9 +124,6 @@ public abstract class AbstractBuildinfoMojo extends AbstractMojo {
@Component
private ToolchainManager toolchainManager;

@Component
protected ArtifactHandlerManager artifactHandlerManager;

@Component
protected RuntimeInformation rtInformation;

Expand Down Expand Up @@ -163,8 +158,8 @@ public void execute() throws MojoExecutionException {

static boolean hasBadOutputTimestamp(
String outputTimestamp, Log log, MavenProject project, List<MavenProject> reactorProjects) {
MavenArchiver archiver = new MavenArchiver();
Date timestamp = archiver.parseOutputTimestamp(outputTimestamp);
Instant timestamp =
MavenArchiver.parseBuildOutputTimestamp(outputTimestamp).orElse(null);
if (timestamp == null) {
log.error("Reproducible Build not activated by project.build.outputTimestamp property: "
+ "see https://maven.apache.org/guides/mini/guide-reproducible-builds.html");
Expand Down Expand Up @@ -218,7 +213,11 @@ protected void copyAggregateToRoot(File aggregate) throws MojoExecutionException
File rootCopy =
new File(root.getBuild().getDirectory(), root.getArtifactId() + '-' + root.getVersion() + extension);
try {
FileUtils.copyFile(aggregate, rootCopy);
Files.copy(
aggregate.toPath(),
rootCopy.toPath(),
LinkOption.NOFOLLOW_LINKS,
StandardCopyOption.REPLACE_EXISTING);
getLog().info("Aggregate " + extension.substring(1) + " copied to " + rootCopy);
} catch (IOException ioe) {
throw new MojoExecutionException("Could not copy " + aggregate + " to " + rootCopy, ioe);
Expand All @@ -240,7 +239,7 @@ protected Map<Artifact, String> generateBuildinfo(boolean mono) throws MojoExecu

try (PrintWriter p = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(Files.newOutputStream(buildinfoFile.toPath()), StandardCharsets.UTF_8)))) {
BuildInfoWriter bi = new BuildInfoWriter(getLog(), p, mono, artifactHandlerManager, rtInformation);
BuildInfoWriter bi = new BuildInfoWriter(getLog(), p, mono, rtInformation);
bi.setIgnoreJavadoc(ignoreJavadoc);
bi.setIgnore(ignore);
bi.setToolchain(getToolchain());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@
import java.util.stream.Collectors;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.apache.maven.rtinfo.RuntimeInformation;
import org.apache.maven.shared.utils.PropertyUtils;
import org.apache.maven.shared.utils.StringUtils;
import org.apache.maven.toolchain.Toolchain;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.util.artifact.ArtifactIdUtils;

/**
* Buildinfo content writer.
Expand All @@ -46,24 +44,17 @@ class BuildInfoWriter {
private final Log log;
private final PrintWriter p;
private final boolean mono;
private final ArtifactHandlerManager artifactHandlerManager;
private final RuntimeInformation rtInformation;
private final Map<Artifact, String> artifacts = new LinkedHashMap<>();
private int projectCount = -1;
private boolean ignoreJavadoc = true;
private List<PathMatcher> ignore;
private Toolchain toolchain;

BuildInfoWriter(
Log log,
PrintWriter p,
boolean mono,
ArtifactHandlerManager artifactHandlerManager,
RuntimeInformation rtInformation) {
BuildInfoWriter(Log log, PrintWriter p, boolean mono, RuntimeInformation rtInformation) {
this.log = log;
this.p = p;
this.mono = mono;
this.artifactHandlerManager = artifactHandlerManager;
this.rtInformation = rtInformation;
}

Expand Down Expand Up @@ -162,32 +153,26 @@ void printArtifacts(MavenProject project) throws MojoExecutionException {
}

// detect Maven 4 consumer POM transient attachment
Artifact consumerPom = project.getAttachedArtifacts().stream()
.filter(a -> "pom".equals(a.getType()) && "consumer".equals(a.getClassifier()))
Artifact consumerPom = RepositoryUtils.toArtifacts(project.getAttachedArtifacts()).stream()
.filter(a -> "pom".equals(a.getExtension()) && "consumer".equals(a.getClassifier()))
.findAny()
.orElse(null);

int n = 0;
Artifact pomArtifact = new DefaultArtifact(
project.getGroupId(),
project.getArtifactId(),
project.getVersion(),
null,
"pom",
"",
artifactHandlerManager.getArtifactHandler("pom"));
Artifact pomArtifact =
new DefaultArtifact(project.getGroupId(), project.getArtifactId(), null, "pom", project.getVersion());
if (consumerPom != null) {
// Maven 4 transient consumer POM attachment is published as the POM, overrides build POM, see
// https://github.com/apache/maven/blob/c79a7a02721f0f9fd7e202e99f60b593461ba8cc/maven-core/src/main/java/org/apache/maven/internal/transformation/ConsumerPomArtifactTransformer.java#L130-L155
try {
Path pomFile = Files.createTempFile(Paths.get(project.getBuild().getDirectory()), "consumer-", ".pom");
Files.copy(consumerPom.getFile().toPath(), pomFile, StandardCopyOption.REPLACE_EXISTING);
pomArtifact.setFile(pomFile.toFile());
pomArtifact = pomArtifact.setFile(pomFile.toFile());
} catch (IOException e) {
p.println("Error processing consumer POM: " + e);
}
} else {
pomArtifact.setFile(project.getFile());
pomArtifact = pomArtifact.setFile(project.getFile());
}

artifacts.put(pomArtifact, prefix + n);
Expand All @@ -202,15 +187,15 @@ void printArtifacts(MavenProject project) throws MojoExecutionException {
}

if (project.getArtifact().getFile() != null) {
printArtifact(prefix, n++, project.getArtifact());
printArtifact(prefix, n++, RepositoryUtils.toArtifact(project.getArtifact()));
}

for (Artifact attached : project.getAttachedArtifacts()) {
for (Artifact attached : RepositoryUtils.toArtifacts(project.getAttachedArtifacts())) {
if (attached == consumerPom) {
// ignore consumer pom
continue;
}
if (attached.getType().endsWith(".asc")) {
if (attached.getExtension().endsWith(".asc")) {
// ignore pgp signatures
continue;
}
Expand All @@ -231,17 +216,18 @@ private void printArtifact(String prefix, int i, Artifact artifact) throws MojoE
prefix = prefix + i;
File artifactFile = artifact.getFile();
if (artifactFile.isDirectory()) {
if ("pom".equals(artifact.getType())) {
if ("pom".equals(artifact.getExtension())) {
// ignore .pom files: they should not be treated as Artifacts
return;
}
// edge case found in a distribution module with default packaging and skip set for
// m-jar-p: should use pom packaging instead
throw new MojoExecutionException("Artifact " + artifact.getId() + " points to a directory: " + artifactFile
+ ". Packaging should be 'pom'?");
throw new MojoExecutionException("Artifact " + ArtifactIdUtils.toId(artifact) + " points to a directory: "
+ artifactFile + ". Packaging should be 'pom'?");
}
if (!artifactFile.isFile()) {
log.warn("Ignoring artifact " + artifact.getId() + " because it points to inexistent " + artifactFile);
log.warn("Ignoring artifact " + ArtifactIdUtils.toId(artifact) + " because it points to inexistent "
+ artifactFile);
return;
}

Expand All @@ -254,14 +240,12 @@ static String getArtifactFilename(Artifact artifact) {

path.append(artifact.getArtifactId()).append('-').append(artifact.getBaseVersion());

if (artifact.hasClassifier()) {
if (!artifact.getClassifier().isEmpty()) {
path.append('-').append(artifact.getClassifier());
}

ArtifactHandler artifactHandler = artifact.getArtifactHandler();

if (StringUtils.isNotEmpty(artifactHandler.getExtension())) {
path.append('.').append(artifactHandler.getExtension());
if (!artifact.getExtension().isEmpty()) {
path.append('.').append(artifact.getExtension());
}

return path.toString();
Expand Down Expand Up @@ -297,7 +281,14 @@ Map<Artifact, String> getArtifacts() {
* @throws MojoExecutionException
*/
static Properties loadOutputProperties(File buildinfo) throws MojoExecutionException {
Properties prop = PropertyUtils.loadOptionalProperties(buildinfo);
Properties prop = new Properties();
if (buildinfo != null) {
try (InputStream is = Files.newInputStream(buildinfo.toPath())) {
prop.load(is);
} catch (IOException e) {
// silent
}
}
for (String name : prop.stringPropertyNames()) {
if (!name.startsWith("outputs.") || name.endsWith(".coordinates")) {
prop.remove(name);
Expand Down
Loading

0 comments on commit c9d385e

Please sign in to comment.