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:
Alan Davis
2015-06-23 07:07:13 +00:00
parent 042003a1cd
commit 6e3fb93759
5 changed files with 222 additions and 133 deletions

View File

@@ -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.
@@ -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,68 +664,26 @@ 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 ) {}
}
}
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

View File

@@ -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
*
@@ -55,4 +57,12 @@ public interface WarHelper
*/
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);
}

View File

@@ -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

View File

@@ -18,24 +18,18 @@
*/
package org.alfresco.repo.module.tool;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import org.alfresco.util.TempFileProvider;
import org.springframework.util.FileCopyUtils;
import de.schlichtherle.truezip.file.TFile;
import de.schlichtherle.truezip.file.TFileInputStream;
import de.schlichtherle.truezip.file.TVFS;
import junit.framework.TestCase;
import org.alfresco.service.cmr.module.ModuleDetails;
import org.alfresco.util.TempFileProvider;
import org.springframework.util.FileCopyUtils;
import java.io.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
/**
* @see org.alfresco.repo.module.tool.ModuleManagementTool
@@ -346,17 +340,72 @@ public class ModuleManagementToolTest extends TestCase
checkForFileExistance(warLocation, files);
}
public void testList()
throws Exception
public void testList() throws Exception
{
String warLocation = getFileLocation(".war", "module/test.war");
String ampLocation = getFileLocation(".amp", "module/test_v1.amp");
this.manager.listModules(warLocation);
}
public void testListAndInstall() throws Exception {
String warLocation = getFileLocation(".war", "module/test.war");
String ampLocation = getFileLocation(".amp", "module/test_v1.amp");
String ampV2Location = getFileLocation(".amp", "module/test_v2.amp");
TFile war = new TFile(warLocation);
List<ModuleDetails> details = this.manager.warHelper.listModules(war);
assertNotNull(details);
assertEquals(details.size(), 0);
this.manager.installModule(ampLocation, warLocation);
this.manager.listModules(warLocation);
details = this.manager.warHelper.listModules(war);
assertNotNull(details);
assertEquals(details.size(), 1);
ModuleDetails aModule = details.get(0);
assertEquals("test", aModule.getId());
assertEquals("1.0", aModule.getModuleVersionNumber().toString());
this.manager.installModule(ampV2Location, warLocation);
details = this.manager.warHelper.listModules(war);
assertNotNull(details);
assertEquals(details.size(), 1);
aModule = details.get(0);
assertEquals("test", aModule.getId());
assertEquals("2.0", aModule.getModuleVersionNumber().toString());
String testAmpDepV2Location = getFileLocation(".amp", "module/dependent_on_test_v2.amp");
String testAmp7 = getFileLocation(".amp", "module/test_v7.amp");
this.manager.installModule(testAmpDepV2Location, warLocation, false, true, false);
this.manager.installModule(testAmp7, warLocation, false, true, false);
details = this.manager.warHelper.listModules(war);
assertNotNull(details);
assertEquals(details.size(), 3);
//Sort them by installation date
details.sort(new Comparator<ModuleDetails>() {
@Override
public int compare(ModuleDetails a, ModuleDetails b) {
return a.getInstallDate().compareTo(b.getInstallDate());
}
});
ModuleDetails installedModule = details.get(0);
assertEquals("test", installedModule.getId());
assertEquals("2.0", installedModule.getModuleVersionNumber().toString());
installedModule = details.get(1);
assertEquals("org.alfresco.module.test.dependent", installedModule.getId());
assertEquals("2.0", installedModule.getModuleVersionNumber().toString());
installedModule = details.get(2);
assertEquals("forcedtest", installedModule.getId());
assertEquals("1.0", installedModule.getModuleVersionNumber().toString());
}
private String getFileLocation(String extension, String location)

View File

@@ -1,30 +1,24 @@
package org.alfresco.repo.module.tool;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
import org.alfresco.repo.module.ModuleDetailsImpl;
import org.alfresco.repo.module.ModuleVersionNumber;
import org.alfresco.service.cmr.module.ModuleDetails;
import org.alfresco.util.TempFileProvider;
import org.alfresco.util.VersionNumber;
import org.junit.Test;
import org.springframework.util.FileCopyUtils;
import de.schlichtherle.truezip.file.TArchiveDetector;
import de.schlichtherle.truezip.file.TConfig;
import de.schlichtherle.truezip.file.TFile;
import de.schlichtherle.truezip.fs.archive.zip.ZipDriver;
import de.schlichtherle.truezip.socket.sl.IOPoolLocator;
import org.alfresco.repo.module.ModuleDetailsImpl;
import org.alfresco.repo.module.ModuleVersionNumber;
import org.alfresco.service.cmr.module.ModuleDetails;
import org.alfresco.service.cmr.module.ModuleInstallState;
import org.alfresco.util.TempFileProvider;
import org.alfresco.util.VersionNumber;
import org.junit.Test;
import org.springframework.util.FileCopyUtils;
import java.io.*;
import java.util.List;
import java.util.Properties;
import static org.junit.Assert.*;
/**
* Tests the war helper.
@@ -296,6 +290,25 @@ public class WarHelperImplTest extends WarHelperImpl
}
@Test
public void testListModules() throws Exception
{
TFile theWar = getFile(".war", "module/test.war");
List<ModuleDetails> details = this.listModules(theWar);
assertNotNull(details);
assertEquals(details.size(), 0);
theWar = getFile(".war", "module/share-4.2.a.war");
details = this.listModules(theWar);
assertNotNull(details);
assertEquals(details.size(), 1);
ModuleDetails aModule = details.get(0);
assertEquals("alfresco-mm-share", aModule.getId());
assertEquals("0.1.5.6", aModule.getModuleVersionNumber().toString());
assertEquals(ModuleInstallState.INSTALLED, aModule.getInstallState());
}
private Properties dummyModuleProperties() {
Properties props = new Properties();