private void initVelocityContext() throws Exception { VelocityContext velocityContext = metadataResourceEngine.getVelocityContext(); velocityContext.put("system", System.getProperties()); velocityContext.put("softwareName", "BEAM gpt"); velocityContext.put("softwareVersion", System.getProperty("beam.version", "")); velocityContext.put("commandLineArgs", commandLineArgs); // Derived properties (shortcuts). // Check if we really want them, if so, we have to maintain them in the future (nf) File targetFile = new File(commandLineArgs.getTargetFilePath()); File parentFile = targetFile.getParentFile(); velocityContext.put("targetFile", targetFile); velocityContext.put("targetDir", parentFile != null ? parentFile : new File(".")); velocityContext.put("targetBaseName", FileUtils.getFilenameWithoutExtension(targetFile)); velocityContext.put("targetName", targetFile.getName()); velocityContext.put("targetFormat", commandLineArgs.getTargetFormatName()); // Check if we also put the following into the context? // Actually no, because this puts the ontext in an unknown state, because we don't know which are the key's names (nf) //velocityContext.putAll(commandLineArgs.getParameterMap()); //velocityContext.putAll(commandLineArgs.getTargetFilePathMap()); //velocityContext.putAll(commandLineArgs.getSourceFilePathMap()); }
@Test public void testTargetOptions() throws Exception { CommandLineArgs lineArgs = parseArgs("./map-proj.xml", "-Tndvi=./out/ndviProduct.dim", "-Tsnow=./out/snowMask.dim", "source.dim"); SortedMap<String, String> targetMap = lineArgs.getTargetFilePathMap(); assertNotNull(targetMap); assertEquals(2, targetMap.size()); assertEquals("./out/ndviProduct.dim", targetMap.get("ndvi")); assertEquals("./out/snowMask.dim", targetMap.get("snow")); assertEquals(null, lineArgs.getTargetFilePath()); SortedMap<String, String> sourceMap = lineArgs.getSourceFilePathMap(); assertEquals(3, sourceMap.size()); assertEquals("source.dim", sourceMap.get("sourceProduct")); assertEquals("source.dim", sourceMap.get("sourceProduct.1")); assertEquals("source.dim", sourceMap.get("sourceProduct1")); // test for backward compatibility }
if (!commandLineContext.isFile(commandLineArgs.getTargetFilePath())) { if (velocityDirPathGiven) { String msgPattern = "Target file '%s' does not exist, but is required to process velocity templates"; logger.warning(String.format(msgPattern, commandLineArgs.getTargetFilePath())); logger.info(String.format(msgPattern, commandLineArgs.getTargetFilePath())); commandLineArgs.getTargetFilePath()); } catch (IOException e) { String msgPattern = "Can't write related resource using template file '%s': %s";
} else { String filePath = commandLineArgs.getTargetFilePath(); String formatName = commandLineArgs.getTargetFormatName(); writeProduct(targetProduct, filePath, formatName, commandLineArgs.isClearCacheAfterRowWrite());
@Test public void testOpWithSource() throws Exception { CommandLineArgs lineArgs = parseArgs("Reproject", "source.dim"); assertEquals("Reproject", lineArgs.getOperatorName()); assertEquals(null, lineArgs.getGraphFilePath()); assertEquals(CommandLineArgs.DEFAULT_TARGET_FILEPATH, lineArgs.getTargetFilePath()); assertEquals(CommandLineArgs.DEFAULT_FORMAT_NAME, lineArgs.getTargetFormatName()); SortedMap<String, String> sourceMap = lineArgs.getSourceFilePathMap(); assertNotNull(sourceMap); assertEquals(3, sourceMap.size()); assertEquals("source.dim", sourceMap.get("sourceProduct")); assertEquals("source.dim", sourceMap.get("sourceProduct.1")); assertEquals("source.dim", sourceMap.get("sourceProduct1")); // test for backward compatibility }
configuration.createChild("file").setValue(commandLineArgs.getTargetFilePath()); configuration.createChild("formatName").setValue(commandLineArgs.getTargetFormatName()); configuration.createChild("clearCacheAfterRowWrite").setValue(
@Test public void testOpWithTargetAndSource() throws Exception { CommandLineArgs lineArgs = parseArgs("Reproject", "-t", "output.dim", "source.dim"); assertEquals("Reproject", lineArgs.getOperatorName()); assertEquals(null, lineArgs.getGraphFilePath()); assertEquals("output.dim", lineArgs.getTargetFilePath()); assertEquals(CommandLineArgs.DEFAULT_FORMAT_NAME, lineArgs.getTargetFormatName()); SortedMap<String, String> sourceMap = lineArgs.getSourceFilePathMap(); assertNotNull(sourceMap); assertEquals(3, sourceMap.size()); assertEquals("source.dim", sourceMap.get("sourceProduct")); assertEquals("source.dim", sourceMap.get("sourceProduct.1")); assertEquals("source.dim", sourceMap.get("sourceProduct1")); // test for backward compatibility }
@Test public void testMinimumGraph() throws Exception { CommandLineArgs lineArgs = parseArgs("./map-proj.xml", "source.dim"); assertEquals(null, lineArgs.getOperatorName()); assertEquals("./map-proj.xml", lineArgs.getGraphFilePath()); assertEquals(CommandLineArgs.DEFAULT_TARGET_FILEPATH, lineArgs.getTargetFilePath()); assertEquals(CommandLineArgs.DEFAULT_FORMAT_NAME, lineArgs.getTargetFormatName()); SortedMap<String, String> map = lineArgs.getSourceFilePathMap(); assertNotNull(map); assertEquals("source.dim", map.get("sourceProduct")); assertEquals("source.dim", map.get("sourceProduct.1")); assertEquals("source.dim", map.get("sourceProduct1")); // test for backward compatibility }
@Test public void testOpOnly() throws Exception { CommandLineArgs lineArgs = parseArgs("Reproject"); assertEquals(false, lineArgs.isHelpRequested()); assertEquals("Reproject", lineArgs.getOperatorName()); assertEquals(null, lineArgs.getGraphFilePath()); assertEquals(CommandLineArgs.DEFAULT_TARGET_FILEPATH, lineArgs.getTargetFilePath()); assertEquals(CommandLineArgs.DEFAULT_FORMAT_NAME, lineArgs.getTargetFormatName()); SortedMap<String, String> map = lineArgs.getSourceFilePathMap(); assertNotNull(map); assertEquals(0, map.size()); }
@Test public void testHelpOption() throws Exception { CommandLineArgs lineArgs = parseArgs("Reproject", "-h"); assertEquals(true, lineArgs.isHelpRequested()); assertEquals("Reproject", lineArgs.getOperatorName()); assertEquals(null, lineArgs.getGraphFilePath()); assertEquals(CommandLineArgs.DEFAULT_TARGET_FILEPATH, lineArgs.getTargetFilePath()); assertEquals(CommandLineArgs.DEFAULT_FORMAT_NAME, lineArgs.getTargetFormatName()); SortedMap<String, String> map = lineArgs.getSourceFilePathMap(); assertNotNull(map); assertEquals(0, map.size()); }
@Test public void testGraphOnly() throws Exception { CommandLineArgs lineArgs = parseArgs("./map-proj.xml"); assertEquals(null, lineArgs.getOperatorName()); assertEquals("./map-proj.xml", lineArgs.getGraphFilePath()); assertEquals(CommandLineArgs.DEFAULT_TARGET_FILEPATH, lineArgs.getTargetFilePath()); assertEquals(CommandLineArgs.DEFAULT_FORMAT_NAME, lineArgs.getTargetFormatName()); SortedMap<String, String> map = lineArgs.getSourceFilePathMap(); assertNotNull(map); }