diff --git a/bin/lfd b/bin/lfd new file mode 120000 index 0000000000..1a3eb8bc0d --- /dev/null +++ b/bin/lfd @@ -0,0 +1 @@ +../util/scripts/launch.sh \ No newline at end of file diff --git a/bin/lfd.ps1 b/bin/lfd.ps1 new file mode 100644 index 0000000000..54ce9397f4 --- /dev/null +++ b/bin/lfd.ps1 @@ -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 diff --git a/buildSrc/src/main/groovy/org.lflang.java-conventions.gradle b/buildSrc/src/main/groovy/org.lflang.java-conventions.gradle index 4cbea8bf20..c3d06302b7 100644 --- a/buildSrc/src/main/groovy/org.lflang.java-conventions.gradle +++ b/buildSrc/src/main/groovy/org.lflang.java-conventions.gradle @@ -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}") + } + } + } +} diff --git a/cli/lfd/build.gradle b/cli/lfd/build.gradle new file mode 100644 index 0000000000..34274d68eb --- /dev/null +++ b/cli/lfd/build.gradle @@ -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() +} diff --git a/cli/lfd/src/main/java/org/lflang/cli/Lfd.java b/cli/lfd/src/main/java/org/lflang/cli/Lfd.java new file mode 100644 index 0000000000..8377381b34 --- /dev/null +++ b/cli/lfd/src/main/java/org/lflang/cli/Lfd.java @@ -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); + } +} diff --git a/gradle.properties b/gradle.properties index e294dedf05..2164bf48ef 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/settings.gradle b/settings.gradle index b7b8588ae0..27a7c330bd 100644 --- a/settings.gradle +++ b/settings.gradle @@ -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') diff --git a/util/scripts/launch.ps1 b/util/scripts/launch.ps1 index be874fd26a..b81b818933 100644 --- a/util/scripts/launch.ps1 +++ b/util/scripts/launch.ps1 @@ -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)) { diff --git a/util/scripts/launch.sh b/util/scripts/launch.sh index f1e685f288..36a342bd25 100755 --- a/util/scripts/launch.sh +++ b/util/scripts/launch.sh @@ -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