Skip to content

Commit 3009d58

Browse files
Add a dependency on Sysand and update SysMLIndexUtil to use it for updating workspaces.
1 parent 07150c9 commit 3009d58

17 files changed

Lines changed: 161 additions & 47 deletions

File tree

org.omg.kerml.xtext/src/org/omg/kerml/xtext/util/KerMLIndexUtil.java

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.nio.file.Path;
2828
import java.util.ArrayList;
2929
import java.util.List;
30-
import java.util.stream.Stream;
3130

3231
import org.eclipse.emf.common.util.BasicEList;
3332
import org.eclipse.emf.ecore.resource.Resource;
@@ -49,30 +48,35 @@ protected static String formatEntry(String elementName, String resourcePath) {
4948
}
5049

5150
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) {
5260
read(inputPath);
5361
File inputFile = new File(inputPath);
62+
String inputDir = inputPath;
5463
if (!inputFile.isDirectory()) {
55-
inputPath = inputFile.getParent();
56-
if (inputPath == null) {
57-
inputPath = "";
58-
}
64+
inputDir = inputFile.getParent();
65+
if (inputDir == null) inputDir = "";
5966
}
60-
List<String> entries = new ArrayList<>();
61-
for (Resource resource: getInputResources()) {
62-
String resourcePath = resource.getURI().toFileString().replace(inputPath + "/", "");
63-
Namespace rootNamespace = (Namespace)resource.getContents().get(0);
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);
6471
List<Membership> memberships = rootNamespace.visibleMemberships(new BasicEList<>(), false, false);
65-
Stream<String> names = memberships.stream().map(Membership::getMemberName);
66-
Stream<String> shortNames = memberships.stream().map(Membership::getMemberShortName);
67-
Stream.concat(names, shortNames)
68-
.filter(name->name != null)
69-
.map(name->formatEntry(name, resourcePath))
70-
.forEach(entries::add);
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+
}
7176
}
72-
entries.sort(null);
73-
return String.join("\n", entries);
77+
return new java.util.LinkedHashMap<>(sorted);
7478
}
75-
79+
7680
public void writeIndex(String inputPath, String outputPath) throws IOException {
7781
String index = index(inputPath);
7882
System.out.println("Writing " + outputPath + "...");

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/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.58.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>

org.omg.sysml.xtext/src/org/omg/sysml/xtext/util/SysMLIndexUtil.java

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
package org.omg.sysml.xtext.util;
2323

24-
import java.io.IOException;
25-
2624
import org.omg.kerml.xtext.util.KerMLIndexUtil;
2725
import org.omg.sysml.xtext.SysMLStandaloneSetup;
2826

@@ -33,24 +31,45 @@ public SysMLIndexUtil() {
3331
SysMLStandaloneSetup.doSetup();
3432
addExtension(".sysml");
3533
}
36-
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+
3754
/**
3855
* <p>Usage:
39-
*
40-
* <p>SysMLIndexUtil input-path output-path
41-
*
42-
* <p>where:
43-
*
44-
* <ul>
45-
* <li>input-path is a path for reading input resources (file or directory)</li>
46-
* <li>output-path is a path for an output file</li>
47-
* </ul>
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}.
4862
*/
4963
public static void main(String[] args) {
5064
try {
51-
new SysMLIndexUtil().writeIndex(args[0], args[1]);
52-
} catch (IOException e) {
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) {
5371
e.printStackTrace();
72+
System.exit(1);
5473
}
5574
}
5675

pom.xml

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
<junit.version>3.5.3</junit.version>
2929
<asciidoctor.maven.plugin.version>3.2.0</asciidoctor.maven.plugin.version>
3030
<asciidoctorj.pdf.version>2.3.19</asciidoctorj.pdf.version>
31-
<sysand-maven-plugin.version>0.0.6</sysand-maven-plugin.version>
31+
<!-- TODO: Release 0.0.11 of sysand-maven-plugin before merging. -->
32+
<sysand.version>0.0.10-SNAPSHOT</sysand.version>
3233
</properties>
3334

3435
<modelVersion>4.0.0</modelVersion>
@@ -37,6 +38,34 @@
3738
<version>${revision}</version>
3839
<packaging>pom</packaging>
3940

41+
<!-- TODO: Remove before merging (needed to be able to test with the snapshot
42+
version of sysand-maven-plugin) -->
43+
<repositories>
44+
<repository>
45+
<id>central-snapshots</id>
46+
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
47+
<releases>
48+
<enabled>false</enabled>
49+
</releases>
50+
<snapshots>
51+
<enabled>true</enabled>
52+
</snapshots>
53+
</repository>
54+
</repositories>
55+
56+
<pluginRepositories>
57+
<pluginRepository>
58+
<id>central-snapshots</id>
59+
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
60+
<releases>
61+
<enabled>false</enabled>
62+
</releases>
63+
<snapshots>
64+
<enabled>true</enabled>
65+
</snapshots>
66+
</pluginRepository>
67+
</pluginRepositories>
68+
4069
<modules>
4170
<module>org.omg.sysml</module>
4271
<module>org.omg.sysml.edit</module>
@@ -298,7 +327,7 @@
298327
<plugin>
299328
<groupId>com.sensmetry</groupId>
300329
<artifactId>sysand-maven-plugin</artifactId>
301-
<version>${sysand-maven-plugin.version}</version>
330+
<version>${sysand.version}</version>
302331
<executions>
303332
<execution>
304333
<goals>
@@ -329,14 +358,14 @@
329358
<outputDirectory>xtend-gen</outputDirectory>
330359
</configuration>
331360
</plugin>
332-
<!--
361+
<!--
333362
From version 3.0 maven install plugin seems to be more strict about subproject outputs.
334363
This is a workaround to solve the error:
335364
The packaging for this project did not assign a file to the build artifact...
336365
in the jupyter-sysml-kernel project.
337366
Related topic:
338367
https://stackoverflow.com/questions/6308162/maven-the-packaging-for-this-project-did-not-assign-a-file-to-the-build-artifac
339-
368+
340369
TODO: Get rid of this part once we remove gradle form the project (ST6RI-764)
341370
-->
342371
<plugin>
@@ -356,6 +385,27 @@
356385
<allowIncompleteProjects>true</allowIncompleteProjects>
357386
</configuration>
358387
</plugin>
388+
<plugin>
389+
<groupId>org.codehaus.mojo</groupId>
390+
<artifactId>exec-maven-plugin</artifactId>
391+
<version>${exec-maven-plugin.version}</version>
392+
<executions>
393+
<execution>
394+
<id>sysand-index</id>
395+
<phase>prepare-package</phase>
396+
<goals>
397+
<goal>java</goal>
398+
</goals>
399+
<configuration>
400+
<mainClass>org.omg.sysml.xtext.util.SysMLIndexUtil</mainClass>
401+
<arguments>
402+
<argument>${maven.multiModuleProjectDirectory}/sysml.library</argument>
403+
</arguments>
404+
<classpathScope>compile</classpathScope>
405+
</configuration>
406+
</execution>
407+
</executions>
408+
</plugin>
359409
<plugin>
360410
<groupId>org.apache.maven.plugins</groupId>
361411
<artifactId>maven-clean-plugin</artifactId>

sysml.library/Domain Libraries/Analysis/.meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
},
88
"created": "2025-03-13T00:00:00Z",
99
"metamodel": "https://www.omg.org/spec/SysML/20250201"
10-
}
10+
}

sysml.library/Domain Libraries/Cause and Effect/.meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
},
66
"created": "2025-03-13T00:00:00Z",
77
"metamodel": "https://www.omg.org/spec/SysML/20250201"
8-
}
8+
}

sysml.library/Domain Libraries/Geometry/.meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
},
66
"created": "2025-03-13T00:00:00Z",
77
"metamodel": "https://www.omg.org/spec/SysML/20250201"
8-
}
8+
}

0 commit comments

Comments
 (0)