Search in sources :

Example 1 with IFileSystem

use of org.eclipse.core.filesystem.IFileSystem in project tesb-studio-se by Talend.

the class Activator method copyConfigs.

private void copyConfigs() throws CoreException, IOException, URISyntaxException {
    // find ESB configuration files folder in plug-in
    URL esbConfigsFolderUrl = FileLocator.find(getBundle(), new Path("esb"), null);
    if (null == esbConfigsFolderUrl) {
        getLog().log(new Status(IStatus.WARNING, getBundle().getSymbolicName(), "cannot find ESB configuration files"));
        return;
    }
    // resolve plug-in ESB config folder URL into file protocol URL
    esbConfigsFolderUrl = FileLocator.toFileURL(esbConfigsFolderUrl);
    // create ESB configuration folder under Studio instalation
    IFileSystem fileSystem = EFS.getLocalFileSystem();
    IFileStore esbConfigsTargetFolder = fileSystem.getStore(EsbConfigUtils.getEclipseEsbFolder().toURI());
    esbConfigsTargetFolder = esbConfigsTargetFolder.mkdir(EFS.SHALLOW, null);
    // retrieve all ESB configuration files packed inside plug-in
    File fileEsbConfigFolder = new File(esbConfigsFolderUrl.getPath());
    IFileStore esbConfigsFolderStore = fileSystem.getStore(fileEsbConfigFolder.toURI());
    IFileStore[] esbConfigsFolderStoreChildren = esbConfigsFolderStore.childStores(EFS.NONE, null);
    if (0 == esbConfigsFolderStoreChildren.length) {
        getLog().log(new Status(IStatus.WARNING, getBundle().getSymbolicName(), "cannot find any ESB configuration files"));
        return;
    }
    // try to copy ESB configuration files (without overwriting)
    for (IFileStore esbConfigFileStore : esbConfigsFolderStoreChildren) {
        if (!esbConfigFileStore.fetchInfo().isDirectory()) {
            String esbConfigFileName = esbConfigFileStore.fetchInfo().getName();
            try {
                esbConfigFileStore.copy(esbConfigsTargetFolder.getChild(esbConfigFileName), EFS.NONE, null);
            } catch (CoreException e) {
                // ignore to do not overwrite possible user changes in configuration files
                return;
            }
        } else {
            String esbConfigFileName = esbConfigFileStore.fetchInfo().getName();
            if ("microservice".equals(esbConfigFileName) && PluginChecker.isTIS()) {
                try {
                    esbConfigFileStore.copy(esbConfigsTargetFolder.getChild(esbConfigFileName), EFS.NONE, null);
                } catch (CoreException e) {
                    // ignore to do not overwrite possible user changes in configuration files
                    return;
                }
            }
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) IFileSystem(org.eclipse.core.filesystem.IFileSystem) IFileStore(org.eclipse.core.filesystem.IFileStore) File(java.io.File) URL(java.net.URL)

Aggregations

File (java.io.File)1 URL (java.net.URL)1 IFileStore (org.eclipse.core.filesystem.IFileStore)1 IFileSystem (org.eclipse.core.filesystem.IFileSystem)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 Path (org.eclipse.core.runtime.Path)1 Status (org.eclipse.core.runtime.Status)1