Skip to content

Commit ac945e9

Browse files
committed
fix: add working dir to generate changelog and update valid pom
1 parent 39b9804 commit ac945e9

File tree

5 files changed

+24
-14
lines changed

5 files changed

+24
-14
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ mvn io.github.zorin95670:semantic-version:release -DtagPrefix=plugin-a@
109109

110110
---
111111

112-
### 📂 Specifying the Working Directory (`basedir`)
112+
### 📂 Specifying the Working Directory (`workingdir`)
113113

114-
All plugin goals support the `basedir` parameter, which determines the directory where the command operates.
114+
All plugin goals support the `workingdir` parameter, which determines the directory where the command operates.
115115

116116
* **Default:** The current working directory where the command is executed.
117-
* **Override:** You can explicitly set the directory using `-Dbasedir=/path/to/your/project`.
117+
* **Override:** You can explicitly set the directory using `-Dworkingdir=/path/to/your/project`.
118118

119119
#### Examples:
120120

@@ -123,12 +123,12 @@ All plugin goals support the `basedir` parameter, which determines the directory
123123
mvn io.github.zorin95670:semantic-version:changelog \
124124
-DtagPrefix=plugin-a@ \
125125
-Dscope=plugin-a \
126-
-Dbasedir=plugins/plugin-a
126+
-Dworkingdir=plugins/plugin-a
127127

128128
# Run release from a custom folder
129129
mvn io.github.zorin95670:semantic-version:release \
130130
-DtagPrefix=plugin-b@ \
131-
-Dbasedir=/absolute/path/to/plugin-b
131+
-Dworkingdir=/absolute/path/to/plugin-b
132132
```
133133

134134
---

src/main/java/io/github/zorin95670/semver/GenerateChangelogMojo.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public class GenerateChangelogMojo extends AbstractMojo {
2525
@Parameter(property = "basedir", defaultValue = "${basedir}", readonly = true)
2626
private File basedir;
2727

28+
@Parameter(property = "workingdir", defaultValue = "${basedir}", readonly = true)
29+
private File workingdir;
30+
2831
public void execute() throws MojoExecutionException {
2932
if (scope == null) {
3033
scope = "";
@@ -34,7 +37,7 @@ public void execute() throws MojoExecutionException {
3437
}
3538
getLog().info("Generate Changelog plugin started");
3639
GitService gitService = new GitService(basedir);
37-
ChangelogService changelogService = new ChangelogService(basedir);
40+
ChangelogService changelogService = new ChangelogService(workingdir);
3841

3942

4043
changelogService.generateFromBeginning(

src/main/java/io/github/zorin95670/semver/ReleaseMojo.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,20 @@ public class ReleaseMojo extends AbstractMojo {
2828
@Parameter(property = "basedir", defaultValue = "${basedir}", readonly = true)
2929
private File basedir;
3030

31+
@Parameter(property = "workingdir", defaultValue = "${basedir}", readonly = true)
32+
private File workingdir;
33+
3134
public void execute() throws MojoExecutionException {
3235
if (scope == null) {
3336
scope = "";
3437
}
3538
if (tagPrefix == null) {
3639
tagPrefix = "v";
3740
}
41+
3842
MavenService mavenService = new MavenService(project);
3943
GitService gitService = new GitService(basedir);
40-
ChangelogService changelogService = new ChangelogService(basedir);
44+
ChangelogService changelogService = new ChangelogService(workingdir);
4145

4246
var lastTag = gitService.getLastTag(tagPrefix).orElse(null);
4347
var commits = gitService.getCommitsFrom(lastTag, scope);
@@ -50,8 +54,12 @@ public void execute() throws MojoExecutionException {
5054

5155
var nextTag = opt.get();
5256

53-
mavenService.upgradeVersion(nextTag, tagPrefix);
54-
gitService.add("pom.xml");
57+
mavenService.upgradeVersion(
58+
nextTag,
59+
new File(workingdir.getAbsolutePath() + "/pom.xml"),
60+
tagPrefix
61+
);
62+
gitService.add(".");
5563
gitService.commit(String.format("chore: bump to version %s [ci skip]", nextTag));
5664
gitService.tag(nextTag);
5765
changelogService.generateFromBeginning(
@@ -61,7 +69,7 @@ public void execute() throws MojoExecutionException {
6169
false,
6270
tagPrefix
6371
);
64-
gitService.add("changelog.md");
72+
gitService.add(".");
6573
gitService.amend();
6674
gitService.tag(nextTag);
6775
}

src/main/java/io/github/zorin95670/semver/service/ChangelogService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public ChangelogService(File projectDir) {
2222
this.projectDir = projectDir;
2323
}
2424

25-
public void generateFromBeginning(String url, List<RevCommit> commits, Map<String, List<String>> taggedCommits, boolean dryRun, String tagPrefix) {
25+
public void generateFromBeginning(String url, List<RevCommit> commits,
26+
Map<String, List<String>> taggedCommits, boolean dryRun, String tagPrefix) {
2627
List<ChangelogReleaseSection> releaseSections = new ArrayList<>();
2728

2829
commits.forEach(commit -> {

src/main/java/io/github/zorin95670/semver/service/MavenService.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ public MavenService(MavenProject project) {
1616
this.project = project;
1717
}
1818

19-
public void upgradeVersion(String version, String tagPrefix) {
20-
File pomFile = project.getFile(); // usually pom.xml
21-
19+
public void upgradeVersion(String version, File pomFile, String tagPrefix) {
2220
try (FileReader reader = new FileReader(pomFile)) {
2321
MavenXpp3Reader xpp3Reader = new MavenXpp3Reader();
2422
Model model = xpp3Reader.read(reader);

0 commit comments

Comments
 (0)