List of usage examples for java.io File separator
String separator
To view the source code for java.io File separator.
Click Source Link
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSaxOracleLoaderCLI.CFAsteriskSaxOracleLoaderCLI.java
public static void main(String args[]) { final String S_ProcName = "CFAsteriskSaxOracleLoaderCLI.main() "; initConsoleLog();//ww w .j ava2 s. c o m int numArgs = args.length; if (numArgs >= 2) { String homeDirName = System.getProperty("HOME"); if (homeDirName == null) { homeDirName = System.getProperty("user.home"); if (homeDirName == null) { log.message(S_ProcName + "ERROR: Home directory not set"); return; } } File homeDir = new File(homeDirName); if (!homeDir.exists()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" does not exist"); return; } if (!homeDir.isDirectory()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" is not a directory"); return; } CFAsteriskConfigurationFile cFAsteriskConfig = new CFAsteriskConfigurationFile(); String cFAsteriskConfigFileName = homeDir.getPath() + File.separator + ".cfasteriskoraclerc"; cFAsteriskConfig.setFileName(cFAsteriskConfigFileName); File cFAsteriskConfigFile = new File(cFAsteriskConfigFileName); if (!cFAsteriskConfigFile.exists()) { cFAsteriskConfig.setDbServer("127.0.0.1"); cFAsteriskConfig.setDbPort(1526); cFAsteriskConfig.setDbDatabase("CFAst24"); cFAsteriskConfig.setDbUserName("system"); cFAsteriskConfig.setDbPassword("edit-me-please"); cFAsteriskConfig.save(); log.message(S_ProcName + "INFO: Created configuration file " + cFAsteriskConfigFileName + ", please edit configuration and restart."); return; } if (!cFAsteriskConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed configuration file " + cFAsteriskConfigFileName + " is not a file."); return; } if (!cFAsteriskConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read configuration file " + cFAsteriskConfigFileName); return; } cFAsteriskConfig.load(); boolean fastExit = false; CFAsteriskClientConfigurationFile cFDbTestClientConfig = new CFAsteriskClientConfigurationFile(); String cFDbTestClientConfigFileName = homeDir.getPath() + File.separator + ".cfdbtestclientrc"; cFDbTestClientConfig.setFileName(cFDbTestClientConfigFileName); File cFDbTestClientConfigFile = new File(cFDbTestClientConfigFileName); if (!cFDbTestClientConfigFile.exists()) { String cFDbTestKeyStoreFileName = homeDir.getPath() + File.separator + ".msscfjceks"; cFDbTestClientConfig.setKeyStore(cFDbTestKeyStoreFileName); InetAddress localHost; try { localHost = InetAddress.getLocalHost(); } catch (UnknownHostException e) { localHost = null; } if (localHost == null) { log.message(S_ProcName + "ERROR: LocalHost is null"); return; } String hostName = localHost.getHostName(); if ((hostName == null) || (hostName.length() <= 0)) { log.message("ERROR: LocalHost.HostName is null or empty"); return; } String userName = System.getProperty("user.name"); if ((userName == null) || (userName.length() <= 0)) { log.message("ERROR: user.name is null or empty"); return; } String deviceName = hostName.replaceAll("[^\\w]", "_").toLowerCase() + "-" + userName.replaceAll("[^\\w]", "_").toLowerCase(); cFDbTestClientConfig.setDeviceName(deviceName); cFDbTestClientConfig.save(); log.message(S_ProcName + "INFO: Created CFAsterisk client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } if (!cFDbTestClientConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed client configuration file " + cFDbTestClientConfigFileName + " is not a file."); fastExit = true; } if (!cFDbTestClientConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } cFDbTestClientConfig.load(); if (fastExit) { return; } // Configure logging Properties sysProps = System.getProperties(); sysProps.setProperty("log4j.rootCategory", "WARN"); sysProps.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger"); Logger httpLogger = Logger.getLogger("org.apache.http"); httpLogger.setLevel(Level.WARN); ICFAsteriskSchema cFAsteriskSchema = new CFAsteriskOracleSchema(); cFAsteriskSchema.setConfigurationFile(cFAsteriskConfig); ICFAsteriskSchemaObj cFAsteriskSchemaObj = new CFAsteriskSchemaObj(); cFAsteriskSchemaObj.setBackingStore(cFAsteriskSchema); CFAsteriskSaxLoaderCLI cli = new CFAsteriskSaxOracleLoaderCLI(); CFAsteriskSaxLoader loader = cli.getSaxLoader(); loader.setSchemaObj(cFAsteriskSchemaObj); cFAsteriskSchema.connect(); String url = args[1]; if (numArgs >= 5) { cli.setClusterName(args[2]); cli.setTenantName(args[3]); cli.setSecUserName(args[4]); } else { cli.setClusterName("default"); cli.setTenantName("system"); cli.setSecUserName("system"); } loader.setUseCluster(cli.getClusterObj()); loader.setUseTenant(cli.getTenantObj()); try { cFAsteriskSchema.beginTransaction(); cFAsteriskSchemaObj.setSecCluster(cli.getClusterObj()); cFAsteriskSchemaObj.setSecTenant(cli.getTenantObj()); cFAsteriskSchemaObj.setSecUser(cli.getSecUserObj()); cFAsteriskSchemaObj.setSecSession(cli.getSecSessionObj()); CFSecurityAuthorization auth = new CFSecurityAuthorization(); auth.setSecCluster(cFAsteriskSchemaObj.getSecCluster()); auth.setSecTenant(cFAsteriskSchemaObj.getSecTenant()); auth.setSecSession(cFAsteriskSchemaObj.getSecSession()); cFAsteriskSchemaObj.setAuthorization(auth); applyLoaderOptions(loader, args[0]); if (numArgs >= 5) { cli.evaluateRemainingArgs(args, 5); } else { cli.evaluateRemainingArgs(args, 2); } loader.parseFile(url); cFAsteriskSchema.commit(); cFAsteriskSchema.disconnect(true); } catch (Exception e) { log.message(S_ProcName + "EXCEPTION: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } catch (Error e) { log.message(S_ProcName + "ERROR: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } finally { if (cFAsteriskSchema.isConnected()) { cFAsteriskSchema.rollback(); cFAsteriskSchema.disconnect(false); } } } else { log.message(S_ProcName + "ERROR: Expected at least two argument specifying the loader options and the name of the XML file to parse. The first argument may be empty."); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSaxMSSqlLoaderCLI.CFAsteriskSaxMSSqlLoaderCLI.java
public static void main(String args[]) { final String S_ProcName = "CFAsteriskSaxMSSqlLoaderCLI.main() "; initConsoleLog();/*from w w w .j a va 2s. c o m*/ int numArgs = args.length; if (numArgs >= 2) { String homeDirName = System.getProperty("HOME"); if (homeDirName == null) { homeDirName = System.getProperty("user.home"); if (homeDirName == null) { log.message(S_ProcName + "ERROR: Home directory not set"); return; } } File homeDir = new File(homeDirName); if (!homeDir.exists()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" does not exist"); return; } if (!homeDir.isDirectory()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" is not a directory"); return; } CFAsteriskConfigurationFile cFAsteriskConfig = new CFAsteriskConfigurationFile(); String cFAsteriskConfigFileName = homeDir.getPath() + File.separator + ".cfasteriskmssqlrc"; cFAsteriskConfig.setFileName(cFAsteriskConfigFileName); File cFAsteriskConfigFile = new File(cFAsteriskConfigFileName); if (!cFAsteriskConfigFile.exists()) { cFAsteriskConfig.setDbServer("127.0.0.1"); cFAsteriskConfig.setDbPort(1433); cFAsteriskConfig.setDbDatabase("CFAst24"); cFAsteriskConfig.setDbUserName("sa"); cFAsteriskConfig.setDbPassword("edit-me-please"); cFAsteriskConfig.save(); log.message(S_ProcName + "INFO: Created configuration file " + cFAsteriskConfigFileName + ", please edit configuration and restart."); return; } if (!cFAsteriskConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed configuration file " + cFAsteriskConfigFileName + " is not a file."); return; } if (!cFAsteriskConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read configuration file " + cFAsteriskConfigFileName); return; } cFAsteriskConfig.load(); boolean fastExit = false; CFAsteriskClientConfigurationFile cFDbTestClientConfig = new CFAsteriskClientConfigurationFile(); String cFDbTestClientConfigFileName = homeDir.getPath() + File.separator + ".cfdbtestclientrc"; cFDbTestClientConfig.setFileName(cFDbTestClientConfigFileName); File cFDbTestClientConfigFile = new File(cFDbTestClientConfigFileName); if (!cFDbTestClientConfigFile.exists()) { String cFDbTestKeyStoreFileName = homeDir.getPath() + File.separator + ".msscfjceks"; cFDbTestClientConfig.setKeyStore(cFDbTestKeyStoreFileName); InetAddress localHost; try { localHost = InetAddress.getLocalHost(); } catch (UnknownHostException e) { localHost = null; } if (localHost == null) { log.message(S_ProcName + "ERROR: LocalHost is null"); return; } String hostName = localHost.getHostName(); if ((hostName == null) || (hostName.length() <= 0)) { log.message("ERROR: LocalHost.HostName is null or empty"); return; } String userName = System.getProperty("user.name"); if ((userName == null) || (userName.length() <= 0)) { log.message("ERROR: user.name is null or empty"); return; } String deviceName = hostName.replaceAll("[^\\w]", "_").toLowerCase() + "-" + userName.replaceAll("[^\\w]", "_").toLowerCase(); cFDbTestClientConfig.setDeviceName(deviceName); cFDbTestClientConfig.save(); log.message(S_ProcName + "INFO: Created CFAsterisk client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } if (!cFDbTestClientConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed client configuration file " + cFDbTestClientConfigFileName + " is not a file."); fastExit = true; } if (!cFDbTestClientConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } cFDbTestClientConfig.load(); if (fastExit) { return; } // Configure logging Properties sysProps = System.getProperties(); sysProps.setProperty("log4j.rootCategory", "WARN"); sysProps.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger"); Logger httpLogger = Logger.getLogger("org.apache.http"); httpLogger.setLevel(Level.WARN); ICFAsteriskSchema cFAsteriskSchema = new CFAsteriskMSSqlSchema(); cFAsteriskSchema.setConfigurationFile(cFAsteriskConfig); ICFAsteriskSchemaObj cFAsteriskSchemaObj = new CFAsteriskSchemaObj(); cFAsteriskSchemaObj.setBackingStore(cFAsteriskSchema); CFAsteriskSaxLoaderCLI cli = new CFAsteriskSaxMSSqlLoaderCLI(); CFAsteriskSaxLoader loader = cli.getSaxLoader(); loader.setSchemaObj(cFAsteriskSchemaObj); cFAsteriskSchema.connect(); String url = args[1]; if (numArgs >= 5) { cli.setClusterName(args[2]); cli.setTenantName(args[3]); cli.setSecUserName(args[4]); } else { cli.setClusterName("default"); cli.setTenantName("system"); cli.setSecUserName("system"); } loader.setUseCluster(cli.getClusterObj()); loader.setUseTenant(cli.getTenantObj()); try { cFAsteriskSchema.beginTransaction(); cFAsteriskSchemaObj.setSecCluster(cli.getClusterObj()); cFAsteriskSchemaObj.setSecTenant(cli.getTenantObj()); cFAsteriskSchemaObj.setSecUser(cli.getSecUserObj()); cFAsteriskSchemaObj.setSecSession(cli.getSecSessionObj()); CFSecurityAuthorization auth = new CFSecurityAuthorization(); auth.setSecCluster(cFAsteriskSchemaObj.getSecCluster()); auth.setSecTenant(cFAsteriskSchemaObj.getSecTenant()); auth.setSecSession(cFAsteriskSchemaObj.getSecSession()); cFAsteriskSchemaObj.setAuthorization(auth); applyLoaderOptions(loader, args[0]); if (numArgs >= 5) { cli.evaluateRemainingArgs(args, 5); } else { cli.evaluateRemainingArgs(args, 2); } loader.parseFile(url); cFAsteriskSchema.commit(); cFAsteriskSchema.disconnect(true); } catch (Exception e) { log.message(S_ProcName + "EXCEPTION: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } catch (Error e) { log.message(S_ProcName + "ERROR: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } finally { if (cFAsteriskSchema.isConnected()) { cFAsteriskSchema.rollback(); cFAsteriskSchema.disconnect(false); } } } else { log.message(S_ProcName + "ERROR: Expected at least two argument specifying the loader options and the name of the XML file to parse. The first argument may be empty."); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSaxPgSqlLoaderCLI.CFAsteriskSaxPgSqlLoaderCLI.java
public static void main(String args[]) { final String S_ProcName = "CFAsteriskSaxPgSqlLoaderCLI.main() "; initConsoleLog();/*from ww w.j a va2 s . c o m*/ int numArgs = args.length; if (numArgs >= 2) { String homeDirName = System.getProperty("HOME"); if (homeDirName == null) { homeDirName = System.getProperty("user.home"); if (homeDirName == null) { log.message(S_ProcName + "ERROR: Home directory not set"); return; } } File homeDir = new File(homeDirName); if (!homeDir.exists()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" does not exist"); return; } if (!homeDir.isDirectory()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" is not a directory"); return; } CFAsteriskConfigurationFile cFAsteriskConfig = new CFAsteriskConfigurationFile(); String cFAsteriskConfigFileName = homeDir.getPath() + File.separator + ".cfasteriskpgsqlrc"; cFAsteriskConfig.setFileName(cFAsteriskConfigFileName); File cFAsteriskConfigFile = new File(cFAsteriskConfigFileName); if (!cFAsteriskConfigFile.exists()) { cFAsteriskConfig.setDbServer("127.0.0.1"); cFAsteriskConfig.setDbPort(5432); cFAsteriskConfig.setDbDatabase("CFAst24"); cFAsteriskConfig.setDbUserName("postgres"); cFAsteriskConfig.setDbPassword("edit-me-please"); cFAsteriskConfig.save(); log.message(S_ProcName + "INFO: Created configuration file " + cFAsteriskConfigFileName + ", please edit configuration and restart."); return; } if (!cFAsteriskConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed configuration file " + cFAsteriskConfigFileName + " is not a file."); return; } if (!cFAsteriskConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read configuration file " + cFAsteriskConfigFileName); return; } cFAsteriskConfig.load(); boolean fastExit = false; CFAsteriskClientConfigurationFile cFDbTestClientConfig = new CFAsteriskClientConfigurationFile(); String cFDbTestClientConfigFileName = homeDir.getPath() + File.separator + ".cfdbtestclientrc"; cFDbTestClientConfig.setFileName(cFDbTestClientConfigFileName); File cFDbTestClientConfigFile = new File(cFDbTestClientConfigFileName); if (!cFDbTestClientConfigFile.exists()) { String cFDbTestKeyStoreFileName = homeDir.getPath() + File.separator + ".msscfjceks"; cFDbTestClientConfig.setKeyStore(cFDbTestKeyStoreFileName); InetAddress localHost; try { localHost = InetAddress.getLocalHost(); } catch (UnknownHostException e) { localHost = null; } if (localHost == null) { log.message(S_ProcName + "ERROR: LocalHost is null"); return; } String hostName = localHost.getHostName(); if ((hostName == null) || (hostName.length() <= 0)) { log.message("ERROR: LocalHost.HostName is null or empty"); return; } String userName = System.getProperty("user.name"); if ((userName == null) || (userName.length() <= 0)) { log.message("ERROR: user.name is null or empty"); return; } String deviceName = hostName.replaceAll("[^\\w]", "_").toLowerCase() + "-" + userName.replaceAll("[^\\w]", "_").toLowerCase(); cFDbTestClientConfig.setDeviceName(deviceName); cFDbTestClientConfig.save(); log.message(S_ProcName + "INFO: Created CFAsterisk client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } if (!cFDbTestClientConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed client configuration file " + cFDbTestClientConfigFileName + " is not a file."); fastExit = true; } if (!cFDbTestClientConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } cFDbTestClientConfig.load(); if (fastExit) { return; } // Configure logging Properties sysProps = System.getProperties(); sysProps.setProperty("log4j.rootCategory", "WARN"); sysProps.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger"); Logger httpLogger = Logger.getLogger("org.apache.http"); httpLogger.setLevel(Level.WARN); ICFAsteriskSchema cFAsteriskSchema = new CFAsteriskPgSqlSchema(); cFAsteriskSchema.setConfigurationFile(cFAsteriskConfig); ICFAsteriskSchemaObj cFAsteriskSchemaObj = new CFAsteriskSchemaObj(); cFAsteriskSchemaObj.setBackingStore(cFAsteriskSchema); CFAsteriskSaxLoaderCLI cli = new CFAsteriskSaxPgSqlLoaderCLI(); CFAsteriskSaxLoader loader = cli.getSaxLoader(); loader.setSchemaObj(cFAsteriskSchemaObj); cFAsteriskSchema.connect(); String url = args[1]; if (numArgs >= 5) { cli.setClusterName(args[2]); cli.setTenantName(args[3]); cli.setSecUserName(args[4]); } else { cli.setClusterName("default"); cli.setTenantName("system"); cli.setSecUserName("system"); } loader.setUseCluster(cli.getClusterObj()); loader.setUseTenant(cli.getTenantObj()); try { cFAsteriskSchema.beginTransaction(); cFAsteriskSchemaObj.setSecCluster(cli.getClusterObj()); cFAsteriskSchemaObj.setSecTenant(cli.getTenantObj()); cFAsteriskSchemaObj.setSecUser(cli.getSecUserObj()); cFAsteriskSchemaObj.setSecSession(cli.getSecSessionObj()); CFSecurityAuthorization auth = new CFSecurityAuthorization(); auth.setSecCluster(cFAsteriskSchemaObj.getSecCluster()); auth.setSecTenant(cFAsteriskSchemaObj.getSecTenant()); auth.setSecSession(cFAsteriskSchemaObj.getSecSession()); cFAsteriskSchemaObj.setAuthorization(auth); applyLoaderOptions(loader, args[0]); if (numArgs >= 5) { cli.evaluateRemainingArgs(args, 5); } else { cli.evaluateRemainingArgs(args, 2); } loader.parseFile(url); cFAsteriskSchema.commit(); cFAsteriskSchema.disconnect(true); } catch (Exception e) { log.message(S_ProcName + "EXCEPTION: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } catch (Error e) { log.message(S_ProcName + "ERROR: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } finally { if (cFAsteriskSchema.isConnected()) { cFAsteriskSchema.rollback(); cFAsteriskSchema.disconnect(false); } } } else { log.message(S_ProcName + "ERROR: Expected at least two argument specifying the loader options and the name of the XML file to parse. The first argument may be empty."); } }
From source file:com.redhat.satellite.search.DeleteIndexes.java
/** * @param args// w w w . jav a 2 s.co m */ public static void main(String[] args) { try { Configuration config = new Configuration(); DatabaseManager databaseManager = new DatabaseManager(config); String indexWorkDir = config.getString("search.index_work_dir", null); if (StringUtils.isBlank(indexWorkDir)) { log.warn("Couldn't find path for where index files are stored."); log.warn("Looked in config for property: search.index_work_dir"); return; } List<IndexInfo> indexes = new ArrayList<IndexInfo>(); indexes.add(new IndexInfo("deleteLastErrata", indexWorkDir + File.separator + "errata")); indexes.add(new IndexInfo("deleteLastPackage", indexWorkDir + File.separator + "package")); indexes.add(new IndexInfo("deleteLastServer", indexWorkDir + File.separator + "server")); indexes.add(new IndexInfo("deleteLastHardwareDevice", indexWorkDir + File.separator + "hwdevice")); indexes.add(new IndexInfo("deleteLastSnapshotTag", indexWorkDir + File.separator + "snapshotTag")); indexes.add(new IndexInfo("deleteLastServerCustomInfo", indexWorkDir + File.separator + "serverCustomInfo")); indexes.add(new IndexInfo("deleteLastXccdfIdent", indexWorkDir + File.separator + "xccdfIdent")); for (IndexInfo info : indexes) { deleteQuery(databaseManager, info.getQueryName()); if (!deleteIndexPath(info.getDirPath())) { log.warn("Failed to delete index for " + info.getDirPath()); } } } catch (SQLException e) { log.error("Caught Exception: ", e); if (e.getErrorCode() == 17002) { log.error("Unable to establish database connection."); log.error("Ensure database is available and connection details are " + "correct, then retry"); } System.exit(1); } catch (IOException e) { log.error("Caught Exception: ", e); System.exit(1); } log.info("Index files have been deleted and database has been cleaned up, " + "ready to reindex"); }
From source file:com.adobe.aem.demo.gui.AemDemo.java
public static void main(String[] args) { String demoMachineRootFolder = null; // Command line options for this tool Options options = new Options(); options.addOption("f", true, "Path to Demo Machine root folder"); CommandLineParser parser = new BasicParser(); try {/* www. ja v a2s .c o m*/ CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("f")) { demoMachineRootFolder = cmd.getOptionValue("f"); } } catch (ParseException ex) { logger.error(ex.getMessage()); } // Let's check if we have a valid build.xml file to work with... String buildFilePath = (demoMachineRootFolder != null ? demoMachineRootFolder : System.getProperty("user.dir")) + File.separator + "build.xml"; logger.debug("Trying to load build file from " + buildFilePath); buildFile = new File(buildFilePath); if (buildFile.exists() && !buildFile.isDirectory()) { // Launching the main window EventQueue.invokeLater(new Runnable() { public void run() { try { UIManager.getLookAndFeelDefaults().put("defaultFont", new Font("Arial", Font.BOLD, 14)); AemDemo window = new AemDemo(); window.frameMain.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } else { logger.error("No valid build.xml file to work with"); System.exit(-1); } }
From source file:com.asual.lesscss.LessEngineCli.java
public static void main(String[] args) throws LessException, URISyntaxException { Options cmdOptions = new Options(); cmdOptions.addOption(LessOptions.CHARSET_OPTION, true, "Input file charset encoding. Defaults to UTF-8."); cmdOptions.addOption(LessOptions.COMPRESS_OPTION, false, "Flag that enables compressed CSS output."); cmdOptions.addOption(LessOptions.CSS_OPTION, false, "Flag that enables compilation of .css files."); cmdOptions.addOption(LessOptions.LESS_OPTION, true, "Path to a custom less.js for Rhino version."); try {// w w w . j av a 2 s. co m CommandLineParser cmdParser = new GnuParser(); CommandLine cmdLine = cmdParser.parse(cmdOptions, args); LessOptions options = new LessOptions(); if (cmdLine.hasOption(LessOptions.CHARSET_OPTION)) { options.setCharset(cmdLine.getOptionValue(LessOptions.CHARSET_OPTION)); } if (cmdLine.hasOption(LessOptions.COMPRESS_OPTION)) { options.setCompress(true); } if (cmdLine.hasOption(LessOptions.CSS_OPTION)) { options.setCss(true); } if (cmdLine.hasOption(LessOptions.LESS_OPTION)) { options.setLess(new File(cmdLine.getOptionValue(LessOptions.LESS_OPTION)).toURI().toURL()); } LessEngine engine = new LessEngine(options); if (System.in.available() != 0) { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringWriter sw = new StringWriter(); char[] buffer = new char[1024]; int n = 0; while (-1 != (n = in.read(buffer))) { sw.write(buffer, 0, n); } String src = sw.toString(); if (!src.isEmpty()) { System.out.println(engine.compile(src, null, options.isCompress())); System.exit(0); } } String[] files = cmdLine.getArgs(); if (files.length == 1) { System.out.println(engine.compile(new File(files[0]), options.isCompress())); System.exit(0); } if (files.length == 2) { engine.compile(new File(files[0]), new File(files[1]), options.isCompress()); System.exit(0); } } catch (IOException ioe) { System.err.println("Error opening input file."); } catch (ParseException pe) { System.err.println("Error parsing arguments."); } String[] paths = LessEngine.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath() .split(File.separator); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar " + paths[paths.length - 1] + " input [output] [options]", cmdOptions); System.exit(1); }
From source file:licenseUtil.LicenseUtil.java
public static void main(String[] args) throws IOException, IncompleteLicenseObjectException { if (args.length == 0) { logger.error("Missing parameters. Use --help to get a list of the possible options."); } else if (args[0].equals("--addPomToTsv")) { if (args.length < 4) logger.error(//from w w w .ja v a 2 s . co m "Missing arguments for option --addPomToTsv. Please specify <pomFileName> <licenses.stub.tsv> <currentVersion> or use the option --help for further information."); String pomFN = args[1]; String spreadSheetFN = args[2]; String currentVersion = args[3]; MavenProject project = null; try { project = Utils.readPom(new File(pomFN)); } catch (XmlPullParserException e) { logger.error("Could not parse pom file: \"" + pomFN + "\""); } LicensingList licensingList = new LicensingList(); File f = new File(spreadSheetFN); if (f.exists() && !f.isDirectory()) { licensingList.readFromSpreadsheet(spreadSheetFN); } licensingList.addMavenProject(project, currentVersion); licensingList.writeToSpreadsheet(spreadSheetFN); } else if (args[0].equals("--writeLicense3rdParty")) { if (args.length < 4) logger.error( "Missing arguments for option --writeLicense3rdParty. Please provide <licenses.enhanced.tsv> <processModule> <currentVersion> [and <targetDir>] or use the option --help for further information."); String spreadSheetFN = args[1]; String processModule = args[2]; String currentVersion = args[3]; HashMap<String, String> targetDirs = new HashMap<>(); if (args.length > 4) { File targetDir = new File(args[4]); logger.info("scan pom files in direct subdirectories of \"" + targetDir.getPath() + "\" to obtain target locations for 3rd party license files..."); File[] subdirs = targetDir.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY); for (File subdir : subdirs) { File pomFile = new File(subdir.getPath() + File.separator + POM_FN); if (!pomFile.exists()) continue; MavenProject mavenProject; try { mavenProject = Utils.readPom(pomFile); } catch (Exception e) { logger.warn("Could not read from pom file: \"" + pomFile.getPath() + "\" because of " + e.getMessage()); continue; } targetDirs.put(mavenProject.getModel().getArtifactId(), subdir.getAbsolutePath()); } } LicensingList licensingList = new LicensingList(); licensingList.readFromSpreadsheet(spreadSheetFN); if (processModule.toUpperCase().equals("ALL")) { for (String module : licensingList.getNonFixedHeaders()) { try { writeLicense3rdPartyFile(module, licensingList, currentVersion, targetDirs.get(module)); } catch (NoLicenseTemplateSetException e) { logger.error("Could not write file for module \"" + module + "\". There is no template specified for \"" + e.getLicensingObject() + "\". Please add an existing template filename to the column \"" + LicensingObject.ColumnHeader.LICENSE_TEMPLATE.value() + "\" of \"" + spreadSheetFN + "\"."); } } } else { try { writeLicense3rdPartyFile(processModule, licensingList, currentVersion, targetDirs.get(processModule)); } catch (NoLicenseTemplateSetException e) { logger.error("Could not write file for module \"" + processModule + "\". There is no template specified for \"" + e.getLicensingObject() + "\". Please add an existing template filename to the column \"" + LicensingObject.ColumnHeader.LICENSE_TEMPLATE.value() + "\" of \"" + spreadSheetFN + "\"."); } } } else if (args[0].equals("--buildEffectivePom")) { Utils.writeEffectivePom(new File(args[1]), (new File(EFFECTIVE_POM_FN)).getAbsolutePath()); } else if (args[0].equals("--updateTsvWithProjectsInFolder")) { if (args.length < 4) logger.error( "Missing arguments for option --processProjectsInFolder. Please provide <superDirectory> <licenses.stub.tsv> and <currentVersion> or use the option --help for further information."); File directory = new File(args[1]); String spreadSheetFN = args[2]; String currentVersion = args[3]; LicensingList licensingList = new LicensingList(); File f = new File(spreadSheetFN); if (f.exists() && !f.isDirectory()) { licensingList.readFromSpreadsheet(spreadSheetFN); } licensingList.addAll(processProjectsInFolder(directory, currentVersion, false)); licensingList.writeToSpreadsheet(spreadSheetFN); } else if (args[0].equals("--purgeTsv")) { if (args.length < 3) logger.error( "Missing arguments for option --purgeTsv. Please provide <spreadSheetIN.tsv>, <spreadSheetOUT.tsv> and <currentVersion> or use the option --help for further information."); String spreadSheetIN = args[1]; String spreadSheetOUT = args[2]; String currentVersion = args[3]; LicensingList licensingList = new LicensingList(); licensingList.readFromSpreadsheet(spreadSheetIN); licensingList.purge(currentVersion); licensingList.writeToSpreadsheet(spreadSheetOUT); } else if (args[0].equals("--help")) { InputStream in = LicenseUtil.class.getClassLoader().getResourceAsStream(README_PATH); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line; while ((line = reader.readLine()) != null) { System.out.println(line); } } else { logger.error("Unknown parameter: " + args[0] + ". Use --help to get a list of the possible options."); } }
From source file:gemlite.core.commands.WServer.java
public static void main(String[] args2) throws Exception { String[] defaultArgs = new String[] { "D:/work/data/Gemlite-demo/target/Gemlite-demo-0.0.1-SNAPSHOT.war", "8082", "/" }; defaultArgs = args2 == null || args2.length == 0 ? defaultArgs : args2; ServerConfigHelper.initConfig();//from www. j a v a2s. co m ServerConfigHelper.initLog4j("classpath:log4j2-server.xml"); ServerConfigHelper.setProperty("bind-address", ServerConfigHelper.getConfig(ITEMS.BINDIP)); int port = 8080; String contextPath = "/"; String warPath = ""; if (defaultArgs.length < 1) { LogUtil.getCoreLog().error( "Start error,plelase Start Ws server like this : java gemlite.core.command.WServer /home/ws.war"); return; } warPath = defaultArgs[0]; File file = new File(warPath); if (!file.exists()) { LogUtil.getCoreLog().error("Error input:" + defaultArgs[0] + " war path is not existing!"); return; } if (!file.isFile()) { LogUtil.getCoreLog().error("Error input:" + defaultArgs[0] + " war path is not a valid file!"); return; } if (defaultArgs.length > 1) { port = NumberUtils.toInt(defaultArgs[1]); if (port <= 0 || port >= 65535) { LogUtil.getCoreLog().error( "Port Error:" + defaultArgs[1] + ",not a valid port , make sure port>0 and port<65535"); return; } } if (defaultArgs.length > 2) { contextPath += StringUtils.replace(defaultArgs[2], "/", ""); } try { // jetty_home String jetty_home = ServerConfigHelper.getConfig(ITEMS.GS_WORK) + File.separator + "jetty_home"; jetty_home += File.separator + StringUtils.replace(contextPath, "/", "") + port; File jfile = new File(jetty_home); jfile.mkdirs(); System.setProperty("jetty.home", jetty_home); String jetty_logs = jetty_home + File.separator + "logs" + File.separator; File logsFile = new File(jetty_logs); logsFile.mkdirs(); System.setProperty("jetty.logs", jetty_logs); Server server = new Server(); HttpConfiguration config = new HttpConfiguration(); ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(config)); connector.setReuseAddress(true); connector.setIdleTimeout(30000); connector.setPort(port); server.addConnector(connector); WebAppContext webapp = new WebAppContext(); webapp.setContextPath(contextPath); webapp.setWar(warPath); String tmpStr = jetty_home + File.separator + "webapps" + File.separator; File tmpDir = new File(tmpStr); tmpDir.mkdirs(); webapp.setTempDirectory(tmpDir); // ??? // webapp.setExtraClasspath(extrapath); webapp.setParentLoaderPriority(true); // ?Log RequestLogHandler requestLogHandler = new RequestLogHandler(); NCSARequestLog requestLog = new NCSARequestLog( jetty_logs + File.separator + "jetty-yyyy_mm_dd.request.log"); requestLog.setRetainDays(30); requestLog.setAppend(true); requestLog.setExtended(false); requestLog.setLogTimeZone(TimeZone.getDefault().getID()); requestLogHandler.setRequestLog(requestLog); webapp.setHandler(requestLogHandler); ContextHandler ch = webapp.getServletContext().getContextHandler(); ch.setLogger(new Slf4jLog("gemlite.coreLog")); server.setHandler(webapp); server.start(); System.out.println("-----------------------------------------------------"); LogUtil.getCoreLog().info("Ws Server started,You can visite -> http://" + ServerConfigHelper.getConfig(ITEMS.BINDIP) + ":" + port + contextPath); server.join(); } catch (Exception e) { LogUtil.getCoreLog().error("Ws Server error:", e); } }
From source file:mujava.cli.testnew.java
public static void main(String[] args) throws IOException { testnewCom jct = new testnewCom(); String[] argv = { "Flower", "/Users/dmark/mujava/src/Flower" }; new JCommander(jct, args); muJavaHomePath = Util.loadConfig(); // muJavaHomePath= "/Users/dmark/mujava"; // check if debug mode if (jct.isDebug() || jct.isDebugMode()) { Util.debug = true;/*w w w . java2 s. c o m*/ } System.out.println(jct.getParameters().size()); sessionName = jct.getParameters().get(0); // set first parameter as the // session name ArrayList<String> srcFiles = new ArrayList<>(); for (int i = 1; i < jct.getParameters().size(); i++) { srcFiles.add(jct.getParameters().get(i)); // retrieve all src file // names from parameters } // get all existing session name File folder = new File(muJavaHomePath); if (!folder.isDirectory()) { Util.Error("ERROR: cannot locate the folder specified in mujava.config"); return; } File[] listOfFiles = folder.listFiles(); // null checking // check the specified folder has files or not if (listOfFiles == null) { Util.Error("ERROR: no files in the muJava home folder " + muJavaHomePath); return; } List<String> fileNameList = new ArrayList<>(); for (File file : listOfFiles) { fileNameList.add(file.getName()); } // check if the session is new or not if (fileNameList.contains(sessionName)) { Util.Error("Session already exists."); } else { // create sub-directory for the session setupSessionDirectory(sessionName); // move src files into session folder for (String srcFile : srcFiles) { // new (dir, name) // check abs path or not // need to check if srcFile has .java at the end or not if (srcFile.length() > 5) { if (srcFile.substring(srcFile.length() - 5).equals(".java")) // name has .java at the end, e.g. cal.java { // delete .java, e.g. make it cal srcFile = srcFile.substring(0, srcFile.length() - 5); } } File source = new File(srcFile + ".java"); if (!source.isAbsolute()) // relative path, attach path, e.g. cal.java, make it c:\mujava\cal.java { source = new File(muJavaHomePath + "/src" + java.io.File.separator + srcFile + ".java"); } File desc = new File(muJavaHomePath + "/" + sessionName + "/src"); FileUtils.copyFileToDirectory(source, desc); // compile src files // String srcName = "t"; boolean result = compileSrc(srcFile); if (result) Util.Print("Session is built successfully."); } } // System.exit(0); }
From source file:dk.statsbiblioteket.util.qa.PackageScannerDriver.java
/** * @param args The command line arguments. * @throws IOException If command line arguments can't be passed or there * is an error reading class files. *//*from ww w.ja v a 2s. co m*/ @SuppressWarnings("deprecation") public static void main(final String[] args) throws IOException { Report report; CommandLine cli = null; String reportType, projectName, baseSrcDir, targetPackage; String[] targets = null; // Build command line options CommandLineParser cliParser = new PosixParser(); Options options = new Options(); options.addOption("h", "help", false, "Print help message and exit"); options.addOption("n", "name", true, "Project name, default 'Unknown'"); options.addOption("o", "output", true, "Type of output, 'plain' or 'html', default is html"); options.addOption("p", "package", true, "Only scan a particular package in input dirs, use dotted " + "package notation to refine selections"); options.addOption("s", "source-dir", true, "Base source dir to use in report, can be a URL. " + "@FILE@ and @MODULE@ will be escaped"); // Parse and validate command line try { cli = cliParser.parse(options, args); targets = cli.getArgs(); if (args.length == 0 || targets.length == 0 || cli.hasOption("help")) { throw new ParseException("Not enough arguments, no input files"); } } catch (ParseException e) { printHelp(options); System.exit(1); } // Extract information from command line reportType = cli.getOptionValue("output") != null ? cli.getOptionValue("output") : "html"; projectName = cli.getOptionValue("name") != null ? cli.getOptionValue("name") : "Unknown"; baseSrcDir = cli.getOptionValue("source-dir") != null ? cli.getOptionValue("source-dir") : System.getProperty("user.dir"); targetPackage = cli.getOptionValue("package") != null ? cli.getOptionValue("package") : ""; targetPackage = targetPackage.replace(".", File.separator); // Set up report type if ("plain".equals(reportType)) { report = new BasicReport(); } else { report = new HTMLReport(projectName, System.out, baseSrcDir); } // Do actual scanning of provided targets for (String target : targets) { PackageScanner scanner; File f = new File(target); if (f.isDirectory()) { scanner = new PackageScanner(report, f, targetPackage); } else { String filename = f.toString(); scanner = new PackageScanner(report, f.getParentFile(), filename.substring(filename.lastIndexOf(File.separator) + 1)); } scanner.scan(); } // Cloce the report before we exit report.end(); }