66import java .io .IOException ;
77import java .nio .file .Files ;
88import java .nio .file .Path ;
9- import java .nio .file .StandardCopyOption ;
109import java .util .Objects ;
1110
1211/**
1514 * @author Alexander Weigl
1615 * @version 1 (02.02.24)
1716 */
18- public record OutputEnvironment (Path targetFolder ) {
19- /** Returns the source code folder */
17+ public record OutputEnvironment (Path targetFolder , boolean onlyTestDir ) {
18+ /**
19+ * Returns the source code folder
20+ */
2021 public Path getSourceDir () {
21- return targetFolder .resolve ("src" );
22+ return targetFolder .resolve ("src/main/java " );
2223 }
2324
24- /** Returns the test code folder */
25+ /**
26+ * Returns the test code folder
27+ */
2528 public Path getTestSourceDir () {
26- return targetFolder .resolve ("test" );
29+ if (onlyTestDir ) {
30+ return targetFolder ;
31+ }
32+ return targetFolder .resolve ("src/test/java" );
2733 }
2834
29- /** Returns the path to the ANT build.xml file */
35+ /**
36+ * Returns the path to the ANT build.xml file
37+ */
3038 public Path getAntFile () {
3139 return targetFolder .resolve ("build.xml" );
3240 }
3341
34- /** Returns the path to the README.md file */
42+ /**
43+ * Returns the path to the ANT build.xml file
44+ */
45+ public Path getGradleFile () {
46+ return targetFolder .resolve ("build.gradle.kts" );
47+ }
48+
49+ /**
50+ * Returns the path to the pom.xml for Maven file
51+ */
52+ public Path getMavenFile () {
53+ return targetFolder .resolve ("pom.xml" );
54+ }
55+
56+
57+ /**
58+ * Returns the path to the README.md file
59+ */
3560 public Path getReadmeFile () {
3661 return targetFolder .resolve ("README.md" );
3762 }
@@ -42,15 +67,30 @@ public Path getReadmeFile() {
4267 * @throws IOException if the output folder is not write or the folders can not be created.
4368 */
4469 public void init () throws IOException {
45- Files .createDirectories (getSourceDir ());
4670 Files .createDirectories (getTestSourceDir ());
47- installAntFile ();
71+ if (!onlyTestDir ) {
72+ Files .createDirectories (getSourceDir ());
73+ installProjectFile ();
74+ }
4875 }
4976
50- private void installAntFile () throws IOException {
51- try (var buildXml = getClass ().getResourceAsStream ("/de/uka/ilkd/key/tcg/build.xml" )) {
52- Files .copy (Objects .requireNonNull (buildXml ), getAntFile (),
53- StandardCopyOption .REPLACE_EXISTING );
77+ private void installProjectFile () throws IOException {
78+ if (!Files .exists (getAntFile ())) {
79+ try (var buildXml = getClass ().getResourceAsStream ("/de/uka/ilkd/key/tcg/build.xml" )) {
80+ Files .copy (Objects .requireNonNull (buildXml ), getAntFile ());
81+ }
82+ }
83+
84+ if (!Files .exists (getMavenFile ())) {
85+ try (var pomXml = getClass ().getResourceAsStream ("/de/uka/ilkd/key/tcg/pom.xml" )) {
86+ Files .copy (Objects .requireNonNull (pomXml ), getMavenFile ());
87+ }
88+ }
89+
90+ if (!Files .exists (getGradleFile ())) {
91+ try (var gradleKts = getClass ().getResourceAsStream ("/de/uka/ilkd/key/tcg/build.gradle.kts" )) {
92+ Files .copy (Objects .requireNonNull (gradleKts ), getGradleFile ());
93+ }
5494 }
5595 }
5696}
0 commit comments