|
18 | 18 | */ |
19 | 19 | package org.apache.maven.plugins.gpg; |
20 | 20 |
|
| 21 | +import javax.inject.Inject; |
| 22 | + |
21 | 23 | import java.io.File; |
22 | | -import java.util.Collections; |
23 | 24 | import java.util.List; |
24 | 25 |
|
25 | 26 | import org.apache.maven.execution.MavenSession; |
26 | 27 | import org.apache.maven.plugin.AbstractMojo; |
27 | 28 | import org.apache.maven.plugin.MojoExecutionException; |
28 | 29 | import org.apache.maven.plugin.MojoFailureException; |
29 | | -import org.apache.maven.plugins.annotations.Component; |
30 | 30 | import org.apache.maven.plugins.annotations.Parameter; |
31 | 31 | import org.apache.maven.project.MavenProject; |
32 | 32 | import org.apache.maven.settings.Server; |
33 | 33 | import org.apache.maven.settings.Settings; |
34 | | -import org.sonatype.plexus.components.cipher.DefaultPlexusCipher; |
35 | | -import org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher; |
36 | | -import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher; |
37 | | -import org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException; |
| 34 | +import org.apache.maven.settings.building.SettingsProblem; |
| 35 | +import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest; |
| 36 | +import org.apache.maven.settings.crypto.SettingsDecrypter; |
| 37 | +import org.apache.maven.settings.crypto.SettingsDecryptionResult; |
38 | 38 |
|
39 | 39 | /** |
40 | 40 | * @author Benjamin Bentmann |
@@ -256,12 +256,6 @@ public abstract class AbstractGpgMojo extends AbstractMojo { |
256 | 256 | @Parameter(property = "gpg.signer", defaultValue = GpgSigner.NAME) |
257 | 257 | private String signer; |
258 | 258 |
|
259 | | - /** |
260 | | - * @since 3.0.0 |
261 | | - */ |
262 | | - @Component |
263 | | - protected MavenSession session; |
264 | | - |
265 | 259 | /** |
266 | 260 | * Switch to improve plugin enforcement of "best practices". If set to {@code false}, plugin retains all the |
267 | 261 | * backward compatibility regarding getting secrets (but will warn). If set to {@code true}, plugin will fail |
@@ -285,14 +279,16 @@ public abstract class AbstractGpgMojo extends AbstractMojo { |
285 | 279 | protected Settings settings; |
286 | 280 |
|
287 | 281 | /** |
288 | | - * Maven Security Dispatcher. |
289 | | - * |
290 | | - * @since 1.6 |
291 | | - * @deprecated Provides quasi-encryption, should be avoided. |
| 282 | + * @since 3.0.0 |
292 | 283 | */ |
293 | | - @Deprecated |
294 | | - private final SecDispatcher secDispatcher = |
295 | | - new DefaultSecDispatcher(new DefaultPlexusCipher(), Collections.emptyMap(), "~/.m2/settings-security.xml"); |
| 284 | + @Inject |
| 285 | + protected MavenSession session; |
| 286 | + |
| 287 | + /** |
| 288 | + * @since 3.2.6 |
| 289 | + */ |
| 290 | + @Inject |
| 291 | + protected SettingsDecrypter settingsDecrypter; |
296 | 292 |
|
297 | 293 | @Override |
298 | 294 | public final void execute() throws MojoExecutionException, MojoFailureException { |
@@ -415,11 +411,23 @@ private String loadGpgPassphrase() throws MojoFailureException { |
415 | 411 | Server server = settings.getServer(passphraseServerId); |
416 | 412 | if (server != null) { |
417 | 413 | if (isNotBlank(server.getPassphrase())) { |
418 | | - try { |
419 | | - return secDispatcher.decrypt(server.getPassphrase()); |
420 | | - } catch (SecDispatcherException e) { |
421 | | - throw new MojoFailureException("Unable to decrypt gpg passphrase", e); |
| 414 | + SettingsDecryptionResult result = |
| 415 | + settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(server)); |
| 416 | + for (SettingsProblem problem : result.getProblems()) { |
| 417 | + switch (problem.getSeverity()) { |
| 418 | + case WARNING: |
| 419 | + case ERROR: |
| 420 | + getLog().warn(problem.getMessage(), problem.getException()); |
| 421 | + break; |
| 422 | + case FATAL: |
| 423 | + getLog().error(problem.getMessage(), problem.getException()); |
| 424 | + throw new MojoFailureException(problem.getMessage(), problem.getException()); |
| 425 | + default: |
| 426 | + throw new IllegalStateException("Unknown severity: " |
| 427 | + + problem.getSeverity().toString()); |
| 428 | + } |
422 | 429 | } |
| 430 | + return result.getServer().getPassphrase(); |
423 | 431 | } |
424 | 432 | } |
425 | 433 | } |
|