Skip to content

Commit cb41aa6

Browse files
authored
Parent POM 49 (#240)
And some other minor updates. Added workaround for nx3 publisher IT (that needs manual intervention to run) and Maven 4.0.0-rc-5.
1 parent 6f85110 commit cb41aa6

File tree

16 files changed

+107
-47
lines changed

16 files changed

+107
-47
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
build:
1111
name: Verify
12-
uses: maveniverse/parent/.github/workflows/ci.yml@release-48.1
12+
uses: maveniverse/parent/.github/workflows/ci.yml@release-49
1313
with:
1414
maven-matrix: '[ "3.9.12" ]' # IT does the mvn matrix
1515
maven-test: './mvnw clean verify -e -B -V -P run-its -f it'

core/src/main/java/eu/maveniverse/maven/njord/shared/Session.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ default Optional<ArtifactStoreComparator> selectArtifactStoreComparator(String n
9393
*/
9494
ArtifactStoreTemplate selectSessionArtifactStoreTemplate(String uri);
9595

96+
/**
97+
* Returns {@code true} if this repository should be handled by connector. Calls to
98+
* {@link #getOrCreateSessionArtifactStore(RemoteRepository, String)} must be protected by this method.
99+
*/
100+
boolean handleRemoteRepository(RemoteRepository repository);
101+
96102
/**
97103
* Creates session-bound artifact store and memoize it during session.
98104
* {@code repoId::njord:}

core/src/main/java/eu/maveniverse/maven/njord/shared/impl/DefaultSession.java

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@
4040
import java.util.concurrent.atomic.AtomicInteger;
4141
import java.util.stream.Collectors;
4242
import org.apache.maven.model.Model;
43+
import org.apache.maven.rtinfo.RuntimeInformation;
4344
import org.eclipse.aether.DefaultRepositorySystemSession;
4445
import org.eclipse.aether.artifact.Artifact;
4546
import org.eclipse.aether.repository.RemoteRepository;
4647

4748
public class DefaultSession extends CloseableConfigSupport<SessionConfig> implements Session {
48-
private final String sessionBoundStoreKey;
49+
private final RuntimeInformation mavenRuntimeInformation;
50+
private final String sessionBoundStoresKey;
4951
private final InternalArtifactStoreManager internalArtifactStoreManager;
5052
private final ArtifactStoreWriter artifactStoreWriter;
5153
private final ArtifactStoreMerger artifactStoreMerger;
@@ -56,6 +58,7 @@ public class DefaultSession extends CloseableConfigSupport<SessionConfig> implem
5658

5759
public DefaultSession(
5860
SessionConfig sessionConfig,
61+
RuntimeInformation mavenRuntimeInformation,
5962
InternalArtifactStoreManagerFactory internalArtifactStoreManagerFactory,
6063
ArtifactStoreWriterFactory artifactStoreWriterFactory,
6164
ArtifactStoreMergerFactory artifactStoreMergerFactory,
@@ -64,7 +67,8 @@ public DefaultSession(
6467
Map<String, ArtifactStoreComparatorFactory> artifactStoreComparatorFactories,
6568
MavenModelReaderImpl mavenModelReader) {
6669
super(sessionConfig);
67-
this.sessionBoundStoreKey = Session.class.getName() + "." + ArtifactStore.class + "." + UUID.randomUUID();
70+
this.mavenRuntimeInformation = requireNonNull(mavenRuntimeInformation);
71+
this.sessionBoundStoresKey = Session.class.getName() + "." + ArtifactStore.class + "." + UUID.randomUUID();
6872
this.internalArtifactStoreManager = internalArtifactStoreManagerFactory.create(sessionConfig);
6973
this.artifactStoreWriter = requireNonNull(artifactStoreWriterFactory).create(sessionConfig);
7074
this.artifactStoreMerger = requireNonNull(artifactStoreMergerFactory).create(sessionConfig);
@@ -181,12 +185,34 @@ public ArtifactStoreTemplate selectSessionArtifactStoreTemplate(String uri) {
181185
}
182186
}
183187

188+
@Override
189+
public boolean handleRemoteRepository(RemoteRepository repository) {
190+
requireNonNull(repository);
191+
checkClosed();
192+
if (mavenRuntimeInformation.isMavenVersion("[4.0.0-rc-5,4.0.0-rc-5]")) {
193+
// BEGIN: workaround for Maven 4.0.0-rc-5 (only)
194+
// IF: repoId is in form '[some string]-hex' (hex part is 40 char long; sha1)
195+
// THEN: chop it off, and check if "some string" ID repo is already present
196+
if (repository.getId().length() > 41
197+
&& repository
198+
.getId()
199+
.substring(repository.getId().length() - 41)
200+
.matches("-[0-9a-f]+")) {
201+
String id = repository.getId().substring(0, repository.getId().length() - 41);
202+
return getSessionBoundStores().keySet().stream().noneMatch(r -> id.equals(r.getId()));
203+
}
204+
// END: workaround for Maven 4.0.0-rc-5 (only)
205+
}
206+
return true;
207+
}
208+
184209
@Override
185210
public ArtifactStore getOrCreateSessionArtifactStore(RemoteRepository repository, String uri) {
211+
requireNonNull(repository);
186212
requireNonNull(uri);
187213
checkClosed();
188-
ConcurrentMap<RemoteRepository, String> sessionBoundStore = getSessionBoundStore();
189-
String storeName = sessionBoundStore.computeIfAbsent(repository, k -> {
214+
ConcurrentMap<RemoteRepository, String> sessionBoundStores = getSessionBoundStores();
215+
String storeName = sessionBoundStores.computeIfAbsent(repository, r -> {
190216
try {
191217
String artifactStoreName;
192218
boolean isNewArtifactStore = true;
@@ -223,7 +249,9 @@ public ArtifactStore getOrCreateSessionArtifactStore(RemoteRepository repository
223249
} else {
224250
throw new IllegalArgumentException("Invalid repository URI: " + uri);
225251
}
226-
logger.info("Created Njord artifact store {} for remote repository {}", artifactStoreName, repository);
252+
if (isNewArtifactStore) {
253+
logger.info("Created Njord artifact store {} for remote repository {}", artifactStoreName, r);
254+
}
227255
return artifactStoreName;
228256
} catch (IOException e) {
229257
throw new UncheckedIOException(e);
@@ -264,8 +292,8 @@ private String createUsingTemplate(String templateName) throws IOException {
264292
@Override
265293
public int publishSessionArtifactStores() throws IOException {
266294
checkClosed();
267-
ConcurrentMap<RemoteRepository, String> sessionBoundStore = getSessionBoundStore();
268-
if (sessionBoundStore.isEmpty()) {
295+
ConcurrentMap<RemoteRepository, String> sessionBoundStores = getSessionBoundStores();
296+
if (sessionBoundStores.isEmpty()) {
269297
return 0;
270298
}
271299
AtomicInteger result = new AtomicInteger(0);
@@ -275,7 +303,7 @@ public int publishSessionArtifactStores() throws IOException {
275303
Optional<ArtifactStorePublisher> po = selectArtifactStorePublisher(publisherName);
276304
if (po.isPresent()) {
277305
ArtifactStorePublisher p = po.orElseThrow(J8Utils.OET);
278-
for (String storeName : sessionBoundStore.values()) {
306+
for (String storeName : sessionBoundStores.values()) {
279307
logger.info("Publishing {} with {}", storeName, publisherName);
280308
try (ArtifactStore as = internalArtifactStoreManager
281309
.selectArtifactStore(storeName)
@@ -300,12 +328,12 @@ public int publishSessionArtifactStores() throws IOException {
300328
@Override
301329
public int dropSessionArtifactStores() {
302330
checkClosed();
303-
ConcurrentMap<RemoteRepository, String> sessionBoundStore = getSessionBoundStore();
304-
if (sessionBoundStore.isEmpty()) {
331+
ConcurrentMap<RemoteRepository, String> sessionBoundStores = getSessionBoundStores();
332+
if (sessionBoundStores.isEmpty()) {
305333
return 0;
306334
}
307335
AtomicInteger result = new AtomicInteger(0);
308-
for (String storeName : sessionBoundStore.values()) {
336+
for (String storeName : sessionBoundStores.values()) {
309337
try {
310338
if (internalArtifactStoreManager.dropArtifactStore(storeName)) {
311339
result.addAndGet(1);
@@ -326,8 +354,8 @@ protected void doClose() throws IOException {
326354
* Returns map of "Njord URI" to "storeName" that were created in current session.
327355
*/
328356
@SuppressWarnings("unchecked")
329-
private ConcurrentMap<RemoteRepository, String> getSessionBoundStore() {
357+
private ConcurrentMap<RemoteRepository, String> getSessionBoundStores() {
330358
return (ConcurrentHashMap<RemoteRepository, String>)
331-
config.session().getData().computeIfAbsent(sessionBoundStoreKey, ConcurrentHashMap::new);
359+
config.session().getData().computeIfAbsent(sessionBoundStoresKey, ConcurrentHashMap::new);
332360
}
333361
}

core/src/main/java/eu/maveniverse/maven/njord/shared/impl/DefaultSessionFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
import javax.inject.Inject;
2222
import javax.inject.Named;
2323
import javax.inject.Singleton;
24+
import org.apache.maven.rtinfo.RuntimeInformation;
2425

2526
@Singleton
2627
@Named
2728
public class DefaultSessionFactory implements SessionFactory {
29+
private final RuntimeInformation mavenRuntimeInformation;
2830
private final InternalArtifactStoreManagerFactory internalArtifactStoreManagerFactory;
2931
private final ArtifactStoreWriterFactory artifactStoreWriterFactory;
3032
private final ArtifactStoreMergerFactory artifactStoreMergerFactory;
@@ -35,13 +37,15 @@ public class DefaultSessionFactory implements SessionFactory {
3537

3638
@Inject
3739
public DefaultSessionFactory(
40+
RuntimeInformation mavenRuntimeInformation,
3841
InternalArtifactStoreManagerFactory internalArtifactStoreManagerFactory,
3942
ArtifactStoreWriterFactory artifactStoreWriterFactory,
4043
ArtifactStoreMergerFactory artifactStoreMergerFactory,
4144
ArtifactPublisherRedirectorFactory artifactPublisherRedirectorFactory,
4245
Map<String, ArtifactStorePublisherFactory> artifactStorePublisherFactories,
4346
Map<String, ArtifactStoreComparatorFactory> artifactStoreComparatorFactories,
4447
MavenModelReaderImpl mavenModelReader) {
48+
this.mavenRuntimeInformation = requireNonNull(mavenRuntimeInformation);
4549
this.internalArtifactStoreManagerFactory = requireNonNull(internalArtifactStoreManagerFactory);
4650
this.artifactStoreWriterFactory = requireNonNull(artifactStoreWriterFactory);
4751
this.artifactStoreMergerFactory = requireNonNull(artifactStoreMergerFactory);
@@ -55,6 +59,7 @@ public DefaultSessionFactory(
5559
public DefaultSession create(SessionConfig sessionConfig) {
5660
return new DefaultSession(
5761
sessionConfig,
62+
mavenRuntimeInformation,
5863
internalArtifactStoreManagerFactory,
5964
artifactStoreWriterFactory,
6065
artifactStoreMergerFactory,

core/src/test/java/eu/maveniverse/maven/njord/shared/impl/publisher/PublisherTestSupport.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.util.Map;
4040
import java.util.Optional;
4141
import java.util.stream.Collectors;
42+
import org.apache.maven.rtinfo.RuntimeInformation;
4243
import org.eclipse.aether.RepositorySystemSession;
4344
import org.eclipse.aether.artifact.Artifact;
4445
import org.eclipse.aether.internal.impl.checksum.DefaultChecksumAlgorithmFactorySelector;
@@ -140,6 +141,17 @@ protected Session createSession(Context context, SessionConfig config) {
140141
HashMap<String, ArtifactStorePublisherFactory> publishers = new HashMap<>();
141142
publishers.put("sonatype-cp", c -> sonatypeCp());
142143
SessionFactory factory = new DefaultSessionFactory(
144+
new RuntimeInformation() {
145+
@Override
146+
public String getMavenVersion() {
147+
return "3.9.11";
148+
}
149+
150+
@Override
151+
public boolean isMavenVersion(String s) {
152+
return getMavenVersion().equals(s);
153+
}
154+
},
143155
new DefaultInternalArtifactStoreManagerFactory(checksumAlgorithmFactorySelector),
144156
new DefaultArtifactStoreWriterFactory(),
145157
new DefaultArtifactStoreMergerFactory(context.repositorySystem(), checksumAlgorithmFactorySelector),

extension3/src/main/java/eu/maveniverse/maven/njord/extension3/NjordRepositoryConnectorFactory.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,20 @@ public RepositoryConnector newInstance(RepositorySystemSession session, RemoteRe
5757
Optional<Session> nso = NjordUtils.mayGetNjordSession(session);
5858
if (nso.isPresent()) {
5959
Session ns = nso.orElseThrow(J8Utils.OET);
60-
String url = ns.artifactPublisherRedirector().getRepositoryUrl(repository);
61-
if (url != null && url.startsWith(NAME + ":")) {
62-
RepositoryConnectorFactory basicRepositoryConnectorFactory = requireNonNull(
63-
repositoryConnectorFactories.get("basic").get(),
64-
"No basic repository connector factory found");
65-
ArtifactStore artifactStore = ns.getOrCreateSessionArtifactStore(repository, url.substring(6));
66-
return new NjordRepositoryConnector(
67-
artifactStore,
68-
repository,
69-
basicRepositoryConnectorFactory.newInstance(
70-
artifactStore.storeRepositorySession(session),
71-
artifactStore.storeRemoteRepository()));
60+
if (ns.handleRemoteRepository(repository)) {
61+
String url = ns.artifactPublisherRedirector().getRepositoryUrl(repository);
62+
if (url != null && url.startsWith(NAME + ":")) {
63+
RepositoryConnectorFactory basicRepositoryConnectorFactory = requireNonNull(
64+
repositoryConnectorFactories.get("basic").get(),
65+
"No basic repository connector factory found");
66+
ArtifactStore artifactStore = ns.getOrCreateSessionArtifactStore(repository, url.substring(6));
67+
return new NjordRepositoryConnector(
68+
artifactStore,
69+
repository,
70+
basicRepositoryConnectorFactory.newInstance(
71+
artifactStore.storeRepositorySession(session),
72+
artifactStore.storeRemoteRepository()));
73+
}
7274
}
7375
}
7476
}

it/extension-its/pom.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
<name>${project.groupId}:${project.artifactId}</name>
2424

2525
<properties>
26-
<maven39Version>3.9.11</maven39Version>
27-
<maven4Version>4.0.0-rc-4</maven4Version>
28-
2926
<!-- We need to skip this on Java lower than 17 (see profiles below) -->
3027
<mvn4-its-run.skip>true</mvn4-its-run.skip>
3128
</properties>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# Merge All (Release)
22

33
Tests import-all and merge-all usage of Njord.
4+
5+
Note: Maven4 must have consumer POM feature disabled as it inlines the pom (and will end up different).

it/extension-its/src/it/merge-all-release/invoker.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
# 0th: clean
1010
invoker.goals.1 = -V -e njord:${project.version}:drop-all -Dyes
1111
# 1st: deploy/stage
12-
invoker.goals.2 = -V -e clean deploy -DaltDeploymentRepository=id::njord:release-sca -l l01.log -Dattach-classifier=first
12+
invoker.goals.2 = -V -e clean deploy -DaltDeploymentRepository=id::njord:release-sca -l l01.log -Dattach-classifier=first -Dmaven.consumer.pom=false
1313
# 2nd: deploy/stage
14-
invoker.goals.3 = -V -e clean deploy -DaltDeploymentRepository=id::njord:release-sca -l l02.log -Dattach-classifier=second
14+
invoker.goals.3 = -V -e clean deploy -DaltDeploymentRepository=id::njord:release-sca -l l02.log -Dattach-classifier=second -Dmaven.consumer.pom=false
1515
# 3rd: export first
1616
invoker.goals.4 = -V -e njord:${project.version}:export -Dstore=merge-all-release-00001 -l l03.log
1717
# 4th: export second

it/extension-its/src/it/merge-release/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
Tests merge usage of Njord.
44

5-
Merge is supported only be RELEASE stores, and assumption is that build is reproducible.
5+
Merge is supported only be RELEASE stores, and assumption is that build is reproducible.
6+
7+
Note: Maven4 must have consumer POM feature disabled as it inlines the pom (and will end up different).

0 commit comments

Comments
 (0)