Skip to content

Package: RuntimeModeUtil

RuntimeModeUtil

nameinstructionbranchcomplexitylinemethod
isSegmentMode()
M: 6 C: 17
74%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 5
83%
M: 0 C: 1
100%
lambda$1(String)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
report(AbstractReport)
M: 21 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2019 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: * Lucas Koehler - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.spi.core.services.segments;
15:
16: import java.util.Arrays;
17:
18: import org.eclipse.core.runtime.IStatus;
19: import org.eclipse.core.runtime.Platform;
20: import org.eclipse.emfforms.spi.common.report.AbstractReport;
21: import org.eclipse.emfforms.spi.common.report.ReportService;
22: import org.osgi.framework.BundleContext;
23: import org.osgi.framework.FrameworkUtil;
24: import org.osgi.framework.ServiceReference;
25:
26: /**
27: * Allows to query whether runtime generation of segments is enabled for legacy domain model references.
28: *
29: * @author Lucas Koehler
30: *
31: */
32: public final class RuntimeModeUtil {
33:         /**
34:          * This flag enables the automatic generation of segments from existing DMRs.
35:          */
36:         public static final String SEGMENT_GENERATION = "-enableSegmentGeneration"; //$NON-NLS-1$
37:
38:         private static boolean segmentMode;
39:
40:         private RuntimeModeUtil() {
41:                 // Utility class should not be instantiated.
42:         }
43:
44:         /**
45:          * Returns whether runtime segment generation for legacy domain model references is enabled.
46:          *
47:          * @return <code>true</code> if segments should be generated and <code>false</code> otherwise
48:          */
49:         public static boolean isSegmentMode() {
50:                 final String[] applicationArgs = Platform.getApplicationArgs();
51:                 Arrays.stream(applicationArgs).filter(SEGMENT_GENERATION::equals).findFirst()
52:                         .ifPresent(s -> segmentMode = true);
53:•                if (segmentMode) {
54:                         report(new AbstractReport("Segment Generation for legacy DMRs is enabled.", IStatus.INFO)); //$NON-NLS-1$
55:                 }
56:                 return segmentMode;
57:         }
58:
59:         private static void report(AbstractReport report) {
60:                 final BundleContext bundleContext = FrameworkUtil.getBundle(RuntimeModeUtil.class).getBundleContext();
61:                 final ServiceReference<ReportService> serviceReference = bundleContext
62:                         .getServiceReference(ReportService.class);
63:                 final ReportService reportService = bundleContext.getService(serviceReference);
64:                 reportService.report(report);
65:                 bundleContext.ungetService(serviceReference);
66:         }
67: }