List of usage examples for org.apache.commons.vfs2 FileObject resolveFile
FileObject resolveFile(String path) throws FileSystemException;
From source file:com.stratuscom.harvester.CommonsVFSTest.java
/** If we create a virtual file system based on a jar file, we should be able to add other jar files by adding junctions to the root, with the name of the file we're adding./*from w w w . ja va2 s . com*/ Unfortunately, this theory doesn't pan out... org.apache.commons.vfs.FileSystemException: Attempting to create a nested junction at "null/otherStart.properties". Nested junctions are not supported. at org.apache.commons.vfs.impl.VirtualFileSystem.addJunction(VirtualFileSystem.java:111) */ @Test @Ignore /*Didin't work, see above */ public void testFileSystemJunctions() throws Exception { FileObject reggieJar = fileSystemManager.resolveFile(new File("../../build/test/files"), "reggie-module.jar"); assertTrue("Bad file:" + reggieJar.toString(), reggieJar.toString().endsWith("reggie-module.jar")); FileObject reggieJarFS = fileSystemManager.createFileSystem(reggieJar); FileObject virtRoot = fileSystemManager.createVirtualFileSystem((String) null); virtRoot.getFileSystem().addJunction("/", reggieJarFS); checkPresentAndReadable(virtRoot, "start.properties"); FileObject startProperties = virtRoot.resolveFile("start.properties"); assertNotNull(startProperties); assertTrue( "Properties file unreadable:" + startProperties.toString() + " type=" + startProperties.getType(), startProperties.isReadable()); /* Now try to add in a junction to a jar file */ virtRoot.getFileSystem().addJunction("otherStart.properties", startProperties); checkPresentAndReadable(virtRoot, "otherStart.properties"); }
From source file:hadoopInstaller.installation.UploadConfiguration.java
private void modifyEnvShFile(Host host, FileObject configurationDirectory, String fileName) throws InstallationError { log.debug("HostInstallation.Upload.File.Start", //$NON-NLS-1$ fileName, host.getHostname()); FileObject configurationFile; try {/*from w w w . j ava 2 s.com*/ configurationFile = configurationDirectory.resolveFile(fileName); } catch (FileSystemException e) { throw new InstallationError(e, "HostInstallation.CouldNotOpen", //$NON-NLS-1$ fileName); } EnvShBuilder builder = new EnvShBuilder(configurationFile); String path = host.getInstallationDirectory(); URI hadoop = URI.create(MessageFormat.format("file://{0}/{1}/", //$NON-NLS-1$ path, InstallerConstants.HADOOP_DIRECTORY)); URI java = URI.create(MessageFormat.format("file://{0}/{1}/", //$NON-NLS-1$ path, InstallerConstants.JAVA_DIRECTORY)); builder.setCustomConfig(getLocalFileContents(fileName)); builder.setHadoopPrefix(hadoop.getPath()); builder.setJavaHome(java.getPath()); try { builder.build(); } catch (IOException e) { throw new InstallationError(e, "HostInstallation.CouldNotWrite", //$NON-NLS-1$ configurationFile.getName().getURI()); } try { configurationFile.close(); } catch (FileSystemException e) { log.warn("HostInstallation.CouldNotClose", //$NON-NLS-1$ configurationFile.getName().getURI()); } log.debug("HostInstallation.Upload.File.Success", //$NON-NLS-1$ fileName, host.getHostname()); }
From source file:de.innovationgate.wgpublisher.design.fs.AbstractDesignFile.java
private FileObject getMetadataDir() throws FileSystemException, WGDesignSyncException { FileObject codeFile = getCodeFile(); FileObject metadataDir = codeFile.resolveFile("../" + DesignDirectory.NAME_METADATADIR); return metadataDir; }
From source file:net.sourceforge.fullsync.ui.FileObjectChooser.java
public void setBaseFileObject(final FileObject base) { if (null == activeFileObject) { activeFileObject = base;//w ww .ja va 2 s.c o m } try { rootFileObject = base.resolveFile("/"); //$NON-NLS-1$ labelBaseUrl.setText(rootFileObject.getName().toString()); setActiveFileObject(activeFileObject); } catch (FileSystemException e) { ExceptionHandler.reportException(e); } }
From source file:de.innovationgate.wgpublisher.design.fs.FileSystemDesignProvider.java
public static void createDowngradeFiles(FileSystemDesignProvider originalDesignProvider, OverlayData data, FileObject targetFolder, String targetEncoding, Logger log) throws Exception { for (Map.Entry<String, ResourceData> resourceEntry : data.getOverlayResources().entrySet()) { boolean changed = false; FileObject targetFile = targetFolder.resolveFile(resourceEntry.getKey()); if (targetFile.exists()) { InputStream in = new BufferedInputStream(targetFile.getContent().getInputStream(), 4096); MD5HashingOutputStream out = new MD5HashingOutputStream(new NullOutputStream()); resourceInToOut(in, targetEncoding, out, targetEncoding); if (!out.getHash().equals(resourceEntry.getValue().getMd5Hash())) { changed = true;/* w ww . j a v a2 s . com*/ } } else { changed = true; } if (changed == true) { String basePath = getOverlayResourcePathInBaseDesign(resourceEntry.getKey()); FileObject sourceFile = originalDesignProvider.getBaseFolder().resolveFile(basePath); if (sourceFile.exists()) { FileObject conflictFile = createConflictFile(targetFile); log.info("Writing downgrade file of modified overlay resource " + resourceEntry.getKey() + " to conflict file: " + targetFolder.getName().getRelativeName(conflictFile.getName())); InputStream in = new BufferedInputStream(sourceFile.getContent().getInputStream(), 4096); OutputStream out = new BufferedOutputStream(conflictFile.getContent().getOutputStream(), 4096); resourceInToOut(in, originalDesignProvider.getFileEncoding(), out, targetEncoding); } else { log.warn("Overlay resource '" + resourceEntry.getKey() + "' does not exist any more in the current base design version."); } } } }
From source file:com.stratuscom.harvester.classloading.VirtualFileSystemClassLoader.java
public void addClasspathFilters(List<ClasspathFilter> filters, FileObject fileRoot) throws FileSystemException { for (ClasspathFilter filter : filters) { FileObject entryObject = fileRoot.resolveFile(filter.getJarName()); FileObject entryFileSystem = fileRoot.getFileSystem().getFileSystemManager() .createFileSystem(entryObject); classpathEntries.add(new ClasspathEntry(filter, entryFileSystem)); }//from w w w . jav a 2 s . c o m }
From source file:de.innovationgate.wgpublisher.design.fs.FileSystemDesignProvider.java
public static OverlayStatus determineOverlayStatus(FileSystemDesignProvider sourceDesignProvider, PluginID baseId, FileObject targetDirectory, String targetEncoding, Logger log, DesignFileValidator validator) throws Exception { OverlayStatus status = new OverlayStatus(); // Copy an overlay flag file to the system file container FileObject targetFCFolder = targetDirectory.resolveFile(DesignDirectory.FOLDERNAME_FILES); FileObject systemFC = targetFCFolder.resolveFile("system"); if (!systemFC.exists()) { systemFC.createFolder();//from w w w .j a v a 2 s . c o m } // Import overlay data, if available FileObject overlayDataFile = systemFC.resolveFile(OverlayDesignProvider.OVERLAY_DATA_FILE); if (overlayDataFile.exists()) { try { InputStream in = new BufferedInputStream(overlayDataFile.getContent().getInputStream()); status.setOverlayData(OverlayData.read(in)); in.close(); } catch (Exception e) { log.error("Exception reading overlay status. Creating new status file", e); } if (status.getOverlayData() != null && !status.getOverlayData().getBasepluginName().equals(baseId.getUniqueName())) { throw new WGDesignSyncException("The overlay folder '" + targetDirectory.getName().getPath() + "' is used with plugin '" + status.getOverlayData().getBasepluginName() + "' not '" + baseId.getUniqueName() + "'. Overlay status determination was canceled."); } } Version providerVersion = baseId.getVersion(); if (status.getOverlayData() == null) { OverlayData overlayData = new OverlayData(); overlayData.setBasepluginName(baseId.getUniqueName()); status.setOverlayData(overlayData); status.setNewOverlay(true); overlayData.setInitialBasepluginVersion(providerVersion.toString()); } // Test for version compatibility between base design and overlay status.setCurrentBaseVersion(providerVersion); if (status.getOverlayData().getBasepluginVersion() != null) { Version baseVersion = new Version(status.getOverlayData().getBasepluginVersion()); // Base design version is different than the compliance version of the overlay. Look if it higher (=upgrade) or lower (=error) if (!providerVersion.equals(baseVersion) || providerVersion.getBuildVersion() != baseVersion.getBuildVersion()) { if (providerVersion.compareTo(baseVersion) >= 0 || (providerVersion.equals(baseVersion) && providerVersion.getBuildVersion() > baseVersion.getBuildVersion())) { status.setUpdatedBaseDesign(true); } else if (providerVersion.compareTo(baseVersion) < 0) { throw new WGDesignSyncException("The used base design version (" + providerVersion.toString() + ") is lower than the compliant version for the overlay (" + status.getOverlayData().getBasepluginVersion() + ")."); } } } if (status.isUpdatedBaseDesign()) { log.info("Used version of base design is " + providerVersion.toString() + ". Overlay currently complies with base design version " + status.getOverlayData().getBasepluginVersion() + ". The overlay can be upgraded."); } // Gather changed resources in base design, so we can priorize them against the overlay resources FileObject sourceTmlFolder = sourceDesignProvider.getTmlFolder(); FileObject targetTmlFolder = targetDirectory.resolveFile(DesignDirectory.FOLDERNAME_TML); if (sourceTmlFolder.exists() && sourceTmlFolder.getType().equals(FileType.FOLDER)) { for (FileObject mediaKeyFolder : sourceTmlFolder.getChildren()) { FileObject overlayFolder = mediaKeyFolder.resolveFile(OverlayDesignProvider.OVERLAY_FOLDER); if (overlayFolder.exists()) { FileObject targetMediaKeyFolder = targetTmlFolder .resolveFile(mediaKeyFolder.getName().getBaseName()); determineChangedResources(WGDocument.TYPE_TML, targetMediaKeyFolder, overlayFolder, targetMediaKeyFolder, targetDirectory, sourceDesignProvider.getFileEncoding(), targetEncoding, status, log, validator); } } } FileObject targetScriptFolder = targetDirectory.resolveFile(DesignDirectory.FOLDERNAME_SCRIPT); FileObject sourceScriptFolder = sourceDesignProvider.getScriptFolder(); if (sourceScriptFolder.exists() && sourceScriptFolder.getType().equals(FileType.FOLDER)) { for (FileObject scriptTypeFolder : sourceScriptFolder.getChildren()) { FileObject overlayFolder = scriptTypeFolder.resolveFile(OverlayDesignProvider.OVERLAY_FOLDER); if (overlayFolder.exists()) { FileObject targetScriptTypeFolder = targetScriptFolder .resolveFile(scriptTypeFolder.getName().getBaseName()); determineChangedResources(WGDocument.TYPE_CSSJS, targetScriptTypeFolder, overlayFolder, targetScriptTypeFolder, targetDirectory, sourceDesignProvider.getFileEncoding(), targetEncoding, status, log, validator); } } } FileObject overlayFolder = sourceDesignProvider.getFilesFolder() .resolveFile(OverlayDesignProvider.OVERLAY_FOLDER); if (overlayFolder.exists()) { determineChangedFileContainerResources(targetFCFolder, overlayFolder, targetFCFolder, targetDirectory, null, null, status, log, validator); } return status; }
From source file:com.stratuscom.harvester.deployer.StarterServiceDeployer.java
void createWorkDirectoryFor(ApplicationEnvironment env) throws IOException { FileObject managerDir = fileUtility.getWorkingDirectory(env.getApplicationManagerName()); FileObject workingDir = managerDir.resolveFile(env.getServiceName()); if (!workingDir.exists()) { workingDir.createFolder();//from w w w. j a v a 2 s.c om } File workingDirFile = new File(workingDir.getName().getPath()); env.setWorkingDirectory(workingDirFile); }
From source file:de.innovationgate.wgpublisher.design.fs.FileSystemDesignProvider.java
private static void determineChangedResources(int resourceType, FileObject categoryFolder, FileObject source, FileObject target, FileObject baseFolder, String sourceEncoding, String targetEncoding, OverlayStatus status, Logger log, DesignFileValidator validator) throws WGDesignSyncException, NoSuchAlgorithmException, IOException { for (FileObject sourceFile : source.getChildren()) { if (!isValidDesignFile(sourceFile, validator)) { continue; }/* w w w . ja v a 2s .c o m*/ FileObject targetFile = target.resolveFile(sourceFile.getName().getBaseName()); String resourcePath = baseFolder.getName().getRelativeName(targetFile.getName()); if (sourceFile.getType().equals(FileType.FOLDER)) { if (!targetFile.exists()) { status.getNewFolders().add(targetFile.getName().getPath()); } else if (targetFile.getType().equals(FileType.FILE)) { throw new WGDesignSyncException("Unable to apply overlay. Folder '" + baseFolder.getName().getRelativeName(targetFile.getName()) + " already exists as file. Delete it to enable overlay management again"); } determineChangedResources(resourceType, categoryFolder, sourceFile, targetFile, baseFolder, sourceEncoding, targetEncoding, status, log, validator); } else if (sourceFile.getType().equals(FileType.FILE)) { // File does not exist. if (!targetFile.exists()) { // Was it once deployed? ResourceData originalHash = status.getOverlayData().getOverlayResources().get(resourcePath); if (originalHash == null) { // No, so it must be new in base status.addChangedResource(resourceType, sourceFile, targetFile, categoryFolder, OverlayStatus.ChangeType.NEW, resourcePath, null); } else { // Yes, Check if the base file changed since deployment String newHash = MD5HashingInputStream .getStreamHash(sourceFile.getContent().getInputStream()); if (newHash.equals(originalHash.getMd5Hash())) { // Nope. So this is no change. The overlay just chose not to use the file continue; } else { // Yes, so it is indeed a conflict status.addChangedResource(resourceType, sourceFile, targetFile, categoryFolder, OverlayStatus.ChangeType.CONFLICT, resourcePath, null); } } } // File does exist: Determine if is updated in base since the overlay file was deployed else { ResourceData originalHash = status.getOverlayData().getOverlayResources().get(resourcePath); if (originalHash == null) { if (!status.isUpdatedBaseDesign()) { log.info("There is no information about the original deployment state of resource " + resourcePath + ". Setting original deployment state now to the current base version."); OverlayData.ResourceData resource = new OverlayData.ResourceData(); resource.setMd5Hash( MD5HashingInputStream.getStreamHash(sourceFile.getContent().getInputStream())); status.getOverlayData().setOverlayResource(resourcePath, resource); } else { log.info("Cannot update overlay resource " + resourcePath + " as there is no information of its original deployment state."); } continue; } // First determine if the resource really changed from what was distributed String newHash = MD5HashingInputStream.getStreamHash(sourceFile.getContent().getInputStream()); if (newHash.equals(originalHash.getMd5Hash())) { continue; } // Determine if the target file is the same as was distributed. If not then it was user modified, so it is a conflict String currentHash = MD5HashingInputStream .getStreamHash(targetFile.getContent().getInputStream()); if (!currentHash.equals(originalHash.getMd5Hash())) { status.addChangedResource(resourceType, sourceFile, targetFile, categoryFolder, OverlayStatus.ChangeType.CONFLICT, resourcePath, null); } // It is a normal change else { status.addChangedResource(resourceType, sourceFile, targetFile, categoryFolder, OverlayStatus.ChangeType.CHANGED, resourcePath, null); } } } } }
From source file:com.stratuscom.harvester.deployer.StarterServiceDeployer.java
public Properties readStartProperties(FileObject serviceRoot) throws FileSystemException, LocalizedRuntimeException, IOException { /*// ww w . j a v a 2 s . com Read the start.properties file. */ FileObject startProperties = serviceRoot.resolveFile(Strings.START_PROPERTIES); if (startProperties == null || !startProperties.getType().equals(FileType.FILE) || !startProperties.isReadable()) { throw new LocalizedRuntimeException(MessageNames.BUNDLE_NAME, MessageNames.CANT_READ_START_PROPERTIES, new Object[] { Strings.START_PROPERTIES, serviceRoot.getName().getBaseName() }); } Properties startProps = propertiesFileReader.getProperties(startProperties); return startProps; }