Skip to content

Commit ce1c127

Browse files
authored
Add changelog support (#103)
* Add changelog support * Add documentation for changelogs
1 parent e793b0c commit ce1c127

File tree

6 files changed

+191
-20
lines changed

6 files changed

+191
-20
lines changed

src/it/test20-changelog/pom.xml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>de.dentrassi.maven.rpm.test</groupId>
7+
<artifactId>test20-changelog</artifactId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>Test Package #20</name>
12+
<description>Test changelog generation</description>
13+
14+
<url>http://dentrassi.de</url>
15+
16+
<organization>
17+
<name>Jens Reimann</name>
18+
<url>http://dentrassi.de</url>
19+
</organization>
20+
21+
<licenses>
22+
<license>
23+
<name>Eclipse Public License - v 1.0</name>
24+
<distribution>repo</distribution>
25+
<url>https://www.eclipse.org/legal/epl-v10.html</url>
26+
</license>
27+
</licenses>
28+
29+
<properties>
30+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
31+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
32+
<skipSigning>true</skipSigning>
33+
</properties>
34+
35+
<build>
36+
37+
<plugins>
38+
<plugin>
39+
<groupId>de.dentrassi.maven</groupId>
40+
<artifactId>rpm</artifactId>
41+
<version>@project.version@</version>
42+
<executions>
43+
<execution>
44+
<goals>
45+
<goal>rpm</goal>
46+
</goals>
47+
<configuration>
48+
<attach>false</attach>
49+
<group>Application/Misc</group>
50+
51+
<forceRelease>true</forceRelease>
52+
<snapshotVersion>1.2.3</snapshotVersion>
53+
<version>4.5.6</version>
54+
55+
<signature>
56+
<keyId>${keyId}</keyId>
57+
<keyringFile>${user.home}/.gnupg/secring.gpg</keyringFile>
58+
<passphrase>${passphrase}</passphrase>
59+
<hashAlgorithm>SHA1</hashAlgorithm>
60+
<skip>${skipSigning}</skip>
61+
</signature>
62+
63+
<changelogs>
64+
<changelog>
65+
<date>2024-04-15T10:14:00+01:00</date>
66+
<author>John Doe</author>
67+
<text>A new release 1</text>
68+
</changelog>
69+
<changelog>
70+
<timestamp>1712232000</timestamp>
71+
<author>Jane Doe</author>
72+
<text>Older Release</text>
73+
</changelog>
74+
</changelogs>
75+
76+
</configuration>
77+
</execution>
78+
</executions>
79+
</plugin>
80+
</plugins>
81+
</build>
82+
83+
<profiles>
84+
<profile>
85+
<id>sign</id>
86+
<activation>
87+
<activeByDefault>false</activeByDefault>
88+
</activation>
89+
<properties>
90+
<skipSigning>false</skipSigning>
91+
</properties>
92+
</profile>
93+
</profiles>
94+
95+
</project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
def clog () {
3+
Process proc = ('rpm --changelog -qp ' + basedir + "/target/test20-changelog-4.5.6-1.noarch.rpm").execute();
4+
return proc.in.getText().trim();
5+
}
6+
7+
String text = clog()
8+
return text.contains("A new release 1") && text.contains("Thu Apr 04 2024 Jane Doe")

src/main/java/de/dentrassi/rpm/builder/RpmMojo.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
import java.nio.file.Path;
3232
import java.nio.file.Paths;
3333
import java.time.Instant;
34+
import java.time.OffsetDateTime;
3435
import java.time.ZoneOffset;
3536
import java.time.format.DateTimeFormatter;
37+
import java.util.ArrayList;
3638
import java.util.Arrays;
3739
import java.util.LinkedList;
3840
import java.util.List;
@@ -67,6 +69,8 @@
6769
import org.eclipse.packager.rpm.build.RpmBuilder.PackageInformation;
6870
import org.eclipse.packager.rpm.build.RpmBuilder.Version;
6971
import org.eclipse.packager.rpm.deps.RpmDependencyFlags;
72+
import org.eclipse.packager.rpm.header.Header;
73+
import org.eclipse.packager.rpm.info.RpmInformation;
7074
import org.eclipse.packager.rpm.signature.RsaHeaderSignatureProcessor;
7175
import org.eclipse.packager.rpm.signature.RsaSignatureProcessor;
7276
import org.eclipse.packager.rpm.signature.SignatureProcessor;
@@ -438,6 +442,12 @@ public void setGenerateDefaultSourcePackage(final boolean generateDefaultSourceP
438442
@Parameter
439443
String defaultRuleset;
440444

445+
/**
446+
* A list of change-logs for this RPM
447+
*/
448+
@Parameter
449+
List<Changelog> changelogs = new LinkedList<>();
450+
441451
private Logger logger;
442452

443453
private RulesetEvaluator eval;
@@ -1138,6 +1148,25 @@ private void customizeHeader(final RpmBuilder builder) {
11381148
this.logger.debug("Overriding build time: %s", outputTimestampInstant);
11391149
rpmTagHeader.putInt(RpmTag.BUILDTIME, (int) (outputTimestampInstant.toEpochMilli() / 1000));
11401150
}
1151+
1152+
if (changelogs != null && !changelogs.isEmpty()) {
1153+
List<String> authors = changelogs.stream().map(Changelog::getAuthor).collect(Collectors.toList());
1154+
List<String> text = changelogs.stream().map(Changelog::getText).collect(Collectors.toList());
1155+
List<Integer> dates = new ArrayList<>();
1156+
1157+
for (Changelog changelog : changelogs) {
1158+
if (changelog.getDate() != null && !changelog.getDate().isEmpty()) {
1159+
dates.add((int)OffsetDateTime.parse(changelog.getDate()).toEpochSecond());
1160+
} else {
1161+
dates.add((int)changelog.getTimestamp());
1162+
}
1163+
}
1164+
this.logger.debug("Building changelog with authors %s and dates %s and text %s", authors, dates, text);
1165+
1166+
Header.putIntFields(rpmTagHeader, dates, RpmTag.CHANGELOG_TIMESTAMP, Integer::intValue);
1167+
rpmTagHeader.putStringArray(RpmTag.CHANGELOG_AUTHOR, authors.toArray(new String[0]));
1168+
rpmTagHeader.putStringArray(RpmTag.CHANGELOG_TEXT, text.toArray(new String[0]));
1169+
}
11411170
});
11421171
}
11431172

@@ -1423,4 +1452,13 @@ private static void ifSet(final Consumer<String> setter, final String value, fin
14231452
}
14241453
}
14251454

1455+
1456+
public static class Changelog extends RpmInformation.Changelog {
1457+
1458+
private String date;
1459+
1460+
public String getDate() {
1461+
return date;
1462+
}
1463+
}
14261464
}

src/site/apt/example-primary.apt.vm

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
Example configuration – Primary artifact
1010

11-
This is an example configuration showing how to use the plugin to create an RPM as the primary project artifact
12-
11+
This is an example configuration showing how to use the plugin to create an RPM as the primary project artifact
12+
1313
+----+
1414
<?xml version="1.0" encoding="UTF-8"?>
1515
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -22,7 +22,7 @@ Example configuration – Primary artifact
2222
<packaging>rpm</packaging> <!-- Primary Artifact Configuration -->
2323

2424
<name>Test Package #2 -- Primary</name> <!-- used for "summary" field -->
25-
25+
2626
<!-- used for "description" field -->
2727
<description>
2828
This is some long long text about foo bar and all the rest.
@@ -57,13 +57,12 @@ Example configuration – Primary artifact
5757
<extensions>true</extensions> <!-- Primary Artifact Configuration -->
5858
<executions>
5959
<execution>
60-
60+
6161
<goals>
6262
<goal>rpm</goal>
6363
</goals>
64-
64+
6565
<configuration>
66-
<attach>false</attach> <!-- don't attach RPM as a secondary artifact -->
6766
<group>Application/Misc</group> <!-- set RPM group -->
6867

6968
<!-- rule sets -->
@@ -109,22 +108,22 @@ Example configuration – Primary artifact
109108
</rulesets>
110109

111110
<entries>
112-
111+
113112
<!-- add explicit directory -->
114-
113+
115114
<entry>
116115
<name>/etc/foo</name>
117116
<directory>true</directory>
118117
<user>root</user>
119118
<group>root</group>
120119
<mode>0755</mode>
121-
120+
122121
<!-- will use the default ruleset -->
123-
122+
124123
</entry>
125-
124+
126125
<!-- add single file -->
127-
126+
128127
<entry>
129128
<name>/etc/foo/bar.txt</name>
130129
<file>src/main/resources/bar.txt</file>
@@ -133,19 +132,19 @@ Example configuration – Primary artifact
133132
<mode>0600</mode>
134133
<ruleset>my-default</ruleset>
135134
</entry>
136-
135+
137136
<!-- collect all files from : target/classes -->
138-
137+
139138
<entry>
140139
<name>/usr/lib/foobar</name>
141140
<collect>
142141
<from>target/classes</from>
143142
</collect>
144143
<ruleset>my-default</ruleset>
145144
</entry>
146-
145+
147146
<!-- collect all files from : src/main/resources/etc -->
148-
147+
149148
<entry>
150149
<name>/etc</name>
151150
<collect>
@@ -154,9 +153,9 @@ Example configuration – Primary artifact
154153
</collect>
155154
<ruleset>my-default</ruleset>
156155
</entry>
157-
156+
158157
<!-- collect all files from : src/main/resources/lib -->
159-
158+
160159
<entry>
161160
<name>/usr/lib</name>
162161
<collect>
@@ -165,9 +164,17 @@ Example configuration – Primary artifact
165164
</collect>
166165
<ruleset>my-default</ruleset>
167166
</entry>
168-
167+
169168
</entries>
170-
169+
170+
<changelogs>
171+
<changelog>
172+
<date>2024-04-15T10:14:00+01:00</date>
173+
<author>John Doe</author>
174+
<text>My new release</text>
175+
</changelog>
176+
</changelogs>
177+
171178
</configuration>
172179
</execution>
173180
</executions>

src/site/markdown/changelog.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Changelogs
2+
3+
RPMs allow the change log of a package to be included in the distribution file. This may be accessed by `rpm -q --changelog <package>`.
4+
5+
To add changelogs via the plugin the following may be used:
6+
7+
~~~xml
8+
<changelogs>
9+
<changelog>
10+
<date>2024-04-15T10:14:00+01:00</date>
11+
<author>John Doe</author>
12+
<text>A new release 1</text>
13+
</changelog>
14+
<changelog>
15+
<timestamp>1712232000</timestamp>
16+
<author>Jane Doe</author>
17+
<text>Older Release</text>
18+
</changelog>
19+
</changelogs>
20+
~~~
21+
22+
Note that the timestamp entry may be either in [ISO_OFFSET_DATE_TIME](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/time/format/DateTimeFormatter.html#ISO_OFFSET_DATE_TIME) or in milliseconds as an epoch unix timestamp.

src/site/site.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<item name="Naming" href="naming.html" />
2323
<item name="Lead information" href="lead.html" />
2424
<item name="Verification flags" href="verify.html" />
25+
<item name="Changelogs" href="changelog.html" />
2526
</menu>
2627

2728
<menu ref="reports" />

0 commit comments

Comments
 (0)