use of org.jboss.pnc.bacon.pig.impl.pnc.ArtifactWrapper in project bacon by project-ncl.
the class ArtifactVersion method get.
/*
* gets artifact coordinates from a location of a form artifactVersion://groupId:artifactId[@buildName] and gets a
* version of the artifact from the build
*/
public static String get(String location, String defaultBuildName, Map<String, PncBuild> builds) {
if (!location.startsWith(ArtifactVersion.prefix)) {
throw new RuntimeException("location: " + location + " is not a proper artifactVersion location");
}
String value = location.substring(prefix.length());
String[] split = value.split("@");
String gaString = split[0];
String[] gaSplit = gaString.split(":");
if (gaSplit.length != 2) {
throw new RuntimeException("Expected artifactVersion://groupId:artifactId... as the version locator, got: " + value);
}
String groupId = gaSplit[0];
String artifactId = gaSplit[1];
String buildName = split.length > 1 ? split[1] : defaultBuildName;
PncBuild pncBuild = builds.get(buildName);
if (pncBuild == null) {
throw new RuntimeException("Build " + buildName + " not found among the builds");
}
Optional<ArtifactWrapper> maybeArtifact = pncBuild.getBuiltArtifacts().stream().filter(a -> {
GAV gav = a.toGAV();
return gav.getArtifactId().equals(artifactId) && gav.getGroupId().equals(groupId);
}).findAny();
return maybeArtifact.orElseThrow(() -> new RuntimeException("Unable to find artifact matching " + groupId + ":" + artifactId + " in artifacts produced by " + buildName)).toGAV().getVersion();
}
use of org.jboss.pnc.bacon.pig.impl.pnc.ArtifactWrapper in project bacon by project-ncl.
the class RepoManager method resolveAndRepackage.
public RepositoryData resolveAndRepackage() {
try {
log.info("Generating maven repository");
File sourceDir = createMavenGenerationDir();
boolean tempBuild = PigContext.get().isTempBuild();
String settingsXmlPath = Indy.getConfiguredIndySettingsXmlPath(tempBuild);
final MavenArtifactResolver mvnResolver = MavenArtifactResolver.builder().setUserSettings(new File(settingsXmlPath)).setLocalRepository(sourceDir.getAbsolutePath()).build();
Map<String, String> params = generationData.getParameters();
// Must point to a text file which contains list of format "groupId:artifactId:version:type:classifier"
String extensionsListUrl = params.get("extensionsListUrl");
List<Artifact> extensionRtArtifactList = parseExtensionsArtifactList(extensionsListUrl);
Map<Artifact, String> redhatVersionExtensionArtifactMap = collectRedhatVersions(extensionRtArtifactList);
List<Dependency> bomConstraints = Collections.emptyList();
if (generationData.getSourceBuild() != null && !generationData.getSourceBuild().isEmpty() && generationData.getSourceArtifact() != null && !generationData.getSourceArtifact().isEmpty()) {
PncBuild pncBuild = getBuild(generationData.getSourceBuild());
ArtifactWrapper bomArtifact = pncBuild.findArtifactByFileName(generationData.getSourceArtifact());
GAV bomGAV = bomArtifact.toGAV();
String bomConstraintGroupId = bomGAV.getGroupId();
String bomConstraintArtifactId = bomGAV.getArtifactId();
String bomConstraintVersion = bomGAV.getVersion();
final Artifact bom = new DefaultArtifact(bomConstraintGroupId, bomConstraintArtifactId, null, "pom", bomConstraintVersion);
bomConstraints = mvnResolver.resolveDescriptor(bom).getManagedDependencies();
if (bomConstraints.isEmpty()) {
throw new IllegalStateException("Failed to resolve " + bom);
}
}
for (Artifact extensionRtArtifact : extensionRtArtifactList) {
// this will resolve all the artifacts and their dependencies and as a consequence populate the local
// Maven repo
// specified in the user settings.xml
String aptVersion = redhatVersionExtensionArtifactMap.getOrDefault(extensionRtArtifact, extensionRtArtifact.getVersion());
if (extensionRtArtifact.getArtifactId().contains("plugin")) {
Artifact pluginArtifact = new DefaultArtifact(extensionRtArtifact.getGroupId(), extensionRtArtifact.getArtifactId(), extensionRtArtifact.getExtension(), aptVersion);
log.debug("Plugin artifact " + pluginArtifact);
mvnResolver.resolvePluginDependencies(pluginArtifact);
} else {
if ((extensionRtArtifact.getArtifactId().contains("bom") || extensionRtArtifact.getExtension().equals("pom")) && !extensionRtArtifact.getExtension().equals("properties")) {
DefaultArtifact bomPomArtifact = new DefaultArtifact(extensionRtArtifact.getGroupId(), extensionRtArtifact.getArtifactId(), "pom", aptVersion);
log.debug("PomArtifact id " + extensionRtArtifact.getArtifactId());
mvnResolver.resolve(bomPomArtifact);
} else {
DefaultArtifact redHatArtifact = new DefaultArtifact(extensionRtArtifact.getGroupId(), extensionRtArtifact.getArtifactId(), extensionRtArtifact.getClassifier(), extensionRtArtifact.getExtension(), aptVersion);
log.debug("Artifact id " + redHatArtifact.getArtifactId() + " version " + redHatArtifact.getVersion());
mvnResolver.resolve(redHatArtifact);
mvnResolver.resolveManagedDependencies(// runtime extension artifact
redHatArtifact, // enforced direct dependencies, ignore this
Collections.emptyList(), // version constraints from the BOM
bomConstraints, // extra maven repos, ignore this
Collections.emptyList(), "test", // dependency scopes that should be ignored
"provided");
}
}
}
return repackage(sourceDir);
} catch (Exception bme) {
bme.printStackTrace();
throw new RuntimeException("Unable to resolve and package. " + bme.getLocalizedMessage());
}
}
use of org.jboss.pnc.bacon.pig.impl.pnc.ArtifactWrapper in project bacon by project-ncl.
the class OfflineManifestGeneratorTest method assertBuildInclusion.
private void assertBuildInclusion(PncBuild build, List<String> offlinerContent, boolean shouldBeIncluded) {
List<ArtifactWrapper> builtAndDependencies = new ArrayList<>();
builtAndDependencies.addAll(build.getBuiltArtifacts());
builtAndDependencies.addAll(build.getDependencyArtifacts());
for (ArtifactWrapper artifact : builtAndDependencies) {
GAV gav = artifact.toGAV();
String offlinerEntry = String.format("%s,%s/%s", artifact.getSha256(), gav.toVersionPath(), gav.toFileName());
assertEquals(shouldBeIncluded, offlinerContent.contains(offlinerEntry));
}
}
use of org.jboss.pnc.bacon.pig.impl.pnc.ArtifactWrapper in project bacon by project-ncl.
the class ExtraDeliverableDownloader method downloadArtifact.
private void downloadArtifact(PncBuild build, String pattern, String suffix) {
ArtifactWrapper artifact = build.findArtifactByFileName(pattern);
Path releaseDir = Paths.get(releasePath);
Path targetFile = releaseDir.resolve(constructFileName(suffix));
artifact.downloadTo(targetFile.toFile());
}
use of org.jboss.pnc.bacon.pig.impl.pnc.ArtifactWrapper in project bacon by project-ncl.
the class JavadocManager method addImportBOM.
private boolean addImportBOM(Profile profile) {
Dependency dep;
PncBuild build = getBuild(generationData.getImportBom());
if (build != null) {
List<ArtifactWrapper> artifacts = build.getBuiltArtifacts();
if (artifacts != null && !artifacts.isEmpty()) {
GAV tmp = artifacts.get(0).toGAV();
// Get the first artifact and create the dep on the pom
dep = new Dependency();
dep.setArtifactId(tmp.getArtifactId());
dep.setGroupId(tmp.getGroupId());
dep.setVersion(tmp.getVersion());
dep.setType("pom");
dep.setScope("import");
profile.getDependencyManagement().addDependency(dep);
} else {
log.error("Error no artifacts in build for 'importBom' {}", generationData.getImportBom());
return false;
}
} else {
log.error("Error no build found for 'importBom' {}", generationData.getImportBom());
return false;
}
return true;
}
Aggregations