Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Bundle-Version: 2.6.0.qualifier
Fragment-Host: org.eclipse.set.application
Bundle-RequiredExecutionEnvironment: JavaSE-21
Bundle-Vendor: Eclipse Signalling Engineering Toolbox
Import-Package: net.bytebuddy;version="[1.17.0,2.0.0)",
Import-Package: com.google.common.util.concurrent.internal,
net.bytebuddy;version="[1.17.0,2.0.0)",
net.bytebuddy.agent;version="[1.17.0,2.0.0)",
org.apache.commons.lang3.reflect;version="[3.17.0,4.0.0)",
org.eclipse.set.unittest.utils,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
*/
package org.eclipse.set.application.defaultvalue

import org.eclipse.set.model.planpro.PlanPro.ENUMUntergewerkArt
import org.eclipse.set.model.planpro.PlanPro.PlanProFactory
import org.eclipse.set.model.planpro.PlanPro.PlanPro_Schnittstelle
import jakarta.inject.Inject
import org.eclipse.core.runtime.Assert
import org.eclipse.set.core.services.defaultvalue.DefaultValueService
import org.eclipse.set.core.services.version.PlanProVersionService
import org.eclipse.set.model.planpro.PlanPro.ENUMUntergewerkArt
import org.eclipse.set.model.planpro.PlanPro.PlanProFactory
import org.eclipse.set.model.planpro.PlanPro.PlanPro_Schnittstelle

import static extension org.eclipse.set.ppmodel.extensions.PlanProSchnittstelleExtensions.*
import static extension org.eclipse.set.ppmodel.extensions.PlanungProjektExtensions.*
import static extension org.eclipse.set.ppmodel.extensions.PlanungEinzelExtensions.*
import static extension org.eclipse.set.ppmodel.extensions.PlanungProjektExtensions.*

/**
* Implementation of {@link DefaultValueService}.
Expand Down Expand Up @@ -94,8 +94,8 @@ class DefaultValueServiceImpl implements DefaultValueService {
}

if (planungGAllg.planProXSDVersion.wert === null) {
val versionInfo = versionService.createSupportedVersion()
planungGAllg.planProXSDVersion.wert = versionInfo.planPro
val versionInfo = versionService.getCurrentVersion()
planungGAllg.planProXSDVersion.wert = versionInfo.planProVersions.head
}

if (planungGAllg.untergewerkArt === null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@ public interface CacheId {
*/
public static final double TOP_GEO_LENGTH_TOLERANCE = 0.01;

/**
* The separator for supported PlanPro, Signalbegriffe_Ril301 versions
*/
public static final String VERSION_SEPARATOR = ", ";

/**
* The tolerance value between the Begrenzungen of a Teilbereich and its
* associated TOP_KANTE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
package org.eclipse.set.core.services.version;

import java.nio.file.Path;
import java.util.Comparator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.set.model.validationreport.VersionInfo;

Expand All @@ -31,6 +34,9 @@ public interface PlanProVersionService {
*/
public record PlanProVersionFormat(String major, String patch,
String minor) {

private static final String VERSION_FORMAT = "(?<major>[1-9]+\\.\\d+)\\.(?<patch>\\d+)(\\.(?<minor>\\d))*"; //$NON-NLS-1$

/**
* @return <major>.<patch>
*/
Expand All @@ -45,6 +51,11 @@ public String getFullVersion() {
return String.format("%s.%s.%s", major, patch, minor); //$NON-NLS-1$
}

/**
* @param another
* the another version format
* @return true, if same
*/
public int compare(final PlanProVersionFormat another) {
if (!major.equals(another.major)) {
return major.compareToIgnoreCase(another.major);
Expand All @@ -58,14 +69,46 @@ public int compare(final PlanProVersionFormat another) {
return minor.compareToIgnoreCase(another.minor);
}
return 0;
}

/**
* @return the planpro version comparator
*/
public static Comparator<String> compareVersion() {
return (first, second) -> {
final PlanProVersionFormat firstVersion = parseVersionFormat(
first);
final PlanProVersionFormat secondVersion = parseVersionFormat(
second);
return firstVersion.compare(secondVersion);
};
}

/**
* Parse planpro version from string
*
* @param version
* the version
* @return the {@link PlanProVersionFormat}
*/
public static PlanProVersionFormat parseVersionFormat(
final String version) {
final Pattern compile = Pattern.compile(VERSION_FORMAT);
final Matcher matcher = compile.matcher(version);
if (!matcher.matches()) {
throw new IllegalArgumentException("Illegal Version Foramt"); //$NON-NLS-1$
}

return new PlanProVersionFormat(matcher.group("major"), //$NON-NLS-1$
matcher.group("patch"), matcher.group("minor")); //$NON-NLS-1$ //$NON-NLS-2$

}
}

/**
* @return the supported PlanPro version
*/
public VersionInfo createSupportedVersion();
public VersionInfo getSupportedVersions();

/**
* @return the supported PlanPro version format
Expand All @@ -81,7 +124,15 @@ public int compare(final PlanProVersionFormat another) {
public VersionInfo createUsedVersion(Path location);

/**
* @return the current PlanPro version
* @return the version info with actual PlanPro and Signalbegriff_Ril301
* version
*/
public VersionInfo getCurrentVersion();

/**
* @param uri
* the used version in loaded file
* @return true, if this version was supported
*/
public String getCurrentVersion();
public boolean isSupportedVersion(String uri);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
import org.eclipse.set.core.services.Services;
import org.eclipse.set.core.services.version.PlanProVersionService;
import org.eclipse.set.core.services.version.PlanProVersionService.PlanProVersionFormat;
import org.eclipse.set.model.validationreport.ValidationreportFactory;
import org.eclipse.set.model.validationreport.VersionInfo;
import org.junit.function.ThrowingRunnable;
import org.mockito.ArgumentMatchers;
import org.mockito.MockedStatic;
import org.mockito.Mockito;

Expand All @@ -24,6 +27,14 @@ public class MockPlanProVersionService {
private static final PlanProVersionFormat currentVersion = new PlanProVersionFormat(
"1.10", "0", "3"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

private static VersionInfo givenCurrentVersionInfo() {
final VersionInfo currentVersionInfo = ValidationreportFactory.eINSTANCE
.createVersionInfo();
currentVersionInfo.getPlanProVersions().add("1.10.0.3"); //$NON-NLS-1$
currentVersionInfo.getSignalbegriffeVersions().add("1.10.0.4"); //$NON-NLS-1$
return currentVersionInfo;
}

/**
* Mock {@link PlanProVersionService}
*
Expand All @@ -32,12 +43,17 @@ public class MockPlanProVersionService {
* @throws Throwable
* the exception
*/
@SuppressWarnings("boxing")
public static void mockPlanProVersionService(final ThrowingRunnable doTest)
throws Throwable {
final PlanProVersionService mockVersionService = Mockito
.mock(PlanProVersionService.class);

Mockito.when(mockVersionService.getCurrentVersion())
.thenReturn(currentVersion.getFullVersion());
.thenReturn(givenCurrentVersionInfo());
Mockito.when(mockVersionService
.isSupportedVersion(ArgumentMatchers.anyString()))
.thenReturn(Boolean.TRUE);
Mockito.when(mockVersionService.getSupportedVersionFormat())
.thenReturn(currentVersion);
try (MockedStatic<Services> mockStatic = Mockito
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.eclipse.emf.ecore.xmi.XMLResource;
import org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl;
import org.eclipse.set.core.services.version.PlanProVersionService;
import org.eclipse.set.model.validationreport.VersionInfo;

/**
* Make the old minor version compatible
Expand All @@ -21,7 +22,8 @@
*/
public class PlanProXMLHelper extends XMLHelperImpl {

private static final String PLANPRO_URI_PREFIX = "http://www.plan-pro.org/modell/"; //$NON-NLS-1$
private static final String PLANPRO_URI_PREFIX = "http://www.plan-pro.org/modell/PlanPro"; //$NON-NLS-1$
private static final String SIGNALBEGRIFF_RIL_URI_PREFIX = "http://www.plan-pro.org/modell/Signalbegriffe_Ril_301"; //$NON-NLS-1$
private final PlanProVersionService versionService;

private static String parseVersion(final String uri) {
Expand All @@ -42,21 +44,23 @@ public PlanProXMLHelper(final XMLResource resource,

@Override
public void addPrefix(final String prefix, final String uri) {
if (!uri.startsWith(PLANPRO_URI_PREFIX)
|| parseVersion(uri).equals(versionService.getCurrentVersion())
|| !parseVersion(uri)
.startsWith(versionService.getSupportedVersionFormat()
.getMajorPatchVersion())) {
if (!versionService.isSupportedVersion(uri)) {
super.addPrefix(prefix, uri);
return;
}

// When the version isn't equal current version, but this version is
// supported then replace the version part in uri to current version
final String version = parseVersion(uri);
final String newUri = uri.replace(version,
versionService.getCurrentVersion());
final VersionInfo currentVersion = versionService.getCurrentVersion();
String newUri = uri;
final String loadedVersion = parseVersion(uri);
if (uri.startsWith(PLANPRO_URI_PREFIX)) {
newUri = uri.replace(loadedVersion,
currentVersion.getPlanProVersions().getFirst());
} else if (uri.startsWith(SIGNALBEGRIFF_RIL_URI_PREFIX)) {
newUri = uri.replace(loadedVersion,
currentVersion.getSignalbegriffeVersions().getFirst());
}
super.addPrefix(prefix, newUri);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
package org.eclipse.set.core.version;

import static org.eclipse.set.core.services.version.PlanProVersionService.PlanProVersionFormat.parseVersionFormat;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -24,6 +26,7 @@
import org.eclipse.set.model.validationreport.ValidationreportFactory;
import org.eclipse.set.model.validationreport.VersionInfo;
import org.eclipse.set.ppmodel.extensions.PlanProPackageExtensions;
import org.eclipse.set.ppmodel.extensions.SignalbegriffeRil301PackageExtensions;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;

Expand All @@ -41,10 +44,6 @@ public class PlanProVersionServiceImpl implements PlanProVersionService {
private static final String SIGNALS_KEY = "http://www.plan-pro.org/modell/Signalbegriffe_Ril_301/"; //$NON-NLS-1$
private static final int VALUE_GROUP = 1;

private static final String VERSION_FORMAT = "(?<major>[1-9]+\\.[0-9]+)\\.(?<patch>[0-9]+)(\\.(?<minor>[0-9]))*"; //$NON-NLS-1$

private static final String VERSION_SEPARATOR = ", "; //$NON-NLS-1$

@Activate
private void active() {
Services.setPlanProVersionService(this);
Expand Down Expand Up @@ -77,34 +76,22 @@ private static String parseVersion(final String text, final String key) {
return null;
}

private static PlanProVersionFormat parseVersionFormat(
final String version) {
final Pattern compile = Pattern.compile(VERSION_FORMAT);
final Matcher matcher = compile.matcher(version);
if (!matcher.matches()) {
throw new IllegalArgumentException("Illegal Version Foramt"); //$NON-NLS-1$
}

return new PlanProVersionFormat(matcher.group("major"), //$NON-NLS-1$
matcher.group("patch"), matcher.group("minor")); //$NON-NLS-1$ //$NON-NLS-2$

}

@Override
public VersionInfo createSupportedVersion() {
public VersionInfo getSupportedVersions() {
final VersionInfo versionInfo = ValidationreportFactory.eINSTANCE
.createVersionInfo();
final String modelVersionsSupported = getSupportedVersions(
final List<String> modelVersionsSupported = getSupportedVersions(
PlanProPackage.eNAME);

versionInfo.setPlanPro(modelVersionsSupported);
final String signalbegriffSupportedVersion = getSupportedVersions(
versionInfo.getPlanProVersions().addAll(modelVersionsSupported);
final List<String> signalbegriffSupportedVersion = getSupportedVersions(
Signalbegriffe_Ril_301Package.eNAME);
versionInfo.setSignals(signalbegriffSupportedVersion);
versionInfo.getSignalbegriffeVersions()
.addAll(signalbegriffSupportedVersion);
return versionInfo;
}

private static String getSupportedVersions(final String packageName) {
private static List<String> getSupportedVersions(final String packageName) {
return PlanProSchemaDir.getSchemaPaths()
.stream()
.filter(p -> p.getFileName()
Expand All @@ -115,14 +102,8 @@ private static String getSupportedVersions(final String packageName) {
.map(Path::toString)
.collect(Collectors.toSet())
.stream()
.sorted((first, second) -> {
final PlanProVersionFormat firstVersion = parseVersionFormat(
first);
final PlanProVersionFormat secondVersion = parseVersionFormat(
second);
return firstVersion.compare(secondVersion);
})
.collect(Collectors.joining(VERSION_SEPARATOR));
.sorted(PlanProVersionFormat.compareVersion())
.toList();
}

@Override
Expand All @@ -134,8 +115,10 @@ public VersionInfo createUsedVersion(final Path location) {

final String planProVersion = parseVersion(text, PLAN_PRO_KEY);

versionInfo.setPlanPro(planProVersion != null ? planProVersion : ""); //$NON-NLS-1$
versionInfo.setSignals(parseVersion(text, SIGNALS_KEY));
versionInfo.getPlanProVersions()
.add(planProVersion != null ? planProVersion : ""); //$NON-NLS-1$
versionInfo.getSignalbegriffeVersions()
.add(parseVersion(text, SIGNALS_KEY));

return versionInfo;
}
Expand All @@ -146,7 +129,32 @@ public PlanProVersionFormat getSupportedVersionFormat() {
}

@Override
public String getCurrentVersion() {
return PlanProPackageExtensions.getModelVersion();
public VersionInfo getCurrentVersion() {
final VersionInfo versionInfo = ValidationreportFactory.eINSTANCE
.createVersionInfo();
final String planProVersion = PlanProPackageExtensions
.getModelVersion();
versionInfo.getPlanProVersions().add(planProVersion);

final String signalBegriffeVersion = SignalbegriffeRil301PackageExtensions
.getModelVersion();
versionInfo.getSignalbegriffeVersions().add(signalBegriffeVersion);
return versionInfo;
}

@Override
public boolean isSupportedVersion(final String uri) {
final VersionInfo supportedVersions = getSupportedVersions();
final String loadedVersion = uri.substring(uri.lastIndexOf("/") + 1); //$NON-NLS-1$
if (uri.startsWith(PLAN_PRO_KEY)) {
return supportedVersions.getPlanProVersions()
.contains(loadedVersion);
}

if (uri.startsWith(SIGNALS_KEY)) {
return supportedVersions.getSignalbegriffeVersions()
.contains(loadedVersion);
}
return false;
}
}
Loading
Loading