diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 26785ace6..fa96754e9 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -40,7 +40,7 @@ jobs:
- uses: actions/upload-artifact@v4
if: failure()
with:
- name: surefire-reports
+ name: surefire-reports-${{ matrix.os }}-${{ matrix.jdk }}
path: '**/surefire-reports/*.txt'
pmd:
name: ubuntu-latest-pmd
diff --git a/integration-tests/src/test/java/org/wildfly/prospero/it/cli/CacheManifestTest.java b/integration-tests/src/test/java/org/wildfly/prospero/it/cli/CacheManifestTest.java
index cc89893d8..3d75c6d7a 100644
--- a/integration-tests/src/test/java/org/wildfly/prospero/it/cli/CacheManifestTest.java
+++ b/integration-tests/src/test/java/org/wildfly/prospero/it/cli/CacheManifestTest.java
@@ -102,8 +102,10 @@ public void setUp() throws Exception {
));
// create and deploy second manifest
- secondManifest = new ChannelManifest(null, null, null, null,
- List.of(new Stream("org.wildfly.core", "wildfly-controller", UPGRADE_VERSION)));
+ secondManifest = new ChannelManifest.Builder()
+ .setSchemaVersion("1.0.0")
+ .addStreams(new Stream("org.wildfly.core", "wildfly-controller", UPGRADE_VERSION))
+ .build();
repositoryUtils.deployArtifact(new DefaultArtifact(
"org.test.channels",
"wf-core-second",
@@ -321,7 +323,7 @@ public void updateWithManifestNotInCacheAndNotAvailableFails() throws Exception
assertThatThrownBy(()->performUpdate())
.isInstanceOf(UnresolvedChannelMetadataException.class)
.hasFieldOrPropertyWithValue("missingArtifacts",
- Set.of(new ChannelMetadataCoordinate("org.test.channels", "wf-core-base", "",
+ Set.of(new ChannelMetadataCoordinate("org.test.channels", "wf-core-base", "1.0.0",
ChannelManifest.CLASSIFIER, ChannelManifest.EXTENSION)));
}
@@ -383,6 +385,7 @@ private ChannelManifest updateWildflyController() throws MalformedURLException {
return new ChannelManifest(
sourceManifest.getSchemaVersion(),
sourceManifest.getId(),
+ sourceManifest.getLogicalVersion(),
sourceManifest.getDescription(),
sourceManifest.getManifestRequirements(),
streams);
diff --git a/pom.xml b/pom.xml
index cd1b2b6a9..2e0c3963a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -68,13 +68,13 @@
7.2.0.Final
2.0.0.Beta1
2.4.1.Final
- 1.2.1.Final
+ 1.3.0.Beta1
5.14.1
2.0.7
2.2
4.13.2
3.6.0
- 1.1.0.Final
+ 1.2.0.Final
3.10.1
33.0.2.Final
4.7.6
diff --git a/prospero-common/src/main/java/org/wildfly/prospero/actions/InstallationHistoryAction.java b/prospero-common/src/main/java/org/wildfly/prospero/actions/InstallationHistoryAction.java
index 727508f19..8f479894f 100644
--- a/prospero-common/src/main/java/org/wildfly/prospero/actions/InstallationHistoryAction.java
+++ b/prospero-common/src/main/java/org/wildfly/prospero/actions/InstallationHistoryAction.java
@@ -142,7 +142,7 @@ public void prepareRevert(SavedState savedState, MavenOptions mavenOptions, List
prepareCandidateAction.buildCandidate(targetDir, galleonEnv,
ApplyCandidateAction.Type.REVERT, provisioningConfig,
- UpdateSet.EMPTY, (channels) -> revertMetadata.getManifestVersions());
+ UpdateSet.EMPTY, revertMetadata::getManifestVersions);
}
ProsperoLogger.ROOT_LOGGER.revertCandidateCompleted(targetDir);
diff --git a/prospero-common/src/main/java/org/wildfly/prospero/actions/PrepareCandidateAction.java b/prospero-common/src/main/java/org/wildfly/prospero/actions/PrepareCandidateAction.java
index edbfd2199..f75fd9da0 100644
--- a/prospero-common/src/main/java/org/wildfly/prospero/actions/PrepareCandidateAction.java
+++ b/prospero-common/src/main/java/org/wildfly/prospero/actions/PrepareCandidateAction.java
@@ -17,6 +17,8 @@
package org.wildfly.prospero.actions;
+import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.RepositorySystem;
import org.jboss.galleon.Constants;
import org.jboss.galleon.ProvisioningException;
import org.jboss.logging.Logger;
@@ -36,6 +38,7 @@
import org.wildfly.prospero.galleon.GalleonUtils;
import org.wildfly.prospero.licenses.LicenseManager;
import org.wildfly.prospero.metadata.ManifestVersionRecord;
+import org.wildfly.prospero.metadata.ManifestVersionResolver;
import org.wildfly.prospero.metadata.ProsperoMetadataUtils;
import org.wildfly.prospero.model.ProsperoConfig;
import org.wildfly.prospero.updates.CandidateProperties;
@@ -51,7 +54,8 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
-import java.util.function.Function;
+import java.util.function.Supplier;
+
import org.jboss.galleon.api.Provisioning;
import org.jboss.galleon.api.config.GalleonProvisioningConfig;
@@ -91,7 +95,7 @@ boolean buildCandidate(Path targetDir, GalleonEnvironment galleonEnv, ApplyCandi
*/
boolean buildCandidate(Path targetDir, GalleonEnvironment galleonEnv, ApplyCandidateAction.Type operation,
GalleonProvisioningConfig config, UpdateSet updateSet) throws ProvisioningException, OperationException {
- return this.buildCandidate(targetDir, galleonEnv, operation, config, updateSet, this::getManifestVersionRecord);
+ return this.buildCandidate(targetDir, galleonEnv, operation, config, updateSet, () -> getManifestVersionRecord(galleonEnv));
}
/**
@@ -110,7 +114,7 @@ boolean buildCandidate(Path targetDir, GalleonEnvironment galleonEnv, ApplyCandi
*/
boolean buildCandidate(Path targetDir, GalleonEnvironment galleonEnv, ApplyCandidateAction.Type operation,
GalleonProvisioningConfig config, UpdateSet updateSet,
- Function, Optional> manifestVersionRecordSupplier) throws ProvisioningException, OperationException {
+ Supplier> manifestVersionRecordSupplier) throws ProvisioningException, OperationException {
Objects.requireNonNull(manifestVersionRecordSupplier);
doBuildUpdate(targetDir, galleonEnv, config, manifestVersionRecordSupplier);
@@ -127,7 +131,7 @@ boolean buildCandidate(Path targetDir, GalleonEnvironment galleonEnv, ApplyCandi
}
private void doBuildUpdate(Path targetDir, GalleonEnvironment galleonEnv, GalleonProvisioningConfig provisioningConfig,
- Function, Optional> manifestVersionResolver)
+ Supplier> manifestVersionResolver)
throws ProvisioningException, OperationException {
final Provisioning provMgr = galleonEnv.getProvisioning();
try {
@@ -142,7 +146,7 @@ private void doBuildUpdate(Path targetDir, GalleonEnvironment galleonEnv, Galleo
}
- final Optional manifestRecord = manifestVersionResolver.apply(galleonEnv.getChannels());
+ final Optional manifestRecord = manifestVersionResolver.get();
if (LOG.isTraceEnabled()) {
LOG.tracef("Recording manifests: %s", manifestRecord.orElse(new ManifestVersionRecord()));
@@ -165,10 +169,9 @@ private void doBuildUpdate(Path targetDir, GalleonEnvironment galleonEnv, Galleo
}
}
- private Optional getManifestVersionRecord(List channels) {
- final ProsperoManifestVersionResolver manifestResolver = new ProsperoManifestVersionResolver(mavenSessionManager);
+ private Optional getManifestVersionRecord(GalleonEnvironment galleonEnv) {
try {
- return Optional.of(manifestResolver.getCurrentVersions(channels));
+ return Optional.of(ManifestVersionResolver.getCurrentVersions(galleonEnv.getChannelSession()));
} catch (IOException e) {
ProsperoLogger.ROOT_LOGGER.debug("Unable to retrieve current manifest versions", e);
return Optional.empty();
@@ -177,7 +180,10 @@ private Optional getManifestVersionRecord(List c
private void cacheManifests(ManifestVersionRecord manifestRecord, Path installDir) {
try {
- ArtifactCache.getInstance(installDir).cache(manifestRecord, mavenSessionManager.getResolvedArtifactVersions());
+ final RepositorySystem system = mavenSessionManager.newRepositorySystem();
+ final DefaultRepositorySystemSession session = mavenSessionManager.newRepositorySystemSession(system);
+
+ ArtifactCache.getInstance(installDir).cache(manifestRecord, session.getLocalRepositoryManager());
} catch (IOException e) {
ProsperoLogger.ROOT_LOGGER.debug("Unable to record manifests in the internal cache", e);
}
diff --git a/prospero-common/src/main/java/org/wildfly/prospero/actions/ProsperoManifestVersionResolver.java b/prospero-common/src/main/java/org/wildfly/prospero/actions/ProsperoManifestVersionResolver.java
deleted file mode 100644
index 190d9f8e5..000000000
--- a/prospero-common/src/main/java/org/wildfly/prospero/actions/ProsperoManifestVersionResolver.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright 2024 Red Hat, Inc. and/or its affiliates
- * and other contributors as indicated by the @author tags.
- *
- * Licensed 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.wildfly.prospero.actions;
-
-import org.jboss.logging.Logger;
-import org.wildfly.channel.Channel;
-import org.wildfly.channel.ChannelManifestMapper;
-import org.wildfly.channel.MavenArtifact;
-import org.wildfly.channel.MavenCoordinate;
-import org.wildfly.prospero.metadata.ManifestVersionRecord;
-import org.wildfly.prospero.metadata.ManifestVersionResolver;
-import org.wildfly.prospero.wfchannel.MavenSessionManager;
-import org.wildfly.prospero.wfchannel.ResolvedArtifactsStore;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.function.Supplier;
-
-/**
- * Identifies manifests used to provision installation.
- * It uses {@code ResolvedManifestVersions} to find already resolved manifests and falls back onto
- * {@code ManifestVersionResolver} if not possible.
- */
-class ProsperoManifestVersionResolver {
-
- private static final Logger LOG = Logger.getLogger(ProsperoManifestVersionResolver.class.getName());
-
- private final ResolvedArtifactsStore manifestVersions;
-
- private final Supplier manifestVersionResolver;
-
- ProsperoManifestVersionResolver(MavenSessionManager mavenSessionManager) {
- this.manifestVersions = mavenSessionManager.getResolvedArtifactVersions();
- this.manifestVersionResolver = () -> new ManifestVersionResolver(
- mavenSessionManager.getProvisioningRepo(),
- mavenSessionManager.newRepositorySystem());
- }
-
- ProsperoManifestVersionResolver(ResolvedArtifactsStore manifestVersions, ManifestVersionResolver manifestVersionResolver) {
- this.manifestVersions = manifestVersions;
- this.manifestVersionResolver = () -> manifestVersionResolver;
- }
-
- /**
- * attempt to resolve the current versions from artifacts recorded during provisioning.
- * Fallback on artifacts in the local maven cache if not available.
- *
- * @param channels
- * @return
- * @throws IOException
- */
- public ManifestVersionRecord getCurrentVersions(List channels) throws IOException {
- final ManifestVersionRecord record = new ManifestVersionRecord();
- final ArrayList fallbackChannels = new ArrayList<>();
- for (Channel channel : channels) {
- if (channel.getManifestCoordinate().getMaven() != null && channel.getManifestCoordinate().getMaven().getVersion() == null) {
- final MavenCoordinate manifestCoord = channel.getManifestCoordinate().getMaven();
- if (LOG.isDebugEnabled()) {
- LOG.debugf("Trying to lookup manifest %s", manifestCoord);
- }
- final MavenArtifact version = manifestVersions.getManifestVersion(manifestCoord.getGroupId(), manifestCoord.getArtifactId());
- if (version == null) {
- if (LOG.isDebugEnabled()) {
- LOG.debugf("Failed to lookup manifest %s in currently resolved artifacts", manifestCoord);
- }
- fallbackChannels.add(channel);
- } else {
- if (LOG.isDebugEnabled()) {
- LOG.debugf("Manifest %s resolved in currently resolve artifacts, recording.", manifestCoord);
- }
- final String description = ChannelManifestMapper.from(version.getFile().toURI().toURL()).getDescription();
- record.addManifest(new ManifestVersionRecord.MavenManifest(
- manifestCoord.getGroupId(),
- manifestCoord.getArtifactId(),
- version.getVersion(),
- description));
- }
- } else {
- if (LOG.isDebugEnabled()) {
- LOG.debugf("Manifest for channel %s will be resolved via fallback.", channel.getName());
- }
- fallbackChannels.add(channel);
- }
- }
-
- if (LOG.isDebugEnabled()) {
- LOG.debugf("Resolving channel manifests using fallback mechanisms.");
- }
- final ManifestVersionRecord currentVersions = manifestVersionResolver.get().getCurrentVersions(fallbackChannels);
- currentVersions.getMavenManifests().forEach(record::addManifest);
- currentVersions.getOpenManifests().forEach(record::addManifest);
- currentVersions.getUrlManifests().forEach(record::addManifest);
-
- return record;
- }
-}
diff --git a/prospero-common/src/main/java/org/wildfly/prospero/actions/ProvisioningAction.java b/prospero-common/src/main/java/org/wildfly/prospero/actions/ProvisioningAction.java
index 212395fcc..7bca82a87 100644
--- a/prospero-common/src/main/java/org/wildfly/prospero/actions/ProvisioningAction.java
+++ b/prospero-common/src/main/java/org/wildfly/prospero/actions/ProvisioningAction.java
@@ -18,6 +18,8 @@
package org.wildfly.prospero.actions;
import org.apache.commons.lang3.StringUtils;
+import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.resolution.ArtifactResult;
import org.jboss.galleon.universe.maven.MavenUniverseException;
import org.wildfly.channel.ArtifactCoordinate;
@@ -143,8 +145,7 @@ public void provision(GalleonProvisioningConfig provisioningConfig, List version = manifestRecord.getMavenManifests().stream()
+ .filter(m -> m.getGroupId().equals(groupId) && m.getArtifactId().equals(artifactId))
+ .map(ManifestVersionRecord.MavenManifest::getVersion)
+ .findFirst();
+ return version
+ .map(v -> localRepositoryManager.getPathForLocalArtifact(new DefaultArtifact(groupId, artifactId, ChannelManifest.CLASSIFIER, ChannelManifest.EXTENSION, v)))
+ .map(p -> localRepositoryManager.getRepository().getBasedir().toPath().resolve(p).toFile())
+ .map(f -> new MavenArtifact(groupId, artifactId, ChannelManifest.EXTENSION, ChannelManifest.CLASSIFIER, version.get(), f))
+ .orElse(null);
+ }
+
private void init() throws IOException {
Path artifactLog = cacheDir.resolve(CACHE_FILENAME);
diff --git a/prospero-common/src/main/java/org/wildfly/prospero/galleon/CachedVersionResolver.java b/prospero-common/src/main/java/org/wildfly/prospero/galleon/CachedVersionResolver.java
index 31de22592..be5871045 100644
--- a/prospero-common/src/main/java/org/wildfly/prospero/galleon/CachedVersionResolver.java
+++ b/prospero-common/src/main/java/org/wildfly/prospero/galleon/CachedVersionResolver.java
@@ -17,9 +17,6 @@
package org.wildfly.prospero.galleon;
-import org.eclipse.aether.AbstractRepositoryListener;
-import org.eclipse.aether.RepositoryEvent;
-import org.eclipse.aether.RepositoryListener;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.DefaultArtifact;
@@ -28,6 +25,7 @@
import org.jboss.logging.Logger;
import org.wildfly.channel.ArtifactCoordinate;
import org.wildfly.channel.ArtifactTransferException;
+import org.wildfly.channel.ChannelManifest;
import org.wildfly.channel.ChannelMetadataCoordinate;
import org.wildfly.channel.UnresolvedMavenArtifactException;
import org.wildfly.channel.spi.MavenVersionsResolver;
@@ -51,15 +49,12 @@
*/
public class CachedVersionResolver implements MavenVersionsResolver {
private static final Logger LOG = Logger.getLogger(CachedVersionResolver.class.getName());
-
- private static final RepositoryListener NOOP_REPOSITORY_LISTENER = new AbstractRepositoryListener(){};
private final MavenVersionsResolver fallbackResolver;
private final RepositorySystem system;
private final RepositorySystemSession session;
private final ArtifactCache artifactCache;
private final Logger log = Logger.getLogger(CachedVersionResolver.class);
- private final RepositoryListener listener;
private final Function manifestVersionProvider;
public CachedVersionResolver(MavenVersionsResolver fallbackResolver, ArtifactCache cache, RepositorySystem system,
@@ -70,12 +65,30 @@ public CachedVersionResolver(MavenVersionsResolver fallbackResolver, ArtifactCac
this.session = session;
this.artifactCache = cache;
this.manifestVersionProvider = manifestVersionProvider;
- this.listener = session.getRepositoryListener() != null ? session.getRepositoryListener() : NOOP_REPOSITORY_LISTENER;
}
@Override
public Set getAllVersions(String groupId, String artifactId, String extension, String classifier) {
- return fallbackResolver.getAllVersions(groupId, artifactId, extension, classifier);
+ final Set allVersions = fallbackResolver.getAllVersions(groupId, artifactId, extension, classifier);
+
+ if (!allVersions.isEmpty()) {
+ return allVersions;
+ } else {
+ if (ChannelManifest.EXTENSION.equals(extension) && ChannelManifest.CLASSIFIER.equals(classifier)) {
+
+ ArtifactCoordinate a = new ArtifactCoordinate(groupId, artifactId, extension, classifier, "");
+ // get version from manifest_versions to verify this is the latest version
+ final String version = manifestVersionProvider.apply(a);
+ if (LOG.isDebugEnabled()) {
+ LOG.debugf("Last used version for manifest %s is %s.", a, version);
+ }
+
+ if (version != null) {
+ return Set.of(version);
+ }
+ }
+ return allVersions;
+ }
}
@Override
@@ -158,17 +171,23 @@ public List resolveChannelMetadata(List extends ChannelMetadataCoordinate
LOG.debugf("Found cached manifest for %s.", a);
}
log.warnf("Unable to resolve manifest for channel %s, no updates will be resolved for this channel.", a);
- this.listener.artifactResolved(new RepositoryEvent.Builder(session, RepositoryEvent.EventType.ARTIFACT_RESOLVED)
- .setArtifact(new DefaultArtifact(
- a.getGroupId(),
- a.getArtifactId(),
- a.getClassifier(),
- a.getExtension(),
- version,
- null,
- artifact.get()
- ))
- .build());
+ installArtifactLocally(a.getGroupId(),
+ a.getArtifactId(),
+ a.getExtension(),
+ a.getClassifier(),
+ version,
+ artifact.get());
+// this.listener.artifactResolved(new RepositoryEvent.Builder(session, RepositoryEvent.EventType.ARTIFACT_RESOLVED)
+// .setArtifact(new DefaultArtifact(
+// a.getGroupId(),
+// a.getArtifactId(),
+// a.getClassifier(),
+// a.getExtension(),
+// version,
+// null,
+// artifact.get()
+// ))
+// .build());
try {
// maintain order as in manifestCoords
for (int i = 0; i < manifestCoords.size(); i++) {
diff --git a/prospero-common/src/main/java/org/wildfly/prospero/wfchannel/MavenSessionManager.java b/prospero-common/src/main/java/org/wildfly/prospero/wfchannel/MavenSessionManager.java
index 8fc901a17..fe12e7558 100644
--- a/prospero-common/src/main/java/org/wildfly/prospero/wfchannel/MavenSessionManager.java
+++ b/prospero-common/src/main/java/org/wildfly/prospero/wfchannel/MavenSessionManager.java
@@ -44,7 +44,6 @@ public class MavenSessionManager {
private static final String AETHER_OFFLINE_PROTOCOLS_PROPERTY = "aether.offline.protocols";
public static final String AETHER_OFFLINE_PROTOCOLS_VALUE = "file";
private final Path provisioningRepo;
- private final ProsperoMavenRepositoryListener repositoryListener = new ProsperoMavenRepositoryListener();
private boolean offline;
public MavenSessionManager(MavenOptions mavenOptions) throws ProvisioningException {
@@ -100,7 +99,6 @@ public DefaultRepositorySystemSession newRepositorySystemSession(RepositorySyste
final DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
final LocalRepository localRepo = new LocalRepository(provisioningRepo.toAbsolutePath().toFile());
- session.setRepositoryListener(repositoryListener);
session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
session.setOffline(offline);
return session;
@@ -117,13 +115,4 @@ public void setOffline(boolean offline) {
public boolean isOffline() {
return offline;
}
-
- /**
- * returns a {@code ResolvedArtifactsStore} containing artifacts resolved during that maven session.
- *
- * @return
- */
- public ResolvedArtifactsStore getResolvedArtifactVersions() {
- return repositoryListener;
- }
}
diff --git a/prospero-common/src/main/java/org/wildfly/prospero/wfchannel/ProsperoMavenRepositoryListener.java b/prospero-common/src/main/java/org/wildfly/prospero/wfchannel/ProsperoMavenRepositoryListener.java
deleted file mode 100644
index 2ea5f9900..000000000
--- a/prospero-common/src/main/java/org/wildfly/prospero/wfchannel/ProsperoMavenRepositoryListener.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright 2024 Red Hat, Inc. and/or its affiliates
- * and other contributors as indicated by the @author tags.
- *
- * Licensed 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.wildfly.prospero.wfchannel;
-
-import org.eclipse.aether.AbstractRepositoryListener;
-import org.eclipse.aether.RepositoryEvent;
-import org.eclipse.aether.artifact.Artifact;
-import org.wildfly.channel.ChannelManifest;
-import org.wildfly.channel.MavenArtifact;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * listener called every time an artifact is resolved by Maven. Keeps track of artifacts resolved by Maven
- */
-class ProsperoMavenRepositoryListener extends AbstractRepositoryListener implements ResolvedArtifactsStore {
-
- private final Map manifestVersions = new HashMap<>();
-
- @Override
- public MavenArtifact getManifestVersion(String groupId, String artifactId) {
- return manifestVersions.get(getKey(groupId, artifactId, ChannelManifest.CLASSIFIER, ChannelManifest.EXTENSION));
- }
-
- @Override
- public void artifactResolved(RepositoryEvent event) {
- final Artifact a = event.getArtifact();
-
- if (a == null || a.getFile() == null) {
- return;
- }
-
- if (a.getClassifier() != null && a.getClassifier().equals(ChannelManifest.CLASSIFIER)) {
- manifestVersions.put(getKey(a),
- new MavenArtifact(a.getGroupId(), a.getArtifactId(), a.getExtension(), a.getClassifier(), a.getVersion(), a.getFile()));
- }
- }
-
- private static String getKey(Artifact a) {
- return getKey(a.getGroupId(), a.getArtifactId(), a.getClassifier(), a.getExtension());
- }
-
- private static String getKey(String groupId, String artifactId, String classifier, String extension) {
- return String.format("%s:%s:%s:%s", groupId, artifactId, nullable(classifier), nullable(extension));
- }
-
- private static String nullable(String txt) {
- if (txt == null) {
- return "";
- }
- return txt;
- }
-}
diff --git a/prospero-common/src/main/java/org/wildfly/prospero/wfchannel/ResolvedArtifactsStore.java b/prospero-common/src/main/java/org/wildfly/prospero/wfchannel/ResolvedArtifactsStore.java
deleted file mode 100644
index 298155705..000000000
--- a/prospero-common/src/main/java/org/wildfly/prospero/wfchannel/ResolvedArtifactsStore.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright 2024 Red Hat, Inc. and/or its affiliates
- * and other contributors as indicated by the @author tags.
- *
- * Licensed 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.wildfly.prospero.wfchannel;
-
-import org.wildfly.channel.MavenArtifact;
-
-/**
- * a collection of artifacts resolved in the maven session
- */
-public interface ResolvedArtifactsStore {
-
- /**
- * queries the store to find a manifest resolved in this maven session matching the {@code GA}
- *
- * @param groupId - the {@code groupId} of the manifest
- * @param artifactId - the {@code artifactId} of the manifest
- * @return - {@code MavenArtifact} representing the resolved manifest or {@code null} if the manifest has not been resolved
- */
- MavenArtifact getManifestVersion(String groupId, String artifactId);
-}
diff --git a/prospero-common/src/test/java/org/wildfly/channel/ChannelSessionTest.java b/prospero-common/src/test/java/org/wildfly/channel/ChannelSessionTest.java
index 09631cca0..77b06c590 100644
--- a/prospero-common/src/test/java/org/wildfly/channel/ChannelSessionTest.java
+++ b/prospero-common/src/test/java/org/wildfly/channel/ChannelSessionTest.java
@@ -53,6 +53,7 @@ public void testExceptionShouldContainMissingUrlOnManifestNotFound() throws Exce
Assert.assertTrue(e.getCause() instanceof FileNotFoundException);
Assert.assertEquals("file:idontexist.yaml" ,e.getValidationMessages().get(0));
} catch (Exception e) {
+ e.printStackTrace();
Assert.fail("Expecting " + InvalidChannelMetadataException.class + " but " + e.getClass() + " was thrown");
}
}
diff --git a/prospero-common/src/test/java/org/wildfly/prospero/actions/ProsperoManifestVersionResolverTest.java b/prospero-common/src/test/java/org/wildfly/prospero/actions/ProsperoManifestVersionResolverTest.java
deleted file mode 100644
index 88000f561..000000000
--- a/prospero-common/src/test/java/org/wildfly/prospero/actions/ProsperoManifestVersionResolverTest.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Copyright 2024 Red Hat, Inc. and/or its affiliates
- * and other contributors as indicated by the @author tags.
- *
- * Licensed 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.wildfly.prospero.actions;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.wildfly.channel.Channel;
-import org.wildfly.channel.ChannelManifest;
-import org.wildfly.channel.ChannelManifestCoordinate;
-import org.wildfly.channel.ChannelManifestMapper;
-import org.wildfly.channel.MavenArtifact;
-import org.wildfly.prospero.metadata.ManifestVersionRecord;
-import org.wildfly.prospero.metadata.ManifestVersionResolver;
-import org.wildfly.prospero.wfchannel.ResolvedArtifactsStore;
-
-import java.io.File;
-import java.net.URI;
-import java.nio.file.Files;
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-
-@RunWith(MockitoJUnitRunner.class)
-public class ProsperoManifestVersionResolverTest {
- protected static final String A_GROUP_ID = "org.test";
- protected static final String MANIFEST_ONE_ARTIFACT_ID = "manifest-one";
- protected static final String MANIFEST_TWO_ARTIFACT_ID = "manifest-two";
- protected static final String A_VERSION = "1.2.3";
- @Mock
- public ResolvedArtifactsStore artifactVersions;
-
- @Mock
- public ManifestVersionResolver manifestVersionResolver;
-
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
- private File manifestFile;
- private ProsperoManifestVersionResolver resolver;
-
- @Before
- public void setUp() throws Exception {
- manifestFile = temp.newFile("test");
- Files.writeString(manifestFile.toPath(), ChannelManifestMapper.toYaml(
- new ChannelManifest("test", "test", "desc", null)));
-
- // when the fallback resolver is called return an empty record to make the test pass
- when(manifestVersionResolver.getCurrentVersions(any())).thenReturn(new ManifestVersionRecord());
-
- resolver = new ProsperoManifestVersionResolver(artifactVersions, manifestVersionResolver);
- }
-
- @Test
- public void versionResolvedDuringProvisioning() throws Exception {
- whenManifestOneWasResolveDuringProvisioning();
-
- final ManifestVersionRecord currentVersions = resolver.getCurrentVersions(List.of(new Channel.Builder()
- .setManifestCoordinate(new ChannelManifestCoordinate(A_GROUP_ID, MANIFEST_ONE_ARTIFACT_ID))
- .build()));
-
- assertThat(currentVersions.getMavenManifests())
- .map(ManifestVersionRecord.MavenManifest::getVersion)
- .containsOnly(A_VERSION);
- assertThat(currentVersions.getMavenManifests())
- .map(ManifestVersionRecord.MavenManifest::getDescription)
- .containsOnly("desc");
- }
-
- @Test
- public void versionNotResolvedDuringProvisioning_FallsbackToMavenCache() throws Exception {
- when(artifactVersions.getManifestVersion(A_GROUP_ID, MANIFEST_ONE_ARTIFACT_ID)).thenReturn(null);
-
- final List channels = List.of(new Channel.Builder()
- .setManifestCoordinate(new ChannelManifestCoordinate(A_GROUP_ID, MANIFEST_ONE_ARTIFACT_ID))
- .build());
- resolver.getCurrentVersions(channels);
-
- verify(manifestVersionResolver).getCurrentVersions(channels);
- }
-
- @Test
- public void alreadyResolvedChannelsAreNotPassedThrough() throws Exception {
- whenManifestOneWasResolveDuringProvisioning();
-
- final List channels = List.of(
- new Channel.Builder()
- .setManifestCoordinate(new ChannelManifestCoordinate(A_GROUP_ID, MANIFEST_ONE_ARTIFACT_ID))
- .build(),
- new Channel.Builder()
- .setManifestCoordinate(new ChannelManifestCoordinate(A_GROUP_ID, MANIFEST_TWO_ARTIFACT_ID))
- .build());
- resolver.getCurrentVersions(channels);
-
- verify(manifestVersionResolver).getCurrentVersions(List.of(channels.get(1)));
- }
-
- @Test
- public void nonOpenMavenChannelsAreResolvedWithFallback() throws Exception {
- whenManifestOneWasResolveDuringProvisioning();
-
- final List channels = List.of(
- new Channel.Builder()
- .setManifestCoordinate(new ChannelManifestCoordinate(A_GROUP_ID, MANIFEST_ONE_ARTIFACT_ID, A_VERSION))
- .build(),
- new Channel.Builder()
- .setManifestUrl(new URI("http://test.te/manifest.yaml").toURL())
- .build());
- resolver.getCurrentVersions(channels);
-
- verify(manifestVersionResolver).getCurrentVersions(channels);
- }
-
- private void whenManifestOneWasResolveDuringProvisioning() {
- when(artifactVersions.getManifestVersion(A_GROUP_ID, MANIFEST_ONE_ARTIFACT_ID)).thenReturn(
- new MavenArtifact(A_GROUP_ID, MANIFEST_ONE_ARTIFACT_ID, null, null, A_VERSION, manifestFile));
- }
-}
\ No newline at end of file
diff --git a/prospero-common/src/test/java/org/wildfly/prospero/galleon/ArtifactCacheTest.java b/prospero-common/src/test/java/org/wildfly/prospero/galleon/ArtifactCacheTest.java
index a77d658b0..999e39176 100644
--- a/prospero-common/src/test/java/org/wildfly/prospero/galleon/ArtifactCacheTest.java
+++ b/prospero-common/src/test/java/org/wildfly/prospero/galleon/ArtifactCacheTest.java
@@ -21,11 +21,7 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import org.wildfly.channel.ChannelManifest;
import org.wildfly.channel.MavenArtifact;
-import org.wildfly.prospero.metadata.ManifestVersionRecord;
-import org.wildfly.prospero.wfchannel.MavenSessionManager;
-import org.wildfly.prospero.wfchannel.ResolvedArtifactsStore;
import java.io.File;
import java.io.IOException;
@@ -38,8 +34,6 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
public class ArtifactCacheTest {
@@ -158,84 +152,6 @@ public void getArtifactDoesntReturnArtifactIfTheHashIsDifferent() throws Excepti
assertEquals(Optional.empty(), cachedArtifact);
}
- @Test
- public void cacheMavenManifests_ResolvedInList() throws Exception {
- final ManifestVersionRecord record = new ManifestVersionRecord();
- record.addManifest(new ManifestVersionRecord.MavenManifest("foo", "bar", "1.2.3", ""));
- final MavenSessionManager msm = mock(MavenSessionManager.class);
- final ResolvedArtifactsStore manifestVersions = mock(ResolvedArtifactsStore.class);
- when(msm.getResolvedArtifactVersions()).thenReturn(manifestVersions);
- final File testFile = temp.newFile("test");
- Files.writeString(testFile.toPath(), "test file");
- when(manifestVersions.getManifestVersion("foo", "bar")).thenReturn(
- new MavenArtifact("foo", "bar", null, null, "1.2.3", testFile));
-
- cache.cache(record, msm.getResolvedArtifactVersions());
-
- // verify the "test" file exists in cache
- final Optional cachedArtifact = cache.getArtifact("foo", "bar", ChannelManifest.EXTENSION, ChannelManifest.CLASSIFIER, "1.2.3");
- assertThat(cachedArtifact.get())
- .hasSameBinaryContentAs(testFile);
- }
-
- @Test
- public void cacheMavenManifests_NotResolvedLocally() throws Exception {
- final ManifestVersionRecord record = new ManifestVersionRecord();
- record.addManifest(new ManifestVersionRecord.MavenManifest("foo", "bar", "1.2.3", ""));
- final MavenSessionManager msm = mock(MavenSessionManager.class);
- final ResolvedArtifactsStore manifestVersions = mock(ResolvedArtifactsStore.class);
- when(msm.getResolvedArtifactVersions()).thenReturn(manifestVersions);
- // the artifact is not found in resolved list
- when(manifestVersions.getManifestVersion("foo", "bar")).thenReturn(null);
-
- cache.cache(record, msm.getResolvedArtifactVersions());
-
- // verify the "test" file exists in cache
- final Optional cachedArtifact = cache.getArtifact("foo", "bar", ChannelManifest.EXTENSION, ChannelManifest.CLASSIFIER, "1.2.3");
- assertThat(cachedArtifact)
- .isEmpty();
- }
-
- @Test
- public void cacheMavenManifests_ResolvedFileDoesNotExist() throws Exception {
- final ManifestVersionRecord record = new ManifestVersionRecord();
- record.addManifest(new ManifestVersionRecord.MavenManifest("foo", "bar", "1.2.3", ""));
- final MavenSessionManager msm = mock(MavenSessionManager.class);
- final ResolvedArtifactsStore manifestVersions = mock(ResolvedArtifactsStore.class);
- when(msm.getResolvedArtifactVersions()).thenReturn(manifestVersions);
- // the artifact is not found in resolved list
- when(manifestVersions.getManifestVersion("foo", "bar")).thenReturn(null);
-
- cache.cache(record, msm.getResolvedArtifactVersions());
-
- // verify the "test" file exists in cache
- final Optional cachedArtifact = cache.getArtifact("foo", "bar", ChannelManifest.EXTENSION, ChannelManifest.CLASSIFIER, "1.2.3");
- assertThat(cachedArtifact)
- .isEmpty();
- }
-
- @Test
- public void cacheMavenManifests_ResolvedInListWithDifferentVersion() throws Exception {
- final ManifestVersionRecord record = new ManifestVersionRecord();
- record.addManifest(new ManifestVersionRecord.MavenManifest("foo", "bar", "1.2.3", ""));
- final MavenSessionManager msm = mock(MavenSessionManager.class);
- final ResolvedArtifactsStore manifestVersions = mock(ResolvedArtifactsStore.class);
- when(msm.getResolvedArtifactVersions()).thenReturn(manifestVersions);
- final File testFile = temp.newFile("test-1.2.3");
- Files.writeString(testFile.toPath(), "test file 1.2.3");
- final File testFile2 = temp.newFile("test-1.2.4");
- Files.writeString(testFile2.toPath(), "test file 1.2.4");
- when(manifestVersions.getManifestVersion("foo", "bar")).thenReturn(
- new MavenArtifact("foo", "bar", null, null, "1.2.4", testFile2));
-
- cache.cache(record, msm.getResolvedArtifactVersions());
-
- // verify the "test" file exists in cache
- final Optional cachedArtifact = cache.getArtifact("foo", "bar", ChannelManifest.EXTENSION, ChannelManifest.CLASSIFIER, "1.2.3");
- assertThat(cachedArtifact)
- .isEmpty();
- }
-
@Test
public void cacheRecordsArtifactsInAlphabeticOrder() throws Exception {
cache.cache(otherArtifact);
diff --git a/prospero-common/src/test/java/org/wildfly/prospero/galleon/CachedVersionResolverTest.java b/prospero-common/src/test/java/org/wildfly/prospero/galleon/CachedVersionResolverTest.java
index ac89290c4..50fd49d77 100644
--- a/prospero-common/src/test/java/org/wildfly/prospero/galleon/CachedVersionResolverTest.java
+++ b/prospero-common/src/test/java/org/wildfly/prospero/galleon/CachedVersionResolverTest.java
@@ -94,7 +94,6 @@ public class CachedVersionResolverTest {
@Before
public void setUp() throws Exception {
- when(session.getRepositoryListener()).thenReturn(repositoryListener);
resolver = new CachedVersionResolver(mockResolver, artifactCache, system, session, manifestVersionProvider);
}
@@ -237,7 +236,6 @@ public void testResolveChannelMetadata_FallbackReturnsCachedFile() throws Except
assertThat(resolver.resolveChannelMetadata(List.of(new ChannelMetadataCoordinate("org.test", "manifest-one", ChannelManifest.CLASSIFIER, ChannelManifest.EXTENSION))))
.containsExactly(testFile.toURI().toURL());
- verify(repositoryListener).artifactResolved(any());
}
@Test
@@ -260,7 +258,6 @@ public void testResolveChannelMetadata_FallbackReturnsCachedFile_WithTwoManifest
new ChannelMetadataCoordinate("org.test", "manifest-one", ChannelManifest.CLASSIFIER, ChannelManifest.EXTENSION),
new ChannelMetadataCoordinate("org.test", "manifest-two", ChannelManifest.CLASSIFIER, ChannelManifest.EXTENSION))))
.containsExactly(testFileOne.toURI().toURL(), testFileTwo.toURI().toURL());
- verify(repositoryListener, times(2)).artifactResolved(any());
}
@Test
@@ -288,7 +285,5 @@ public void testResolveChannelMetadata_OneManifestResolvedNormally() throws Exce
new ChannelManifestCoordinate("org.test", "manifest-one"),
new ChannelManifestCoordinate("org.test", "manifest-two"))))
.containsExactly(testFileOne.toURI().toURL(), testFileTwo.toURI().toURL());
- // only called on the cached artifact
- verify(repositoryListener).artifactResolved(any());
}
}
\ No newline at end of file
diff --git a/prospero-common/src/test/java/org/wildfly/prospero/wfchannel/ProsperoMavenRepositoryListenerTest.java b/prospero-common/src/test/java/org/wildfly/prospero/wfchannel/ProsperoMavenRepositoryListenerTest.java
deleted file mode 100644
index dc9f0d56b..000000000
--- a/prospero-common/src/test/java/org/wildfly/prospero/wfchannel/ProsperoMavenRepositoryListenerTest.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright 2024 Red Hat, Inc. and/or its affiliates
- * and other contributors as indicated by the @author tags.
- *
- * Licensed 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.wildfly.prospero.wfchannel;
-
-import org.eclipse.aether.RepositoryEvent;
-import org.eclipse.aether.RepositorySystemSession;
-import org.eclipse.aether.artifact.DefaultArtifact;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.wildfly.channel.ChannelManifest;
-import org.wildfly.channel.MavenArtifact;
-
-import java.io.File;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-@RunWith(MockitoJUnitRunner.class)
-public class ProsperoMavenRepositoryListenerTest {
-
- protected static final String A_GROUP = "org.test";
- protected static final String AN_ARTIFACT = "artifact-one";
- protected static final String A_VERSION = "1.2.3";
- @Mock
- private RepositorySystemSession session;
- private ProsperoMavenRepositoryListener listener;
- private File testFile;
-
- @Before
- public void setUp() {
-
- listener = new ProsperoMavenRepositoryListener();
- testFile = new File("test");
- }
-
- @Test
- public void testRecordArtifact() throws Exception {
- listener.artifactResolved(new RepositoryEvent.Builder(session, RepositoryEvent.EventType.ARTIFACT_RESOLVED)
- .setArtifact(resolvedArtifact(testFile))
- .build());
-
- assertThat(listener.getManifestVersion(A_GROUP, AN_ARTIFACT))
- .isEqualTo(new MavenArtifact(A_GROUP, AN_ARTIFACT,
- ChannelManifest.EXTENSION, ChannelManifest.CLASSIFIER, A_VERSION, testFile));
-
- }
-
- @Test
- public void testDontRecordArtifactWithoutFile() throws Exception {
- listener.artifactResolved(new RepositoryEvent.Builder(session, RepositoryEvent.EventType.ARTIFACT_RESOLVED)
- .setArtifact(resolvedArtifact(null))
- .build());
-
- assertThat(listener.getManifestVersion(A_GROUP, AN_ARTIFACT))
- .isNull();
- }
-
- @Test
- public void testDontRecordArtifactWhenEventDoesntHaveArtifact() throws Exception {
- listener.artifactResolved(new RepositoryEvent.Builder(session, RepositoryEvent.EventType.ARTIFACT_RESOLVED)
- .build());
-
- assertThat(listener.getManifestVersion(A_GROUP, AN_ARTIFACT))
- .isNull();
- }
-
- @Test
- public void testReturnNullIfArtifactHasntBeenResolved() throws Exception {
- listener.artifactResolved(new RepositoryEvent.Builder(session, RepositoryEvent.EventType.ARTIFACT_RESOLVED)
- .setArtifact(resolvedArtifact(testFile))
- .build());
-
- assertThat(listener.getManifestVersion(A_GROUP, "idont-exist"))
- .isNull();
- }
-
- @Test
- public void resolvingSameArtifactTwiceReplacesArtifact() throws Exception {
- final File testFileTwo = new File("test-two");
-
- listener.artifactResolved(new RepositoryEvent.Builder(session, RepositoryEvent.EventType.ARTIFACT_RESOLVED)
- .setArtifact(resolvedArtifact(testFile))
- .build());
- listener.artifactResolved(new RepositoryEvent.Builder(session, RepositoryEvent.EventType.ARTIFACT_RESOLVED)
- .setArtifact(resolvedArtifact(testFileTwo))
- .build());
-
- assertThat(listener.getManifestVersion(A_GROUP, AN_ARTIFACT))
- .isEqualTo(new MavenArtifact(A_GROUP, AN_ARTIFACT,
- ChannelManifest.EXTENSION, ChannelManifest.CLASSIFIER, A_VERSION, testFileTwo));
- }
-
- private DefaultArtifact resolvedArtifact(File testFile) {
- if (testFile == null) {
- return new DefaultArtifact(A_GROUP, AN_ARTIFACT,
- ChannelManifest.CLASSIFIER, ChannelManifest.EXTENSION, A_VERSION);
- } else {
- return new DefaultArtifact(A_GROUP, AN_ARTIFACT,
- ChannelManifest.CLASSIFIER, ChannelManifest.EXTENSION, A_VERSION,
- null, testFile);
- }
- }
-}
\ No newline at end of file