Search in sources :

Example 16 with TFile

use of de.schlichtherle.truezip.file.TFile in project alfresco-repository by Alfresco.

the class WarHelperImpl method listModules.

/**
 * Lists all the currently installed modules in the WAR
 *
 * @param war the war
 * @throws ModuleManagementToolException
 */
@Override
public List<ModuleDetails> listModules(TFile war) {
    List<ModuleDetails> moduleDetails = new ArrayList<>();
    boolean moduleFound = false;
    TFile moduleDir = new TFile(war, WarHelper.MODULE_NAMESPACE_DIR);
    if (moduleDir.exists() == false) {
        // empty
        return moduleDetails;
    }
    java.io.File[] dirs = moduleDir.listFiles();
    if (dirs != null && dirs.length != 0) {
        for (java.io.File dir : dirs) {
            if (dir.isDirectory() == true) {
                TFile moduleProperties = new TFile(dir.getPath() + WarHelper.MODULE_CONFIG_IN_WAR);
                if (moduleProperties.exists() == true) {
                    InputStream is = null;
                    try {
                        moduleFound = true;
                        is = new TFileInputStream(moduleProperties);
                        moduleDetails.add(ModuleDetailsHelper.createModuleDetailsFromPropertiesStream(is));
                    } catch (AlfrescoRuntimeException exception) {
                        throw new ModuleManagementToolException("Unable to open module properties file '" + moduleProperties.getPath() + "' " + exception.getMessage(), exception);
                    } catch (IOException exception) {
                        throw new ModuleManagementToolException("Unable to open module properties file '" + moduleProperties.getPath() + "'", exception);
                    } finally {
                        if (is != null) {
                            try {
                                is.close();
                            } catch (Throwable e) {
                            }
                        }
                    }
                }
            }
        }
    }
    return moduleDetails;
}
Also used : TFileInputStream(de.schlichtherle.truezip.file.TFileInputStream) InputStream(java.io.InputStream) TFileInputStream(de.schlichtherle.truezip.file.TFileInputStream) ArrayList(java.util.ArrayList) ModuleDetails(org.alfresco.service.cmr.module.ModuleDetails) IOException(java.io.IOException) TFile(de.schlichtherle.truezip.file.TFile) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) TFile(de.schlichtherle.truezip.file.TFile)

Example 17 with TFile

use of de.schlichtherle.truezip.file.TFile in project alfresco-repository by Alfresco.

the class WarHelperImpl method backup.

/**
 * Backs up a given file or directory.
 *
 * @param file   the file to backup
 * @return the absolute path to the backup file.
 */
@Override
public String backup(TFile file) throws IOException {
    String backupLocation = file.getAbsolutePath() + "-" + System.currentTimeMillis() + ".bak";
    if (file.isArchive()) {
        log.info("Backing up file...");
        TFile source = new TFile(file.getAbsolutePath(), TArchiveDetector.NULL);
        TFile backup = new TFile(backupLocation, TArchiveDetector.NULL);
        // Just copy the file
        source.cp_rp(backup);
    } else {
        log.info("Backing up DIRECTORY...");
        TFile backup = new TFile(backupLocation);
        // Copy the directory
        file.cp_rp(backup);
    }
    log.info("The back up is at '" + backupLocation + "'");
    return backupLocation;
}
Also used : TFile(de.schlichtherle.truezip.file.TFile)

Example 18 with TFile

use of de.schlichtherle.truezip.file.TFile in project alfresco-repository by Alfresco.

the class WarHelperImpl method checkCompatibleEdition.

@Override
public void checkCompatibleEdition(TFile war, ModuleDetails installingModuleDetails) {
    List<String> installableEditions = installingModuleDetails.getEditions();
    if (installableEditions != null && installableEditions.size() > 0) {
        TFile propsFile = new TFile(war + VERSION_PROPERTIES);
        if (propsFile != null && propsFile.exists()) {
            Properties warVers = loadProperties(propsFile);
            String warEdition = warVers.getProperty("version.edition");
            for (String edition : installableEditions) {
                if (warEdition.equalsIgnoreCase(edition)) {
                    // successful match.
                    return;
                }
            }
            throw new ModuleManagementToolException("The module (" + installingModuleDetails.getTitle() + ") can only be installed in one of the following editions" + installableEditions);
        } else {
            checkCompatibleEditionUsingManifest(war, installingModuleDetails);
        }
    }
}
Also used : TFile(de.schlichtherle.truezip.file.TFile) Properties(java.util.Properties)

Example 19 with TFile

use of de.schlichtherle.truezip.file.TFile in project alfresco-repository by Alfresco.

the class InstalledFiles method save.

/**
 * Saves the current modification details into the WAR
 */
public void save() {
    try {
        TFile file = new TFile(getFileLocation());
        if (file.exists() == false) {
            file.createNewFile();
        }
        TFileOutputStream os = new TFileOutputStream(file);
        try {
            for (String add : this.adds) {
                String output = MOD_ADD_FILE + DELIMITER + add + "\n";
                os.write(output.getBytes());
            }
            for (Map.Entry<String, String> update : this.updates.entrySet()) {
                String output = MOD_UPDATE_FILE + DELIMITER + update.getKey() + DELIMITER + update.getValue() + "\n";
                os.write(output.getBytes());
            }
            for (String mkdir : this.mkdirs) {
                String output = MOD_MK_DIR + DELIMITER + mkdir + "\n";
                os.write(output.getBytes());
            }
        } finally {
            os.close();
        }
    } catch (IOException exception) {
        throw new ModuleManagementToolException("Error whilst saving modifications file.", exception);
    }
}
Also used : TFile(de.schlichtherle.truezip.file.TFile) TFileOutputStream(de.schlichtherle.truezip.file.TFileOutputStream) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 20 with TFile

use of de.schlichtherle.truezip.file.TFile in project alfresco-repository by Alfresco.

the class InstalledFiles method load.

/**
 * Loads the exisiting information about the installed files from the WAR
 */
public void load() {
    TFile file = new TFile(getFileLocation());
    if (file.exists() == true) {
        try {
            BufferedReader reader = new BufferedReader(new TFileReader(file));
            try {
                String line = reader.readLine();
                while (line != null) {
                    String[] modification = line.split("\\" + DELIMITER);
                    String mod = modification[0];
                    String location = modification[1];
                    if (mod.equals(MOD_ADD_FILE) == true) {
                        this.adds.add(location);
                    } else if (mod.equals(MOD_MK_DIR) == true) {
                        this.mkdirs.add(location);
                    } else if (mod.equals(MOD_UPDATE_FILE) == true) {
                        this.updates.put(location, modification[2]);
                    }
                    line = reader.readLine();
                }
            } finally {
                reader.close();
            }
        } catch (FileNotFoundException exception) {
            throw new ModuleManagementToolException("The module file install file '" + getFileLocation() + "' does not exist", exception);
        } catch (IOException exception) {
            throw new ModuleManagementToolException("Error whilst reading file '" + getFileLocation(), exception);
        }
    } else {
        throw new ModuleManagementToolException("Invalid module.  The installation file does not exist for module: " + moduleId);
    }
}
Also used : TFile(de.schlichtherle.truezip.file.TFile) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) TFileReader(de.schlichtherle.truezip.file.TFileReader)

Aggregations

TFile (de.schlichtherle.truezip.file.TFile)28 ModuleDetails (org.alfresco.service.cmr.module.ModuleDetails)9 Test (org.junit.Test)8 ModuleDetailsImpl (org.alfresco.repo.module.ModuleDetailsImpl)6 Properties (java.util.Properties)5 IOException (java.io.IOException)4 VersionNumber (org.alfresco.util.VersionNumber)4 TFileInputStream (de.schlichtherle.truezip.file.TFileInputStream)3 ModuleVersionNumber (org.alfresco.repo.module.ModuleVersionNumber)3 TFileOutputStream (de.schlichtherle.truezip.file.TFileOutputStream)2 TFileReader (de.schlichtherle.truezip.file.TFileReader)1 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Manifest (java.util.jar.Manifest)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1