Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
Warning for plugin incompatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
pimotte committed Jul 25, 2014
1 parent ddcbd80 commit 724c9c0
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
1 change: 1 addition & 0 deletions gradle/gradle/plugins.jar.gradle
Expand Up @@ -32,5 +32,6 @@ task pluginJar(type: Jar, dependsOn: [processResources, compileJava]) {
attributes("Plugin-Date": "${pluginDate}")
attributes("Plugin-App-Min-Version": "${pluginAppMinVersion}")
attributes("Plugin-Release": "${pluginRelease}")
attributes("Conflicts-With": "${conflictsWith}")
}
}
13 changes: 13 additions & 0 deletions syncany-cli/src/main/java/org/syncany/cli/PluginCommand.java
Expand Up @@ -164,6 +164,19 @@ private void printResultList(PluginOperationResult operationResult) {
}

private void printResultInstall(PluginOperationResult operationResult) {
List<String> conflictingPluginIds = operationResult.getConflictingPluginIds();
if (conflictingPluginIds != null && conflictingPluginIds.size() > 0) {
if (conflictingPluginIds.size() == 1) {
out.printf("WARNING: Installed plugin conflicts with other installed plugin: %s\n ",
conflictingPluginIds.get(0));
}
else if (conflictingPluginIds.size() > 1) {
out.printf("WARNING: Installed plugin conflicts with other installed plugins: %s\n",
StringUtil.join(conflictingPluginIds, ", "));
}
out.printf("This means you cannot use these plugins simultaneously in the daemon.\n");

}
if (operationResult.getResultCode() == PluginResultCode.OK) {
out.printf("Plugin successfully installed from %s\n", operationResult.getSourcePluginPath());
out.printf("Install location: %s\n", operationResult.getTargetPluginPath());
Expand Down
Expand Up @@ -17,8 +17,15 @@
*/
package org.syncany.operations.plugin;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
import org.syncany.config.to.RepoTO.TransformerTO;
import org.syncany.util.StringUtil;

@Root(name="pluginInfo")
public class PluginInfo {
Expand Down Expand Up @@ -46,6 +53,10 @@ public class PluginInfo {
@Element(name="downloadUrl", required=false)
private String downloadUrl;

// Comma-seperated string of conflicting plugin ids
@Element(name="conflictsWith", required=false)
private String conflictingPluginIds;

public PluginInfo() {
// Nothing.
}
Expand Down Expand Up @@ -113,4 +124,17 @@ public String getDownloadUrl() {
public void setDownloadUrl(String downloadUrl) {
this.downloadUrl = downloadUrl;
}

public List<String> getConflictingPluginIds() {
if (conflictingPluginIds != null) {
return Arrays.asList(conflictingPluginIds.split(","));
}
else {
return new ArrayList<String>();
}
}

public void setConflictingPluginIds(List<String> conflictingPluginIds) {
this.conflictingPluginIds = (conflictingPluginIds != null) ? StringUtil.join(conflictingPluginIds, ",") : null;
}
}
Expand Up @@ -30,6 +30,7 @@
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
Expand Down Expand Up @@ -224,6 +225,24 @@ private void checkPluginCompatibility(PluginInfo pluginInfo) throws Exception {
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);
}

private String calculateChecksum(File tempPluginJarFile) throws Exception {
Expand Down Expand Up @@ -297,7 +316,9 @@ private PluginInfo readPluginInfoFromJar(File pluginJarFile) throws Exception {
pluginInfo.setPluginDate(jarManifest.getMainAttributes().getValue("Plugin-Date"));
pluginInfo.setPluginAppMinVersion(jarManifest.getMainAttributes().getValue("Plugin-App-Min-Version"));
pluginInfo.setPluginRelease(Boolean.parseBoolean(jarManifest.getMainAttributes().getValue("Plugin-Release")));

if (jarManifest.getMainAttributes().getValue("Conflicts-With") != null) {
pluginInfo.setConflictingPluginIds(Arrays.asList(jarManifest.getMainAttributes().getValue("Conflicts-With")));
}
return pluginInfo;
}
}
Expand Down
Expand Up @@ -31,6 +31,7 @@ public enum PluginResultCode {
private String sourcePluginPath;
private String targetPluginPath;
private PluginInfo affectedPluginInfo;
private List<String> conflictingPluginIds;

public List<ExtendedPluginInfo> getPluginList() {
return pluginList;
Expand Down Expand Up @@ -71,4 +72,12 @@ public String getTargetPluginPath() {
public void setTargetPluginPath(String targetPluginPath) {
this.targetPluginPath = targetPluginPath;
}

public List<String> getConflictingPluginIds() {
return conflictingPluginIds;
}

public void setConflictingPlugins(List<String> conflictingPluginIds) {
this.conflictingPluginIds = conflictingPluginIds;
}
}

0 comments on commit 724c9c0

Please sign in to comment.