Skip to content

Commit 0809a0a

Browse files
authored
Merge pull request wildfly#19495 from jamezp/maven-central-release
[WFLY-21301] Add a profile for releasing to Maven Central
2 parents a083b05 + e014640 commit 0809a0a

File tree

19 files changed

+373
-2
lines changed

19 files changed

+373
-2
lines changed

ChecksumUpdater.java

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/// usr/bin/env jbang "$0" "$@" ; exit $?
2+
//JAVA 17+
3+
//DEPS info.picocli:picocli:4.7.7
4+
5+
import java.io.IOException;
6+
import java.io.InputStream;
7+
import java.net.URI;
8+
import java.nio.charset.StandardCharsets;
9+
import java.nio.file.FileSystem;
10+
import java.nio.file.FileSystemNotFoundException;
11+
import java.nio.file.FileSystems;
12+
import java.nio.file.FileVisitResult;
13+
import java.nio.file.Files;
14+
import java.nio.file.Path;
15+
import java.nio.file.SimpleFileVisitor;
16+
import java.nio.file.StandardOpenOption;
17+
import java.nio.file.attribute.BasicFileAttributes;
18+
import java.security.DigestInputStream;
19+
import java.security.MessageDigest;
20+
import java.security.NoSuchAlgorithmException;
21+
import java.util.Locale;
22+
import java.util.Map;
23+
import java.util.concurrent.Callable;
24+
25+
import picocli.AutoComplete;
26+
import picocli.CommandLine;
27+
import picocli.CommandLine.Command;
28+
import picocli.CommandLine.Option;
29+
import picocli.CommandLine.Parameters;
30+
31+
/**
32+
* This is used to hack around the missing md5 and sha1 checksum files required by Maven Central. Specifically for the
33+
* POM's build by the wildfly-bom-builder-maven-plugin.
34+
*
35+
* @author <a href="mailto:jperkins@ibm.com">James R. Perkins</a>
36+
*/
37+
@Command(name = "checksum-updater", mixinStandardHelpOptions = true, version = "checksum-updater 0.1",
38+
description = "Creates missing checksums for POM files.",
39+
showDefaultValues = true, subcommands = AutoComplete.GenerateCompletion.class)
40+
public class ChecksumUpdater implements Callable<Integer> {
41+
42+
private static final char[] table = {
43+
'0', '1', '2', '3', '4', '5', '6', '7',
44+
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
45+
};
46+
47+
@Option(names = {"-a", "--algorithm"}, description = "The algorithm(s) for the generated checksum", split = ",", defaultValue = "md5,sha1")
48+
private String[] algorithms;
49+
50+
@Parameters(arity = "1..*", description = "The directories which contain the file to create the checksums for if they are missing")
51+
private Path[] dirs;
52+
53+
@CommandLine.Spec
54+
private CommandLine.Model.CommandSpec spec;
55+
56+
public static void main(String... args) {
57+
final int exitCode = new CommandLine(new ChecksumUpdater()).execute(args);
58+
System.exit(exitCode);
59+
}
60+
61+
@Override
62+
public Integer call() throws Exception {
63+
for (Path dir : dirs) {
64+
if (!Files.isDirectory(dir)) {
65+
spec.commandLine().getErr().printf("%s must be a directory%n", dir);
66+
return -1;
67+
}
68+
// Walk the ZIP tree looking for missing checksum files and add them
69+
Files.walkFileTree(dir, new SimpleFileVisitor<>() {
70+
@Override
71+
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
72+
if (file.toString().endsWith(".pom")) {
73+
for (String algorithm : algorithms) {
74+
final Path checksumFile = Path.of(file.toAbsolutePath() + "." + algorithm.toLowerCase(Locale.ROOT));
75+
if (Files.notExists(checksumFile)) {
76+
try {
77+
final var md = MessageDigest.getInstance(algorithm.toUpperCase(Locale.ROOT));
78+
try (DigestInputStream dis = new DigestInputStream(Files.newInputStream(file), md)) {
79+
final byte[] buffer = new byte[1024];
80+
while (dis.read(buffer) > 0) {
81+
// Just gathering
82+
}
83+
final byte[] checksum = md.digest();
84+
final String checksumString = bytesToHexString(checksum);
85+
if (Files.exists(checksumFile)) {
86+
Files.delete(checksumFile);
87+
}
88+
Files.writeString(checksumFile, checksumString, StandardCharsets.UTF_8, StandardOpenOption.CREATE_NEW);
89+
}
90+
} catch (NoSuchAlgorithmException e) {
91+
spec.commandLine()
92+
.getErr()
93+
.printf("Algorithm %s not found: %s%n", algorithm, e.getMessage());
94+
}
95+
}
96+
}
97+
}
98+
return FileVisitResult.CONTINUE;
99+
}
100+
});
101+
}
102+
return 0;
103+
}
104+
105+
private static String bytesToHexString(final byte[] bytes) {
106+
final StringBuilder builder = new StringBuilder(bytes.length * 2);
107+
for (byte b : bytes) {
108+
builder.append(table[b >> 4 & 0x0f]).append(table[b & 0x0f]);
109+
}
110+
return builder.toString();
111+
}
112+
}

boms/user/pom.xml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,74 @@
159159
</plugins>
160160
</build>
161161
</profile>
162+
163+
<!--
164+
Disable the parent pom's use of maven-gpg-plugin for these modules
165+
as it can't handle the fact we produce artifacts under multiple
166+
grouopIds; we need to use wildfly-maven-gpg-plugin to deal with signing.
167+
-->
168+
<profile>
169+
<id>maven-central-release</id>
170+
<build>
171+
<plugins>
172+
<plugin>
173+
<groupId>org.apache.maven.plugins</groupId>
174+
<artifactId>maven-gpg-plugin</artifactId>
175+
<executions>
176+
<execution>
177+
<id>gpg-sign</id>
178+
<phase>none</phase>
179+
</execution>
180+
</executions>
181+
</plugin>
182+
<plugin>
183+
<groupId>org.wildfly</groupId>
184+
<artifactId>wildfly-maven-gpg-plugin</artifactId>
185+
<executions>
186+
<execution>
187+
<id>gpg-sign</id>
188+
<goals>
189+
<goal>sign</goal>
190+
</goals>
191+
</execution>
192+
</executions>
193+
</plugin>
194+
<!--
195+
The central-publishing-maven-plugin can't deal with this project's generated artifacts
196+
because it writes maven-metadata-central-staging.xml files for those components that
197+
Maven Central rejects.
198+
So we hack this by redeclaring the central-publishing-maven-plugin
199+
and then *after it* add a 'deploy' phase maven-clean-plugin execution to remove those files.-->
200+
<plugin>
201+
<groupId>org.sonatype.central</groupId>
202+
<artifactId>central-publishing-maven-plugin</artifactId>
203+
</plugin>
204+
<plugin>
205+
<artifactId>maven-clean-plugin</artifactId>
206+
<executions>
207+
<execution>
208+
<id>post-stage-clean</id>
209+
<phase>deploy</phase>
210+
<goals>
211+
<goal>clean</goal>
212+
</goals>
213+
<configuration>
214+
<excludeDefaultDirectories>true</excludeDefaultDirectories>
215+
<filesets>
216+
<fileset>
217+
<directory>${maven.multiModuleProjectDirectory}/target/central-staging</directory>
218+
<includes>
219+
<include>**/maven-metadata-*.xml</include>
220+
</includes>
221+
</fileset>
222+
</filesets>
223+
</configuration>
224+
</execution>
225+
</executions>
226+
</plugin>
227+
</plugins>
228+
</build>
229+
</profile>
162230
</profiles>
163231

164232
</project>

docs/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<!-- Don't try to deploy the module -->
3333
<maven.deploy.skip>true</maven.deploy.skip>
3434
<skipNexusStagingDeployMojo>true</skipNexusStagingDeployMojo>
35+
<skipPublishing>${maven.deploy.skip}</skipPublishing>
3536
</properties>
3637

3738
<build>

ee-feature-pack/layer-metadata-tests/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<!-- Don't try to deploy the module -->
3131
<maven.deploy.skip>true</maven.deploy.skip>
3232
<skipNexusStagingDeployMojo>true</skipNexusStagingDeployMojo>
33+
<skipPublishing>${maven.deploy.skip}</skipPublishing>
3334
</properties>
3435

3536
<dependencies>

galleon-pack/layer-metadata-tests/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<!-- Don't try to deploy the module -->
3131
<maven.deploy.skip>true</maven.deploy.skip>
3232
<skipNexusStagingDeployMojo>true</skipNexusStagingDeployMojo>
33+
<skipPublishing>${maven.deploy.skip}</skipPublishing>
3334
</properties>
3435

3536
<dependencies>

pom.xml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@
9292
<nexus.repository.url>https://repository.jboss.org/nexus/</nexus.repository.url> <!-- duplicated from jboss-parent, but Maven 4 wants to know it before accessing jboss-parent -->
9393
<nexus.repository.staging.url>${nexus.repository.url}repository/${nexus.repository.staging}</nexus.repository.staging.url>
9494

95+
<!-- Maven Central release properties -->
96+
<repo.sonatype.url>https://central.sonatype.com</repo.sonatype.url>
97+
<sonatype.server.id>central</sonatype.server.id>
98+
<autoPublish>false</autoPublish>
99+
<waitUntil>validated</waitUntil>
100+
<skipPublishing>false</skipPublishing>
101+
95102
<!-- Galleon -->
96103
<galleon.fork.embedded>true</galleon.fork.embedded>
97104
<galleon.log.time>true</galleon.log.time>
@@ -288,6 +295,7 @@
288295
-->
289296
<version.ant.junit>1.10.15</version.ant.junit>
290297
<version.asciidoctor.plugin>2.2.6</version.asciidoctor.plugin>
298+
<version.central.publishing.maven.plugin>0.9.0</version.central.publishing.maven.plugin>
291299
<version.org.jacoco>0.8.12</version.org.jacoco>
292300
<version.org.jboss.galleon>7.0.0.Beta3</version.org.jboss.galleon>
293301
<version.org.owasp.dependency-check>12.1.6</version.org.owasp.dependency-check>
@@ -2034,5 +2042,104 @@
20342042
</plugins>
20352043
</build>
20362044
</profile>
2045+
2046+
<profile>
2047+
<id>maven-central-release</id>
2048+
2049+
<distributionManagement>
2050+
<snapshotRepository>
2051+
<id>${sonatype.server.id}</id>
2052+
<url>${repo.sonatype.url}</url>
2053+
</snapshotRepository>
2054+
<repository>
2055+
<id>${sonatype.server.id}</id>
2056+
<url>${repo.sonatype.url}</url>
2057+
</repository>
2058+
</distributionManagement>
2059+
2060+
<build>
2061+
<plugins>
2062+
<!-- Create a source-release artifact that contains the fully buildable
2063+
project directory source structure. This should be released to
2064+
the Maven repository for each JBoss project release. -->
2065+
<plugin>
2066+
<groupId>org.apache.maven.plugins</groupId>
2067+
<artifactId>maven-assembly-plugin</artifactId>
2068+
<version>${version.assembly.plugin}</version>
2069+
<dependencies>
2070+
<dependency>
2071+
<groupId>org.apache.apache.resources</groupId>
2072+
<artifactId>apache-source-release-assembly-descriptor</artifactId>
2073+
<version>1.7</version>
2074+
</dependency>
2075+
</dependencies>
2076+
<executions>
2077+
<execution>
2078+
<id>source-release-assembly</id>
2079+
<phase>package</phase>
2080+
<goals>
2081+
<goal>single</goal>
2082+
</goals>
2083+
<configuration>
2084+
<skipAssembly>${skipReleaseAssembly}</skipAssembly>
2085+
<runOnlyAtExecutionRoot>true</runOnlyAtExecutionRoot>
2086+
<descriptorRefs>
2087+
<descriptorRef>${sourceReleaseAssemblyDescriptor}</descriptorRef>
2088+
</descriptorRefs>
2089+
<tarLongFileMode>gnu</tarLongFileMode>
2090+
</configuration>
2091+
</execution>
2092+
</executions>
2093+
</plugin>
2094+
<plugin>
2095+
<groupId>org.apache.maven.plugins</groupId>
2096+
<artifactId>maven-deploy-plugin</artifactId>
2097+
<executions>
2098+
<execution>
2099+
<id>default-deploy</id>
2100+
<phase>none</phase>
2101+
</execution>
2102+
</executions>
2103+
</plugin>
2104+
<plugin>
2105+
<groupId>org.apache.maven.plugins</groupId>
2106+
<artifactId>maven-javadoc-plugin</artifactId>
2107+
<executions>
2108+
<execution>
2109+
<id>attach-javadocs</id>
2110+
<goals>
2111+
<goal>jar</goal>
2112+
</goals>
2113+
</execution>
2114+
</executions>
2115+
</plugin>
2116+
<plugin>
2117+
<groupId>org.apache.maven.plugins</groupId>
2118+
<artifactId>maven-gpg-plugin</artifactId>
2119+
<executions>
2120+
<execution>
2121+
<id>gpg-sign</id>
2122+
<goals>
2123+
<goal>sign</goal>
2124+
</goals>
2125+
</execution>
2126+
</executions>
2127+
</plugin>
2128+
<plugin>
2129+
<groupId>org.sonatype.central</groupId>
2130+
<artifactId>central-publishing-maven-plugin</artifactId>
2131+
<version>${version.central.publishing.maven.plugin}</version>
2132+
<extensions>true</extensions>
2133+
<configuration>
2134+
<publishingServerId>${sonatype.server.id}</publishingServerId>
2135+
<autoPublish>${autoPublish}</autoPublish>
2136+
<waitUntil>${waitUntil}</waitUntil>
2137+
<deploymentName>wildfly-${project.version}</deploymentName>
2138+
<skipPublishing>${skipPublishing}</skipPublishing>
2139+
</configuration>
2140+
</plugin>
2141+
</plugins>
2142+
</build>
2143+
</profile>
20372144
</profiles>
20382145
</project>

preview/dist/pom.xml

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
~ SPDX-License-Identifier: Apache-2.0
55
-->
66

7-
<project xmlns="http://maven.apache.org/POM/4.0.0"
8-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
8+
xmlns="http://maven.apache.org/POM/4.0.0"
99
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1010
<modelVersion>4.0.0</modelVersion>
1111

@@ -312,6 +312,41 @@
312312
</plugins>
313313
</build>
314314
</profile>
315+
<profile>
316+
<id>maven-central-release</id>
317+
<build>
318+
<plugins>
319+
<!--
320+
The wildfly-bom-builder-maven-plugin generates POM files for the BOM's. These files are added to
321+
the project via the plugin. However, with the central-publishing-maven-plugin these are not
322+
discovered and therefore do not get the checksum files required. To handle this, scan the staging
323+
directory and add checksum's for any POM files that are missing them.
324+
325+
This is executed here as it's the last sub-project/module to be built for releasing.
326+
-->
327+
<plugin>
328+
<groupId>dev.jbang</groupId>
329+
<artifactId>jbang-maven-plugin</artifactId>
330+
<version>0.0.8</version>
331+
<executions>
332+
<execution>
333+
<id>add-missing-checksums</id>
334+
<phase>install</phase>
335+
<goals>
336+
<goal>run</goal>
337+
</goals>
338+
<configuration>
339+
<script>${maven.multiModuleProjectDirectory}/ChecksumUpdater.java</script>
340+
<args>
341+
<arg>${maven.multiModuleProjectDirectory}/target/central-staging/</arg>
342+
</args>
343+
</configuration>
344+
</execution>
345+
</executions>
346+
</plugin>
347+
</plugins>
348+
</build>
349+
</profile>
315350
</profiles>
316351

317352
</project>

spec-api/test/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<!-- Don't try to deploy the module -->
2727
<maven.deploy.skip>true</maven.deploy.skip>
2828
<skipNexusStagingDeployMojo>true</skipNexusStagingDeployMojo>
29+
<skipPublishing>${maven.deploy.skip}</skipPublishing>
2930
</properties>
3031

3132
<build>

0 commit comments

Comments
 (0)