Skip to content

Commit 6ba6eb0

Browse files
authored
Make artifacts parameter possible to point at a file (#134)
That is the loaded up. File should contain artifact strings in expected format, each on new line. Add ITs for new mojo.
1 parent d066c2a commit 6ba6eb0

File tree

7 files changed

+94
-2
lines changed

7 files changed

+94
-2
lines changed

it/extension-its/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<name>${project.groupId}:${project.artifactId}</name>
2424

2525
<properties>
26-
<maven39Version>3.9.9</maven39Version>
26+
<maven39Version>3.9.10</maven39Version>
2727
<maven4Version>4.0.0-rc-3</maven4Version>
2828

2929
<!-- We need to skip this on Java lower than 17 (see profiles below) -->
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (c) 2023-2024 Maveniverse Org.
5+
All rights reserved. This program and the accompanying materials
6+
are made available under the terms of the Eclipse Public License v2.0
7+
which accompanies this distribution, and is available at
8+
https://www.eclipse.org/legal/epl-v20.html
9+
10+
-->
11+
<extensions>
12+
<extension>
13+
<groupId>eu.maveniverse.maven.njord</groupId>
14+
<artifactId>extension</artifactId>
15+
<version>@project.version@</version>
16+
</extension>
17+
</extensions>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Check Artifacts Availability
2+
3+
Tests njord:check-artifacts-availability.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#
2+
# Copyright (c) 2023-2024 Maveniverse Org.
3+
# All rights reserved. This program and the accompanying materials
4+
# are made available under the terms of the Eclipse Public License v2.0
5+
# which accompanies this distribution, and is available at
6+
# https://www.eclipse.org/legal/epl-v20.html
7+
#
8+
9+
# from CLI
10+
invoker.goals.1 = -V -e njord:${project.version}:check-artifacts-availability -DwaitSleep=PT1S -DwaitDelay=PT1S -DwaitTimeout=PT10S "-Dartifacts=junit:junit:jar:4.13.2,junit:junit:pom:4.13.2" -DremoteRepository=central::https://repo.maven.apache.org/maven2/
11+
# from file
12+
invoker.goals.2 = -V -e njord:${project.version}:check-artifacts-availability -DwaitSleep=PT1S -DwaitDelay=PT1S -DwaitTimeout=PT10S -Dartifacts=list.txt -DremoteRepository=central::https://repo.maven.apache.org/maven2/
13+
# from CLI (failing)
14+
invoker.goals.3 = -V -e njord:${project.version}:check-artifacts-availability -DwaitSleep=PT1S -DwaitDelay=PT1S -DwaitTimeout=PT10S "-Dartifacts=junit:junit:jar:4.13.2,junit:junit:pom:4.13.2,nonexistent:nonexistent:1.0" -DremoteRepository=central::https://repo.maven.apache.org/maven2/
15+
invoker.buildResult.3 = failure
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# list of artifacts to check
2+
junit:junit:jar:4.13.2
3+
junit:junit:pom:4.13.2
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (c) 2023-2024 Maveniverse Org.
5+
All rights reserved. This program and the accompanying materials
6+
are made available under the terms of the Eclipse Public License v2.0
7+
which accompanies this distribution, and is available at
8+
https://www.eclipse.org/legal/epl-v20.html
9+
10+
-->
11+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
12+
<modelVersion>4.0.0</modelVersion>
13+
14+
<groupId>eu.maveniverse.maven.njord.it</groupId>
15+
<artifactId>check-artifacts-availability-manual-pom</artifactId>
16+
<version>1.0.0</version>
17+
18+
<name>${project.groupId}:${project.artifactId}</name>
19+
<description>Unused, just load up extension/plugin and have invoker copy this project</description>
20+
21+
<build>
22+
<plugins>
23+
<plugin>
24+
<groupId>eu.maveniverse.maven.plugins</groupId>
25+
<artifactId>njord</artifactId>
26+
<version>@project.version@</version>
27+
</plugin>
28+
</plugins>
29+
</build>
30+
</project>

plugin/src/main/java/eu/maveniverse/maven/njord/plugin3/CheckArtifactsAvailabilityMojo.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
import eu.maveniverse.maven.njord.shared.store.ArtifactStore;
1414
import eu.maveniverse.maven.njord.shared.store.RepositoryMode;
1515
import java.io.IOException;
16+
import java.nio.file.Files;
17+
import java.nio.file.InvalidPathException;
18+
import java.nio.file.Path;
19+
import java.nio.file.Paths;
1620
import java.time.Duration;
1721
import java.time.Instant;
1822
import java.util.ArrayList;
@@ -89,6 +93,10 @@ public class CheckArtifactsAvailabilityMojo extends PublisherSupportMojo {
8993
* The comma separated list of artifacts to check availability for. If this parameter is set, the mojo
9094
* will use this list instead to go for {@link ArtifactStore}. The comma separated list should contain
9195
* artifacts in form of {@code <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>}.
96+
* <p>
97+
* Parameter may point to an existing text file as well, which contains on each line an artifact string
98+
* in format above. The file may contain empty lines and lines starting with {@code #} (comments) that
99+
* are ignored.
92100
*/
93101
@Parameter(property = "artifacts")
94102
private String artifacts;
@@ -107,8 +115,24 @@ public class CheckArtifactsAvailabilityMojo extends PublisherSupportMojo {
107115
@Override
108116
protected void doWithSession(Session ns) throws IOException, MojoFailureException {
109117
if (artifacts != null) {
118+
try {
119+
Path artifactsFile = Paths.get(artifacts);
120+
if (Files.exists(artifactsFile) && !Files.isDirectory(artifactsFile)) {
121+
logger.debug("Mojo parameter artifacts points to an existing file; loading it up");
122+
this.artifacts = Files.readAllLines(artifactsFile).stream()
123+
.map(String::trim)
124+
.filter(l -> !l.isEmpty())
125+
.filter(line -> !line.startsWith("#"))
126+
.collect(Collectors.joining(","));
127+
}
128+
} catch (InvalidPathException e) {
129+
// ignore
130+
}
131+
logger.debug("Artifacts list: {}", this.artifacts);
110132
HashSet<Boolean> snaps = new HashSet<>();
111-
List<Artifact> artifacts = Arrays.stream(this.artifacts.split(","))
133+
List<Artifact> artifacts = Arrays.stream(this.artifacts.split("[,\\s]"))
134+
.map(String::trim)
135+
.filter(l -> !l.isEmpty())
112136
.map(DefaultArtifact::new)
113137
.peek(a -> snaps.add(a.isSnapshot()))
114138
.collect(Collectors.toList());

0 commit comments

Comments
 (0)