Skip to content

Commit 7501963

Browse files
committed
feat: moving semantic versioning to its own mojo
1 parent 85e5a1a commit 7501963

13 files changed

+242
-88
lines changed

README.md

+36-16
Original file line numberDiff line numberDiff line change
@@ -185,20 +185,40 @@ Have a look at the [pom.xml](/git-changelog-maven-plugin-example/pom.xml) where
185185

186186
The version in `pom.xml` can be automatically updated based on [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/).
187187

188+
From command line:
189+
190+
```sh
191+
mvn se.bjurr.gitchangelog:git-changelog-maven-plugin:VERSION_HERE:semantic-version
192+
```
193+
194+
Or in `pom.xml`:
195+
188196
```xml
189-
<configuration>
190-
<!-- Skip changelog generation //-->
191-
<skip>true</skip>
192-
193-
<!-- Update the <version> tag //-->
194-
<updatePomWithNextSemanticVersion>true</updatePomWithNextSemanticVersion>
195-
196-
<!-- Suffix version with -SNAPSHOT //-->
197-
<updatePomWithNextSemanticVersionSuffixSnapshot>true</updatePomWithNextSemanticVersionSuffixSnapshot>
198-
199-
<!-- Regexp patterns used to identify next version can optionally be adjusted //-->
200-
<semanticMajorVersionPattern>^[Bb]reaking</semanticMajorVersionPattern>
201-
<semanticMinorVersionPattern>[Ff]eature</semanticMinorVersionPattern>
202-
<semanticPatchVersionPattern>[Ff]ix</semanticPatchVersionPattern>
203-
</configuration>
204-
```
197+
<build>
198+
<plugins>
199+
<plugin>
200+
<groupId>se.bjurr.gitchangelog</groupId>
201+
<artifactId>git-changelog-maven-plugin</artifactId>
202+
<version>${changelog}</version>
203+
<executions>
204+
<execution>
205+
<id>GenerateGitChangelog</id>
206+
<phase>generate-sources</phase>
207+
<goals>
208+
<goal>semantic-version</goal>
209+
</goals>
210+
<configuration>
211+
<!-- Suffix version with -SNAPSHOT //-->
212+
<updatePomWithNextSemanticVersionSuffixSnapshot>true</updatePomWithNextSemanticVersionSuffixSnapshot>
213+
214+
<!-- Regexp patterns used to identify next version can optionally be adjusted //-->
215+
<semanticMajorVersionPattern>^[Bb]reaking</semanticMajorVersionPattern>
216+
<semanticMinorVersionPattern>[Ff]eature</semanticMinorVersionPattern>
217+
<semanticPatchVersionPattern>[Ff]ix</semanticPatchVersionPattern>
218+
</configuration>
219+
</execution>
220+
</executions>
221+
</plugin>
222+
</plugins>
223+
</build>
224+
```

git-changelog-maven-plugin-example/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
Changelog of git-changelog-maven-plugin.
44

5+
## 1.94.0 (2022-09-25)
6+
7+
### Features
8+
9+
- optional custom patterns for conventional commits ([5d522](https://github.com/tomasbjerre/git-changelog-maven-plugin/commit/5d5222ae4ce034f) Tomas Bjerre)
10+
511
## 1.93.0 (2022-09-25)
612

713
### Features

git-changelog-maven-plugin-example/CHANGELOG_custom.md

+14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ Changelog of Git Changelog Maven plugin.
1010

1111

1212

13+
## git-changelog-maven-plugin-1.94.0
14+
### No issue /
15+
[maven-release-plugin] prepare release git-changelog-maven-plugin-1.94.0
16+
17+
chore: setting version 1.94.0-SNAPSHOT
18+
19+
feat: optional custom patterns for conventional commits
20+
21+
chore: updating changelog
22+
23+
[maven-release-plugin] prepare for next development iteration
24+
25+
26+
1327
## git-changelog-maven-plugin-1.93.0
1428
### No issue /
1529
[maven-release-plugin] prepare release git-changelog-maven-plugin-1.93.0

git-changelog-maven-plugin-example/CHANGELOG_ignoreCommitsOlderThan.md

+14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ Changelog of Git Changelog Maven plugin.
44

55
## Unreleased
66
### No issue
7+
chore: updating changelog *2022-09-25 13:57:51*
8+
9+
[maven-release-plugin] prepare for next development iteration *2022-09-25 13:57:28*
10+
11+
12+
13+
## git-changelog-maven-plugin-1.94.0
14+
### No issue
15+
[maven-release-plugin] prepare release git-changelog-maven-plugin-1.94.0 *2022-09-25 13:57:23*
16+
17+
chore: setting version 1.94.0-SNAPSHOT *2022-09-25 13:57:13*
18+
19+
feat: optional custom patterns for conventional commits *2022-09-25 13:56:52*
20+
721
chore: updating changelog *2022-09-25 13:26:11*
822

923
[maven-release-plugin] prepare for next development iteration *2022-09-25 13:25:40*

git-changelog-maven-plugin-example/CHANGELOG_inline.md

+24
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,30 @@ Changelog of Git Changelog Maven plugin.
55
## Unreleased
66
### No issue
77

8+
[85e5a1a9dc15958](https://github.com/tomasbjerre/git-changelog-maven-plugin/commit/85e5a1a9dc15958) Tomas Bjerre *2022-09-25 13:57:51*
9+
10+
chore: updating changelog
11+
12+
[234a390d1f40605](https://github.com/tomasbjerre/git-changelog-maven-plugin/commit/234a390d1f40605) Tomas Bjerre *2022-09-25 13:57:28*
13+
14+
[maven-release-plugin] prepare for next development iteration
15+
16+
17+
## git-changelog-maven-plugin-1.94.0
18+
### No issue
19+
20+
[4caa819ae18f3c6](https://github.com/tomasbjerre/git-changelog-maven-plugin/commit/4caa819ae18f3c6) Tomas Bjerre *2022-09-25 13:57:23*
21+
22+
[maven-release-plugin] prepare release git-changelog-maven-plugin-1.94.0
23+
24+
[c06ae415aa3c5f0](https://github.com/tomasbjerre/git-changelog-maven-plugin/commit/c06ae415aa3c5f0) Tomas Bjerre *2022-09-25 13:57:13*
25+
26+
chore: setting version 1.94.0-SNAPSHOT
27+
28+
[5d5222ae4ce034f](https://github.com/tomasbjerre/git-changelog-maven-plugin/commit/5d5222ae4ce034f) Tomas Bjerre *2022-09-25 13:56:52*
29+
30+
feat: optional custom patterns for conventional commits
31+
832
[443355dd3420145](https://github.com/tomasbjerre/git-changelog-maven-plugin/commit/443355dd3420145) Tomas Bjerre *2022-09-25 13:26:11*
933

1034
chore: updating changelog

git-changelog-maven-plugin-example/CHANGELOG_jira.md

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
Changelog of git-changelog-maven-plugin.
44

5+
## 1.94.0 (2022-09-25)
6+
7+
### Features
8+
9+
- optional custom patterns for conventional commits ([5d522](https://github.com/tomasbjerre/git-changelog-maven-plugin/commit/5d5222ae4ce034f) Tomas Bjerre)
10+
11+
### Other changes
12+
13+
**[maven-release-plugin] prepare release git-changelog-maven-plugin-1.94.0**
14+
15+
16+
[4caa8](https://github.com/tomasbjerre/git-changelog-maven-plugin/commit/4caa819ae18f3c6) Tomas Bjerre *2022-09-25 13:57:23*
17+
18+
**[maven-release-plugin] prepare for next development iteration**
19+
20+
21+
[0f8f1](https://github.com/tomasbjerre/git-changelog-maven-plugin/commit/0f8f152636abed4) Tomas Bjerre *2022-09-25 13:25:40*
22+
23+
524
## 1.93.0 (2022-09-25)
625

726
### Features

git-changelog-maven-plugin-example/CHANGELOG_minimal.md

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
Changelog of git-changelog-maven-plugin.
44

5+
## git-changelog-maven-plugin-1.94.0 (2022-09-25)
6+
7+
### Features
8+
9+
- optional custom patterns for conventional commits ([5d522](https://github.com/tomasbjerre/git-changelog-maven-plugin/commit/5d5222ae4ce034f) Tomas Bjerre)
10+
11+
### Other changes
12+
13+
**[maven-release-plugin] prepare release git-changelog-maven-plugin-1.94.0**
14+
15+
16+
[4caa8](https://github.com/tomasbjerre/git-changelog-maven-plugin/commit/4caa819ae18f3c6) Tomas Bjerre *2022-09-25 13:57:23*
17+
18+
**[maven-release-plugin] prepare for next development iteration**
19+
20+
21+
[0f8f1](https://github.com/tomasbjerre/git-changelog-maven-plugin/commit/0f8f152636abed4) Tomas Bjerre *2022-09-25 13:25:40*
22+
23+
524
## git-changelog-maven-plugin-1.93.0 (2022-09-25)
625

726
### Features

git-changelog-maven-plugin-example/CHANGELOG_mixed.md

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ Changelog of Git Changelog Maven plugin.
44

55
## These commits are not included in any tag
66
### These commits have not issue in their commit comment
7+
chore: updating changelog *13:57:51*
8+
9+
10+
11+
## 1.94.0
12+
### These commits have not issue in their commit comment
13+
chore: setting version 1.94.0-SNAPSHOT *13:57:13*
14+
15+
feat: optional custom patterns for conventional commits *13:56:52*
16+
717
chore: updating changelog *13:26:11*
818

919

git-changelog-maven-plugin-example/CHANGELOG_settings.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ Changelog of git-changelog-maven-plugin.
44

55
## Next release ()
66

7+
## 1.94.0 (2022-09-25)
8+
9+
### Features
10+
11+
- optional custom patterns for conventional commits ([5d522](https://github.com/tomasbjerre/git-changelog-maven-plugin/commit/5d5222ae4ce034f) Tomas Bjerre)
12+
713
## 1.93.0 (2022-09-25)
814

915
### Features

git-changelog-maven-plugin-example/CHANGELOG_templatefile.md

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
Changelog of git-changelog-maven-plugin.
44

5+
## 1.94.0 (2022-09-25)
6+
7+
### Features
8+
9+
- optional custom patterns for conventional commits ([5d522](https://github.com/tomasbjerre/git-changelog-maven-plugin/commit/5d5222ae4ce034f) Tomas Bjerre)
10+
11+
### Other changes
12+
13+
**[maven-release-plugin] prepare release git-changelog-maven-plugin-1.94.0**
14+
15+
16+
[4caa8](https://github.com/tomasbjerre/git-changelog-maven-plugin/commit/4caa819ae18f3c6) Tomas Bjerre *2022-09-25 13:57:23*
17+
18+
**[maven-release-plugin] prepare for next development iteration**
19+
20+
21+
[0f8f1](https://github.com/tomasbjerre/git-changelog-maven-plugin/commit/0f8f152636abed4) Tomas Bjerre *2022-09-25 13:25:40*
22+
23+
524
## 1.93.0 (2022-09-25)
625

726
### Features

git-changelog-maven-plugin-example/pom.xml

+2-13
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
<groupId>se.bjurr.gitchangelog</groupId>
44
<artifactId>git-changelog-maven-plugin-example</artifactId>
55
<name>git-changelog-maven-plugin-example</name>
6-
<version>1.93.1-SNAPSHOT</version>
6+
<version>1.94.1-SNAPSHOT</version>
77
<properties>
88
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
99
<maven.compiler.target>1.8</maven.compiler.target>
1010
<maven.compiler.source>1.8</maven.compiler.source>
11-
<changelog.version>1.93.1-SNAPSHOT</changelog.version>
11+
<changelog.version>1.94.1-SNAPSHOT</changelog.version>
1212
</properties>
1313
<build>
1414
<plugins>
@@ -450,17 +450,6 @@ Handlebars.registerHelper('firstLetters', function(from, options) {
450450
</templateContent>
451451
</configuration>
452452
</execution>
453-
<execution>
454-
<id>UpdateVersionInPom</id>
455-
<phase>generate-sources</phase>
456-
<goals>
457-
<goal>git-changelog</goal>
458-
</goals>
459-
<configuration>
460-
<skip>true</skip>
461-
<updatePomWithNextSemanticVersion>true</updatePomWithNextSemanticVersion>
462-
</configuration>
463-
</execution>
464453
</executions>
465454
</plugin>
466455
</plugins>

src/main/java/se/bjurr/gitchangelog/plugin/GitChangelogMojo.java

-59
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,16 @@
1111
import java.util.HashMap;
1212
import java.util.List;
1313
import java.util.Map;
14-
import org.apache.maven.model.Model;
1514
import org.apache.maven.plugin.AbstractMojo;
1615
import org.apache.maven.plugin.MojoExecutionException;
17-
import org.apache.maven.plugins.annotations.Component;
1816
import org.apache.maven.plugins.annotations.Mojo;
1917
import org.apache.maven.plugins.annotations.Parameter;
20-
import org.apache.maven.project.MavenProject;
2118
import se.bjurr.gitchangelog.api.GitChangelogApi;
22-
import se.bjurr.gitchangelog.internal.semantic.SemanticVersion;
2319

2420
@Mojo(name = "git-changelog", defaultPhase = PROCESS_SOURCES, threadSafe = true)
2521
public class GitChangelogMojo extends AbstractMojo {
2622
private static final String DEFAULT_FILE = "CHANGELOG.md";
2723

28-
@Component private MavenProject project;
29-
3024
@Parameter(property = "toRef", required = false)
3125
private String toRef;
3226

@@ -182,61 +176,8 @@ public class GitChangelogMojo extends AbstractMojo {
182176
@Parameter(property = "prependToFile", required = false)
183177
public Boolean prependToFile;
184178

185-
@Parameter(
186-
property = "updatePomWithNextSemanticVersion",
187-
required = false,
188-
defaultValue = "false")
189-
private boolean updatePomWithNextSemanticVersion;
190-
191-
@Parameter(
192-
property = "updatePomWithNextSemanticVersionSuffixSnapshot",
193-
required = false,
194-
defaultValue = "true")
195-
private boolean updatePomWithNextSemanticVersionSuffixSnapshot;
196-
197-
@Parameter(property = "semanticMajorVersionPattern", required = false)
198-
private String semanticMajorVersionPattern;
199-
200-
@Parameter(property = "semanticMinorVersionPattern", required = false)
201-
private String semanticMinorVersionPattern;
202-
203-
@Parameter(property = "semanticPatchVersionPattern", required = false)
204-
private String semanticPatchVersionPattern;
205-
206179
@Override
207180
public void execute() throws MojoExecutionException {
208-
if (this.updatePomWithNextSemanticVersion) {
209-
try {
210-
final GitChangelogApi gitChangelogApiBuilder = gitChangelogApiBuilder();
211-
if (this.isSupplied(this.semanticMajorVersionPattern)) {
212-
gitChangelogApiBuilder.withSemanticMajorVersionPattern(this.semanticMajorVersionPattern);
213-
}
214-
if (this.isSupplied(this.semanticMinorVersionPattern)) {
215-
gitChangelogApiBuilder.withSemanticMinorVersionPattern(this.semanticMinorVersionPattern);
216-
}
217-
if (this.isSupplied(this.semanticPatchVersionPattern)) {
218-
gitChangelogApiBuilder.withSemanticPatchVersionPattern(this.semanticPatchVersionPattern);
219-
}
220-
final SemanticVersion nextSemanticVersion = gitChangelogApiBuilder.getNextSemanticVersion();
221-
final String nextVersion =
222-
this.updatePomWithNextSemanticVersionSuffixSnapshot
223-
? nextSemanticVersion.getVersion() + "-SNAPSHOT"
224-
: nextSemanticVersion.getVersion();
225-
226-
final Model model = this.project.getModel();
227-
final String versionOrig = model.getVersion();
228-
final File pomFile = this.project.getFile();
229-
this.getLog()
230-
.info("Setting version to " + nextVersion + " was (" + versionOrig + ") in " + pomFile);
231-
// Change version during build
232-
model.setVersion(nextVersion);
233-
234-
// Change version in file
235-
new XmlModifier(pomFile).setVersion(nextVersion);
236-
} catch (final Exception e) {
237-
throw new MojoExecutionException(e.getMessage(), e);
238-
}
239-
}
240181
if (this.skip != null && this.skip == true) {
241182
this.getLog().info("Skipping changelog generation");
242183
return;

0 commit comments

Comments
 (0)