Skip to content

Commit 71d0351

Browse files
committed
Better use of outputDir & SaveRequest
1 parent 0877906 commit 71d0351

File tree

7 files changed

+41
-41
lines changed

7 files changed

+41
-41
lines changed

webtide-release-tools-api/src/main/java/net/webtide/tools/release/ChangelogTool.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public void save(SaveRequest saveRequest) throws IOException
443443
if (commit.getFiles() != null)
444444
changedFiles.addAll(commit.getFiles());
445445
}
446-
for (String filename : changedFiles.stream().sorted().collect(Collectors.toList()))
446+
for (String filename : changedFiles.stream().sorted().toList())
447447
{
448448
writer.write(filename);
449449
writer.write("\n");
@@ -479,7 +479,7 @@ public void setVersionRange(String tagOldVersion, String refCurrentVersion)
479479

480480
public void writeMarkdown(SaveRequest saveRequest) throws IOException
481481
{
482-
try (BufferedWriter writer = Files.newBufferedWriter(saveRequest.outputFile(), UTF_8);
482+
try (BufferedWriter writer = Files.newBufferedWriter(saveRequest.outputDir().resolve(saveRequest.outputFormat().getFilename()), UTF_8);
483483
PrintWriter out = new PrintWriter(writer))
484484
{
485485
List<Change> relevantChanges = changes.stream()
@@ -526,7 +526,7 @@ public void writeMarkdown(SaveRequest saveRequest) throws IOException
526526

527527
public void writeVersionTagTxt(SaveRequest saveRequest) throws IOException
528528
{
529-
try (BufferedWriter writer = Files.newBufferedWriter(saveRequest.outputFile(), UTF_8);
529+
try (BufferedWriter writer = Files.newBufferedWriter(saveRequest.outputDir().resolve(saveRequest.outputFormat().getFilename()), UTF_8);
530530
PrintWriter out = new PrintWriter(writer))
531531
{
532532
List<Change> relevantChanges = changes.stream()

webtide-release-tools-api/src/main/java/net/webtide/tools/release/Main.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
package net.webtide.tools.release;
1414

1515
import java.nio.file.Files;
16-
import java.nio.file.Path;
16+
17+
import static net.webtide.tools.release.SaveRequest.OUTPUT_FORMAT.MARKDOWN;
1718

1819
public class Main
1920
{
@@ -45,14 +46,12 @@ public static void main(String[] args) throws Exception
4546

4647
String projectVersion = null;
4748
String date = null;
48-
Path outputFile = null;
4949

5050
SaveRequest saveRequest = new SaveRequest(config.outputPath,
5151
config.includeDependencyChanges,
52-
SaveRequest.OUTPUT_FORMAT.MARKDOWN,
52+
MARKDOWN,
5353
projectVersion,
54-
date,
55-
outputFile);
54+
date);
5655
changelog.save(saveRequest);
5756
System.out.printf("Wrote changelog to %s%n", config.outputPath.toAbsolutePath());
5857
}

webtide-release-tools-api/src/main/java/net/webtide/tools/release/SaveRequest.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,23 @@
1515
import java.nio.file.Path;
1616

1717
public record SaveRequest(Path outputDir, boolean includeDependencyChanges, OUTPUT_FORMAT outputFormat, String projectVersion,
18-
String date, Path outputFile)
18+
String date)
1919
{
20-
2120
public enum OUTPUT_FORMAT
2221
{
23-
MARKDOWN, TAG_TXT
22+
MARKDOWN("changelog.md"),
23+
TAG_TXT("version-tag.txt");
24+
25+
String filename;
26+
27+
OUTPUT_FORMAT(String filename)
28+
{
29+
this.filename = filename;
30+
}
31+
32+
public String getFilename()
33+
{
34+
return filename;
35+
}
2436
}
2537
}

webtide-release-tools-plugin/src/main/java/net/webtide/tools/release/plugins/AbstractReleaseToolsPlugin.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
package net.webtide.tools.release.plugins;
1414

15+
import java.io.File;
1516
import java.io.IOException;
1617
import java.nio.file.Files;
1718
import java.nio.file.Path;
@@ -35,8 +36,8 @@ public abstract class AbstractReleaseToolsPlugin extends AbstractMojo
3536
protected String version;
3637
@Parameter(required = true)
3738
private Path configFile;
38-
@Parameter(defaultValue = "target/release-output")
39-
private Path outputDir;
39+
@Parameter(readonly = true, defaultValue = "${project.build.directory}")
40+
protected File projectBuildDirectory;
4041
@Parameter(property = "webtide.release.tools.refVersionCurrent")
4142
private String refVersionCurrent;
4243
@Parameter(property = "webtide.release.tools.tagVersionPrior")
@@ -85,7 +86,7 @@ protected Config buildConfig() throws MojoExecutionException
8586
try
8687
{
8788
this.config = Config.loadConfig(configFile);
88-
this.config.setOutputPath(outputDir);
89+
this.config.setOutputPath(projectBuildDirectory.toPath());
8990
this.config.setRefVersionCurrent(refVersionCurrent);
9091
this.config.setTagVersionPrior(tagVersionPrior);
9192
this.config.setRepoPath(Paths.get("./"));

webtide-release-tools-plugin/src/main/java/net/webtide/tools/release/plugins/GitHubReleaseMojo.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
package net.webtide.tools.release.plugins;
1414

15-
import java.io.File;
1615
import java.text.SimpleDateFormat;
1716
import java.util.Date;
1817

@@ -22,7 +21,8 @@
2221
import org.apache.maven.plugin.MojoFailureException;
2322
import org.apache.maven.plugins.annotations.LifecyclePhase;
2423
import org.apache.maven.plugins.annotations.Mojo;
25-
import org.apache.maven.plugins.annotations.Parameter;
24+
25+
import static net.webtide.tools.release.SaveRequest.OUTPUT_FORMAT.MARKDOWN;
2626

2727
/**
2828
* Produce a target/version-tag.txt which represents the changes
@@ -32,13 +32,6 @@
3232
@Mojo(name = "gh-release", defaultPhase = LifecyclePhase.PROCESS_RESOURCES, threadSafe = true)
3333
public class GitHubReleaseMojo extends AbstractReleaseToolsPlugin
3434
{
35-
36-
/**
37-
* The generated changelog file.
38-
*/
39-
@Parameter(property = "webtide.release.tools.gh-release.output.file", defaultValue = "${project.build.directory}/changelog.md")
40-
protected File changelogOutputFile;
41-
4235
@Override
4336
public void execute() throws MojoExecutionException, MojoFailureException
4437
{
@@ -49,14 +42,13 @@ public void execute() throws MojoExecutionException, MojoFailureException
4942
SaveRequest saveRequest = new SaveRequest(
5043
config.getOutputPath(),
5144
config.isIncludeDependencyChanges(),
52-
SaveRequest.OUTPUT_FORMAT.MARKDOWN,
45+
MARKDOWN,
5346
version,
54-
sdf.format(new Date()),
55-
changelogOutputFile.toPath()
47+
sdf.format(new Date())
5648
);
5749
doExecute(saveRequest);
5850

59-
getLog().info("Wrote version tag txt to" + changelogOutputFile);
51+
getLog().info("Wrote version tag txt to" + config.getOutputPath().resolve(MARKDOWN.getFilename()));
6052
}
6153
catch (Exception e)
6254
{

webtide-release-tools-plugin/src/main/java/net/webtide/tools/release/plugins/TagMojo.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
package net.webtide.tools.release.plugins;
1414

15-
import java.io.File;
1615
import java.text.SimpleDateFormat;
1716
import java.util.Date;
1817

@@ -22,7 +21,8 @@
2221
import org.apache.maven.plugin.MojoFailureException;
2322
import org.apache.maven.plugins.annotations.LifecyclePhase;
2423
import org.apache.maven.plugins.annotations.Mojo;
25-
import org.apache.maven.plugins.annotations.Parameter;
24+
25+
import static net.webtide.tools.release.SaveRequest.OUTPUT_FORMAT.TAG_TXT;
2626

2727
/**
2828
* Produce a target/version-tag.txt which represents the changes
@@ -32,13 +32,6 @@
3232
@Mojo(name = "tag", defaultPhase = LifecyclePhase.PROCESS_RESOURCES, threadSafe = true)
3333
public class TagMojo extends AbstractReleaseToolsPlugin
3434
{
35-
36-
/**
37-
* The generated version-tag.txt file.
38-
*/
39-
@Parameter(property = "webtide.release.tools.tag.output.file", defaultValue = "${project.build.directory}/version-tag.txt")
40-
protected File versionTagOutputFile;
41-
4235
@Override
4336
public void execute() throws MojoExecutionException, MojoFailureException
4437
{
@@ -49,14 +42,13 @@ public void execute() throws MojoExecutionException, MojoFailureException
4942
SaveRequest saveRequest = new SaveRequest(
5043
config.getOutputPath(),
5144
config.isIncludeDependencyChanges(),
52-
SaveRequest.OUTPUT_FORMAT.TAG_TXT,
45+
TAG_TXT,
5346
version,
54-
sdf.format(new Date()),
55-
versionTagOutputFile.toPath()
47+
sdf.format(new Date())
5648
);
5749
doExecute(saveRequest);
5850

59-
getLog().info("Wrote version tag txt to" + versionTagOutputFile);
51+
getLog().info("Wrote version tag txt to" + config.getOutputPath().resolve(TAG_TXT.getFilename()));
6052
}
6153
catch (Exception e)
6254
{

webtide-release-tools-plugin/src/main/java/net/webtide/tools/release/plugins/UpdateVersionTextMojo.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.io.File;
1616
import java.io.IOException;
1717
import java.nio.file.Files;
18+
import java.nio.file.Path;
1819
import java.nio.file.StandardOpenOption;
1920

2021
import org.apache.maven.plugin.MojoExecutionException;
@@ -23,6 +24,8 @@
2324
import org.apache.maven.plugins.annotations.Mojo;
2425
import org.apache.maven.plugins.annotations.Parameter;
2526

27+
import static net.webtide.tools.release.SaveRequest.OUTPUT_FORMAT.TAG_TXT;
28+
2629
@Mojo(name = "update-version-text", defaultPhase = LifecyclePhase.PACKAGE, threadSafe = true)
2730
public class UpdateVersionTextMojo extends TagMojo
2831
{
@@ -47,7 +50,8 @@ public void execute() throws MojoExecutionException, MojoFailureException
4750
try
4851
{
4952
Files.deleteIfExists(versionTextOutputFile.toPath());
50-
Files.write(versionTextOutputFile.toPath(), Files.readAllBytes(versionTagOutputFile.toPath()), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE);
53+
Path versionTagOutputFile = projectBuildDirectory.toPath().resolve(TAG_TXT.getFilename());
54+
Files.write(versionTextOutputFile.toPath(), Files.readAllBytes(versionTagOutputFile), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE);
5155
Files.write(versionTextOutputFile.toPath(), Files.readAllBytes(originalVersionTextOutputFile.toPath()), StandardOpenOption.APPEND);
5256
}
5357
catch (IOException e)

0 commit comments

Comments
 (0)