List of usage examples for org.apache.maven.artifact.versioning ComparableVersion equals
@Override public boolean equals(Object o)
From source file:org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory.java
License:Open Source License
private static void checkCompatibleVersion(Plugin metadataPlugin) { ComparableVersion version = new ComparableVersion(metadataPlugin.getVersion()); if (!version.equals(new ComparableVersion(LIFECYCLE_MAPPING_PLUGIN_VERSION))) { SourceLocation location = SourceLocationHelper.findLocation(metadataPlugin, SourceLocationHelper.VERSION); throw new LifecycleMappingConfigurationException( NLS.bind(Messages.LifecycleMappingPluginVersionIncompatible, metadataPlugin.getVersion()), location);/* ww w .j a va2 s. co m*/ } }
From source file:org.rhq.core.clientapi.descriptor.AgentPluginDescriptorUtil.java
License:Open Source License
/** * Determines which of the two plugins is obsolete - in other words, this determines which * plugin is older. Each plugin must have the same logical name, but * one of which will be determined to be obsolete and should not be deployed. * If they have the same MD5, they are identical, so <code>null</code> will be returned. * Otherwise, the versions are compared and the one with the oldest version is obsolete. * If they have the same versions, the one with the oldest timestamp is obsolete. * If they have the same timestamp too, we have no other way to determine obsolescence so plugin1 * will be picked arbitrarily and a message will be logged when this occurs. * * @param plugin1/*from w w w . j a v a 2s . com*/ * @param plugin2 * @return a reference to the obsolete plugin (plugin1 or plugin2 reference will be returned) * <code>null</code> is returned if they are the same (i.e. they have the same MD5) * @throws IllegalArgumentException if the two plugins have different logical names */ public static Plugin determineObsoletePlugin(Plugin plugin1, Plugin plugin2) { if (!plugin1.getName().equals(plugin2.getName())) { throw new IllegalArgumentException( "The two plugins don't have the same name:" + plugin1 + ":" + plugin2); } if (plugin1.getMd5().equals(plugin2.getMd5())) { return null; } else { String version1Str = plugin1.getVersion(); String version2Str = plugin2.getVersion(); ComparableVersion plugin1Version = new ComparableVersion((version1Str != null) ? version1Str : "0"); ComparableVersion plugin2Version = new ComparableVersion((version2Str != null) ? version2Str : "0"); if (plugin1Version.equals(plugin2Version)) { if (plugin1.getMtime() == plugin2.getMtime()) { LOG.info("Plugins [" + plugin1 + ", " + plugin2 + "] are the same logical plugin but have different content. The plugin [" + plugin1 + "] will be considered obsolete."); return plugin1; } else if (plugin1.getMtime() < plugin2.getMtime()) { return plugin1; } else { return plugin2; } } else if (plugin1Version.compareTo(plugin2Version) < 0) { return plugin1; } else { return plugin2; } } }
From source file:org.rhq.enterprise.server.core.AgentManagerBean.java
License:Open Source License
@ExcludeDefaultInterceptors public AgentVersionCheckResults isAgentVersionSupported(AgentVersion agentVersionInfo) { try {//from ww w. j a v a 2 s . co m Properties properties = getAgentUpdateVersionFileContent(); String supportedAgentBuilds = properties.getProperty(RHQ_AGENT_SUPPORTED_BUILDS); // this is optional String latestAgentVersion = properties.getProperty(RHQ_AGENT_LATEST_VERSION); String latestAgentBuild = properties.getProperty(RHQ_AGENT_LATEST_BUILD_NUMBER); if (latestAgentVersion == null) { throw new NullPointerException("no agent version in file"); } boolean isSupported; //if no list of supportedBuilds provident then, if (supportedAgentBuilds == null || supportedAgentBuilds.isEmpty()) { // we weren't given a regex of supported versions, make a simple string equality test on latest agent version ComparableVersion agent = new ComparableVersion(agentVersionInfo.getVersion()); ComparableVersion server = new ComparableVersion(latestAgentVersion); isSupported = agent.equals(server); } else { // we were given a regex of supported builds, check the agent build to see if it matches the regex isSupported = agentVersionInfo.getBuild().matches(supportedAgentBuilds); } return new AgentVersionCheckResults(isSupported, new AgentVersion(latestAgentVersion, latestAgentBuild)); } catch (Exception e) { LOG.warn("Cannot determine if agent version [" + agentVersionInfo + "] is supported. Cause: " + e); return new AgentVersionCheckResults(false, null); // assume we can't talk to it } }
From source file:org.rhq.enterprise.server.xmlschema.ServerPluginDescriptorUtil.java
License:Open Source License
/** * Determines which of the two plugins is obsolete - in other words, this determines which * plugin is older. Each plugin must have the same logical name, but * one of which will be determined to be obsolete and should not be deployed. * If they have the same MD5, they are identical, so <code>null</code> will be returned. * Otherwise, the versions are compared and the one with the oldest version is obsolete. * If they have the same versions, the one with the oldest timestamp is obsolete. * If they have the same timestamp too, we have no other way to determine obsolescence so plugin1 * will be picked arbitrarily and a message will be logged when this occurs. * * @param plugin1/*from w w w . j av a 2 s .co m*/ * @param plugin2 * @return a reference to the obsolete plugin (plugin1 or plugin2 reference will be returned) * <code>null</code> is returned if they are the same (i.e. they have the same MD5) * @throws IllegalArgumentException if the two plugins have different logical names or different types */ public static ServerPlugin determineObsoletePlugin(ServerPlugin plugin1, ServerPlugin plugin2) { if (!plugin1.getName().equals(plugin2.getName())) { throw new IllegalArgumentException( "The two plugins don't have the same name:" + plugin1 + ":" + plugin2); } if (!plugin1.getType().equals(plugin2.getType())) { throw new IllegalArgumentException( "The two plugins don't have the same type:" + plugin1 + ":" + plugin2); } if (plugin1.getMd5().equals(plugin2.getMd5())) { return null; } else { String version1Str = plugin1.getVersion(); String version2Str = plugin2.getVersion(); ComparableVersion plugin1Version = new ComparableVersion((version1Str != null) ? version1Str : "0"); ComparableVersion plugin2Version = new ComparableVersion((version2Str != null) ? version2Str : "0"); if (plugin1Version.equals(plugin2Version)) { if (plugin1.getMtime() == plugin2.getMtime()) { LOG.info("Plugins [" + plugin1 + ", " + plugin2 + "] are the same logical plugin but have different content. The plugin [" + plugin1 + "] will be considered obsolete."); return plugin1; } else if (plugin1.getMtime() < plugin2.getMtime()) { return plugin1; } else { return plugin2; } } else if (plugin1Version.compareTo(plugin2Version) < 0) { return plugin1; } else { return plugin2; } } }