- Added some more validation code - Hardened the converters not to cause fatal exceptions if optional FDK parts are missing.
Project: http://git-wip-us.apache.org/repos/asf/flex-utilities/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-utilities/commit/55f0ba19 Tree: http://git-wip-us.apache.org/repos/asf/flex-utilities/tree/55f0ba19 Diff: http://git-wip-us.apache.org/repos/asf/flex-utilities/diff/55f0ba19 Branch: refs/heads/as3httpclient-work Commit: 55f0ba191144b2d31f4c1a7a20dfefb2fcb46bec Parents: 07c77ee Author: Christofer Dutz <christofer.d...@codecentric.de> Authored: Fri Apr 10 12:08:07 2015 +0200 Committer: Christofer Dutz <christofer.d...@codecentric.de> Committed: Fri Apr 10 12:08:07 2015 +0200 ---------------------------------------------------------------------- .../converter/core/SdkConverterCLI.java | 152 +++++++++++++------ .../utilities/converter/air/AirConverter.java | 11 +- .../converter/flash/FlashConverter.java | 9 +- .../utilities/converter/flex/FlexConverter.java | 11 +- .../retrievers/download/DownloadRetriever.java | 1 - 5 files changed, 130 insertions(+), 54 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/55f0ba19/mavenizer/cli/src/main/java/org/apache/flex/utilities/converter/core/SdkConverterCLI.java ---------------------------------------------------------------------- diff --git a/mavenizer/cli/src/main/java/org/apache/flex/utilities/converter/core/SdkConverterCLI.java b/mavenizer/cli/src/main/java/org/apache/flex/utilities/converter/core/SdkConverterCLI.java index 32cb60d..0f088e6 100644 --- a/mavenizer/cli/src/main/java/org/apache/flex/utilities/converter/core/SdkConverterCLI.java +++ b/mavenizer/cli/src/main/java/org/apache/flex/utilities/converter/core/SdkConverterCLI.java @@ -22,31 +22,51 @@ import java.util.*; */ public class SdkConverterCLI { + public static final String COMMAND_LIST = "list"; + public static final String COMMAND_DOWNLOAD = "download"; + public static final String COMMAND_CONVERT = "convert"; + public static final String COMMAND_DEPLOY = "deploy"; + + public static final String OPTION_FLEX_VERSION = "flexVersion"; + public static final String OPTION_FLASH_VERSIONS = "flashVersions"; + public static final String OPTION_AIT_VERSION = "airVersion"; + public static final String OPTION_FONTKIT = "fontkit"; + public static final String OPTION_PLATFORMS = "platforms"; + + public static final String OPTION_FDK_DIR = "fdkDir"; + public static final String OPTION_MAVEN_DIR = "mavenDir"; + + public static final String OPTION_REPO_URL = "repoUrl"; + public static final String OPTION_REPO_USERNAME = "repoUsername"; + public static final String OPTION_REPO_PASSWORD = "repoPassword"; + + + @SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("version").hasArg(). withDescription("(Optional and Only valid for download) Version of the " + "FDK which should be downloaded."). isRequired(false). - create("flexVersion")); + create(OPTION_FLEX_VERSION)); options.addOption(OptionBuilder.withArgName("version(s)").hasArg(). withValueSeparator(','). withDescription("(Optional and Only valid for download) Version(s) of the " + "Adobe Flash SDK which should be downloaded. Multiple versions can " + "be separated by \",\"."). isRequired(false). - create("flashVersion")); + create(OPTION_FLASH_VERSIONS)); options.addOption(OptionBuilder.withArgName("version").hasArg(). withDescription("(Optional and Only valid for download) Version of the " + "Adobe Air SDK which should be downloaded."). isRequired(false). - create("airVersion")); + create(OPTION_AIT_VERSION)); options.addOption(OptionBuilder. withDescription("(Optional and Only valid for download) If provided, the " + "Converter will also download the Fontkit libraries needed for font " + "encoding."). isRequired(false). - create("fontkit")); + create(OPTION_FONTKIT)); options.addOption(OptionBuilder.withArgName("platform(s)").hasArg(). withValueSeparator(','). withDescription("(Optional and Only valid for download) Platform the artifacts " + @@ -54,34 +74,34 @@ public class SdkConverterCLI { "on will be used. Valid options are: \"WINDOWS\", \"MAC\" and \"LNX\". " + "Multiple versions can be separated by \",\"."). isRequired(false). - create("platform")); + create(OPTION_PLATFORMS)); options.addOption(OptionBuilder.withArgName("dir").hasArg(). - withDescription("(Optional) Directory that the mavenized artifacts will be located in. " + + withDescription("(Optional) Directory that the FDK will be located in. " + "If omitted, a temporary directory will be used."). isRequired(false). - create("mavenDir")); + create(OPTION_FDK_DIR)); options.addOption(OptionBuilder.withArgName("dir").hasArg(). - withDescription("(Optional) Directory that the FDK will be located in. " + + withDescription("(Optional) Directory that the mavenized artifacts will be located in. " + "If omitted, a temporary directory will be used."). isRequired(false). - create("fdkDir")); + create(OPTION_MAVEN_DIR)); options.addOption(OptionBuilder.withArgName("url").hasArg(). withDescription("(Optional and only valid for deploy) Url of the remote Maven " + "repository that the generated Maven artifacts should be deployed to."). isRequired(false). - create("repoUrl")); + create(OPTION_REPO_URL)); options.addOption(OptionBuilder.withArgName("username").hasArg(). withDescription("(Optional and only valid for deploy) Username used to authenticate " + "on the remote Maven repository that the generated Maven artifacts should be " + "deployed to."). isRequired(false). - create("repoUsername")); + create(OPTION_REPO_USERNAME)); options.addOption(OptionBuilder.withArgName("password").hasArg(). withDescription("(Optional and only valid for deploy) Password used to authenticate " + "on the remote Maven repository that the generated Maven artifacts should be " + "deployed to."). isRequired(false). - create("repoPassword")); + create(OPTION_REPO_PASSWORD)); CommandLineParser parser = new BasicParser(); try { @@ -92,7 +112,7 @@ public class SdkConverterCLI { // Find out the desired platform(s). List<PlatformType> platforms = new ArrayList<PlatformType>(); - String platformParam = cmd.getOptionValue("platform"); + String platformParam = cmd.getOptionValue(OPTION_PLATFORMS); if((platformParam != null) && !platformParam.isEmpty()) { String[] platformNames = platformParam.split(","); for(String platformName : platformNames) { @@ -112,13 +132,59 @@ public class SdkConverterCLI { } } + ///////////////////////////////////////////////////////// + // Validate sensible combinations of commands. + ///////////////////////////////////////////////////////// + + // Check that all commands are valid. + for(String command : (List<String>) cmd.getArgList()) { + if(!COMMAND_LIST.equals(command) && !COMMAND_DOWNLOAD.equals(command) && + !COMMAND_CONVERT.equals(command) && !COMMAND_DEPLOY.equals(command)) { + System.err.println("Unsupported command '" + command + "'."); + System.exit(1); + } + } + + // Downloading and deploying without converting doesn't make sense. + if(cmd.getArgList().contains(COMMAND_DOWNLOAD) && !cmd.getArgList().contains(COMMAND_CONVERT) && + cmd.getArgList().contains(COMMAND_DEPLOY)) { + System.err.println("Downloading and deploying without conversion doesn't make much sense."); + System.exit(1); + } + + // If Downloading and not converting, the fdkDir parameter has to be provided as + // otherwise the download result would reside in some strange temp directory. + if(cmd.getArgList().contains(COMMAND_DOWNLOAD) && !cmd.getArgList().contains(COMMAND_CONVERT) + && !cmd.hasOption(OPTION_FDK_DIR)) { + System.err.println("Parameter 'fdkDir' required for task 'download' without conversion."); + System.exit(1); + } + + // If Converting and not deploying, the mavenDir parameter has to be provided as + // otherwise the converted FDK would reside in some strange temp directory. + if(cmd.getArgList().contains(COMMAND_CONVERT) && !cmd.getArgList().contains(COMMAND_DEPLOY) + && !cmd.hasOption(OPTION_MAVEN_DIR)) { + System.err.println("Parameter 'mavenDir' required for task 'convert' without deployment."); + System.exit(1); + } + + // Downloading nothing doesn't really make sense. On the bad side it even causes + // problems with the converter without any fdkDir parameter, therefore we abort here. + if(cmd.getArgList().contains(COMMAND_DOWNLOAD) && !cmd.hasOption(OPTION_FLEX_VERSION) && + !cmd.hasOption(OPTION_FLASH_VERSIONS) && !cmd.hasOption(OPTION_AIT_VERSION) && + !cmd.hasOption(OPTION_FONTKIT)) { + System.err.println("At least one of the parameters 'flexVersion', 'flashVersions', 'airVersion' or " + + "'fontkit' required for task 'download'."); + System.exit(1); + } + // Find out where to download or convert from. - File fdkDir = cmd.hasOption("fdkDir") ? - new File(cmd.getOptionValue("fdkDir")) : getTempDir("FLEX-DOWNLOAD"); + File fdkDir = cmd.hasOption(OPTION_FDK_DIR) ? + new File(cmd.getOptionValue(OPTION_FDK_DIR)) : getTempDir("FLEX-DOWNLOAD-"); // Find out where to convert to or deploy from. - File mavenDir = cmd.hasOption("mavenDir") ? - new File(cmd.getOptionValue("mavenDir")) : getTempDir("FLEX-MAVEN"); + File mavenDir = cmd.hasOption(OPTION_MAVEN_DIR) ? + new File(cmd.getOptionValue(OPTION_MAVEN_DIR)) : getTempDir("FLEX-MAVEN-"); //////////////////////////////////////////////////////////////////////////// // Exectute operations @@ -130,7 +196,7 @@ public class SdkConverterCLI { } // Output a list of all available downloads. - if(cmd.getArgList().contains("list")) { + if(cmd.getArgList().contains(COMMAND_LIST)) { System.out.println("-----------------------------------------------"); System.out.println("- Available downloads"); System.out.println("-----------------------------------------------"); @@ -176,14 +242,14 @@ public class SdkConverterCLI { } // Handle the downloading of atifacts. - if(cmd.getArgList().contains("download")) { + if(cmd.getArgList().contains(COMMAND_DOWNLOAD)) { System.out.println("-----------------------------------------------"); System.out.println("- Downloading"); System.out.println("-----------------------------------------------"); DownloadRetriever retriever = new DownloadRetriever(); - String flexVersion = cmd.getOptionValue("flexVersion", null); + String flexVersion = cmd.getOptionValue(OPTION_FLEX_VERSION, null); if(flexVersion != null) { System.out.println("- Downloading Flex SDK version: " + flexVersion + " to directory: " + fdkDir.getAbsolutePath()); @@ -192,7 +258,7 @@ public class SdkConverterCLI { mergeDirectories(fdkDownloadDirectory, fdkDir); } - String flashVersions = cmd.getOptionValue("flashVersion", ""); + String flashVersions = cmd.getOptionValue(OPTION_FLASH_VERSIONS, ""); if(!flashVersions.isEmpty()) { for(String flashVersion : flashVersions.split(",")) { System.out.println("- Downloading Flash SDK version: " + flashVersion + @@ -203,21 +269,19 @@ public class SdkConverterCLI { } } - String airVersions = cmd.getOptionValue("airVersion", ""); - if(!airVersions.isEmpty()) { - for(String airVersion : airVersions.split(",")) { - for(PlatformType platformType : platforms) { - System.out.println("- Downloading Air SDK version: " + airVersion + - " and platform " + platformType.name() + - " to directory: " + fdkDir.getAbsolutePath()); - File airDownloadDirectory = retriever.retrieve(SdkType.AIR, airVersion, platformType); - // Integrate the download into the FDK directory. - mergeDirectories(airDownloadDirectory, fdkDir); - } + String airVersion = cmd.getOptionValue(OPTION_AIT_VERSION, ""); + if(!airVersion.isEmpty()) { + for(PlatformType platformType : platforms) { + System.out.println("- Downloading Air SDK version: " + airVersion + + " and platform " + platformType.name() + + " to directory: " + fdkDir.getAbsolutePath()); + File airDownloadDirectory = retriever.retrieve(SdkType.AIR, airVersion, platformType); + // Integrate the download into the FDK directory. + mergeDirectories(airDownloadDirectory, fdkDir); } } - if(cmd.hasOption("fontkit")) { + if(cmd.hasOption(OPTION_FONTKIT)) { System.out.println("- Downloading Flex Fontkit libraries" + " to directory: " + fdkDir.getAbsolutePath()); File fontkitDownloadDirectory = retriever.retrieve(SdkType.FONTKIT); @@ -229,7 +293,7 @@ public class SdkConverterCLI { } // Handle the conversion. - if(cmd.getArgList().contains("convert")) { + if(cmd.getArgList().contains(COMMAND_CONVERT)) { System.out.println("-----------------------------------------------"); System.out.println("- Conversion"); System.out.println("-----------------------------------------------"); @@ -244,7 +308,7 @@ public class SdkConverterCLI { FlashConverter flashConverter = new FlashConverter(fdkDir, mavenDir); flashConverter.convert(); - System.out.println("- Converting Air SDKs from " + fdkDir.getAbsolutePath() + + System.out.println("- Converting Air SDK from " + fdkDir.getAbsolutePath() + " to " + mavenDir.getAbsolutePath()); AirConverter airConverter = new AirConverter(fdkDir, mavenDir); airConverter.convert(); @@ -258,19 +322,19 @@ public class SdkConverterCLI { } // Handle the deployment. - if(cmd.getArgList().contains("deploy")) { + if(cmd.getArgList().contains(COMMAND_DEPLOY)) { System.out.println("-----------------------------------------------"); System.out.println("- Deployment"); System.out.println("-----------------------------------------------"); - if(!cmd.hasOption("repoUrl")) { + if(!cmd.hasOption(OPTION_REPO_URL)) { System.err.println("Parameter 'repoUrl' required for task 'deploy'."); System.exit(1); } - String repoUrl = cmd.getOptionValue("repoUrl"); - String repoUsername = cmd.getOptionValue("repoUsername", null); - String repoPassword = cmd.getOptionValue("repoPassword", null); + String repoUrl = cmd.getOptionValue(OPTION_REPO_URL); + String repoUsername = cmd.getOptionValue(OPTION_REPO_USERNAME, null); + String repoPassword = cmd.getOptionValue(OPTION_REPO_PASSWORD, null); System.out.println("- Deploying libraries to " + repoUrl + " from " + mavenDir.getAbsolutePath()); @@ -292,8 +356,8 @@ public class SdkConverterCLI { "directories in your systems temp directory and uses these for the follwoing commands.\n" + " - list:\nList all available versions and platforms (for download)\n" + " - download:\nDownload the selected versions of FDK parts specified by 'flexVersion', " + - "'flashVersion', 'airVersion' and 'fontkit' and creates an FDK in the directory specified by " + - "'fdkDir'. If 'airVersion' is specified, the 'platform' parameter specifies the platforms for which " + + "'flashVersions', 'airVersion' and 'fontkit' and creates an FDK in the directory specified by " + + "'fdkDir'. If 'airVersion' is specified, the 'platforms' parameter specifies the platforms for which " + "the given AIR SDK should be downloaded, if not specified the current systems platform is used. \n" + " - convert:\nConvert the FDK located in 'fdkDir' into a mavenized form at 'mavenDir'.\n" + " - deploy:\nDeploy the maven artifacts located in 'mavenDir', to the remote maven repository " + @@ -303,8 +367,8 @@ public class SdkConverterCLI { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("java -jar apache-flex-sdk-converter.jar [list] [-fdkDir <fdkDir>] " + - "[-mavenDir <mavenDir>] [[-flexVersion <version>] [-flashVersion <version(s)>] " + - "[-airVersion <version> [-platform <platform(s)>]] [-fontkit] download] [convert] " + + "[-mavenDir <mavenDir>] [[-flexVersion <version>] [-flashVersions <version(s)>] " + + "[-airVersion <version> [-platforms <platform(s)>]] [-fontkit] download] [convert] " + "[-repoUrl <url> [-repoUsername <username> -repoPassword <password>] deploy]", headerText, options, ""); } http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/55f0ba19/mavenizer/converters/air/src/main/java/org/apache/flex/utilities/converter/air/AirConverter.java ---------------------------------------------------------------------- diff --git a/mavenizer/converters/air/src/main/java/org/apache/flex/utilities/converter/air/AirConverter.java b/mavenizer/converters/air/src/main/java/org/apache/flex/utilities/converter/air/AirConverter.java index c655df5..d1dbbfc 100644 --- a/mavenizer/converters/air/src/main/java/org/apache/flex/utilities/converter/air/AirConverter.java +++ b/mavenizer/converters/air/src/main/java/org/apache/flex/utilities/converter/air/AirConverter.java @@ -52,8 +52,9 @@ public class AirConverter extends BaseConverter implements Converter { */ @Override protected void processDirectory() throws ConverterException { - if(!rootSourceDirectory.exists() || !rootSourceDirectory.isDirectory()) { - throw new ConverterException("Air SDK directory '" + rootSourceDirectory.getPath() + "' is invalid."); + if((airSdkVersion == null) || !rootSourceDirectory.exists() || !rootSourceDirectory.isDirectory()) { + System.out.println("Skipping AIR SDK generation."); + return; } generateCompilerArtifacts(); @@ -210,9 +211,11 @@ public class AirConverter extends BaseConverter implements Converter { // stick to that for now. final File sdkDescriptor = new File(rootDirectory, "AIR SDK Readme.txt"); + + // If the descriptor is not present, return null as this FDK directory doesn't + // seem to contain a AIR SDK. if(!sdkDescriptor.exists() || !sdkDescriptor.isFile()) { - throw new ConverterException("Air SDK directory '" + rootDirectory.getPath() + - "' is missing a the version text-file 'AIR SDK Readme.txt'."); + return null; } DataInputStream in = null; http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/55f0ba19/mavenizer/converters/flash/src/main/java/org/apache/flex/utilities/converter/flash/FlashConverter.java ---------------------------------------------------------------------- diff --git a/mavenizer/converters/flash/src/main/java/org/apache/flex/utilities/converter/flash/FlashConverter.java b/mavenizer/converters/flash/src/main/java/org/apache/flex/utilities/converter/flash/FlashConverter.java index 5ce72f6..a2c1831 100644 --- a/mavenizer/converters/flash/src/main/java/org/apache/flex/utilities/converter/flash/FlashConverter.java +++ b/mavenizer/converters/flash/src/main/java/org/apache/flex/utilities/converter/flash/FlashConverter.java @@ -53,7 +53,8 @@ public class FlashConverter extends BaseConverter implements Converter { @Override protected void processDirectory() throws ConverterException { if(!rootSourceDirectory.exists() || !rootSourceDirectory.isDirectory()) { - throw new ConverterException("Flash SDK directory '" + rootSourceDirectory.getPath() + "' is invalid."); + System.out.println("Skipping Flash SDK generation."); + return; } generateRuntimeArtifacts(); @@ -69,7 +70,7 @@ public class FlashConverter extends BaseConverter implements Converter { // Create a list of all libs that should belong to the Flash SDK runtime. final File directory = new File(rootSourceDirectory, "runtimes" + File.separator + "player"); if(!directory.exists() || !directory.isDirectory()) { - System.out.println("Skipping runtime generation."); + System.out.println("Skipping Flash runtime generation."); return; } final List<File> playerVersions = new ArrayList<File>(); @@ -214,8 +215,10 @@ public class FlashConverter extends BaseConverter implements Converter { protected void generateFrameworkArtifacts() throws ConverterException { // Create a list of all libs that should belong to the Flash SDK runtime. final File directory = new File(rootSourceDirectory, "frameworks.libs.player".replace(".", File.separator)); + // It seems the fdk directory doesn't contain any flash resources. if (!directory.exists() || !directory.isDirectory()) { - throw new ConverterException("Runtime directory does not exist."); + System.out.println("Skipping Flash framework generation."); + return; } final List<File> playerVersions = new ArrayList<File>(); final File[] versions = directory.listFiles(); http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/55f0ba19/mavenizer/converters/flex/src/main/java/org/apache/flex/utilities/converter/flex/FlexConverter.java ---------------------------------------------------------------------- diff --git a/mavenizer/converters/flex/src/main/java/org/apache/flex/utilities/converter/flex/FlexConverter.java b/mavenizer/converters/flex/src/main/java/org/apache/flex/utilities/converter/flex/FlexConverter.java index 841aec6..be8c000 100644 --- a/mavenizer/converters/flex/src/main/java/org/apache/flex/utilities/converter/flex/FlexConverter.java +++ b/mavenizer/converters/flex/src/main/java/org/apache/flex/utilities/converter/flex/FlexConverter.java @@ -61,8 +61,9 @@ public class FlexConverter extends BaseConverter implements Converter { */ @Override protected void processDirectory() throws ConverterException { - if(!rootSourceDirectory.exists() || !rootSourceDirectory.isDirectory()) { - throw new ConverterException("Flex SDK directory '" + rootSourceDirectory.getPath() + "' is invalid."); + if((flexSdkVersion == null) || !rootSourceDirectory.exists() || !rootSourceDirectory.isDirectory()) { + System.out.println("Skipping Flex SDK generation."); + return; } generateCompilerArtifacts(); @@ -563,6 +564,12 @@ public class FlexConverter extends BaseConverter implements Converter { protected String getFlexVersion(File rootDirectory) throws ConverterException { final File sdkDescriptor = new File(rootDirectory, "flex-sdk-description.xml"); + // If the descriptor is not present, return null as this FDK directory doesn't + // seem to contain a Flex SDK. + if(!sdkDescriptor.exists()) { + return null; + } + final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { // Parse the document http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/55f0ba19/mavenizer/retrievers/download/src/main/java/org/apache/flex/utilities/converter/retrievers/download/DownloadRetriever.java ---------------------------------------------------------------------- diff --git a/mavenizer/retrievers/download/src/main/java/org/apache/flex/utilities/converter/retrievers/download/DownloadRetriever.java b/mavenizer/retrievers/download/src/main/java/org/apache/flex/utilities/converter/retrievers/download/DownloadRetriever.java index 96e95ff..81c4f75 100644 --- a/mavenizer/retrievers/download/src/main/java/org/apache/flex/utilities/converter/retrievers/download/DownloadRetriever.java +++ b/mavenizer/retrievers/download/src/main/java/org/apache/flex/utilities/converter/retrievers/download/DownloadRetriever.java @@ -31,7 +31,6 @@ import org.apache.http.impl.client.DefaultHttpClient; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.w3c.dom.Document; import org.w3c.dom.Element; -import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException;