use of io.quarkus.registry.catalog.selection.ExtensionOrigins in project quarkus by quarkusio.
the class UpdateCommandHandler method addOrigins.
private static void addOrigins(final List<ExtensionOrigins> extOrigins, Extension e) {
ExtensionOrigins.Builder eoBuilder = null;
for (ExtensionOrigin o : e.getOrigins()) {
if (!(o instanceof ExtensionCatalog)) {
continue;
}
final ExtensionCatalog c = (ExtensionCatalog) o;
final OriginPreference op = (OriginPreference) c.getMetadata().get("origin-preference");
if (op == null) {
continue;
}
if (eoBuilder == null) {
eoBuilder = ExtensionOrigins.builder(e.getArtifact().getKey());
}
eoBuilder.addOrigin(c, op);
}
if (eoBuilder != null) {
extOrigins.add(eoBuilder.build());
}
}
use of io.quarkus.registry.catalog.selection.ExtensionOrigins in project quarkus by quarkusio.
the class CreateProjectCommandHandler method addOrigins.
private static void addOrigins(final List<ExtensionOrigins> extOrigins, Extension e) {
ExtensionOrigins.Builder eoBuilder = null;
for (ExtensionOrigin o : e.getOrigins()) {
if (!(o instanceof ExtensionCatalog)) {
continue;
}
final ExtensionCatalog c = (ExtensionCatalog) o;
final OriginPreference op = (OriginPreference) c.getMetadata().get("origin-preference");
if (op == null) {
continue;
}
if (eoBuilder == null) {
eoBuilder = ExtensionOrigins.builder(e.getArtifact().getKey());
}
eoBuilder.addOrigin(c, op);
}
if (eoBuilder != null) {
extOrigins.add(eoBuilder.build());
}
}
use of io.quarkus.registry.catalog.selection.ExtensionOrigins in project quarkus by quarkusio.
the class UpdateCommandHandler method getRecommendedOrigins.
private static List<ExtensionCatalog> getRecommendedOrigins(ExtensionCatalog extensionCatalog, List<Extension> extensions) throws QuarkusCommandException {
final List<ExtensionOrigins> extOrigins = new ArrayList<>(extensions.size());
for (Extension e : extensions) {
addOrigins(extOrigins, e);
}
final OriginCombination recommendedCombination = OriginSelector.of(extOrigins).calculateRecommendedCombination();
if (recommendedCombination == null) {
final StringBuilder buf = new StringBuilder();
buf.append("Failed to determine a compatible Quarkus version for the requested extensions: ");
buf.append(extensions.get(0).getArtifact().getKey().toGacString());
for (int i = 1; i < extensions.size(); ++i) {
buf.append(", ").append(extensions.get(i).getArtifact().getKey().toGacString());
}
throw new QuarkusCommandException(buf.toString());
}
return recommendedCombination.getUniqueSortedOrigins().stream().map(o -> o.getCatalog()).collect(Collectors.toList());
}
use of io.quarkus.registry.catalog.selection.ExtensionOrigins in project quarkus by quarkusio.
the class CreateProjectCommandHandler method execute.
@Override
public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws QuarkusCommandException {
final Set<String> extensionsQuery = invocation.getValue(ProjectGenerator.EXTENSIONS, Collections.emptySet());
// Default to cleaned groupId if packageName not set
final String className = invocation.getStringValue(CLASS_NAME);
final String pkgName = invocation.getStringValue(PACKAGE_NAME);
final String groupId = invocation.getStringValue(PROJECT_GROUP_ID);
if (pkgName == null) {
if (className != null && className.contains(".")) {
final int idx = className.lastIndexOf('.');
invocation.setValue(PACKAGE_NAME, className.substring(0, idx));
invocation.setValue(CLASS_NAME, className.substring(idx + 1));
} else if (groupId != null) {
invocation.setValue(PACKAGE_NAME, groupId.replace('-', '.').replace('_', '.'));
}
}
List<Extension> extensionsToAdd = computeRequiredExtensions(invocation.getExtensionsCatalog(), extensionsQuery, invocation.log());
// legacy platform initialization
ExtensionCatalog mainCatalog = invocation.getExtensionsCatalog();
final List<ExtensionCatalog> extensionOrigins;
try {
extensionOrigins = getExtensionOrigins(mainCatalog, extensionsToAdd);
} catch (QuarkusCommandException e) {
final StringBuilder buf = new StringBuilder();
buf.append(ERROR_ICON).append(' ').append(e.getLocalizedMessage());
invocation.log().info(buf.toString());
return QuarkusCommandOutcome.failure();
}
final List<ArtifactCoords> platformBoms = new ArrayList<>(Math.max(extensionOrigins.size(), 1));
if (extensionOrigins.size() > 0) {
// necessary to set the versions from the selected origins
extensionsToAdd = computeRequiredExtensions(CatalogMergeUtility.merge(extensionOrigins), extensionsQuery, invocation.log());
// collect platform BOMs to import
boolean sawFirstPlatform = false;
for (ExtensionCatalog c : extensionOrigins) {
if (!c.isPlatform()) {
continue;
}
if (c.getBom().getArtifactId().equals("quarkus-bom") || !sawFirstPlatform) {
mainCatalog = c;
sawFirstPlatform = true;
}
platformBoms.add(c.getBom());
}
} else {
platformBoms.add(mainCatalog.getBom());
}
final List<ArtifactCoords> extensionCoords = new ArrayList<>(extensionsToAdd.size());
for (Extension e : extensionsToAdd) {
ArtifactCoords coords = e.getArtifact();
for (ExtensionOrigin origin : e.getOrigins()) {
if (origin.isPlatform() && origin.getBom() != null && platformBoms.contains(origin.getBom())) {
coords = Extensions.stripVersion(coords);
break;
}
}
extensionCoords.add(coords);
}
invocation.setValue(BOM_GROUP_ID, mainCatalog.getBom().getGroupId());
invocation.setValue(BOM_ARTIFACT_ID, mainCatalog.getBom().getArtifactId());
invocation.setValue(BOM_VERSION, mainCatalog.getBom().getVersion());
invocation.setValue(QUARKUS_VERSION, mainCatalog.getQuarkusCoreVersion());
final Properties quarkusProps = ToolsUtils.readQuarkusProperties(mainCatalog);
quarkusProps.forEach((k, v) -> {
final String name = k.toString().replace('-', '_');
if (!invocation.hasValue(name)) {
invocation.setValue(name, v.toString());
}
});
try {
Map<String, Object> platformData = new HashMap<>();
if (mainCatalog.getMetadata().get("maven") != null) {
platformData.put("maven", mainCatalog.getMetadata().get("maven"));
}
if (mainCatalog.getMetadata().get("gradle") != null) {
platformData.put("gradle", mainCatalog.getMetadata().get("gradle"));
}
final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder().addPlatforms(platformBoms).addExtensions(extensionCoords).buildTool(invocation.getQuarkusProject().getBuildTool()).example(invocation.getValue(EXAMPLE)).noCode(invocation.getValue(NO_CODE, false)).addCodestarts(invocation.getValue(EXTRA_CODESTARTS, Collections.emptySet())).noBuildToolWrapper(invocation.getValue(NO_BUILDTOOL_WRAPPER, false)).noDockerfiles(invocation.getValue(NO_DOCKERFILES, false)).addData(platformData).addData(LegacySupport.convertFromLegacy(invocation.getValues())).putData(APP_CONFIG, invocation.getValue(APP_CONFIG, Collections.emptyMap())).messageWriter(invocation.log()).build();
invocation.log().info("-----------");
if (!extensionsToAdd.isEmpty()) {
invocation.log().info("selected extensions: \n" + extensionsToAdd.stream().map(e -> "- " + e.getArtifact().getGroupId() + ":" + e.getArtifact().getArtifactId() + "\n").collect(Collectors.joining()));
}
final QuarkusCodestartCatalog catalog = QuarkusCodestartCatalog.fromExtensionsCatalog(invocation.getQuarkusProject().getExtensionsCatalog(), invocation.getQuarkusProject().getCodestartResourceLoaders());
final CodestartProjectDefinition projectDefinition = catalog.createProject(input);
projectDefinition.generate(invocation.getQuarkusProject().getProjectDirPath());
invocation.log().info("\n-----------\n" + MessageIcons.OK_ICON + " " + projectDefinition.getRequiredCodestart(CodestartType.PROJECT).getName() + " project has been successfully generated in:\n--> " + invocation.getQuarkusProject().getProjectDirPath().toString() + "\n-----------");
} catch (IOException e) {
throw new QuarkusCommandException("Failed to create project: " + e.getMessage(), e);
}
return QuarkusCommandOutcome.success();
}
use of io.quarkus.registry.catalog.selection.ExtensionOrigins in project quarkus by quarkusio.
the class CreateProjectCommandHandler method getExtensionOrigins.
private static List<ExtensionCatalog> getExtensionOrigins(ExtensionCatalog extensionCatalog, List<Extension> extensionsToAdd) throws QuarkusCommandException {
final List<ExtensionOrigins> extOrigins = new ArrayList<>(extensionsToAdd.size());
for (Extension e : extensionsToAdd) {
addOrigins(extOrigins, e);
}
if (extOrigins.isEmpty()) {
// legacy 1.x or universe platform
return Collections.emptyList();
}
// we add quarkus-core as a selected extension here only to include the quarkus-bom
// in the list of platforms. quarkus-core won't be added to the generated POM though.
final Optional<Extension> quarkusCore = extensionCatalog.getExtensions().stream().filter(e -> e.getArtifact().getArtifactId().equals("quarkus-core")).findFirst();
if (!quarkusCore.isPresent()) {
throw new QuarkusCommandException("Failed to locate quarkus-core in the extension catalog");
}
addOrigins(extOrigins, quarkusCore.get());
final OriginCombination recommendedCombination = OriginSelector.of(extOrigins).calculateRecommendedCombination();
if (recommendedCombination == null) {
final StringBuilder buf = new StringBuilder();
buf.append("Failed to determine a compatible Quarkus version for the requested extensions: ");
buf.append(extensionsToAdd.get(0).getArtifact().getKey().toGacString());
for (int i = 1; i < extensionsToAdd.size(); ++i) {
buf.append(", ").append(extensionsToAdd.get(i).getArtifact().getKey().toGacString());
}
throw new QuarkusCommandException(buf.toString());
}
return recommendedCombination.getUniqueSortedOrigins().stream().map(o -> o.getCatalog()).collect(Collectors.toList());
}
Aggregations