From 528fab96943fcbfd0b70367b8fa388d8ac2a8bbc Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Sat, 23 Mar 2024 20:00:17 +0100 Subject: [PATCH] [MGPG-113] SignAndDeployFileMojo results in 401 (#82) The RemoteRepository was "bare", it has to be equipped with AuthenticationSelector to be able to perform authenticated deploys. Also, remove "layout" as since Maven 3.0 there is no other layout than "default". Also, a bit of tidy up, layout is deprecated in Maven3 and is unused. --- https://issues.apache.org/jira/browse/MGPG-113 --- .../maven/plugins/gpg/AbstractGpgMojo.java | 4 +--- .../plugins/gpg/SignAndDeployFileMojo.java | 18 +++--------------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/gpg/AbstractGpgMojo.java b/src/main/java/org/apache/maven/plugins/gpg/AbstractGpgMojo.java index 9e159d0..c87ecf0 100644 --- a/src/main/java/org/apache/maven/plugins/gpg/AbstractGpgMojo.java +++ b/src/main/java/org/apache/maven/plugins/gpg/AbstractGpgMojo.java @@ -258,8 +258,6 @@ public abstract class AbstractGpgMojo extends AbstractMojo { @Component protected MavenSession session; - // === Deprecated stuff - /** * Switch to improve plugin enforcement of "best practices". If set to {@code false}, plugin retains all the * backward compatibility regarding getting secrets (but will warn). If set to {@code true}, plugin will fail @@ -280,7 +278,7 @@ public abstract class AbstractGpgMojo extends AbstractMojo { * @since 1.6 */ @Parameter(defaultValue = "${settings}", readonly = true, required = true) - private Settings settings; + protected Settings settings; /** * Maven Security Dispatcher. diff --git a/src/main/java/org/apache/maven/plugins/gpg/SignAndDeployFileMojo.java b/src/main/java/org/apache/maven/plugins/gpg/SignAndDeployFileMojo.java index 2d2c699..a276e13 100644 --- a/src/main/java/org/apache/maven/plugins/gpg/SignAndDeployFileMojo.java +++ b/src/main/java/org/apache/maven/plugins/gpg/SignAndDeployFileMojo.java @@ -72,12 +72,6 @@ public class SignAndDeployFileMojo extends AbstractGpgMojo { @Parameter(property = "gpg.ascDirectory") private File ascDirectory; - /** - * Flag whether Maven is currently in online/offline mode. - */ - @Parameter(defaultValue = "${settings.offline}", readonly = true) - private boolean offline; - /** * GroupId of the artifact to be deployed. Retrieved from POM file if specified. */ @@ -147,12 +141,6 @@ public class SignAndDeployFileMojo extends AbstractGpgMojo { @Parameter(property = "repositoryId", defaultValue = "remote-repository", required = true) private String repositoryId; - /** - * The type of remote repository layout to deploy to. Try legacy for a Maven 1.x-style repository layout. - */ - @Parameter(property = "repositoryLayout", defaultValue = "default") - private String repositoryLayout; - /** * The bundled API docs for the artifact. * @@ -241,7 +229,7 @@ private void initProperties() throws MojoExecutionException { @Override protected void doExecute() throws MojoExecutionException, MojoFailureException { - if (offline) { + if (settings.isOffline()) { throw new MojoFailureException("Cannot deploy artifacts when Maven is in offline mode"); } @@ -253,8 +241,6 @@ protected void doExecute() throws MojoExecutionException, MojoFailureException { throw new MojoFailureException(file.getPath() + " not found."); } - RemoteRepository deploymentRepository = new RemoteRepository.Builder(repositoryId, "default", url).build(); - // create artifacts List artifacts = new ArrayList<>(); @@ -369,6 +355,8 @@ protected void doExecute() throws MojoExecutionException, MojoFailureException { artifacts.addAll(signatures); // deploy all + RemoteRepository deploymentRepository = repositorySystem.newDeploymentRepository( + session.getRepositorySession(), new RemoteRepository.Builder(repositoryId, "default", url).build()); try { deploy(deploymentRepository, artifacts); } catch (DeploymentException e) {