Skip to content

Commit 6275a06

Browse files
committed
Xcore and Plantuml commands
1 parent b7083c8 commit 6275a06

5 files changed

Lines changed: 193 additions & 7 deletions

File tree

pom.xml

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@
8181
<artifactId>http</artifactId>
8282
<version>2026.2.0</version>
8383
</dependency>
84+
<dependency>
85+
<groupId>org.nasdanika.core</groupId>
86+
<artifactId>emf-json</artifactId>
87+
<version>2026.2.0</version>
88+
</dependency>
89+
<dependency>
90+
<groupId>org.nasdanika.core</groupId>
91+
<artifactId>plantuml</artifactId>
92+
<version>2026.2.0</version>
93+
</dependency>
8494
<!--
8595
<dependency>
8696
<groupId>org.nasdanika.core</groupId>
@@ -120,7 +130,53 @@
120130
<artifactId>junit-jupiter-engine</artifactId>
121131
<version>6.0.1</version>
122132
<scope>test</scope>
123-
</dependency>
133+
</dependency>
134+
135+
136+
<!-- XCore dependencies -->
137+
<dependency>
138+
<groupId>org.nasdanika</groupId>
139+
<artifactId>xtext</artifactId>
140+
<classifier>jpms-ready</classifier>
141+
<version>2.42.0</version>
142+
</dependency>
143+
<dependency>
144+
<groupId>org.eclipse.emf</groupId>
145+
<artifactId>org.eclipse.emf.ecore.xcore</artifactId>
146+
<version>1.36.0</version>
147+
<exclusions>
148+
<exclusion>
149+
<groupId>org.eclipse.xtext</groupId>
150+
<artifactId>org.eclipse.xtext</artifactId>
151+
</exclusion>
152+
<exclusion>
153+
<groupId>org.eclipse.xtext</groupId>
154+
<artifactId>org.eclipse.xtext.util</artifactId>
155+
</exclusion>
156+
</exclusions>
157+
</dependency>
158+
<dependency>
159+
<groupId>org.eclipse.emf</groupId>
160+
<artifactId>org.eclipse.emf.ecore.xcore.lib</artifactId>
161+
<version>1.7.1</version>
162+
</dependency>
163+
<dependency>
164+
<groupId>org.apache.logging.log4j</groupId>
165+
<artifactId>log4j-api</artifactId>
166+
<version>2.25.4</version>
167+
</dependency>
168+
<dependency>
169+
<groupId>org.apache.logging.log4j</groupId>
170+
<artifactId>log4j-core</artifactId>
171+
<version>2.25.4</version>
172+
</dependency>
173+
174+
<dependency>
175+
<groupId>org.apache.logging.log4j</groupId>
176+
<artifactId>log4j-1.2-api</artifactId>
177+
<version>2.25.4</version>
178+
</dependency>
179+
124180
</dependencies>
125181

126182
<build>
@@ -315,4 +371,13 @@
315371
</build>
316372
</profile>
317373
</profiles>
374+
375+
<!-- For Xtext wrapper -->
376+
<repositories>
377+
<repository>
378+
<id>nasdanika-releases</id>
379+
<url>https://maven.nasdanika.org/releases</url>
380+
</repository>
381+
</repositories>
382+
318383
</project>

src/main/java/module-info.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1+
import org.nasdanika.capability.CapabilityFactory;
2+
import org.nasdanika.launcher.XcoreCommandFactory;
3+
14
module org.nasdanika.launcher {
2-
5+
36
exports org.nasdanika.launcher;
4-
7+
58
requires transitive org.nasdanika.cli;
6-
9+
710
// For loading configuration
811
requires ch.qos.logback.classic;
9-
requires ch.qos.logback.core;
10-
12+
requires ch.qos.logback.core;
13+
1114
requires org.nasdanika.models.echarts.graph;
1215
requires java.sql;
13-
16+
17+
// For XcoreCommand
18+
requires org.nasdanika.xtext;
19+
requires org.eclipse.emf.ecore.xcore;
20+
requires com.google.guice;
21+
requires org.eclipse.xtext.common.types;
22+
requires org.apache.log4j;
23+
24+
opens org.nasdanika.launcher to info.picocli, org.nasdanika.cli;
25+
26+
provides CapabilityFactory with XcoreCommandFactory;
1427
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.nasdanika.launcher;
2+
3+
public class ModuleVersionProvider extends org.nasdanika.cli.ModuleVersionProvider {
4+
5+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package org.nasdanika.launcher;
2+
3+
import java.io.File;
4+
import java.util.Collection;
5+
6+
import org.eclipse.emf.common.util.URI;
7+
import org.eclipse.emf.ecore.EModelElement;
8+
import org.eclipse.emf.ecore.resource.Resource;
9+
import org.eclipse.emf.ecore.util.EcoreUtil;
10+
import org.eclipse.emf.ecore.xcore.XcoreStandaloneSetup;
11+
import org.eclipse.xtext.resource.XtextResourceSet;
12+
import org.nasdanika.capability.CapabilityLoader;
13+
import org.nasdanika.cli.CommandGroup;
14+
import org.nasdanika.cli.ParentCommands;
15+
import org.nasdanika.cli.ResourceSetMixIn;
16+
import org.nasdanika.cli.RootCommand;
17+
import org.nasdanika.common.Description;
18+
import org.nasdanika.common.EModelElementSupplier;
19+
import org.nasdanika.common.ProgressMonitor;
20+
21+
import com.google.inject.Injector;
22+
23+
import picocli.CommandLine.Command;
24+
import picocli.CommandLine.Mixin;
25+
import picocli.CommandLine.Option;
26+
import picocli.CommandLine.Parameters;
27+
28+
@Command(
29+
description = "Loads Ecore models from an Xcore URI or file",
30+
versionProvider = ModuleVersionProvider.class,
31+
mixinStandardHelpOptions = true,
32+
name = "xcore")
33+
@ParentCommands(RootCommand.class)
34+
@Description(icon = "https://docs.nasdanika.org/images/xcore-logo-g.svg")
35+
public class XcoreCommand extends CommandGroup implements EModelElementSupplier<EModelElement> {
36+
37+
protected XcoreCommand() {
38+
super();
39+
}
40+
41+
protected XcoreCommand(CapabilityLoader capabilityLoader) {
42+
super(capabilityLoader);
43+
}
44+
45+
@Parameters(
46+
index = "0",
47+
arity = "1",
48+
description = {
49+
"Xcore resource URI or file path",
50+
"resolved relative to the current directory"
51+
})
52+
private String uri;
53+
54+
@Option(
55+
names = {"-f", "--file"},
56+
description = "URI parameter is a file path")
57+
private boolean isFile;
58+
59+
@Override
60+
public Collection<EModelElement> getEObjects(ProgressMonitor progressMonitor) {
61+
URI theUri = isFile ? URI.createFileURI(new File(uri).getAbsolutePath()) : URI.createURI(uri).resolve(URI.createFileURI(new File(".").getAbsolutePath()).appendSegment(""));
62+
63+
Injector injector = new XcoreStandaloneSetup().createInjectorAndDoEMFRegistration();
64+
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
65+
Resource resource = resourceSet.getResource(theUri, true);
66+
EcoreUtil.resolveAll(resource);
67+
68+
return resource.getContents()
69+
.stream()
70+
.filter(EModelElement.class::isInstance)
71+
.map(EModelElement.class::cast)
72+
.toList();
73+
74+
}
75+
76+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.nasdanika.launcher;
2+
3+
import java.util.List;
4+
import java.util.concurrent.CompletableFuture;
5+
import java.util.concurrent.CompletionStage;
6+
7+
import org.nasdanika.cli.SubCommandCapabilityFactory;
8+
import org.nasdanika.common.ProgressMonitor;
9+
10+
import picocli.CommandLine;
11+
12+
public class XcoreCommandFactory extends SubCommandCapabilityFactory<XcoreCommand> {
13+
14+
@Override
15+
protected Class<XcoreCommand> getCommandType() {
16+
return XcoreCommand.class;
17+
}
18+
19+
@Override
20+
protected CompletionStage<XcoreCommand> doCreateCommand(
21+
List<CommandLine> parentPath,
22+
Loader loader,
23+
ProgressMonitor progressMonitor) {
24+
return CompletableFuture.completedStage(new XcoreCommand(loader.getCapabilityLoader()));
25+
}
26+
27+
}

0 commit comments

Comments
 (0)