List of usage examples for java.io File isAbsolute
public boolean isAbsolute()
From source file:org.apache.nifi.bootstrap.RunNiFi.java
private File getFile(final String filename, final File workingDir) { File file = new File(filename); if (!file.isAbsolute()) { file = new File(workingDir, filename); }// w w w . j a va 2s. c o m return file; }
From source file:com.cyberway.issue.crawler.Heritrix.java
/** * @return The directory into which we put jobs. If the system property * 'heritrix.jobsdir' is set, we will use its value in place of the default * 'jobs' directory in the current working directory. * @throws IOException//from w ww .ja va 2 s.co m */ public static File getJobsdir() throws IOException { Heritrix.loadProperties(); // if called in constructor String jobsdirStr = System.getProperty("heritrix.jobsdir", "jobs"); File jobsdir = new File(jobsdirStr); return (jobsdir.isAbsolute()) ? jobsdir : new File(getHeritrixHome(), jobsdirStr); }
From source file:org.apache.oozie.test.XTestCase.java
/** * Like {@link #setUp()} but allows skipping cleaning up the database tables. Most tests should use the other method, unless * they specifically don't want to (or can't) clean up the database tables. * * @param cleanUpDBTables true if should cleanup the database tables, false if not * @throws Exception if the test workflow working directory could not be created or there was a problem cleaning the database *//*www .ja v a2 s. c om*/ protected void setUp(boolean cleanUpDBTables) throws Exception { RUNNING_TESTCASES.incrementAndGet(); super.setUp(); String baseDir = System.getProperty(OOZIE_TEST_DIR, new File("target/test-data").getAbsolutePath()); String msg = null; File f = new File(baseDir); if (!f.isAbsolute()) { msg = XLog.format("System property [{0}]=[{1}] must be set to an absolute path", OOZIE_TEST_DIR, baseDir); } else { if (baseDir.length() < 4) { msg = XLog.format("System property [{0}]=[{1}] path must be at least 4 chars", OOZIE_TEST_DIR, baseDir); } } if (msg != null) { System.err.println(); System.err.println(msg); System.exit(-1); } f.mkdirs(); if (!f.exists() || !f.isDirectory()) { System.err.println(); System.err.println(XLog.format("Could not create test dir [{0}]", baseDir)); System.exit(-1); } hadoopVersion = System.getProperty(HADOOP_VERSION, "0.20.0"); testCaseDir = createTestCaseDir(this, true); //setting up Oozie HOME and Oozie conf directory setSystemProperty(Services.OOZIE_HOME_DIR, testCaseDir); Services.setOozieHome(); testCaseConfDir = createTestCaseSubDir("conf"); // load test Oozie site String oozieTestDB = System.getProperty("oozie.test.db", "hsqldb"); String defaultOozieSize = new File(OOZIE_SRC_DIR, "core/src/test/resources/" + oozieTestDB + "-oozie-site.xml").getAbsolutePath(); String customOozieSite = System.getProperty("oozie.test.config.file", defaultOozieSize); File source = new File(customOozieSite); if (!source.isAbsolute()) { source = new File(OOZIE_SRC_DIR, customOozieSite); } source = source.getAbsoluteFile(); InputStream oozieSiteSourceStream = null; if (source.exists()) { oozieSiteSourceStream = new FileInputStream(source); } else { // If we can't find it, try using the class loader (useful if we're using XTestCase from outside core) URL sourceURL = getClass().getClassLoader().getResource(oozieTestDB + "-oozie-site.xml"); if (sourceURL != null) { oozieSiteSourceStream = sourceURL.openStream(); } else { // If we still can't find it, then exit System.err.println(); System.err.println(XLog.format("Custom configuration file for testing does not exist [{0}]", source.getAbsolutePath())); System.err.println(); System.exit(-1); } } // Copy the specified oozie-site file from oozieSiteSourceStream to the test case dir as oozie-site.xml Configuration oozieSiteConf = new Configuration(false); oozieSiteConf.addResource(oozieSiteSourceStream); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); InputStream inputStream = classLoader.getResourceAsStream(ConfigurationService.DEFAULT_CONFIG_FILE); XConfiguration configuration = new XConfiguration(inputStream); String classes = configuration.get(Services.CONF_SERVICE_CLASSES); // Disable sharelib service as it cannot find the sharelib jars // as maven has target/classes in classpath and not the jar because test phase is before package phase oozieSiteConf.set(Services.CONF_SERVICE_CLASSES, classes.replaceAll("org.apache.oozie.service.ShareLibService,", "")); // Make sure to create the Oozie DB during unit tests oozieSiteConf.set(JPAService.CONF_CREATE_DB_SCHEMA, "true"); File target = new File(testCaseConfDir, "oozie-site.xml"); oozieSiteConf.writeXml(new FileOutputStream(target)); File hadoopConfDir = new File(testCaseConfDir, "hadoop-conf"); hadoopConfDir.mkdir(); File actionConfDir = new File(testCaseConfDir, "action-conf"); actionConfDir.mkdir(); source = new File(OOZIE_SRC_DIR, "core/src/test/resources/hadoop-config.xml"); InputStream hadoopConfigResourceStream = null; if (!source.exists()) { // If we can't find it, try using the class loader (useful if we're using XTestCase from outside core) URL sourceURL = getClass().getClassLoader().getResource("hadoop-config.xml"); if (sourceURL != null) { hadoopConfigResourceStream = sourceURL.openStream(); } else { // If we still can't find it, then exit System.err.println(); System.err.println( XLog.format("hadoop-config.xml configuration file for testing does not exist [{0}]", source.getAbsolutePath())); System.err.println(); System.exit(-1); } } else { hadoopConfigResourceStream = new FileInputStream(source); } target = new File(hadoopConfDir, "hadoop-site.xml"); IOUtils.copyStream(hadoopConfigResourceStream, new FileOutputStream(target)); if (System.getProperty("oozielocal.log") == null) { setSystemProperty("oozielocal.log", "/tmp/oozielocal.log"); } if (System.getProperty("oozie.test.hadoop.security", "simple").equals("kerberos")) { System.setProperty("oozie.service.HadoopAccessorService.kerberos.enabled", "true"); } if (System.getProperty("oozie.test.hadoop.minicluster", "true").equals("true")) { setUpEmbeddedHadoop(getTestCaseDir()); // Second cluster is not necessary without the first one if (System.getProperty("oozie.test.hadoop.minicluster2", "false").equals("true")) { setUpEmbeddedHadoop2(); } } if (System.getProperty("oozie.test.db.host") == null) { System.setProperty("oozie.test.db.host", "localhost"); } setSystemProperty(ConfigurationService.OOZIE_DATA_DIR, testCaseDir); setSystemProperty(HadoopAccessorService.SUPPORTED_FILESYSTEMS, "*"); if (mrCluster != null) { OutputStream os = new FileOutputStream(new File(hadoopConfDir, "core-site.xml")); Configuration conf = createJobConfFromMRCluster(); conf.writeXml(os); os.close(); } if (System.getProperty("oozie.test.metastore.server", "false").equals("true")) { setupHCatalogServer(); } if (System.getProperty("oozie.test.hive.server.2", "false").equals("true")) { setupHiveServer2(); } // Cleanup any leftover database data to make sure we start each test with an empty database if (cleanUpDBTables) { cleanUpDBTables(); } }
From source file:org.globus.workspace.cloud.client.AllArgs.java
private String resolvePathProperty(String key, String val, String sourcePath) { if (val.indexOf("~/") == 0) { String home_dir = System.getProperty("user.home") + "/"; val = val.replaceFirst("~/", home_dir); }//from w w w . j a va2 s . c o m File f = new File(val); if (!f.isAbsolute() && sourcePath != null) { f = new File(new File(sourcePath).getParent(), val); String path = f.getAbsolutePath(); this.print.dbg("Resolved " + key + " property relative to config file: " + val + " -> " + path); return path; } return val; }
From source file:name.livitski.databag.cli.Launcher.java
public File getMpath() { File mpath = null; if (hasOption(MEDIUM_OPTION) && 1 < options.getOptionValues(MEDIUM_OPTION).length) { mpath = new File(options.getOptionValues(MEDIUM_OPTION)[1]); if (mpath.isAbsolute()) throw new IllegalArgumentException( "Path to the bag on medium " + getMedium() + " must be relative, got: " + mpath); }/* w w w . ja va 2 s . c o m*/ return mpath; }
From source file:org.eclipse.jubula.client.ui.rcp.widgets.autconfig.AutConfigComponent.java
/** * The action of the working directory field. * @return <code>null</code> if the new value is valid. Otherwise, returns * a status parameter indicating the cause of the problem. *//* w ww . ja v a2s .co m*/ public DialogStatusParameter modifyWorkingDirFieldAction() { DialogStatusParameter error = null; boolean isEmpty = m_autWorkingDirectoryTextField.getText().length() <= 0; if (isValid(m_autWorkingDirectoryTextField, true) && !isEmpty) { if (checkLocalhostServer()) { File dir = new File(m_autWorkingDirectoryTextField.getText()); if (!dir.isAbsolute()) { // Start from server dir, rather than client dir dir = new File("../server/" + //$NON-NLS-1$ m_autWorkingDirectoryTextField.getText()); } if (!dir.isDirectory()) { try { error = createWarningStatus( NLS.bind(Messages.AUTConfigComponentNoDir, dir.getCanonicalPath())); } catch (IOException e) { error = createWarningStatus(NLS.bind(Messages.AUTConfigComponentFileNotFound, m_autWorkingDirectoryTextField.getText())); } } } } else if (!isEmpty) { error = createErrorStatus(Messages.AUTConfigComponentWrongWorkDir); } putConfigValue(AutConfigConstants.WORKING_DIR, m_autWorkingDirectoryTextField.getText()); return error; }
From source file:oracle.kv.hadoop.hive.table.TableSerDeBase.java
private String createLocalKVSecurity(final String loginFlnm, final String trustFlnm) throws SerDeException { if (loginFlnm == null) { return null; }// ww w . j a v a 2s . c o m if (trustFlnm == null) { return null; } String localLoginFile = loginFlnm; String localTrustFile = trustFlnm; final File localLoginFileFd = new File(localLoginFile); final File localTrustFileFd = new File(localTrustFile); if (!localLoginFileFd.exists() || !localTrustFileFd.exists()) { final ClassLoader cl = TableSerDeBase.class.getClassLoader(); final File userSecurityDirFd = new File(USER_SECURITY_DIR); if (!userSecurityDirFd.exists()) { if (!userSecurityDirFd.mkdirs()) { throw new SerDeException(new IOException("failed to create " + userSecurityDirFd)); } } try { if (!localTrustFileFd.exists()) { if (localTrustFileFd.isAbsolute()) { localTrustFile = localTrustFileFd.getName(); } InputStream trustStream = null; if (cl != null) { trustStream = cl.getResourceAsStream(localTrustFile); } else { trustStream = ClassLoader.getSystemResourceAsStream(localTrustFile); } final File trustFd = new File(USER_SECURITY_DIR + FILE_SEP + localTrustFile); final FileOutputStream trustFlnmFos = new FileOutputStream(trustFd); if (trustStream != null) { int nextByte = trustStream.read(); while (nextByte != -1) { trustFlnmFos.write(nextByte); nextByte = trustStream.read(); } } trustFlnmFos.close(); } if (!localLoginFileFd.exists()) { String loginFileNoPath = localLoginFile; if (localLoginFileFd.isAbsolute()) { loginFileNoPath = localLoginFileFd.getName(); } InputStream loginStream = null; if (cl != null) { loginStream = cl.getResourceAsStream(loginFileNoPath); } else { loginStream = ClassLoader.getSystemResourceAsStream(loginFileNoPath); } final Properties loginProps = new Properties(); if (loginStream != null) { loginProps.load(loginStream); } final String trustFlnmFromLogin = loginProps .getProperty(KVSecurityConstants.SSL_TRUSTSTORE_FILE_PROPERTY); if (trustFlnmFromLogin != null && !trustFlnmFromLogin.equals(localTrustFile)) { /* Replace <path>/trustFlnm with existing trustFlnm. */ loginProps.setProperty(KVSecurityConstants.SSL_TRUSTSTORE_FILE_PROPERTY, localTrustFile); } localLoginFile = USER_SECURITY_DIR + FILE_SEP + loginFileNoPath; final File loginFd = new File(localLoginFile); final FileOutputStream loginFos = new FileOutputStream(loginFd); loginProps.store(loginFos, null); loginFos.close(); } } catch (IOException e) { throw new SerDeException(e); } } return localLoginFile; }
From source file:com.github.lindenb.mscheduler.MScheduler.java
private int build(final String argv[]) { Transaction txn = null;//from w w w.ja v a 2 s . co m BufferedReader in = null; String makeExecutable = "make"; try { this.options .addOption(Option.builder(OPTION_MAKE_EXECUTABLE).hasArg(true).longOpt(OPTION_MAKE_EXECUTABLE) .argName("MAKE").desc("make executable. Default: " + makeExecutable).build()); this.options.addOption(Option.builder(OPTION_MAKEFILEIN).hasArg(true).longOpt("makefile").argName("DIR") .desc("debug Makefile").build()); final CommandLineParser parser = new DefaultParser(); this.cmdLine = parser.parse(this.options, argv); final List<String> args = this.cmdLine.getArgList(); if (cmdLine.hasOption(OPTION_MAKE_EXECUTABLE)) { makeExecutable = cmdLine.getOptionValue(OPTION_MAKE_EXECUTABLE); } if (cmdLine.hasOption(OPTION_HELP)) { return printHelp("build"); } if (parseWorkingDirectory() != 0) return -1; if (!cmdLine.hasOption(OPTION_MAKEFILEIN)) { LOG.error("option -" + OPTION_MAKEFILEIN + " undefined"); return -1; } final File makefileIn = new File(cmdLine.getOptionValue(OPTION_MAKEFILEIN)); if (!makefileIn.exists()) { System.err.println("Option -" + OPTION_MAKEFILEIN + " file doesn't exists: " + makefileIn); return -1; } if (!makefileIn.isFile()) { System.err.println("Option -" + OPTION_MAKEFILEIN + " this is not a file : " + makefileIn); return -1; } if (!makefileIn.isAbsolute() || makefileIn.getParentFile() == null) { System.err.println("Option -" + OPTION_MAKEFILEIN + " path is not absolute : " + makefileIn); return -1; } if (openEnvironement(txn, true, false) != 0) { return -1; } final List<String> cmdargs = new ArrayList<>(); cmdargs.add(makeExecutable); cmdargs.add("-ndr"); cmdargs.add("-C"); cmdargs.add(makefileIn.getParentFile().getPath()); cmdargs.add("-f"); cmdargs.add(makefileIn.getName()); for (final String arg : args) cmdargs.add(arg); LOG.info("invoking make :" + String.join(" ", cmdargs)); final ProcessBuilder procbuilder = new ProcessBuilder(cmdargs); procbuilder.directory(makefileIn.getParentFile()); final Process proc = procbuilder.start(); final StreamBoozer sb = new StreamBoozer(proc.getErrorStream(), System.err, "[make]"); sb.start(); LOG.info("Reading graph"); in = new BufferedReader(new InputStreamReader(proc.getInputStream())); final Graph graph = Graph.parse(in); IoUtils.close(in); in = null; final Task.Binding taskBinding = new Task.Binding(); int nTargets = 0; LOG.info("inserting targets"); final DatabaseEntry key = new DatabaseEntry(); final DatabaseEntry data = new DatabaseEntry(); for (final Target t : graph.getTargets()) { if (nTargets++ % 100 == 0) LOG.info("inserting " + t.getName() + " " + nTargets); final Task task = new Task(t); //skip those targets, eg. "Makefile" if (task.shellScriptLines.isEmpty() && task.getPrerequisites().isEmpty()) { task.targetStatus = TaskStatus.COMPLETED; } StringBinding.stringToEntry(t.getName(), key); taskBinding.objectToEntry(task, data); if (this.targetsDatabase.put(txn, key, data) != OperationStatus.SUCCESS) { LOG.error("Cannot insert " + task); return -1; } } LOG.info("inserting metadata"); StringBinding.stringToEntry(BASEDIRKEY, key); StringBinding.stringToEntry(makefileIn.getParentFile().getPath(), data); if (this.metaDatabase.put(txn, key, data) != OperationStatus.SUCCESS) { LOG.error("Cannot insert " + BASEDIRKEY); return -1; } return 0; } catch (Exception err) { LOG.error("Boum", err); return -1; } finally { close(); } }
From source file:org.apache.catalina.valves.ExtendedAccessLogValve.java
/** * Open the new log file for the date specified by <code>dateStamp</code>. *///from w w w .ja v a2 s.c o m private synchronized void open() { // Create the directory if necessary File dir = new File(directory); if (!dir.isAbsolute()) dir = new File(System.getProperty("catalina.base"), directory); dir.mkdirs(); // Open the current log file try { String pathname; // If no rotate - no need for dateStamp in fileName if (rotatable) { pathname = dir.getAbsolutePath() + File.separator + prefix + dateStamp + suffix; } else { pathname = dir.getAbsolutePath() + File.separator + prefix + suffix; } currentLogFile = new File(pathname); writer = new PrintWriter(new FileWriter(pathname, true), true); if (currentLogFile.length() == 0) { writer.println("#Fields: " + pattern); writer.println("#Version: 1.0"); writer.println("#Software: " + ServerInfo.getServerInfo()); } } catch (IOException e) { writer = null; currentLogFile = null; } }
From source file:com.sshtools.j2ssh.SftpClient.java
/** * * * @param remotedir//from w w w.j a v a 2 s . c o m * @param localdir * @param recurse * @param sync * @param commit * @param progress * * @return * * @throws IOException */ public DirectoryOperation copyRemoteDirectory(String remotedir, String localdir, boolean recurse, boolean sync, boolean commit, FileTransferProgress progress) throws IOException { // Create an operation object to hold the information DirectoryOperation op = new DirectoryOperation(); String actual; if (remotedir.equals("")) { actual = sftp.getDefaultDirectory(); } else { actual = resolveRemotePath(remotedir); actual = sftp.getAbsolutePath(actual); } FileAttributes attr = sftp.getAttributes(actual); if (!attr.isDirectory()) { throw new IOException(remotedir + " is not a directory"); } String cwd = actual; // Setup the local cwd String base = remotedir; int idx = base.lastIndexOf('/'); if (idx != -1) { base = base.substring(idx + 1); } File local = new File(localdir, base); if (!local.isAbsolute()) { local = new File(lpwd(), localdir); } if (!local.exists() && commit) { local.mkdir(); } if (commit && preserve) { setLocalAttrs(local.getCanonicalPath(), attr); } List files = ls(cwd); SftpFile file; File f; for (Iterator it = files.iterator(); it.hasNext();) { file = (SftpFile) it.next(); if (file.isDirectory() && !file.getFilename().equals(".") && !file.getFilename().equals("..")) { if (recurse) { f = new File(local, file.getFilename()); op.addDirectoryOperation(copyRemoteDirectory(file.getAbsolutePath(), local.getAbsolutePath(), recurse, sync, commit, progress), f); } } else if (file.isFile()) { f = new File(local, file.getFilename()); if (f.exists() && (f.length() == file.getAttributes().getSize().longValue()) && ((f.lastModified() / 1000) == file.getAttributes().getModifiedTime().longValue())) { if (commit) { op.addUnchangedFile(f); } else { op.addUnchangedFile(file); } continue; } if (f.exists()) { if (commit) { op.addUpdatedFile(f); } else { op.addUpdatedFile(file); } } else { if (commit) { op.addNewFile(f); } else { op.addNewFile(file); } } if (commit) { FileAttributes attrs = get(file.getAbsolutePath(), f.getAbsolutePath(), progress); // f.setLastModified(attrs.getModifiedTime().longValue() * 1000); } } } if (sync) { // List the contents of the new local directory and remove any // files/directories that were not updated File[] contents = local.listFiles(); if (contents != null) { for (int i = 0; i < contents.length; i++) { if (!op.containsFile(contents[i])) { op.addDeletedFile(contents[i]); if (contents[i].isDirectory() && !contents[i].getName().equals(".") && !contents[i].getName().equals("..")) { recurseMarkForDeletion(contents[i], op); if (commit) { IOUtil.recurseDeleteDirectory(contents[i]); } } else if (commit) { contents[i].delete(); } } } } } return op; }