Skip to content

Commit 6c97398

Browse files
authored
Configure Wagon from settings.xml (#1233)
This regressed with e414d23 This closes #1217
1 parent 3d09433 commit 6c97398

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,14 @@ under the License.
284284
<version>${mavenVersion}</version>
285285
<scope>provided</scope>
286286
</dependency>
287+
<!-- reusing component to configure Wagon -->
288+
<dependency>
289+
<groupId>org.apache.maven.resolver</groupId>
290+
<artifactId>maven-resolver-transport-wagon</artifactId>
291+
<version>1.4.1</version>
292+
<!-- version shipping with Maven 3.6.3-->
293+
<scope>compile</scope>
294+
</dependency>
287295

288296
<dependency>
289297
<groupId>org.apache.maven</groupId>

src/main/java/org/apache/maven/plugins/site/deploy/AbstractDeployMojo.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
import org.apache.maven.wagon.observers.Debug;
5656
import org.apache.maven.wagon.proxy.ProxyInfo;
5757
import org.apache.maven.wagon.repository.Repository;
58+
import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
59+
import org.codehaus.plexus.util.xml.Xpp3Dom;
60+
import org.eclipse.aether.transport.wagon.WagonConfigurator;
5861

5962
/**
6063
* Abstract base class for deploy mojos.
@@ -129,6 +132,8 @@ public abstract class AbstractDeployMojo extends AbstractSiteMojo {
129132
@Inject
130133
SettingsDecrypter settingsDecrypter;
131134

135+
@Inject
136+
private WagonConfigurator wagonConfigurator;
132137
/**
133138
* {@inheritDoc}
134139
*/
@@ -285,6 +290,28 @@ private Wagon getWagon(final Repository repository) throws MojoExecutionExceptio
285290
throw new MojoExecutionException(
286291
"Wagon protocol '" + repository.getProtocol() + "' doesn't support directory copying");
287292
}
293+
// retrieve relevant settings
294+
Server server = settings.getServer(repository.getId());
295+
// taken over from
296+
// https://github.com/apache/maven/blob/18a52647884dcc822eb04bf5a3265a21dc83256c/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java#L242
297+
if (server != null && server.getConfiguration() != null) {
298+
Xpp3Dom dom = (Xpp3Dom) server.getConfiguration();
299+
for (int i = dom.getChildCount() - 1; i >= 0; i--) {
300+
Xpp3Dom child = dom.getChild(i);
301+
if ("wagonProvider".equals(child.getName())) {
302+
dom.removeChild(i);
303+
}
304+
}
305+
XmlPlexusConfiguration config = new XmlPlexusConfiguration(dom);
306+
try {
307+
// use Wagon configurator from Resolver
308+
wagonConfigurator.configure(wagon, config);
309+
} catch (Exception e) {
310+
throw new MojoExecutionException(
311+
"Error configuring wagon with server configuration for server id '" + repository.getId() + "'",
312+
e);
313+
}
314+
}
288315
return wagon;
289316
}
290317

0 commit comments

Comments
 (0)