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;
}
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;
}
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);
}
}
}
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);
}
}
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);
}
}
Aggregations