Files
.externalToolBuilders
config
source
cpp
java
org
alfresco
example
filesys
jcr
linkvalidation
model
repo
action
admin
attributes
audit
avm
cache
clt
coci
configuration
content
copy
deploy
descriptor
dictionary
domain
exporter
forum
importer
jscript
lock
model
module
tool
InstalledFiles.java
ModuleDetailsHelper.java
ModuleManagementTool.java
ModuleManagementToolException.java
ModuleManagementToolTest.java
default-file-mapping.properties
AbstractModuleComponent.java
ComponentsTest.java
ImporterModuleComponent.java
LoggerModuleComponent.java
ModuleComponent.java
ModuleComponentHelper.java
ModuleComponentHelperTest.java
ModuleDetailsImpl.java
ModuleDetailsImplTest.java
ModuleServiceImpl.java
ModuleStarter.java
node
ownable
policy
processor
remote
rule
search
security
service
template
transaction
version
workflow
sandbox
service
tools
util
apache
queryRegister.dtd
meta-inf
test-resources
web
.classpath
.project
build.xml
alfresco-community-repo/source/java/org/alfresco/repo/module/tool/InstalledFiles.java
Derek Hulley 31efa6d4f3 Support for renaming of modules
- When a module ID changes, the old ID gets put in a list against property 'module.aliases'.
 - The tool and the repo startup detect the existing installation against the alias and perform a rename.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5559 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2007-04-26 08:42:19 +00:00

226 lines
6.7 KiB
Java

package org.alfresco.repo.module.tool;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import de.schlichtherle.io.File;
import de.schlichtherle.io.FileInputStream;
import de.schlichtherle.io.FileOutputStream;
/**
* Details of the files installed during a module installation into a WAR
*
* @author Roy Wetherall
*/
public class InstalledFiles
{
/** Modification types */
private static final String MOD_ADD_FILE = "add";
private static final String MOD_UPDATE_FILE = "update";
private static final String MOD_MK_DIR = "mkdir";
/** Delimieter used in the file */
private static final String DELIMITER = "|";
/** War location **/
private String warLocation;
/** Module id **/
private String moduleId;
/** Lists containing the modifications made */
private List<String> adds = new ArrayList<String>();
private Map<String, String> updates = new HashMap<String, String>();
private List<String> mkdirs = new ArrayList<String>();
/**
* Constructor
*
* @param warLocation the war location
* @param moduleId the module id
*/
public InstalledFiles(String warLocation, String moduleId)
{
this.warLocation = warLocation;
this.moduleId = moduleId;
}
/**
* Loads the exisiting information about the installed files from the WAR
*/
public void load()
{
File file = new File(getFileLocation(), ModuleManagementTool.DETECTOR_AMP_AND_WAR);
if (file.exists() == true)
{
try
{
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(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);
}
}
}
/**
* Saves the current modification details into the WAR
*/
public void save()
{
try
{
File file = new File(getFileLocation(), ModuleManagementTool.DETECTOR_AMP_AND_WAR);
if (file.exists() == false)
{
file.createNewFile();
}
FileOutputStream os = new FileOutputStream(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);
}
}
/**
* Returns the location of the modifications file based on the module id
*
* @return the file location
*/
public String getFileLocation()
{
return this.warLocation + getFilePathInWar();
}
/**
* @return Returns the path of the install file within the WAR
*/
public String getFilePathInWar()
{
return ModuleManagementTool.MODULE_DIR + "/" + this.moduleId + "/modifications.install";
}
/**
* Get all the added files
*
* @return list of files added to war
*/
public List<String> getAdds()
{
return adds;
}
/**
* Get all the updated files, key is the file that has been updated and the value is the
* location of the backup made before modification took place.
*
* @return map of file locaiton and backup
*/
public Map<String, String> getUpdates()
{
return updates;
}
/**
* Gets a list of the dirs added during install
*
* @return list of directories added
*/
public List<String> getMkdirs()
{
return mkdirs;
}
/**
* Add a file addition
*
* @param location the file added
*/
public void addAdd(String location)
{
this.adds.add(location);
}
/**
* Add a file update
*
* @param location the file updated
* @param backup the backup location
*/
public void addUpdate(String location, String backup)
{
this.updates.put(location, backup);
}
/**
* Add a directory
*
* @param location the directory location
*/
public void addMkdir(String location)
{
this.mkdirs.add(location);
}
}