Skip to content

Commit e152bf3

Browse files
authored
[MRESOLVER-301] Artifact generators (apache#432)
Artifact generators and one implementation: GnuPG Signer. The "signer" generator is simple module for signing artifacts with GnuPG Signer. --- https://issues.apache.org/jira/browse/MRESOLVER-301
1 parent 3c6991e commit e152bf3

File tree

37 files changed

+1904
-198
lines changed

37 files changed

+1904
-198
lines changed

maven-resolver-api/src/main/java/org/eclipse/aether/ConfigurationProperties.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,27 @@ public final class ConfigurationProperties {
6060
*/
6161
public static final String PREFIX_LAYOUT = PREFIX_AETHER + "layout.";
6262

63+
/**
64+
* Prefix for checksum related configurations. <em>For internal use only.</em>
65+
*
66+
* @since 2.0.0
67+
*/
68+
public static final String PREFIX_CHECKSUMS = PREFIX_AETHER + "checksums.";
69+
6370
/**
6471
* Prefix for local repository manager related configurations. <em>For internal use only.</em>
6572
*
6673
* @since 2.0.0
6774
*/
6875
public static final String PREFIX_LRM = PREFIX_AETHER + "lrm.";
6976

77+
/**
78+
* Prefix for generator related configurations. <em>For internal use only.</em>
79+
*
80+
* @since 2.0.0
81+
*/
82+
public static final String PREFIX_GENERATOR = PREFIX_AETHER + "generator.";
83+
7084
/**
7185
* Prefix for transport related configurations. <em>For internal use only.</em>
7286
*

maven-resolver-demos/maven-resolver-demo-snippets/pom.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434

3535
<properties>
3636
<Automatic-Module-Name>org.apache.maven.resolver.demo.snippets</Automatic-Module-Name>
37-
<!-- To make Jetty work -->
38-
<javaVersion>11</javaVersion>
37+
<!-- Jetty 10.x needs Java 11, generator-signer needs 17: we want both to work -->
38+
<javaVersion>17</javaVersion>
3939
</properties>
4040

4141
<dependencies>
@@ -75,6 +75,10 @@
7575
<groupId>org.apache.maven.resolver</groupId>
7676
<artifactId>maven-resolver-transport-jetty</artifactId>
7777
</dependency>
78+
<dependency>
79+
<groupId>org.apache.maven.resolver</groupId>
80+
<artifactId>maven-resolver-generator-gnupg</artifactId>
81+
</dependency>
7882
<dependency>
7983
<groupId>org.apache.maven.resolver</groupId>
8084
<artifactId>maven-resolver-supplier</artifactId>

maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/supplier/SupplierRepositorySystemFactory.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@
1818
*/
1919
package org.apache.maven.resolver.examples.supplier;
2020

21+
import java.util.LinkedHashMap;
2122
import java.util.Map;
2223

2324
import org.eclipse.aether.RepositorySystem;
25+
import org.eclipse.aether.generator.gnupg.GnupgSignatureArtifactGeneratorFactory;
26+
import org.eclipse.aether.generator.gnupg.loaders.*;
27+
import org.eclipse.aether.spi.artifact.generator.ArtifactGeneratorFactory;
2428
import org.eclipse.aether.spi.connector.transport.TransporterFactory;
2529
import org.eclipse.aether.supplier.RepositorySystemSupplier;
2630
import org.eclipse.aether.transport.jdk.JdkTransporterFactory;
@@ -32,6 +36,26 @@
3236
public class SupplierRepositorySystemFactory {
3337
public static RepositorySystem newRepositorySystem() {
3438
return new RepositorySystemSupplier() {
39+
@Override
40+
protected Map<String, ArtifactGeneratorFactory> createArtifactGeneratorFactories() {
41+
Map<String, ArtifactGeneratorFactory> result = super.createArtifactGeneratorFactories();
42+
result.put(
43+
GnupgSignatureArtifactGeneratorFactory.NAME,
44+
new GnupgSignatureArtifactGeneratorFactory(
45+
getArtifactPredicateFactory(), getGnupgSignatureArtifactGeneratorFactoryLoaders()));
46+
return result;
47+
}
48+
49+
private Map<String, GnupgSignatureArtifactGeneratorFactory.Loader>
50+
getGnupgSignatureArtifactGeneratorFactoryLoaders() {
51+
// order matters
52+
LinkedHashMap<String, GnupgSignatureArtifactGeneratorFactory.Loader> loaders = new LinkedHashMap<>();
53+
loaders.put(GpgEnvLoader.NAME, new GpgEnvLoader());
54+
loaders.put(GpgConfLoader.NAME, new GpgConfLoader());
55+
loaders.put(GpgAgentPasswordLoader.NAME, new GpgAgentPasswordLoader());
56+
return loaders;
57+
}
58+
3559
@Override
3660
protected Map<String, TransporterFactory> createTransporterFactories() {
3761
Map<String, TransporterFactory> result = super.createTransporterFactories();

maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/util/Booter.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.apache.maven.resolver.examples.util;
2020

21+
import java.nio.file.Path;
2122
import java.nio.file.Paths;
2223
import java.util.ArrayList;
2324
import java.util.Collections;
@@ -61,22 +62,29 @@ public static RepositorySystem newRepositorySystem(final String factory) {
6162
}
6263

6364
public static SessionBuilder newRepositorySystemSession(RepositorySystem system) {
65+
Path localRepo = Paths.get("target/local-repo");
6466
// FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
65-
SessionBuilder result = new SessionBuilderSupplier(system)
67+
return new SessionBuilderSupplier(system)
6668
.get()
6769
// .withLocalRepositoryBaseDirectories(fs.getPath("local-repo"))
68-
.withLocalRepositoryBaseDirectories(Paths.get("target/local-repo"))
70+
.withLocalRepositoryBaseDirectories(localRepo)
6971
.setRepositoryListener(new ConsoleRepositoryListener())
70-
.setTransferListener(new ConsoleTransferListener());
71-
result.setConfigProperty("aether.syncContext.named.factory", "noop");
72+
.setTransferListener(new ConsoleTransferListener())
73+
.setConfigProperty("aether.generator.gpg.enabled", Boolean.TRUE.toString())
74+
.setConfigProperty(
75+
"aether.generator.gpg.keyFilePath",
76+
Paths.get("src/main/resources/alice.key")
77+
.toAbsolutePath()
78+
.toString())
79+
.setConfigProperty("aether.syncContext.named.factory", "noop");
7280
// result.addOnSessionEndedHandler(() -> {
7381
// try {
7482
// fs.close();
7583
// } catch (IOException e) {
7684
// throw new UncheckedIOException(e);
7785
// }
7886
// });
79-
return result;
87+
8088
// uncomment to generate dirty trees
8189
// session.setDependencyGraphTransformer( null );
8290
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-----BEGIN PGP PRIVATE KEY BLOCK-----
2+
Comment: Alice's OpenPGP Transferable Secret Key
3+
Comment: https://www.ietf.org/id/draft-bre-openpgp-samples-01.html
4+
5+
lFgEXEcE6RYJKwYBBAHaRw8BAQdArjWwk3FAqyiFbFBKT4TzXcVBqPTB3gmzlC/U
6+
b7O1u10AAP9XBeW6lzGOLx7zHH9AsUDUTb2pggYGMzd0P3ulJ2AfvQ4RtCZBbGlj
7+
ZSBMb3ZlbGFjZSA8YWxpY2VAb3BlbnBncC5leGFtcGxlPoiQBBMWCAA4AhsDBQsJ
8+
CAcCBhUKCQgLAgQWAgMBAh4BAheAFiEE64W7X6M6deFelE5j8jFVDE9H444FAl2l
9+
nzoACgkQ8jFVDE9H447pKwD6A5xwUqIDprBzrHfahrImaYEZzncqb25vkLV2arYf
10+
a78A/R3AwtLQvjxwLDuzk4dUtUwvUYibL2sAHwj2kGaHnfICnF0EXEcE6RIKKwYB
11+
BAGXVQEFAQEHQEL/BiGtq0k84Km1wqQw2DIikVYrQrMttN8d7BPfnr4iAwEIBwAA
12+
/3/xFPG6U17rhTuq+07gmEvaFYKfxRB6sgAYiW6TMTpQEK6IeAQYFggAIBYhBOuF
13+
u1+jOnXhXpROY/IxVQxPR+OOBQJcRwTpAhsMAAoJEPIxVQxPR+OOWdABAMUdSzpM
14+
hzGs1O0RkWNQWbUzQ8nUOeD9wNbjE3zR+yfRAQDbYqvtWQKN4AQLTxVJN5X5AWyb
15+
Pnn+We1aTBhaGa86AQ==
16+
=n8OM
17+
-----END PGP PRIVATE KEY BLOCK-----
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<parent>
24+
<groupId>org.apache.maven.resolver</groupId>
25+
<artifactId>maven-resolver</artifactId>
26+
<version>2.0.0-SNAPSHOT</version>
27+
</parent>
28+
29+
<artifactId>maven-resolver-generator-gnupg</artifactId>
30+
31+
<name>Maven Artifact Resolver GnuPG Signer Generator</name>
32+
<description>A generator implementation for GnuPG signatures.</description>
33+
34+
<properties>
35+
<Automatic-Module-Name>org.apache.maven.resolver.generator.gnupg</Automatic-Module-Name>
36+
<Bundle-SymbolicName>${Automatic-Module-Name}</Bundle-SymbolicName>
37+
38+
<bouncycastleVersion>1.77</bouncycastleVersion>
39+
40+
<javaVersion>17</javaVersion>
41+
</properties>
42+
43+
<dependencies>
44+
<dependency>
45+
<groupId>org.apache.maven.resolver</groupId>
46+
<artifactId>maven-resolver-api</artifactId>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.apache.maven.resolver</groupId>
50+
<artifactId>maven-resolver-spi</artifactId>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.apache.maven.resolver</groupId>
54+
<artifactId>maven-resolver-util</artifactId>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.slf4j</groupId>
58+
<artifactId>slf4j-api</artifactId>
59+
</dependency>
60+
<dependency>
61+
<groupId>javax.inject</groupId>
62+
<artifactId>javax.inject</artifactId>
63+
<scope>provided</scope>
64+
<optional>true</optional>
65+
</dependency>
66+
<dependency>
67+
<groupId>org.eclipse.sisu</groupId>
68+
<artifactId>org.eclipse.sisu.inject</artifactId>
69+
<scope>provided</scope>
70+
<optional>true</optional>
71+
</dependency>
72+
73+
<dependency>
74+
<groupId>org.bouncycastle</groupId>
75+
<artifactId>bcpg-jdk18on</artifactId>
76+
<version>${bouncycastleVersion}</version>
77+
</dependency>
78+
<dependency>
79+
<groupId>org.bouncycastle</groupId>
80+
<artifactId>bcprov-jdk18on</artifactId>
81+
<version>${bouncycastleVersion}</version>
82+
</dependency>
83+
84+
<dependency>
85+
<groupId>org.junit.jupiter</groupId>
86+
<artifactId>junit-jupiter-api</artifactId>
87+
<scope>test</scope>
88+
</dependency>
89+
<dependency>
90+
<groupId>org.apache.maven.resolver</groupId>
91+
<artifactId>maven-resolver-test-util</artifactId>
92+
<scope>test</scope>
93+
</dependency>
94+
<dependency>
95+
<groupId>org.slf4j</groupId>
96+
<artifactId>slf4j-simple</artifactId>
97+
<scope>test</scope>
98+
</dependency>
99+
<dependency>
100+
<groupId>org.mockito</groupId>
101+
<artifactId>mockito-core</artifactId>
102+
<scope>test</scope>
103+
</dependency>
104+
</dependencies>
105+
106+
<build>
107+
<plugins>
108+
<plugin>
109+
<groupId>org.apache.rat</groupId>
110+
<artifactId>apache-rat-plugin</artifactId>
111+
<configuration>
112+
<excludes combine.children="append">
113+
<exclude>src/test/resources/gpg-signing/**</exclude>
114+
</excludes>
115+
</configuration>
116+
</plugin>
117+
<plugin>
118+
<groupId>org.eclipse.sisu</groupId>
119+
<artifactId>sisu-maven-plugin</artifactId>
120+
</plugin>
121+
<plugin>
122+
<groupId>biz.aQute.bnd</groupId>
123+
<artifactId>bnd-maven-plugin</artifactId>
124+
</plugin>
125+
<plugin>
126+
<groupId>org.apache.maven.plugins</groupId>
127+
<artifactId>maven-jar-plugin</artifactId>
128+
<configuration>
129+
<archive>
130+
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
131+
</archive>
132+
</configuration>
133+
</plugin>
134+
</plugins>
135+
</build>
136+
</project>
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.eclipse.aether.generator.gnupg;
20+
21+
import org.eclipse.aether.ConfigurationProperties;
22+
import org.eclipse.aether.RepositorySystemSession;
23+
24+
/**
25+
* Configuration for GPG Signer.
26+
*
27+
* @since 2.0.0
28+
*/
29+
public final class GnupgConfigurationKeys {
30+
private GnupgConfigurationKeys() {}
31+
32+
static final String NAME = "gpg";
33+
34+
static final String CONFIG_PROPS_PREFIX = ConfigurationProperties.PREFIX_GENERATOR + NAME + ".";
35+
36+
/**
37+
* Whether GnuPG signer is enabled.
38+
*
39+
* @configurationSource {@link RepositorySystemSession#getConfigProperties()}
40+
* @configurationType {@link Boolean}
41+
* @configurationDefaultValue {@link #DEFAULT_ENABLED}
42+
*/
43+
public static final String CONFIG_PROP_ENABLED = CONFIG_PROPS_PREFIX + "enabled";
44+
45+
public static final boolean DEFAULT_ENABLED = false;
46+
47+
/**
48+
* The PGP KeyID, optional. If not set, first secret key found will be used.
49+
*
50+
* @configurationSource {@link RepositorySystemSession#getConfigProperties()}
51+
* @configurationType {@link Long}
52+
*/
53+
public static final String CONFIG_PROP_KEY_ID = CONFIG_PROPS_PREFIX + "keyId";
54+
55+
/**
56+
* The path to the OpenPGP transferable secret key file. If relative, is resolved from local repository root.
57+
*
58+
* @configurationSource {@link RepositorySystemSession#getConfigProperties()}
59+
* @configurationType {@link String}
60+
* @configurationDefaultValue {@link #DEFAULT_KEY_FILE_PATH}
61+
*/
62+
public static final String CONFIG_PROP_KEY_FILE_PATH = CONFIG_PROPS_PREFIX + "keyFilePath";
63+
64+
public static final String DEFAULT_KEY_FILE_PATH = "maven-signing-key.key";
65+
66+
/**
67+
* The GnuPG agent socket(s) to try. Comma separated list of socket paths. If relative, will be resolved from
68+
* user home directory.
69+
*
70+
* @configurationSource {@link RepositorySystemSession#getConfigProperties()}
71+
* @configurationType {@link String}
72+
* @configurationDefaultValue {@link #DEFAULT_AGENT_SOCKET_LOCATIONS}
73+
*/
74+
public static final String CONFIG_PROP_AGENT_SOCKET_LOCATIONS = CONFIG_PROPS_PREFIX + "agentSocketLocations";
75+
76+
public static final String DEFAULT_AGENT_SOCKET_LOCATIONS = ".gnupg/S.gpg-agent";
77+
78+
/**
79+
* Env variable name to pass in key pass.
80+
*/
81+
public static final String RESOLVER_GPG_KEY_PASS = "RESOLVER_GPG_KEY_PASS";
82+
83+
/**
84+
* Env variable name to pass in key material.
85+
*/
86+
public static final String RESOLVER_GPG_KEY = "RESOLVER_GPG_KEY";
87+
88+
/**
89+
* Env variable name to pass in key ID.
90+
*/
91+
public static final String RESOLVER_GPG_KEY_ID = "RESOLVER_GPG_KEY_ID";
92+
}

0 commit comments

Comments
 (0)