private void buildCplContext() throws XmlParsingException, FileNotFoundException { logger.debug("Building CPL contexts..."); File assetMapFile = new File(inputParameters.getImpDirectoryFile(), CoreConstants.ASSETMAP_FILE); logger.debug("Parsing ASSETMAP.xml ('{}')...", assetMapFile.getAbsolutePath()); this.assetMap = new AssetMapParser().parse(inputParameters.getImpDirectoryFile(), assetMapFile); logger.debug("Parsed ASSETMAP.xml: OK"); logger.debug("Parsing CPL ('{}')...", inputParameters.getCplFile().getAbsolutePath()); this.cplContextBuilder = new CplContextBuilder(contextProvider, assetMap, inputParameters.getCplFile()); cplContextBuilder.build(); logger.debug("Parsed CPL: OK"); logger.debug("Built CPL contexts: OK\n"); }
/** * Gets a full path to CPL file. It can be defined either in config.xml or via command line arguments. * Setting a parameter via command line argument overwrites value from config.xml. * * @return a file defining a full path to CPL or null if it's not specified neither in config.xml nor via command line arguments */ public File getCplFile() { // cmd line argument has first priority String cpl = cmdLineArgs.getCpl() != null ? cmdLineArgs.getCpl() : defaultCpl; if (cpl == null) { return null; } // try if a valid path for CPL is specified. File cplFile = new File(cpl); if (cplFile.isFile()) { return cplFile; } // assume that the CPL is relative to IMP. File impDirectory = getImpDirectoryFile(); if (impDirectory == null) { return cplFile; } return new File(impDirectory, cpl); }
private void buildDynamicContextPreCpl() { logger.debug("Building Dynamic context before parsing CPL..."); // build default dynamic parameters DynamicTemplateParameterContext dynamicContext = contextProvider.getDynamicContext(); dynamicContext.addParameter(DynamicContextParameters.IMP, inputParameters.getImpDirectoryFile().getAbsolutePath()); dynamicContext.addParameter(DynamicContextParameters.CPL, inputParameters.getCplFile().getAbsolutePath()); dynamicContext.addParameter(DynamicContextParameters.VALIDATION_TOOL, inputParameters.getImfValidationTool()); // build format-specific dynamic parameters doBuildDynamicContextPreCpl(); logger.debug("Built Dynamic context before parsing CPL: OK\n"); }
/** * Checks whether all input parameters needed for conversion are specified (such as CPL, IMP) are specified. * These parameters can be set either via command line arguments or in config.xml. So, the method must be called * after config.xml is processed. * * @param inputParameters the input to be validated * @throws ArgumentValidationException if some of the required command lines arguments are missing. */ public static void validateInputParameters(ImfUtilityInputParameters inputParameters) throws ArgumentValidationException { File impDirectory = inputParameters.getImpDirectoryFile(); if (impDirectory == null) { throw new ArgumentValidationException("IMP directory must be specified either as a command line argument or in config.xml"); } if (!impDirectory.isDirectory()) { throw new ArgumentValidationException(String.format( "IMP directory '%s' must be an existing folder", impDirectory.getAbsolutePath())); } File cplFile = inputParameters.getCplFile(); if (cplFile == null) { throw new ArgumentValidationException("CPL file must be specified either as a command line argument or in config.xml"); } if (!cplFile.isFile()) { throw new ArgumentValidationException(String.format( "CPL file '%s' must be an existing file", cplFile.getAbsolutePath())); } File workingDir = inputParameters.getWorkingDirFile(); if (workingDir == null) { throw new ArgumentValidationException("Working directory must be specified either as a command line argument or in config.xml"); } }
@Test public void testDefaultImpFolder() throws Exception { String[] args = new String[]{}; ImfUtilityInputParameters inputParameters = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, args), new FakeDefaultTools()); inputParameters.setDefaultImp("defaultImp"); assertEquals(new File("defaultImp"), inputParameters.getImpDirectoryFile()); }
@Test public void testCmdLineImpReplacesDefault() throws Exception { String[] args = new String[]{ "--imp", ImpUtils.getImpFolder().getAbsolutePath() }; ImfUtilityInputParameters inputParameters = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, args), new FakeDefaultTools()); inputParameters.setDefaultImp("defaultImp"); assertEquals(ImpUtils.getImpFolder(), inputParameters.getImpDirectoryFile()); }
@Test public void testImpFolder() throws Exception { String[] argsImp = new String[]{ "--imp", ImpUtils.getImpFolder().getAbsolutePath() }; String[] argsNoImp = new String[]{}; ImfUtilityInputParameters inputParametersImp = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, argsImp), new FakeDefaultTools()); ImfUtilityInputParameters inputParametersNoImp = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, argsNoImp), new FakeDefaultTools()); assertEquals(ImpUtils.getImpFolder(), inputParametersImp.getImpDirectoryFile()); assertNull(inputParametersNoImp.getImpDirectoryFile()); }