List of usage examples for org.apache.commons.vfs FileSystemManager resolveFile
public FileObject resolveFile(String name) throws FileSystemException;
From source file:org.jahia.configuration.configurators.JahiaGlobalConfigurator.java
public FileObject findVFSFile(String parentPath, String fileMatchingPattern) { Pattern matchingPattern = Pattern.compile(fileMatchingPattern); try {// w ww . ja v a 2s. c om FileSystemManager fsManager = VFS.getManager(); FileObject parentFileObject = fsManager.resolveFile(parentPath); FileObject[] children = parentFileObject.getChildren(); for (FileObject child : children) { Matcher matcher = matchingPattern.matcher(child.getName().getBaseName()); if (matcher.matches()) { return child; } } } catch (FileSystemException e) { logger.debug("Couldn't find file matching pattern " + fileMatchingPattern + " at path " + parentPath); } return null; }
From source file:org.jahia.configuration.configurators.JahiaPropertiesConfiguratorTest.java
public void testUpdateConfiguration() throws IOException { URL jahiaDefaultConfigJARURL = this.getClass().getClassLoader().getResource("jahia-default-config.jar"); // Locate the Jar file FileSystemManager fsManager = VFS.getManager(); ConfigFile jahiaPropertiesConfigFile = new VFSConfigFile( fsManager.resolveFile("jar:" + jahiaDefaultConfigJARURL.toExternalForm()), "org/jahia/defaults/config/properties/jahia.properties"); File jahiaDefaultConfigFile = new File(jahiaDefaultConfigJARURL.getFile()); String jahiaDefaultConfigFileParentPath = jahiaDefaultConfigFile.getParentFile().getPath() + File.separator; String targetJahiaPropertiesFile = jahiaDefaultConfigFileParentPath + "jahia.properties"; String secondTargetJahiaPropertiesFile = jahiaDefaultConfigFileParentPath + "jahia2.properties"; SLF4JLogger logger = new SLF4JLogger(LoggerFactory.getLogger(JahiaPropertiesConfiguratorTest.class)); jahiaPropertiesConfigFile = new VFSConfigFile( fsManager.resolveFile("jar:" + jahiaDefaultConfigJARURL.toExternalForm()), "org/jahia/defaults/config/properties/jahia.advanced.properties"); targetJahiaPropertiesFile = jahiaDefaultConfigFileParentPath + "jahia.advanced.properties"; JahiaPropertiesConfigurator websphereOracleConfigurator = new JahiaPropertiesConfigurator( oracleDBProperties, websphereOracleConfigBean); websphereOracleConfigurator.updateConfiguration(jahiaPropertiesConfigFile, targetJahiaPropertiesFile); new JahiaNodePropertiesConfigurator(logger, websphereOracleConfigBean) .updateConfiguration(jahiaPropertiesConfigFile, targetJahiaPropertiesFile); Properties websphereOracleProperties = new Properties(); FileInputStream inStream = new FileInputStream( jahiaDefaultConfigFileParentPath + "jahia.advanced.properties"); try {//from www . ja v a 2 s .co m websphereOracleProperties.load(inStream); } finally { IOUtils.closeQuietly(inStream); } // test for the additional properties assertEquals("true", websphereOracleProperties.getProperty("jahia.dm.viewer.enabled")); assertEquals("c:\\Program Files (x86)\\SWFTools\\pdf2swf.exe", websphereOracleProperties.getProperty("jahia.dm.viewer.pdf2swf")); assertNotNull(websphereOracleProperties.getProperty("auth.spnego.bypassForUrls")); JahiaPropertiesConfigurator tomcatMySQLConfigurator = new JahiaPropertiesConfigurator(mysqlDBProperties, tomcatMySQLConfigBean); tomcatMySQLConfigurator.updateConfiguration(new VFSConfigFile(fsManager, targetJahiaPropertiesFile), secondTargetJahiaPropertiesFile); new JahiaNodePropertiesConfigurator(logger, tomcatMySQLConfigBean).updateConfiguration( new VFSConfigFile(fsManager, secondTargetJahiaPropertiesFile), secondTargetJahiaPropertiesFile); Properties tomcatMySQLProperties = new Properties(); inStream = new FileInputStream(secondTargetJahiaPropertiesFile); try { tomcatMySQLProperties.load(inStream); } finally { IOUtils.closeQuietly(inStream); } //assertEquals("tomcat", tomcatMySQLProperties.getProperty("server")); }
From source file:org.jahia.configuration.configurators.VFSConfigFile.java
public VFSConfigFile(FileSystemManager fileSystemManager, String uri) throws FileSystemException { this.fileObject = fileSystemManager.resolveFile(uri); }
From source file:org.jclouds.vfs.provider.blobstore.test.BlobStoreProviderTestCase.java
private FileObject setUpTests(final FileSystemManager manager, String uri) throws FileSystemException, IOException { FileObject base = manager.resolveFile(uri); FileObject writeTests = base.resolveFile("write-tests"); FileObject readTests = base.resolveFile("read-tests"); if (base instanceof BlobStoreFileObject) { BlobStore blobStore = ((BlobStoreFileObject) base).getBlobStore(); String container = ((BlobStoreFileObject) base).getContainer(); blobStore.clearContainer(container); } else {// w ww. ja va2 s .co m writeTests.delete(new AllFileSelector()); readTests.delete(new AllFileSelector()); } writeTests.createFolder(); readTests.createFolder(); for (String name : new String[] { "file1.txt", "file%25.txt", "file space.txt" }) { writeFile(readTests, name, FILE1_CONTENT); } writeFile(readTests, "empty.txt", ""); FileObject dir = readTests.resolveFile("dir1"); dir.createFolder(); write3Files(dir); for (String subdirName : new String[] { "subdir1", "subdir2", "subdir3" }) { FileObject subdir = dir.resolveFile(subdirName); subdir.createFolder(); write3Files(subdir); } return base; }
From source file:org.josso.tooling.gshell.install.commands.InstallJavaAgentCommand.java
protected void setup() throws Exception { // ----------------------------------------------------------------------- // TODO : We could use a remote repository to get our artifacts instead of the vfs or we could use vfs providers. FileSystemManager fs = VFS.getManager(); homeDir = fs.resolveFile(getHomeDir()); libsDir = homeDir.resolveFile("dist/agents/bin"); srcsDir = homeDir.resolveFile("dist/agents/src"); trdpartyDir = libsDir.resolveFile("3rdparty"); confDir = homeDir.resolveFile("dist/agents/config/" + getTargetPlatformId()); iis32Dir = libsDir.resolveFile("Win32"); iis64Dir = libsDir.resolveFile("Win64"); }
From source file:org.josso.tooling.gshell.install.commands.InstallWebGatewayCommand.java
protected void setup() throws Exception { // ----------------------------------------------------------------------- // TODO : We could use a remote repository to get our artifacts instead of the vfs or we could use vfs providers. FileSystemManager fs = VFS.getManager(); homeDir = fs.resolveFile(getHomeDir()); appDir = homeDir.resolveFile("dist/gateway/apps"); confDir = homeDir.resolveFile("dist/gateway/config/"); log.debug("JAVA TMP : " + System.getProperty("java.io.tmpdir")); tmpDir = fs.resolveFile(System.getProperty("java.io.tmpdir")); }
From source file:org.josso.tooling.gshell.install.commands.InstallWebSamplesCommand.java
protected void setup() throws Exception { // ----------------------------------------------------------------------- // TODO : We could use a remote repository to get our artifacts instead of the vfs or we could use vfs providers. FileSystemManager fs = VFS.getManager(); homeDir = fs.resolveFile(getHomeDir()); appDir = homeDir.resolveFile("dist/samples/apps"); }
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 w w . ja v a 2s . c o m*/ // 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.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();// w w w .ja v a 2 s .c o m fileSynchronizer.updateLocal(); }
From source file:org.org.eclipse.core.utils.platform.tools.ArchivesToolBox.java
private static FileObject createFileObject(FileSystemManager fileSystemManager, File file, String archiveProtocol, String pathInArchive) throws FileSystemException { return fileSystemManager.resolveFile(archiveProtocol + "/" + file.getAbsolutePath() + pathInArchive); }