From 9b38938c03d454415258226ae10e7d3aa464493e Mon Sep 17 00:00:00 2001 From: Christofer Dutz Date: Fri, 3 Feb 2017 15:31:03 +0100 Subject: [PATCH] - Switched from System.out.println to logback - Fixed a problem in the AirConverter, not packaging all the required parts --- .../utilities/converter/air/AirConverter.java | 40 +++++++++++++++---- .../converters/base/pom.xml | 16 ++++++++ .../utilities/converter/BaseConverter.java | 10 +++-- .../base/src/main/resources/logback.xml | 16 ++++++++ .../deployer/aether/AetherDeployer.java | 26 +++++++----- 5 files changed, 86 insertions(+), 22 deletions(-) create mode 100644 flex-maven-tools/flex-sdk-converter/converters/base/src/main/resources/logback.xml diff --git a/flex-maven-tools/flex-sdk-converter/converters/air/src/main/java/org/apache/flex/utilities/converter/air/AirConverter.java b/flex-maven-tools/flex-sdk-converter/converters/air/src/main/java/org/apache/flex/utilities/converter/air/AirConverter.java index 46373c48..205daaa2 100644 --- a/flex-maven-tools/flex-sdk-converter/converters/air/src/main/java/org/apache/flex/utilities/converter/air/AirConverter.java +++ b/flex-maven-tools/flex-sdk-converter/converters/air/src/main/java/org/apache/flex/utilities/converter/air/AirConverter.java @@ -20,6 +20,8 @@ import org.apache.flex.utilities.converter.Converter; import org.apache.flex.utilities.converter.exceptions.ConverterException; import org.apache.flex.utilities.converter.model.MavenArtifact; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.*; import java.util.*; @@ -31,6 +33,8 @@ */ public class AirConverter extends BaseConverter implements Converter { + private static final Logger LOG = LoggerFactory.getLogger(AirConverter.class); + private String airSdkVersion; /** @@ -53,7 +57,7 @@ public AirConverter(File rootSourceDirectory, File rootTargetDirectory) throws C @Override protected void processDirectory() throws ConverterException { if ((airSdkVersion == null) || !rootSourceDirectory.exists() || !rootSourceDirectory.isDirectory()) { - System.out.println("Skipping AIR SDK generation."); + LOG.info("Skipping AIR SDK generation."); return; } @@ -94,13 +98,28 @@ private void generateCompilerArtifacts() throws ConverterException { compiler.addDependency(artifact); } + // Generate the common package (files from the bin directory) + File binDir = new File(rootSourceDirectory, "bin"); + if (binDir.exists() && binDir.isDirectory()) { + final File commonZip = new File(rootTargetDirectory, + "com.adobe.air.compiler.adt.".replace(".", File.separator) + airSdkVersion + + File.separator + "adt-" + airSdkVersion + "-common.zip"); + generateZip(binDir, commonZip, new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + return "adt".equals(name) || "adt.bat".equals(name) || + "adl".equals(name) || "adl.exe".equals(name); + } + }); + } + // Generate the android package (android directory) File androidDir = new File(directory, "android"); if (androidDir.exists() && androidDir.isDirectory()) { final File androidZip = new File(rootTargetDirectory, "com.adobe.air.compiler.adt.".replace(".", File.separator) + airSdkVersion + File.separator + "adt-" + airSdkVersion + "-android.zip"); - generateCompilerPlatformArtifact(androidDir, androidZip); + generateZip(androidDir, androidZip); } // Generate the ios package (aot directory) @@ -109,7 +128,7 @@ private void generateCompilerArtifacts() throws ConverterException { final File iosZip = new File(rootTargetDirectory, "com.adobe.air.compiler.adt.".replace(".", File.separator) + airSdkVersion + File.separator + "adt-" + airSdkVersion + "-ios.zip"); - generateCompilerPlatformArtifact(iosDir, iosZip); + generateZip(iosDir, iosZip); } // Generate the exe, dmg, deb, rpm packages (nai directory) @@ -118,7 +137,7 @@ private void generateCompilerArtifacts() throws ConverterException { final File desktopZip = new File(rootTargetDirectory, "com.adobe.air.compiler.adt.".replace(".", File.separator) + airSdkVersion + File.separator + "adt-" + airSdkVersion + "-desktop.zip"); - generateCompilerPlatformArtifact(desktopDir, desktopZip); + generateZip(desktopDir, desktopZip); } // Generate the windows packages (win directory) @@ -127,7 +146,7 @@ private void generateCompilerArtifacts() throws ConverterException { final File windowsZip = new File(rootTargetDirectory, "com.adobe.air.compiler.adt.".replace(".", File.separator) + airSdkVersion + File.separator + "adt-" + airSdkVersion + "-win.zip"); - generateCompilerPlatformArtifact(windowsDir, windowsZip); + generateZip(windowsDir, windowsZip); } // Write this artifact to file. @@ -279,12 +298,17 @@ private void generateMiscArtifact() throws ConverterException { // /////////////////////////////////////////////////////////////////////////////////////////////////// - private void generateCompilerPlatformArtifact(File inputDir, File outputFile) throws ConverterException { + private void generateZip(File inputDir, File outputFile) throws ConverterException { + generateZip(inputDir, outputFile, null); + } + + private void generateZip(File inputDir, File outputFile, FilenameFilter filter) + throws ConverterException { try { // Add all the content to a zip-file. final ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(outputFile)); // Package all the compiler parts. - File[] zipfiles = inputDir.listFiles(); + File[] zipfiles = (filter != null) ? inputDir.listFiles(filter) : inputDir.listFiles(); if(zipfiles != null) { for (final File file : zipfiles) { addFileToZip(zipOutputStream, file, rootSourceDirectory); @@ -436,7 +460,7 @@ public boolean accept(File pathname) { result = !(pathname.getName().endsWith(".swc") || pathname.getName().endsWith(".swf")); } - System.out.println(relativePath + " = " + result); + LOG.debug(relativePath + " = " + result); return result; } } diff --git a/flex-maven-tools/flex-sdk-converter/converters/base/pom.xml b/flex-maven-tools/flex-sdk-converter/converters/base/pom.xml index 71d9a925..fcc4881b 100644 --- a/flex-maven-tools/flex-sdk-converter/converters/base/pom.xml +++ b/flex-maven-tools/flex-sdk-converter/converters/base/pom.xml @@ -47,6 +47,22 @@ freemarker 2.3.22 + + + org.slf4j + slf4j-api + 1.7.21 + + + ch.qos.logback + logback-classic + 1.1.7 + + + ch.qos.logback + logback-core + 1.1.7 + diff --git a/flex-maven-tools/flex-sdk-converter/converters/base/src/main/java/org/apache/flex/utilities/converter/BaseConverter.java b/flex-maven-tools/flex-sdk-converter/converters/base/src/main/java/org/apache/flex/utilities/converter/BaseConverter.java index d80cf8f2..f74257e5 100644 --- a/flex-maven-tools/flex-sdk-converter/converters/base/src/main/java/org/apache/flex/utilities/converter/BaseConverter.java +++ b/flex-maven-tools/flex-sdk-converter/converters/base/src/main/java/org/apache/flex/utilities/converter/BaseConverter.java @@ -26,6 +26,8 @@ import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONTokener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.SAXException; @@ -50,6 +52,8 @@ */ public abstract class BaseConverter { + private static final Logger LOG = LoggerFactory.getLogger(BaseConverter.class); + protected final Map checksums = new HashMap(); protected static final String MAVEN_CENTRAL_SHA_1_QUERY_URL = "http://search.maven.org/solrsearch/select?rows=20&wt=json&q=1:"; @@ -210,7 +214,7 @@ protected MavenArtifact lookupMetadataForChecksum(String checksum) throws Conver return artifactMetadata; } else { - System.out.println("For jar-file with checksum: " + checksum + + LOG.warn("For jar-file with checksum: " + checksum + " more than one result was returned by query: " + MAVEN_CENTRAL_SHA_1_QUERY_URL + checksum); } @@ -319,7 +323,7 @@ protected MavenArtifact resolveArtifact(File sourceFile, String defaultGroupId, // Reusing artifact from other sdk version. if(artifact != null) { - System.out.println("Reusing artifact (" + checksum + ") : " + artifact.getGroupId() + ":" + + LOG.info("Reusing artifact (" + checksum + ") : " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion()); return artifact; } @@ -330,7 +334,7 @@ protected MavenArtifact resolveArtifact(File sourceFile, String defaultGroupId, // The file was available on maven central, so use that version instead of the one coming with the sdk. if(artifact != null) { - System.out.println("Using artifact from Maven Central (" + checksum + ") : " + + LOG.info("Using artifact from Maven Central (" + checksum + ") : " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion()); } // The file was not available on maven central, so we have to add it manually. diff --git a/flex-maven-tools/flex-sdk-converter/converters/base/src/main/resources/logback.xml b/flex-maven-tools/flex-sdk-converter/converters/base/src/main/resources/logback.xml new file mode 100644 index 00000000..f58d9671 --- /dev/null +++ b/flex-maven-tools/flex-sdk-converter/converters/base/src/main/resources/logback.xml @@ -0,0 +1,16 @@ + + + + + + + %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + \ No newline at end of file diff --git a/flex-maven-tools/flex-sdk-converter/deployers/aether/src/main/java/org/apache/flex/utilities/converter/deployer/aether/AetherDeployer.java b/flex-maven-tools/flex-sdk-converter/deployers/aether/src/main/java/org/apache/flex/utilities/converter/deployer/aether/AetherDeployer.java index 89b991b5..68b7cfcb 100644 --- a/flex-maven-tools/flex-sdk-converter/deployers/aether/src/main/java/org/apache/flex/utilities/converter/deployer/aether/AetherDeployer.java +++ b/flex-maven-tools/flex-sdk-converter/deployers/aether/src/main/java/org/apache/flex/utilities/converter/deployer/aether/AetherDeployer.java @@ -45,6 +45,8 @@ import org.eclipse.aether.transport.http.HttpTransporterFactory; import org.eclipse.aether.transport.wagon.WagonTransporterFactory; import org.eclipse.aether.util.repository.AuthenticationBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.FileReader; @@ -62,6 +64,8 @@ */ public class AetherDeployer { + private static final Logger LOG = LoggerFactory.getLogger(AetherDeployer.class); + private File directory; private String url; private String username; @@ -94,13 +98,13 @@ public static void main(String[] args) { } private static void printUsage() { - System.out.println("\nUsage: java -cp flex-sdk-converter-1.0.jar SDKInVMDeployer \"directory\" \"url\" [\"username\", \"password\"]\n"); - System.out.println("The SDKDeployer needs at least 2 ordered parameters separated by spaces:"); - System.out.println("\t1- directory: The path to the directory containing the artifacts that should be deployed."); - System.out.println("\t2- url: URL where the artifacts will be deployed."); - System.out.println("If the targeted repository requires authentication two more parameters have to be provided:"); - System.out.println("\t3- username: The username used to authenticate on the target repository."); - System.out.println("\t4- password: The password used to authenticate on the target repository."); + LOG.error("\nUsage: java -cp flex-sdk-converter-1.0.jar SDKInVMDeployer \"directory\" \"url\" [\"username\", \"password\"]\n" + + "The SDKDeployer needs at least 2 ordered parameters separated by spaces:\n" + + "\t1- directory: The path to the directory containing the artifacts that should be deployed.\b" + + "\t2- url: URL where the artifacts will be deployed.\n" + + "If the targeted repository requires authentication two more parameters have to be provided:\n" + + "\t3- username: The username used to authenticate on the target repository.\n" + + "\t4- password: The password used to authenticate on the target repository."); } public void deploy() { @@ -120,7 +124,7 @@ public void deploy() { final RepositorySystem repositorySystem = locator.getService(RepositorySystem.class); if (repositorySystem == null) { - System.out.println("Couldn't initialize local maven repository system."); + LOG.error("Couldn't initialize local maven repository system."); System.exit(0); } else { // Setup the repository system session based upon the current maven settings.xml. @@ -141,7 +145,7 @@ public void deploy() { processDir(rootDir, repositorySystem, session, remoteRepository); } } catch (Throwable e) { - e.printStackTrace(); + LOG.error("Error deploying artifacts in directory: " + directory.getAbsolutePath(), e); } } @@ -214,10 +218,10 @@ private void processArtifact(File pomFile, RepositorySystem repositorySystem, Re } // Actually install the artifact. - System.out.println("Installing Artifact: " + pomArtifact.getGroupId() + ":" + + LOG.info("Installing Artifact: " + pomArtifact.getGroupId() + ":" + pomArtifact.getArtifactId() + ":" + pomArtifact.getVersion()); for (final Artifact artifact : artifactInstallRequest.getArtifacts()) { - System.out.println(" - File with extension " + artifact.getExtension() + + LOG.info(" - File with extension " + artifact.getExtension() + ((artifact.getClassifier().length() > 0) ? " and classifier " + artifact.getClassifier() : "")); }