Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/versioning/external_dependencies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ org.slf4j:slf4j-simple;1.7.36
redis.clients:jedis;6.2.0
testdep_net.bytebuddy:byte-buddy;1.17.7
testdep_net.bytebuddy:byte-buddy-agent;1.17.7
org.openrewrite.recipe:rewrite-recipe-bom;3.9.0
org.openrewrite.recipe:rewrite-recipe-bom;3.22.0

## Spring boot dependency versions
org.springframework.boot:spring-boot-maven-plugin;2.7.18
Expand Down
8 changes: 7 additions & 1 deletion sdk/tools/azure-openrewrite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-recipe-bom</artifactId>
<version>3.9.0</version> <!-- {x-version-update;org.openrewrite.recipe:rewrite-recipe-bom;external_dependency} -->
<version>3.22.0</version> <!-- {x-version-update;org.openrewrite.recipe:rewrite-recipe-bom;external_dependency} -->
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -113,6 +113,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-java-25</artifactId>
<scope>test</scope>
</dependency>

<!-- rewrite-maven dependency only necessary for Maven Recipe development -->


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.azure.openrewrite.migration;


import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.parallel.Execution;
Expand All @@ -9,6 +8,8 @@
import org.junit.jupiter.params.provider.MethodSource;
import org.openrewrite.Tree;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.style.Autodetect;
import org.openrewrite.java.style.ImportLayoutStyle;
import org.openrewrite.java.style.TabsAndIndentsStyle;
import org.openrewrite.style.NamedStyles;
import org.openrewrite.style.Style;
Expand All @@ -18,15 +19,16 @@
import org.openrewrite.test.TypeValidation;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.openrewrite.java.Assertions.java;
Expand All @@ -51,61 +53,34 @@ static boolean isDisabledDir(Path dir) {
}

static Stream<String> sampleDirectories() throws IOException {
List<Path> packageDirectories = packageDirectories().collect(Collectors.toList());
List<String> sampleDirectories = new ArrayList<>();
for (Path packageDirectory : packageDirectories) {
sampleDirectories.addAll(Files
.list(packageDirectory)
.filter(Files::isDirectory)
.map(path -> path.toString())
.collect(Collectors.toList()));
}

return sampleDirectories.stream();
return packageDirectories().flatMap(packageDirectory -> {
try {
return Files.list(packageDirectory).filter(Files::isDirectory).map(Path::toString);
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
});
}

static Stream<Path> packageDirectories() throws IOException {
return Files.list(Paths.get("src/test/resources/migrationExamples"))
.filter(Files::isDirectory);
return Files.list(Paths.get("src/test/resources/migrationExamples")).filter(Files::isDirectory);
}

static Stream<Path> gatherAllRegularFiles(Path sampleDir) throws IOException {
return Files.walk(sampleDir)
.filter(Files::isRegularFile).collect(Collectors.toList()).stream();
return Files.walk(sampleDir).filter(Files::isRegularFile);
}



private static List<NamedStyles> getStyles() {

List<Style> styles = new ArrayList<>();
styles.add(new org.openrewrite.java.style.ImportLayoutStyle(
9999,
9999,
org.openrewrite.java.style.Autodetect.detector().getImportLayoutStyle().getLayout(),
Collections.emptyList()
));
styles.add(new org.openrewrite.java.style.TabsAndIndentsStyle(
false,
4,
4,
4,
true,
new TabsAndIndentsStyle.MethodDeclarationParameters(true)
));



return Collections.singletonList(
new NamedStyles(
Tree.randomId(),
"com.azure.openrewrite.style",
"Azure OpenRewrite Style",
"The sytle for Azure OpenRewrite",
Collections.emptySet(),
styles
)
);
List<Style> styles = Arrays.asList(
new ImportLayoutStyle(9999, 9999, Autodetect.detector().getImportLayoutStyle().getLayout(),
Collections.emptyList()),
new TabsAndIndentsStyle(false, 4, 4, 4, true, new TabsAndIndentsStyle.MethodDeclarationParameters(true),
new TabsAndIndentsStyle.RecordComponents(true)));

return Collections.singletonList(new NamedStyles(Tree.randomId(), "com.azure.openrewrite.style",
"Azure OpenRewrite Style", "The style for Azure OpenRewrite", Collections.emptySet(), styles));
}

@Override
Expand All @@ -119,12 +94,12 @@ public void defaults(RecipeSpec spec) {
@Execution(ExecutionMode.CONCURRENT)
@MethodSource("sampleDirectories")
public void testGoldenImage(String sampleDirString) throws Exception {
System.out.printf("Sample: %s;\n Active Recipe: %s\n", sampleDirString, RECIPE_NAME);
System.out.printf("Sample: %s;\nActive Recipe: %s\n", sampleDirString, RECIPE_NAME);

Path sampleDir = Paths.get(sampleDirString);

Assumptions.assumeFalse(isDisabledDir(sampleDir));
Map<String, String> fileMap = new HashMap<String, String>();
Map<String, String> fileMap = new HashMap<>();

Path unmigratedDir = sampleDir.resolve(ORIGINAL_IMAGE);
gatherAllRegularFiles(unmigratedDir).forEach(file -> {
Expand All @@ -141,7 +116,7 @@ public void testGoldenImage(String sampleDirString) throws Exception {
}

public void assertFullMigration(Map<String,String> fileMap, String name) throws IOException {
List<SourceSpecs> sourceSpecs = new ArrayList<SourceSpecs>();
List<SourceSpecs> sourceSpecs = new ArrayList<>();
for (Map.Entry<String,String> entry : fileMap.entrySet()) {

String before = Files.readAllLines(Paths.get(entry.getKey()))
Expand All @@ -164,11 +139,10 @@ public void assertFullMigration(Map<String,String> fileMap, String name) throws
spec -> spec
.parser(JavaParser.fromJavaVersion().classpath(JavaParser.runtimeClasspath()).styles(getStyles()))
.recipeFromResources(RECIPE_NAME),
sourceSpecs.toArray(new SourceSpecs[sourceSpecs.size()])
sourceSpecs.toArray(new SourceSpecs[0])
);
} catch (AssertionError e) {
String message = e.getMessage();
throw new AssertionError("Migration failed for sample directory: " + name + "\n" + e.getLocalizedMessage());
throw new AssertionError("Migration failed for sample directory: " + name, e);
}

}
Expand Down
Loading