use of org.jboss.pnc.bacon.pig.impl.pnc.PncBuild 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.PncBuild 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.PncBuild in project bacon by project-ncl.
the class OfflineManifestGeneratorTest method testBuildGroupExcludedSources.
@Test
public void testBuildGroupExcludedSources() throws IOException {
List<String> excludeSourceBuilds = Arrays.asList("build2", "build4");
pigConfiguration.getFlow().getRepositoryGeneration().setExcludeSourceBuilds(excludeSourceBuilds);
OfflineManifestGenerator generator = new OfflineManifestGenerator(pigConfiguration, builds, "target/", "extras", buildInfoCollector);
generator.trigger();
Path offlinerFilePath = Paths.get("target/offliner.txt");
List<String> offlinerContent = Files.lines(offlinerFilePath).collect(Collectors.toList());
for (PncBuild build : builds.values()) {
assertBuildInclusion(build, offlinerContent, !excludeSourceBuilds.contains(build.getId()));
}
}
use of org.jboss.pnc.bacon.pig.impl.pnc.PncBuild in project bacon by project-ncl.
the class OfflineManifestGeneratorTest method testGeneration.
@Test
public void testGeneration() throws Exception {
OfflineManifestGenerator generator = new OfflineManifestGenerator(pigConfiguration, builds, "target/", "extras", buildInfoCollector);
generator.trigger();
Path offlinerFilePath = Paths.get("target/offliner.txt");
assertTrue(offlinerFilePath.toFile().exists());
List<String> offlinerContent = Files.lines(offlinerFilePath).collect(Collectors.toList());
assertEquals(artifacts.size(), offlinerContent.size());
for (PncBuild build : builds.values()) {
assertBuildInclusion(build, offlinerContent, true);
}
}
use of org.jboss.pnc.bacon.pig.impl.pnc.PncBuild in project bacon by project-ncl.
the class OfflineManifestGeneratorTest method mockBuildsAndArtifacts.
private void mockBuildsAndArtifacts() {
TargetRepository repository = TargetRepository.refBuilder().identifier("repo1").repositoryType(RepositoryType.MAVEN).build();
builds = new HashMap<>();
artifacts = new HashSet<>();
for (int i = 1; i <= 5; i++) {
String buildName = "build" + i;
List<Artifact> builtArtifacts = new ArrayList<>();
for (int j = 1; j <= i * 2; j++) {
builtArtifacts.add(Artifact.builder().targetRepository(repository).identifier("org:built:jar:" + i + "." + j).filename("built-" + i + "." + j + ".jar").sha256("built_" + i + "_" + j).build());
}
List<Artifact> dependencies = new ArrayList<>();
for (int k = 1; k <= i * 3; k++) {
dependencies.add(Artifact.builder().targetRepository(repository).identifier("org:dependency:jar:" + i + "." + k).filename("dependency-" + i + "." + k + ".jar").sha256("dependency_" + i + "_" + k).build());
}
PncBuild build = new PncBuild();
build.setId(buildName);
build.setName(buildName);
build.addBuiltArtifacts(builtArtifacts);
build.addDependencyArtifacts(dependencies);
builds.put(buildName, build);
artifacts.addAll(builtArtifacts);
artifacts.addAll(dependencies);
}
}
Aggregations