Example usage for org.apache.commons.vfs2 FileObject createFolder

List of usage examples for org.apache.commons.vfs2 FileObject createFolder

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileObject createFolder.

Prototype

void createFolder() throws FileSystemException;

Source Link

Document

Creates this folder, if it does not exist.

Usage

From source file:fi.mystes.synapse.mediator.vfs.VFSTestHelper.java

public static void createDirectory(String dirPath) throws FileSystemException {
    FileObject dir = VFS.getManager().resolveFile(dirPath);
    if (!dir.exists()) {
        dir.createFolder();
    }//w w  w  .  j  a  va 2 s .  com
}

From source file:com.stratuscom.harvester.FileUtilityImpl.java

public FileObject getWorkingDirectory(String name) throws IOException {

    FileObject workDir = getProfileDirectory().resolveFile(Strings.WORK).resolveFile(name);
    if (!workDir.exists()) {
        workDir.createFolder();
    }//from  w  ww  . j a  va  2s . c o m
    return workDir;
}

From source file:com.sonicle.webtop.vfs.sfs.StoreFileSystem.java

private void initRootFileObject() throws FileSystemException {
    configureOptions();/*from   w  ww .j  a v  a2s  .c  o  m*/
    FileSystemManager fsm = VFS.getManager();
    FileObject fo = fsm.resolveFile(uri.toString(), fso);
    if (autoCreateRoot && !fo.exists())
        fo.createFolder();
    if (fo.exists())
        rootFo = fo;
}

From source file:net.sourceforge.fullsync.fs.connection.CommonsVfsConnection.java

@Override
public final boolean makeDirectory(final File dir) throws IOException {
    FileObject obj = base.resolveFile(dir.getPath());
    obj.createFolder();
    return true;//from ww w . ja va  2s . c  om
}

From source file:hadoopInstaller.configurationGeneration.LoadFromFolder.java

@Override
public FileObject generateConfigurationFiles() throws InstallationFatalError {
    FileObject folder;
    this.log.debug("HadoopInstaller.LoadFromFolder.Loading", this.folderName);//$NON-NLS-1$
    try {//from w w  w .j a v  a  2s .co  m
        folder = this.localDirectory.resolveFile(this.folderName);
        if (!folder.exists()) {
            folder.createFolder();
            this.log.warn("HadoopInstaller.LoadFromFolder.FolderDoesntExist", //$NON-NLS-1$
                    this.folderName);
        }
    } catch (FileSystemException e) {
        throw new InstallationFatalError(e, "HadoopInstaller.LoadFromFolder.FolderCouldNotOpen", //$NON-NLS-1$
                this.folderName);
    }
    this.log.debug("HadoopInstaller.LoadFromFolder.Loaded", this.folderName); //$NON-NLS-1$
    return folder;
}

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();
    }// w  ww .j  a v  a 2 s. co 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:fi.mystes.synapse.mediator.vfs.VfsFileTransferUtility.java

/**
 * Helper method to create directory by given path.
 * /*from w  w  w .j  a v  a 2 s.  com*/
 * @param path
 *            Path object to create directory
 * @throws FileSystemException
 *             If directory creation fails
 */
private void createFolder(FileObject path) throws FileSystemException {
    path.createFolder();
}

From source file:de.innovationgate.wgpublisher.design.fs.AbstractDesignFile.java

private FileObject getOrCreateMetadataDir() throws FileSystemException, WGDesignSyncException {
    FileObject metadataDir = getMetadataDir();

    if (!metadataDir.exists() && metadataDir.getFileSystem().hasCapability(Capability.CREATE)) {
        metadataDir.createFolder();
    }//from  w  ww  .j a  v a2  s. c o m

    return metadataDir;
}

From source file:hadoopInstaller.installation.Installer.java

private void analyzeBundles() throws InstallationFatalError {
    getLog().trace("HadoopInstaller.InstallationBundles.Start"); //$NON-NLS-1$
    FileObject folder;
    try {//from  w w  w  .  ja  va2s .c  om
        folder = getLocalDirectory().resolveFile(InstallerConstants.TGZ_BUNDLES_FOLDER);
        if (!folder.exists()) {
            folder.createFolder();
            getLog().warn("HadoopInstaller.InstallationBundles.FolderDoesntExist", //$NON-NLS-1$
                    InstallerConstants.TGZ_BUNDLES_FOLDER, InstallerConstants.CONFIGURATION_FILE);
        }
    } catch (FileSystemException e) {
        throw new InstallationFatalError(e, "HadoopInstaller.InstallationBundles.FolderCouldNotOpen", //$NON-NLS-1$
                InstallerConstants.TGZ_BUNDLES_FOLDER);
    }
    for (String resource : getConfig().getFiles().keySet()) {
        String fileName = getConfig().getFiles().get(resource);
        try {
            getLog().trace("HadoopInstaller.InstallationBundles.From", resource, //$NON-NLS-1$
                    fileName);
            FileObject bundle = folder.resolveFile(fileName);
            if (!bundle.exists()) {
                throw new InstallationFatalError("HadoopInstaller.InstallationBundles.Missing", //$NON-NLS-1$
                        fileName, folder.getName().getBaseName());
            }
            if (doDeploy()) {
                getBundleHashes(bundle);
            }
            getBundleInstallDirectory(resource, bundle);
            try {
                bundle.close();
            } catch (FileSystemException ex) {
                getLog().warn(ex, "HadoopInstaller.CouldNotClose", //$NON-NLS-1$
                        fileName);
            }
        } catch (FileSystemException e) {
            throw new InstallationFatalError(e, "HadoopInstaller.InstallationBundles.Error", //$NON-NLS-1$
                    resource, fileName);
        }
        getLog().trace("HadoopInstaller.InstallationBundles.Success", //$NON-NLS-1$
                resource, fileName);
    }
    try {
        folder.close();
    } catch (FileSystemException e) {
        getLog().warn(e, "HadoopInstaller.CouldNotClose", //$NON-NLS-1$
                InstallerConstants.TGZ_BUNDLES_FOLDER);
    }
}

From source file:de.innovationgate.wgpublisher.design.fs.FileSystemDesignProvider.java

public static boolean upgradeOverlay(FileSystemDesignProvider originalDesignProvider, PluginID baseId,
        OverlayStatus status, FileObject targetFolder, String targetEncoding, Logger log,
        DesignFileValidator validator) throws Exception {

    if (!status.isUpdatedBaseDesign() && !status.isNewOverlay()) {
        throw new WGDesignSyncException(
                "Used base plugin is no higher version than overlay compliance version. Cannot perform upgrade");
    }//from w w  w. ja v a 2  s .c o m

    if (status.isNewOverlay()) {
        log.info("Initializing empty overlay");
    } else {
        log.info("Upgrading overlay from base design version " + status.getCompliantBaseVersion() + " to "
                + status.getCurrentBaseVersion());
    }

    // Creating new folders (Done separately because there may be empty folders in the overlay which would not be created via resource changes)
    for (String folder : status.getNewFolders()) {
        FileObject targetFile = targetFolder.resolveFile(folder);
        if (!targetFile.exists()) {
            log.info("Adding new overlay folder "
                    + targetFolder.getName().getRelativeName(targetFile.getName()));
            targetFile.createFolder();
        }
    }

    // Perform resource changes
    boolean conflictFileCreated = false;
    for (ChangedDocument resource : status.getChangedDocuments().values()) {
        if (performChange(resource, originalDesignProvider, status, targetEncoding, targetFolder, log,
                validator)) {
            conflictFileCreated = true;
        }
    }

    // Overwrite plugin version
    status.getOverlayData().setBasepluginVersion(baseId.getVersion().toString());

    // Write new overlay data file
    FileObject targetFCFolder = targetFolder.resolveFile(DesignDirectory.FOLDERNAME_FILES);
    FileObject systemFC = targetFCFolder.resolveFile("system");
    FileObject overlayDataFile = systemFC.resolveFile(OverlayDesignProvider.OVERLAY_DATA_FILE);
    OutputStream out = new BufferedOutputStream(overlayDataFile.getContent().getOutputStream(false));
    status.getOverlayData().write(out);
    out.flush();
    out.close();

    // Eventually update base-csconfig.xml
    FileObject baseCsConfigFile = originalDesignProvider.getFilesFolder().resolveFile("system/csconfig.xml");
    if (baseCsConfigFile.exists()) {
        String sourceHash = MD5HashingInputStream.getStreamHash(baseCsConfigFile.getContent().getInputStream());
        String targetHash = "";
        FileObject baseCsConfigFileOnOverlay = systemFC.resolveFile("base-csconfig.xml");
        if (baseCsConfigFileOnOverlay.exists()) {
            targetHash = MD5HashingInputStream
                    .getStreamHash(baseCsConfigFileOnOverlay.getContent().getInputStream());
        }
        if (!sourceHash.equals(targetHash)) {
            baseCsConfigFileOnOverlay.delete();
            FileUtil.copyContent(baseCsConfigFile, baseCsConfigFileOnOverlay);
        }
    }

    // Eventually update the dependency to the base plugin on csconfig.xml's plugin config
    FileObject overlayCsConfigFile = systemFC.resolveFile("csconfig.xml");
    if (overlayCsConfigFile.exists()) {
        CSConfig overlayCsConfig = CSConfig.load(overlayCsConfigFile);
        if (overlayCsConfig.getPluginConfig() != null) {
            boolean dependencyUpdated = false;
            for (PluginID id : overlayCsConfig.getPluginConfig().getDependencies()) {
                if (id.getUniqueName().equals(baseId.getUniqueName())
                        && !id.getVersion().equals(baseId.getVersion())) {
                    Version dependencyVersion = new Version(baseId.getVersion().getMajorVersion(),
                            baseId.getVersion().getMinorVersion(), baseId.getVersion().getMaintenanceVersion(),
                            baseId.getVersion().getPatchVersion(), 0);
                    id.setVersion(dependencyVersion);
                    dependencyUpdated = true;
                }
            }

            if (dependencyUpdated) {
                log.info("Updating dependency to base plugin in overlay plugin to new version "
                        + baseId.getVersion());
                overlayCsConfig.write(overlayCsConfigFile);
            }
        }
    }

    // Read/Write design configuration model to ensure correct storage versions of csconfig.xml (#00003634)
    FileObject designDefinitionFile = DesignDirectory.getDesignDefinitionFile(targetFolder);
    WGADesignConfigurationModel model = new WGADesignConfigurationModel(
            new File(designDefinitionFile.getName().getPath()));
    model.saveChanges();

    // Clear the overlay status
    status.overlayWasUpgraded();

    return conflictFileCreated;

}