Skip to content

Commit

Permalink
Fix windows paths
Browse files Browse the repository at this point in the history
(cherry picked from commit 95e445d)
  • Loading branch information
ia3andy authored and aloubyansky committed Oct 31, 2023
1 parent edecc42 commit 154fe51
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public static FetchResult fetchRecipes(MessageWriter log, MavenArtifactResolver
recipeDirectoryNames.put("core", new String[] { currentVersion, targetVersion });
for (ExtensionUpdateInfo dep : topExtensionDependency) {
recipeDirectoryNames.put(
dep.getCurrentDep().getArtifact().getArtifactId() + "/"
+ dep.getCurrentDep().getArtifact().getGroupId(),
toKey(dep),
new String[] { dep.getCurrentDep().getVersion(), dep.getRecommendedDependency().getVersion() });
}

Expand Down Expand Up @@ -134,15 +133,15 @@ static boolean shouldApplyRecipe(String recipeFileName, String currentVersion, S
return currentAVersion.compareTo(recipeAVersion) < 0 && targetAVersion.compareTo(recipeAVersion) >= 0;
}

static List<String> fetchRecipesAsList(ResourceLoader resourceLoader, String loaction,
static List<String> fetchRecipesAsList(ResourceLoader resourceLoader, String location,
Map<String, String[]> recipeDirectoryNames) throws IOException {
return resourceLoader.loadResourceAsPath(loaction,
return resourceLoader.loadResourceAsPath(location,
path -> {
try (final Stream<Path> pathStream = Files.walk(path)) {
return pathStream
.filter(Files::isDirectory)
.flatMap(dir -> {
String key = path.relativize(dir).toString();
String key = toKey(path.relativize(dir).toString());
String versions[] = recipeDirectoryNames.get(key);
if (versions != null && versions.length != 0) {
try {
Expand Down Expand Up @@ -172,4 +171,15 @@ static List<String> fetchRecipesAsList(ResourceLoader resourceLoader, String loa
});

}

private static String toKey(ExtensionUpdateInfo dep) {
return String.format("%s:%s", dep.getCurrentDep().getArtifact().getGroupId(),
dep.getCurrentDep().getArtifact().getArtifactId());
}

static String toKey(String directory) {
return directory
.replaceAll("(^[/\\\\])|([/\\\\]$)", "")
.replaceAll("[/\\\\]", ":");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ void testShouldApplyRecipeWithCSV(String recipeVersion, String currentVersion, S
void testShouldLoadRecipesFromTheDirectory() throws IOException {
Map<String, String[]> recipeDirectoryNames = new LinkedHashMap<>();
recipeDirectoryNames.put("core", new String[] { "2.7", "3.1" });
recipeDirectoryNames.put("org.apache.camel.quarkus/camel-quarkus-core", new String[] { "2.7", "3.0" });
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);
int noOfRecipes = recipes.size();
assertEquals(noOfRecipes, 3);
assertEquals(3, noOfRecipes);

}
}

0 comments on commit 154fe51

Please sign in to comment.