Skip to content

Commit

Permalink
Update java version from recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
ia3andy committed Jun 28, 2023
1 parent 848a6f2 commit 35f9368
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 66 deletions.
2 changes: 1 addition & 1 deletion devtools/cli/src/main/java/io/quarkus/cli/CreateApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import io.quarkus.cli.create.TargetGAVGroup;
import io.quarkus.cli.create.TargetLanguageGroup;
import io.quarkus.devtools.commands.CreateProject.CreateProjectKey;
import io.quarkus.devtools.project.SourceType;
import io.quarkus.devtools.commands.data.QuarkusCommandInvocation;
import io.quarkus.devtools.commands.handlers.CreateJBangProjectCommandHandler;
import io.quarkus.devtools.commands.handlers.CreateProjectCommandHandler;
import io.quarkus.devtools.project.BuildTool;
import io.quarkus.devtools.project.SourceType;
import picocli.CommandLine;

@CommandLine.Command(name = "app", header = "Create a Quarkus application project.", description = "%n"
Expand Down
2 changes: 1 addition & 1 deletion devtools/cli/src/main/java/io/quarkus/cli/CreateCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import io.quarkus.cli.create.TargetGAVGroup;
import io.quarkus.cli.create.TargetLanguageGroup;
import io.quarkus.devtools.commands.CreateProject.CreateProjectKey;
import io.quarkus.devtools.project.SourceType;
import io.quarkus.devtools.commands.data.QuarkusCommandInvocation;
import io.quarkus.devtools.commands.handlers.CreateJBangProjectCommandHandler;
import io.quarkus.devtools.commands.handlers.CreateProjectCommandHandler;
import io.quarkus.devtools.project.BuildTool;
import io.quarkus.devtools.project.SourceType;
import picocli.CommandLine;

@CommandLine.Command(name = "cli", header = "Create a Quarkus command-line project.", description = "%n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import io.quarkus.cli.registry.ToggleRegistryClientMixin;
import io.quarkus.devtools.commands.CreateProject.CreateProjectKey;
import io.quarkus.devtools.commands.CreateProjectHelper;
import io.quarkus.devtools.project.SourceType;
import io.quarkus.devtools.commands.data.QuarkusCommandInvocation;
import io.quarkus.devtools.project.BuildTool;
import io.quarkus.devtools.project.QuarkusProject;
import io.quarkus.devtools.project.SourceType;
import io.quarkus.registry.RegistryResolutionException;
import picocli.CommandLine;
import picocli.CommandLine.Model.CommandSpec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import java.util.stream.Collectors;

import io.quarkus.cli.common.OutputOptionMixin;
import io.quarkus.devtools.project.SourceType;
import io.quarkus.devtools.project.BuildTool;
import io.quarkus.devtools.project.JavaVersion;
import io.quarkus.devtools.project.SourceType;
import picocli.CommandLine;
import picocli.CommandLine.Model.CommandSpec;
import picocli.CommandLine.ParameterException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.quarkus.cli.common.TargetQuarkusPlatformGroup;
import io.quarkus.devtools.commands.CreateProjectHelper;
import io.quarkus.devtools.project.BuildTool;
import io.quarkus.devtools.project.JavaVersion;
import io.quarkus.devtools.project.QuarkusProject;
import io.quarkus.devtools.project.QuarkusProjectHelper;
import io.quarkus.maven.dependency.ArtifactCoords;
Expand Down Expand Up @@ -62,7 +63,7 @@ public QuarkusProject createQuarkusProject(Path projectRoot, TargetQuarkusPlatfo
+ "Use the maven/gradle plugins when working with Quarkus 1.x projects.");
}
catalog = CreateProjectHelper.completeCatalog(catalog, extensions, QuarkusProjectHelper.artifactResolver());
return QuarkusProjectHelper.getProject(projectRoot, catalog, buildTool, log);
return QuarkusProjectHelper.getProject(projectRoot, catalog, buildTool, JavaVersion.NA, log);
}

ExtensionCatalog getExtensionCatalog(TargetQuarkusPlatformGroup targetVersion, OutputOptionMixin log)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.OptionalInt;

import io.quarkus.bootstrap.model.ApplicationModel;
import io.quarkus.devtools.commands.UpdateProject;
Expand Down Expand Up @@ -76,13 +78,20 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws
if (!noRewrite) {
final BuildTool buildTool = quarkusProject.getExtensionManager().getBuildTool();
String kotlinVersion = getMetadata(targetCatalog, "project", "properties", "kotlin-version");

final OptionalInt minJavaVersion = extensionsUpdateInfo.getMinJavaVersion();
final Optional<Integer> updateJavaVersion;
if (minJavaVersion.isPresent()
&& minJavaVersion.getAsInt() > invocation.getQuarkusProject().getJavaVersion().getAsInt()) {
updateJavaVersion = Optional.of(minJavaVersion.getAsInt());
} else {
updateJavaVersion = Optional.empty();
}
QuarkusUpdates.ProjectUpdateRequest request = new QuarkusUpdates.ProjectUpdateRequest(
buildTool,
projectQuarkusPlatformBom.getVersion(),
targetPlatformVersion,
kotlinVersion,
extensionsUpdateInfo.getMinJavaVersion());
updateJavaVersion);
Path recipe = null;
try {
recipe = Files.createTempFile("quarkus-project-recipe-", ".yaml");
Expand All @@ -91,6 +100,7 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws
final QuarkusUpdatesRepository.FetchResult fetchResult = QuarkusUpdates.createRecipe(invocation.log(),
recipe,
QuarkusProjectHelper.artifactResolver(), buildTool, updateRecipesVersion, request);
invocation.log().info("OpenRewrite recipe generated: %s", recipe);
final String rewritePluginVersion = invocation.getValue(UpdateProject.REWRITE_PLUGIN_VERSION,
fetchResult.getRewritePluginVersion());
final boolean rewriteDryRun = invocation.getValue(UpdateProject.REWRITE_DRY_RUN, false);
Expand All @@ -108,15 +118,6 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws
throw new QuarkusCommandException("Error while generating the project update script", e);
} catch (QuarkusUpdateException e) {
throw new QuarkusCommandException("Error while running the project update script", e);
} finally {
if (recipe != null) {
try {
Files.deleteIfExists(recipe);
} catch (IOException e) {
// ignore
}
}

}
}
}
Expand Down Expand Up @@ -179,13 +180,19 @@ private static void logUpdates(QuarkusProject project, ProjectState currentState
log.info("");
}

if (extensionsUpdateInfo.isEmpty()) {
if (!platformUpdateInfo.isPlatformUpdatesAvailable()) {
log.info("The project is up-to-date");
}
if (extensionsUpdateInfo.isUpToDate() && !platformUpdateInfo.isPlatformUpdatesAvailable()) {
log.info("The project is up-to-date");
return;
}

if (extensionsUpdateInfo.getMinJavaVersion().isPresent()) {
final Integer extensionsMinJavaVersion = extensionsUpdateInfo.getMinJavaVersion().getAsInt();
if (extensionsMinJavaVersion > project.getJavaVersion().getAsInt()) {
log.warn("We detected that some of the updated extensions require an update of the Java version to: %s",
extensionsMinJavaVersion);
}
}

for (PlatformInfo platform : platformUpdateInfo.getPlatformImports().values()) {
final String provider = platform.getRecommendedProviderKey();
if (!extensionsUpdateInfo.getVersionedManagedExtensions().containsKey(provider)
Expand All @@ -202,14 +209,15 @@ private static void logUpdates(QuarkusProject project, ProjectState currentState
sb.append(" -> remove version (managed)");
log.info(sb.toString());
}
for (ArtifactCoords e : extensionsUpdateInfo.getAddedExtensions().getOrDefault(provider, Collections.emptyList())) {
for (ExtensionUpdateInfo i : extensionsUpdateInfo.getAddedExtensions().getOrDefault(provider,
Collections.emptyList())) {
log.info(String.format(UpdateProjectCommandHandler.ITEM_FORMAT, UpdateProjectCommandHandler.ADD,
e.getKey().toGacString()));
i.getRecommendedDependency().getKey().toGacString()));
}
for (ArtifactCoords e : extensionsUpdateInfo.getRemovedExtensions().getOrDefault(provider,
for (ExtensionUpdateInfo i : extensionsUpdateInfo.getRemovedExtensions().getOrDefault(provider,
Collections.emptyList())) {
log.info(String.format(UpdateProjectCommandHandler.ITEM_FORMAT, UpdateProjectCommandHandler.REMOVE,
e.getKey().toGacString()));
i.getCurrentDep().getKey().toGacString()));
}
log.info("");
}
Expand All @@ -236,13 +244,7 @@ private static void logUpdates(QuarkusProject project, ProjectState currentState
log.info("");
}
}
if (extensionsUpdateInfo.getMinJavaVersion().isPresent()) {
final int extensionsMinJavaVersion = extensionsUpdateInfo.getMinJavaVersion().getAsInt();
if (extensionsMinJavaVersion > project.getJavaVersion().getAsInt()) {
log.warn("We detected that some of the updated extensions require an update of the Java version to: ",
extensionsMinJavaVersion);
}
}

}

@SuppressWarnings({ "rawtypes", "unchecked" })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public ExtensionUpdateInfoBuilder setRecommendedDep(TopExtensionDependency recom
}

public ExtensionUpdateInfo build() {
return new ExtensionUpdateInfo(currentDep, currentDep.getCatalogMetadata(), resolveRecommendedDep());
final TopExtensionDependency effectiveRecommendedDep = resolveRecommendedDep();
return new ExtensionUpdateInfo(currentDep, effectiveRecommendedDep.getCatalogMetadata(), effectiveRecommendedDep);
}

public TopExtensionDependency resolveRecommendedDep() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,47 @@
package io.quarkus.devtools.project.update;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.stream.Stream;

import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.devtools.project.JavaVersion;
import io.quarkus.platform.catalog.processor.ExtensionProcessor;

public class ProjectExtensionsUpdateInfo {
private final Map<String, List<ExtensionUpdateInfo>> managedExtensions;
final Map<String, List<ExtensionUpdateInfo>> versionedManagedExtensions;
final Map<String, List<ArtifactCoords>> removedExtensions;
final Map<String, List<ArtifactCoords>> addedExtensions;
final Map<String, List<ExtensionUpdateInfo>> removedExtensions;
final Map<String, List<ExtensionUpdateInfo>> addedExtensions;
final Map<String, List<ExtensionUpdateInfo>> nonPlatformExtensions;

public ProjectExtensionsUpdateInfo(Map<String, List<ExtensionUpdateInfo>> versionedManagedExtensions,
Map<String, List<ArtifactCoords>> removedExtensions, Map<String, List<ArtifactCoords>> addedExtensions,
public ProjectExtensionsUpdateInfo(Map<String, List<ExtensionUpdateInfo>> managedExtensions,
Map<String, List<ExtensionUpdateInfo>> versionedManagedExtensions,
Map<String, List<ExtensionUpdateInfo>> removedExtensions,
Map<String, List<ExtensionUpdateInfo>> addedExtensions,
Map<String, List<ExtensionUpdateInfo>> nonPlatformExtensionUpdate) {
this.managedExtensions = managedExtensions;
this.versionedManagedExtensions = versionedManagedExtensions;
this.removedExtensions = removedExtensions;
this.addedExtensions = addedExtensions;
this.nonPlatformExtensions = nonPlatformExtensionUpdate;
}

public Map<String, List<ExtensionUpdateInfo>> getManagedExtensions() {
return managedExtensions;
}

public Map<String, List<ExtensionUpdateInfo>> getVersionedManagedExtensions() {
return versionedManagedExtensions;
}

public Map<String, List<ArtifactCoords>> getRemovedExtensions() {
public Map<String, List<ExtensionUpdateInfo>> getRemovedExtensions() {
return removedExtensions;
}

public Map<String, List<ArtifactCoords>> getAddedExtensions() {
public Map<String, List<ExtensionUpdateInfo>> getAddedExtensions() {
return addedExtensions;
}

Expand All @@ -40,13 +50,18 @@ public Map<String, List<ExtensionUpdateInfo>> getNonPlatformExtensions() {
}

public OptionalInt getMinJavaVersion() {
return Stream.concat(getVersionedManagedExtensions().values().stream(), getNonPlatformExtensions().values().stream())
.flatMap(List::stream)
.mapToInt(e -> ExtensionProcessor.getMinimumJavaVersion(e.getRecommendedMetadata()))
return Stream.of(getManagedExtensions().values(),
getVersionedManagedExtensions().values(),
getNonPlatformExtensions().values(),
getAddedExtensions().values())
.flatMap(Collection::stream)
.flatMap(Collection::stream)
.mapToInt(e -> Optional.ofNullable(ExtensionProcessor.getMinimumJavaVersion(e.getRecommendedMetadata()))
.orElse(JavaVersion.DEFAULT_JAVA_VERSION))
.max();
}

public boolean isEmpty() {
public boolean isUpToDate() {
return versionedManagedExtensions.isEmpty()
&& removedExtensions.isEmpty()
&& addedExtensions.isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ public static ProjectExtensionsUpdateInfo resolveExtensionsUpdateInfo(ProjectSta
info.setRecommendedDep(dep);
}
}
final Map<String, List<ExtensionUpdateInfo>> managedExtensions = new LinkedHashMap<>(0);
final Map<String, List<ExtensionUpdateInfo>> versionedManagedExtensions = new LinkedHashMap<>(0);
final Map<String, List<ArtifactCoords>> removedExtensions = new LinkedHashMap<>(0);
final Map<String, List<ArtifactCoords>> addedExtensions = new LinkedHashMap<>(0);
final Map<String, List<ExtensionUpdateInfo>> removedExtensions = new LinkedHashMap<>(0);
final Map<String, List<ExtensionUpdateInfo>> addedExtensions = new LinkedHashMap<>(0);
final Map<String, List<ExtensionUpdateInfo>> nonPlatformExtensionUpdates = new LinkedHashMap<>();
for (ExtensionUpdateInfoBuilder infoBuilder : extensionInfo.values()) {
final ExtensionUpdateInfo info = infoBuilder.build();
Expand All @@ -55,14 +56,14 @@ public static ProjectExtensionsUpdateInfo resolveExtensionsUpdateInfo(ProjectSta
if (!info.getCurrentDep().getKey().equals(info.getRecommendedDependency().getKey())) {
if (info.getCurrentDep().isPlatformExtension()) {
removedExtensions.computeIfAbsent(info.getCurrentDep().getProviderKey(), k -> new ArrayList<>())
.add(info.getCurrentDep().getArtifact());
.add(new ExtensionUpdateInfo(info.getCurrentDep(), null, null));
} else {
nonPlatformExtensionUpdates.computeIfAbsent(info.getCurrentDep().getProviderKey(), k -> new ArrayList<>())
.add(info);
}
if (info.getRecommendedDependency().isPlatformExtension()) {
addedExtensions.computeIfAbsent(info.getRecommendedDependency().getProviderKey(), k -> new ArrayList<>())
.add(info.getRecommendedDependency().getArtifact());
.add(new ExtensionUpdateInfo(null, info.getRecommendedMetadata(), info.getRecommendedDependency()));
} else {
nonPlatformExtensionUpdates
.computeIfAbsent(info.getRecommendedDependency().getProviderKey(), k -> new ArrayList<>())
Expand All @@ -73,13 +74,18 @@ public static ProjectExtensionsUpdateInfo resolveExtensionsUpdateInfo(ProjectSta
versionedManagedExtensions
.computeIfAbsent(info.getRecommendedDependency().getProviderKey(), k -> new ArrayList<>())
.add(info);
} else {
managedExtensions
.computeIfAbsent(info.getRecommendedDependency().getProviderKey(), k -> new ArrayList<>())
.add(info);
}
} else if (!info.getCurrentDep().getVersion().equals(info.getRecommendedDependency().getVersion())) {
nonPlatformExtensionUpdates
.computeIfAbsent(info.getRecommendedDependency().getProviderKey(), k -> new ArrayList<>()).add(info);
}
}
return new ProjectExtensionsUpdateInfo(versionedManagedExtensions, removedExtensions, addedExtensions,
return new ProjectExtensionsUpdateInfo(managedExtensions, versionedManagedExtensions, removedExtensions,
addedExtensions,
nonPlatformExtensionUpdates);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static String toYaml(QuarkusUpdateRecipe recipe) {
q.putAll(QuarkusUpdateRecipe.QUARKUS_RECIPE);
List<Object> recipeList = new ArrayList<>();
for (RewriteOperation o : recipe.getOperations()) {
recipeList.add(o.toMap(recipe.getBuildTool()));
recipeList.addAll(o.multi(recipe.getBuildTool()));
}
recipeList.addAll(recipe.getOtherRecipeNames());
q.put(QuarkusUpdateRecipe.RECIPE_LIST_KEY, recipeList);
Expand Down
Loading

0 comments on commit 35f9368

Please sign in to comment.