Skip to content

Commit

Permalink
Maven CLI: bettter verbose + added debug for upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriOndrusek committed Oct 17, 2023
1 parent 2501def commit 620bbee
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ public Integer updateProject(TargetQuarkusVersionGroup targetQuarkusVersion, Rew
args.add(ToolsUtils.getPluginKey(props) + ":" + ToolsUtils.getMavenPluginVersion(props) + ":update");
args.add("-e");
args.add("-N");
if (output.isVerbose()) {
args.add("-X");
}
if (targetQuarkusVersion.platformVersion != null) {
args.add("-DplatformVersion=" + targetQuarkusVersion.platformVersion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -56,7 +57,7 @@ public static FetchResult fetchRecipes(MessageWriter log, MavenArtifactResolver
final Artifact artifact = artifactResolver.resolve(DependencyUtils.toArtifact(gav)).getArtifact();
final ResourceLoader resourceLoader = ResourceLoaders.resolveFileResourceLoader(
artifact.getFile());
final List<String> recipes = fetchRecipesAsList(resourceLoader, "quarkus-updates", recipeDirectoryNames);
final List<String[]> recipes = fetchRecipesAsList(resourceLoader, "quarkus-updates", recipeDirectoryNames);
final Properties props = resourceLoader.loadResourceAsPath("quarkus-updates/", p -> {
final Properties properties = new Properties();
final Path propPath = p.resolve("recipes.properties");
Expand All @@ -77,8 +78,16 @@ public static FetchResult fetchRecipes(MessageWriter log, MavenArtifactResolver
targetVersion,
buildTool,
propRewritePluginVersion));
log.debug(String.format(
"Detected dependencies:\n %s ",
recipeDirectoryNames.entrySet().stream()
.map(e -> String.format("%s (%s -> %s)", e.getKey(), e.getValue()[0], e.getValue()[1]))
.sorted().collect(Collectors.joining("\n"))));
log.debug(String.format(
"Detected recipe(s):\n %s",
recipes.stream().map(o -> o[0]).sorted().collect(Collectors.joining("\n"))));
return new FetchResult(artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion(),
recipes, propRewritePluginVersion);
recipes.stream().map(o -> o[1]).collect(Collectors.toList()), propRewritePluginVersion);
} catch (BootstrapMavenException e) {
throw new RuntimeException("Failed to resolve artifact: " + gav, e);
} catch (IOException e) {
Expand Down Expand Up @@ -133,7 +142,7 @@ static boolean shouldApplyRecipe(String recipeFileName, String currentVersion, S
return currentAVersion.compareTo(recipeAVersion) < 0 && targetAVersion.compareTo(recipeAVersion) >= 0;
}

static List<String> fetchRecipesAsList(ResourceLoader resourceLoader, String location,
static List<String[]> fetchRecipesAsList(ResourceLoader resourceLoader, String location,
Map<String, String[]> recipeDirectoryNames) throws IOException {
return resourceLoader.loadResourceAsPath(location,
path -> {
Expand All @@ -152,7 +161,8 @@ static List<String> fetchRecipesAsList(ResourceLoader resourceLoader, String loc
versions[0], versions[1]))
.map(p -> {
try {
return new String(Files.readAllBytes(p));
return new String[] { p.toString(),
new String(Files.readAllBytes(p)) };
} catch (IOException e) {
throw new RuntimeException("Error reading file: " + p, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.junit.jupiter.api.Test;
Expand All @@ -30,7 +29,7 @@ void testShouldLoadRecipesFromTheDirectory() throws IOException {
recipeDirectoryNames.put("core", new String[] { "2.7", "3.1" });
recipeDirectoryNames.put("org.apache.camel.quarkus:camel-quarkus-core", new String[] { "2.7", "3.0" });
ClassPathResourceLoader resourceLoader = new ClassPathResourceLoader();
List<String> recipes = fetchRecipesAsList(resourceLoader, "dir/quarkus-update", recipeDirectoryNames);
Map<String, String> recipes = fetchRecipesAsList(resourceLoader, "dir/quarkus-update", recipeDirectoryNames);
int noOfRecipes = recipes.size();
assertEquals(3, noOfRecipes);

Expand Down

0 comments on commit 620bbee

Please sign in to comment.