Skip to content

Commit 1a909eb

Browse files
committed
Handle problem with EM 2.1 using wrong Bundle-Name.
1 parent 43b376d commit 1a909eb

File tree

3 files changed

+89
-14
lines changed

3 files changed

+89
-14
lines changed

EnrichmentMapPlugin/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
<groupId>org.baderlab.csplugins</groupId>
66
<artifactId>enrichmentmap</artifactId>
7-
<version>2.2</version>
7+
<version>2.2.0</version>
88
<packaging>bundle</packaging>
9+
<name>EnrichmentMap</name>
910

1011
<properties>
1112
<project.name>EnrichmentMap</project.name>

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/CyActivator.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
import static org.cytoscape.work.ServiceProperties.PREFERRED_MENU;
88
import static org.cytoscape.work.ServiceProperties.TITLE;
99

10+
import java.io.File;
11+
import java.io.IOException;
12+
import java.nio.file.Files;
13+
import java.nio.file.Path;
1014
import java.util.HashMap;
1115
import java.util.Map;
1216
import java.util.Properties;
@@ -26,6 +30,7 @@
2630
import org.baderlab.csplugins.enrichmentmap.view.HeatMapPanel;
2731
import org.baderlab.csplugins.enrichmentmap.view.ParametersPanel;
2832
import org.baderlab.csplugins.enrichmentmap.view.PostAnalysisPanel;
33+
import org.cytoscape.application.CyApplicationConfiguration;
2934
import org.cytoscape.application.CyApplicationManager;
3035
import org.cytoscape.application.events.SetCurrentNetworkListener;
3136
import org.cytoscape.application.events.SetCurrentNetworkViewListener;
@@ -64,7 +69,9 @@
6469
import org.cytoscape.work.SynchronousTaskManager;
6570
import org.cytoscape.work.TaskFactory;
6671
import org.cytoscape.work.swing.DialogTaskManager;
72+
import org.osgi.framework.Bundle;
6773
import org.osgi.framework.BundleContext;
74+
import org.osgi.framework.Version;
6875

6976

7077

@@ -98,17 +105,7 @@ public void start(BundleContext bc) {
98105
@SuppressWarnings("rawtypes")
99106
SynchronousTaskManager syncTaskManager = getService(bc, SynchronousTaskManager.class);
100107
DialogTaskManager dialogTaskManager = getService(bc, DialogTaskManager.class);
101-
// Used with annotations to make Groups of nodes
102-
CyGroupFactory groupFactory = getService(bc, CyGroupFactory.class);
103-
CyGroupManager groupManager = getService(bc, CyGroupManager.class);
104-
// Used to create/remove the annotations (ellipses and text labels)
105-
AnnotationManager annotationManager = getService(bc, AnnotationManager.class);
106-
@SuppressWarnings("unchecked")
107-
AnnotationFactory<ShapeAnnotation> shapeFactory = (AnnotationFactory<ShapeAnnotation>) getService(bc, AnnotationFactory.class, "(type=ShapeAnnotation.class)");
108-
@SuppressWarnings("unchecked")
109-
AnnotationFactory<TextAnnotation> textFactory = (AnnotationFactory<TextAnnotation>) getService(bc, AnnotationFactory.class, "(type=TextAnnotation.class)");
110-
CommandExecutorTaskFactory commandExecutor = getService(bc, CommandExecutorTaskFactory.class);
111-
//get the service registrar so we can register new services in different classes
108+
CyApplicationConfiguration applicationConfiguration = getService(bc, CyApplicationConfiguration.class);
112109
CyServiceRegistrar registrar = getService(bc, CyServiceRegistrar.class);
113110

114111

@@ -142,8 +139,7 @@ public void start(BundleContext bc) {
142139
serviceProperties.put(IN_MENU_BAR, "true");
143140
serviceProperties.put(PREFERRED_MENU, APP_MENU);
144141
serviceProperties.put(INSERT_SEPARATOR_BEFORE, "true");
145-
HelpAction helpAction = new HelpAction(serviceProperties, cyApplicationManagerRef, cyNetworkViewManagerRef,
146-
registrar);
142+
HelpAction helpAction = new HelpAction(serviceProperties, cyApplicationManagerRef, cyNetworkViewManagerRef, registrar);
147143
helpAction.setMenuGravity(2.1f);
148144

149145
//About Action
@@ -210,5 +206,7 @@ public void start(BundleContext bc) {
210206
tableColumnTaskFactoryProps.setProperty("tableTypes", "edge");
211207
registerService(bc, tableColumnTaskFactory, TableColumnTaskFactory.class, tableColumnTaskFactoryProps);
212208

209+
Em21Handler.removeVersion21(bc, applicationConfiguration);
213210
}
211+
214212
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package org.baderlab.csplugins.enrichmentmap;
2+
3+
import java.io.File;
4+
import java.nio.file.Files;
5+
import java.nio.file.Path;
6+
7+
import org.cytoscape.application.CyApplicationConfiguration;
8+
import org.osgi.framework.Bundle;
9+
import org.osgi.framework.BundleContext;
10+
import org.osgi.framework.Version;
11+
12+
13+
14+
/**
15+
* Version 2.1.0 of EnrichmentMap on the app store has the wrong Bundle-Name in the manifest file.
16+
* It was accidentally set to "enrichmentmap" when it should be "EnrichmentMap".
17+
* That means the cytoscape app manager won't remove version 2.1 when installing version 2.2 or higher.
18+
* The only fix is to manually remove the 2.1 app file programatically, sigh.
19+
*/
20+
public class Em21Handler {
21+
22+
private static final String baseName = "EnrichmentMap-v2.1.0";
23+
24+
public static void removeVersion21(BundleContext bc, CyApplicationConfiguration appConfig) {
25+
try {
26+
if(isEM21Installed(bc)) {
27+
System.out.println("EnrichmentMap 2.1 is installed");
28+
29+
Path installFolder = getAppInstallFolder(appConfig);
30+
Path jarFile = installFolder.resolve(baseName + ".jar");
31+
32+
boolean deleted = Files.deleteIfExists(jarFile);
33+
if(deleted) {
34+
System.out.println("Deleted EnrichmentMap 2.1 App Jar file: " + jarFile);
35+
}
36+
else {
37+
// We know its installed but the above code didn't delete the file.
38+
// Sometimes the App manager appends numbers to the end of the file name, lets try that.
39+
for(int i = 1; i <= 5; i++) {
40+
jarFile = installFolder.resolve(baseName + "-" + i + ".jar");
41+
deleted = Files.deleteIfExists(jarFile);
42+
if(deleted) {
43+
System.out.println("Deleted App Jar file: " + jarFile);
44+
break;
45+
}
46+
}
47+
if(!deleted) {
48+
// For some reason the file couldn't be deleted.
49+
// Don't pop up a warning dialog, because we've had UI deadocks by throwing up dialogs
50+
// during cytoscape initialization. Just log it.
51+
System.out.println("Could not automatically uninstall EnrichmentMap 2.1, please uninstall it using the App Manager");
52+
}
53+
}
54+
}
55+
} catch(Exception e) {
56+
e.printStackTrace();
57+
}
58+
}
59+
60+
private static boolean isEM21Installed(BundleContext bc) {
61+
for(Bundle bundle : bc.getBundles()) {
62+
String name = bundle.getSymbolicName();
63+
Version version = bundle.getVersion();
64+
if(name.equals("org.baderlab.csplugins.enrichmentmap") && version.equals(new Version(2,1,0))) {
65+
return true;
66+
}
67+
}
68+
return false;
69+
}
70+
71+
private static Path getAppInstallFolder(CyApplicationConfiguration appConfig) {
72+
File configFolder = appConfig.getConfigurationDirectoryLocation();
73+
Path installFolder = configFolder.toPath().resolve("3/apps/installed");
74+
return installFolder;
75+
}
76+
}

0 commit comments

Comments
 (0)