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;
}
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;
}
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);
}
}
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;
}
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);
}
}
Aggregations