Skip to content

Commit

Permalink
Merge pull request #10 from spyrkob/warn_if_artifact_not_in_pnc
Browse files Browse the repository at this point in the history
 Warn if artifact is not in PNC
  • Loading branch information
spyrkob authored Jan 9, 2025
2 parents 078c6f7 + 99e47df commit e6314b8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/main/java/org/jboss/set/components/ManifestVerifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public VerificationResult verifyComponents(URL manifestURL) throws MalformedURLE
final BuildRecorder recorder = new BuildRecorder();

final Collection<ArtifactCoordinate> imported = new ConcurrentLinkedQueue<>();
final List<ArtifactCoordinate> missingArtifacts = new ArrayList<>();
final Collection<ArtifactCoordinate> ungrouped = new ArrayList<>();

// record all artifacts from resolved builds, so that we don't need to resolve them twice
Expand All @@ -53,6 +54,11 @@ public VerificationResult verifyComponents(URL manifestURL) throws MalformedURLE

final PncArtifact artifact = pncManager.getArtifact(artifactCoordinate);

if (artifact == null) {
missingArtifacts.add(artifactCoordinate);
return;
}

if (artifact.isImported()) {
imported.add(artifact.getCoordinate());
return;
Expand Down Expand Up @@ -95,6 +101,10 @@ public VerificationResult verifyComponents(URL manifestURL) throws MalformedURLE
}
}

if (!missingArtifacts.isEmpty()) {
res.addWarning(new Warning("[WARN] Artifacts not build in PNC:", missingArtifacts));
}


if (!imported.isEmpty()) {
res.addWarning(new Warning("[WARN] Ignored imported artifacts:", new ArrayList<>(imported)));
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/org/jboss/set/components/pnc/PncManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class PncManagerImpl implements PncManager {
Expand All @@ -33,9 +34,12 @@ public PncArtifact getArtifact(ArtifactCoordinate coordinate) {
final var allFiltered = artifactClient.getAllFiltered(coordinate.getGroupId() + ":" + coordinate.getArtifactId() + ":*:" + coordinate.getVersion(),
null, null, null);

// allFiltered.forEach(System.out::println);
// TODO: check that all artifacts are coming from the same build
final ArtifactInfo artifact = allFiltered.iterator().next();
final Iterator<ArtifactInfo> iterator = allFiltered.iterator();
if (!iterator.hasNext()) {
return null;
}

final ArtifactInfo artifact = iterator.next();
final var artifactInfo = artifactClient.getSpecific(artifact.getId());
return new PncArtifact(new PncArtifact.Id(artifact.getId()), parseIdentifier(artifact.getIdentifier()), StringUtils.isNotEmpty(artifactInfo.getOriginUrl()));
} catch (RemoteResourceException e) {
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/org/jboss/set/components/ManifestVerifierTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,27 @@ public void differentComponentVersionsFromTheDifferentBuild_Violation() throws E
)));
}

@Test
public void nonExistingArtifactVersion_Warning() throws Exception {
final ManifestVerifier manifestVerifier = new ManifestVerifier(pncManager);
final PncArtifact pncArtifactBuild = new PncArtifact(
new PncArtifact.Id("abcd1"),
new ArtifactCoordinate("io.opentelemetry", "opentelemetry-context", null, null, "1.29.0"),
false);
when(pncManager.getArtifact(pncArtifactBuild.getCoordinate())).thenReturn(null);

final ChannelManifest manifest = new ChannelManifest.Builder()
.setSchemaVersion(ChannelManifestMapper.SCHEMA_VERSION_1_1_0)
.addStreams(new Stream("io.opentelemetry", "opentelemetry-context", "1.29.0"))
.build();
final Path manifestFile = tempDir.resolve("test-manifest.yaml");
Files.writeString(manifestFile, ChannelManifestMapper.toYaml(manifest));

final VerificationResult verificationResult = manifestVerifier.verifyComponents(manifestFile.toUri().toURL());

assertThat(verificationResult.getViolations()).isEmpty();
assertThat(verificationResult.getWarnings())
.map(Warning::getMessage)
.containsOnly("[WARN] Artifacts not build in PNC:");
}
}

0 comments on commit e6314b8

Please sign in to comment.