Search in sources :

Example 1 with PncBuild

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();
}
Also used : GAV(org.jboss.pnc.bacon.pig.impl.utils.GAV) Map(java.util.Map) Optional(java.util.Optional) PncBuild(org.jboss.pnc.bacon.pig.impl.pnc.PncBuild) ArtifactWrapper(org.jboss.pnc.bacon.pig.impl.pnc.ArtifactWrapper) ArtifactWrapper(org.jboss.pnc.bacon.pig.impl.pnc.ArtifactWrapper) PncBuild(org.jboss.pnc.bacon.pig.impl.pnc.PncBuild) GAV(org.jboss.pnc.bacon.pig.impl.utils.GAV)

Example 2 with PncBuild

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());
    }
}
Also used : Dependency(org.eclipse.aether.graph.Dependency) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) FatalException(org.jboss.pnc.bacon.common.exception.FatalException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ArtifactWrapper(org.jboss.pnc.bacon.pig.impl.pnc.ArtifactWrapper) MavenArtifactResolver(io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver) File(java.io.File) PncBuild(org.jboss.pnc.bacon.pig.impl.pnc.PncBuild) GAV(org.jboss.pnc.bacon.pig.impl.utils.GAV) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 3 with PncBuild

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()));
    }
}
Also used : Path(java.nio.file.Path) PncBuild(org.jboss.pnc.bacon.pig.impl.pnc.PncBuild) Test(org.junit.jupiter.api.Test)

Example 4 with PncBuild

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);
    }
}
Also used : Path(java.nio.file.Path) PncBuild(org.jboss.pnc.bacon.pig.impl.pnc.PncBuild) Test(org.junit.jupiter.api.Test)

Example 5 with PncBuild

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);
    }
}
Also used : TargetRepository(org.jboss.pnc.dto.TargetRepository) ArrayList(java.util.ArrayList) PncBuild(org.jboss.pnc.bacon.pig.impl.pnc.PncBuild) Artifact(org.jboss.pnc.dto.Artifact)

Aggregations

PncBuild (org.jboss.pnc.bacon.pig.impl.pnc.PncBuild)29 File (java.io.File)10 PigConfiguration (org.jboss.pnc.bacon.pig.impl.config.PigConfiguration)8 ArtifactWrapper (org.jboss.pnc.bacon.pig.impl.pnc.ArtifactWrapper)8 GAV (org.jboss.pnc.bacon.pig.impl.utils.GAV)8 Map (java.util.Map)7 Path (java.nio.file.Path)5 ArrayList (java.util.ArrayList)5 Collectors (java.util.stream.Collectors)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 FileNotFoundException (java.io.FileNotFoundException)4 PrintWriter (java.io.PrintWriter)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 Collection (java.util.Collection)4 HashMap (java.util.HashMap)4 List (java.util.List)4 FatalException (org.jboss.pnc.bacon.common.exception.FatalException)4 RepoGenerationData (org.jboss.pnc.bacon.pig.impl.config.RepoGenerationData)4 BuildInfoCollector (org.jboss.pnc.bacon.pig.impl.pnc.BuildInfoCollector)4