modules/core/domain/src/main/java/org/rhq/core/domain/content/PackageDetailsKey.java | 98 ++++-- modules/core/domain/src/main/java/org/rhq/core/domain/content/composite/PackageVersionMetadataComposite.java | 55 +-- modules/core/util/src/main/java/org/rhq/core/util/RpmVersionComparator.java | 162 ++++++++++ modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ContentUtils.java | 4 modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentManagerHelper.java | 3 modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentSourceManagerBean.java | 8 modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentUIManagerBean.java | 9 modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentProviderPackageDetailsKey.java | 16 modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/sync/PackageSourceSynchronizer.java | 4 modules/enterprise/server/plugins/disk/src/main/java/org/rhq/enterprise/server/plugins/disk/DiskSource.java | 2 modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNHelper.java | 16 modules/enterprise/server/plugins/yum/src/main/java/org/rhq/enterprise/server/plugins/yum/Repo.java | 9 modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/StandaloneManagedDeploymentComponent.java | 25 - modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/ApplicationComponent.java | 126 +++---- modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/util/JarContentDelegate.java | 74 ++-- modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/content/SimpleContentFactory.java | 2 modules/plugins/platform/src/main/java/org/rhq/plugins/platform/content/RpmPackageDiscoveryDelegate.java | 9 modules/plugins/platform/src/main/java/org/rhq/plugins/platform/content/yum/Primary.java | 58 ++- modules/plugins/platform/src/main/java/org/rhq/plugins/platform/win/WindowsSoftwareDelegate.java | 2 19 files changed, 453 insertions(+), 229 deletions(-)
New commits: commit 576e30720adc0f843cc72e9a798ac7dedd80b779 Author: Sayli Karmarkar skarmark@redhat.com Date: Mon Feb 1 20:07:29 2010 -0500
1753 - Updating functions and queries to make use of domain model changes made for package release and epoch + adding RpmVersionComparator.java
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/content/PackageDetailsKey.java b/modules/core/domain/src/main/java/org/rhq/core/domain/content/PackageDetailsKey.java index da51e4b..e6ea6f1 100644 --- a/modules/core/domain/src/main/java/org/rhq/core/domain/content/PackageDetailsKey.java +++ b/modules/core/domain/src/main/java/org/rhq/core/domain/content/PackageDetailsKey.java @@ -1,25 +1,25 @@ - /* - * RHQ Management Platform - * Copyright (C) 2005-2008 Red Hat, Inc. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, as - * published by the Free Software Foundation, and/or the GNU Lesser - * General Public License, version 2.1, also as published by the Free - * Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License and the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License - * and the GNU Lesser General Public License along with this program; - * if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ +/* + * RHQ Management Platform + * Copyright (C) 2005-2008 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation, and/or the GNU Lesser + * General Public License, version 2.1, also as published by the Free + * Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License and the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License + * and the GNU Lesser General Public License along with this program; + * if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ package org.rhq.core.domain.content;
import java.io.Serializable; @@ -50,6 +50,10 @@ public class PackageDetailsKey implements Serializable { */ private final String version;
+ private final String release; + + private final String epoch; + /** * Fully qualified name of the package type this package; */ @@ -62,6 +66,32 @@ public class PackageDetailsKey implements Serializable {
// Constructors --------------------------------------------
+ public PackageDetailsKey(String name, String version, String release, String epoch, String packageTypeName, + String architectureName) { + if (name == null || name.length() == 0) { + throw new IllegalArgumentException("name cannot be null or zero length"); + } + + if (version == null || version.length() == 0) { + throw new IllegalArgumentException("version cannot be null or zero length"); + } + + if (packageTypeName == null || packageTypeName.length() == 0) { + throw new IllegalArgumentException("packageTypeName cannot be null or zero length"); + } + + if (architectureName == null || architectureName.length() == 0) { + throw new IllegalArgumentException("architectureName cannot be null or zero length"); + } + + this.name = name; + this.version = version; + this.release = release; + this.epoch = epoch; + this.packageTypeName = packageTypeName; + this.architectureName = architectureName; + } + public PackageDetailsKey(String name, String version, String packageTypeName, String architectureName) { if (name == null || name.length() == 0) { throw new IllegalArgumentException("name cannot be null or zero length"); @@ -81,6 +111,8 @@ public class PackageDetailsKey implements Serializable {
this.name = name; this.version = version; + this.release = null; + this.epoch = null; this.packageTypeName = packageTypeName; this.architectureName = architectureName; } @@ -95,6 +127,14 @@ public class PackageDetailsKey implements Serializable { return version; }
+ public String getRelease() { + return release; + } + + public String getEpoch() { + return epoch; + } + public String getPackageTypeName() { return packageTypeName; } @@ -115,6 +155,12 @@ public class PackageDetailsKey implements Serializable { int result = 1; result = (prime * result) + name.hashCode(); result = (prime * result) + version.hashCode(); + if (release != null) { + result = (prime * result) + release.hashCode(); + } + if (epoch != null) { + result = (prime * result) + epoch.hashCode(); + } result = (prime * result) + packageTypeName.hashCode(); result = (prime * result) + architectureName.hashCode(); return result; @@ -144,6 +190,14 @@ public class PackageDetailsKey implements Serializable { return false; }
+ if ((release == null && other.release != null) || (release != null && !release.equals(other.release))) { + return false; + } + + if ((epoch == null && other.epoch != null) || (epoch != null && !epoch.equals(other.epoch))) { + return false; + } + if (!packageTypeName.equals(other.packageTypeName)) { return false; } diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/content/composite/PackageVersionMetadataComposite.java b/modules/core/domain/src/main/java/org/rhq/core/domain/content/composite/PackageVersionMetadataComposite.java index 1d541f5..c949a55 100644 --- a/modules/core/domain/src/main/java/org/rhq/core/domain/content/composite/PackageVersionMetadataComposite.java +++ b/modules/core/domain/src/main/java/org/rhq/core/domain/content/composite/PackageVersionMetadataComposite.java @@ -1,28 +1,29 @@ - /* - * RHQ Management Platform - * Copyright (C) 2005-2008 Red Hat, Inc. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, as - * published by the Free Software Foundation, and/or the GNU Lesser - * General Public License, version 2.1, also as published by the Free - * Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License and the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License - * and the GNU Lesser General Public License along with this program; - * if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ +/* + * RHQ Management Platform + * Copyright (C) 2005-2008 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation, and/or the GNU Lesser + * General Public License, version 2.1, also as published by the Free + * Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License and the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License + * and the GNU Lesser General Public License along with this program; + * if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ package org.rhq.core.domain.content.composite;
import java.io.Serializable; + import org.rhq.core.domain.content.PackageDetailsKey; import org.rhq.core.domain.content.PackageVersion;
@@ -39,15 +40,19 @@ public class PackageVersionMetadataComposite implements Serializable { private final byte[] metadata; private final String packageName; private final String version; + private final String release; + private final String epoch; private final String packageTypeName; private final String archName;
public PackageVersionMetadataComposite(int packageVersionId, byte[] metadata, String packageName, String version, - String packageTypeName, String architectureName) { + String release, String epoch, String packageTypeName, String architectureName) { this.packageVersionId = packageVersionId; this.metadata = metadata; this.packageName = packageName; this.version = version; + this.release = release; + this.epoch = epoch; this.packageTypeName = packageTypeName; this.archName = architectureName; } @@ -61,6 +66,6 @@ public class PackageVersionMetadataComposite implements Serializable { }
public PackageDetailsKey getPackageDetailsKey() { - return new PackageDetailsKey(packageName, version, packageTypeName, archName); + return new PackageDetailsKey(packageName, version, release, epoch, packageTypeName, archName); } -} \ No newline at end of file +} diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ContentUtils.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ContentUtils.java index a53b8d2..a11f08f 100644 --- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ContentUtils.java +++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ContentUtils.java @@ -42,8 +42,8 @@ public class ContentUtils { Package pkg = packageVersion.getGeneralPackage(); PackageType pkgType = pkg.getPackageType();
- PackageDetailsKey key = new PackageDetailsKey(pkg.getName(), packageVersion.getVersion(), pkgType.getName(), - packageVersion.getArchitecture().getName()); + PackageDetailsKey key = new PackageDetailsKey(pkg.getName(), packageVersion.getVersion(), packageVersion + .getRelease(), packageVersion.getEpoch(), pkgType.getName(), packageVersion.getArchitecture().getName());
ResourcePackageDetails details = new ResourcePackageDetails(key); details.setClassification(pkg.getClassification()); diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentManagerHelper.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentManagerHelper.java index 7656d93..4bce4a5 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentManagerHelper.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentManagerHelper.java @@ -80,7 +80,8 @@ public class ContentManagerHelper { Package generalPackage = packageVersion.getGeneralPackage();
PackageDetailsKey key = new PackageDetailsKey(generalPackage.getName(), packageVersion.getVersion(), - packageVersion.getGeneralPackage().getPackageType().getName(), packageVersion.getArchitecture().getName()); + packageVersion.getRelease(), packageVersion.getEpoch(), packageVersion.getGeneralPackage().getPackageType() + .getName(), packageVersion.getArchitecture().getName()); ResourcePackageDetails details = new ResourcePackageDetails(key);
details.setClassification(generalPackage.getClassification()); diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentSourceManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentSourceManagerBean.java index c1ad1d3..6c5506f 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentSourceManagerBean.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentSourceManagerBean.java @@ -1752,8 +1752,8 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal { // Used by export of content through http
PackageDetailsKey packageDetailsKey = new PackageDetailsKey(packageVersion.getDisplayName(), packageVersion - .getDisplayVersion(), packageVersion.getGeneralPackage().getPackageType().toString(), packageVersion - .getArchitecture().toString()); + .getDisplayVersion(), packageVersion.getRelease(), packageVersion.getEpoch(), packageVersion + .getGeneralPackage().getPackageType().toString(), packageVersion.getArchitecture().toString());
int resourceId = 0; //set to dummy value
@@ -1769,8 +1769,8 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal { // Used by export of content through http
PackageDetailsKey packageDetailsKey = new PackageDetailsKey(packageVersion.getDisplayName(), packageVersion - .getDisplayVersion(), packageVersion.getGeneralPackage().getPackageType().toString(), packageVersion - .getArchitecture().toString()); + .getDisplayVersion(), packageVersion.getRelease(), packageVersion.getEpoch(), packageVersion + .getGeneralPackage().getPackageType().toString(), packageVersion.getArchitecture().toString());
int resourceId = 0; //set to dummy value
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentUIManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentUIManagerBean.java index d7b3e0a..7bae8f3 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentUIManagerBean.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentUIManagerBean.java @@ -53,6 +53,7 @@ import org.rhq.core.domain.util.PageControl; import org.rhq.core.domain.util.PageList; import org.rhq.core.domain.util.PageOrdering; import org.rhq.core.domain.util.PersistenceUtility; +import org.rhq.core.util.RpmVersionComparator; import org.rhq.enterprise.server.RHQConstants;
/** @@ -329,13 +330,15 @@ public class ContentUIManagerBean implements ContentUIManagerLocal { List<PackageVersionComposite> latestResults = new ArrayList<PackageVersionComposite>();
PackageVersionComposite latestPackage = null; - + RpmVersionComparator rpmvercmp = new RpmVersionComparator(); + int verCmpResult = 0; for (PackageVersionComposite newPackage : modifiedResults) { latestPackage = newPackage;
for (PackageVersionComposite pack : testResults) { - if (pack.getPackageName().equals(latestPackage.getPackageName()) - && latestPackage.getPackageVersion().getVersion().compareTo(pack.getPackageVersion().getVersion()) < 0) { + verCmpResult = rpmvercmp.compare(latestPackage.getPackageVersion().getVersion(), pack + .getPackageVersion().getVersion()); + if (pack.getPackageName().equals(latestPackage.getPackageName()) && verCmpResult < 0) { latestPackage = pack; } } diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentProviderPackageDetailsKey.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentProviderPackageDetailsKey.java index e0802d0..4b7d3cc 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentProviderPackageDetailsKey.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentProviderPackageDetailsKey.java @@ -53,6 +53,22 @@ public class ContentProviderPackageDetailsKey extends PackageDetailsKey { this.resourceTypePluginName = resourceTypePluginName; }
+ public ContentProviderPackageDetailsKey(String name, String version, String release, String epoch, + String packageTypeName, String architectureName, String resourceTypeName, String resourceTypePluginName) { + super(name, version, release, epoch, packageTypeName, architectureName); + + if (resourceTypeName == null) { + throw new IllegalArgumentException("resourceTypeName cannot be null"); + } + + if (resourceTypePluginName == null) { + throw new IllegalArgumentException("resourceTypePluginName cannot be null"); + } + + this.resourceTypeName = resourceTypeName; + this.resourceTypePluginName = resourceTypePluginName; + } + /** * The name of the {@link ResourceType} that this package's type belongs to. All package types are defined and * supported by a particular {@link ResourceType}, this name is part of the natural key of a resource type. See diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/sync/PackageSourceSynchronizer.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/sync/PackageSourceSynchronizer.java index 4f7d05a..d4fd03f 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/sync/PackageSourceSynchronizer.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/sync/PackageSourceSynchronizer.java @@ -240,8 +240,8 @@ public class PackageSourceSynchronizer { ResourceType rt = p.getPackageType().getResourceType();
ContentProviderPackageDetailsKey key; - key = new ContentProviderPackageDetailsKey(p.getName(), pv.getVersion(), p.getPackageType().getName(), pv - .getArchitecture().getName(), rt.getName(), rt.getPlugin()); + key = new ContentProviderPackageDetailsKey(p.getName(), pv.getVersion(), pv.getRelease(), pv.getEpoch(), p + .getPackageType().getName(), pv.getArchitecture().getName(), rt.getName(), rt.getPlugin());
ContentProviderPackageDetails details = new ContentProviderPackageDetails(key); details.setClassification(pv.getGeneralPackage().getClassification()); diff --git a/modules/enterprise/server/plugins/disk/src/main/java/org/rhq/enterprise/server/plugins/disk/DiskSource.java b/modules/enterprise/server/plugins/disk/src/main/java/org/rhq/enterprise/server/plugins/disk/DiskSource.java index 336117f..3155976 100644 --- a/modules/enterprise/server/plugins/disk/src/main/java/org/rhq/enterprise/server/plugins/disk/DiskSource.java +++ b/modules/enterprise/server/plugins/disk/src/main/java/org/rhq/enterprise/server/plugins/disk/DiskSource.java @@ -316,7 +316,7 @@ public class DiskSource implements ContentProvider, PackageSource, RepoSource {
String resourceAndPlugin = configuration.getSimpleValue("resourceType", null);
- String resourceType = resourceAndPlugin.substring( (resourceAndPlugin.indexOf('-') + 1) ); + String resourceType = resourceAndPlugin.substring((resourceAndPlugin.indexOf('-') + 1)); String pluginType = resourceAndPlugin.substring(0, resourceAndPlugin.indexOf('-'));
supportedPackageType.resourceTypeName = resourceType; diff --git a/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNHelper.java b/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNHelper.java index 411bbb9..7729959 100644 --- a/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNHelper.java +++ b/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNHelper.java @@ -247,19 +247,11 @@ public class RHNHelper { String downloadName = constructRpmDownloadName(name, version, p.getRelease(), p.getEpoch(), arch); String displayName = constructRpmDisplayName(name, version, p.getRelease(), arch); // - // RHQ doesn't have the concept of Epoch or Release, this is causing us to lose packages which have - // the same version but different release or epoch. Look at the hashcode() definition for PackageDetailsKey - // and the PackageReport's use of a Set<ContentProviderPackageDetails> to see the problem. - // The solution we are targetting here is to store the package version inside of RHQ as a conglomerate of - // epoch:version-release - // - String rhqVersion = version + "-" + release; - if (!StringUtils.isBlank(epoch)) { - rhqVersion = epoch + ":" + rhqVersion; - } + // Release and epoch definition is added to Package domain model, so we do not need to append release and epoch + // information to version string anymore.
- ContentProviderPackageDetailsKey key = new ContentProviderPackageDetailsKey(name, rhqVersion, "rpm", arch, - "Linux", "Platforms"); + ContentProviderPackageDetailsKey key = new ContentProviderPackageDetailsKey(name, version, release, epoch, + "rpm", arch, "Linux", "Platforms"); ContentProviderPackageDetails pkg = new ContentProviderPackageDetails(key);
pkg.setDisplayName(name); diff --git a/modules/enterprise/server/plugins/yum/src/main/java/org/rhq/enterprise/server/plugins/yum/Repo.java b/modules/enterprise/server/plugins/yum/src/main/java/org/rhq/enterprise/server/plugins/yum/Repo.java index 318a031..d4c806e 100644 --- a/modules/enterprise/server/plugins/yum/src/main/java/org/rhq/enterprise/server/plugins/yum/Repo.java +++ b/modules/enterprise/server/plugins/yum/src/main/java/org/rhq/enterprise/server/plugins/yum/Repo.java @@ -219,10 +219,13 @@ public class Repo { */ private ContentProviderPackageDetails getDetails(Element p) throws Exception { String name = p.getChildText("name", Repodata.yumns); - String version = encodeVersion(p); + String version = p.getAttributeValue("ver"); + String release = p.getAttributeValue("rel"); + String epoch = p.getAttributeValue("epoch"); String arch = p.getChildText("arch", Repodata.yumns); - ContentProviderPackageDetailsKey key = new ContentProviderPackageDetailsKey(name, version, "rpm", arch, - "Linux", "Platforms"); + + ContentProviderPackageDetailsKey key = new ContentProviderPackageDetailsKey(name, version, release, epoch, + "rpm", arch, "Linux", "Platforms"); ContentProviderPackageDetails pkg = new ContentProviderPackageDetails(key); String filename = filename(p); pkg.setDisplayName(filename); diff --git a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/StandaloneManagedDeploymentComponent.java b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/StandaloneManagedDeploymentComponent.java index 4e48e7c..127c1c7 100644 --- a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/StandaloneManagedDeploymentComponent.java +++ b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/StandaloneManagedDeploymentComponent.java @@ -37,11 +37,12 @@ import java.util.Set; import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.jboss.deployers.spi.management.ManagementView; import org.jboss.deployers.spi.management.deploy.DeploymentManager; import org.jboss.deployers.spi.management.deploy.DeploymentProgress; import org.jboss.deployers.spi.management.deploy.DeploymentStatus; -import org.jboss.profileservice.spi.NoSuchDeploymentException; + import org.rhq.core.domain.content.PackageDetailsKey; import org.rhq.core.domain.content.PackageType; import org.rhq.core.domain.content.transfer.ContentResponseResult; @@ -176,8 +177,7 @@ public class StandaloneManagedDeploymentComponent extends AbstractManagedDeploym if (packages.size() != 1) { log.warn("Request to update " + resourceTypeName + " file contained multiple packages: " + packages); DeployPackagesResponse response = new DeployPackagesResponse(ContentResponseResult.FAILURE); - response - .setOverallRequestErrorMessage("Only one " + resourceTypeName + " can be updated at a time."); + response.setOverallRequestErrorMessage("Only one " + resourceTypeName + " can be updated at a time."); return response; }
@@ -217,8 +217,8 @@ public class StandaloneManagedDeploymentComponent extends AbstractManagedDeploym FileUtils.copyFile(this.deploymentFile, backupOfOriginalFile, true); } } catch (Exception e) { - throw new RuntimeException("Failed to backup existing " + resourceTypeName + "'" + this.deploymentFile + "' to '" - + backupOfOriginalFile + "'."); + throw new RuntimeException("Failed to backup existing " + resourceTypeName + "'" + this.deploymentFile + + "' to '" + backupOfOriginalFile + "'."); }
// Now stop the original app. @@ -253,10 +253,9 @@ public class StandaloneManagedDeploymentComponent extends AbstractManagedDeploym if (this.deploymentFile.exists()) { try { FileUtils.forceDelete(this.deploymentFile); - } - catch (IOException e1) { + } catch (IOException e1) { log.debug("Failed to delete application file '" + this.deploymentFile - + "' that failed to deploy.", e1); + + "' that failed to deploy.", e1); } } // Now redeploy the original file - this generally should succeed. @@ -267,8 +266,8 @@ public class StandaloneManagedDeploymentComponent extends AbstractManagedDeploym errorMessage += " ***** FAILED TO ROLLBACK TO ORIGINAL APPLICATION FILE. *****: " + ThrowableUtil.getAllMessages(e1); } - log.info("Failed to update " + resourceTypeName + " file '" - + this.deploymentFile + "' using [" + packageDetails + "]."); + log.info("Failed to update " + resourceTypeName + " file '" + this.deploymentFile + "' using [" + + packageDetails + "]."); return failApplicationDeployment(errorMessage, packageDetails); }
@@ -282,7 +281,7 @@ public class StandaloneManagedDeploymentComponent extends AbstractManagedDeploym response.addPackageResponse(packageResponse);
log.debug("Updated " + resourceTypeName + " file '" + this.deploymentFile - + "' successfully - returning response [" + response + "]..."); + + "' successfully - returning response [" + response + "]...");
return response; } @@ -297,10 +296,10 @@ public class StandaloneManagedDeploymentComponent extends AbstractManagedDeploym } catch (Exception e) { // The deployment no longer exists, so there's nothing for us to do. Someone most likely undeployed it // outside of Jopr or EmbJopr, e.g. via the jmx-console or by deleting the app file from the deploy dir. - log.warn("Cannot delete the deployment [" + this.deploymentName + "], since it no longer exists"); + log.warn("Cannot delete the deployment [" + this.deploymentName + "], since it no longer exists"); return; } - + log.debug("Stopping deployment [" + this.deploymentName + "]..."); DeploymentProgress progress = deploymentManager.stop(this.deploymentName); DeploymentStatus stopStatus = DeploymentUtils.run(progress); diff --git a/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/ApplicationComponent.java b/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/ApplicationComponent.java index b9ae355..6ed76b1 100644 --- a/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/ApplicationComponent.java +++ b/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/ApplicationComponent.java @@ -51,9 +51,9 @@ import org.rhq.core.pluginapi.content.ContentFacet; import org.rhq.core.pluginapi.content.ContentServices; import org.rhq.core.pluginapi.content.version.PackageVersions; import org.rhq.core.pluginapi.inventory.DeleteResourceFacet; -import org.rhq.core.pluginapi.util.FileUtils; import org.rhq.core.pluginapi.operation.OperationFacet; import org.rhq.core.pluginapi.operation.OperationResult; +import org.rhq.core.pluginapi.util.FileUtils; import org.rhq.core.util.ZipUtil; import org.rhq.core.util.exception.ThrowableUtil; import org.rhq.plugins.jbossas.helper.MainDeployer; @@ -64,8 +64,8 @@ import org.rhq.plugins.jmx.MBeanResourceComponent; * * @author Ian Springer */ -public class ApplicationComponent - extends MBeanResourceComponent<JBossASServerComponent> implements ContentFacet, DeleteResourceFacet, OperationFacet { +public class ApplicationComponent extends MBeanResourceComponent<JBossASServerComponent> implements ContentFacet, + DeleteResourceFacet, OperationFacet { private static final String BACKUP_FILE_EXTENSION = ".rej";
/** @@ -106,12 +106,10 @@ public class ApplicationComponent if (packageFile.isDirectory()) { fileToSend = File.createTempFile("rhq", ".zip"); ZipUtil.zipFileOrDirectory(packageFile, fileToSend); - } - else + } else fileToSend = packageFile; return new BufferedInputStream(new FileInputStream(fileToSend)); - } - catch (IOException e) { + } catch (IOException e) { throw new RuntimeException("Failed to retrieve package bits for " + packageDetails, e); } } @@ -124,20 +122,20 @@ public class ApplicationComponent String fullFileName = pluginConfiguration.getSimpleValue(FILENAME_PLUGIN_CONFIG_PROP, null);
if (fullFileName == null) { - throw new IllegalStateException("Plugin configuration does not contain the full file name of the EAR/WAR file."); + throw new IllegalStateException( + "Plugin configuration does not contain the full file name of the EAR/WAR file."); }
// If the parent EAR/WAR resource was found, this file should exist File file = new File(fullFileName); - if (file.exists()) - { + if (file.exists()) { // Package name and file name of the application are the same String fileName = new File(fullFileName).getName();
PackageVersions versions = loadApplicationVersions(); String version = versions.getVersion(fileName); - // First discovery of this EAR/WAR + if (version == null) { version = "1.0"; versions.putVersion(fileName, version); @@ -174,7 +172,8 @@ public class ApplicationComponent if (packages.size() != 1) { log.warn("Request to update an EAR/WAR file contained multiple packages."); DeployPackagesResponse response = new DeployPackagesResponse(ContentResponseResult.FAILURE); - response.setOverallRequestErrorMessage("When deploying an EAR/WAR, only one EAR/WAR can be updated at a time."); + response + .setOverallRequestErrorMessage("When deploying an EAR/WAR, only one EAR/WAR can be updated at a time."); return response; }
@@ -191,10 +190,9 @@ public class ApplicationComponent File tempFile; try { tempFile = writeNewAppBitsToTempFile(appFile, contentServices, packageDetails); - } - catch (Exception e) { + } catch (Exception e) { return failApplicationDeployment("Error writing new application bits to temporary file - cause: " + e, - packageDetails); + packageDetails); }
// Backup the existing app file/dir to <filename>.rej. @@ -208,8 +206,7 @@ public class ApplicationComponent MainDeployer mainDeployer = getParentResourceComponent().getMainDeployer(); try { mainDeployer.redeploy(appFile); - } - catch (Exception e) { + } catch (Exception e) { // Deploy failed - rollback to the original app file... String errorMessage = ThrowableUtil.getAllMessages(e); try { @@ -218,10 +215,9 @@ public class ApplicationComponent // Need to redeploy the original file - this generally should succeed. mainDeployer.redeploy(appFile); errorMessage += " ***** ROLLED BACK TO ORIGINAL APPLICATION FILE. *****"; - } - catch (Exception e1) { + } catch (Exception e1) { errorMessage += " ***** FAILED TO ROLLBACK TO ORIGINAL APPLICATION FILE. *****: " - + ThrowableUtil.getAllMessages(e1); + + ThrowableUtil.getAllMessages(e1); } return failApplicationDeployment(errorMessage, packageDetails); } @@ -232,8 +228,8 @@ public class ApplicationComponent persistApplicationVersion(packageDetails, appFile);
DeployPackagesResponse response = new DeployPackagesResponse(ContentResponseResult.SUCCESS); - DeployIndividualPackageResponse packageResponse = - new DeployIndividualPackageResponse(packageDetails.getKey(), ContentResponseResult.SUCCESS); + DeployIndividualPackageResponse packageResponse = new DeployIndividualPackageResponse(packageDetails.getKey(), + ContentResponseResult.SUCCESS); response.addPackageResponse(packageResponse);
return response; @@ -247,21 +243,16 @@ public class ApplicationComponent
File file = new File(fullFileName);
- if (file.exists()) { try { getParentResourceComponent().undeployFile(file); - } - catch (Exception e) { + } catch (Exception e) { log.error("Failed to undeploy file [" + file + "].", e); throw e; - } - finally - { + } finally { try { FileUtils.purge(file, true); - } - catch(IOException e) { + } catch (IOException e) { log.error("Failed to delete file [" + file + "].", e); // if the undeploy also failed that exception will be lost // and this one will be seen by the caller instead. @@ -271,8 +262,7 @@ public class ApplicationComponent throw e; } } - } - else { + } else { log.info("deleteResource: File [" + fullFileName + "] was not found - ignoring."); }
@@ -286,39 +276,36 @@ public class ApplicationComponent Configuration pluginConfig = getResourceContext().getPluginConfiguration(); String path = pluginConfig.getSimpleValue(FILENAME_PLUGIN_CONFIG_PROP, null); for (MeasurementScheduleRequest request : requests) { - String metricName = request.getName(); - if (metricName.equals(APPLICATION_PATH_TRAIT)) { - MeasurementDataTrait trait = new MeasurementDataTrait(request, path); - report.addData(trait); - } - else if (metricName.equals(APPLICATION_EXPLODED_TRAIT)) { - boolean exploded = new File(path).isDirectory(); - MeasurementDataTrait trait = new MeasurementDataTrait(request, (exploded) ? "yes" : "no"); - report.addData(trait); - } + String metricName = request.getName(); + if (metricName.equals(APPLICATION_PATH_TRAIT)) { + MeasurementDataTrait trait = new MeasurementDataTrait(request, path); + report.addData(trait); + } else if (metricName.equals(APPLICATION_EXPLODED_TRAIT)) { + boolean exploded = new File(path).isDirectory(); + MeasurementDataTrait trait = new MeasurementDataTrait(request, (exploded) ? "yes" : "no"); + report.addData(trait); + } } } }
- // OperationFacet Implementation ------------------------------------------------
- public OperationResult invokeOperation(String name, Configuration parameters) throws InterruptedException, Exception { + public OperationResult invokeOperation(String name, Configuration parameters) throws InterruptedException, + Exception { if ("revert".equals(name)) { try { revertFromBackupFile(); return new OperationResult("Successfully reverted from backup"); - } - catch (Exception e) { + } catch (Exception e) { throw new RuntimeException("Error reverting from Backup: " + e.getMessage()); } - } - else { - return super.invokeOperation(name,parameters); + } else { + return super.invokeOperation(name, parameters); } }
- // Public -------------------------------------------- + // Public --------------------------------------------
/** * Returns the name of the application. @@ -357,20 +344,19 @@ public class ApplicationComponent String fileName; // Check if we have an exploded war or not. if (fullFileName != null && fullFileName.endsWith("/")) { - fileName = fullFileName.substring(0,fullFileName.length()-1); - } - else { + fileName = fullFileName.substring(0, fullFileName.length() - 1); + } else { fileName = fullFileName; }
- backup = new File (fileName + ".bak"); + backup = new File(fileName + ".bak");
if (!backup.exists()) { throw new FileNotFoundException("Backup file " + backup + " does not exist"); } File directory = backup.getParentFile(); if (!directory.canWrite()) { - throw new IOException("Can not modify directory " + directory ); + throw new IOException("Can not modify directory " + directory); }
File tmpBackup = new File(fileName + ".tmp.bak"); @@ -388,21 +374,17 @@ public class ApplicationComponent // move backup in failed good = tmpBackup.renameTo(file); if (!good) { - throw new IOException("Installing backup " + backup + " failed and re-installing the original from " + - tmpBackup + " failed too. Please correct this manually" ); + throw new IOException("Installing backup " + backup + " failed and re-installing the original from " + + tmpBackup + " failed too. Please correct this manually"); } - } - else { + } else { // installing from backup worked - FileUtils.purge(tmpBackup,true); + FileUtils.purge(tmpBackup, true); } getParentResourceComponent().deployFile(file);
- }
- - // Private --------------------------------------------
/** @@ -423,8 +405,8 @@ public class ApplicationComponent
String dataDirectory = dataDirectoryFile.getAbsolutePath();
- log.debug("Creating application versions store with plugin name [" + pluginName + - "] and data directory [" + dataDirectory + "]"); + log.debug("Creating application versions store with plugin name [" + pluginName + "] and data directory [" + + dataDirectory + "]");
versions = new PackageVersions(pluginName, dataDirectory); versions.loadFromDisk(); @@ -444,8 +426,8 @@ public class ApplicationComponent private DeployPackagesResponse failApplicationDeployment(String errorMessage, ResourcePackageDetails packageDetails) { DeployPackagesResponse response = new DeployPackagesResponse(ContentResponseResult.FAILURE);
- DeployIndividualPackageResponse packageResponse = - new DeployIndividualPackageResponse(packageDetails.getKey(), ContentResponseResult.FAILURE); + DeployIndividualPackageResponse packageResponse = new DeployIndividualPackageResponse(packageDetails.getKey(), + ContentResponseResult.FAILURE); packageResponse.setErrorMessage(errorMessage);
response.addPackageResponse(packageResponse); @@ -462,8 +444,7 @@ public class ApplicationComponent private void deleteBackupOfOriginalFile(File backupOfOriginalFile) { try { FileUtils.purge(backupOfOriginalFile, true); - } - catch (Exception e) { + } catch (Exception e) { // not critical. log.warn("Failed to delete backup of original file: " + backupOfOriginalFile); } @@ -494,8 +475,8 @@ public class ApplicationComponent } }
- private File writeNewAppBitsToTempFile(File file, ContentServices contentServices, ResourcePackageDetails packageDetails - ) throws Exception { + private File writeNewAppBitsToTempFile(File file, ContentServices contentServices, + ResourcePackageDetails packageDetails) throws Exception { File tempDir = getResourceContext().getTemporaryDirectory(); File tempFile = new File(tempDir.getAbsolutePath(), file.getName() + System.currentTimeMillis());
@@ -507,7 +488,8 @@ public class ApplicationComponent OutputStream tempOutputStream = null; try { tempOutputStream = new BufferedOutputStream(new FileOutputStream(tempFile)); - contentServices.downloadPackageBits(getResourceContext().getContentContext(), packageDetails.getKey(), tempOutputStream, true); + contentServices.downloadPackageBits(getResourceContext().getContentContext(), packageDetails.getKey(), + tempOutputStream, true); } catch (IOException e) { log.error("Error writing updated application bits to temporary location: " + tempFile, e); throw e; diff --git a/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/util/JarContentDelegate.java b/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/util/JarContentDelegate.java index a334488..c099fe9 100644 --- a/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/util/JarContentDelegate.java +++ b/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/util/JarContentDelegate.java @@ -1,25 +1,25 @@ - /* - * Jopr Management Platform - * Copyright (C) 2005-2008 Red Hat, Inc. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, as - * published by the Free Software Foundation, and/or the GNU Lesser - * General Public License, version 2.1, also as published by the Free - * Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License and the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License - * and the GNU Lesser General Public License along with this program; - * if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ +/* + * Jopr Management Platform + * Copyright (C) 2005-2008 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation, and/or the GNU Lesser + * General Public License, version 2.1, also as published by the Free + * Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License and the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License + * and the GNU Lesser General Public License along with this program; + * if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ package org.rhq.plugins.jbossas.util;
import java.io.File; @@ -89,25 +89,21 @@ public class JarContentDelegate extends FileContentDelegate { jf = new JarFile(file);
Manifest manifest = jf.getManifest(); - String version=null; + String version = null;
- if (manifest!=null) { + if (manifest != null) { Attributes attributes = manifest.getMainAttributes(); - + version = attributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
config.put(new PropertySimple("version", version)); - config.put(new PropertySimple("title", attributes.getValue( - Attributes.Name.IMPLEMENTATION_TITLE))); - config.put(new PropertySimple("url", attributes.getValue( - Attributes.Name.IMPLEMENTATION_URL))); - config.put(new PropertySimple("vendor", attributes.getValue( - Attributes.Name.IMPLEMENTATION_VENDOR))); - - config.put(new PropertySimple("classpath", attributes.getValue( - Attributes.Name.CLASS_PATH))); - config.put(new PropertySimple("sealed", attributes.getValue( - Attributes.Name.SEALED))); + config.put(new PropertySimple("title", attributes.getValue(Attributes.Name.IMPLEMENTATION_TITLE))); + config.put(new PropertySimple("url", attributes.getValue(Attributes.Name.IMPLEMENTATION_URL))); + config + .put(new PropertySimple("vendor", attributes.getValue(Attributes.Name.IMPLEMENTATION_VENDOR))); + + config.put(new PropertySimple("classpath", attributes.getValue(Attributes.Name.CLASS_PATH))); + config.put(new PropertySimple("sealed", attributes.getValue(Attributes.Name.SEALED))); }
if (version == null) { @@ -128,10 +124,10 @@ public class JarContentDelegate extends FileContentDelegate { // If we can't open it, don't worry about it, we just won't know the version } finally { try { - if (jf!=null) - jf.close(); + if (jf != null) + jf.close(); } catch (Exception e) { - // Nothing we can do here ... + // Nothing we can do here ... } } } diff --git a/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/content/SimpleContentFactory.java b/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/content/SimpleContentFactory.java index 3fb9123..4c8b2ce 100644 --- a/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/content/SimpleContentFactory.java +++ b/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/content/SimpleContentFactory.java @@ -20,8 +20,10 @@ package org.rhq.plugins.perftest.content;
import java.util.HashSet; import java.util.Set; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.rhq.core.domain.content.PackageDetailsKey; import org.rhq.core.domain.content.PackageType; import org.rhq.core.domain.content.transfer.ResourcePackageDetails; diff --git a/modules/plugins/platform/src/main/java/org/rhq/plugins/platform/content/RpmPackageDiscoveryDelegate.java b/modules/plugins/platform/src/main/java/org/rhq/plugins/platform/content/RpmPackageDiscoveryDelegate.java index 8cbba32..0a91dfe 100644 --- a/modules/plugins/platform/src/main/java/org/rhq/plugins/platform/content/RpmPackageDiscoveryDelegate.java +++ b/modules/plugins/platform/src/main/java/org/rhq/plugins/platform/content/RpmPackageDiscoveryDelegate.java @@ -105,6 +105,7 @@ public class RpmPackageDiscoveryDelegate { while ((rpmName = rpmNameReader.readLine()) != null) { String name = null; String version = null; + String release = null; String epoch = null; String architectureName = null;
@@ -116,7 +117,7 @@ public class RpmPackageDiscoveryDelegate { .setArguments(new String[] { "-q", "--qf", - "%{NAME}\n%{VERSION}.%{RELEASE}\n{EPOCH}\n%{ARCH}\n%{INSTALLTIME}\n%{FILEMD5S}\n%{GROUP}\n%{FILENAMES}\n%{SIZE}\n%{LICENSE}\n%{DESCRIPTION}", + "%{NAME}\n%{VERSION}\n%{RELEASE}\n{EPOCH}\n%{ARCH}\n%{INSTALLTIME}\n%{FILEMD5S}\n%{GROUP}\n%{FILENAMES}\n%{SIZE}\n%{LICENSE}\n%{DESCRIPTION}", rpmName }); rpmQuery.setCaptureOutput(true);
@@ -127,6 +128,7 @@ public class RpmPackageDiscoveryDelegate {
name = rpmDataReader.readLine(); version = rpmDataReader.readLine(); + release = rpmDataReader.readLine(); epoch = rpmDataReader.readLine(); architectureName = rpmDataReader.readLine(); String installTimeString = rpmDataReader.readLine(); @@ -168,10 +170,7 @@ public class RpmPackageDiscoveryDelegate { continue; }
- if ((epoch != null) && (epoch.trim() != "")) { - version = epoch + ":" + version; - } - PackageDetailsKey key = new PackageDetailsKey(name, version, "rpm", architectureName); + PackageDetailsKey key = new PackageDetailsKey(name, version, release, epoch, "rpm", architectureName); ResourcePackageDetails packageDetails = new ResourcePackageDetails(key); packageDetails.setClassification(category); packageDetails.setDisplayName(name); diff --git a/modules/plugins/platform/src/main/java/org/rhq/plugins/platform/content/yum/Primary.java b/modules/plugins/platform/src/main/java/org/rhq/plugins/platform/content/yum/Primary.java index 961e92f..75d5e44 100644 --- a/modules/plugins/platform/src/main/java/org/rhq/plugins/platform/content/yum/Primary.java +++ b/modules/plugins/platform/src/main/java/org/rhq/plugins/platform/content/yum/Primary.java @@ -1,25 +1,25 @@ - /* - * RHQ Management Platform - * Copyright (C) 2005-2008 Red Hat, Inc. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, as - * published by the Free Software Foundation, and/or the GNU Lesser - * General Public License, version 2.1, also as published by the Free - * Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License and the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License - * and the GNU Lesser General Public License along with this program; - * if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ +/* + * RHQ Management Platform + * Copyright (C) 2005-2008 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation, and/or the GNU Lesser + * General Public License, version 2.1, also as published by the Free + * Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License and the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License + * and the GNU Lesser General Public License along with this program; + * if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ package org.rhq.plugins.platform.content.yum;
import java.io.ByteArrayInputStream; @@ -35,6 +35,7 @@ import java.util.concurrent.locks.ReentrantLock; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; + import org.rhq.core.domain.content.PackageDetailsKey; import org.rhq.core.domain.content.composite.PackageVersionMetadataComposite; import org.rhq.core.domain.util.PageControl; @@ -280,6 +281,14 @@ public class Primary extends Content { sb.append(key.getName()); sb.append(",ver="); sb.append(key.getVersion()); + if (key.getRelease() != null) { + sb.append(",rel="); + sb.append(key.getRelease()); + } + if (key.getEpoch() != null) { + sb.append(",epoch="); + sb.append(key.getEpoch()); + } sb.append(",arch="); sb.append(key.getArchitectureName()); return sb.toString(); @@ -293,6 +302,7 @@ public class Primary extends Content { * @return A package details key. */ static PackageDetailsKey toKey(Map<String, String> args) { - return new PackageDetailsKey(args.get("name"), args.get("ver"), args.get("type"), args.get("arch")); + return new PackageDetailsKey(args.get("name"), args.get("ver"), args.get("rel"), args.get("epoch"), args + .get("type"), args.get("arch")); } -} \ No newline at end of file +} diff --git a/modules/plugins/platform/src/main/java/org/rhq/plugins/platform/win/WindowsSoftwareDelegate.java b/modules/plugins/platform/src/main/java/org/rhq/plugins/platform/win/WindowsSoftwareDelegate.java index e3f4e9c..0039f60 100644 --- a/modules/plugins/platform/src/main/java/org/rhq/plugins/platform/win/WindowsSoftwareDelegate.java +++ b/modules/plugins/platform/src/main/java/org/rhq/plugins/platform/win/WindowsSoftwareDelegate.java @@ -72,7 +72,7 @@ public class WindowsSoftwareDelegate { } try { ResourcePackageDetails details = new ResourcePackageDetails(new PackageDetailsKey(displayName, - version, type.getName(), "noarch")); + version, null, null, type.getName(), "noarch")); details.setFileCreatedDate(getDate(installDateString)); details.setInstallationTimestamp(getDate(installDateString)); details.setFileSize((long) packageKey.getIntValue("EstimatedSize", 0));
commit b1288682040a678d13ab63838fe838af46cf485a Author: Sayli Karmarkar skarmark@redhat.com Date: Mon Feb 1 20:07:08 2010 -0500
1753 - Updating functions and queries to make use of domain model changes made for package release and epoch + adding RpmVersionComparator.java
diff --git a/modules/core/util/src/main/java/org/rhq/core/util/RpmVersionComparator.java b/modules/core/util/src/main/java/org/rhq/core/util/RpmVersionComparator.java new file mode 100644 index 0000000..609b55f --- /dev/null +++ b/modules/core/util/src/main/java/org/rhq/core/util/RpmVersionComparator.java @@ -0,0 +1,162 @@ +/** + * Copyright (c) 2009 Red Hat, Inc. + * + * This software is licensed to you under the GNU General Public License, + * version 2 (GPLv2). There is NO WARRANTY for this software, express or + * implied, including the implied warranties of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 + * along with this software; if not, see + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. + * + * Red Hat trademarks are not licensed under GPLv2. No permission is + * granted to use or replicate Red Hat trademarks that are incorporated + * in this software or its documentation. + */ +package org.rhq.core.util; + +import java.util.Comparator; + +/** + * Implement the rpmvercmp function provided by librpm + * in Java. The comparator operates on two strings that + * represent an RPM version or release. + * + * <p> This comparator is not perfectly antysymmetric for unequal versions, + * but close enough to warrant being a comparator. For examples of asymmetry, + * check the test. + * + * @version $Rev$ + */ +public class RpmVersionComparator implements Comparator { + + /** + * {@inheritDoc} + */ + public int compare(Object o1, Object o2) { + // This method tries to mimick rpmvercmp.c as + // closely as possible; it is deliberately doing things + // in a more C-like manner + if (o1 != null && o1.equals(o2)) { + return 0; + } + + String str1 = (String) o1; + String str2 = (String) o2; + int b1 = 0; + int b2 = 0; + + /* loop through each version segment of str1 and str2 and compare them */ + while (b1 < str1.length() && b2 < str2.length()) { + b1 = skipNonAlnum(str1, b1); + b2 = skipNonAlnum(str2, b2); + + /* grab first completely alpha or completely numeric segment */ + /* str1.substring(b1, e1) and str2.substring(b2, e2) will */ + /* contain the segments */ + int e1, e2; + boolean isnum; + if (xisdigit(xchar(str1, b1))) { + e1 = skipDigits(str1, b1); + e2 = skipDigits(str2, b2); + isnum = true; + } else { + e1 = skipAlpha(str1, b1); + e2 = skipAlpha(str2, b2); + isnum = false; + } + /* take care of the case where the two version segments are */ + /* different types: one numeric, the other alpha (i.e. empty) */ + if (b1 == e1) { + return -1; /* arbitrary */ + } + if (b2 == e2) { + return (isnum ? 1 : -1); + } + + if (isnum) { + b1 = skipZeros(str1, b1, e1); + b2 = skipZeros(str2, b2, e2); + + /* whichever number has more digits wins */ + if (e1 - b1 > e2 - b2) { + return 1; + } + if (e2 - b2 > e1 - b1) { + return -1; + } + } + + /* compareTo will return which one is greater - even if the two */ + /* segments are alpha or if they are numeric. don't return */ + /* if they are equal because there might be more segments to */ + /* compare */ + String seg1 = str1.substring(b1, e1); + String seg2 = str2.substring(b2, e2); + int rc = seg1.compareTo(seg2); + if (rc != 0) { + return (rc < 0) ? -1 : 1; + } + // Reinitilize + b1 = e1; + b2 = e2; + } + /* this catches the case where all numeric and alpha segments have */ + /* compared identically but the segment sepparating characters were */ + /* different */ + if (b1 == str1.length() && b2 == str2.length()) { + return 0; + } + + /* whichever version still has characters left over wins */ + if (b1 == str1.length()) { + return -1; + } else { + return 1; + } + } + + private int skipZeros(String s, int b, int e) { + /* throw away any leading zeros - it's a number, right? */ + while (xchar(s, b) == '0' && b < e) { + b++; + } + return b; + } + + private int skipDigits(String s, int i) { + while (i < s.length() && xisdigit(xchar(s, i))) { + i++; + } + return i; + } + + private int skipAlpha(String s, int i) { + while (i < s.length() && xisalpha(xchar(s, i))) { + i++; + } + return i; + } + + private int skipNonAlnum(String s, int i) { + while (i < s.length() && !xisalnum(xchar(s, i))) { + i++; + } + return i; + } + + private boolean xisalnum(char c) { + return xisdigit(c) || xisalpha(c); + } + + private boolean xisdigit(char c) { + return Character.isDigit(c); + } + + private boolean xisalpha(char c) { + return Character.isLetter(c); + } + + private char xchar(String s, int i) { + return (i < s.length() ? s.charAt(i) : '\0'); + } +}
rhq-commits@lists.fedorahosted.org