mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud)
106699: Made the listModules method public so you can find out what modules are installed. UTF-77 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@106795 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -18,28 +18,20 @@
|
||||
*/
|
||||
package org.alfresco.repo.module.tool;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
|
||||
import de.schlichtherle.truezip.file.*;
|
||||
import de.schlichtherle.truezip.fs.archive.zip.JarDriver;
|
||||
import de.schlichtherle.truezip.socket.sl.IOPoolLocator;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.module.ModuleVersionNumber;
|
||||
import org.alfresco.service.cmr.module.ModuleDetails;
|
||||
import org.alfresco.service.cmr.module.ModuleInstallState;
|
||||
import org.alfresco.util.VersionNumber;
|
||||
import org.safehaus.uuid.UUIDGenerator;
|
||||
|
||||
import de.schlichtherle.truezip.file.TArchiveDetector;
|
||||
import de.schlichtherle.truezip.file.TConfig;
|
||||
import de.schlichtherle.truezip.file.TFile;
|
||||
import de.schlichtherle.truezip.file.TFileInputStream;
|
||||
import de.schlichtherle.truezip.file.TVFS;
|
||||
import de.schlichtherle.truezip.fs.archive.zip.JarDriver;
|
||||
import de.schlichtherle.truezip.socket.sl.IOPoolLocator;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* Module management tool.
|
||||
@@ -178,13 +170,13 @@ public class ModuleManagementTool implements LogOutput
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs a given AMP file into a given WAR file.
|
||||
*
|
||||
* @see ModuleManagementTool#installModule(String, String, boolean, boolean, boolean)
|
||||
*
|
||||
* @param ampFileLocation the location of the AMP file to be installed
|
||||
* @param warFileLocation the location of the WAR file into which the AMP file is to be installed
|
||||
/**
|
||||
* Installs a given AMP file into a given WAR file.
|
||||
*
|
||||
* @see ModuleManagementTool#installModule(String, String, boolean, boolean, boolean)
|
||||
*
|
||||
* @param ampFileLocation the location of the AMP file to be installed
|
||||
* @param warFileLocation the location of the WAR file into which the AMP file is to be installed
|
||||
*/
|
||||
public void installModule(String ampFileLocation, String warFileLocation)
|
||||
{
|
||||
@@ -399,6 +391,14 @@ public class ModuleManagementTool implements LogOutput
|
||||
return dirChanges;
|
||||
}
|
||||
|
||||
/**
|
||||
* Backsup a given WAR file.
|
||||
*
|
||||
* @see ModuleManagementTool#installModule(String, String, boolean, boolean, boolean)
|
||||
*
|
||||
* @param warFile the location of the AMP file to be installed
|
||||
* @param warFileLocation the location of the WAR file into which the AMP file is to be installed
|
||||
*/
|
||||
private void backupWar(TFile warFile, boolean backupWAR) throws IOException
|
||||
{
|
||||
|
||||
@@ -664,69 +664,27 @@ public class ModuleManagementTool implements LogOutput
|
||||
*/
|
||||
public void listModules(String warLocation)
|
||||
{
|
||||
ModuleDetails moduleDetails = null;
|
||||
boolean previous = this.verbose;
|
||||
this.verbose = true;
|
||||
boolean moduleFound = false;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
TFile moduleDir = new TFile(warLocation + WarHelper.MODULE_NAMESPACE_DIR);
|
||||
if (moduleDir.exists() == false)
|
||||
List<ModuleDetails> modulesFound = warHelper.listModules(new TFile(warLocation));
|
||||
|
||||
if (modulesFound.size() < 1)
|
||||
{
|
||||
outputVerboseMessage("No modules are installed in this WAR file");
|
||||
}
|
||||
|
||||
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 = 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 ) {}
|
||||
}
|
||||
}
|
||||
outputVerboseMessage("Module '" + moduleDetails.getId() + "' installed in '" + warLocation + "'");
|
||||
outputVerboseMessage(" Title: " + moduleDetails.getTitle(), true);
|
||||
outputVerboseMessage(" Version: " + moduleDetails.getModuleVersionNumber(), true);
|
||||
outputVerboseMessage(" Install Date: " + moduleDetails.getInstallDate(), true);
|
||||
outputVerboseMessage(" Description: " + moduleDetails.getDescription(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Iterator<ModuleDetails> iterator = modulesFound.iterator(); iterator.hasNext(); ) {
|
||||
ModuleDetails moduleDetails = iterator.next();
|
||||
outputVerboseMessage("Module '" + moduleDetails.getId() + "' installed in '" + warLocation + "'");
|
||||
outputVerboseMessage(" Title: " + moduleDetails.getTitle(), true);
|
||||
outputVerboseMessage(" Version: " + moduleDetails.getModuleVersionNumber(), true);
|
||||
outputVerboseMessage(" Install Date: " + moduleDetails.getInstallDate(), true);
|
||||
outputVerboseMessage(" Description: " + moduleDetails.getDescription(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
outputVerboseMessage("No modules are installed in this WAR file");
|
||||
}
|
||||
if (!moduleFound)
|
||||
{
|
||||
outputVerboseMessage("No modules were found in this WAR file");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@@ -4,6 +4,8 @@ import org.alfresco.service.cmr.module.ModuleDetails;
|
||||
|
||||
import de.schlichtherle.truezip.file.TFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Performs various actions on a war file or exploded war directory
|
||||
*
|
||||
@@ -54,5 +56,13 @@ public interface WarHelper
|
||||
* @return boolean - true if it is a share war
|
||||
*/
|
||||
public boolean isShareWar(TFile war);
|
||||
|
||||
|
||||
/**
|
||||
* Lists all the currently installed modules in the WAR
|
||||
* @since 5.1
|
||||
* @param war the war
|
||||
* @return List<ModuleDetails> an unordered list of module details.
|
||||
* @throws ModuleManagementToolException
|
||||
*/
|
||||
List<ModuleDetails> listModules(TFile war);
|
||||
}
|
||||
|
@@ -1,5 +1,13 @@
|
||||
package org.alfresco.repo.module.tool;
|
||||
|
||||
import de.schlichtherle.truezip.file.TFile;
|
||||
import de.schlichtherle.truezip.file.TFileInputStream;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.module.ModuleDetailsImpl;
|
||||
import org.alfresco.service.cmr.module.ModuleDependency;
|
||||
import org.alfresco.service.cmr.module.ModuleDetails;
|
||||
import org.alfresco.util.VersionNumber;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
@@ -8,14 +16,6 @@ import java.util.Properties;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
import org.alfresco.repo.module.ModuleDetailsImpl;
|
||||
import org.alfresco.service.cmr.module.ModuleDependency;
|
||||
import org.alfresco.service.cmr.module.ModuleDetails;
|
||||
import org.alfresco.util.VersionNumber;
|
||||
|
||||
import de.schlichtherle.truezip.file.TFile;
|
||||
import de.schlichtherle.truezip.file.TFileInputStream;
|
||||
|
||||
|
||||
/**
|
||||
* Performs logic for the Module Management Tool.
|
||||
@@ -138,7 +138,7 @@ public class WarHelperImpl implements WarHelper
|
||||
* Compares the version information with the module details to see if their valid. If they are invalid then it throws an exception.
|
||||
* @param warVersion
|
||||
* @param installingModuleDetails
|
||||
* @throws ModuleManagementToolException
|
||||
* @throws ModuleManagementToolException/home/gethin/development/projects/updatetool/code/update-tool
|
||||
*/
|
||||
private void checkVersions(VersionNumber warVersion, ModuleDetails installingModuleDetails) throws ModuleManagementToolException
|
||||
{
|
||||
@@ -276,6 +276,65 @@ public class WarHelperImpl implements WarHelper
|
||||
return false; //default
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
return moduleDetails; //empty
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the module details for the specified module from the war.
|
||||
* @param war a valid war file or exploded directory from a war
|
||||
|
Reference in New Issue
Block a user