Example usage for org.apache.maven.artifact.versioning ComparableVersion toString

List of usage examples for org.apache.maven.artifact.versioning ComparableVersion toString

Introduction

In this page you can find the example usage for org.apache.maven.artifact.versioning ComparableVersion toString.

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:org.jbpm.kie.services.api.DeploymentIdResolver.java

License:Apache License

public static String findLatest(Collection<String> deploymentIds) {
    List<ComparableVersion> comparableVersions = new ArrayList<ComparableVersion>();
    Map<String, String> versionToIdentifier = new HashMap<String, String>();
    for (String deploymentId : deploymentIds) {
        GAVInfo gav = new GAVInfo(deploymentId);
        comparableVersions.add(new ComparableVersion(gav.getVersion()));
        versionToIdentifier.put(gav.getVersion(), deploymentId);
    }//from w  w w.j ava2  s.  c o m

    ComparableVersion latest = Collections.max(comparableVersions);

    return versionToIdentifier.get(latest.toString());
}

From source file:org.rhq.enterprise.server.core.plugin.ProductPluginDeployer.java

License:Open Source License

/**
 * This is the mechanism to kick off the registration of a new plugin. You must ensure you call this at the
 * appropriate time such that the plugin getting registered already has its dependencies registered.
 *//* www  .  j a  v a2 s .c  om*/
private void registerPluginJar(PluginDescriptor pluginDescriptor, CannedGroupAddition addition,
        DeploymentInfo deploymentInfo, boolean forceUpdate) {
    if (pluginDescriptor == null) {
        log.error("Missing plugin descriptor; is [" + deploymentInfo.url + "] a valid plugin?");
        return;
    }

    try {
        File localPluginFile = new File(deploymentInfo.url.toURI());

        String pluginName = pluginDescriptor.getName();
        String displayName = pluginDescriptor.getDisplayName();
        String pluginNameDisplayName = pluginName + " (" + displayName + ")";
        ComparableVersion comparableVersion = this.pluginVersions.get(pluginName);
        String version = (comparableVersion != null) ? comparableVersion.toString() : null;
        log.debug("Registering RHQ plugin " + pluginNameDisplayName + ", "
                + ((version != null) ? "version " + version : "undefined version") + "...");
        checkVersionCompatibility(pluginDescriptor.getAmpsVersion());

        String filename = getPluginJarFilename(deploymentInfo); // make sure this is only the filename
        Plugin plugin = new Plugin(pluginName, filename);
        plugin.setDisplayName((displayName != null) ? displayName : pluginName);
        plugin.setEnabled(true);
        plugin.setDescription(pluginDescriptor.getDescription());
        plugin.setAmpsVersion(getAmpsVersion(pluginDescriptor));

        // get the last modified of the "real" plugin jar since that's the one the user touches
        long mtime = deploymentInfo.url.openConnection().getLastModified();
        plugin.setMtime(mtime);

        if (pluginDescriptor.getHelp() != null && !pluginDescriptor.getHelp().getContent().isEmpty()) {
            plugin.setHelp(String.valueOf(pluginDescriptor.getHelp().getContent().get(0)));
        }

        plugin.setVersion(version);
        plugin.setMD5(MessageDigestGenerator.getDigestString(localPluginFile));

        // this manager is responsible for handling the munging of plugins that depend on other plugins
        // since we assume we are called in the proper deployment order, this should not fail
        // if we are called when hot-deploying a plugin whose dependencies aren't deployed, this will fail
        PluginManagerLocal pluginMgr = LookupUtil.getPluginManager();
        pluginMgr.registerPlugin(plugin, pluginDescriptor, localPluginFile, forceUpdate);
        if (addition != null) {
            GroupDefinitionManagerLocal groupDefMgr = LookupUtil.getGroupDefinitionManager();
            groupDefMgr.updateGroupsByCannedExpressions(pluginName, addition.getExpressions());
        }
    } catch (Exception e) {
        log.error("Failed to register RHQ plugin file [" + deploymentInfo.url + "]", e);
    }
}

From source file:org.rhq.enterprise.server.core.plugin.ServerPluginScanner.java

License:Open Source License

/**
 * This is called when a server plugin jar has been found on the filesystem that hasn't been seen yet
 * during this particular lifetime of the scanner. This does not necessarily mean its a new plugin jar,
 * it only means this is the first time we've seen it since this object has been instantiated.
 * This method will check to see if the database record matches the new plugin file and if so, does nothing.
 * /*from  w  w w  .j a  v a 2 s  .  com*/
 * @param pluginFile the new server plugin file
 */
private void registerServerPlugin(File pluginFile) {
    try {
        ServerPluginDescriptorType descriptor;
        descriptor = this.serverPluginsOnFilesystem.get(pluginFile).descriptor;

        String pluginName = descriptor.getName();
        String displayName = descriptor.getDisplayName();

        ComparableVersion version; // this must be non-null, the next line ensures this
        version = ServerPluginDescriptorUtil.getPluginVersion(pluginFile, descriptor);

        log.debug("Registering server plugin [" + pluginName + "], version " + version);

        ServerPlugin plugin = new ServerPlugin(pluginName, pluginFile.getName());
        plugin.setDisplayName((displayName != null) ? displayName : pluginName);
        plugin.setEnabled(!descriptor.isDisabledOnDiscovery());
        plugin.setDescription(descriptor.getDescription());
        plugin.setMtime(pluginFile.lastModified());
        plugin.setVersion(version.toString());
        plugin.setAmpsVersion(descriptor.getApiVersion());
        plugin.setMD5(MessageDigestGenerator.getDigestString(pluginFile));
        plugin.setPluginConfiguration(getDefaultPluginConfiguration(descriptor));
        plugin.setScheduledJobsConfiguration(getDefaultScheduledJobsConfiguration(descriptor));
        plugin.setType(new ServerPluginType(descriptor).stringify());

        if (descriptor.getHelp() != null && !descriptor.getHelp().getContent().isEmpty()) {
            plugin.setHelp(String.valueOf(descriptor.getHelp().getContent().get(0)));
        }

        ServerPluginManagerLocal serverPluginsManager = LookupUtil.getServerPluginManager();

        // see if this plugin has been deleted previously; if so, don't register and delete the file
        PluginKey newPluginKey = new PluginKey(plugin);
        PluginStatusType status = serverPluginsManager.getServerPluginStatus(newPluginKey);

        if (PluginStatusType.DELETED == status) {
            log.warn("Plugin file [" + pluginFile + "] has been detected but that plugin with name ["
                    + pluginName
                    + "] was previously undeployed. Will not re-register that plugin and the file will be deleted.");
            boolean succeeded = pluginFile.delete();
            if (!succeeded) {
                log.error("Failed to delete obsolete plugin file [" + pluginFile + "].");
            }
        } else {
            // now attempt to register the plugin. "dbPlugin" will be the new updated plugin; but if
            // the scanned plugin does not obsolete the current plugin, then dbPlugin will be the old, still valid, plugin.
            SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
            ServerPlugin dbPlugin = serverPluginsManager.registerServerPlugin(subjectManager.getOverlord(),
                    plugin, pluginFile);
            log.info("Registered server plugin [" + dbPlugin.getName() + "], version " + dbPlugin.getVersion());
        }
    } catch (Exception e) {
        log.error("Failed to register server plugin file [" + pluginFile + "]", e);
    }
    return;
}