Skip to content

Commit 96a0212

Browse files
authored
Merge pull request #751 from Systems-Modeling/ST6RI-898
ST6RI-898 Automatically update the `index` field in .meta.json for standard library releases
2 parents 5694b8a + fa00700 commit 96a0212

21 files changed

Lines changed: 306 additions & 15 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ dependency-reduced-pom.xml
4040

4141
# Built libraries
4242
*.kpar
43+
44+
# Sysand JAR
45+
org.omg.sysml.xtext/lib/sysand.jar
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2026 Model Driven Solutions, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
*******************************************************************************/
21+
22+
package org.omg.kerml.xtext.util;
23+
24+
import java.io.File;
25+
import java.io.IOException;
26+
import java.nio.file.Files;
27+
import java.nio.file.Path;
28+
import java.util.ArrayList;
29+
import java.util.List;
30+
31+
import org.eclipse.emf.common.util.BasicEList;
32+
import org.eclipse.emf.ecore.resource.Resource;
33+
import org.omg.kerml.xtext.KerMLStandaloneSetup;
34+
import org.omg.sysml.lang.sysml.Membership;
35+
import org.omg.sysml.lang.sysml.Namespace;
36+
import org.omg.sysml.util.SysMLUtil;
37+
38+
public class KerMLIndexUtil extends SysMLUtil {
39+
40+
public KerMLIndexUtil() {
41+
super();
42+
KerMLStandaloneSetup.doSetup();
43+
addExtension(".kerml");
44+
}
45+
46+
protected static String formatEntry(String elementName, String resourcePath) {
47+
return " \"" + elementName + "\": \"" + resourcePath + "\"";
48+
}
49+
50+
public String index(String inputPath) {
51+
java.util.LinkedHashMap<String, String> map = indexAsMap(inputPath);
52+
List<String> entries = new ArrayList<>();
53+
for (var entry : map.entrySet()) {
54+
entries.add(formatEntry(entry.getKey(), entry.getValue()));
55+
}
56+
return String.join("\n", entries);
57+
}
58+
59+
public java.util.LinkedHashMap<String, String> indexAsMap(String inputPath) {
60+
read(inputPath);
61+
File inputFile = new File(inputPath);
62+
String inputDir = inputPath;
63+
if (!inputFile.isDirectory()) {
64+
inputDir = inputFile.getParent();
65+
if (inputDir == null) inputDir = "";
66+
}
67+
java.util.TreeMap<String, String> sorted = new java.util.TreeMap<>();
68+
for (Resource resource : getInputResources()) {
69+
String resourcePath = resource.getURI().toFileString().replace(inputDir + "/", "");
70+
Namespace rootNamespace = (Namespace) resource.getContents().get(0);
71+
List<Membership> memberships = rootNamespace.visibleMemberships(new BasicEList<>(), false, false);
72+
for (Membership m : memberships) {
73+
if (m.getMemberName() != null) sorted.put(m.getMemberName(), resourcePath);
74+
if (m.getMemberShortName() != null) sorted.put(m.getMemberShortName(), resourcePath);
75+
}
76+
}
77+
return new java.util.LinkedHashMap<>(sorted);
78+
}
79+
80+
public void writeIndex(String inputPath, String outputPath) throws IOException {
81+
String index = index(inputPath);
82+
System.out.println("Writing " + outputPath + "...");
83+
Files.writeString(Path.of(outputPath), index);
84+
}
85+
86+
/**
87+
* <p>Usage:
88+
*
89+
* <p>KerMLIndexUtil input-path output-path
90+
*
91+
* <p>where:
92+
*
93+
* <ul>
94+
* <li>input-path is a path for reading input resources (file or directory)</li>
95+
* <li>output-path is a path for an output file</li>
96+
* </ul>
97+
*/
98+
public static void main(String[] args) {
99+
try {
100+
new KerMLIndexUtil().writeIndex(args[0], args[1]);
101+
} catch (IOException e) {
102+
e.printStackTrace();
103+
}
104+
}
105+
106+
}

org.omg.sysml.interactive/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@
9696
<artifactId>exec-maven-plugin</artifactId>
9797
<version>${exec-maven-plugin.version}</version>
9898
<executions>
99+
<!-- Disable the sysand-index execution inherited from pluginManagement,
100+
since it needs to be executed only once. -->
101+
<execution>
102+
<id>sysand-index</id>
103+
<phase>none</phase>
104+
</execution>
99105
<execution>
100106
<phase>package</phase>
101107
<goals>

org.omg.sysml.xtext/.classpath

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<attribute name="module" value="true"/>
99
</attributes>
1010
</classpathentry>
11+
<classpathentry kind="lib" path="lib/sysand.jar"/>
1112
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
1213
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/org.omg.sysml"/>
1314
<classpathentry combineaccessrules="false" kind="src" path="/org.omg.kerml.xtext"/>

org.omg.sysml.xtext/.project

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@
2525
<arguments>
2626
</arguments>
2727
</buildCommand>
28+
<buildCommand>
29+
<name>org.eclipse.m2e.core.maven2Builder</name>
30+
<arguments>
31+
</arguments>
32+
</buildCommand>
2833
</buildSpec>
2934
<natures>
35+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
3036
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
3137
<nature>org.eclipse.jdt.core.javanature</nature>
3238
<nature>org.eclipse.pde.PluginNature</nature>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1

org.omg.sysml.xtext/META-INF/MANIFEST.MF

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Bundle-Vendor: SysML v2 Submission Team
77
Bundle-Version: 0.59.0.qualifier
88
Bundle-SymbolicName: org.omg.sysml.xtext; singleton:=true
99
Bundle-ActivationPolicy: lazy
10+
Bundle-ClassPath: .,
11+
lib/sysand.jar
1012
Require-Bundle: org.eclipse.xtext,
1113
org.eclipse.xtext.xbase,
1214
org.eclipse.equinox.common;bundle-version="3.5.0",

org.omg.sysml.xtext/build.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ source.. = src/,\
22
src-gen/,\
33
xtend-gen/
44
bin.includes = .,\
5-
META-INF/
5+
META-INF/,\
6+
lib/
67
bin.excludes = **/*.mwe2,\
78
**/*.xtend
89
additional.bundles = org.eclipse.xtext.xbase,\

org.omg.sysml.xtext/pom.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
<artifactId>org.omg.sysml.xtext</artifactId>
1414
<packaging>eclipse-plugin</packaging>
1515

16+
<dependencies>
17+
<dependency>
18+
<groupId>com.sensmetry</groupId>
19+
<artifactId>sysand</artifactId>
20+
<version>${sysand.version}</version>
21+
</dependency>
22+
</dependencies>
23+
1624
<build>
1725
<plugins>
1826
<plugin>
@@ -25,6 +33,34 @@
2533
</execution>
2634
</executions>
2735
</plugin>
36+
<plugin>
37+
<artifactId>maven-dependency-plugin</artifactId>
38+
<executions>
39+
<execution>
40+
<id>copy-sysand</id>
41+
<phase>generate-resources</phase>
42+
<goals>
43+
<goal>copy</goal>
44+
</goals>
45+
<configuration>
46+
<artifactItems>
47+
<artifactItem>
48+
<groupId>com.sensmetry</groupId>
49+
<artifactId>sysand</artifactId>
50+
<version>${sysand.version}</version>
51+
52+
<outputDirectory>${project.basedir}/lib</outputDirectory>
53+
<destFileName>sysand.jar</destFileName>
54+
</artifactItem>
55+
</artifactItems>
56+
</configuration>
57+
</execution>
58+
</executions>
59+
</plugin>
60+
<plugin>
61+
<groupId>org.codehaus.mojo</groupId>
62+
<artifactId>exec-maven-plugin</artifactId>
63+
</plugin>
2864
<plugin>
2965
<groupId>org.eclipse.xtend</groupId>
3066
<artifactId>xtend-maven-plugin</artifactId>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2026 Model Driven Solutions, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
*******************************************************************************/
21+
22+
package org.omg.sysml.xtext.util;
23+
24+
import org.omg.kerml.xtext.util.KerMLIndexUtil;
25+
import org.omg.sysml.xtext.SysMLStandaloneSetup;
26+
27+
public class SysMLIndexUtil extends KerMLIndexUtil {
28+
29+
public SysMLIndexUtil() {
30+
super();
31+
SysMLStandaloneSetup.doSetup();
32+
addExtension(".sysml");
33+
}
34+
35+
/**
36+
* Index all projects in a sysand workspace. For each project, parses SysML/KerML
37+
* files, computes symbol-to-file index, and updates the project's {@code .meta.json}.
38+
*
39+
* @param workspacePath path to the workspace directory containing {@code .workspace.json}
40+
*/
41+
public void indexWorkspace(String workspacePath) throws com.sensmetry.sysand.exceptions.SysandException {
42+
String[] projectPaths = com.sensmetry.sysand.Sysand.workspaceProjectPaths(
43+
java.nio.file.Paths.get(workspacePath));
44+
for (String projectPath : projectPaths) {
45+
System.out.println("Indexing project: " + projectPath);
46+
SysMLIndexUtil util = new SysMLIndexUtil();
47+
java.util.LinkedHashMap<String, String> index = util.indexAsMap(projectPath);
48+
com.sensmetry.sysand.Sysand.setProjectIndex(
49+
java.nio.file.Paths.get(projectPath), index);
50+
System.out.println(" Updated " + index.size() + " index entries");
51+
}
52+
}
53+
54+
/**
55+
* <p>Usage:
56+
*
57+
* <p>Workspace mode: SysMLIndexUtil workspace-path
58+
* <p>Single-file mode: SysMLIndexUtil input-path output-path
59+
*
60+
* <p>Workspace mode is detected when the first argument is a directory
61+
* containing {@code .workspace.json}.
62+
*/
63+
public static void main(String[] args) {
64+
try {
65+
if (new java.io.File(args[0], ".workspace.json").exists()) {
66+
new SysMLIndexUtil().indexWorkspace(args[0]);
67+
} else {
68+
new SysMLIndexUtil().writeIndex(args[0], args[1]);
69+
}
70+
} catch (Exception e) {
71+
e.printStackTrace();
72+
System.exit(1);
73+
}
74+
}
75+
76+
}

0 commit comments

Comments
 (0)