Search in sources :

Example 21 with TFile

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

the class ModuleDetailsHelper method saveModuleDetails.

/**
 * Saves the module details to the war in the correct location based on the module id
 *
 * @param warLocation   the war location
 * @param moduleDetails      the module id
 */
public static void saveModuleDetails(String warLocation, ModuleDetails moduleDetails) {
    // Ensure that it is a valid set of properties
    String moduleId = moduleDetails.getId();
    try {
        String modulePropertiesFileLocation = getModulePropertiesFileLocation(warLocation, moduleId);
        TFile file = new TFile(modulePropertiesFileLocation);
        if (file.exists() == false) {
            file.createNewFile();
        }
        // Get all the module properties
        Properties moduleProperties = moduleDetails.getProperties();
        OutputStream os = new TFileOutputStream(file);
        try {
            moduleProperties.store(os, null);
        } finally {
            os.close();
        }
    } catch (IOException exception) {
        throw new ModuleManagementToolException("Unable to save module details into WAR file: \n" + "   Module: " + moduleDetails.getId() + "\n" + "   Properties: " + moduleDetails.getProperties(), exception);
    }
}
Also used : TFile(de.schlichtherle.truezip.file.TFile) OutputStream(java.io.OutputStream) TFileOutputStream(de.schlichtherle.truezip.file.TFileOutputStream) TFileOutputStream(de.schlichtherle.truezip.file.TFileOutputStream) IOException(java.io.IOException) Properties(java.util.Properties)

Example 22 with TFile

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

the class WarHelperImplTest method testCheckCompatibleVersion.

@Test
public void testCheckCompatibleVersion() {
    // Version 4.1.0
    TFile theWar = getFile(".war", "module/test.war");
    ModuleDetails installingModuleDetails = new ModuleDetailsImpl("test_it", new ModuleVersionNumber("9999"), "Test Mod", "Testing module");
    installingModuleDetails.setRepoVersionMin(new VersionNumber("10.1"));
    try {
        this.checkCompatibleVersion(theWar, installingModuleDetails);
        // should never get here
        fail();
    } catch (ModuleManagementToolException exception) {
        assertTrue(exception.getMessage().contains("must be installed on a war version equal to or greater than 10.1"));
    }
    installingModuleDetails.setRepoVersionMin(new VersionNumber("1.1"));
    // does not throw exception
    this.checkCompatibleVersion(theWar, installingModuleDetails);
    installingModuleDetails.setRepoVersionMax(new VersionNumber("3.0"));
    try {
        this.checkCompatibleVersion(theWar, installingModuleDetails);
        // should never get here
        fail();
    } catch (ModuleManagementToolException exception) {
        assertTrue(exception.getMessage().contains("cannot be installed on a war version greater than 3.0"));
    }
    installingModuleDetails.setRepoVersionMax(new VersionNumber("99"));
    // does not throw exception
    this.checkCompatibleVersion(theWar, installingModuleDetails);
    // current war version
    installingModuleDetails.setRepoVersionMin(new VersionNumber("4.1.0"));
    // current war version
    installingModuleDetails.setRepoVersionMax(new VersionNumber("4.1.0"));
    // does not throw exception
    this.checkCompatibleVersion(theWar, installingModuleDetails);
    // current war version
    installingModuleDetails.setRepoVersionMin(new VersionNumber("3.4.0"));
    // current war version
    installingModuleDetails.setRepoVersionMax(new VersionNumber("4.1.0"));
    // does not throw exception
    this.checkCompatibleVersion(theWar, installingModuleDetails);
    try {
        // current war version
        installingModuleDetails.setRepoVersionMin(new VersionNumber("3.4.0"));
        // current war version
        installingModuleDetails.setRepoVersionMax(new VersionNumber("4.0.999"));
        // does not throw exception
        this.checkCompatibleVersion(theWar, installingModuleDetails);
        // should never get here
        fail("Should not pass as current version is 4.1.0 and the max value is 4.0.999");
    } catch (ModuleManagementToolException exception) {
        assertTrue(exception.getMessage().contains("cannot be installed on a war version greater than 4.0.999"));
    }
}
Also used : TFile(de.schlichtherle.truezip.file.TFile) ModuleDetailsImpl(org.alfresco.repo.module.ModuleDetailsImpl) ModuleVersionNumber(org.alfresco.repo.module.ModuleVersionNumber) ModuleDetails(org.alfresco.service.cmr.module.ModuleDetails) VersionNumber(org.alfresco.util.VersionNumber) ModuleVersionNumber(org.alfresco.repo.module.ModuleVersionNumber) Test(org.junit.Test)

Example 23 with TFile

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

the class WarHelperImplTest method testCheckCompatibleEdition.

@Test
public void testCheckCompatibleEdition() {
    Properties props = dummyModuleProperties();
    ModuleDetails installingModuleDetails = new ModuleDetailsImpl(props);
    // Community Edition
    TFile theWar = getFile(".war", "module/test.war");
    // Test for no edition specified
    // does not throw exception
    this.checkCompatibleEdition(theWar, installingModuleDetails);
    // Test for invalid edition
    props.setProperty(ModuleDetails.PROP_EDITIONS, "CommuniT");
    installingModuleDetails = new ModuleDetailsImpl(props);
    try {
        this.checkCompatibleEdition(theWar, installingModuleDetails);
        // should never get here
        fail();
    } catch (ModuleManagementToolException exception) {
        assertTrue(exception.getMessage().endsWith("can only be installed in one of the following editions[CommuniT]"));
    }
    // should ignore case
    props.setProperty(ModuleDetails.PROP_EDITIONS, ("CoMMunity"));
    installingModuleDetails = new ModuleDetailsImpl(props);
    // does not throw exception
    this.checkCompatibleEdition(theWar, installingModuleDetails);
    // should ignore case
    props.setProperty(ModuleDetails.PROP_EDITIONS, ("enterprise,community,bob"));
    installingModuleDetails = new ModuleDetailsImpl(props);
    // does not throw exception
    this.checkCompatibleEdition(theWar, installingModuleDetails);
    // should ignore case
    props.setProperty(ModuleDetails.PROP_EDITIONS, ("enterprise,Community"));
    installingModuleDetails = new ModuleDetailsImpl(props);
    // does not throw exception
    this.checkCompatibleVersion(theWar, installingModuleDetails);
}
Also used : TFile(de.schlichtherle.truezip.file.TFile) ModuleDetailsImpl(org.alfresco.repo.module.ModuleDetailsImpl) ModuleDetails(org.alfresco.service.cmr.module.ModuleDetails) Properties(java.util.Properties) Test(org.junit.Test)

Example 24 with TFile

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

the class WarHelperImplTest method testfindManifest.

@Test
public void testfindManifest() throws Exception {
    // Now check the compatible versions using the manifest
    TFile theWar = getFile(".war", "module/share-3.4.11.war");
    Manifest manifest = this.findManifest(theWar);
    assertNotNull(manifest);
    assertEquals("Alfresco Share Enterprise", manifest.getMainAttributes().getValue(MANIFEST_IMPLEMENTATION_TITLE));
    assertEquals("3.4.11", manifest.getMainAttributes().getValue(MANIFEST_SPECIFICATION_VERSION));
    theWar = getFile(".war", "module/alfresco-4.2.a.war");
    manifest = this.findManifest(theWar);
    assertNotNull(manifest);
    assertEquals("Alfresco Repository Community", manifest.getMainAttributes().getValue(MANIFEST_IMPLEMENTATION_TITLE));
    assertEquals("4.2.a", manifest.getMainAttributes().getValue(MANIFEST_SPECIFICATION_VERSION));
}
Also used : TFile(de.schlichtherle.truezip.file.TFile) Manifest(java.util.jar.Manifest) Test(org.junit.Test)

Example 25 with TFile

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

the class WarHelperImplTest method testListModules.

@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());
}
Also used : TFile(de.schlichtherle.truezip.file.TFile) ModuleDetails(org.alfresco.service.cmr.module.ModuleDetails) Test(org.junit.Test)

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