Skip to content

Commit 22efbcf

Browse files
authored
Install publisher (#274)
Add new "install" publisher that is able to install (to local repository, just like m-install-p does) the artifact store. Added two ITs as well that start from scratch, by importing a NTB and install them, with snapshots and releases.
1 parent dafb064 commit 22efbcf

File tree

26 files changed

+423
-20
lines changed

26 files changed

+423
-20
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public Optional<Model> readEffectiveModel(Artifact artifact, List<RemoteReposito
151151
try {
152152
ModelResponse response = mavenModelReader.readModel(
153153
new DefaultRepositorySystemSession(config.session())
154-
.setTransferListener(new NjordTransferListener()),
154+
.setTransferListener(new NjordTransferListener(true)),
155155
ModelRequest.builder()
156156
.setArtifact(artifact)
157157
.setRepositories(remoteRepositories)

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

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,34 @@
2626
public class NjordTransferListener extends AbstractTransferListener {
2727
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
2828

29+
private final boolean silent;
30+
31+
public NjordTransferListener(boolean silent) {
32+
this.silent = silent;
33+
}
34+
2935
@Override
3036
public void transferSucceeded(TransferEvent event) {
3137
String action = (event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploaded" : "Downloaded");
3238
String direction = event.getRequestType() == TransferEvent.RequestType.PUT ? "to" : "from";
3339
TransferResource resource = event.getResource();
34-
logger.debug(
35-
"{} {} {}: {}{}",
36-
action,
37-
direction,
38-
resource.getRepositoryId(),
39-
resource.getRepositoryUrl(),
40-
resource.getResourceName());
40+
if (silent) {
41+
logger.debug(
42+
"{} {} {}: {}{}",
43+
action,
44+
direction,
45+
resource.getRepositoryId(),
46+
resource.getRepositoryUrl(),
47+
resource.getResourceName());
48+
} else {
49+
logger.info(
50+
"{} {} {}: {}{}",
51+
action,
52+
direction,
53+
resource.getRepositoryId(),
54+
resource.getRepositoryUrl(),
55+
resource.getResourceName());
56+
}
4157
}
4258

4359
@Override
@@ -48,13 +64,23 @@ public void transferFailed(TransferEvent event) {
4864
// if we are called here without exception = bug in resolver/maven
4965
Exception exception = requireNonNull(event.getException());
5066
if (event.getRequestType() != TransferEvent.RequestType.PUT && exception instanceof ArtifactNotFoundException) {
51-
logger.debug(
52-
"Failed {} {} {}: {}{}; not found",
53-
action,
54-
direction,
55-
resource.getRepositoryId(),
56-
resource.getRepositoryUrl(),
57-
resource.getResourceName());
67+
if (silent) {
68+
logger.debug(
69+
"Failed {} {} {}: {}{}; not found",
70+
action,
71+
direction,
72+
resource.getRepositoryId(),
73+
resource.getRepositoryUrl(),
74+
resource.getResourceName());
75+
} else {
76+
logger.info(
77+
"Failed {} {} {}: {}{}; not found",
78+
action,
79+
direction,
80+
resource.getRepositoryId(),
81+
resource.getRepositoryUrl(),
82+
resource.getResourceName());
83+
}
5884
} else {
5985
logger.warn(
6086
"Failed {} {} {}: {}{}; {}",

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
import org.eclipse.aether.repository.RemoteRepository;
2424

2525
/**
26-
* Helper class.
26+
* Helper class, that uses {@link RepositorySystem#deploy(RepositorySystemSession, DeployRequest)} calls to perform
27+
* deploys "just like maven-deploy-plugin would".
2728
*/
2829
public class ArtifactStoreDeployer extends ComponentSupport {
2930
private final RepositorySystem repositorySystem;
@@ -42,6 +43,9 @@ public ArtifactStoreDeployer(
4243
this.repositoryPrepared = repositoryPrepared;
4344
}
4445

46+
/**
47+
* Deploys all artifacts from the store.
48+
*/
4549
public void deploy(ArtifactStore artifactStore) throws IOException {
4650
requireNonNull(artifactStore);
4751
deploy(
@@ -51,6 +55,9 @@ public void deploy(ArtifactStore artifactStore) throws IOException {
5155
.collect(Collectors.toList()));
5256
}
5357

58+
/**
59+
* Deploys given artifacts from the store. This is useful when we need to deploy only a subset of the store.
60+
*/
5461
public void deploy(ArtifactStore artifactStore, Collection<Artifact> artifacts) throws IOException {
5562
requireNonNull(artifactStore);
5663
requireNonNull(artifacts);
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
package eu.maveniverse.maven.njord.shared.impl.store;
9+
10+
import static java.util.Objects.requireNonNull;
11+
12+
import eu.maveniverse.maven.njord.shared.store.ArtifactStore;
13+
import eu.maveniverse.maven.shared.core.component.ComponentSupport;
14+
import java.io.IOException;
15+
import java.util.Collection;
16+
import java.util.stream.Collectors;
17+
import org.eclipse.aether.RepositorySystem;
18+
import org.eclipse.aether.RepositorySystemSession;
19+
import org.eclipse.aether.RequestTrace;
20+
import org.eclipse.aether.artifact.Artifact;
21+
import org.eclipse.aether.installation.InstallRequest;
22+
import org.eclipse.aether.installation.InstallationException;
23+
24+
/**
25+
* Helper class, that uses {@link RepositorySystem#install(RepositorySystemSession, InstallRequest)} calls to perform
26+
* installs "just like maven-install-plugin would".
27+
*/
28+
public class ArtifactStoreInstaller extends ComponentSupport {
29+
private final RepositorySystem repositorySystem;
30+
private final RepositorySystemSession repositorySystemSession;
31+
32+
public ArtifactStoreInstaller(RepositorySystem repositorySystem, RepositorySystemSession repositorySystemSession) {
33+
this.repositorySystem = requireNonNull(repositorySystem);
34+
this.repositorySystemSession = requireNonNull(repositorySystemSession);
35+
}
36+
37+
/**
38+
* Installs all artifacts from the store.
39+
*/
40+
public void install(ArtifactStore artifactStore) throws IOException {
41+
requireNonNull(artifactStore);
42+
install(
43+
artifactStore,
44+
artifactStore.artifacts().stream()
45+
.map(a -> a.setVersion(a.getBaseVersion()))
46+
.collect(Collectors.toList()));
47+
}
48+
49+
/**
50+
* Installs given artifacts from the store. This is useful when we need to install only a subset of the store.
51+
*/
52+
public void install(ArtifactStore artifactStore, Collection<Artifact> artifacts) throws IOException {
53+
requireNonNull(artifactStore);
54+
requireNonNull(artifacts);
55+
InstallRequest installRequest = new InstallRequest();
56+
installRequest.setArtifacts(artifacts);
57+
installRequest.setTrace(new RequestTrace(artifactStore));
58+
try {
59+
repositorySystem.install(repositorySystemSession, installRequest);
60+
} catch (InstallationException e) {
61+
throw new IOException(e);
62+
}
63+
}
64+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void redeploy(ArtifactStore source, ArtifactStore target) throws IOExcept
5959
new ArtifactStoreDeployer(
6060
repositorySystem,
6161
new DefaultRepositorySystemSession(sessionConfig.session())
62-
.setTransferListener(new NjordTransferListener()),
62+
.setTransferListener(new NjordTransferListener(true)),
6363
new RemoteRepository.Builder(targetName, "default", "njord:store:" + targetName).build(),
6464
true)
6565
.deploy(from);
@@ -110,7 +110,7 @@ public void merge(ArtifactStore source, ArtifactStore target) throws IOException
110110
new ArtifactStoreDeployer(
111111
repositorySystem,
112112
new DefaultRepositorySystemSession(sessionConfig.session())
113-
.setTransferListener(new NjordTransferListener()),
113+
.setTransferListener(new NjordTransferListener(true)),
114114
new RemoteRepository.Builder(targetName, "default", "njord:store:" + targetName).build(),
115115
true)
116116
.deploy(from, toBeWritten);

extension3/pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@
2626
<groupId>eu.maveniverse.maven.njord</groupId>
2727
<artifactId>core</artifactId>
2828
</dependency>
29+
<dependency>
30+
<groupId>eu.maveniverse.maven.njord.publisher</groupId>
31+
<artifactId>apache</artifactId>
32+
</dependency>
2933
<dependency>
3034
<groupId>eu.maveniverse.maven.njord.publisher</groupId>
3135
<artifactId>deploy</artifactId>
3236
</dependency>
3337
<dependency>
3438
<groupId>eu.maveniverse.maven.njord.publisher</groupId>
35-
<artifactId>apache</artifactId>
39+
<artifactId>install</artifactId>
3640
</dependency>
3741
<dependency>
3842
<groupId>eu.maveniverse.maven.njord.publisher</groupId>

it/extension-its/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
<cloneClean>true</cloneClean>
9191
<pomIncludes>
9292
<pomInclude>*/pom.xml</pomInclude>
93+
<pomInclude>*/fake-pom.xml</pomInclude>
9394
</pomIncludes>
9495
<scriptVariables>
9596
<projectVersion>${project.version}</projectVersion>

it/extension-its/src/it/import-install-release/.mvn/placeholder

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Import-Install
2+
3+
Tests imports a NTB and installs it into local repository.
4+
5+
In this test we have no project nor POM, as we are only interested in the import and installation of the NTB.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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>import-install</artifactId>
16+
<version>1.0.0</version>
17+
18+
<name>${project.groupId}:${project.artifactId}</name>
19+
20+
<!-- "fake pom" just to trigger invoker plugin -->
21+
22+
</project>

0 commit comments

Comments
 (0)