Skip to content

Commit

Permalink
minimal implementation of lfd
Browse files Browse the repository at this point in the history
  • Loading branch information
cmnrd committed Jun 16, 2023
1 parent 864ac74 commit 2f30d0a
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 3 deletions.
1 change: 1 addition & 0 deletions bin/lfd
9 changes: 9 additions & 0 deletions bin/lfd.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#==========================================================
# Description: Run the lff compiler.
# Authors: Ruomu Xu
# Usage: Usage: lff [options] files...
#==========================================================

$launchScript="$PSScriptRoot\..\util\scripts\launch.ps1"
# PS requires spattling: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Splatting?view=powershell-7.2
. $launchScript @args
21 changes: 21 additions & 0 deletions buildSrc/src/main/groovy/org.lflang.java-conventions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,24 @@ spotless {
formatAnnotations()
}
}

configurations.all {
resolutionStrategy {
dependencySubstitution {
// The maven property ${osgi.platform} is not handled by Gradle
// so we replace the dependency, using the osgi platform from the project settings
//def swtVersion = "3.123.0"
def swtVersion = '3.124.0'
def os = System.getProperty("os.name").toLowerCase()
if (os.contains("windows")) {
substitute module('org.eclipse.platform:org.eclipse.swt.${osgi.platform}') using module("org.eclipse.platform:org.eclipse.swt.win32.win32.x86_64:${swtVersion}")
}
else if (os.contains("linux")) {
substitute module('org.eclipse.platform:org.eclipse.swt.${osgi.platform}') using module("org.eclipse.platform:org.eclipse.swt.gtk.linux.x86_64:${swtVersion}")
}
else if (os.contains("mac")) {
substitute module('org.eclipse.platform:org.eclipse.swt.${osgi.platform}') using module("org.eclipse.platform:org.eclipse.swt.cocoa.macosx.x86_64:${swtVersion}")
}
}
}
}
35 changes: 35 additions & 0 deletions cli/lfd/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
plugins {
id 'org.lflang.java-application-conventions'
id 'com.github.johnrengelman.shadow'
}

dependencies {
implementation project(':cli:base')
implementation ("de.cau.cs.kieler.klighd:de.cau.cs.kieler.klighd.standalone:$klighdVersion") {
exclude group: 'de.cau.cs.kieler.swt.mock'
}
implementation ("de.cau.cs.kieler.klighd:de.cau.cs.kieler.klighd.piccolo:${klighdVersion}") {
exclude group: 'de.cau.cs.kieler.swt.mock'
}
implementation ("de.cau.cs.kieler.klighd:de.cau.cs.kieler.klighd.piccolo.freehep:${klighdVersion}") {
exclude group: 'de.cau.cs.kieler.swt.mock'
}
implementation ("org.freehep:freehep-graphicsio-svg:${freehepVersion}")
}

application {
mainClass = 'org.lflang.cli.Lfd'
tasks.run.workingDir = System.getProperty("user.dir")
}

test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
showStandardStreams = true
}
}

shadowJar {
mergeServiceFiles()
}
58 changes: 58 additions & 0 deletions cli/lfd/src/main/java/org/lflang/cli/Lfd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.lflang.cli;

import de.cau.cs.kieler.klighd.LightDiagramServices;
import de.cau.cs.kieler.klighd.standalone.KlighdStandaloneSetup;
import java.nio.file.Path;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.ecore.resource.Resource;
import org.lflang.lf.Model;
import org.lflang.util.FileUtil;
import picocli.CommandLine.Command;

/**
* Command lin tool for generating diagrams from Lingua Franca programs.
*
* @author Christian Menard
*/
@Command(
name = "lfd",
// Enable usageHelp (--help) and versionHelp (--version) options.
mixinStandardHelpOptions = true,
versionProvider = VersionProvider.class)
public class Lfd extends CliBase {

@Override
public void doRun() {
KlighdStandaloneSetup.initialize();

for (Path relativePath : getInputPaths()) {
Path path = toAbsolutePath(relativePath);
final Resource resource = getResource(path);
final Model model = (Model) resource.getContents().get(0);
String baseName = FileUtil.nameWithoutExtension(relativePath);
IStatus status = LightDiagramServices.renderOffScreen(model, "svg", baseName + ".svg");
if (!status.isOK()) {
reporter.printFatalErrorAndExit(status.getMessage());
}
}
}

/**
* Main entry point of the diagram tool.
*
* @param args CLI arguments
*/
public static void main(String[] args) {
main(Io.SYSTEM, args);
}

/**
* Programmatic entry point, with a custom IO.
*
* @param io IO streams.
* @param args Command-line arguments.
*/
public static void main(Io io, final String... args) {
cliMain("lfd", Lfd.class, io, args);
}
}
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ picocliVersion=4.7.0
resourcesVersion=3.16.0
xtextVersion=2.28.0
klighdVersion=2.3.0.v20230606
freehepVersion=2.4
swtVersion=3.124.0

[manifestPropertyNames]
org.eclipse.xtext=xtextVersion
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
rootProject.name = 'org.lflang'
include('core', 'lsp', 'cli:base', 'cli:lfc', 'cli:lff')
include('core', 'lsp', 'cli:base', 'cli:lfc', 'cli:lff', 'cli:lfd')
2 changes: 1 addition & 1 deletion util/scripts/launch.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
$invokerPath = $MyInvocation.PSCommandPath
$invokerName = [System.IO.Path]::GetFileNameWithoutExtension("$(Split-Path -Path $invokerPath -Leaf -Resolve)")

$mainClassTable = @{"lfc" = "org.lflang.cli.Lfc"; "lff" = "org.lflang.cli.Lff"}
$mainClassTable = @{"lfc" = "org.lflang.cli.Lfc"; "lff" = "org.lflang.cli.Lff"; "lfd" = "org.lflang.cli.Lfd}
$tool = $null
foreach ($k in $mainClassTable.Keys) {
if ($invokerName.EndsWith($k)) {
Expand Down
4 changes: 3 additions & 1 deletion util/scripts/launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ if [[ "$0" == *lfc ]]; then
tool="lfc"
elif [[ "$0" == *lff ]]; then
tool="lff"
elif [[ "$0" == *lfd ]]; then
tool="lfd"
else
known_commands="[lfc, lff]"
known_commands="[lfc, lff, lfd]"
echo \
"ERROR: $0 is not a known lf command! Known commands are ${known_commands}.
In case you use a symbolic or hard link to one of the Lingua Franca
Expand Down

0 comments on commit 2f30d0a

Please sign in to comment.