/** * Finds a single attribute from a war manifest file. * @param war the war * @param attributeName key name of attribute * @return attribute value * @throws ModuleManagementToolException */ protected String findManifestArtibute(TFile war, String attributeName) throws ModuleManagementToolException { Manifest manifest = findManifest(war); Attributes attribs = manifest.getMainAttributes(); return attribs.getValue(attributeName); }
@Override public boolean isShareWar(TFile warFile) { if (!warFile.exists()) { throw new ModuleManagementToolException("The war file '" + warFile + "' does not exist."); } String title = findManifestArtibute(warFile, MANIFEST_SPECIFICATION_TITLE); if (MANIFEST_SHARE.equals(title)) return true; //It is share return false; //default }
@Override public ModuleDetails getModuleDetailsOrAlias(TFile war, ModuleDetails installingModuleDetails) { ModuleDetails installedModuleDetails = getModuleDetails(war, installingModuleDetails.getId()); if (installedModuleDetails == null) { // It might be there as one of the aliases List<String> installingAliases = installingModuleDetails.getAliases(); for (String installingAlias : installingAliases) { ModuleDetails installedAliasModuleDetails = getModuleDetails(war, installingAlias); if (installedAliasModuleDetails == null) { // There is nothing by that alias continue; } // We found an alias and will treat it as the same module installedModuleDetails = installedAliasModuleDetails; //outputMessage("Module '" + installingAlias + "' is installed and is an alias of '" + installingModuleDetails + "'", false); break; } } return installedModuleDetails; }
/** * Gets the module details for the specified module from the war. * @param war a valid war file or exploded directory from a war * @param moduleId String * @return ModuleDetails */ protected ModuleDetails getModuleDetails(TFile war, String moduleId) { ModuleDetails moduleDets = null; TFile theFile = getModuleDetailsFile(war, moduleId); if (theFile != null && theFile.exists()) { moduleDets = new ModuleDetailsImpl(loadProperties(theFile)); } return moduleDets; }
@Override public void checkCompatibleVersion(TFile war, ModuleDetails installingModuleDetails) { //Version check TFile propsFile = new TFile(war+VERSION_PROPERTIES); if (propsFile != null && propsFile.exists()) { log.info("INFO: Checking the war version using "+VERSION_PROPERTIES); Properties warVers = loadProperties(propsFile); VersionNumber warVersion = new VersionNumber(warVers.getProperty("version.major")+"."+warVers.getProperty("version.minor")+"."+warVers.getProperty("version.revision")); checkVersions(warVersion, installingModuleDetails); } else { log.info("INFO: Checking the war version using the manifest."); checkCompatibleVersionUsingManifest(war,installingModuleDetails); } }
@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)) { return; //successful match. } } throw new ModuleManagementToolException("The module ("+installingModuleDetails.getTitle() +") can only be installed in one of the following editions"+installableEditions); } else { checkCompatibleEditionUsingManifest(war,installingModuleDetails); } } }
String version = findManifestArtibute(war, MANIFEST_SPECIFICATION_VERSION); if (version != null && version.length() > 0) checkVersions(warVersion, installingModuleDetails); String edition = findManifestArtibute(war, MANIFEST_IMPLEMENTATION_TITLE); if (edition.endsWith(MANIFEST_COMMUNITY))
@Override public void checkCompatibleVersion(TFile war, ModuleDetails installingModuleDetails) { //Version check TFile propsFile = new TFile(war+VERSION_PROPERTIES); if (propsFile != null && propsFile.exists()) { log.info("INFO: Checking the war version using "+VERSION_PROPERTIES); Properties warVers = loadProperties(propsFile); VersionNumber warVersion = new VersionNumber(warVers.getProperty("version.major")+"."+warVers.getProperty("version.minor")+"."+warVers.getProperty("version.revision")); checkVersions(warVersion, installingModuleDetails); } else { log.info("INFO: Checking the war version using the manifest."); checkCompatibleVersionUsingManifest(war,installingModuleDetails); } }
/** * Gets the module details for the specified module from the war. * @param war a valid war file or exploded directory from a war * @param moduleId String * @return ModuleDetails */ protected ModuleDetails getModuleDetails(TFile war, String moduleId) { ModuleDetails moduleDets = null; TFile theFile = getModuleDetailsFile(war, moduleId); if (theFile != null && theFile.exists()) { moduleDets = new ModuleDetailsImpl(loadProperties(theFile)); } return moduleDets; }
@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)) { return; //successful match. } } throw new ModuleManagementToolException("The module ("+installingModuleDetails.getTitle() +") can only be installed in one of the following editions"+installableEditions); } else { checkCompatibleEditionUsingManifest(war,installingModuleDetails); } } }
String version = findManifestArtibute(war, MANIFEST_SPECIFICATION_VERSION); if (version != null && version.length() > 0) checkVersions(warVersion, installingModuleDetails); String edition = findManifestArtibute(war, MANIFEST_IMPLEMENTATION_TITLE); if (edition.endsWith(MANIFEST_COMMUNITY))
@Override public boolean isShareWar(TFile warFile) { if (!warFile.exists()) { throw new ModuleManagementToolException("The war file '" + warFile + "' does not exist."); } String title = findManifestArtibute(warFile, MANIFEST_SPECIFICATION_TITLE); if (MANIFEST_SHARE.equals(title)) return true; //It is share return false; //default }
@Override public ModuleDetails getModuleDetailsOrAlias(TFile war, ModuleDetails installingModuleDetails) { ModuleDetails installedModuleDetails = getModuleDetails(war, installingModuleDetails.getId()); if (installedModuleDetails == null) { // It might be there as one of the aliases List<String> installingAliases = installingModuleDetails.getAliases(); for (String installingAlias : installingAliases) { ModuleDetails installedAliasModuleDetails = getModuleDetails(war, installingAlias); if (installedAliasModuleDetails == null) { // There is nothing by that alias continue; } // We found an alias and will treat it as the same module installedModuleDetails = installedAliasModuleDetails; //outputMessage("Module '" + installingAlias + "' is installed and is an alias of '" + installingModuleDetails + "'", false); break; } } return installedModuleDetails; }
/** * Finds a single attribute from a war manifest file. * @param war the war * @param attributeName key name of attribute * @return attribute value * @throws ModuleManagementToolException */ protected String findManifestArtibute(TFile war, String attributeName) throws ModuleManagementToolException { Manifest manifest = findManifest(war); Attributes attribs = manifest.getMainAttributes(); return attribs.getValue(attributeName); }
String warEdition = findManifestArtibute(war, MANIFEST_IMPLEMENTATION_TITLE); if (warEdition != null && warEdition.length() > 0)
@Override public void checkModuleDependencies(TFile war, ModuleDetails installingModuleDetails) { // Check that the target war has the necessary dependencies for this install List<ModuleDependency> installingModuleDependencies = installingModuleDetails.getDependencies(); List<ModuleDependency> missingDependencies = new ArrayList<ModuleDependency>(0); for (ModuleDependency dependency : installingModuleDependencies) { String dependencyId = dependency.getDependencyId(); ModuleDetails dependencyModuleDetails = getModuleDetails(war, dependencyId); // Check the dependency. The API specifies that a null returns false, so no null check is required if (!dependency.isValidDependency(dependencyModuleDetails)) { missingDependencies.add(dependency); continue; } } if (missingDependencies.size() > 0) { throw new ModuleManagementToolException("The following modules must first be installed: " + missingDependencies); } }
String warEdition = findManifestArtibute(war, MANIFEST_IMPLEMENTATION_TITLE); if (warEdition != null && warEdition.length() > 0)
@Override public void checkModuleDependencies(TFile war, ModuleDetails installingModuleDetails) { // Check that the target war has the necessary dependencies for this install List<ModuleDependency> installingModuleDependencies = installingModuleDetails.getDependencies(); List<ModuleDependency> missingDependencies = new ArrayList<ModuleDependency>(0); for (ModuleDependency dependency : installingModuleDependencies) { String dependencyId = dependency.getDependencyId(); ModuleDetails dependencyModuleDetails = getModuleDetails(war, dependencyId); // Check the dependency. The API specifies that a null returns false, so no null check is required if (!dependency.isValidDependency(dependencyModuleDetails)) { missingDependencies.add(dependency); continue; } } if (missingDependencies.size() > 0) { throw new ModuleManagementToolException("The following modules must first be installed: " + missingDependencies); } }