/* * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* * Check each of the properties for a given basename.
*/ staticvoid test(String baseName, Map<String, String> args) {
validateArg(baseName,"", args);
validateArg(baseName,".display", args);
validateArg(baseName,".format", args);
}
// If an argument is -D defined, the corresponding property must be equal staticvoid validateArg(String name, String ext, Map<String, String> args) {
String extName = name.concat(ext);
String arg = args.get(extName);
String prop = System.getProperty(extName); if (arg == null && prop == null) {
System.out.printf("No values for %s%n", extName);
} else {
System.out.printf("validateArg %s: arg: %s, prop: %s%n", extName, arg, prop);
}
if (arg != null) { if (!Objects.equals(arg, prop)) { thrownew RuntimeException(extName + ": -D value should match property: "
+ arg + " != " + prop);
}
} elseif (prop != null) { // no command line arg for extName and some value for prop // Check that if a property is not overridden then it is not equal to the base if (ext != null && !ext.isEmpty()) {
String value = System.getProperty(name); if (Objects.equals(value, prop)) { thrownew RuntimeException(extName + " property should not be equals to "
+ name + " property: " + prop);
}
}
}
}
/** * Extract the -D arguments from the command line and return a map of key, value. * @return a map of key, values defined by -D on the command line.
*/ static HashMap<String, String> commandLineDefines() {
HashMap<String, String> props = new HashMap<>();
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
List<String> args = runtime.getInputArguments();
System.out.printf("args: %s%n", args); for (String arg : args) { if (arg.startsWith("-Duser.")) {
String[] kv = arg.substring(2).split("="); switch (kv.length) { case 1:
props.put(kv[0], ""); break; case 2:
props.put(kv[0], kv[1]); break; default: thrownew IllegalArgumentException("Illegal property syntax: " + arg);
}
}
} return props;
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.0 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.