List of usage examples for java.util Properties Properties
public Properties()
From source file:com.googlecode.flyway.commandline.Main.java
/** * Main method.//from ww w . ja v a 2 s.c o m * * @param args The command-line arguments. */ public static void main(String[] args) { boolean debug = isDebug(args); try { printVersion(); String operation = determineOperation(args); if (operation == null) { printUsage(); return; } loadJdbcDriversAndJavaMigrations(); Flyway flyway = new Flyway(); Properties properties = new Properties(); initializeDefaults(properties); loadConfigurationFile(properties, args); overrideConfiguration(properties, args); flyway.configure(properties); if ("clean".equals(operation)) { flyway.clean(); } else if ("init".equals(operation)) { flyway.init(); } else if ("migrate".equals(operation)) { flyway.migrate(); } else if ("validate".equals(operation)) { flyway.validate(); } else if ("status".equals(operation)) { MetaDataTableRowDumper.dumpMigration(flyway.status()); } else if ("history".equals(operation)) { MetaDataTableRowDumper.dumpMigrations(flyway.history()); } else { printUsage(); } } catch (Exception e) { if (debug) { LOG.error("Unexpected error", e); } else { LOG.error(ClassUtils.getShortName(e.getClass()) + ": " + e.getMessage()); outputFirstStackTraceElement(e); @SuppressWarnings({ "ThrowableResultOfMethodCallIgnored" }) Throwable rootCause = ExceptionUtils.getRootCause(e); if (rootCause != null) { LOG.error("Caused by " + rootCause.toString()); outputFirstStackTraceElement(rootCause); } } System.exit(1); } }
From source file:com.jdom.mediadownloader.MediaDownloader.java
public static void main(String[] args) { if (args.length != 1) { throw new IllegalArgumentException( "You must pass the location to the properties file to the application!"); }/*from w w w . j a va 2 s .c o m*/ File file = new File(args[0]); Properties properties = new Properties(); FileReader fileReader = null; try { fileReader = new FileReader(file); properties.load(fileReader); } catch (Exception e) { throw new RuntimeException(e); } finally { Closeables.closeQuietly(fileReader); } System.getProperties().putAll(properties); initializeContext(); MediaDownloader mediaDownloader = ctx.getBean(MediaDownloader.class); mediaDownloader.processDownloads(); }
From source file:com.mirth.connect.server.launcher.MirthLauncher.java
public static void main(String[] args) { try {/* w w w .j a va 2 s. c o m*/ try { uninstallPendingExtensions(); installPendingExtensions(); } catch (Exception e) { logger.error("Error uninstalling or installing pending extensions.", e); } Properties mirthProperties = new Properties(); String includeCustomLib = null; try { mirthProperties.load(new FileInputStream(new File(MIRTH_PROPERTIES_FILE))); includeCustomLib = mirthProperties.getProperty(PROPERTY_INCLUDE_CUSTOM_LIB); createAppdataDir(mirthProperties); } catch (Exception e) { logger.error("Error creating the appdata directory.", e); } ManifestFile mirthServerJar = new ManifestFile("server-lib/mirth-server.jar"); ManifestFile mirthClientCoreJar = new ManifestFile("server-lib/mirth-client-core.jar"); ManifestDirectory serverLibDir = new ManifestDirectory("server-lib"); serverLibDir.setExcludes(new String[] { "mirth-client-core.jar" }); List<ManifestEntry> manifestList = new ArrayList<ManifestEntry>(); manifestList.add(mirthServerJar); manifestList.add(mirthClientCoreJar); manifestList.add(serverLibDir); // We want to include custom-lib if the property isn't found, or if it equals "true" if (includeCustomLib == null || Boolean.valueOf(includeCustomLib)) { manifestList.add(new ManifestDirectory("custom-lib")); } ManifestEntry[] manifest = manifestList.toArray(new ManifestEntry[manifestList.size()]); // Get the current server version JarFile mirthClientCoreJarFile = new JarFile(mirthClientCoreJar.getName()); Properties versionProperties = new Properties(); versionProperties.load(mirthClientCoreJarFile .getInputStream(mirthClientCoreJarFile.getJarEntry("version.properties"))); String currentVersion = versionProperties.getProperty("mirth.version"); List<URL> classpathUrls = new ArrayList<URL>(); addManifestToClasspath(manifest, classpathUrls); addExtensionsToClasspath(classpathUrls, currentVersion); URLClassLoader classLoader = new URLClassLoader(classpathUrls.toArray(new URL[classpathUrls.size()])); Class<?> mirthClass = classLoader.loadClass("com.mirth.connect.server.Mirth"); Thread mirthThread = (Thread) mirthClass.newInstance(); mirthThread.setContextClassLoader(classLoader); mirthThread.start(); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.sf.jodreports.cli.CreateDocument.java
public static void main(String[] args) throws Exception { if (args.length < 3) { System.err.println("USAGE: " + CreateDocument.class.getName() + " <template-document> <data-file> <output-document>"); System.exit(0);/*from w w w . j a v a2s . c om*/ } File templateFile = new File(args[0]); File dataFile = new File(args[1]); File outputFile = new File(args[2]); DocumentTemplateFactory documentTemplateFactory = new DocumentTemplateFactory(); DocumentTemplate template = documentTemplateFactory.getTemplate(templateFile); Object model = null; String dataFileExtension = FilenameUtils.getExtension(dataFile.getName()); if (dataFileExtension.equals("xml")) { model = NodeModel.parse(dataFile); } else if (dataFileExtension.equals("properties")) { Properties properties = new Properties(); properties.load(new FileInputStream(dataFile)); model = properties; } else { throw new IllegalArgumentException( "data file must be 'xml' or 'properties'; unsupported type: " + dataFileExtension); } template.createDocument(model, new FileOutputStream(outputFile)); }
From source file:com.adobe.aem.demomachine.Checksums.java
public static void main(String[] args) { String rootFolder = null;//w w w. java2 s . c o m // Command line options for this tool Options options = new Options(); options.addOption("f", true, "Demo Machine root folder"); CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("f")) { rootFolder = cmd.getOptionValue("f"); } } catch (Exception e) { System.exit(-1); } Properties md5properties = new Properties(); List<String[]> listPaths = Arrays.asList(AemDemoConstants.demoPaths); for (String[] path : listPaths) { if (path.length == 5) { logger.debug(path[1]); File pathFolder = new File(rootFolder + (path[1].length() > 0 ? (File.separator + path[1]) : "")); if (pathFolder.exists()) { String md5 = AemDemoUtils.calcMD5HashForDir(pathFolder, Boolean.parseBoolean(path[3]), false); logger.debug("MD5 is: " + md5); md5properties.setProperty("demo.path." + path[0], path[1]); md5properties.setProperty("demo.md5." + path[0], md5); } else { logger.error("Folder cannot be found"); } } } File md5 = new File(rootFolder + File.separator + "conf" + File.separator + "checksums.properties"); try { @SuppressWarnings("serial") Properties tmpProperties = new Properties() { @Override public synchronized Enumeration<Object> keys() { return Collections.enumeration(new TreeSet<Object>(super.keySet())); } }; tmpProperties.putAll(md5properties); tmpProperties.store(new FileOutputStream(md5), null); } catch (Exception e) { logger.error(e.getMessage()); } System.out.println("MD5 checkums generated"); }
From source file:com.adobe.aem.demomachine.Updates.java
public static void main(String[] args) { String rootFolder = null;/* w w w .j a v a2s. c o m*/ // Command line options for this tool Options options = new Options(); options.addOption("f", true, "Demo Machine root folder"); CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("f")) { rootFolder = cmd.getOptionValue("f"); } } catch (Exception e) { System.exit(-1); } Properties md5properties = new Properties(); try { URL url = new URL( "https://raw.githubusercontent.com/Adobe-Marketing-Cloud/aem-demo-machine/master/conf/checksums.properties"); InputStream in = url.openStream(); Reader reader = new InputStreamReader(in, "UTF-8"); md5properties.load(reader); reader.close(); } catch (Exception e) { System.out.println("Error: Cannot connect to GitHub.com to check for updates"); System.exit(-1); } System.out.println(AemDemoConstants.HR); int nbUpdateAvailable = 0; List<String[]> listPaths = Arrays.asList(AemDemoConstants.demoPaths); for (String[] path : listPaths) { if (path.length == 5) { logger.debug(path[1]); File pathFolder = new File(rootFolder + (path[1].length() > 0 ? (File.separator + path[1]) : "")); if (pathFolder.exists()) { String newMd5 = AemDemoUtils.calcMD5HashForDir(pathFolder, Boolean.parseBoolean(path[3]), false); logger.debug("MD5 is: " + newMd5); String oldMd5 = md5properties.getProperty("demo.md5." + path[0]); if (oldMd5 == null || oldMd5.length() == 0) { logger.error("Cannot find MD5 for " + path[0]); System.out.println(path[2] + " : Cannot find M5 checksum"); continue; } if (newMd5.equals(oldMd5)) { continue; } else { System.out.println(path[2] + " : New update available" + (path[0].equals("0") ? " (use 'git pull' to get the latest changes)" : "")); nbUpdateAvailable++; } } else { System.out.println(path[2] + " : Not installed"); } } } if (nbUpdateAvailable == 0) { System.out.println("Your AEM Demo Machine is up to date!"); } System.out.println(AemDemoConstants.HR); }
From source file:com.cloud.sample.UserCloudAPIExecutor.java
public static void main(String[] args) { // Host/* w w w. j a v a 2 s .co m*/ String host = null; // Fully qualified URL with http(s)://host:port String apiUrl = null; // ApiKey and secretKey as given by your CloudStack vendor String apiKey = null; String secretKey = null; try { Properties prop = new Properties(); prop.load(new FileInputStream("usercloud.properties")); // host host = prop.getProperty("host"); if (host == null) { System.out.println( "Please specify a valid host in the format of http(s)://:/client/api in your usercloud.properties file."); } // apiUrl apiUrl = prop.getProperty("apiUrl"); if (apiUrl == null) { System.out.println( "Please specify a valid API URL in the format of command=¶m1=¶m2=... in your usercloud.properties file."); } // apiKey apiKey = prop.getProperty("apiKey"); if (apiKey == null) { System.out.println( "Please specify your API Key as provided by your CloudStack vendor in your usercloud.properties file."); } // secretKey secretKey = prop.getProperty("secretKey"); if (secretKey == null) { System.out.println( "Please specify your secret Key as provided by your CloudStack vendor in your usercloud.properties file."); } if (apiUrl == null || apiKey == null || secretKey == null) { return; } System.out.println("Constructing API call to host = '" + host + "' with API command = '" + apiUrl + "' using apiKey = '" + apiKey + "' and secretKey = '" + secretKey + "'"); // Step 1: Make sure your APIKey is URL encoded String encodedApiKey = URLEncoder.encode(apiKey, "UTF-8"); // Step 2: URL encode each parameter value, then sort the parameters and apiKey in // alphabetical order, and then toLowerCase all the parameters, parameter values and apiKey. // Please note that if any parameters with a '&' as a value will cause this test client to fail since we are using // '&' to delimit // the string List<String> sortedParams = new ArrayList<String>(); sortedParams.add("apikey=" + encodedApiKey.toLowerCase()); StringTokenizer st = new StringTokenizer(apiUrl, "&"); String url = null; boolean first = true; while (st.hasMoreTokens()) { String paramValue = st.nextToken(); String param = paramValue.substring(0, paramValue.indexOf("=")); String value = URLEncoder .encode(paramValue.substring(paramValue.indexOf("=") + 1, paramValue.length()), "UTF-8"); if (first) { url = param + "=" + value; first = false; } else { url = url + "&" + param + "=" + value; } sortedParams.add(param.toLowerCase() + "=" + value.toLowerCase()); } Collections.sort(sortedParams); System.out.println("Sorted Parameters: " + sortedParams); // Step 3: Construct the sorted URL and sign and URL encode the sorted URL with your secret key String sortedUrl = null; first = true; for (String param : sortedParams) { if (first) { sortedUrl = param; first = false; } else { sortedUrl = sortedUrl + "&" + param; } } System.out.println("sorted URL : " + sortedUrl); String encodedSignature = signRequest(sortedUrl, secretKey); // Step 4: Construct the final URL we want to send to the CloudStack Management Server // Final result should look like: // http(s)://://client/api?&apiKey=&signature= String finalUrl = host + "?" + url + "&apiKey=" + apiKey + "&signature=" + encodedSignature; System.out.println("final URL : " + finalUrl); // Step 5: Perform a HTTP GET on this URL to execute the command HttpClient client = new HttpClient(); HttpMethod method = new GetMethod(finalUrl); int responseCode = client.executeMethod(method); if (responseCode == 200) { // SUCCESS! System.out.println("Successfully executed command"); } else { // FAILED! System.out.println("Unable to execute command with response code: " + responseCode); } } catch (Throwable t) { System.out.println(t); } }
From source file:com.ibm.watson.developer_cloud.professor_languo.pipeline.PipelineDriver.java
public static void main(String[] args) { Properties properties = new Properties(); try (FileInputStream propertiesFileStream = new FileInputStream(args[0])) { // Load the properties from the properties file properties.load(propertiesFileStream); // Load the bluemix properties IndexerAndSearcherFactory.loadStaticBluemixProperties(properties); // Launch the pipeline drive(properties);/*from ww w . j av a2 s.c om*/ } catch (IOException | PipelineException e) { logger.fatal(e.getMessage()); throw new RuntimeException(e); } }
From source file:com.machinelinking.cli.loader.java
public static void main(String[] args) { if (args.length != 2) { System.err.println("Usage: $0 <config-file> <dump>"); System.exit(1);//w w w .j a va2 s . c o m } try { final File configFile = check(args[0]); final File dumpFile = check(args[1]); final Properties properties = new Properties(); properties.load(FileUtils.openInputStream(configFile)); final Flag[] flags = WikiPipelineFactory.getInstance().toFlags(getPropertyOrFail(properties, LOADER_FLAGS_PROP, "valid flags: " + Arrays.toString(WikiPipelineFactory.getInstance().getDefinedFlags()))); final JSONStorageFactory jsonStorageFactory = MultiJSONStorageFactory .loadJSONStorageFactory(getPropertyOrFail(properties, LOADER_STORAGE_FACTORY_PROP, null)); final String jsonStorageConfig = getPropertyOrFail(properties, LOADER_STORAGE_CONFIG_PROP, null); final URL prefixURL = readURL(getPropertyOrFail(properties, LOADER_PREFIX_URL_PROP, "expected a valid URL prefix like: http://en.wikipedia.org/"), LOADER_PREFIX_URL_PROP); final DefaultJSONStorageLoader[] loader = new DefaultJSONStorageLoader[1]; final boolean[] finalReportProduced = new boolean[] { false }; Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { if (!finalReportProduced[0] && loader[0] != null) { System.err.println( "Process interrupted. Partial loading report: " + loader[0].createReport()); } System.err.println("Shutting down."); } })); final JSONStorageConfiguration storageConfig = jsonStorageFactory .createConfiguration(jsonStorageConfig); try (final JSONStorage storage = jsonStorageFactory.createStorage(storageConfig)) { loader[0] = new DefaultJSONStorageLoader(WikiPipelineFactory.getInstance(), flags, storage); final StorageLoaderReport report = loader[0].load(prefixURL, FileUtil.openDecompressedInputStream(dumpFile)); System.err.println("Loading report: " + report); finalReportProduced[0] = true; } System.exit(0); } catch (Exception e) { e.printStackTrace(); System.exit(2); } }
From source file:eu.qualimaster.easy.extension.debug.DebugProfile.java
/** * Executes the test./*from w w w .j a v a 2 s . co m*/ * * @param args the first argument shall be the model location * @throws ModelManagementException in case that obtaining the models fails * @throws IOException if file operations fail */ public static void main(String[] args) throws ModelManagementException, IOException { if (0 == args.length) { System.out.println("qualimaster.profile: <model location>"); System.exit(0); } else { Properties prop = new Properties(); prop.put(CoordinationConfiguration.PIPELINE_ELEMENTS_REPOSITORY, "https://projects.sse.uni-hildesheim.de/qm/maven/"); CoordinationConfiguration.configure(prop, false); File tmp = new File(FileUtils.getTempDirectory(), "qmDebugProfile"); FileUtils.deleteDirectory(tmp); tmp.mkdirs(); File modelLocation = new File(args[0]); if (!modelLocation.exists()) { System.out.println("model location " + modelLocation + " does not exist"); System.exit(0); } initialize(); ModelInitializer.registerLoader(ProgressObserver.NO_OBSERVER); ModelInitializer.addLocation(modelLocation, ProgressObserver.NO_OBSERVER); Project project = RepositoryHelper.obtainModel(VarModel.INSTANCE, "QM", null); // create descriptor before clearing the location - in infrastructure pass vil directly/resolve VIL Configuration monConfig = RepositoryHelper.createConfiguration(project, "MONITORING"); QmProjectDescriptor source = new QmProjectDescriptor(tmp); try { ProfileData data = AlgorithmProfileHelper.createProfilePipeline(monConfig, "ProfileTestPip", "fCorrelationFinancial", "TopoSoftwareCorrelationFinancial", source); // "fPreprocessor", "Preprocessor", source); System.out.println("Creation successful. " + data.getPipeline()); } catch (VilException e) { e.printStackTrace(); } ModelInitializer.removeLocation(modelLocation, ProgressObserver.NO_OBSERVER); } }