List of usage examples for java.io File canRead
public boolean canRead()
From source file:edu.kit.dama.util.release.GenerateSourceRelease.java
public static void main(String[] args) throws Exception { if (args.length != 3) { System.err.println("Usage: GenerateSourceRelease TYPE SOURCE DESTINATION"); System.err.println(""); System.err.println("TYPE\tThe release type. Must be one of KITDM, GENERIC_CLIENT or BARE_DEMO"); System.err.println("SOURCE\tThe source folder containing all sources for the selected release type."); System.err.println("DESTINATION\tThe destination folder where all sources of the release are placed."); System.exit(1);/*from w ww . j a va 2s .com*/ } String releaseType = args[0]; RELEASE_TYPE type = RELEASE_TYPE.KITDM; try { type = RELEASE_TYPE.valueOf(releaseType); } catch (IllegalArgumentException ex) { System.err.println( "Invalid release type. Valid relase types arguments are KITDM, GENERIC_CLIENT or BARE_DEMO"); System.exit(1); } String source = args[1]; String destination = args[2]; File sourceFile = new File(source); File destinationFile = new File(destination); if ((sourceFile.exists() && !sourceFile.isDirectory()) || (destinationFile.exists() && !destinationFile.isDirectory())) { System.err.println("Either source or destination are no directories."); System.exit(1); } if (!sourceFile.exists() || !sourceFile.canRead()) { System.err.println("Source either does not exist or is not readable."); System.exit(1); } if ((destinationFile.exists() && !sourceFile.canWrite()) || (!destinationFile.exists() && !destinationFile.mkdirs())) { System.err.println("Destination is either not writable or cannot be created."); System.exit(1); } ReleaseConfiguration config = null; switch (type) { case KITDM: config = getKITDMSourceReleaseConfig(source, destination); break; case GENERIC_CLIENT: config = getGenericRepoClientSourceReleaseConfig(source, destination); break; case BARE_DEMO: config = getBaReDemoSourceReleaseConfig(source, destination); break; } generateSourceRelease(config); System.out.println("Generating Release finished."); System.out.println("Please manually check pom.xml:"); System.out.println(" - Remove profiles"); System.out.println(" - Update links to SCM, ciManagement and internal repositories"); }
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 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 + ".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.CFAsteriskSaxSybaseLoaderCLI.CFAsteriskSaxSybaseLoaderCLI.java
public static void main(String args[]) { final String S_ProcName = "CFAsteriskSaxSybaseLoaderCLI.main() "; initConsoleLog();//from w ww . java 2s .c om 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 + ".cfasterisksybaserc"; cFAsteriskConfig.setFileName(cFAsteriskConfigFileName); File cFAsteriskConfigFile = new File(cFAsteriskConfigFileName); if (!cFAsteriskConfigFile.exists()) { cFAsteriskConfig.setDbServer("localhost"); cFAsteriskConfig.setDbPort(2345); 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 CFAsteriskSybaseSchema(); cFAsteriskSchema.setConfigurationFile(cFAsteriskConfig); ICFAsteriskSchemaObj cFAsteriskSchemaObj = new CFAsteriskSchemaObj(); cFAsteriskSchemaObj.setBackingStore(cFAsteriskSchema); CFAsteriskSaxLoaderCLI cli = new CFAsteriskSaxSybaseLoaderCLI(); 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.CFAsteriskSaxDb2LUWLoaderCLI.CFAsteriskSaxDb2LUWLoaderCLI.java
public static void main(String args[]) { final String S_ProcName = "CFAsteriskSaxDb2LUWLoaderCLI.main() "; initConsoleLog();// www .j a v a 2s . co 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 + ".cfasteriskdb2luwrc"; 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("luw"); 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 CFAsteriskDb2LUWSchema(); cFAsteriskSchema.setConfigurationFile(cFAsteriskConfig); ICFAsteriskSchemaObj cFAsteriskSchemaObj = new CFAsteriskSchemaObj(); cFAsteriskSchemaObj.setBackingStore(cFAsteriskSchema); CFAsteriskSaxLoaderCLI cli = new CFAsteriskSaxDb2LUWLoaderCLI(); 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.CFAsteriskSaxMySqlLoaderCLI.CFAsteriskSaxMySqlLoaderCLI.java
public static void main(String args[]) { final String S_ProcName = "CFAsteriskSaxMySqlLoaderCLI.main() "; initConsoleLog();// w w w . j a v a2 s . co 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 + ".cfasteriskmysqlrc"; cFAsteriskConfig.setFileName(cFAsteriskConfigFileName); File cFAsteriskConfigFile = new File(cFAsteriskConfigFileName); if (!cFAsteriskConfigFile.exists()) { cFAsteriskConfig.setDbServer("127.0.0.1"); cFAsteriskConfig.setDbPort(3306); cFAsteriskConfig.setDbDatabase("CFAst24"); cFAsteriskConfig.setDbUserName("root"); 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 CFAsteriskMySqlSchema(); cFAsteriskSchema.setConfigurationFile(cFAsteriskConfig); ICFAsteriskSchemaObj cFAsteriskSchemaObj = new CFAsteriskSchemaObj(); cFAsteriskSchemaObj.setBackingStore(cFAsteriskSchema); CFAsteriskSaxLoaderCLI cli = new CFAsteriskSaxMySqlLoaderCLI(); 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.CFAsteriskSaxOracleLoaderCLI.CFAsteriskSaxOracleLoaderCLI.java
public static void main(String args[]) { final String S_ProcName = "CFAsteriskSaxOracleLoaderCLI.main() "; initConsoleLog();/*from w w w .j a v a2 s. co 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.CFAsteriskSaxPgSqlLoaderCLI.CFAsteriskSaxPgSqlLoaderCLI.java
public static void main(String args[]) { final String S_ProcName = "CFAsteriskSaxPgSqlLoaderCLI.main() "; initConsoleLog();/*from w w w . j a v a2s .co 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:fll.scheduler.TableOptimizer.java
/** * @param args/*from www . java 2 s . c o m*/ */ public static void main(final String[] args) { LogUtils.initializeLogging(); File schedfile = null; final Options options = buildOptions(); try { final CommandLineParser parser = new PosixParser(); final CommandLine cmd = parser.parse(options, args); schedfile = new File(cmd.getOptionValue(SCHED_FILE_OPTION)); } catch (final org.apache.commons.cli.ParseException pe) { LOGGER.error(pe.getMessage()); usage(options); System.exit(1); } FileInputStream fis = null; try { if (!schedfile.canRead()) { LOGGER.fatal(schedfile.getAbsolutePath() + " is not readable"); System.exit(4); } final boolean csv = schedfile.getName().endsWith("csv"); final CellFileReader reader; final String sheetName; if (csv) { reader = new CSVCellReader(schedfile); sheetName = null; } else { sheetName = SchedulerUI.promptForSheetName(schedfile); if (null == sheetName) { return; } fis = new FileInputStream(schedfile); reader = new ExcelCellReader(fis, sheetName); } final ColumnInformation columnInfo = TournamentSchedule.findColumns(reader, new LinkedList<String>()); if (null != fis) { fis.close(); fis = null; } final List<SubjectiveStation> subjectiveStations = SchedulerUI.gatherSubjectiveStationInformation(null, columnInfo); // not bothering to get the schedule params as we're just tweaking table // assignments, which wont't be effected by the schedule params. final SchedParams params = new SchedParams(subjectiveStations, SchedParams.DEFAULT_PERFORMANCE_MINUTES, SchedParams.MINIMUM_CHANGETIME_MINUTES, SchedParams.MINIMUM_PERFORMANCE_CHANGETIME_MINUTES); final List<String> subjectiveHeaders = new LinkedList<String>(); for (final SubjectiveStation station : subjectiveStations) { subjectiveHeaders.add(station.getName()); } final String name = Utilities.extractBasename(schedfile); final TournamentSchedule schedule; if (csv) { schedule = new TournamentSchedule(name, schedfile, subjectiveHeaders); } else { fis = new FileInputStream(schedfile); schedule = new TournamentSchedule(name, fis, sheetName, subjectiveHeaders); } final TableOptimizer optimizer = new TableOptimizer(params, schedule, schedfile.getAbsoluteFile().getParentFile()); final long start = System.currentTimeMillis(); optimizer.optimize(null); final long stop = System.currentTimeMillis(); LOGGER.info("Optimization took: " + (stop - start) / 1000.0 + " seconds"); } catch (final ParseException e) { LOGGER.fatal(e, e); System.exit(5); } catch (final ScheduleParseException e) { LOGGER.fatal(e, e); System.exit(6); } catch (final IOException e) { LOGGER.fatal("Error reading file", e); System.exit(4); } catch (final RuntimeException e) { LOGGER.fatal(e, e); throw e; } catch (InvalidFormatException e) { LOGGER.fatal(e, e); System.exit(7); } finally { try { if (null != fis) { fis.close(); } } catch (final IOException e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Error closing stream", e); } } } }
From source file:com.github.rwhogg.git_vcr.App.java
/** * main is the entry point for Git-VCR//from w w w.j a va 2 s . c om * @param args Command-line arguments */ public static void main(String[] args) { Options options = parseCommandLine(args); HierarchicalINIConfiguration configuration = null; try { configuration = getConfiguration(); } catch (ConfigurationException e) { Util.error("could not parse configuration file!"); } // verify we are in a git folder and then construct the repo final File currentFolder = new File("."); FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository localRepo = null; try { localRepo = builder.findGitDir().build(); } catch (IOException e) { Util.error("not in a Git folder!"); } // deal with submodules assert localRepo != null; if (localRepo.isBare()) { FileRepositoryBuilder parentBuilder = new FileRepositoryBuilder(); Repository parentRepo; try { parentRepo = parentBuilder.setGitDir(new File("..")).findGitDir().build(); localRepo = SubmoduleWalk.getSubmoduleRepository(parentRepo, currentFolder.getName()); } catch (IOException e) { Util.error("could not find parent of submodule!"); } } // if we need to retrieve the patch file, get it now URL patchUrl = options.getPatchUrl(); String patchPath = patchUrl.getFile(); File patchFile = null; HttpUrl httpUrl = HttpUrl.get(patchUrl); if (httpUrl != null) { try { patchFile = com.twitter.common.io.FileUtils.SYSTEM_TMP.createFile(".diff"); Request request = new Request.Builder().url(httpUrl).build(); OkHttpClient client = new OkHttpClient(); Call call = client.newCall(request); Response response = call.execute(); ResponseBody body = response.body(); if (!response.isSuccessful()) { Util.error("could not retrieve diff file from URL " + patchUrl); } String content = body.string(); org.apache.commons.io.FileUtils.write(patchFile, content, (Charset) null); } catch (IOException ie) { Util.error("could not retrieve diff file from URL " + patchUrl); } } else { patchFile = new File(patchPath); } // find the patch //noinspection ConstantConditions if (!patchFile.canRead()) { Util.error("patch file " + patchFile.getAbsolutePath() + " is not readable!"); } final Git git = new Git(localRepo); // handle the branch String branchName = options.getBranchName(); String theOldCommit = null; try { theOldCommit = localRepo.getBranch(); } catch (IOException e2) { Util.error("could not get reference to current branch!"); } final String oldCommit = theOldCommit; // needed to reference from shutdown hook if (branchName != null) { // switch to the branch try { git.checkout().setName(branchName).call(); } catch (RefAlreadyExistsException e) { // FIXME Auto-generated catch block e.printStackTrace(); } catch (RefNotFoundException e) { Util.error("the branch " + branchName + " was not found!"); } catch (InvalidRefNameException e) { Util.error("the branch name " + branchName + " is invalid!"); } catch (org.eclipse.jgit.api.errors.CheckoutConflictException e) { Util.error("there was a checkout conflict!"); } catch (GitAPIException e) { Util.error("there was an unspecified Git API failure!"); } } // ensure there are no changes before we apply the patch try { if (!git.status().call().isClean()) { Util.error("cannot run git-vcr while there are uncommitted changes!"); } } catch (NoWorkTreeException e1) { // won't happen assert false; } catch (GitAPIException e1) { Util.error("call to git status failed!"); } // list all the files changed String patchName = patchFile.getName(); Patch patch = new Patch(); try { patch.parse(new FileInputStream(patchFile)); } catch (FileNotFoundException e) { assert false; } catch (IOException e) { Util.error("could not parse the patch file!"); } ReviewResults oldResults = new ReviewResults(patchName, patch, configuration, false); try { oldResults.review(); } catch (InstantiationException e1) { Util.error("could not instantiate a review tool class!"); } catch (IllegalAccessException e1) { Util.error("illegal access to a class"); } catch (ClassNotFoundException e1) { Util.error("could not find a review tool class"); } catch (ReviewFailedException e1) { e1.printStackTrace(); Util.error("Review failed!"); } // we're about to change the repo, so register a shutdown hook to clean it up Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { cleanupGit(git, oldCommit); } }); // apply the patch try { git.apply().setPatch(new FileInputStream(patchFile)).call(); } catch (PatchFormatException e) { Util.error("patch file " + patchFile.getAbsolutePath() + " is malformatted!"); } catch (PatchApplyException e) { Util.error("patch file " + patchFile.getAbsolutePath() + " did not apply correctly!"); } catch (FileNotFoundException e) { assert false; } catch (GitAPIException e) { Util.error(e.getLocalizedMessage()); } ReviewResults newResults = new ReviewResults(patchName, patch, configuration, true); try { newResults.review(); } catch (InstantiationException e1) { Util.error("could not instantiate a review tool class!"); } catch (IllegalAccessException e1) { Util.error("illegal access to a class"); } catch (ClassNotFoundException e1) { Util.error("could not find a review tool class"); } catch (ReviewFailedException e1) { e1.printStackTrace(); Util.error("Review failed!"); } // generate and show the report VelocityReport report = new VelocityReport(patch, oldResults, newResults); File reportFile = null; try { reportFile = com.twitter.common.io.FileUtils.SYSTEM_TMP.createFile(".html"); org.apache.commons.io.FileUtils.write(reportFile, report.toString(), (String) null); } catch (IOException e) { Util.error("could not generate the results page!"); } try { assert reportFile != null; Desktop.getDesktop().open(reportFile); } catch (IOException e) { Util.error("could not open the results page!"); } }
From source file:CommandLineInterpreter.java
/** * Main method, command line input will get parsed here. * * @param args//from w w w . j a v a 2 s .co m */ public static void main(String[] args) { // // test-arguments: // args = new String[] { "1.9", "-gui" }; boolean success = false; if (args.length == 1) { String arg = args[0].trim().replaceAll("[-]+", ""); if (arg.equals("help") || arg.equals("h")) printHelp(null); } if (args.length == 0) { printHelp("ONE ARGUMENT NEEDED"); } else { try { boolean guiAlert = false; Float minVersion = null; File resourcesFile = null; // ------------------------------------------------ // // -- // ------------------------------------------------ // final String minJavaVersionArgument = args[0]; if (!minJavaVersionArgument.trim().isEmpty()) { try { minVersion = Float.parseFloat(minJavaVersionArgument); } catch (Exception e) { // do nothing } } if (minVersion == null || minVersion > 2 || minVersion < 1.6) { printHelp("VERSION STRING IS NOT VALID"); } // ------------------------------------------------ // // -- // ------------------------------------------------ // for (int i = 1; i < (args.length <= 3 ? args.length : 3); i++) { final String argument = args[i].trim(); if (argument.equals("-gui")) { guiAlert = true; } else { String resourcesFilePath = argument; if (!resourcesFilePath.isEmpty()) { resourcesFile = new File(resourcesFilePath); if (!resourcesFile.exists() || !resourcesFile.isFile() || !resourcesFile.canRead()) { printHelp("RESOURCES FILE IS NOT VALID\n[" + resourcesFile.getAbsolutePath() + "]"); } } } } // ------------------------------------------------ // // -- // ------------------------------------------------ // success = checkJREVersion(minVersion, guiAlert); if (success && resourcesFile != null) { success = checkResources(resourcesFile, guiAlert); } } catch (Exception e) { success = false; e.printStackTrace(); } } if (!success) { // set error exit code System.exit(1); } }