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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ dependency-reduced-pom.xml

# Built libraries
*.kpar

# Sysand JAR
org.omg.sysml.xtext/lib/sysand.jar
106 changes: 106 additions & 0 deletions org.omg.kerml.xtext/src/org/omg/kerml/xtext/util/KerMLIndexUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*******************************************************************************
* SysML 2 Pilot Implementation
* Copyright (c) 2026 Model Driven Solutions, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
*
*******************************************************************************/

package org.omg.kerml.xtext.util;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.ecore.resource.Resource;
import org.omg.kerml.xtext.KerMLStandaloneSetup;
import org.omg.sysml.lang.sysml.Membership;
import org.omg.sysml.lang.sysml.Namespace;
import org.omg.sysml.util.SysMLUtil;

public class KerMLIndexUtil extends SysMLUtil {

public KerMLIndexUtil() {
super();
KerMLStandaloneSetup.doSetup();
addExtension(".kerml");
}

protected static String formatEntry(String elementName, String resourcePath) {
return " \"" + elementName + "\": \"" + resourcePath + "\"";
}

public String index(String inputPath) {
java.util.LinkedHashMap<String, String> map = indexAsMap(inputPath);
List<String> entries = new ArrayList<>();
for (var entry : map.entrySet()) {
entries.add(formatEntry(entry.getKey(), entry.getValue()));
}
return String.join("\n", entries);
}

public java.util.LinkedHashMap<String, String> indexAsMap(String inputPath) {
read(inputPath);
File inputFile = new File(inputPath);
String inputDir = inputPath;
if (!inputFile.isDirectory()) {
inputDir = inputFile.getParent();
if (inputDir == null) inputDir = "";
}
java.util.TreeMap<String, String> sorted = new java.util.TreeMap<>();
for (Resource resource : getInputResources()) {
String resourcePath = resource.getURI().toFileString().replace(inputDir + "/", "");
Namespace rootNamespace = (Namespace) resource.getContents().get(0);
List<Membership> memberships = rootNamespace.visibleMemberships(new BasicEList<>(), false, false);
for (Membership m : memberships) {
if (m.getMemberName() != null) sorted.put(m.getMemberName(), resourcePath);
if (m.getMemberShortName() != null) sorted.put(m.getMemberShortName(), resourcePath);
}
}
return new java.util.LinkedHashMap<>(sorted);
}

public void writeIndex(String inputPath, String outputPath) throws IOException {
String index = index(inputPath);
System.out.println("Writing " + outputPath + "...");
Files.writeString(Path.of(outputPath), index);
}

/**
* <p>Usage:
*
* <p>KerMLIndexUtil input-path output-path
*
* <p>where:
*
* <ul>
* <li>input-path is a path for reading input resources (file or directory)</li>
* <li>output-path is a path for an output file</li>
* </ul>
*/
public static void main(String[] args) {
try {
new KerMLIndexUtil().writeIndex(args[0], args[1]);
} catch (IOException e) {
e.printStackTrace();
}
}

}
6 changes: 6 additions & 0 deletions org.omg.sysml.interactive/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin.version}</version>
<executions>
<!-- Disable the sysand-index execution inherited from pluginManagement,
since it needs to be executed only once. -->
<execution>
<id>sysand-index</id>
<phase>none</phase>
</execution>
<execution>
<phase>package</phase>
<goals>
Expand Down
1 change: 1 addition & 0 deletions org.omg.sysml.xtext/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/sysand.jar"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/org.omg.sysml"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.omg.kerml.xtext"/>
Expand Down
6 changes: 6 additions & 0 deletions org.omg.sysml.xtext/.project
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
Expand Down
4 changes: 4 additions & 0 deletions org.omg.sysml.xtext/.settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
2 changes: 2 additions & 0 deletions org.omg.sysml.xtext/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Bundle-Vendor: SysML v2 Submission Team
Bundle-Version: 0.59.0.qualifier
Bundle-SymbolicName: org.omg.sysml.xtext; singleton:=true
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .,
lib/sysand.jar
Require-Bundle: org.eclipse.xtext,
org.eclipse.xtext.xbase,
org.eclipse.equinox.common;bundle-version="3.5.0",
Expand Down
3 changes: 2 additions & 1 deletion org.omg.sysml.xtext/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ source.. = src/,\
src-gen/,\
xtend-gen/
bin.includes = .,\
META-INF/
META-INF/,\
lib/
bin.excludes = **/*.mwe2,\
**/*.xtend
additional.bundles = org.eclipse.xtext.xbase,\
Expand Down
36 changes: 36 additions & 0 deletions org.omg.sysml.xtext/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
<artifactId>org.omg.sysml.xtext</artifactId>
<packaging>eclipse-plugin</packaging>

<dependencies>
<dependency>
<groupId>com.sensmetry</groupId>
<artifactId>sysand</artifactId>
<version>${sysand.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand All @@ -25,6 +33,34 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-sysand</id>
<phase>generate-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.sensmetry</groupId>
<artifactId>sysand</artifactId>
<version>${sysand.version}</version>

<outputDirectory>${project.basedir}/lib</outputDirectory>
<destFileName>sysand.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.eclipse.xtend</groupId>
<artifactId>xtend-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*******************************************************************************
* SysML 2 Pilot Implementation
* Copyright (c) 2026 Model Driven Solutions, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
*
*******************************************************************************/

package org.omg.sysml.xtext.util;

import org.omg.kerml.xtext.util.KerMLIndexUtil;
import org.omg.sysml.xtext.SysMLStandaloneSetup;

public class SysMLIndexUtil extends KerMLIndexUtil {

public SysMLIndexUtil() {
super();
SysMLStandaloneSetup.doSetup();
addExtension(".sysml");
}

/**
* Index all projects in a sysand workspace. For each project, parses SysML/KerML
* files, computes symbol-to-file index, and updates the project's {@code .meta.json}.
*
* @param workspacePath path to the workspace directory containing {@code .workspace.json}
*/
public void indexWorkspace(String workspacePath) throws com.sensmetry.sysand.exceptions.SysandException {
String[] projectPaths = com.sensmetry.sysand.Sysand.workspaceProjectPaths(
java.nio.file.Paths.get(workspacePath));
for (String projectPath : projectPaths) {
System.out.println("Indexing project: " + projectPath);
SysMLIndexUtil util = new SysMLIndexUtil();
java.util.LinkedHashMap<String, String> index = util.indexAsMap(projectPath);
com.sensmetry.sysand.Sysand.setProjectIndex(
java.nio.file.Paths.get(projectPath), index);
System.out.println(" Updated " + index.size() + " index entries");
}
}

/**
* <p>Usage:
*
* <p>Workspace mode: SysMLIndexUtil workspace-path
* <p>Single-file mode: SysMLIndexUtil input-path output-path
*
* <p>Workspace mode is detected when the first argument is a directory
* containing {@code .workspace.json}.
*/
public static void main(String[] args) {
try {
if (new java.io.File(args[0], ".workspace.json").exists()) {
new SysMLIndexUtil().indexWorkspace(args[0]);
} else {
new SysMLIndexUtil().writeIndex(args[0], args[1]);
}
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}

}
57 changes: 53 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<junit.version>3.5.3</junit.version>
<asciidoctor.maven.plugin.version>3.2.0</asciidoctor.maven.plugin.version>
<asciidoctorj.pdf.version>2.3.19</asciidoctorj.pdf.version>
<sysand-maven-plugin.version>0.0.6</sysand-maven-plugin.version>
<sysand.version>0.0.11</sysand.version>
</properties>

<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -298,7 +298,7 @@
<plugin>
<groupId>com.sensmetry</groupId>
<artifactId>sysand-maven-plugin</artifactId>
<version>${sysand-maven-plugin.version}</version>
<version>${sysand.version}</version>
<executions>
<execution>
<goals>
Expand Down Expand Up @@ -329,14 +329,14 @@
<outputDirectory>xtend-gen</outputDirectory>
</configuration>
</plugin>
<!--
<!--
From version 3.0 maven install plugin seems to be more strict about subproject outputs.
This is a workaround to solve the error:
The packaging for this project did not assign a file to the build artifact...
in the jupyter-sysml-kernel project.
Related topic:
https://stackoverflow.com/questions/6308162/maven-the-packaging-for-this-project-did-not-assign-a-file-to-the-build-artifac

TODO: Get rid of this part once we remove gradle form the project (ST6RI-764)
-->
<plugin>
Expand All @@ -356,6 +356,27 @@
<allowIncompleteProjects>true</allowIncompleteProjects>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin.version}</version>
<executions>
<execution>
<id>sysand-index</id>
<phase>prepare-package</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>org.omg.sysml.xtext.util.SysMLIndexUtil</mainClass>
<arguments>
<argument>${maven.multiModuleProjectDirectory}/sysml.library</argument>
</arguments>
<classpathScope>compile</classpathScope>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
Expand All @@ -377,6 +398,34 @@
</execution>
</executions>
</plugin>
<!-- Tell Eclipse m2e to execute maven-dependency-plugin:copy so that
sysand.jar is copied to lib/ automatically during workspace builds. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<versionRange>[1.0,)</versionRange>
<goals>
<goal>copy</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>false</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Expand Down
Loading
Loading