use of io.quarkus.registry.catalog.Extension in project quarkus by quarkusio.
the class UpdateCommandHandler method resolveRecommendedState.
private static ProjectState resolveRecommendedState(ProjectState currentState, ExtensionCatalog latestCatalog, MessageWriter log) {
if (currentState.getPlatformBoms().isEmpty()) {
return currentState;
}
if (currentState.getExtensions().isEmpty()) {
return currentState;
}
final ExtensionMap extensionInfo = new ExtensionMap();
for (TopExtensionDependency dep : currentState.getExtensions()) {
extensionInfo.add(new ExtensionInfo(dep));
}
for (Extension e : latestCatalog.getExtensions()) {
final ExtensionInfo candidate = extensionInfo.get(e.getArtifact().getKey());
if (candidate != null && candidate.latestMetadata == null) {
// if the latestMetadata has already been initialized, it's already the preferred one
// that could happen if an artifact has relocated
candidate.latestMetadata = e;
}
}
final List<ExtensionInfo> unknownExtensions = new ArrayList<>(0);
final List<Extension> updateCandidates = new ArrayList<>(extensionInfo.size());
final Map<String, ExtensionMap> updateCandidatesByOrigin = new HashMap<>();
for (ExtensionInfo i : extensionInfo.values()) {
if (i.latestMetadata == null) {
unknownExtensions.add(i);
} else {
updateCandidates.add(i.latestMetadata);
for (ExtensionOrigin o : i.latestMetadata.getOrigins()) {
updateCandidatesByOrigin.computeIfAbsent(o.getId(), k -> new ExtensionMap()).add(i);
}
}
}
if (extensionInfo.isEmpty()) {
return currentState;
}
if (!unknownExtensions.isEmpty()) {
log.warn("The configured Quarkus registries did not provide any compatibility information for the following extensions in the context of the currently recommended Quarkus platforms:");
unknownExtensions.forEach(e -> log.warn(" " + e.currentDep.getArtifact().toCompactCoords()));
}
final List<ExtensionCatalog> recommendedOrigins;
try {
recommendedOrigins = getRecommendedOrigins(latestCatalog, updateCandidates);
} catch (QuarkusCommandException e) {
log.info("Failed to find a compatible configuration update for the project");
return currentState;
}
int collectedUpdates = 0;
for (ExtensionCatalog recommendedOrigin : recommendedOrigins) {
final ExtensionMap candidates = updateCandidatesByOrigin.get(recommendedOrigin.getId());
for (Extension e : recommendedOrigin.getExtensions()) {
final ExtensionInfo info = candidates.get(e.getArtifact().getKey());
if (info != null && info.recommendedMetadata == null) {
info.setRecommendedMetadata(e);
if (++collectedUpdates == updateCandidates.size()) {
break;
}
}
}
}
final ProjectState.Builder stateBuilder = ProjectState.builder();
for (ExtensionCatalog c : recommendedOrigins) {
if (c.isPlatform()) {
stateBuilder.addPlatformBom(c.getBom());
}
}
final Map<String, ExtensionProvider.Builder> extProviders = new LinkedHashMap<>(recommendedOrigins.size());
for (ExtensionInfo info : extensionInfo.values()) {
final TopExtensionDependency ext = info.getRecommendedDependency();
stateBuilder.addExtensionDependency(ext);
extProviders.computeIfAbsent(ext.getProviderKey(), k -> ExtensionProvider.builder().setOrigin(ext.getOrigin())).addExtension(ext);
}
extProviders.values().forEach(b -> stateBuilder.addExtensionProvider(b.build()));
for (ModuleState module : currentState.getModules()) {
final ModuleState.Builder moduleBuilder = ModuleState.builder().setMainModule(module.isMain()).setWorkspaceModule(module.getWorkspaceModule());
for (TopExtensionDependency dep : module.getExtensions()) {
final TopExtensionDependency recommendedDep = extensionInfo.get(dep.getKey()).getRecommendedDependency();
moduleBuilder.addExtensionDependency(recommendedDep);
final ExtensionOrigin origin = recommendedDep.getOrigin();
if (origin != null && origin.isPlatform()) {
moduleBuilder.addPlatformBom(origin.getBom());
}
}
stateBuilder.addModule(moduleBuilder.build());
}
return stateBuilder.build();
}
use of io.quarkus.registry.catalog.Extension in project quarkus by quarkusio.
the class CodestartResourceLoadersBuilder method getCodestartResourceLoaders.
private static List<ResourceLoader> getCodestartResourceLoaders(String baseCodestartsArtifactCoords, Collection<String> extraCodestartsArtifactCoords, ExtensionCatalog catalog, MavenArtifactResolver mvn) {
final Map<String, Artifact> codestartsArtifacts = new LinkedHashMap<>();
if (catalog != null) {
// Load codestarts from each extensions codestart artifacts
for (Extension e : catalog.getExtensions()) {
final String artifactCoords = getCodestartArtifact(e);
if (artifactCoords == null || codestartsArtifacts.containsKey(artifactCoords)) {
continue;
}
codestartsArtifacts.put(artifactCoords, DependencyNodeUtils.toArtifact(artifactCoords));
}
}
// Load base codestart artifacts
if (baseCodestartsArtifactCoords != null) {
codestartsArtifacts.put(baseCodestartsArtifactCoords, DependencyNodeUtils.toArtifact(baseCodestartsArtifactCoords));
}
if (catalog != null) {
// Load codestarts from catalog codestart artifacts
final List<String> catalogCodestartArtifacts = getCodestartArtifacts(catalog);
for (String artifactCoords : catalogCodestartArtifacts) {
if (codestartsArtifacts.containsKey(artifactCoords)) {
continue;
}
codestartsArtifacts.put(artifactCoords, DependencyNodeUtils.toArtifact(artifactCoords));
}
}
// Load codestarts from the given artifacts
for (String codestartArtifactCoords : extraCodestartsArtifactCoords) {
codestartsArtifacts.put(codestartArtifactCoords, DependencyNodeUtils.toArtifact(codestartArtifactCoords));
}
final List<ResourceLoader> codestartResourceLoaders = new ArrayList<>(codestartsArtifacts.size());
for (Artifact a : codestartsArtifacts.values()) {
try {
final File artifactFile = mvn.resolve(a).getArtifact().getFile();
codestartResourceLoaders.add(resolveFileResourceLoader(artifactFile));
} catch (Exception e) {
throw new RuntimeException("Failed to resolve codestart artifact " + a, e);
}
}
return codestartResourceLoaders;
}
use of io.quarkus.registry.catalog.Extension in project quarkus by quarkusio.
the class ExtensionPredicateTest method acceptKeywordInArtifactId.
@Test
void acceptKeywordInArtifactId() {
ExtensionPredicate predicate = new ExtensionPredicate("foo");
Extension extension = Extension.builder().setArtifact(new ArtifactCoords("g", "foo-bar", null, "jar", "1.0")).build();
assertThat(predicate).accepts(extension);
}
use of io.quarkus.registry.catalog.Extension in project quarkus by quarkusio.
the class ExtensionPredicateTest method acceptKeywordInLabel.
@Test
void acceptKeywordInLabel() {
ExtensionPredicate predicate = new ExtensionPredicate("foo");
Extension extension = Extension.builder().setArtifact(new ArtifactCoords("g", "a", null, "jar", "1.0")).setMetadata(Extension.MD_KEYWORDS, Arrays.asList("foo", "bar")).build();
assertThat(predicate).accepts(extension);
}
use of io.quarkus.registry.catalog.Extension 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;
}
Aggregations