Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove maven listener and simplify the way manifests are cached #771

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)));
}

Expand Down Expand Up @@ -383,6 +385,7 @@ private ChannelManifest updateWildflyController() throws MalformedURLException {
return new ChannelManifest(
sourceManifest.getSchemaVersion(),
sourceManifest.getId(),
sourceManifest.getLogicalVersion(),
sourceManifest.getDescription(),
sourceManifest.getManifestRequirements(),
streams);
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@
<version.org.wildfly.galleon-plugins>7.2.0.Final</version.org.wildfly.galleon-plugins>
<version.org.wildfly.installation-manager>2.0.0.Beta1</version.org.wildfly.installation-manager>
<version.org.wildfly.maven.plugins.licenses-plugin>2.4.1.Final</version.org.wildfly.maven.plugins.licenses-plugin>
<version.org.wildfly.prospero.prospero-metadata>1.2.1.Final</version.org.wildfly.prospero.prospero-metadata>
<version.org.wildfly.prospero.prospero-metadata>1.3.0.Beta1</version.org.wildfly.prospero.prospero-metadata>
<version.org.mockito>5.14.1</version.org.mockito>
<version.org.slf4j>2.0.7</version.org.slf4j>
<version.org.yaml.snakeyaml>2.2</version.org.yaml.snakeyaml>
<version.junit>4.13.2</version.junit>
<version.maven-shade-plugin>3.6.0</version.maven-shade-plugin>
<version.org.wildfly.channel>1.1.0.Final</version.org.wildfly.channel>
<version.org.wildfly.channel>1.2.0.Final</version.org.wildfly.channel>
<version.maven-compiler-plugin>3.10.1</version.maven-compiler-plugin>
<version.org.wildfly.galleon-pack>33.0.2.Final</version.org.wildfly.galleon-pack>
<version.info.picocli>4.7.6</version.info.picocli>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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<List<Channel>, Optional<ManifestVersionRecord>> manifestVersionRecordSupplier) throws ProvisioningException, OperationException {
Supplier<Optional<ManifestVersionRecord>> manifestVersionRecordSupplier) throws ProvisioningException, OperationException {
Objects.requireNonNull(manifestVersionRecordSupplier);

doBuildUpdate(targetDir, galleonEnv, config, manifestVersionRecordSupplier);
Expand All @@ -127,7 +131,7 @@ boolean buildCandidate(Path targetDir, GalleonEnvironment galleonEnv, ApplyCandi
}

private void doBuildUpdate(Path targetDir, GalleonEnvironment galleonEnv, GalleonProvisioningConfig provisioningConfig,
Function<List<Channel>, Optional<ManifestVersionRecord>> manifestVersionResolver)
Supplier<Optional<ManifestVersionRecord>> manifestVersionResolver)
throws ProvisioningException, OperationException {
final Provisioning provMgr = galleonEnv.getProvisioning();
try {
Expand All @@ -142,7 +146,7 @@ private void doBuildUpdate(Path targetDir, GalleonEnvironment galleonEnv, Galleo
}


final Optional<ManifestVersionRecord> manifestRecord = manifestVersionResolver.apply(galleonEnv.getChannels());
final Optional<ManifestVersionRecord> manifestRecord = manifestVersionResolver.get();

if (LOG.isTraceEnabled()) {
LOG.tracef("Recording manifests: %s", manifestRecord.orElse(new ManifestVersionRecord()));
Expand All @@ -165,10 +169,9 @@ private void doBuildUpdate(Path targetDir, GalleonEnvironment galleonEnv, Galleo
}
}

private Optional<ManifestVersionRecord> getManifestVersionRecord(List<Channel> channels) {
final ProsperoManifestVersionResolver manifestResolver = new ProsperoManifestVersionResolver(mavenSessionManager);
private Optional<ManifestVersionRecord> 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();
Expand All @@ -177,7 +180,10 @@ private Optional<ManifestVersionRecord> getManifestVersionRecord(List<Channel> 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);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -143,8 +145,7 @@ public void provision(GalleonProvisioningConfig provisioningConfig, List<Channel
ProsperoLogger.ROOT_LOGGER.debug("Resolving installed manifest versions");
}

manifestRecord = new ManifestVersionResolver(mavenSessionManager.getProvisioningRepo(), mavenSessionManager.newRepositorySystem())
.getCurrentVersions(channels);
manifestRecord = ManifestVersionResolver.getCurrentVersions(galleonEnv.getChannelSession());
} catch (IOException e) {
throw ProsperoLogger.ROOT_LOGGER.unableToDownloadFile(e);
}
Expand Down Expand Up @@ -191,7 +192,10 @@ public void provision(GalleonProvisioningConfig provisioningConfig, List<Channel

private void cacheManifests(ManifestVersionRecord manifestRecord) {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.wildfly.prospero.galleon;

import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.repository.LocalRepositoryManager;
import org.jboss.galleon.universe.maven.MavenUniverseException;
import org.jboss.galleon.util.HashUtils;
import org.jboss.galleon.util.IoUtils;
Expand All @@ -26,7 +28,6 @@
import org.wildfly.prospero.ProsperoLogger;
import org.wildfly.prospero.metadata.ManifestVersionRecord;
import org.wildfly.prospero.metadata.ProsperoMetadataUtils;
import org.wildfly.prospero.wfchannel.ResolvedArtifactsStore;

import java.io.BufferedWriter;
import java.io.File;
Expand Down Expand Up @@ -200,35 +201,41 @@ public void cache(MavenArtifact artifact) throws IOException {
* NOTE: only manifests identified by maven coordinates are cached.
*
* @param manifestRecord - record containing all manifest used in installation.
* @param resolvedArtifacts - artifacts resolved during provisioning.
* @param localRepositoryManager - Maven manager for the local repository.
* @throws IOException
*/
public void cache(ManifestVersionRecord manifestRecord, ResolvedArtifactsStore resolvedArtifacts) throws IOException {
public void cache(ManifestVersionRecord manifestRecord, LocalRepositoryManager localRepositoryManager) throws IOException {
Objects.requireNonNull(manifestRecord);
Objects.requireNonNull(resolvedArtifacts);
Objects.requireNonNull(localRepositoryManager);

for (ManifestVersionRecord.MavenManifest manifest : manifestRecord.getMavenManifests()) {
final MavenArtifact record = resolvedArtifacts.getManifestVersion(manifest.getGroupId(), manifest.getArtifactId());
final MavenArtifact record = mapToFile(manifestRecord, localRepositoryManager, manifest.getGroupId(), manifest.getArtifactId());
if (record != null && record.getVersion().equals(manifest.getVersion())) {
if (LOG.isDebugEnabled()) {
LOG.debugf("Adding manifest %s to the cache", record);
}
final File cachedManifest = record.getFile();

if (cachedManifest.exists()) {
cache(new MavenArtifact(
manifest.getGroupId(),
manifest.getArtifactId(),
ChannelManifest.EXTENSION,
ChannelManifest.CLASSIFIER,
manifest.getVersion(),
cachedManifest
));
cache(record);
}
}
}
}

private MavenArtifact mapToFile(ManifestVersionRecord manifestRecord, LocalRepositoryManager localRepositoryManager,
String groupId, String artifactId) {
final Optional<String> 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);

Expand Down
Loading
Loading