You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by cd...@apache.org on 2015/07/20 11:43:56 UTC
[2/2] git commit: [flex-utilities] [refs/heads/develop] - - Changed
the way the Proxy authentication credentials are provided for URLConnections
- Added proxy options to downloading of the config-xml (Was missing any form
of proxy features)
- Changed the way the Proxy authentication credentials are provided for URLConnections
- Added proxy options to downloading of the config-xml (Was missing any form of proxy features)
Project: http://git-wip-us.apache.org/repos/asf/flex-utilities/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-utilities/commit/57a41275
Tree: http://git-wip-us.apache.org/repos/asf/flex-utilities/tree/57a41275
Diff: http://git-wip-us.apache.org/repos/asf/flex-utilities/diff/57a41275
Branch: refs/heads/develop
Commit: 57a412750fedc29aa0e023eccd967ecc6e3eb101
Parents: a4a9c88
Author: Christofer Dutz <ch...@codecentric.de>
Authored: Mon Jul 20 11:43:43 2015 +0200
Committer: Christofer Dutz <ch...@codecentric.de>
Committed: Mon Jul 20 11:43:43 2015 +0200
----------------------------------------------------------------------
.../converter/mavenextension/FlexEventSpy.java | 18 ++++++++++++++++-
.../retrievers/download/DownloadRetriever.java | 21 +++++++++++++-------
2 files changed, 31 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/57a41275/flex-maven-tools/mavenizer/maven-extension/src/main/java/org/apache/flex/utilities/converter/mavenextension/FlexEventSpy.java
----------------------------------------------------------------------
diff --git a/flex-maven-tools/mavenizer/maven-extension/src/main/java/org/apache/flex/utilities/converter/mavenextension/FlexEventSpy.java b/flex-maven-tools/mavenizer/maven-extension/src/main/java/org/apache/flex/utilities/converter/mavenextension/FlexEventSpy.java
index 88d7e72..4ee9915 100644
--- a/flex-maven-tools/mavenizer/maven-extension/src/main/java/org/apache/flex/utilities/converter/mavenextension/FlexEventSpy.java
+++ b/flex-maven-tools/mavenizer/maven-extension/src/main/java/org/apache/flex/utilities/converter/mavenextension/FlexEventSpy.java
@@ -1,6 +1,7 @@
package org.apache.flex.utilities.converter.mavenextension;
import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.flex.utilities.converter.air.AirConverter;
import org.apache.flex.utilities.converter.flash.FlashConverter;
import org.apache.flex.utilities.converter.flex.FlexConverter;
@@ -25,6 +26,8 @@ import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.File;
+import java.net.Authenticator;
+import java.net.PasswordAuthentication;
/**
* Maven EventSpy that listens for resolution requests and in case of Flex related
@@ -190,9 +193,22 @@ public class FlexEventSpy extends AbstractEventSpy {
File localRepoBaseDir = new File(mavenSession.getLocalRepository().getBasedir());
DownloadRetriever downloadRetriever = new DownloadRetriever();
- ProxySettings proxySettings = null;
+ final ProxySettings proxySettings;
if(mavenSession.getSettings().getActiveProxy() != null) {
proxySettings = getProxySettings();
+ if(!StringUtils.isEmpty(proxySettings.getUsername()) &&
+ !StringUtils.isEmpty(proxySettings.getPassword())) {
+ Authenticator authenticator = new Authenticator() {
+ @Override
+ protected PasswordAuthentication getPasswordAuthentication() {
+ return new PasswordAuthentication(proxySettings.getUsername(),
+ proxySettings.getPassword().toCharArray());
+ }
+ };
+ Authenticator.setDefault(authenticator);
+ }
+ } else {
+ proxySettings = null;
}
PlatformType platformType;
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/57a41275/flex-maven-tools/mavenizer/retrievers/download/src/main/java/org/apache/flex/utilities/converter/retrievers/download/DownloadRetriever.java
----------------------------------------------------------------------
diff --git a/flex-maven-tools/mavenizer/retrievers/download/src/main/java/org/apache/flex/utilities/converter/retrievers/download/DownloadRetriever.java b/flex-maven-tools/mavenizer/retrievers/download/src/main/java/org/apache/flex/utilities/converter/retrievers/download/DownloadRetriever.java
index f086221..490f8c0 100644
--- a/flex-maven-tools/mavenizer/retrievers/download/src/main/java/org/apache/flex/utilities/converter/retrievers/download/DownloadRetriever.java
+++ b/flex-maven-tools/mavenizer/retrievers/download/src/main/java/org/apache/flex/utilities/converter/retrievers/download/DownloadRetriever.java
@@ -120,7 +120,7 @@ public class DownloadRetriever extends BaseRetriever {
return targetRootDir;
} else {
- final URL sourceUrl = new URL(getBinaryUrl(type, version, platformType));
+ final URL sourceUrl = new URL(getBinaryUrl(type, version, platformType, proxySettings));
final File targetFile = File.createTempFile(type.toString() + "-" + version +
((platformType != null) ? "-" + platformType : "") + "-",
sourceUrl.getFile().substring(sourceUrl.getFile().lastIndexOf(".")));
@@ -185,11 +185,8 @@ public class DownloadRetriever extends BaseRetriever {
URLConnection connection;
if(proxySettings != null) {
SocketAddress socketAddress = new InetSocketAddress(proxySettings.getHost(), proxySettings.getPort());
- Proxy proxy = new Proxy(Proxy.Type.valueOf(proxySettings.getProtocol()), socketAddress);
+ Proxy proxy = new Proxy(Proxy.Type.valueOf(proxySettings.getProtocol().toUpperCase()), socketAddress);
connection = sourceUrl.openConnection(proxy);
- String encoded = new String
- (Base64.getEncoder().encode("username:password".getBytes()));
- connection.setRequestProperty("Proxy-Authorization", "Basic " + encoded);
} else {
connection = sourceUrl.openConnection();
}
@@ -280,12 +277,22 @@ public class DownloadRetriever extends BaseRetriever {
System.out.println("===========================================================");
}
- protected String getBinaryUrl(SdkType sdkType, String version, PlatformType platformType)
+ protected String getBinaryUrl(SdkType sdkType, String version, PlatformType platformType,
+ ProxySettings proxySettings)
throws RetrieverException {
try {
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
final DocumentBuilder builder = factory.newDocumentBuilder();
- final Document doc = builder.parse(getFlexInstallerConfigUrl());
+ final URL configUrl = new URL(getFlexInstallerConfigUrl());
+ URLConnection connection;
+ if(proxySettings != null) {
+ SocketAddress socketAddress = new InetSocketAddress(proxySettings.getHost(), proxySettings.getPort());
+ Proxy proxy = new Proxy(Proxy.Type.valueOf(proxySettings.getProtocol().toUpperCase()), socketAddress);
+ connection = configUrl.openConnection(proxy);
+ } else {
+ connection = configUrl.openConnection();
+ }
+ final Document doc = builder.parse(connection.getInputStream());
//Evaluate XPath against Document itself
final String expression = getUrlXpath(sdkType, version, platformType);