Skip to content
Permalink
Browse files
flex-sdk-converter: DownloadRetriever and ProgressBar use slf4j Simpl…
…eLogger so that Maven -q option will correctly hide non-error output
  • Loading branch information
joshtynjala committed Jul 23, 2017
1 parent 8b168c1 commit b1a013c9694699081277dca2b690655cc9dbe6fc
Showing 3 changed files with 36 additions and 23 deletions.
@@ -57,6 +57,11 @@
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.21</version>
</dependency>

<!--TEST-->
<dependency>
@@ -17,12 +17,16 @@
package org.apache.flex.utilities.converter.retrievers.utils;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Created by cdutz on 24.05.2014.
*/
public class ProgressBar {

private static final Logger LOG = LoggerFactory.getLogger(ProgressBar.class);

protected long total;

public ProgressBar(long total) {
@@ -39,7 +43,7 @@ protected void drawOutput(long current) {
((double) current / (double) total) * (double) 100);
final int segmentsTransferred = transferredPercent / 2;
final int segmentsRest = 50 - segmentsTransferred;
System.out.print("\r" + String.format(" %3d", transferredPercent) + "% [" +
LOG.info("\r" + String.format(" %3d", transferredPercent) + "% [" +
StringUtils.repeat("=", segmentsTransferred) +
((segmentsRest > 0) ? ">" + StringUtils.repeat(" ", segmentsRest - 1) : "") + "] ");
}
@@ -32,6 +32,8 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
@@ -62,6 +64,8 @@ public class DownloadRetriever extends BaseRetriever {

public static final long MEGABYTE = 1 << 20;

private static final Logger LOG = LoggerFactory.getLogger(DownloadRetriever.class);

/**
* Wrapper to allow simple overriding of this property.
*
@@ -140,17 +144,17 @@ public File retrieve(SdkType type, String version, PlatformType platformType)
FileUtils.moveFile(targetFile, libDestFile);
return targetDirectory;
} else {
System.out.println("Extracting archive to temp directory.");
LOG.info("Extracting archive to temp directory.");
File targetDirectory = new File(targetFile.getParent(),
targetFile.getName().substring(0, targetFile.getName().lastIndexOf(".") - 1));
if (type.equals(SdkType.SWFOBJECT)) {
unpack(targetFile, new File(targetDirectory, "templates"));
} else {
unpack(targetFile, targetDirectory);
}
System.out.println();
System.out.println("Finished extracting.");
System.out.println("===========================================================");
LOG.info("");
LOG.info("Finished extracting.");
LOG.info("===========================================================");

// In case of the swfobject, delete some stuff we don't want in there.
if (type.equals(SdkType.SWFOBJECT)) {
@@ -207,12 +211,12 @@ protected void performFastDownload(URL sourceUrl, File targetFile) throws IOExce
final long expectedSize = connection.getContentLength();
long transferedSize = 0L;

System.out.println("===========================================================");
System.out.println("Downloading " + sourceUrl.toString());
LOG.info("===========================================================");
LOG.info("Downloading " + sourceUrl.toString());
if (expectedSize > 1014 * 1024) {
System.out.println("Expected size: " + (expectedSize / 1024 / 1024) + "MB");
LOG.info("Expected size: " + (expectedSize / 1024 / 1024) + "MB");
} else {
System.out.println("Expected size: " + (expectedSize / 1024) + "KB");
LOG.info("Expected size: " + (expectedSize / 1024) + "KB");
}
final ProgressBar progressBar = new ProgressBar(expectedSize);
while (transferedSize < expectedSize) {
@@ -235,9 +239,9 @@ protected void performFastDownload(URL sourceUrl, File targetFile) throws IOExce
}
}
}
System.out.println();
System.out.println("Finished downloading.");
System.out.println("===========================================================");
LOG.info("");
LOG.info("Finished downloading.");
LOG.info("===========================================================");
}

protected void performSafeDownload(URI sourceUri, File targetFile) throws IOException {
@@ -259,8 +263,8 @@ protected void performSafeDownload(URI sourceUri, File targetFile) throws IOExce

String reasonPhrase = response.getStatusLine().getReasonPhrase();
int statusCode = response.getStatusLine().getStatusCode();
System.out.println(String.format("statusCode: %d", statusCode));
System.out.println(String.format("reasonPhrase: %s", reasonPhrase));
LOG.info(String.format("statusCode: %d", statusCode));
LOG.info(String.format("reasonPhrase: %s", reasonPhrase));

HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
@@ -276,21 +280,21 @@ protected void performSafeDownload(URI sourceUri, File targetFile) throws IOExce
////////////////////////////////////////////////////////////////////////////////

final long expectedSize = entity.getContentLength();
System.out.println("===========================================================");
System.out.println("Downloading " + sourceUri.toString());
LOG.info("===========================================================");
LOG.info("Downloading " + sourceUri.toString());
if (expectedSize <= 0) {
try {
System.out.println("Unknown size.");
LOG.info("Unknown size.");
IOUtils.copy(content, fos);
} finally {
// close http network connection
content.close();
}
} else {
if (expectedSize > 1014 * 1024) {
System.out.println("Expected size: " + (expectedSize / 1024 / 1024) + "MB");
LOG.info("Expected size: " + (expectedSize / 1024 / 1024) + "MB");
} else {
System.out.println("Expected size: " + (expectedSize / 1024) + "KB");
LOG.info("Expected size: " + (expectedSize / 1024) + "KB");
}
final ProgressBar progressBar = new ProgressBar(expectedSize);
long transferredSize = 0L;
@@ -304,10 +308,10 @@ protected void performSafeDownload(URI sourceUri, File targetFile) throws IOExce
progressBar.updateProgress(transferredSize);
}
fos.close();
System.out.println();
LOG.info("");
}
System.out.println("Finished downloading.");
System.out.println("===========================================================");
LOG.info("Finished downloading.");
LOG.info("===========================================================");
} finally {
if(rbc != null) {
try {
@@ -347,7 +351,7 @@ protected String getBinaryUrl(SdkType sdkType, String version, PlatformType plat
SocketAddress socketAddress = new InetSocketAddress(proxySettings.getHost(), proxySettings.getPort());
Proxy proxy = new Proxy(Proxy.Type.valueOf(proxySettings.getProtocol().toUpperCase()), socketAddress);
connection = configUrl.openConnection(proxy);
System.out.println("Using proxy: " + proxySettings.getHost());
LOG.info("Using proxy: " + proxySettings.getHost());
} else {
connection = configUrl.openConnection();
}

0 comments on commit b1a013c

Please sign in to comment.