mirror of
https://gitee.com/dcren/initializr.git
synced 2025-09-19 01:58:16 +08:00
Move source file extension to Language abstraction
Closes gh-995
This commit is contained in:
@@ -53,121 +53,122 @@ class CodeComplianceTests extends AbstractComplianceTests {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
void currentGenerationJar(Language language, String extension) {
|
||||
void currentGenerationJar(Language language) {
|
||||
ProjectStructure project = generateProject(language, maven, "2.1.1.RELEASE");
|
||||
assertThat(project).filePaths().contains(
|
||||
String.format("src/main/%s/com/example/demo/DemoApplication.%s", language.id(), extension),
|
||||
String.format("src/test/%s/com/example/demo/DemoApplicationTests.%s", language.id(), extension),
|
||||
String.format("src/main/%s/com/example/demo/DemoApplication.%s", language.id(),
|
||||
language.sourceFileExtension()),
|
||||
String.format("src/test/%s/com/example/demo/DemoApplicationTests.%s", language.id(),
|
||||
language.sourceFileExtension()),
|
||||
"src/main/resources/application.properties");
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
void currentGenerationWar(Language language, String extension) {
|
||||
void currentGenerationWar(Language language) {
|
||||
ProjectStructure project = generateProject(language, maven, "2.1.1.RELEASE",
|
||||
(description) -> description.setPackaging(Packaging.forId("war")));
|
||||
assertThat(project).filePaths().contains(
|
||||
String.format("src/main/%s/com/example/demo/DemoApplication.%s", language.id(), extension),
|
||||
String.format("src/test/%s/com/example/demo/DemoApplicationTests.%s", language.id(), extension),
|
||||
String.format("src/main/%s/com/example/demo/DemoApplication.%s", language.id(),
|
||||
language.sourceFileExtension()),
|
||||
String.format("src/test/%s/com/example/demo/DemoApplicationTests.%s", language.id(),
|
||||
language.sourceFileExtension()),
|
||||
"src/main/resources/application.properties");
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
void currentGenerationMainClass(Language language, String extension) {
|
||||
void currentGenerationMainClass(Language language) {
|
||||
ProjectStructure project = generateProject(language, maven, "2.1.1.RELEASE");
|
||||
assertThat(project).asJvmModule(language, extension).mainSource("com.example.demo", "DemoApplication")
|
||||
assertThat(project).asJvmModule(language).mainSource("com.example.demo", "DemoApplication")
|
||||
.hasSameContentAs(new ClassPathResource(
|
||||
"project/" + language + "/standard/DemoApplication." + getExpectedExtension(extension)));
|
||||
"project/" + language + "/standard/DemoApplication." + getExpectedExtension(language)));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
void previousGenerationMainClass(Language language, String extension) {
|
||||
void previousGenerationMainClass(Language language) {
|
||||
ProjectStructure project = generateProject(language, maven, "2.1.1.RELEASE",
|
||||
(description) -> description.setPlatformVersion(Version.parse("1.5.18.RELEASE")));
|
||||
assertThat(project).asJvmModule(language, extension).mainSource("com.example.demo", "DemoApplication")
|
||||
assertThat(project).asJvmModule(language).mainSource("com.example.demo", "DemoApplication")
|
||||
.hasSameContentAs(new ClassPathResource(
|
||||
"project/" + language + "/previous/" + "/DemoApplication." + getExpectedExtension(extension)));
|
||||
"project/" + language + "/previous/" + "/DemoApplication." + getExpectedExtension(language)));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
void currentGenerationTestClass(Language language, String extension) {
|
||||
void currentGenerationTestClass(Language language) {
|
||||
ProjectStructure project = generateProject(language, maven, "2.1.1.RELEASE");
|
||||
assertThat(project).asJvmModule(language, extension).testSource("com.example.demo", "DemoApplicationTests")
|
||||
assertThat(project).asJvmModule(language).testSource("com.example.demo", "DemoApplicationTests")
|
||||
.hasSameContentAs(new ClassPathResource(
|
||||
"project/" + language + "/standard/DemoApplicationTests." + getExpectedExtension(extension)));
|
||||
"project/" + language + "/standard/DemoApplicationTests." + getExpectedExtension(language)));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
void currentGenerationTestClassWeb(Language language, String extension) {
|
||||
void currentGenerationTestClassWeb(Language language) {
|
||||
ProjectStructure project = generateProject(language, maven, "2.1.1.RELEASE",
|
||||
(description) -> description.addDependency("web", MetadataBuildItemMapper.toDependency(WEB)));
|
||||
assertThat(project).asJvmModule(language, extension).testSource("com.example.demo", "DemoApplicationTests")
|
||||
.hasSameContentAs(new ClassPathResource("project/" + language + "/standard/DemoApplicationTestsWeb."
|
||||
+ getExpectedExtension(extension)));
|
||||
assertThat(project).asJvmModule(language).testSource("com.example.demo", "DemoApplicationTests")
|
||||
.hasSameContentAs(new ClassPathResource(
|
||||
"project/" + language + "/standard/DemoApplicationTestsWeb." + getExpectedExtension(language)));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
void currentGenerationServletInitializer(Language language, String extension) {
|
||||
void currentGenerationServletInitializer(Language language) {
|
||||
ProjectStructure project = generateProject(language, maven, "2.1.1.RELEASE",
|
||||
(description) -> description.setPackaging(Packaging.forId("war")));
|
||||
assertThat(project).asJvmModule(language, extension).mainSource("com.example.demo", "ServletInitializer")
|
||||
.hasSameContentAs(new ClassPathResource("project/" + language + "/standard/" + "ServletInitializer."
|
||||
+ getExpectedExtension(extension)));
|
||||
assertThat(project).asJvmModule(language).mainSource("com.example.demo", "ServletInitializer")
|
||||
.hasSameContentAs(new ClassPathResource(
|
||||
"project/" + language + "/standard/" + "ServletInitializer." + getExpectedExtension(language)));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
void previousGenerationServletInitializer(Language language, String extension) {
|
||||
void previousGenerationServletInitializer(Language language) {
|
||||
ProjectStructure project = generateProject(language, maven, "2.1.1.RELEASE", (description) -> {
|
||||
description.setPackaging(Packaging.forId("war"));
|
||||
description.setPlatformVersion(Version.parse("1.5.18.RELEASE"));
|
||||
});
|
||||
assertThat(project).asJvmModule(language, extension).mainSource("com.example.demo", "ServletInitializer")
|
||||
.hasSameContentAs(new ClassPathResource("project/" + language + "/previous/" + "ServletInitializer."
|
||||
+ getExpectedExtension(extension)));
|
||||
assertThat(project).asJvmModule(language).mainSource("com.example.demo", "ServletInitializer")
|
||||
.hasSameContentAs(new ClassPathResource(
|
||||
"project/" + language + "/previous/" + "ServletInitializer." + getExpectedExtension(language)));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
void currentGenerationCustomCoordinates(Language language, String extension) {
|
||||
void currentGenerationCustomCoordinates(Language language) {
|
||||
ProjectStructure project = generateProject(language, maven, "2.1.1.RELEASE", (description) -> {
|
||||
description.setGroupId("com.example.acme");
|
||||
description.setArtifactId("my-project");
|
||||
description.setPackageName("com.example.acme.myproject");
|
||||
description.setApplicationName("MyProjectApplication");
|
||||
});
|
||||
assertThat(project).asJvmModule(language, extension)
|
||||
.mainSource("com.example.acme.myproject", "MyProjectApplication")
|
||||
assertThat(project).asJvmModule(language).mainSource("com.example.acme.myproject", "MyProjectApplication")
|
||||
.hasSameContentAs(new ClassPathResource(
|
||||
"project/" + language + "/standard/MyProjectApplication." + getExpectedExtension(extension)));
|
||||
assertThat(project).asJvmModule(language, extension)
|
||||
.testSource("com.example.acme.myproject", "MyProjectApplicationTests")
|
||||
"project/" + language + "/standard/MyProjectApplication." + getExpectedExtension(language)));
|
||||
assertThat(project).asJvmModule(language).testSource("com.example.acme.myproject", "MyProjectApplicationTests")
|
||||
.hasSameContentAs(new ClassPathResource("project/" + language + "/standard/MyProjectApplicationTests."
|
||||
+ getExpectedExtension(extension)));
|
||||
+ getExpectedExtension(language)));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
void previousGenerationCustomCoordinates(Language language, String extension) {
|
||||
void previousGenerationCustomCoordinates(Language language) {
|
||||
ProjectStructure project = generateProject(language, maven, "1.5.18.RELEASE", (description) -> {
|
||||
description.setGroupId("com.example.acme");
|
||||
description.setArtifactId("my-project");
|
||||
description.setPackageName("com.example.acme.myproject");
|
||||
description.setApplicationName("MyProjectApplication");
|
||||
});
|
||||
assertThat(project).asJvmModule(language, extension)
|
||||
.mainSource("com.example.acme.myproject", "MyProjectApplication")
|
||||
assertThat(project).asJvmModule(language).mainSource("com.example.acme.myproject", "MyProjectApplication")
|
||||
.hasSameContentAs(new ClassPathResource(
|
||||
"project/" + language + "/previous/MyProjectApplication." + getExpectedExtension(extension)));
|
||||
"project/" + language + "/previous/MyProjectApplication." + getExpectedExtension(language)));
|
||||
}
|
||||
|
||||
private String getExpectedExtension(String extension) {
|
||||
return extension + ".gen";
|
||||
private String getExpectedExtension(Language language) {
|
||||
return language.sourceFileExtension() + ".gen";
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -40,12 +40,11 @@ public abstract class AbstractJvmModuleAssert<SELF extends AbstractJvmModuleAsse
|
||||
|
||||
private final String sourceFileExtension;
|
||||
|
||||
protected AbstractJvmModuleAssert(Path projectDirectory, Language language, String sourceFileExtension,
|
||||
Class<?> selfType) {
|
||||
protected AbstractJvmModuleAssert(Path projectDirectory, Language language, Class<?> selfType) {
|
||||
super(projectDirectory, selfType);
|
||||
this.mainDirectory = new SourceStructure(projectDirectory.resolve("src/main/"), language.id());
|
||||
this.testDirectory = new SourceStructure(projectDirectory.resolve("src/test/"), language.id());
|
||||
this.sourceFileExtension = sourceFileExtension;
|
||||
this.mainDirectory = new SourceStructure(projectDirectory.resolve("src/main/"), language);
|
||||
this.testDirectory = new SourceStructure(projectDirectory.resolve("src/test/"), language);
|
||||
this.sourceFileExtension = language.sourceFileExtension();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -37,16 +37,15 @@ public abstract class AbstractModuleAssert<SELF extends AbstractModuleAssert<SEL
|
||||
|
||||
/**
|
||||
* Return a {@link JvmModuleAssert JVM module} assertion for the specified
|
||||
* {@link Language} and file source extension, to allow chaining of jvm
|
||||
* module-specific assertions from this call.
|
||||
* {@link Language}, to allow chaining of jvm module-specific assertions from this
|
||||
* call.
|
||||
* <p>
|
||||
* Does not validate that the module has source code for the specified language.
|
||||
* @param language the language of the module
|
||||
* @param sourceFileExtension the source file extension
|
||||
* @return a {@link JvmModuleAssert} for the specified language
|
||||
*/
|
||||
public JvmModuleAssert asJvmModule(Language language, String sourceFileExtension) {
|
||||
return new JvmModuleAssert(this.actual, language, sourceFileExtension);
|
||||
public JvmModuleAssert asJvmModule(Language language) {
|
||||
return new JvmModuleAssert(this.actual, language);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -27,8 +27,8 @@ import io.spring.initializr.generator.language.Language;
|
||||
*/
|
||||
public class JvmModuleAssert extends AbstractJvmModuleAssert<JvmModuleAssert> {
|
||||
|
||||
public JvmModuleAssert(Path projectDirectory, Language language, String sourceFileExtension) {
|
||||
super(projectDirectory, language, sourceFileExtension, JvmModuleAssert.class);
|
||||
public JvmModuleAssert(Path projectDirectory, Language language) {
|
||||
super(projectDirectory, language, JvmModuleAssert.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -137,7 +137,7 @@ class JvmModuleAssertTests {
|
||||
}
|
||||
|
||||
private AssertProvider<AbstractJvmModuleAssert> forJavaProject(Path root) {
|
||||
return () -> new JvmModuleAssert(root, JAVA_LANGUAGE, "java");
|
||||
return () -> new JvmModuleAssert(root, JAVA_LANGUAGE);
|
||||
}
|
||||
|
||||
private void createFile(Path root, String path) throws IOException {
|
||||
|
@@ -127,7 +127,7 @@ class ModuleAssertTests {
|
||||
@Test
|
||||
void asJavaProject(@TempDir Path dir) throws IOException {
|
||||
createFiles(dir, "src/main/java/com/example/Test.java");
|
||||
assertThat(forDirectory(dir)).asJvmModule(new JavaLanguage(), "java").hasMainPackage("com.example")
|
||||
assertThat(forDirectory(dir)).asJvmModule(new JavaLanguage()).hasMainPackage("com.example")
|
||||
.hasMainSource("com.example", "Test");
|
||||
}
|
||||
|
||||
|
@@ -53,7 +53,7 @@ public interface BuildSystem {
|
||||
* @return a {@link SourceStructure} for main assets
|
||||
*/
|
||||
default SourceStructure getMainSource(Path projectRoot, Language language) {
|
||||
return new SourceStructure(projectRoot.resolve("src/main/"), language.id());
|
||||
return new SourceStructure(projectRoot.resolve("src/main/"), language);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +63,7 @@ public interface BuildSystem {
|
||||
* @return a {@link SourceStructure} for test assets
|
||||
*/
|
||||
default SourceStructure getTestSource(Path projectRoot, Language language) {
|
||||
return new SourceStructure(projectRoot.resolve("src/test/"), language.id());
|
||||
return new SourceStructure(projectRoot.resolve("src/test/"), language);
|
||||
}
|
||||
|
||||
static BuildSystem forId(String id) {
|
||||
|
@@ -27,9 +27,12 @@ public abstract class AbstractLanguage implements Language {
|
||||
|
||||
private final String jvmVersion;
|
||||
|
||||
protected AbstractLanguage(String id, String jvmVersion) {
|
||||
private final String sourceFileExtension;
|
||||
|
||||
protected AbstractLanguage(String id, String jvmVersion, String sourceFileExtension) {
|
||||
this.id = id;
|
||||
this.jvmVersion = (jvmVersion != null) ? jvmVersion : DEFAULT_JVM_VERSION;
|
||||
this.sourceFileExtension = sourceFileExtension;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -42,6 +45,11 @@ public abstract class AbstractLanguage implements Language {
|
||||
return this.jvmVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String sourceFileExtension() {
|
||||
return this.sourceFileExtension;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return id();
|
||||
|
@@ -32,10 +32,24 @@ public interface Language {
|
||||
*/
|
||||
String DEFAULT_JVM_VERSION = "1.8";
|
||||
|
||||
/**
|
||||
* Return the language identifier.
|
||||
* @return the language id
|
||||
*/
|
||||
String id();
|
||||
|
||||
/**
|
||||
* Return the JVM version level to use.
|
||||
* @return the JVM version or {@value DEFAULT_JVM_VERSION} if not set
|
||||
*/
|
||||
String jvmVersion();
|
||||
|
||||
/**
|
||||
* Return the file extension to use for source file of this language.
|
||||
* @return the source file extension
|
||||
*/
|
||||
String sourceFileExtension();
|
||||
|
||||
static Language forId(String id, String jvmVersion) {
|
||||
return SpringFactoriesLoader.loadFactories(LanguageFactory.class, LanguageFactory.class.getClassLoader())
|
||||
.stream().map((factory) -> factory.createLanguage(id, jvmVersion)).filter(Objects::nonNull).findFirst()
|
||||
|
@@ -21,7 +21,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* Provide dedicated method for directories that hold sources.
|
||||
* Provide dedicated methods for a structure that holds sources.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@@ -29,16 +29,19 @@ public class SourceStructure {
|
||||
|
||||
private final Path rootDirectory;
|
||||
|
||||
private final Language language;
|
||||
|
||||
private final Path sourcesDirectory;
|
||||
|
||||
public SourceStructure(Path rootDirectory, String sourcesDirectoryName) {
|
||||
public SourceStructure(Path rootDirectory, Language language) {
|
||||
this.rootDirectory = rootDirectory;
|
||||
this.sourcesDirectory = rootDirectory.resolve(sourcesDirectoryName);
|
||||
this.language = language;
|
||||
this.sourcesDirectory = rootDirectory.resolve(language.id());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the root {@link Path} of this structure. Can be used to access additional
|
||||
* resources.
|
||||
* Return the root {@link Path directory} of this structure. Can be used to access
|
||||
* additional resources.
|
||||
* @return the root directory
|
||||
*/
|
||||
public Path getRootDirectory() {
|
||||
@@ -46,7 +49,7 @@ public class SourceStructure {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the sources {@link Path} of this structure.
|
||||
* Return the sources {@link Path directory} of this structure.
|
||||
* @return the source code directory
|
||||
*/
|
||||
public Path getSourcesDirectory() {
|
||||
@@ -54,15 +57,17 @@ public class SourceStructure {
|
||||
}
|
||||
|
||||
/**
|
||||
* Resource a source file, creating its package structure if necessary.
|
||||
* Resolve a source file, creating its package structure if necessary. Does not create
|
||||
* the file itself.
|
||||
* @param packageName the name of the package
|
||||
* @param file the name of the file (including its extension)
|
||||
* @return the file to use to store a {@code CompilationUnit} with the specified
|
||||
* package name name
|
||||
* @param fileName the name of the file (without its extension)
|
||||
* @return the {@link Path file} to use to store a {@code CompilationUnit} with the
|
||||
* specified package and name
|
||||
* @throws IOException if an error occurred while trying to create the directory
|
||||
* structure
|
||||
*/
|
||||
public Path resolveSourceFile(String packageName, String file) throws IOException {
|
||||
public Path resolveSourceFile(String packageName, String fileName) throws IOException {
|
||||
String file = fileName + "." + this.language.sourceFileExtension();
|
||||
return createPackage(this.sourcesDirectory, packageName).resolve(file);
|
||||
}
|
||||
|
||||
|
@@ -36,7 +36,7 @@ public final class GroovyLanguage extends AbstractLanguage {
|
||||
}
|
||||
|
||||
public GroovyLanguage(String jvmVersion) {
|
||||
super(ID, jvmVersion);
|
||||
super(ID, jvmVersion, "groovy");
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -95,8 +95,7 @@ public class GroovySourceCodeWriter implements SourceCodeWriter<GroovySourceCode
|
||||
}
|
||||
|
||||
private void writeTo(SourceStructure structure, GroovyCompilationUnit compilationUnit) throws IOException {
|
||||
Path output = structure.resolveSourceFile(compilationUnit.getPackageName(),
|
||||
compilationUnit.getName() + ".groovy");
|
||||
Path output = structure.resolveSourceFile(compilationUnit.getPackageName(), compilationUnit.getName());
|
||||
try (IndentingWriter writer = this.indentingWriterFactory.createIndentingWriter("groovy",
|
||||
Files.newBufferedWriter(output))) {
|
||||
writer.println("package " + compilationUnit.getPackageName());
|
||||
|
@@ -37,7 +37,7 @@ public final class JavaLanguage extends AbstractLanguage {
|
||||
}
|
||||
|
||||
public JavaLanguage(String jvmVersion) {
|
||||
super(ID, jvmVersion);
|
||||
super(ID, jvmVersion, "java");
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -96,8 +96,7 @@ public class JavaSourceCodeWriter implements SourceCodeWriter<JavaSourceCode> {
|
||||
}
|
||||
|
||||
private void writeTo(SourceStructure structure, JavaCompilationUnit compilationUnit) throws IOException {
|
||||
Path output = structure.resolveSourceFile(compilationUnit.getPackageName(),
|
||||
compilationUnit.getName() + ".java");
|
||||
Path output = structure.resolveSourceFile(compilationUnit.getPackageName(), compilationUnit.getName());
|
||||
Files.createDirectories(output.getParent());
|
||||
try (IndentingWriter writer = this.indentingWriterFactory.createIndentingWriter("java",
|
||||
Files.newBufferedWriter(output))) {
|
||||
|
@@ -36,7 +36,7 @@ public final class KotlinLanguage extends AbstractLanguage {
|
||||
}
|
||||
|
||||
public KotlinLanguage(String jvmVersion) {
|
||||
super(ID, jvmVersion);
|
||||
super(ID, jvmVersion, "kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -61,7 +61,7 @@ public class KotlinSourceCodeWriter implements SourceCodeWriter<KotlinSourceCode
|
||||
}
|
||||
|
||||
private void writeTo(SourceStructure structure, KotlinCompilationUnit compilationUnit) throws IOException {
|
||||
Path output = structure.resolveSourceFile(compilationUnit.getPackageName(), compilationUnit.getName() + ".kt");
|
||||
Path output = structure.resolveSourceFile(compilationUnit.getPackageName(), compilationUnit.getName());
|
||||
Files.createDirectories(output.getParent());
|
||||
try (IndentingWriter writer = this.indentingWriterFactory.createIndentingWriter("kotlin",
|
||||
Files.newBufferedWriter(output))) {
|
||||
|
@@ -53,14 +53,14 @@ class BuildSystemTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultMainDirectory(@TempDir Path directory) {
|
||||
void defaultMainSource(@TempDir Path directory) {
|
||||
SourceStructure mainCodeStructure = BuildSystem.forId("gradle").getMainSource(directory, new JavaLanguage());
|
||||
assertThat(mainCodeStructure.getRootDirectory()).isEqualTo(directory.resolve("src/main"));
|
||||
assertThat(mainCodeStructure.getSourcesDirectory()).isEqualTo(directory.resolve("src/main/java"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultTestDirectory(@TempDir Path directory) {
|
||||
void defaultTestSource(@TempDir Path directory) {
|
||||
SourceStructure testCodeStructure = BuildSystem.forId("gradle").getTestSource(directory, new KotlinLanguage());
|
||||
assertThat(testCodeStructure.getRootDirectory()).isEqualTo(directory.resolve("src/test"));
|
||||
assertThat(testCodeStructure.getSourcesDirectory()).isEqualTo(directory.resolve("src/test/kotlin"));
|
||||
|
@@ -20,6 +20,7 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import io.spring.initializr.generator.language.java.JavaLanguage;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
@@ -32,9 +33,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
class SourceStructureTests {
|
||||
|
||||
public static final JavaLanguage JAVA_LANGUAGE = new JavaLanguage();
|
||||
|
||||
@Test
|
||||
void createPackage(@TempDir Path dir) throws IOException {
|
||||
Path target = new SourceStructure(dir, "java").createPackage(dir, "com.example.test");
|
||||
Path target = new SourceStructure(dir, JAVA_LANGUAGE).createPackage(dir, "com.example.test");
|
||||
assertThat(target).exists().isDirectory().isEqualByComparingTo(dir.resolve("com/example/test"));
|
||||
}
|
||||
|
||||
@@ -43,7 +46,7 @@ class SourceStructureTests {
|
||||
Path target = dir.resolve("com/example");
|
||||
Files.createDirectories(target);
|
||||
assertThat(target).exists().isDirectory();
|
||||
Path path = new SourceStructure(dir, "java").createPackage(dir, "com.example");
|
||||
Path path = new SourceStructure(dir, JAVA_LANGUAGE).createPackage(dir, "com.example");
|
||||
assertThat(path).isEqualByComparingTo(target);
|
||||
}
|
||||
|
||||
@@ -52,7 +55,8 @@ class SourceStructureTests {
|
||||
Path rootDir = dir.resolve("src/main/java/com/example");
|
||||
assertThat(rootDir).doesNotExist();
|
||||
Path target = rootDir.resolve("Test.java");
|
||||
Path path = new SourceStructure(dir, "src/main/java").resolveSourceFile("com.example", "Test.java");
|
||||
SourceStructure sourceStructure = new SourceStructure(dir.resolve("src/main"), JAVA_LANGUAGE);
|
||||
Path path = sourceStructure.resolveSourceFile("com.example", "Test");
|
||||
assertThat(path).doesNotExist().isEqualByComparingTo(target);
|
||||
assertThat(rootDir).exists().isDirectory();
|
||||
}
|
||||
@@ -64,7 +68,8 @@ class SourceStructureTests {
|
||||
assertThat(rootDir).exists().isDirectory();
|
||||
Path target = rootDir.resolve("Test.java");
|
||||
assertThat(target).doesNotExist();
|
||||
Path path = new SourceStructure(dir, "src/main/java").resolveSourceFile("com.example", "Test.java");
|
||||
SourceStructure sourceStructure = new SourceStructure(dir.resolve("src/main"), JAVA_LANGUAGE);
|
||||
Path path = sourceStructure.resolveSourceFile("com.example", "Test");
|
||||
assertThat(path).doesNotExist().isEqualByComparingTo(target);
|
||||
}
|
||||
|
||||
|
@@ -29,6 +29,7 @@ import java.util.UUID;
|
||||
|
||||
import io.spring.initializr.generator.io.IndentingWriterFactory;
|
||||
import io.spring.initializr.generator.language.Annotation;
|
||||
import io.spring.initializr.generator.language.Language;
|
||||
import io.spring.initializr.generator.language.Parameter;
|
||||
import io.spring.initializr.generator.language.SourceStructure;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -47,6 +48,8 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
*/
|
||||
class GroovySourceCodeWriterTests {
|
||||
|
||||
private static final Language LANGUAGE = new GroovyLanguage();
|
||||
|
||||
@TempDir
|
||||
Path directory;
|
||||
|
||||
@@ -285,7 +288,8 @@ class GroovySourceCodeWriterTests {
|
||||
}
|
||||
|
||||
private Path writeSourceCode(GroovySourceCode sourceCode) throws IOException {
|
||||
SourceStructure sourceStructure = new SourceStructure(this.directory, UUID.randomUUID().toString());
|
||||
Path srcDirectory = this.directory.resolve(UUID.randomUUID().toString());
|
||||
SourceStructure sourceStructure = new SourceStructure(srcDirectory, LANGUAGE);
|
||||
this.writer.writeTo(sourceStructure, sourceCode);
|
||||
return sourceStructure.getSourcesDirectory();
|
||||
}
|
||||
|
@@ -29,6 +29,7 @@ import java.util.UUID;
|
||||
|
||||
import io.spring.initializr.generator.io.IndentingWriterFactory;
|
||||
import io.spring.initializr.generator.language.Annotation;
|
||||
import io.spring.initializr.generator.language.Language;
|
||||
import io.spring.initializr.generator.language.Parameter;
|
||||
import io.spring.initializr.generator.language.SourceStructure;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -47,6 +48,8 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
*/
|
||||
class JavaSourceCodeWriterTests {
|
||||
|
||||
private static final Language LANGUAGE = new JavaLanguage();
|
||||
|
||||
@TempDir
|
||||
Path directory;
|
||||
|
||||
@@ -286,7 +289,8 @@ class JavaSourceCodeWriterTests {
|
||||
}
|
||||
|
||||
private Path writeSourceCode(JavaSourceCode sourceCode) throws IOException {
|
||||
SourceStructure sourceStructure = new SourceStructure(this.directory, UUID.randomUUID().toString());
|
||||
Path srcDirectory = this.directory.resolve(UUID.randomUUID().toString());
|
||||
SourceStructure sourceStructure = new SourceStructure(srcDirectory, LANGUAGE);
|
||||
this.writer.writeTo(sourceStructure, sourceCode);
|
||||
return sourceStructure.getSourcesDirectory();
|
||||
}
|
||||
|
@@ -28,6 +28,7 @@ import java.util.UUID;
|
||||
|
||||
import io.spring.initializr.generator.io.IndentingWriterFactory;
|
||||
import io.spring.initializr.generator.language.Annotation;
|
||||
import io.spring.initializr.generator.language.Language;
|
||||
import io.spring.initializr.generator.language.Parameter;
|
||||
import io.spring.initializr.generator.language.SourceStructure;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -46,6 +47,8 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
*/
|
||||
class KotlinSourceCodeWriterTests {
|
||||
|
||||
private static final Language LANGUAGE = new KotlinLanguage();
|
||||
|
||||
@TempDir
|
||||
Path directory;
|
||||
|
||||
@@ -343,7 +346,8 @@ class KotlinSourceCodeWriterTests {
|
||||
}
|
||||
|
||||
private Path writeSourceCode(KotlinSourceCode sourceCode) throws IOException {
|
||||
SourceStructure sourceStructure = new SourceStructure(this.directory, UUID.randomUUID().toString());
|
||||
Path srcDirectory = this.directory.resolve(UUID.randomUUID().toString());
|
||||
SourceStructure sourceStructure = new SourceStructure(srcDirectory, LANGUAGE);
|
||||
this.writer.writeTo(sourceStructure, sourceCode);
|
||||
return sourceStructure.getSourcesDirectory();
|
||||
}
|
||||
|
Reference in New Issue
Block a user