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

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

Introduction

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

Prototype

public FileName getName();

Source Link

Document

Returns the name of this file.

Usage

From source file:org.josso.tooling.gshell.install.commands.InstallWebGatewayCommand.java

protected void installConfig() throws Exception {

    if (copyConfigFiles) {
        // Generate a key for rememberme auth
        SecretKeySpec key = CipherUtil.generateAESKey();
        byte[] keyBytes = key.getEncoded();
        String keyStr = CipherUtil.encodeBase64(keyBytes);

        FileObject authProperties = tmpDir.resolveFile("josso-auth.properties");

        authProperties.createFile();/*from w w w  . j av  a  2s . co  m*/
        OutputStream os = authProperties.getContent().getOutputStream(true);
        java.util.Properties authProps = new java.util.Properties();

        authProps.setProperty("josso.rememberme.authscheme.key", keyStr);
        authProps.store(os, "JOSSO 'Remember Me' authentication schemem properties.");

        printer.printActionOkStatus("Generating", "'Remember Me' AES key",
                "Created " + authProperties.getName().getFriendlyURI());

        getInstaller().installConfiguration(
                createArtifact(tmpDir.getURL().toString(), JOSSOScope.GATEWAY, "josso-auth.properties"),
                isReplaceConfig());
        try {
            authProperties.delete();
        } catch (java.io.IOException e) {
            /* */ }

        String persistenceFileName = "josso-gateway-" + persistence + "-stores.xml";
        printer.printActionOkStatus("Using", "'" + persistence + "' default configuration",
                "Installing " + persistenceFileName + " as " + "josso-gateway-stores.xml");

        // Install all configuration files :
        FileObject[] libs = confDir.getChildren();
        for (int i = 0; i < confDir.getChildren().length; i++) {
            FileObject cfgFile = libs[i];

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

            String fileName = cfgFile.getName().getBaseName();
            if (fileName.equals(persistenceFileName)) {
                getInstaller().installConfiguration(
                        createArtifact(confDir.getURL().toString(), JOSSOScope.GATEWAY, fileName),
                        "josso-gateway-stores.xml", isReplaceConfig());
            }

            getInstaller().installConfiguration(
                    createArtifact(confDir.getURL().toString(), JOSSOScope.GATEWAY, fileName),
                    isReplaceConfig());
        }
    } else {
        //TODO backup configuration files, if they exist
        io.out.println("Backup and remove existing configuration files");
        getInstaller().backupGatewayConfigurations(true);
    }

}

From source file:org.josso.tooling.gshell.install.commands.InstallWebSamplesCommand.java

protected void deployWar() throws Exception {

    for (FileObject child : appDir.getChildren()) {
        getInstaller().installApplication(
                createArtifact(appDir.getURL().toString(), JOSSOScope.AGENT, child.getName().getBaseName()),
                true);//from   w  w w.  ja va2s  .  c om
    }

}

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

public void installApplication(JOSSOArtifact artifact, boolean replace) throws InstallException {
    try {//from www  .j  ava2 s .  com
        // If the war is already expanded, copy it with a new name.
        FileObject srcFile = getFileSystemManager().resolveFile(artifact.getLocation());

        // Is this the josso gateaway ?
        String name = artifact.getBaseName();
        boolean isFolder = srcFile.getType().equals(FileType.FOLDER);

        if (artifact.getType().equals("war") && name.startsWith("josso-gateway-web")) {
            // INSTALL GWY
            String newName = "josso.war";

            // Do we have to explode the war ?
            if (getTargetPlatform().isJOSSOWarExploded() && !isFolder) {
                installJar(srcFile, this.targetDeployDir, newName, true, replace);

                if (getTargetPlatform().getVersion().startsWith("6")) {
                    // Under JBoss 6 remove commons logging JAR files which conflict with slf4j replacement
                    FileObject webInfLibFolder = targetDeployDir.resolveFile(newName + "/WEB-INF/lib");

                    boolean exists = webInfLibFolder.exists();

                    if (exists) {
                        FileObject[] sharedLibs = webInfLibFolder.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("commons-logging")
                                    && jarFile.getName().getBaseName().endsWith(".jar")) {
                                jarFile.delete();
                            }
                        }
                    }
                }
            } else {
                installFile(srcFile, this.targetDeployDir, replace);
            }
            return;
        }

        if ((getTargetPlatform().getVersion().startsWith("5")
                || getTargetPlatform().getVersion().startsWith("6")) && artifact.getType().equals("ear")
                && artifact.getBaseName().startsWith("josso-partner-jboss5")) {
            installFile(srcFile, this.targetDeployDir, replace);
            return;
        } else if (!(getTargetPlatform().getVersion().startsWith("5")
                || getTargetPlatform().getVersion().startsWith("6")) && artifact.getType().equals("ear")
                && artifact.getBaseName().startsWith("josso-partner-jboss-app")) {
            installFile(srcFile, this.targetDeployDir, replace);
            return;
        }

        log.debug("Skipping partner application : " + srcFile.getName().getFriendlyURI());

    } catch (IOException e) {
        throw new InstallException(e.getMessage(), e);
    }
}

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

protected void configureServerXml() throws InstallException {

    // --------------------------------------------------------------------
    // Configure server.xml
    // --------------------------------------------------------------------
    // We will use xupdate to alter catalina configuration : server.xml
    FileObject serverXml = null;/*w  w  w. j  av  a  2 s  . co m*/
    try {

        String jbossWeb = "jbossweb.sar"; // jboss 5 by default
        if (getPlatformVersion().startsWith("4.2"))
            jbossWeb = "jboss-web.deployer";
        else if (getPlatformVersion().startsWith("4.0"))
            jbossWeb = "jbossweb-tomcat55.sar";
        else if (getPlatformVersion().startsWith("3.2"))
            jbossWeb = "jbossweb-tomcat50.sar";

        FileObject targetJBossWebDir = targetDeployDir.resolveFile(jbossWeb);
        serverXml = targetJBossWebDir.resolveFile("server.xml");

        // Get a DOM document of the server.xml :
        Node serverXmlDom = readContentAsDom(serverXml);

        boolean modified = false;

        // Perfomr specific configurations
        if (configureRealm(serverXmlDom))
            modified = true;

        if (configureValve(serverXmlDom))
            modified = true;

        if (modified) {
            // Backup Container configuration.  If we cannot perform a backup, do nothing
            if (!backupFile(serverXml, targetJBossWebDir)) {
                getPrinter().printActionWarnStatus("Configure",
                        targetJBossWebDir.getName().getFriendlyURI() + "/server.xml",
                        "Must be done manually (Follow setup guide)");
                return;
            }

            // Write modifications to file
            writeContentFromDom(serverXmlDom, serverXml);
            getPrinter().printActionOkStatus("Save", serverXml.getName().getBaseName(),
                    serverXml.getName().getFriendlyURI());
        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        getPrinter().printErrStatus("Cannot configure container : ", e.getMessage());
        getPrinter().printActionWarnStatus("Configure",
                targetConfDir.getName().getFriendlyURI() + "/server.xml",
                "Must be done manually (Follow setup guide)");
    }
}

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

protected void configureLoginConfigXml() throws InstallException {
    // --------------------------------------------------------------------
    // Configure login-config.xml
    // --------------------------------------------------------------------

    // We will use xupdate to alter catalina configuration : server.xml
    FileObject loginConfigXml = null;

    try {//w ww. j  a va  2 s  .co  m

        // Get a DOM document of the server.xml :
        loginConfigXml = targetConfDir.resolveFile("login-config.xml");
        Document loginConfigXmlDom = readContentAsDom(loginConfigXml);

        boolean modified = false;
        // Perfomr specific configurations
        if (configureLoginConfig(loginConfigXmlDom))
            modified = true;

        // Write modifications to file
        if (modified) {
            if (!backupFile(loginConfigXml, targetConfDir)) {
                getPrinter().printActionWarnStatus("Configure", loginConfigXml.getName().getFriendlyURI(),
                        "Must be done manually (Follow setup guide)");
                return;
            }

            writeContentFromDom(loginConfigXmlDom, loginConfigXml);
            getPrinter().printActionOkStatus("Save", loginConfigXml.getName().getBaseName(),
                    loginConfigXml.getName().getFriendlyURI());
        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        getPrinter().printErrStatus("Cannot configure container : ", e.getMessage());
        getPrinter().printActionWarnStatus("Configure",
                targetConfDir.getName().getFriendlyURI() + "/login-config.xml",
                "Must be done manually (Follow setup guide)");
    }

}

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

public void install3rdPartyComponent(JOSSOArtifact artifact, boolean replace) throws InstallException {

    if (artifact.getBaseName().startsWith("log4j") || artifact.getBaseName().startsWith("spring-2.0"))
        return;//from   w  w w.  j  a  v a 2s .  c  o m

    if (artifact.getBaseName().startsWith("slf4j"))
        return;

    if (artifact.getBaseName().startsWith("jcl-over-slf4j"))
        return;

    if (artifact.getBaseName().startsWith("logback"))
        return;

    try {

        FileObject srcFile = getFileSystemManager().resolveFile(artifact.getLocation());

        // Some jars must be copied in special directories in Tomcat 5.5 / 5.0
        if (getTargetPlatform().getVersion().startsWith("5.")) {

            if (artifact.getBaseName().startsWith("commons-collections")) {
                removeOldJar(srcFile.getName().getBaseName(), this.targetEndorsedLibDir, true);
                installFile(srcFile, this.targetEndorsedLibDir, replace);
            } else {
                removeOldJar(srcFile.getName().getBaseName(), this.targetLibDir, true);
                installFile(srcFile, this.targetLibDir, replace);
            }

        } else if (getTargetPlatform().getVersion().startsWith("6.0")
                || getTargetPlatform().getVersion().startsWith("7.0")) {

            // Minmal set of dependencies for TC 6/7
            if (artifact.getBaseName().startsWith("spring-")) {
                removeOldJar(srcFile.getName().getBaseName(), this.targetLibDir, true);
                installFile(srcFile, this.targetLibDir, replace);
            } else if (artifact.getBaseName().startsWith("xbean-")) {
                removeOldJar(srcFile.getName().getBaseName(), this.targetLibDir, true);
                installFile(srcFile, this.targetLibDir, replace);
            } else if (artifact.getBaseName().startsWith("commons-")) {
                removeOldJar(srcFile.getName().getBaseName(), this.targetLibDir, true);
                installFile(srcFile, this.targetLibDir, replace);
            }

        } else {
            removeOldJar(srcFile.getName().getBaseName(), this.targetLibDir, true);
            installFile(srcFile, this.targetLibDir, replace);
        }

    } catch (IOException e) {
        throw new InstallException(e.getMessage(), e);
    }
}

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

@Override
public void installConfiguration(JOSSOArtifact artifact, boolean replace) throws InstallException {
    try {//w  w w.  j av a2 s. c om
        FileObject srcFile = getFileSystemManager().resolveFile(artifact.getLocation());

        String name = srcFile.getName().getBaseName();

        if (name.startsWith("setenv")) {
            installFile(srcFile, this.targetBinDir, replace);
        } else if (name.equals("jaas.conf")) {
            installFile(srcFile, this.targetConfDir, replace);
        } else {
            installFile(srcFile, this.targetJOSSOConfDir, replace);
        }
    } catch (IOException e) {
        throw new InstallException(e.getMessage(), e);
    }

}

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

@Override
public boolean backupAgentConfigurations(boolean remove) {
    try {/*w  w  w .j  a v  a2s.c o m*/
        super.backupAgentConfigurations(remove);
        // backup jaas.conf
        FileObject jaasConfigFile = targetConfDir.resolveFile("jaas.conf");
        if (jaasConfigFile.exists()) {
            // backup file in the same folder it is installed
            backupFile(jaasConfigFile, jaasConfigFile.getParent());
            if (remove) {
                jaasConfigFile.delete();
            }
        }
        // backup setenv.sh and setenv.bat
        FileObject[] libs = targetBinDir.getChildren();
        for (int i = 0; i < libs.length; i++) {
            FileObject cfgFile = libs[i];

            if (!cfgFile.getType().getName().equals(FileType.FILE.getName())) {
                // ignore folders
                continue;
            }
            if (cfgFile.getName().getBaseName().startsWith("setenv")
                    && (cfgFile.getName().getBaseName().endsWith(".sh")
                            || cfgFile.getName().getBaseName().endsWith(".bat"))) {
                // backup files in the same folder they're installed in
                backupFile(cfgFile, cfgFile.getParent());
                if (remove) {
                    cfgFile.delete();
                }
            }
        }
    } catch (Exception e) {
        getPrinter().printErrStatus("BackupAgentConfigurations", e.getMessage());
        return false;
    }
    return true;
}

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

protected void configureServerXml() throws InstallException {
    // --------------------------------------------------------------------
    // Configure server.xml
    // --------------------------------------------------------------------

    // We will use xupdate to alter catalina configuration : server.xml
    FileObject serverXml = null;

    try {//from  w  ww .jav  a  2s  .c  o m

        serverXml = targetConfDir.resolveFile("server.xml");

        // Get a DOM document of the server.xml :
        Node serverXmlDom = readContentAsDom(serverXml);

        boolean modified = false;

        // Perfomr specific configurations
        if (configureRealm(serverXmlDom))
            modified = true;

        if (configureValve(serverXmlDom))
            modified = true;

        if (modified) {

            // Backup Container configuration.  If we cannot perform a backup, do nothing
            if (!backupFile(serverXml, targetConfDir)) {
                getPrinter().printActionWarnStatus("Configure",
                        targetConfDir.getName().getFriendlyURI() + "/server.xml",
                        "Must be done manually (Follow setup guide)");
                return;
            }

            // Write modifications to file
            writeContentFromDom(serverXmlDom, serverXml);
            getPrinter().printActionOkStatus("Save", serverXml.getName().getBaseName(),
                    serverXml.getName().getFriendlyURI());

        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        getPrinter().printErrStatus("Cannot configure container : ", e.getMessage());
        getPrinter().printActionWarnStatus("Configure",
                targetConfDir.getName().getFriendlyURI() + "/server.xml",
                "Must be done manually (Follow setup guide)");
    }

}

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

/**
 * Default implementation for 3rd party jars install
 *
 * @param artifact/*from  w  w  w  .  j a va2s .c  om*/
 * @param replace
 * @throws InstallException
 */
public void install3rdPartyComponent(JOSSOArtifact artifact, boolean replace) throws InstallException {
    try {
        FileObject srcFile = getFileSystemManager().resolveFile(artifact.getLocation());
        removeOldJar(srcFile.getName().getBaseName(), this.targetLibDir, false);
        installFile(srcFile, this.targetLibDir, replace);
    } catch (IOException e) {
        throw new InstallException(e.getMessage(), e);
    }
}