Skip to content

Commit f2591f8

Browse files
ST6RI-927: Add support for setting build and metamodel tags when building stdlib KPARs
Signed-off-by: Vytautas Astrauskas <vytautas.astrauskas@sensmetry.com>
1 parent cd4816d commit f2591f8

14 files changed

Lines changed: 326 additions & 89 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
distribution: 'temurin'
2929
cache: maven
3030
- name: Build with Maven
31-
run: ./mvnw -B clean verify --file pom.xml
31+
run: ./mvnw -B clean verify --file pom.xml -Dsysml.build-tag=nightly-$(date +'%Y%m%d') -Dsysml.metadata-tag=$(date +'%Y%m%d')
3232
- name: Upload SysML Library .kpar files
3333
uses: actions/upload-artifact@v5
3434
with:

org.omg.sysml.xtext/pom.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,27 @@
6060
<plugin>
6161
<groupId>org.codehaus.mojo</groupId>
6262
<artifactId>exec-maven-plugin</artifactId>
63+
<executions>
64+
<execution>
65+
<id>update-project-versions</id>
66+
<phase>prepare-package</phase>
67+
<goals>
68+
<goal>java</goal>
69+
</goals>
70+
<configuration>
71+
<mainClass>org.omg.sysml.xtext.util.StdLibVersionUtil</mainClass>
72+
<arguments>
73+
<argument>--workspace</argument>
74+
<argument>${maven.multiModuleProjectDirectory}/sysml.library</argument>
75+
<argument>--build-tag</argument>
76+
<argument>${sysml.build-tag}</argument>
77+
<argument>--metamodel-tag</argument>
78+
<argument>${sysml.metadata-tag}</argument>
79+
</arguments>
80+
<classpathScope>compile</classpathScope>
81+
</configuration>
82+
</execution>
83+
</executions>
6384
</plugin>
6485
<plugin>
6586
<groupId>org.eclipse.xtend</groupId>
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2026 Sensmetry, UAB.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the Eclipse Public License as published by
7+
* the Eclipse Foundation, version 2 of the License.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* Eclipse Public License for more details.
13+
*
14+
* You should have received a copy of the Eclipse Public License
15+
* along with this program. If not, see <https://www.eclipse.org/legal/epl-2.0/>.
16+
*
17+
* @license EPL-2.0 <http://spdx.org/licenses/EPL-2.0>
18+
*
19+
*******************************************************************************/
20+
21+
package org.omg.sysml.xtext.util;
22+
23+
import java.nio.file.Path;
24+
import java.nio.file.Paths;
25+
26+
import com.sensmetry.sysand.Sysand;
27+
import com.sensmetry.sysand.exceptions.SysandException;
28+
import com.sensmetry.sysand.model.InterchangeProject;
29+
import com.sensmetry.sysand.model.InterchangeProjectInfo;
30+
import com.sensmetry.sysand.model.InterchangeProjectMetadata;
31+
import com.sensmetry.sysand.model.InterchangeProjectUsage;
32+
33+
public class StdLibVersionUtil {
34+
35+
private static final String DEV_SEPARATOR = "-dev.";
36+
37+
/** Strips any existing -dev.* suffix, then appends -dev.<buildTag>. */
38+
static String withBuildTag(String version, String buildTag) {
39+
int idx = version.indexOf(DEV_SEPARATOR);
40+
String base = idx >= 0 ? version.substring(0, idx) : version;
41+
return base + DEV_SEPARATOR + buildTag;
42+
}
43+
44+
/** Strips any existing -dev.* suffix. */
45+
static String stripBuildTag(String version) {
46+
int idx = version.indexOf(DEV_SEPARATOR);
47+
return idx >= 0 ? version.substring(0, idx) : version;
48+
}
49+
50+
/** Applies build tag to a versionConstraint like "=1.0.0" → "=1.0.0-dev.<tag>". */
51+
static String withBuildTagConstraint(String constraint, String buildTag) {
52+
int start = 0;
53+
while (start < constraint.length() && !Character.isDigit(constraint.charAt(start))) {
54+
start++;
55+
}
56+
return constraint.substring(0, start) + withBuildTag(constraint.substring(start), buildTag);
57+
}
58+
59+
/** Strips any existing -dev.* suffix from a versionConstraint like "=1.0.0-dev.<tag>" → "=1.0.0". */
60+
static String stripBuildTagConstraint(String constraint) {
61+
int start = 0;
62+
while (start < constraint.length() && !Character.isDigit(constraint.charAt(start))) {
63+
start++;
64+
}
65+
return constraint.substring(0, start) + stripBuildTag(constraint.substring(start));
66+
}
67+
68+
/**
69+
* Replaces the date segment in a spec resource URL with buildTag.
70+
* URL structure: https://www.omg.org/spec/{lang}/{date}/{name}.kpar
71+
* Splitting by "/" yields the date at index 5.
72+
*/
73+
static String withBuildTagResource(String resource, String buildTag) {
74+
String[] parts = resource.split("/");
75+
if (parts.length >= 7) {
76+
parts[5] = buildTag;
77+
}
78+
return String.join("/", parts);
79+
}
80+
81+
/**
82+
* Replaces the date segment in a spec metamodel URL with buildTag.
83+
* URL structure: https://www.omg.org/spec/{lang}/{date}
84+
* Splitting by "/" yields the date at index 5.
85+
*/
86+
static String withBuildTagMetamodelUrl(String url, String buildTag) {
87+
String[] parts = url.split("/");
88+
if (parts.length >= 6) {
89+
parts[5] = buildTag;
90+
}
91+
return String.join("/", parts);
92+
}
93+
94+
static void updateProject(Path projectPath, String buildTag, String metamodelTag) throws SysandException {
95+
InterchangeProject project = Sysand.infoPath(projectPath);
96+
InterchangeProjectInfo info = project.info;
97+
98+
if (info.getVersion() != null) {
99+
info.setVersion(buildTag != null
100+
? withBuildTag(info.getVersion(), buildTag)
101+
: stripBuildTag(info.getVersion()));
102+
}
103+
104+
InterchangeProjectUsage[] usages = info.getUsage();
105+
for (InterchangeProjectUsage usage : usages) {
106+
if (buildTag != null && usage.getResource() != null) {
107+
usage.setResource(withBuildTagResource(usage.getResource(), buildTag));
108+
}
109+
if (usage.getVersionConstraint() != null) {
110+
usage.setVersionConstraint(buildTag != null
111+
? withBuildTagConstraint(usage.getVersionConstraint(), buildTag)
112+
: stripBuildTagConstraint(usage.getVersionConstraint()));
113+
}
114+
}
115+
info.setUsage(usages);
116+
117+
Sysand.setProjectInfo(projectPath, info);
118+
119+
InterchangeProjectMetadata metadata = project.metadata;
120+
if (metadata != null && metadata.getMetamodel() != null && metamodelTag != null) {
121+
metadata.setMetamodel(withBuildTagMetamodelUrl(metadata.getMetamodel(), metamodelTag));
122+
Sysand.setProjectMetadata(projectPath, metadata);
123+
}
124+
}
125+
126+
public static void updateWorkspace(String workspacePath, String buildTag, String metamodelTag) throws SysandException {
127+
String[] projectPaths = Sysand.workspaceProjectPaths(Paths.get(workspacePath));
128+
for (String projectPath : projectPaths) {
129+
System.out.println(" Updating: " + projectPath);
130+
updateProject(Paths.get(projectPath), buildTag, metamodelTag);
131+
}
132+
}
133+
134+
private static boolean isMavenPlaceholder(String value) {
135+
return value != null && value.startsWith("${");
136+
}
137+
138+
private static String parseTag(String value) {
139+
return (value != null && !value.isEmpty() && !isMavenPlaceholder(value)) ? value : null;
140+
}
141+
142+
private static void printUsage() {
143+
System.err.println("Usage: StdLibVersionUtil --workspace WORKSPACE_PATH");
144+
System.err.println(" [--build-tag BUILD_TAG] [--metamodel-tag METAMODEL_TAG]");
145+
System.err.println();
146+
System.err.println(" --workspace Path to the workspace directory containing .workspace.json (required)");
147+
System.err.println(" --build-tag Stamp -dev.<tag> onto version, versionConstraint, and resource");
148+
System.err.println(" URLs in each project's .project.json");
149+
System.err.println(" --metamodel-tag Replace the date segment of the metamodel URL in each project's");
150+
System.err.println(" .meta.json");
151+
System.err.println(" --help Show this message");
152+
System.err.println();
153+
System.err.println("At least one of --build-tag or --metamodel-tag must be provided.");
154+
}
155+
156+
public static void main(String[] args) throws SysandException {
157+
String workspacePath = null;
158+
String buildTag = null;
159+
String metamodelTag = null;
160+
String rawBuildTag = null;
161+
String rawMetamodelTag = null;
162+
163+
for (int i = 0; i < args.length; i++) {
164+
switch (args[i]) {
165+
case "--help":
166+
printUsage();
167+
return;
168+
case "--workspace":
169+
if (++i >= args.length) { printUsage(); return; }
170+
workspacePath = args[i];
171+
break;
172+
case "--build-tag":
173+
if (++i >= args.length) { printUsage(); return; }
174+
rawBuildTag = args[i];
175+
buildTag = parseTag(args[i]);
176+
break;
177+
case "--metamodel-tag":
178+
if (++i >= args.length) { printUsage(); return; }
179+
rawMetamodelTag = args[i];
180+
metamodelTag = parseTag(args[i]);
181+
break;
182+
default:
183+
System.err.println("Unknown argument: " + args[i]);
184+
printUsage();
185+
return;
186+
}
187+
}
188+
189+
if (workspacePath == null) {
190+
System.err.println("Error: --workspace is required.");
191+
printUsage();
192+
return;
193+
}
194+
195+
if (buildTag == null && metamodelTag == null) {
196+
if (isMavenPlaceholder(rawBuildTag) || isMavenPlaceholder(rawMetamodelTag)) {
197+
System.out.println("Skipping: both --build-tag and --metamodel-tag are Maven placeholders.");
198+
return;
199+
}
200+
System.err.println("Error: at least one of --build-tag or --metamodel-tag must be provided.");
201+
printUsage();
202+
return;
203+
}
204+
205+
if (buildTag != null) {
206+
System.out.println("Applying build tag '" + buildTag + "' to .project.json files in: " + workspacePath);
207+
}
208+
if (metamodelTag != null) {
209+
System.out.println("Applying metamodel tag '" + metamodelTag + "' to .meta.json files in: " + workspacePath);
210+
}
211+
updateWorkspace(workspacePath, buildTag, metamodelTag);
212+
System.out.println("Done.");
213+
}
214+
}

pom.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
<properties>
77
<revision>0.60.0-SNAPSHOT</revision>
8+
<sysml.build-tag>20260501</sysml.build-tag>
9+
<sysml.metadata-tag>20250201</sysml.metadata-tag>
810
<tycho-version>4.0.13</tycho-version>
911
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1012
<maven-antrun-plugin.version>3.1.0</maven-antrun-plugin.version>
@@ -28,7 +30,7 @@
2830
<junit.version>3.5.3</junit.version>
2931
<asciidoctor.maven.plugin.version>3.2.0</asciidoctor.maven.plugin.version>
3032
<asciidoctorj.pdf.version>2.3.19</asciidoctorj.pdf.version>
31-
<sysand.version>0.0.11</sysand.version>
33+
<sysand.version>0.1.0-rc.1</sysand.version>
3234
</properties>
3335

3436
<modelVersion>4.0.0</modelVersion>
@@ -358,14 +360,14 @@
358360
<artifactId>build-helper-maven-plugin</artifactId>
359361
<version>${build-helper-maven-plugin.version}</version>
360362
</plugin>
361-
<!--
363+
<!--
362364
From version 3.0 maven install plugin seems to be more strict about subproject outputs.
363365
This is a workaround to solve the error:
364366
The packaging for this project did not assign a file to the build artifact...
365367
in the jupyter-sysml-kernel project.
366368
Related topic:
367369
https://stackoverflow.com/questions/6308162/maven-the-packaging-for-this-project-did-not-assign-a-file-to-the-build-artifac
368-
370+
369371
TODO: Get rid of this part once we remove gradle form the project (ST6RI-764)
370372
-->
371373
<plugin>
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
{
22
"name": "SysML Analysis Library",
3-
"version": "2.0.0",
43
"description": "Standard analysis domain library for the Systems Modeling Language (SysML)",
4+
"version": "2.1.0-dev.20260501",
55
"usage": [
66
{
7-
"resource": "https://www.omg.org/spec/KerML/20250201/Semantic-Library.kpar",
8-
"versionConstraint": "1.0.0"
7+
"resource": "https://www.omg.org/spec/KerML/20260501/Semantic-Library.kpar",
8+
"versionConstraint": "1.1.0-dev.20260501"
99
},
1010
{
11-
"resource": "https://www.omg.org/spec/KerML/20250201/Data-Type-Library.kpar",
12-
"versionConstraint": "1.0.0"
11+
"resource": "https://www.omg.org/spec/KerML/20260501/Data-Type-Library.kpar",
12+
"versionConstraint": "1.1.0-dev.20260501"
1313
},
1414
{
15-
"resource": "https://www.omg.org/spec/KerML/20250201/Function-Library.kpar",
16-
"versionConstraint": "1.0.0"
15+
"resource": "https://www.omg.org/spec/KerML/20260501/Function-Library.kpar",
16+
"versionConstraint": "1.1.0-dev.20260501"
1717
},
1818
{
19-
"resource": "https://www.omg.org/spec/SysML/20250201/Systems-Library.kpar",
20-
"versionConstraint": "2.0.0"
19+
"resource": "https://www.omg.org/spec/SysML/20260501/Systems-Library.kpar",
20+
"versionConstraint": "2.1.0-dev.20260501"
2121
},
2222
{
23-
"resource": "https://www.omg.org/spec/KerML/20250201/Quantities-and-Units-Library.kpar",
24-
"versionConstraint": "2.0.0"
23+
"resource": "https://www.omg.org/spec/SysML/20260501/Quantities-and-Units-Domain-Library.kpar",
24+
"versionConstraint": "2.1.0-dev.20260501"
2525
}
2626
]
27-
}
27+
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
{
22
"name": "SysML Cause and Effect Library",
3-
"version": "2.0.0",
43
"description": "Standard cause-and-effect domain library for the Systems Modeling Language (SysML)",
4+
"version": "2.1.0-dev.20260501",
55
"usage": [
66
{
7-
"resource": "https://www.omg.org/spec/KerML/20250201/Semantic-Library.kpar",
8-
"versionConstraint": "1.0.0"
7+
"resource": "https://www.omg.org/spec/KerML/20260501/Semantic-Library.kpar",
8+
"versionConstraint": "1.1.0-dev.20260501"
99
},
1010
{
11-
"resource": "https://www.omg.org/spec/KerML/20250201/Data-Type-Library.kpar",
12-
"versionConstraint": "1.0.0"
11+
"resource": "https://www.omg.org/spec/KerML/20260501/Data-Type-Library.kpar",
12+
"versionConstraint": "1.1.0-dev.20260501"
1313
},
1414
{
15-
"resource": "https://www.omg.org/spec/KerML/20250201/Function-Library.kpar",
16-
"versionConstraint": "1.0.0"
15+
"resource": "https://www.omg.org/spec/KerML/20260501/Function-Library.kpar",
16+
"versionConstraint": "1.1.0-dev.20260501"
1717
},
1818
{
19-
"resource": "https://www.omg.org/spec/SysML/20250201/Systems-Library.kpar",
20-
"versionConstraint": "2.0.0"
19+
"resource": "https://www.omg.org/spec/SysML/20260501/Systems-Library.kpar",
20+
"versionConstraint": "2.1.0-dev.20260501"
2121
}
2222
]
23-
}
23+
}

0 commit comments

Comments
 (0)