Skip to content

Package: Activator$CDOServerBrowserImpl

Activator$CDOServerBrowserImpl

nameinstructionbranchcomplexitylinemethod
Activator.CDOServerBrowserImpl(Activator, Map)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getRepository(String)
M: 40 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
getRepositoryNames()
M: 42 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011 Eike Stepper (Berlin, Germany) 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: *******************************************************************************/
14: package org.eclipse.emf.ecp.cdo.internal.core;
15:
16: import java.util.HashSet;
17: import java.util.Map;
18: import java.util.Set;
19:
20: import org.eclipse.core.runtime.CoreException;
21: import org.eclipse.core.runtime.IStatus;
22: import org.eclipse.core.runtime.Plugin;
23: import org.eclipse.core.runtime.Status;
24: import org.eclipse.emf.cdo.server.CDOServerBrowser;
25: import org.eclipse.emf.cdo.spi.server.InternalRepository;
26: import org.eclipse.emf.cdo.spi.workspace.InternalCDOWorkspace;
27: import org.eclipse.emf.ecp.core.ECPProject;
28: import org.eclipse.emf.ecp.core.util.ECPUtil;
29: import org.eclipse.emf.ecp.spi.core.InternalProject;
30: import org.osgi.framework.BundleContext;
31:
32: /**
33: * The activator class controls the plug-in life cycle.
34: *
35: * @author Eike Stepper
36: */
37: public class Activator extends Plugin {
38:         /**
39:          * @author Jonas
40:          *
41:          */
42:         private final class CDOServerBrowserImpl extends CDOServerBrowser {
43:                 /**
44:                  * @param repositories
45:                  */
46:                 private CDOServerBrowserImpl(Map<String, InternalRepository> repositories) {
47:                         super(repositories);
48:                 }
49:
50:                 @Override
51:                 protected Set<String> getRepositoryNames() {
52:                         final Set<String> names = new HashSet<String>();
53:•                        for (final ECPProject project : ECPUtil.getECPProjectManager().getProjects()) {
54:•                                if (project.getProvider().getName().equals(CDOProvider.NAME)) {
55:                                         final CDOProjectData projectData = CDOProvider.getProjectData((InternalProject) project);
56:                                         final InternalCDOWorkspace workspace = (InternalCDOWorkspace) projectData.getWorkspace();
57:•                                        if (workspace != null) {
58:                                                 final InternalRepository localRepository = workspace.getLocalRepository();
59:                                                 names.add(localRepository.getName());
60:                                         }
61:                                 }
62:                         }
63:
64:                         return names;
65:                 }
66:
67:                 @Override
68:                 protected InternalRepository getRepository(String name) {
69:•                        for (final ECPProject project : ECPUtil.getECPProjectManager().getProjects()) {
70:•                                if (project.getProvider().getName().equals(CDOProvider.NAME)) {
71:                                         final CDOProjectData projectData = CDOProvider.getProjectData((InternalProject) project);
72:                                         final InternalCDOWorkspace workspace = (InternalCDOWorkspace) projectData.getWorkspace();
73:•                                        if (workspace != null) {
74:                                                 final InternalRepository localRepository = workspace.getLocalRepository();
75:•                                                if (localRepository.getName().equals(name)) {
76:                                                         return localRepository;
77:                                                 }
78:                                         }
79:                                 }
80:                         }
81:
82:                         return null;
83:                 }
84:         }
85:
86:         /**
87:          * The PlugIn ID.
88:          */
89:         public static final String PLUGIN_ID = "org.eclipse.emf.ecp.cdo.core"; //$NON-NLS-1$
90:
91:         private static Activator instance;
92:
93:         private CDOServerBrowser serverBrowser;
94:
95:         // BEGIN SUPRESS CATCH EXCEPTION
96:         @Override
97:         public void start(BundleContext bundleContext) throws Exception {
98:                 super.start(bundleContext);
99:                 instance = this;
100:
101:                 serverBrowser = new CDOServerBrowserImpl(null);
102:                 // TODO: Please check this. Added. because EMFCP fails on start up if this port is in use
103:                 try {
104:                         serverBrowser.setPort(7778);
105:                         serverBrowser.activate();
106:                 } catch (final Exception e) {
107:                         log(e.getMessage());
108:                         // TODO: Please check this. Added. because EMFCP fails on start up if this port is in use
109:                 }
110:         }
111:
112:         @Override
113:         public void stop(BundleContext bundleContext) throws Exception {
114:                 serverBrowser.deactivate();
115:                 serverBrowser = null;
116:
117:                 if (CDOProvider.getInstance() != null) {
118:                         CDOProvider.getInstance().dispose();
119:                 }
120:
121:                 instance = null;
122:                 super.stop(bundleContext);
123:         }
124:
125:         // END SUPRESS CATCH EXCEPTION
126:         /**
127:          * Returns the shared instance.
128:          *
129:          * @return the shared instance
130:          */
131:         public static Activator getInstance() {
132:                 return instance;
133:         }
134:
135:         /**
136:          * Logs messages.
137:          *
138:          * @param message the message
139:          */
140:         public static void log(String message) {
141:                 instance.getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message));
142:         }
143:
144:         /**
145:          * Logs {@link IStatus}.
146:          *
147:          * @param status the {@link IStatus}
148:          */
149:         public static void log(IStatus status) {
150:                 instance.getLog().log(status);
151:         }
152:
153:         /**
154:          * Logs {@link Throwable}.
155:          *
156:          * @param t the {@link Throwable}
157:          * @return the message of the created status
158:          */
159:         public static String log(Throwable t) {
160:                 final IStatus status = getStatus(t);
161:                 log(status);
162:                 return status.getMessage();
163:         }
164:
165:         /**
166:          * Gets a {@link IStatus} for a throwable.
167:          *
168:          * @param t the {@link Throwable}
169:          * @return the created {@link IStatus}
170:          */
171:         public static IStatus getStatus(Throwable t) {
172:                 if (t instanceof CoreException) {
173:                         final CoreException coreException = (CoreException) t;
174:                         return coreException.getStatus();
175:                 }
176:
177:                 String msg = t.getLocalizedMessage();
178:                 if (msg == null || msg.length() == 0) {
179:                         msg = t.getClass().getName();
180:                 }
181:
182:                 return new Status(IStatus.ERROR, PLUGIN_ID, msg, t);
183:         }
184: }