Example usage for org.apache.commons.vfs FileObject getParent

List of usage examples for org.apache.commons.vfs FileObject getParent

Introduction

In this page you can find the example usage for org.apache.commons.vfs FileObject getParent.

Prototype

public FileObject getParent() throws FileSystemException;

Source Link

Document

Returns the folder that contains this file.

Usage

From source file:org.josso.tooling.gshell.install.installer.VFSInstaller.java

public boolean backupAgentConfigurations(boolean remove) {
    try {/*w w  w .j  a  v  a 2s .  co  m*/
        // backup josso-agent-config.xml
        FileObject agentConfigFile = targetJOSSOConfDir.resolveFile("josso-agent-config.xml");
        if (agentConfigFile.exists()) {
            // backup file in the same folder it is installed
            backupFile(agentConfigFile, agentConfigFile.getParent());
            if (remove) {
                agentConfigFile.delete();
            }
        }
    } catch (Exception e) {
        getPrinter().printErrStatus("BackupAgentConfigurations", e.getMessage());
        return false;
    }
    return true;
}

From source file:org.josso.tooling.gshell.install.installer.VFSInstaller.java

public boolean removeOldComponents(boolean backup) {
    try {/*from  www .j a  v a 2s . com*/
        FileObject[] sharedLibs = targetJOSSOSharedLibDir.getChildren();
        for (int i = 0; i < sharedLibs.length; i++) {
            FileObject jarFile = sharedLibs[i];

            if (!jarFile.getType().getName().equals(FileType.FILE.getName())) {
                // ignore folders
                continue;
            }
            if (jarFile.getName().getBaseName().startsWith("josso-")
                    && jarFile.getName().getBaseName().endsWith(".jar")) {
                if (backup) {
                    // backup files in the same folder they're installed in
                    backupFile(jarFile, jarFile.getParent());
                }
                jarFile.delete();
            }
        }

        FileObject[] libs = targetJOSSOLibDir.getChildren();
        for (int i = 0; i < libs.length; i++) {
            FileObject jarFile = libs[i];

            if (!jarFile.getType().getName().equals(FileType.FILE.getName())) {
                // ignore folders
                continue;
            }
            if (jarFile.getName().getBaseName().startsWith("josso-")
                    && jarFile.getName().getBaseName().endsWith(".jar")) {
                if (backup) {
                    // backup files in the same folder they're installed in
                    backupFile(jarFile, jarFile.getParent());
                }
                jarFile.delete();
            }
        }
    } catch (Exception e) {
        getPrinter().printErrStatus("RemoveOldComponents", e.getMessage());
        return false;
    }
    return true;
}

From source file:org.josso.tooling.gshell.install.installer.VFSInstaller.java

public boolean removeOldJar(String fullJarName, FileObject destDir, boolean backup) {
    try {/*from   www  .  j av  a  2s.  c  om*/
        if (fullJarName.endsWith(".jar") && fullJarName.lastIndexOf("-") != -1) {
            String jarNameWithoutVersion = fullJarName.substring(0, fullJarName.lastIndexOf("-"));

            FileObject[] files = destDir.getChildren();
            for (int i = 0; i < files.length; i++) {
                FileObject file = files[i];

                if (!file.getType().getName().equals(FileType.FILE.getName())) {
                    // ignore folders
                    continue;
                }

                String fileName = file.getName().getBaseName();
                if (fileName.startsWith(jarNameWithoutVersion) && fileName.endsWith(".jar")
                        && fileName
                                .substring(jarNameWithoutVersion.length(), jarNameWithoutVersion.length() + 2)
                                .matches("-[0-9]|\\.j")) {
                    if (backup) {
                        // backup files in the same folder they're installed in
                        backupFile(file, file.getParent());
                    }
                    file.delete();
                    break;
                }
            }
        }
    } catch (Exception e) {
        getPrinter().printErrStatus("RemoveOldJar", e.getMessage());
        return false;
    }
    return true;
}

From source file:org.pentaho.di.core.encryption.TwoWayPasswordEncoderPluginType.java

@Override
protected void registerXmlPlugins() throws KettlePluginException {
    for (PluginFolderInterface folder : pluginFolders) {

        if (folder.isPluginXmlFolder()) {
            List<FileObject> pluginXmlFiles = findPluginXmlFiles(folder.getFolder());
            for (FileObject file : pluginXmlFiles) {

                try {
                    Document document = XMLHandler.loadXMLFile(file);
                    Node pluginNode = XMLHandler.getSubNode(document, "plugin");
                    if (pluginNode != null) {
                        registerPluginFromXmlResource(pluginNode, KettleVFS.getFilename(file.getParent()),
                                this.getClass(), false, file.getParent().getURL());
                    }/*  w  w  w.  j a  va  2  s .  co  m*/
                } catch (Exception e) {
                    // We want to report this plugin.xml error, perhaps an XML typo or something like that...
                    //
                    log.logError("Error found while reading password encoder plugin.xml file: "
                            + file.getName().toString(), e);
                }
            }
        }
    }
}

From source file:org.pentaho.di.core.logging.LoggingPluginType.java

@Override
protected void registerXmlPlugins() throws KettlePluginException {
    for (PluginFolderInterface folder : pluginFolders) {

        if (folder.isPluginXmlFolder()) {
            List<FileObject> pluginXmlFiles = findPluginXmlFiles(folder.getFolder());
            for (FileObject file : pluginXmlFiles) {

                try {
                    Document document = XMLHandler.loadXMLFile(file);
                    Node pluginNode = XMLHandler.getSubNode(document, "plugin");
                    if (pluginNode != null) {
                        registerPluginFromXmlResource(pluginNode, KettleVFS.getFilename(file.getParent()),
                                this.getClass(), false, file.getParent().getURL());
                    }// www . jav a 2  s. c o  m
                } catch (Exception e) {
                    // We want to report this plugin.xml error, perhaps an XML typo or something like that...
                    //
                    log.logError(
                            "Error found while reading logging plugin.xml file: " + file.getName().toString(),
                            e);
                }
            }
        }
    }
}

From source file:org.pentaho.di.core.logging.LogTablePluginType.java

protected void registerXmlPlugins() throws KettlePluginException {
    for (PluginFolderInterface folder : pluginFolders) {

        if (folder.isPluginXmlFolder()) {
            List<FileObject> pluginXmlFiles = findPluginXmlFiles(folder.getFolder());
            for (FileObject file : pluginXmlFiles) {

                try {
                    Document document = XMLHandler.loadXMLFile(file);
                    Node pluginNode = XMLHandler.getSubNode(document, "plugin");
                    if (pluginNode != null) {
                        registerPluginFromXmlResource(pluginNode, KettleVFS.getFilename(file.getParent()),
                                this.getClass(), false, file.getParent().getURL());
                    }/*from   w  w  w. j av  a 2 s.c  om*/
                } catch (Exception e) {
                    // We want to report this plugin.xml error, perhaps an XML typo or something like that...
                    //
                    log.logError(
                            "Error found while reading logging plugin.xml file: " + file.getName().toString(),
                            e);
                }
            }
        }
    }
}

From source file:org.pentaho.di.core.plugins.BasePluginType.java

protected List<JarFileAnnotationPlugin> findAnnotatedClassFiles(String annotationClassName) {
    JarFileCache jarFileCache = JarFileCache.getInstance();
    List<JarFileAnnotationPlugin> classFiles = new ArrayList<JarFileAnnotationPlugin>();

    // We want to scan the plugins folder for plugin.xml files...
    ////from  w w  w . j a  v  a  2  s. c o m
    for (PluginFolderInterface pluginFolder : getPluginFolders()) {

        if (pluginFolder.isPluginAnnotationsFolder()) {

            try {
                // Get all the jar files in the plugin folder...
                //
                FileObject[] fileObjects = jarFileCache.getFileObjects(pluginFolder);
                if (fileObjects != null) {
                    for (FileObject fileObject : fileObjects) {

                        // These are the jar files : find annotations in it...
                        //
                        AnnotationDB annotationDB = jarFileCache.getAnnotationDB(fileObject);

                        // These are the jar files : find annotations in it...
                        //
                        Set<String> impls = annotationDB.getAnnotationIndex().get(annotationClassName);
                        if (impls != null) {

                            for (String fil : impls) {
                                classFiles.add(new JarFileAnnotationPlugin(fil, fileObject.getURL(),
                                        fileObject.getParent().getURL()));
                            }
                        }
                    }

                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    return classFiles;
}

From source file:org.pentaho.di.core.plugins.BasePluginType.java

protected void registerPluginJars() throws KettlePluginException {
    List<JarFileAnnotationPlugin> jarFilePlugins = findAnnotatedClassFiles(pluginType.getName());
    for (JarFileAnnotationPlugin jarFilePlugin : jarFilePlugins) {

        URLClassLoader urlClassLoader = createUrlClassLoader(jarFilePlugin.getJarFile(),
                getClass().getClassLoader());

        try {//ww w  . j av  a  2  s. c o  m
            Class<?> clazz = urlClassLoader.loadClass(jarFilePlugin.getClassName());
            if (clazz == null) {
                throw new KettlePluginException("Unable to load class: " + jarFilePlugin.getClassName());
            }
            List<String> libraries = new ArrayList<String>();
            java.lang.annotation.Annotation annotation = null;
            try {
                annotation = clazz.getAnnotation(pluginType);

                String jarFilename = URLDecoder.decode(jarFilePlugin.getJarFile().getFile(), "UTF-8");
                libraries.add(jarFilename);
                FileObject fileObject = KettleVFS.getFileObject(jarFilename);
                FileObject parentFolder = fileObject.getParent();
                String parentFolderName = KettleVFS.getFilename(parentFolder);
                String libFolderName = null;
                if (parentFolderName.endsWith(Const.FILE_SEPARATOR + "lib")) {
                    libFolderName = parentFolderName;
                } else {
                    libFolderName = parentFolderName + Const.FILE_SEPARATOR + "lib";
                }

                PluginFolder folder = new PluginFolder(libFolderName, false, false, searchLibDir);
                FileObject[] jarFiles = folder.findJarFiles(true);

                if (jarFiles != null) {
                    for (FileObject jarFile : jarFiles) {

                        String fileName = KettleVFS.getFilename(jarFile);

                        // If the plugin is in the lib folder itself, we'll ignore it here
                        if (fileObject.equals(jarFile)) {
                            continue;
                        }
                        libraries.add(fileName);
                    }
                }
            } catch (Exception e) {
                throw new KettlePluginException(
                        "Unexpected error loading class " + clazz.getName() + " of plugin type: " + pluginType,
                        e);
            }

            handlePluginAnnotation(clazz, annotation, libraries, false, jarFilePlugin.getPluginFolder());
        } catch (Exception e) {
            // Ignore for now, don't know if it's even possible.
            LogChannel.GENERAL
                    .logError("Unexpected error registering jar plugin file: " + jarFilePlugin.getJarFile(), e);
        } finally {
            if (urlClassLoader != null && urlClassLoader instanceof KettleURLClassLoader) {
                ((KettleURLClassLoader) urlClassLoader).closeClassLoader();
            }
        }
    }
}

From source file:org.pentaho.di.core.plugins.CartePluginType.java

protected void registerXmlPlugins() throws KettlePluginException {
    for (PluginFolderInterface folder : pluginFolders) {

        if (folder.isPluginXmlFolder()) {
            List<FileObject> pluginXmlFiles = findPluginXmlFiles(folder.getFolder());
            for (FileObject file : pluginXmlFiles) {

                try {
                    Document document = XMLHandler.loadXMLFile(file);
                    Node pluginNode = XMLHandler.getSubNode(document, "plugin");
                    if (pluginNode != null) {
                        registerPluginFromXmlResource(pluginNode, KettleVFS.getFilename(file.getParent()),
                                this.getClass(), false, file.getParent().getURL());
                    }/* w  w w .ja  v  a2  s. c  o m*/
                } catch (Exception e) {
                    // We want to report this plugin.xml error, perhaps an XML typo or
                    // something like that...
                    //
                    log.logError("Error found while reading step plugin.xml file: " + file.getName().toString(),
                            e);
                }
            }
        }
    }
}

From source file:org.pentaho.di.core.plugins.JobEntryPluginType.java

protected void registerXmlPlugins() throws KettlePluginException {
    for (PluginFolderInterface folder : pluginFolders) {

        if (folder.isPluginXmlFolder()) {
            List<FileObject> pluginXmlFiles = findPluginXmlFiles(folder.getFolder());
            for (FileObject file : pluginXmlFiles) {

                try {
                    Document document = XMLHandler.loadXMLFile(file);
                    Node pluginNode = XMLHandler.getSubNode(document, "plugin");

                    registerPluginFromXmlResource(pluginNode, KettleVFS.getFilename(file.getParent()),
                            this.getClass(), false, file.getParent().getURL());
                } catch (Exception e) {
                    // We want to report this plugin.xml error, perhaps an XML typo or something like that...
                    //
                    log.logError(/*  w w  w  .j  a v a2 s  .  c o m*/
                            "Error found while reading job entry plugin.xml file: " + file.getName().toString(),
                            e);
                }
            }
        }
    }
}