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"); }
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 testDefaultCpl() throws Exception { String[] args = new String[]{}; ImfUtilityInputParameters inputParameters = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, args), new FakeDefaultTools()); inputParameters.setDefaultImp("defaultImp"); inputParameters.setDefaultCpl("defaultCpl"); assertEquals(new File("defaultImp", "defaultCpl"), inputParameters.getCplFile()); }
@Test public void testCmdLineCplReplacesDefault() throws Exception { String[] args = new String[]{ "--cpl", ImpUtils.getCorrectCpl().getName(), "--imp", ImpUtils.getImpFolder().getAbsolutePath() }; ImfUtilityInputParameters inputParameters = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, args), new FakeDefaultTools()); inputParameters.setDefaultCpl("defaultCpl"); assertEquals(ImpUtils.getCorrectCpl(), inputParameters.getCplFile()); }
@Test public void testCpl() throws Exception { String[] argsCplImp = new String[]{ "--cpl", ImpUtils.getCorrectCpl().getName(), "--imp", ImpUtils.getImpFolder().getAbsolutePath() }; String[] argsCplNoImp = new String[]{ "--cpl", ImpUtils.getCorrectCpl().getName() }; String[] argsNoCplNoImp = new String[]{ }; ImfUtilityInputParameters inputParametersCplImp = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, argsCplImp), new FakeDefaultTools()); ImfUtilityInputParameters inputParametersCplNoImp = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, argsCplNoImp), new FakeDefaultTools()); ImfUtilityInputParameters inputParametersNoCplNoImp = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, argsNoCplNoImp), new FakeDefaultTools()); assertEquals(ImpUtils.getCorrectCpl(), inputParametersCplImp.getCplFile()); assertEquals(new File(ImpUtils.getCorrectCpl().getName()), inputParametersCplNoImp.getCplFile()); assertNull(inputParametersNoCplNoImp.getCplFile()); }