Search in sources :

Example 1 with BootstrapMavenException

use of io.quarkus.bootstrap.resolver.maven.BootstrapMavenException in project quarkus by quarkusio.

the class CreateProjectHelper method completeCatalog.

/**
 * This method checks whether extensions to be added are specified using complete artifact coordinates,
 * in which case they are resolved and added to the catalog so that their codestarts are picked up by the code generator.
 *
 * @param catalog original extension catalog
 * @param extensions extra extensions to add to the catalog
 * @param mvn Maven artifact resolver
 * @return complete extension catalog
 * @throws BootstrapMavenException in case of a failure to resolve extensions requested by the user
 */
public static ExtensionCatalog completeCatalog(ExtensionCatalog catalog, Collection<String> extensions, MavenArtifactResolver mvn) {
    ExtensionCatalog.Mutable mutableCatalog = null;
    for (String extArg : extensions) {
        if (isFullArtifactCoords(extArg)) {
            var coords = ArtifactCoords.fromString(extArg.trim());
            final Path extJar;
            try {
                extJar = mvn.resolve(new DefaultArtifact(coords.getGroupId(), coords.getArtifactId(), coords.getClassifier(), coords.getType(), coords.getVersion())).getArtifact().getFile().toPath();
            } catch (BootstrapMavenException e) {
                throw new RuntimeException("Failed to resolve extension " + coords, e);
            }
            final Extension ext = PathTree.ofDirectoryOrArchive(extJar).apply(BootstrapConstants.EXTENSION_METADATA_PATH, visit -> {
                if (visit == null) {
                    return null;
                }
                try {
                    return Extension.fromFile(visit.getPath());
                } catch (IOException e) {
                    throw new IllegalStateException("Failed to parse Quarkus extension metadata " + visit.getPath());
                }
            });
            if (ext != null) {
                if (mutableCatalog == null) {
                    mutableCatalog = catalog.mutable();
                }
                var i = mutableCatalog.getExtensions().iterator();
                boolean add = true;
                while (i.hasNext()) {
                    final ArtifactCoords catalogCoords = i.next().getArtifact();
                    if (catalogCoords.getKey().equals(ext.getArtifact().getKey())) {
                        if (catalogCoords.getVersion().equals(ext.getArtifact().getVersion())) {
                            add = false;
                        } else {
                            i.remove();
                        }
                        break;
                    }
                }
                if (add) {
                    mutableCatalog.addExtension(ext);
                }
            }
        }
    }
    if (mutableCatalog != null) {
        catalog = mutableCatalog.build();
    }
    return catalog;
}
Also used : Path(java.nio.file.Path) ArtifactCoords(io.quarkus.maven.ArtifactCoords) ExtensionCatalog(io.quarkus.registry.catalog.ExtensionCatalog) IOException(java.io.IOException) BootstrapMavenException(io.quarkus.bootstrap.resolver.maven.BootstrapMavenException) Extension(io.quarkus.registry.catalog.Extension) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 2 with BootstrapMavenException

use of io.quarkus.bootstrap.resolver.maven.BootstrapMavenException in project quarkus by quarkusio.

the class ExtensionDescriptorMojo method resolver.

private MavenArtifactResolver resolver() throws MojoExecutionException {
    if (resolver == null) {
        final DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repoSession);
        session.setWorkspaceReader(workspaceProvider.workspace());
        try {
            final BootstrapMavenContext ctx = new BootstrapMavenContext(BootstrapMavenContext.config().setRepositorySystem(repoSystem).setRemoteRepositoryManager(remoteRepoManager).setRepositorySystemSession(session).setRemoteRepositories(repos).setPreferPomsFromWorkspace(true).setCurrentProject(workspaceProvider.origin()));
            resolver = new MavenArtifactResolver(ctx);
        } catch (BootstrapMavenException e) {
            throw new MojoExecutionException("Failed to initialize Maven artifact resolver", e);
        }
    }
    return resolver;
}
Also used : BootstrapMavenException(io.quarkus.bootstrap.resolver.maven.BootstrapMavenException) BootstrapMavenContext(io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenArtifactResolver(io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver)

Example 3 with BootstrapMavenException

use of io.quarkus.bootstrap.resolver.maven.BootstrapMavenException in project quarkus by quarkusio.

the class WorkspaceLoader method readModel.

static final Model readModel(Path pom) throws BootstrapMavenException {
    try {
        final Model model = ModelUtils.readModel(pom);
        model.setPomFile(pom.toFile());
        return model;
    } catch (NoSuchFileException e) {
        // some projects may be missing pom.xml relying on Maven extensions (e.g. tycho-maven-plugin) to build them,
        // which we don't support in this workspace loader
        log.warn("Module(s) under " + pom.getParent() + " will be handled as thirdparty dependencies because " + pom + " does not exist");
        return null;
    } catch (IOException e) {
        throw new BootstrapMavenException("Failed to read " + pom, e);
    }
}
Also used : BootstrapMavenException(io.quarkus.bootstrap.resolver.maven.BootstrapMavenException) Model(org.apache.maven.model.Model) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException)

Example 4 with BootstrapMavenException

use of io.quarkus.bootstrap.resolver.maven.BootstrapMavenException in project quarkus by quarkusio.

the class WorkspaceLoader method locateCurrentProjectPom.

static Path locateCurrentProjectPom(Path path, boolean required) throws BootstrapMavenException {
    Path p = path;
    while (p != null) {
        final Path pom = p.resolve(POM_XML);
        if (Files.exists(pom)) {
            return pom;
        }
        p = p.getParent();
    }
    if (required) {
        throw new BootstrapMavenException("Failed to locate project pom.xml for " + path);
    }
    return null;
}
Also used : Path(java.nio.file.Path) BootstrapMavenException(io.quarkus.bootstrap.resolver.maven.BootstrapMavenException)

Example 5 with BootstrapMavenException

use of io.quarkus.bootstrap.resolver.maven.BootstrapMavenException in project quarkus by quarkusio.

the class LocalProject method readModel.

static final Model readModel(Path pom) throws BootstrapMavenException {
    try {
        final Model model = ModelUtils.readModel(pom);
        model.setPomFile(pom.toFile());
        return model;
    } catch (IOException e) {
        throw new BootstrapMavenException("Failed to read " + pom, e);
    }
}
Also used : BootstrapMavenException(io.quarkus.bootstrap.resolver.maven.BootstrapMavenException) Model(org.apache.maven.model.Model) IOException(java.io.IOException)

Aggregations

BootstrapMavenException (io.quarkus.bootstrap.resolver.maven.BootstrapMavenException)16 IOException (java.io.IOException)8 Path (java.nio.file.Path)8 MavenArtifactResolver (io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver)7 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)5 BootstrapMavenContext (io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 ArtifactCoords (io.quarkus.maven.ArtifactCoords)3 Model (org.apache.maven.model.Model)3 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)3 Artifact (org.eclipse.aether.artifact.Artifact)3 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)3 RegistryResolutionException (io.quarkus.registry.RegistryResolutionException)2 Extension (io.quarkus.registry.catalog.Extension)2 ExtensionCatalog (io.quarkus.registry.catalog.ExtensionCatalog)2 NoSuchFileException (java.nio.file.NoSuchFileException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 QuietMavenTransferListener (org.apache.maven.cli.transfer.QuietMavenTransferListener)2 CuratedApplication (io.quarkus.bootstrap.app.CuratedApplication)1