Search in sources :

Example 16 with Version

use of com.github.zafarkhaja.semver.Version in project syncany by syncany.

the class PluginOperation method executeList.

private PluginOperationResult executeList() throws Exception {
    final Version applicationVersion = Version.valueOf(Client.getApplicationVersion());
    Map<String, ExtendedPluginInfo> pluginInfos = new TreeMap<String, ExtendedPluginInfo>();
    // First, list local plugins
    if (options.getListMode() == PluginListMode.ALL || options.getListMode() == PluginListMode.LOCAL) {
        for (PluginInfo localPluginInfo : getLocalList()) {
            if (options.getPluginId() != null && !localPluginInfo.getPluginId().equals(options.getPluginId())) {
                continue;
            }
            // Determine standard plugin information
            ExtendedPluginInfo extendedPluginInfo = new ExtendedPluginInfo();
            extendedPluginInfo.setLocalPluginInfo(localPluginInfo);
            extendedPluginInfo.setInstalled(true);
            // Test if plugin can be uninstalled
            Plugin plugin = Plugins.get(localPluginInfo.getPluginId());
            File pluginJarFile = getJarFile(plugin);
            boolean canUninstall = canUninstall(pluginJarFile);
            extendedPluginInfo.setCanUninstall(canUninstall);
            // Add to list
            pluginInfos.put(localPluginInfo.getPluginId(), extendedPluginInfo);
        }
    }
    // Then, list remote plugins
    if (options.getListMode() == PluginListMode.ALL || options.getListMode() == PluginListMode.REMOTE) {
        for (PluginInfo remotePluginInfo : getRemotePluginInfoList()) {
            if (options.getPluginId() != null && !remotePluginInfo.getPluginId().equals(options.getPluginId())) {
                continue;
            }
            ExtendedPluginInfo extendedPluginInfo = pluginInfos.get(remotePluginInfo.getPluginId());
            boolean localPluginInstalled = extendedPluginInfo != null;
            if (!localPluginInstalled) {
                // Locally not installed
                extendedPluginInfo = new ExtendedPluginInfo();
                extendedPluginInfo.setInstalled(false);
                extendedPluginInfo.setRemoteAvailable(true);
            } else {
                // Locally also installed
                extendedPluginInfo.setRemoteAvailable(true);
                Version localVersion = Version.valueOf(extendedPluginInfo.getLocalPluginInfo().getPluginVersion());
                Version remoteVersion = Version.valueOf(remotePluginInfo.getPluginVersion());
                Version remoteMinAppVersion = Version.valueOf(remotePluginInfo.getPluginAppMinVersion());
                boolean localVersionOutdated = localVersion.lessThan(remoteVersion);
                boolean applicationVersionCompatible = applicationVersion.greaterThanOrEqualTo(remoteMinAppVersion);
                boolean pluginIsOutdated = localVersionOutdated && applicationVersionCompatible;
                extendedPluginInfo.setOutdated(pluginIsOutdated);
            }
            extendedPluginInfo.setRemotePluginInfo(remotePluginInfo);
            pluginInfos.put(remotePluginInfo.getPluginId(), extendedPluginInfo);
        }
    }
    result.setPluginList(new ArrayList<ExtendedPluginInfo>(pluginInfos.values()));
    result.setResultCode(PluginResultCode.OK);
    return result;
}
Also used : Version(com.github.zafarkhaja.semver.Version) TreeMap(java.util.TreeMap) File(java.io.File) Plugin(org.syncany.plugins.Plugin)

Example 17 with Version

use of com.github.zafarkhaja.semver.Version in project syncany by syncany.

the class PluginOperation method checkPluginCompatibility.

private void checkPluginCompatibility(PluginInfo pluginInfo) throws Exception {
    Version applicationVersion = Version.valueOf(Client.getApplicationVersion());
    Version pluginAppMinVersion = Version.valueOf(pluginInfo.getPluginAppMinVersion());
    logger.log(Level.INFO, "Checking plugin compatibility:");
    logger.log(Level.INFO, "- Application version:             " + Client.getApplicationVersion() + "(" + applicationVersion + ")");
    logger.log(Level.INFO, "- Plugin min. application version: " + pluginInfo.getPluginAppMinVersion() + "(" + pluginAppMinVersion + ")");
    if (applicationVersion.lessThan(pluginAppMinVersion)) {
        throw new Exception("Plugin is incompatible to this application version. Plugin min. application version is " + pluginInfo.getPluginAppMinVersion() + ", current application version is " + Client.getApplicationVersion());
    }
    // Verify if any conflicting plugins are installed
    logger.log(Level.INFO, "Checking for conflicting plugins.");
    List<String> conflictingIds = pluginInfo.getConflictingPluginIds();
    List<String> conflictingInstalledIds = new ArrayList<String>();
    if (conflictingIds != null) {
        for (String pluginId : conflictingIds) {
            Plugin plugin = Plugins.get(pluginId);
            if (plugin != null) {
                logger.log(Level.INFO, "- Conflicting plugin " + pluginId + " found.");
                conflictingInstalledIds.add(pluginId);
            }
            logger.log(Level.FINE, "- Conflicting plugin " + pluginId + " not installed");
        }
    }
    result.setConflictingPlugins(conflictingInstalledIds);
}
Also used : Version(com.github.zafarkhaja.semver.Version) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Plugin(org.syncany.plugins.Plugin)

Example 18 with Version

use of com.github.zafarkhaja.semver.Version in project syncany by syncany.

the class UpdateOperation method executeCheck.

private UpdateOperationResult executeCheck() throws Exception {
    Version localAppVersion = Version.valueOf(Client.getApplicationVersion());
    String appInfoResponseStr = getAppInfoResponseStr();
    AppInfoResponse appInfoResponse = new Persister().read(AppInfoResponse.class, appInfoResponseStr);
    ArrayList<AppInfo> appInfoList = appInfoResponse.getAppInfoList();
    if (appInfoList.size() > 0) {
        AppInfo remoteAppInfo = appInfoList.get(0);
        Version remoteAppVersion = Version.valueOf(remoteAppInfo.getAppVersion());
        boolean newVersionAvailable = remoteAppVersion.greaterThan(localAppVersion);
        result.setResultCode(UpdateResultCode.OK);
        result.setAppInfo(remoteAppInfo);
        result.setNewVersionAvailable(newVersionAvailable);
        return result;
    } else {
        result.setResultCode(UpdateResultCode.NOK);
        return result;
    }
}
Also used : Version(com.github.zafarkhaja.semver.Version) Persister(org.simpleframework.xml.core.Persister)

Example 19 with Version

use of com.github.zafarkhaja.semver.Version in project graylog2-server by Graylog2.

the class RequiredVersionRule method apply.

@Override
public Statement apply(Statement base, FrameworkMethod method, Object target) {
    log.trace("Running version check hook on test {}", method.getMethod());
    final Version serverUnderTestVersion = restAssuredSetupRule.getServerUnderTestVersion();
    if (serverUnderTestVersion == null) {
        throw new NullPointerException("Server version is null!");
    }
    final RequiresVersion methodAnnotation = method.getMethod().getAnnotation(RequiresVersion.class);
    final RequiresVersion classAnnotation = method.getDeclaringClass().getAnnotation(RequiresVersion.class);
    String versionRequirement = null;
    if (classAnnotation != null) {
        versionRequirement = classAnnotation.value();
    } else if (methodAnnotation != null) {
        versionRequirement = methodAnnotation.value();
    }
    log.debug("Checking {} against version {}: ", versionRequirement, serverUnderTestVersion, versionRequirement != null ? serverUnderTestVersion.satisfies(versionRequirement) : "skipped");
    if (versionRequirement != null && !serverUnderTestVersion.satisfies(versionRequirement)) {
        log.warn("Skipping test <{}> because its version requirement <{}> does not meet the server's API version {}", method.getName(), versionRequirement, serverUnderTestVersion);
        return new IgnoreStatement("API Version " + serverUnderTestVersion + " does not meet test requirement " + versionRequirement);
    } else {
        return base;
    }
}
Also used : Version(com.github.zafarkhaja.semver.Version)

Example 20 with Version

use of com.github.zafarkhaja.semver.Version in project java-buildpack-dependency-builder by cloudfoundry.

the class VersionHolder method parse.

private static Version parse(String raw) {
    StringTokenizer stringTokenizer = new StringTokenizer(raw, ".-");
    Queue<String> tokens = new LinkedList<>();
    while (stringTokenizer.hasMoreElements()) {
        tokens.add(stringTokenizer.nextToken());
    }
    Integer major;
    try {
        major = Integer.parseInt(tokens.peek());
        tokens.remove();
    } catch (NumberFormatException e) {
        major = 0;
    }
    Integer minor;
    try {
        minor = Integer.parseInt(tokens.peek());
        tokens.remove();
    } catch (NumberFormatException e) {
        minor = 0;
    }
    Integer micro;
    try {
        micro = Integer.parseInt(tokens.peek());
        tokens.remove();
    } catch (NumberFormatException e) {
        micro = 0;
    }
    String qualifier = tokens.stream().collect(Collectors.joining("-"));
    try {
        Version version = Version.forIntegers(major, minor, micro);
        if (qualifier != null && !qualifier.isEmpty()) {
            version = version.setPreReleaseVersion(qualifier);
        }
        return version;
    } catch (Exception e) {
        throw new IllegalArgumentException("Invalid version " + raw, e);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) Version(com.github.zafarkhaja.semver.Version) LinkedList(java.util.LinkedList)

Aggregations

Version (com.github.zafarkhaja.semver.Version)27 Test (org.junit.Test)6 File (java.io.File)4 IOException (java.io.IOException)4 BrokerFilterBadVersionException (org.apache.pulsar.broker.loadbalance.BrokerFilterBadVersionException)3 JsonWriter (com.serotonin.json.JsonWriter)2 JsonObject (com.serotonin.json.type.JsonObject)2 JsonString (com.serotonin.json.type.JsonString)2 JsonTypeReader (com.serotonin.json.type.JsonTypeReader)2 StringWriter (java.io.StringWriter)2 HashMap (java.util.HashMap)2 TreeMap (java.util.TreeMap)2 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)2 HttpPost (org.apache.http.client.methods.HttpPost)2 StringEntity (org.apache.http.entity.StringEntity)2 BrokerData (org.apache.pulsar.broker.BrokerData)2 Plugin (org.syncany.plugins.Plugin)2 UpgradeServerVersion (org.talend.dataprep.api.service.upgrade.UpgradeServerVersion)2 NonNull (android.support.annotation.NonNull)1 MongoCluster (com.antwerkz.bottlerocket.clusters.MongoCluster)1