List of usage examples for org.apache.commons.vfs FileObject getFileSystem
public FileSystem getFileSystem();
From source file:org.codehaus.mojo.unix.maven.plugin.CopyArtifact.java
public AssemblyOperation createOperation(FileObject basedir, FileAttributes defaultFileAttributes, FileAttributes defaultDirectoryAttributes) throws MojoFailureException, FileSystemException, UnknownArtifactException { File artifactFile = validateArtifact(artifact); RelativePath toFile = validateAndResolveOutputFile(artifactFile, toDir, this.toFile); return new CopyFileOperation(defaultFileAttributes.useAsDefaultsFor(attributes.create()), resolve(basedir.getFileSystem(), artifactFile), toFile); }
From source file:org.codehaus.mojo.unix.maven.plugin.CopyFile.java
public AssemblyOperation createOperation(FileObject basedir, FileAttributes defaultFileAttributes, FileAttributes defaultDirectoryAttributes) throws MojoFailureException, FileSystemException { return new CopyFileOperation(defaultFileAttributes.useAsDefaultsFor(attributes.create()), resolve(basedir.getFileSystem(), path), validateAndResolveOutputFile(path, toDir, this.toFile)); }
From source file:org.codehaus.mojo.unix.maven.sysvpkg.PkgUnixPackage.java
public FileObject fromFile(final FileObject fromFile, UnixFsObject.RegularFile file) throws FileSystemException { // If it is a file on the local file system, just point the entry in the prototype file to it if (fromFile.getFileSystem() instanceof LocalFileSystem) { return fromFile; }/*from w w w .j a v a2 s . c o m*/ // Creates a file under the working directory that should match the destination path final FileObject tmpFile = workingDirectory.resolveFile(file.path.string); operations = operations.cons(new Callable() { public Object call() throws Exception { OutputStream outputStream = null; try { tmpFile.getParent().createFolder(); tmpFile.copyFrom(fromFile, Selectors.SELECT_ALL); tmpFile.getContent().setLastModifiedTime(fromFile.getContent().getLastModifiedTime()); } finally { IOUtil.close(outputStream); } return Unit.unit(); } }); return tmpFile; }
From source file:org.eclim.plugin.core.command.archive.ArchiveReadCommand.java
/** * {@inheritDoc}//from w w w .j a va2 s . co m */ public String execute(CommandLine commandLine) throws Exception { InputStream in = null; OutputStream out = null; FileSystemManager fsManager = null; try { String file = commandLine.getValue(Options.FILE_OPTION); fsManager = VFS.getManager(); FileObject fileObject = fsManager.resolveFile(file); FileObject tempFile = fsManager .resolveFile(SystemUtils.JAVA_IO_TMPDIR + "/eclim/" + fileObject.getName().getPath()); // the vfs file cache isn't very intelligent, so clear it. fsManager.getFilesCache().clear(fileObject.getFileSystem()); fsManager.getFilesCache().clear(tempFile.getFileSystem()); // NOTE: FileObject.getName().getPath() does not include the drive // information. String path = tempFile.getName().getURI().substring(URI_PREFIX.length()); // account for windows uri which has an extra '/' in front of the drive // letter (file:///C:/blah/blah/blah). if (WIN_PATH.matcher(path).matches()) { path = path.substring(1); } //if(!tempFile.exists()){ tempFile.createFile(); in = fileObject.getContent().getInputStream(); out = tempFile.getContent().getOutputStream(); IOUtils.copy(in, out); new File(path).deleteOnExit(); //} return path; } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } }
From source file:org.efaps.webdav4vfs.lock.LockManager.java
/** * Evaluate an 'If:' header condition./*from ww w .j a v a 2 s .c om*/ * The condition may be a tagged list or an untagged list. Tagged lists define the resource, the condition * applies to in front of the condition (ex. 1, 2, 5, 6). Conditions may be inverted by using 'Not' at the * beginning of the condition (ex. 3, 4, 6). The list constitutes an OR expression while the list of * conditions within braces () constitutes an AND expression. * <p/> * Evaluate example 2:<br/> * <code> * URI(/resource1) { ( * is-locked-with(urn:uuid:181d4fae-7d8c-11d0-a765-00a0c91e6bf2) * AND matches-etag(W/"A weak ETag") ) * OR ( matches-etag("strong ETag") ) } * </code> * <p/> * Examples: * <ol> * <li> <http://cid:8080/litmus/unmapped_url> (<opaquelocktoken:cd6798>)</li> * <li> </resource1> (<urn:uuid:181d4fae-7d8c-11d0-a765-00a0c91e6bf2> [W/"A weak ETag"]) (["strong ETag"])</li> * <li> (<urn:uuid:181d4fae-7d8c-11d0-a765-00a0c91e6bf2>) (Not <DAV:no-lock>)</li> * <li> (Not <urn:uuid:181d4fae-7d8c-11d0-a765-00a0c91e6bf2> <urn:uuid:58f202ac-22cf-11d1-b12d-002035b29092>)</li> * <li> </specs/rfc2518.doc> (["4217"])</li> * <li> </specs/rfc2518.doc> (Not ["4217"])</li> * </ol> * * @param contextObject the contextual resource (needed when the If: condition is not tagged) * @param ifCondition the string of the condition as sent by the If: header * @return evaluation of the condition expression * @throws ParseException if the condition does not meet the syntax requirements * @throws LockConflictException * @throws FileSystemException */ public EvaluationResult evaluateCondition(final FileObject contextObject, final String ifCondition) throws FileSystemException, LockConflictException, ParseException { List<Lock> locks = discoverLock(contextObject); final EvaluationResult evaluation = new EvaluationResult(); if ((ifCondition == null) || ifCondition.isEmpty()) { if (locks != null) { throw new LockConflictException(locks); } evaluation.result = true; return evaluation; } final Matcher matcher = IF_PATTERN.matcher(ifCondition); FileObject resource = contextObject; while (matcher.find()) { String token = matcher.group(); switch (token.charAt(0)) { case TOKEN_LOWER_THAN: String resourceUri = token.substring(1, token.length() - 1); try { resource = contextObject.getFileSystem().resolveFile(new URI(resourceUri).getPath()); locks = discoverLock(resource); } catch (URISyntaxException e) { throw new ParseException(ifCondition, matcher.start()); } break; case TOKEN_LEFT_BRACE: LOG.debug(String.format("URI(%s) {", resource)); Matcher condMatcher = CONDITION_PATTERN.matcher(token.substring(1, token.length() - 1)); boolean expressionResult = true; while (condMatcher.find()) { String condToken = condMatcher.group(); boolean negate = false; if (condToken.matches("[Nn][Oo][Tt]")) { negate = true; condMatcher.find(); condToken = condMatcher.group(); } switch (condToken.charAt(0)) { case TOKEN_LOWER_THAN: String lockToken = condToken.substring(1, condToken.length() - 1); boolean foundLock = false; if (locks != null) { for (Lock lock : locks) { if (lockToken.equals(lock.getToken())) { evaluation.locks.add(lock); foundLock = true; break; } } } final boolean foundLockResult = negate ? !foundLock : foundLock; LOG.debug(String.format(" %sis-locked-with(%s) = %b", negate ? "NOT " : "", lockToken, foundLockResult)); expressionResult = expressionResult && foundLockResult; break; case TOKEN_LEFT_BRACKET: String eTag = condToken.substring(1, condToken.length() - 1); String resourceETag = Util.getETag(resource); boolean resourceTagMatches = resourceETag.equals(eTag); final boolean matchesEtagResult = negate ? !resourceTagMatches : resourceTagMatches; LOG.debug(String.format(" %smatches-etag(%s) = %b", negate ? "NOT " : "", eTag, matchesEtagResult)); expressionResult = expressionResult && matchesEtagResult; break; default: throw new ParseException( String.format("syntax error in condition '%s' at %d", ifCondition, matcher.start() + condMatcher.start()), matcher.start() + condMatcher.start()); } } evaluation.result = evaluation.result || expressionResult; LOG.debug("} => " + evaluation.result); break; default: throw new ParseException( String.format("syntax error in condition '%s' at %d", ifCondition, matcher.start()), matcher.start()); } } // regardless of the evaluation, if the object is locked but there is no valed lock token in the // conditions we must fail with a lock conflict too if (evaluation.result && (locks != null && !locks.isEmpty()) && evaluation.locks.isEmpty()) { throw new LockConflictException(locks); } return evaluation; }
From source file:org.kalypso.simulation.grid.GridJobSubmitter.java
public void submitJob(final FileObject workingDir, final String executable, ISimulationMonitor monitor, String... arguments) throws SimulationException { if (monitor == null) { monitor = new NullSimulationMonitor(); }//from w ww.j ava 2 s . c om // prepare streams FileObject stdoutFile = null; FileObject stderrFile = null; int returnCode = IStatus.ERROR; try { // stream stdout and stderr to files stdoutFile = workingDir.resolveFile("stdout"); stderrFile = workingDir.resolveFile("stderr"); // create process handle final String processFactoryId = "org.kalypso.simulation.gridprocess"; // TODO: refactor so tempdir is created inside process final String tempDirName = workingDir.getName().getBaseName(); final IProcess process = KalypsoCommonsExtensions.createProcess(processFactoryId, tempDirName, executable, arguments); // process.setProgressMonitor( new SimulationMonitorAdaptor( monitor ) ); process.environment().put("OMP_NUM_THREADS", "4"); final FileContent stdOutContent = stdoutFile.getContent(); final OutputStream stdOut = stdOutContent.getOutputStream(); final FileContent stdErrContent = stderrFile.getContent(); final OutputStream stdErr = stdErrContent.getOutputStream(); // stage-in files final FileSystemManager manager = workingDir.getFileSystem().getFileSystemManager(); for (final URI einput : m_externalInputs.keySet()) { final FileObject inputFile = manager.resolveFile(getUriAsString(einput)); final String destName = m_externalInputs.get(einput); if (destName != null) { final FileObject destFile = workingDir.resolveFile(destName); VFSUtil.copy(inputFile, destFile, null, true); } else { VFSUtil.copy(inputFile, workingDir, null, true); } } // start process returnCode = process.startProcess(stdOut, stdErr, null, null); } catch (final CoreException e) { // when process cannot be created throw new SimulationException("Could not create process.", e); } catch (final ProcessTimeoutException e) { e.printStackTrace(); } catch (final FileNotFoundException e) { // can only happen when files cannot be created in tmpdir throw new SimulationException("Could not create temporary files for stdout and stderr.", e); } catch (final IOException e) { throw new SimulationException("Process I/O error.", e); } finally { // close files if (stdoutFile != null) { try { stdoutFile.getContent().close(); } catch (final FileSystemException e) { // gobble } } if (stderrFile != null) { try { stderrFile.getContent().close(); } catch (final FileSystemException e) { // gobble } } } // process failure handling if (returnCode != IStatus.OK) { String errString = "Process failed."; try { final FileContent content = stderrFile.getContent(); final InputStream input2 = content.getInputStream(); errString = errString + "\n" + IOUtils.toString(input2); content.close(); } catch (final IOException e) { // ignore } monitor.setFinishInfo(returnCode, errString); throw new SimulationException(errString); } else { monitor.setFinishInfo(IStatus.OK, "Process finished successfully."); } }
From source file:org.kalypso.simulation.grid.SimpleGridProcess.java
private FileObject createSandbox(final String tempDirName) throws FileSystemException { final String gridFtpRoot = "gridftp://" + m_targetHostName; final FileObject remoteRoot = m_manager.resolveFile(gridFtpRoot); final FileSystem fileSystem = remoteRoot.getFileSystem(); // get home directory of user who created this job final String homeDirString = (String) fileSystem.getAttribute("HOME_DIRECTORY"); final FileObject homeDir = remoteRoot.resolveFile(homeDirString); final FileObject workingDir = homeDir.resolveFile(tempDirName); workingDir.createFolder();//from w ww. ja va2 s .c o m return workingDir; }
From source file:org.kalypso.simulation.grid.TestGridFTP.java
public void testGridFTP() throws Exception { final FileSystemManager manager = VFSUtilities.getManager(); final FileObject remoteRoot = manager.resolveFile("gsiftp://gramd1.gridlab.uni-hannover.de"); final FileSystem fileSystem = remoteRoot.getFileSystem(); final String homeDirString = (String) fileSystem.getAttribute(GsiFtpFileProvider.ATTR_HOME_DIR); final FileObject homeDir = remoteRoot.resolveFile(homeDirString); final String testDirName = "test"; final FileObject localDir = manager.toFileObject(new File(testDirName)); final FileObject remoteDir = homeDir.resolveFile(testDirName); final FileSynchronizer fileSynchronizer = new FileSynchronizer(localDir, remoteDir); fileSynchronizer.updateRemote();//from www. j a v a 2s. c o m fileSynchronizer.updateLocal(); }
From source file:org.mule.transports.vfs.VFSConnector.java
protected void closeFileSystem(FileObject file) { FileSystem fs = file.getFileSystem(); FileSystemManager fsm = fs.getFileSystemManager(); fsm.closeFileSystem(fs);/*from w w w. j ava2 s.c om*/ }
From source file:org.objectweb.proactive.extensions.dataspaces.vfs.DefaultOptionsFileSystemManager.java
@Override public FileObject resolveFile(FileObject baseFile, String uri) throws FileSystemException { final FileSystemOptions options; if (baseFile == null) options = defaultOptions;/* www .ja v a2s . co m*/ else options = baseFile.getFileSystem().getFileSystemOptions(); return resolveFile(baseFile, uri, options); }