Skip to content

Package: Activator

Activator

nameinstructionbranchcomplexitylinemethod
Activator()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getECPObserverBus()
M: 0 C: 16
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getECPProjectManager()
M: 0 C: 16
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getECPProviderRegistry()
M: 0 C: 16
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
getECPRepositoryManager()
M: 0 C: 16
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
getInstance()
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getStatus(Throwable)
M: 9 C: 20
69%
M: 4 C: 2
33%
M: 3 C: 1
25%
M: 2 C: 5
71%
M: 0 C: 1
100%
log(IStatus)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
log(String)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
log(Throwable)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
log(int, String)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
start(BundleContext)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
stop(BundleContext)
M: 0 C: 20
100%
M: 2 C: 6
75%
M: 2 C: 3
60%
M: 0 C: 10
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2012 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Eike Stepper - initial API and implementation
13: * Eugen Neufeld - JavaDoc
14: *******************************************************************************/
15:
16: package org.eclipse.emf.ecp.internal.core;
17:
18: import org.eclipse.core.runtime.CoreException;
19: import org.eclipse.core.runtime.IStatus;
20: import org.eclipse.core.runtime.Plugin;
21: import org.eclipse.core.runtime.Status;
22: import org.eclipse.emf.ecp.core.ECPProjectManager;
23: import org.eclipse.emf.ecp.core.ECPProviderRegistry;
24: import org.eclipse.emf.ecp.core.ECPRepositoryManager;
25: import org.eclipse.emf.ecp.core.util.observer.ECPObserverBus;
26: import org.eclipse.emfforms.common.ServiceObjectTracker;
27: import org.osgi.framework.BundleContext;
28:
29: /**
30: * This is the Activator for the ECP Core plugin.
31: *
32: * @author Eike Stepper
33: * @author Eugen Neufeld
34: */
35: public final class Activator extends Plugin {
36:         /**
37:          * The constant holding the id of this plugin.
38:          */
39:         public static final String PLUGIN_ID = "org.eclipse.emf.ecp.core"; //$NON-NLS-1$
40:
41:         private static Activator instance;
42:
43:         private static ServiceObjectTracker<ECPRepositoryManager> repositorManagerTracker;
44:         private static ServiceObjectTracker<ECPProjectManager> projectManagerTracker;
45:         private static ServiceObjectTracker<ECPProviderRegistry> providerRegistryTracker;
46:         private static ServiceObjectTracker<ECPObserverBus> observerBusTracker;
47:
48:         /**
49:          * Default constructor.
50:          */
51:         public Activator() {
52:         }
53:
54:         // BEGIN SUPRESS CATCH EXCEPTION
55:         @Override
56:         public void start(BundleContext bundleContext) throws Exception {
57:                 instance = this;
58:                 super.start(bundleContext);
59:         }
60:
61:         @Override
62:         public void stop(BundleContext bundleContext) throws Exception {
63:•                if (repositorManagerTracker != null) {
64:                         repositorManagerTracker.dispose();
65:                 }
66:•                if (projectManagerTracker != null) {
67:                         projectManagerTracker.dispose();
68:                 }
69:•                if (providerRegistryTracker != null) {
70:                         providerRegistryTracker.dispose();
71:                 }
72:•                if (observerBusTracker != null) {
73:                         observerBusTracker.dispose();
74:                 }
75:                 super.stop(bundleContext);
76:         }
77:
78:         // END SUPRESS CATCH EXCEPTION
79:         /**
80:          * Returns the instance of this Activator.
81:          *
82:          * @return the saved instance
83:          */
84:         public static Activator getInstance() {
85:                 return instance;
86:         }
87:
88:         /**
89:          * Logs and Info message.
90:          *
91:          * @param message the message to log
92:          */
93:         public static void log(String message) {
94:                 instance.getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message));
95:         }
96:
97:         /**
98:          * Logs a message with a specific status.
99:          *
100:          * @param status the {@link IStatus} value
101:          * @param message the message to log
102:          */
103:         public static void log(int status, String message) {
104:                 instance.getLog().log(new Status(status, PLUGIN_ID, message));
105:         }
106:
107:         private static void log(IStatus status) {
108:                 instance.getLog().log(status);
109:         }
110:
111:         /**
112:          * Logs a {@link Throwable}.
113:          *
114:          * @param t the {@link Throwable} to log
115:          * @return the message of the {@link Throwable}
116:          */
117:         public static String log(Throwable t) {
118:                 final IStatus status = getStatus(t);
119:                 log(status);
120:                 return status.getMessage();
121:         }
122:
123:         private static IStatus getStatus(Throwable t) {
124:•                if (t instanceof CoreException) {
125:                         final CoreException coreException = (CoreException) t;
126:                         return coreException.getStatus();
127:                 }
128:
129:                 String msg = t.getLocalizedMessage();
130:•                if (msg == null || msg.length() == 0) {
131:                         msg = t.getClass().getName();
132:                 }
133:
134:                 return new Status(IStatus.ERROR, PLUGIN_ID, msg, t);
135:         }
136:
137:         /**
138:          * Helper method to get the {@link ECPProjectManager}.
139:          *
140:          * @return the {@link ECPProjectManager}
141:          */
142:         public static synchronized ECPProjectManager getECPProjectManager() {
143:•                if (projectManagerTracker == null) {
144:                         final BundleContext bundleContext = instance.getBundle().getBundleContext();
145:                         projectManagerTracker = new ServiceObjectTracker<ECPProjectManager>(bundleContext, ECPProjectManager.class);
146:                 }
147:                 return projectManagerTracker.getService();
148:         }
149:
150:         /**
151:          * Helper method to get the {@link ECPRepositoryManager}.
152:          *
153:          * @return the {@link ECPRepositoryManager}
154:          */
155:         public static synchronized ECPRepositoryManager getECPRepositoryManager() {
156:•                if (repositorManagerTracker == null) {
157:                         final BundleContext bundleContext = instance.getBundle().getBundleContext();
158:                         repositorManagerTracker = new ServiceObjectTracker<ECPRepositoryManager>(bundleContext,
159:                                 ECPRepositoryManager.class);
160:                 }
161:                 return repositorManagerTracker.getService();
162:         }
163:
164:         /**
165:          * Helper method to get the {@link ECPProviderRegistry}.
166:          *
167:          * @return the {@link ECPProviderRegistry}
168:          */
169:         public static synchronized ECPProviderRegistry getECPProviderRegistry() {
170:•                if (providerRegistryTracker == null) {
171:                         final BundleContext bundleContext = instance.getBundle().getBundleContext();
172:                         providerRegistryTracker = new ServiceObjectTracker<ECPProviderRegistry>(bundleContext,
173:                                 ECPProviderRegistry.class);
174:                 }
175:                 return providerRegistryTracker.getService();
176:         }
177:
178:         /**
179:          * Helper method to get the {@link ECPObserverBus}.
180:          *
181:          * @return the {@link ECPObserverBus}
182:          */
183:         public static synchronized ECPObserverBus getECPObserverBus() {
184:•                if (observerBusTracker == null) {
185:                         final BundleContext bundleContext = instance.getBundle().getBundleContext();
186:                         observerBusTracker = new ServiceObjectTracker<ECPObserverBus>(bundleContext, ECPObserverBus.class);
187:                 }
188:                 return observerBusTracker.getService();
189:         }
190: }