Search in sources :

Example 1 with ArtifactWrapper

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();
}
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 ArtifactWrapper

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());
    }
}
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 ArtifactWrapper

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

Example 4 with ArtifactWrapper

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

Example 5 with ArtifactWrapper

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

Aggregations

ArtifactWrapper (org.jboss.pnc.bacon.pig.impl.pnc.ArtifactWrapper)9 PncBuild (org.jboss.pnc.bacon.pig.impl.pnc.PncBuild)7 GAV (org.jboss.pnc.bacon.pig.impl.utils.GAV)6 File (java.io.File)5 ArrayList (java.util.ArrayList)5 MavenArtifactResolver (io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver)3 IOException (java.io.IOException)3 MalformedURLException (java.net.MalformedURLException)3 Path (java.nio.file.Path)3 Map (java.util.Map)3 Artifact (org.eclipse.aether.artifact.Artifact)3 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)3 Dependency (org.eclipse.aether.graph.Dependency)3 FatalException (org.jboss.pnc.bacon.common.exception.FatalException)3 BufferedReader (java.io.BufferedReader)2 Closeable (java.io.Closeable)2 InputStreamReader (java.io.InputStreamReader)2 HttpURLConnection (java.net.HttpURLConnection)2 URL (java.net.URL)2 Paths (java.nio.file.Paths)2