Skip to content

Commit 4643833

Browse files
Update to PlanPro-Model 1.10.0.3 (#1812)
* Update planpro version * Update Unitest * update targer platform * Update PlanProschema directory * Update Visitation support Version * remove byte-buddy dependencies * fix bytebuddy depdency issues * adjust validation information reference --------- Co-authored-by: Marius Heine <[email protected]>
1 parent 9b3166b commit 4643833

File tree

19 files changed

+506
-125
lines changed

19 files changed

+506
-125
lines changed

java/bundles/org.eclipse.set.basis/src/org/eclipse/set/basis/PlanProSchemaDir.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@ private static class LSInputImpl implements LSInput {
4242
private final String baseURI;
4343
private final String publicId;
4444
private final String systemId;
45+
private final String version;
4546
private final Bundle bundle = FrameworkUtil
4647
.getBundle(PlanPro_Schnittstelle.class);
4748

4849
LSInputImpl(final String publicId, final String systemId,
49-
final String baseURI) {
50+
final String baseURI, final String version) {
5051
this.publicId = publicId;
5152
this.systemId = systemId;
5253
this.baseURI = baseURI;
54+
this.version = version;
5355
}
5456

5557
@Override
@@ -133,8 +135,12 @@ public void setSystemId(final String systemId) {
133135
throw new UnsupportedOperationException();
134136
}
135137

138+
private String getSchemaDir() {
139+
return String.format("%s/%s", SCHEMA_DIR, version); //$NON-NLS-1$
140+
}
141+
136142
private String getSchemaPath() {
137-
final Enumeration<URL> entries = bundle.findEntries(SCHEMA_DIR,
143+
final Enumeration<URL> entries = bundle.findEntries(getSchemaDir(),
138144
getSystemId(), true);
139145
final URL element = entries.nextElement();
140146
Assert.isTrue(!entries.hasMoreElements());
@@ -153,7 +159,14 @@ public ResourceResolver() {
153159
public LSInput resolveResource(final String type,
154160
final String namespaceURI, final String publicId,
155161
final String systemId, final String baseURI) {
156-
return new LSInputImpl(publicId, systemId, baseURI);
162+
final String version = namespaceURI
163+
.substring(namespaceURI.lastIndexOf("/") + 1); //$NON-NLS-1$
164+
String schemaId = systemId;
165+
// Take only schema name, fall the schema not in same directory
166+
if (schemaId.contains("/")) { //$NON-NLS-1$
167+
schemaId = systemId.substring(systemId.lastIndexOf("/") + 1); //$NON-NLS-1$
168+
}
169+
return new LSInputImpl(publicId, schemaId, baseURI, version);
157170
}
158171
}
159172

java/bundles/org.eclipse.set.basis/src/org/eclipse/set/basis/files/PlanProFileResource.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.util.Map;
1414

1515
import org.eclipse.emf.common.util.URI;
16+
import org.eclipse.emf.ecore.xmi.XMLHelper;
1617
import org.eclipse.emf.ecore.xmi.XMLResource;
1718
import org.eclipse.emf.ecore.xmi.XMLSave;
1819
import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl;
@@ -21,7 +22,24 @@
2122
* Adapted resource implementation for the EMF-XML Resources
2223
*/
2324
public class PlanProFileResource extends XMLResourceImpl {
25+
2426
private String standalone;
27+
private XMLHelper xmlHelper;
28+
29+
/**
30+
* Creates an instance of the resource. <!-- begin-user-doc --> <!--
31+
* end-user-doc -->
32+
*
33+
* @param uri
34+
* the URI of the new resource.
35+
* @param xmlHelper
36+
* the {@link XMLHelper}
37+
* @generated
38+
*/
39+
public PlanProFileResource(final URI uri, final XMLHelper xmlHelper) {
40+
this(uri);
41+
this.xmlHelper = xmlHelper;
42+
}
2543

2644
/**
2745
* Creates an instance of the resource. <!-- begin-user-doc --> <!--
@@ -33,7 +51,7 @@ public class PlanProFileResource extends XMLResourceImpl {
3351
*/
3452
public PlanProFileResource(final URI uri) {
3553
super(uri);
36-
54+
this.xmlHelper = null;
3755
getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA,
3856
Boolean.TRUE);
3957
getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA,
@@ -49,6 +67,9 @@ public PlanProFileResource(final URI uri) {
4967
XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
5068
getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER,
5169
Boolean.TRUE);
70+
getDefaultLoadOptions().put(
71+
XMLResource.OPTION_USE_PACKAGE_NS_URI_AS_LOCATION,
72+
Boolean.FALSE);
5273
}
5374

5475
static final String STANDALONE = "standalone"; //$NON-NLS-1$
@@ -70,4 +91,12 @@ protected XMLSave createXMLSave() {
7091
public void setStandalone(final String value) {
7192
standalone = value;
7293
}
94+
95+
@Override
96+
protected XMLHelper createXMLHelper() {
97+
if (xmlHelper != null) {
98+
return xmlHelper;
99+
}
100+
return super.createXMLHelper();
101+
}
73102
}

java/bundles/org.eclipse.set.core.services/src/org/eclipse/set/core/services/Services.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.eclipse.set.core.services.graph.TopologicalGraphService;
1717
import org.eclipse.set.core.services.planningaccess.PlanningAccessService;
1818
import org.eclipse.set.core.services.siteplan.SiteplanService;
19+
import org.eclipse.set.core.services.version.PlanProVersionService;
1920
import org.eclipse.set.core.services.viewmodel.ToolboxViewModelService;
2021

2122
/**
@@ -33,6 +34,7 @@ public class Services {
3334
private static UserConfigurationService userConfigurationService;
3435
private static TopologicalGraphService topGraphService;
3536
private static PointObjectPositionService pointObjectPositionService;
37+
private static PlanProVersionService planProVersionService;
3638

3739
/**
3840
* @return the siteplan service
@@ -183,4 +185,20 @@ public static void setPointObjectPositionService(
183185
final PointObjectPositionService pointObjectPositionService) {
184186
Services.pointObjectPositionService = pointObjectPositionService;
185187
}
188+
189+
/**
190+
* @param planProVersionService
191+
* the {@link PlanProVersionService}
192+
*/
193+
public static void setPlanProVersionService(
194+
final PlanProVersionService planProVersionService) {
195+
Services.planProVersionService = planProVersionService;
196+
}
197+
198+
/**
199+
* @return the {@link PlanProVersionService}
200+
*/
201+
public static PlanProVersionService getPlanProVersionService() {
202+
return planProVersionService;
203+
}
186204
}

java/bundles/org.eclipse.set.core.services/src/org/eclipse/set/core/services/version/PlanProVersionService.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,69 @@
1919
*/
2020
public interface PlanProVersionService {
2121

22+
/**
23+
* The PlanPro Version format <major>.<patch>.<minor>
24+
*
25+
* @param major
26+
* the major version
27+
* @param patch
28+
* the patch version
29+
* @param minor
30+
* the minor version
31+
*/
32+
public record PlanProVersionFormat(String major, String patch,
33+
String minor) {
34+
/**
35+
* @return <major>.<patch>
36+
*/
37+
public String getMajorPatchVersion() {
38+
return major + "." + patch; //$NON-NLS-1$
39+
}
40+
41+
/**
42+
* @return <major>.<patch>.<version>
43+
*/
44+
public String getFullVersion() {
45+
return String.format("%s.%s.%s", major, patch, minor); //$NON-NLS-1$
46+
}
47+
48+
public int compare(final PlanProVersionFormat another) {
49+
if (!major.equals(another.major)) {
50+
return major.compareToIgnoreCase(another.major);
51+
}
52+
53+
if (!patch.equals(another.patch)) {
54+
return patch.compareToIgnoreCase(another.patch);
55+
}
56+
57+
if (!minor.equals(another.minor)) {
58+
return minor.compareToIgnoreCase(another.minor);
59+
}
60+
return 0;
61+
62+
}
63+
}
64+
2265
/**
2366
* @return the supported PlanPro version
2467
*/
2568
public VersionInfo createSupportedVersion();
2669

70+
/**
71+
* @return the supported PlanPro version format
72+
*/
73+
public PlanProVersionFormat getSupportedVersionFormat();
74+
2775
/**
2876
* @param location
2977
* location to the PlanPro model
3078
*
3179
* @return the used version
3280
*/
3381
public VersionInfo createUsedVersion(Path location);
82+
83+
/**
84+
* @return the current PlanPro version
85+
*/
86+
public String getCurrentVersion();
3487
}

java/bundles/org.eclipse.set.core.test/META-INF/MANIFEST.MF

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@ Fragment-Host: org.eclipse.set.core;bundle-version="0.1.0"
77
Automatic-Module-Name: org.eclipse.set.core.test
88
Bundle-RequiredExecutionEnvironment: JavaSE-21
99
Bundle-Vendor: Eclipse Signalling Engineering Toolbox
10-
Import-Package: org.eclipse.set.feature.validation.session,
10+
Import-Package: org.eclipse.set.core.services.version,
11+
org.eclipse.set.feature.validation.session,
1112
org.eclipse.set.model.planpro.PlanPro,
1213
org.eclipse.set.model.planpro.Signalbegriffe_Ril_301,
1314
org.eclipse.set.sessionservice,
1415
org.eclipse.set.unittest.utils,
1516
org.eclipse.set.unittest.utils.session,
1617
org.eclipse.set.unittest.utils.toolboxfile,
1718
org.junit,
19+
org.junit.function,
1820
org.junit.jupiter.api
19-
Require-Bundle: org.hamcrest.core
21+
Require-Bundle: org.hamcrest.core,
22+
org.mockito.mockito-core,
23+
net.bytebuddy.byte-buddy,
24+
net.bytebuddy.byte-buddy-agent
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Copyright (c) 2025 DB InfraGO AG and others
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v2.0 which is available at
6+
* https://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
*/
11+
package org.eclipse.set.core.fileservice;
12+
13+
import org.eclipse.set.core.services.Services;
14+
import org.eclipse.set.core.services.version.PlanProVersionService;
15+
import org.eclipse.set.core.services.version.PlanProVersionService.PlanProVersionFormat;
16+
import org.junit.function.ThrowingRunnable;
17+
import org.mockito.MockedStatic;
18+
import org.mockito.Mockito;
19+
20+
/**
21+
* The {@link PlanProVersionService} is needed for open planpro file
22+
*/
23+
public class MockPlanProVersionService {
24+
private static final PlanProVersionFormat currentVersion = new PlanProVersionFormat(
25+
"1.10", "0", "3"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
26+
27+
/**
28+
* Mock {@link PlanProVersionService}
29+
*
30+
* @param doTest
31+
* the test code
32+
* @throws Throwable
33+
* the exception
34+
*/
35+
public static void mockPlanProVersionService(final ThrowingRunnable doTest)
36+
throws Throwable {
37+
final PlanProVersionService mockVersionService = Mockito
38+
.mock(PlanProVersionService.class);
39+
Mockito.when(mockVersionService.getCurrentVersion())
40+
.thenReturn(currentVersion.getFullVersion());
41+
Mockito.when(mockVersionService.getSupportedVersionFormat())
42+
.thenReturn(currentVersion);
43+
try (MockedStatic<Services> mockStatic = Mockito
44+
.mockStatic(Services.class)) {
45+
mockStatic.when(Services::getPlanProVersionService)
46+
.thenReturn(mockVersionService);
47+
doTest.run();
48+
}
49+
}
50+
}

java/bundles/org.eclipse.set.core.test/src/org/eclipse/set/core/fileservice/PlainToolboxFileTest.xtend

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
*/
99
package org.eclipse.set.core.fileservice
1010

11-
import java.io.IOException
1211
import java.nio.file.Paths
1312
import org.eclipse.set.basis.files.ToolboxFile
1413
import org.eclipse.set.basis.files.ToolboxFileRole
15-
import org.eclipse.set.core.services.files.ToolboxFileFormatService
14+
import org.eclipse.set.feature.validation.session.SetSessionService
1615
import org.eclipse.set.unittest.utils.toolboxfile.AbstractToolboxFileTest
1716
import org.junit.jupiter.api.Test
18-
import org.eclipse.set.feature.validation.session.SetSessionService
1917

2018
/**
2119
* Test for {@link PlainToolboxFile}
@@ -28,30 +26,37 @@ class PlainToolboxFileTest extends AbstractToolboxFileTest {
2826
* Test method for {@link PlainToolboxFile#open()}
2927
*/
3028
@Test
31-
def void testOpen() throws IOException{
32-
whenOpen
33-
thenExpectContentsExists(true)
29+
def void testOpen() throws Throwable{
30+
MockPlanProVersionService.mockPlanProVersionService([
31+
whenOpen
32+
thenExpectContentsExists(true)
33+
])
3434
}
3535

3636
/**
3737
* Test method for {@link PlainToolboxFile#close()}
3838
*/
3939
@Test
40-
def void testClose() throws IOException{
41-
whenOpen
42-
whenClose
43-
thenExpectContentsExists(false)
40+
def void testClose() throws Throwable{
41+
MockPlanProVersionService.mockPlanProVersionService([
42+
whenOpen
43+
whenClose
44+
thenExpectContentsExists(false)
45+
])
46+
4447
}
4548

4649
/**
4750
* Test method for multiple {@link PlainToolboxFile#close()}
4851
*/
4952
@Test
50-
def void testMultipleClose() throws IOException{
51-
whenOpen
52-
whenClose
53-
whenClose
54-
thenExpectContentsExists(false)
53+
def void testMultipleClose() throws Throwable{
54+
MockPlanProVersionService.mockPlanProVersionService([
55+
whenOpen
56+
whenClose
57+
whenClose
58+
thenExpectContentsExists(false)
59+
])
5560
}
5661

5762
/**
@@ -60,19 +65,15 @@ class PlainToolboxFileTest extends AbstractToolboxFileTest {
6065
*
6166
*/
6267
@Test
63-
def void testCloseThenOpen() throws IOException{
64-
whenOpen
65-
thenExpectContentsExists(true)
66-
whenClose
67-
thenExpectContentsExists(false)
68-
whenOpen
69-
thenExpectContentsExists(true)
70-
}
71-
72-
def ToolboxFileFormatService setUpFormatService() {
73-
val formatService = new PlainFileFormatService
74-
formatService.sessionService = new SetSessionService
75-
return formatService
68+
def void testCloseThenOpen() throws Throwable {
69+
MockPlanProVersionService.mockPlanProVersionService([
70+
whenOpen
71+
thenExpectContentsExists(true)
72+
whenClose
73+
thenExpectContentsExists(false)
74+
whenOpen
75+
thenExpectContentsExists(true)
76+
])
7677
}
7778

7879
override protected ToolboxFile createToolboxFile(ToolboxFileRole role) {

0 commit comments

Comments
 (0)