本文整理汇总了Java中ca.nrc.cadc.util.ArgumentMap类的典型用法代码示例。如果您正苦于以下问题:Java ArgumentMap类的具体用法?Java ArgumentMap怎么用?Java ArgumentMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ArgumentMap类属于ca.nrc.cadc.util包,在下文中一共展示了ArgumentMap类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initFileLogging
import ca.nrc.cadc.util.ArgumentMap; //导入依赖的package包/类
/**
* Initializes logging to a file.
* @param loggerNames the names of the loggers (usually names of packages
* or classes or ancestors of packages or classes). Can't be null.
* @param argMap command line arguments.
*/
public static synchronized void initFileLogging(String[] loggerNames, ArgumentMap argMap, String filename)
throws IOException
{
Level level = DEFAULT_FILE_LOGGING_LEVEL;
if (argMap.isSet(Argument.LOG_QUIET_SHORT) || argMap.isSet(Argument.LOG_QUIET)) level = Level.ERROR;
if (argMap.isSet(Argument.LOG_VERBOSE_SHORT) || argMap.isSet(Argument.LOG_VERBOSE)) level = Level.INFO;
if (argMap.isSet(Argument.LOG_DEBUG_SHORT) || argMap.isSet(Argument.DEBUG)) level = Level.DEBUG;
FileAppender fileAppender = new FileAppender(new PatternLayout(), filename);
boolean append = true;
Writer fileWriter = new FileWriter(filename, append);
for (String loggerName : loggerNames)
Log4jInit.setLevel(loggerName, level, fileWriter);
}
示例2: doTest
import ca.nrc.cadc.util.ArgumentMap; //导入依赖的package包/类
protected void doTest(String[] args, String outFilename)
throws Exception
{
String userDir = System.getProperty("user.dir");
String[] exec = new String[args.length + 2];
exec[0] = "-d";
exec[1] = "--out="+outFilename;
System.arraycopy(args, 0, exec, 2, args.length);
log.debug("\r\n");
for (int i = 0; i < exec.length; i++)
{
log.debug("arg[" + i + "] = " + exec[i]);
}
ArgumentMap argsMap = new ArgumentMap(exec);
Ingest ingest = Main.createIngest(argsMap);
ingest.run();
}
示例3: testGetFitsMapping
import ca.nrc.cadc.util.ArgumentMap; //导入依赖的package包/类
@Test
public void testGetFitsMapping() throws Exception
{
String[] args = new String[]
{
"--default=src/test/resources/userConfig.default"
};
ArgumentMap argsMap = new ArgumentMap(args);
Map<String,String> config = Util.loadConfig("src/test/resources/userConfig.config");
FitsMapping mapping = Util.getFitsMapping(config, "src/test/resources/userConfig.default", null);
// Mapped in internal config.
String value = mapping.getMapping("Observation.instrument.keywords");
Assert.assertNotNull(value);
Assert.assertEquals("instrumentKeywords", value);
// Mapped in userConfig.
value = mapping.getMapping("Observation.instrument.name");
Assert.assertNotNull(value);
Assert.assertEquals("myUserConfigValue", value);
}
示例4: testNoArguments
import ca.nrc.cadc.util.ArgumentMap; //导入依赖的package包/类
@Test
public void testNoArguments()
{
ArgumentMap argsMap = new ArgumentMap(new String[] {});
try
{
Ingest ing = Main.createIngest(argsMap);
Assert.fail("expected IllegalArgumentException");
}
catch(IllegalArgumentException expected)
{
log.debug("caught expected exception: " + expected);
}
catch(Exception unexpected)
{
log.error("unexpected exception", unexpected);
Assert.fail("unexpected exception: " + unexpected);
}
}
示例5: testArguments
import ca.nrc.cadc.util.ArgumentMap; //导入依赖的package包/类
@Test
public void testArguments()
{
String[] args = new String[ minimalArguments.length + 1];
System.arraycopy(minimalArguments, 0, args, 0, minimalArguments.length);
args[args.length-1] = "--foo";
ArgumentMap argsMap = new ArgumentMap(args);
try
{
Ingest ing = Main.createIngest(argsMap);
}
catch(IllegalArgumentException expected)
{
log.debug("caught expected exception: " + expected);
}
catch(Exception unexpected)
{
log.error("unexpected exception", unexpected);
Assert.fail("unexpected exception: " + unexpected);
}
}
示例6: testInvalidArguments
import ca.nrc.cadc.util.ArgumentMap; //导入依赖的package包/类
@Test
public void testInvalidArguments()
{
String[] args = new String[]
{
"--" + Argument.COLLECTION + "=arg.collection",
"--" + Argument.OBSERVATION_ID + "=arg.observationID",
"--" + Argument.PRODUCT_ID + "=arg.productID",
"--" + Argument.URI + "[email protected]/test/resources/uriAndLocal.txt",
"--" + Argument.OUT + "=src/test/resources/out.xml",
"--" + Argument.LOCAL + "=foo"
};
ArgumentMap argsMap = new ArgumentMap(args);
try
{
Ingest ing = Main.createIngest(argsMap);
Assert.fail("expected IllegalArgumentException for invalid arguments");
}
catch(IllegalArgumentException expected) { }
catch(Exception unexpected)
{
log.error("unexpected exception", unexpected);
Assert.fail("unexpected exception: " + unexpected);
}
}
示例7: main
import ca.nrc.cadc.util.ArgumentMap; //导入依赖的package包/类
public static void main(String[] args) {
try {
ArgumentMap am = new ArgumentMap(args);
if (am.isSet("d") || am.isSet("debug")) {
Log4jInit.setLevel("ca.nrc.cadc.caom2.repo.client", Level.DEBUG);
Log4jInit.setLevel("ca.nrc.cadc.reg.client", Level.DEBUG);
} else if (am.isSet("v") || am.isSet("verbose")) {
Log4jInit.setLevel("ca.nrc.cadc.caom2.repo.client", Level.INFO);
} else {
Log4jInit.setLevel("ca.nrc.cadc", Level.WARN);
Log4jInit.setLevel("ca.nrc.cadc.caom2.repo.client", Level.WARN);
}
if (am.isSet("h") || am.isSet("help")) {
usage();
System.exit(0);
}
// TODO: implement useful command-line fatures here:
// setup
// am.getValue("resourceID")
// am.getValue("collection")
// get list
// am.isSet("list")
// am.getValue("maxrec")
// get a single observation
// am.getValue("observationID")
} catch (Throwable uncaught) {
log.error("uncaught exception", uncaught);
System.exit(-1);
}
}
示例8: initConsoleLogging
import ca.nrc.cadc.util.ArgumentMap; //导入依赖的package包/类
/**
* Initializes logging to the console.
* @param loggerNames the names of the loggers (usually names of packages
* or classes or ancestors of packages or classes). Can't be null.
* @param argMap command line arguments.
*/
private static synchronized Level initConsoleLogging(String[] loggerNames, ArgumentMap argMap)
{
Level level = DEFAULT_CONSOLE_LOGGING_LEVEL;
if (argMap.isSet(Argument.LOG_QUIET_SHORT) || argMap.isSet(Argument.LOG_QUIET)) level = Level.ERROR;
if (argMap.isSet(Argument.LOG_VERBOSE_SHORT) || argMap.isSet(Argument.LOG_VERBOSE)) level = Level.INFO;
if (argMap.isSet(Argument.LOG_DEBUG_SHORT) || argMap.isSet(Argument.DEBUG)) level = Level.DEBUG;
for (int i = 0; i < loggerNames.length; i++)
Log4jInit.setLevel(loggerNames[i], level);
return level;
}
示例9: testMinimalValidArguments
import ca.nrc.cadc.util.ArgumentMap; //导入依赖的package包/类
@Test
public void testMinimalValidArguments()
{
ArgumentMap argsMap = new ArgumentMap(minimalArguments);
try
{
Ingest ing = Main.createIngest(argsMap);
}
catch(Exception unexpected)
{
log.error("unexpected exception", unexpected);
Assert.fail("unexpected exception: " + unexpected);
}
}
示例10: testAllValidArguments
import ca.nrc.cadc.util.ArgumentMap; //导入依赖的package包/类
@Test
public void testAllValidArguments()
{
ArgumentMap argsMap = new ArgumentMap(allArguments);
try
{
Ingest ing = Main.createIngest(argsMap);
}
catch(Exception unexpected)
{
log.error("unexpected exception", unexpected);
Assert.fail("unexpected exception: " + unexpected);
}
}
示例11: main
import ca.nrc.cadc.util.ArgumentMap; //导入依赖的package包/类
public static void main(String[] args) {
try {
ArgumentMap am = new ArgumentMap(args);
if (am.isSet("h") || am.isSet("help")) {
usage();
System.exit(0);
}
// Set debug mode
CaomEntity.MCS_DEBUG = true;
if (am.isSet("d") || am.isSet("debug")) {
Log4jInit.setLevel("ca.nrc.cadc.caom2", Level.DEBUG);
} else if (am.isSet("v") || am.isSet("verbose")) {
Log4jInit.setLevel("ca.nrc.cadc.caom2", Level.INFO);
} else {
Log4jInit.setLevel("ca.nrc.cadc.caom2", Level.WARN);
}
if (am.getPositionalArgs().isEmpty()) {
usage();
System.exit(1);
}
String fname = am.getPositionalArgs().get(0);
File f = new File(fname);
ObservationReader r = new ObservationReader();
Observation obs = r.read(new FileReader(f));
if (am.getPositionalArgs().size() == 2) {
File out = new File(am.getPositionalArgs().get(1));
ObservationWriter w = new ObservationWriter();
w.write(obs, new FileWriter(out));
log.info("wrote copy: " + out.getAbsolutePath());
}
List<Runnable> validators = new ArrayList<>();
if (am.isSet("checksum")) {
int depth = 5;
if (am.isSet("depth")) {
try {
depth = Integer.parseInt(am.getValue("depth"));
} catch (NumberFormatException ex) {
log.error("invalid depth: " + am.getValue("depth") + ": must be integer in [1,5]");
usage();
System.exit(1);
}
}
validators.add(new ChecksumValidator(obs, depth, am.isSet("acc")));
}
if (am.isSet("wcs")) {
validators.add(new WCSValidator(obs));
}
for (Runnable v : validators) {
log.info("START " + v.getClass().getName());
v.run();
log.info("DONE " + v.getClass().getName() + System.getProperty("line.separator"));
}
} catch (Throwable t) {
log.error("unexpected failure", t);
System.exit(1);
}
System.exit(0);
}
示例12: main
import ca.nrc.cadc.util.ArgumentMap; //导入依赖的package包/类
public static void main(String[] args) {
String cur = null;
try {
ArgumentMap am = new ArgumentMap(args);
if (am.isSet("h") || am.isSet("help")) {
usage();
System.exit(0);
}
Level lvl = Level.WARN;
if (am.isSet("d") || am.isSet("debug")) {
lvl = Level.DEBUG;
} else if (am.isSet("v") || am.isSet("verbose")) {
lvl = Level.INFO;
}
Log4jInit.setLevel("ca.nrc.cadc.caom2.viz", lvl);
Log4jInit.setLevel("ca.nrc.cadc.caom2.types", lvl);
Log4jInit.setLevel("ca.nrc.cadc.caom2.wcs", lvl);
String fname = am.getValue("in");
String productID = am.getValue("productID");
boolean recomp = am.isSet("r");
boolean headless = am.isSet("headless");
if (fname == null) {
usage();
System.exit(1);
}
File f = new File(fname);
if (headless) {
ComputeFromXML cu = new ComputeFromXML(f, productID);
cu.doit();
} else {
VizUnion vu = new VizUnion(f, productID, recomp);
vu.doit();
}
} catch (Exception ex) {
log.error("failed to display: " + cur, ex);
}
}
示例13: initialize
import ca.nrc.cadc.util.ArgumentMap; //导入依赖的package包/类
/**
* Configures logging to either the console or a file, but not both.
*
* If the ArgumentMap contains a key name 'log', a file logger named with the
* value of 'log' is created. If the value of 'log' is null or an empty string,
* a file logger will not be created. If the ArgumentMap doesn't contain
* a 'log' key, a console logger is created.
*
* The log level is set using log level arguments in the ArgumentMap. If the
* ArgumentMap doesn't contain log level arguments, the default log level
* for the console logger is WARN, and the default log level for
* the file logger is INFO.
*
* @param loggerNames names of the loggers to apply the logging options of
* in the argsMap to.
* @param argMap command line argument options.
* @throws IOException problems with the log file
* @throws IllegalArgumentException if there is a disagreement with the way
* the file is handled.
*/
public static void initialize(String[] loggerNames, ArgumentMap argMap)
throws IOException, IllegalArgumentException
{
if (argMap.isSet(Argument.LOG))
{
String filename = argMap.getValue(Argument.LOG);
if (filename.isEmpty())
{
filename = "empty or zero-length string";
throw new IllegalArgumentException("Illegal log file name option: " + filename);
}
initFileLogging(loggerNames, argMap, filename);
}
else
{
initConsoleLogging(loggerNames, argMap);
}
}