Skip to content
Snippets Groups Projects
Commit 4678d014 authored by René Schöne's avatar René Schöne
Browse files

Allow svg/pdf/html, cleanup.

parent b98c0bae
No related branches found
No related tags found
No related merge requests found
Pipeline #13664 failed
......@@ -39,7 +39,6 @@ dependencies {
api group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11'
implementation group: 'com.github.spullara.mustache.java', name: 'compiler', version: '0.9.10'
// runtime group: 'org.jastadd', name: 'jastadd', version: '2.3.4'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.8.2'
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.8.2'
......@@ -184,13 +183,13 @@ task fatJar(type: Jar) {
archiveAppendix = "fatjar"
from sourceSets.main.output
from {
configurations.runtimeClasspath.collect {println it; it.isDirectory() ? it : zipTree(it) }
configurations.runtimeClasspath.collect {it.isDirectory() ? it : zipTree(it) }
}
manifest.attributes "Main-Class": "${mainClassName}"
}
def versionFile = 'src/main/resources/grammar2umlVersion.properties'
def versionFile = "src/main/resources/${project.getName()}Version.properties"
try {
def oldProps = new Properties()
......
......@@ -7,6 +7,9 @@ import de.tudresden.inf.st.jastadd.grammar2uml.ast.GrammarFile;
import de.tudresden.inf.st.jastadd.grammar2uml.ast.Program;
import de.tudresden.inf.st.jastadd.grammar2uml.parser.Grammar2UmlParser;
import de.tudresden.inf.st.jastadd.grammar2uml.scanner.Grammar2UmlScanner;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.FileUtils;
import net.sourceforge.plantuml.SourceStringReader;
import org.jastadd.option.BooleanOption;
import org.jastadd.option.ValueOption;
......@@ -26,25 +29,24 @@ public class Compiler extends AbstractCompiler {
private ValueOption optionOutputFile;
private ValueOption optionInputGrammar2Uml;
private BooleanOption optionDefaultFolders;
private BooleanOption optionPrintSource;
private BooleanOption optionHelp;
private BooleanOption optionVersion;
private BooleanOption optionVerbose;
public Compiler() {
super("grammar2uml", false);
super("grammar2uml" , false);
}
/**
* Reads the version string.
*
* <p>
* The version string is read from the property file
* src/main/resources/Version.properties. This
* file should be generated during the build process. If it is missing
* then there is some problem in the build script.
*
* @author Jesper Öqvist <jesper.oqvist@cs.lth.se>
* @return the read version string, or <code>version ?</code>
* @author Jesper Öqvist <jesper.oqvist@cs.lth.se>
*/
private String readVersion() {
try {
......@@ -55,7 +57,7 @@ public class Compiler extends AbstractCompiler {
}
public static void main(String[] args) {
System.setProperty("mustache.debug", "true");
System.setProperty("mustache.debug" , "true");
try {
new Compiler().run(args);
} catch (CompilerException e) {
......@@ -70,29 +72,26 @@ public class Compiler extends AbstractCompiler {
protected void initOptions() {
optionOutputFile = addOption(
new ValueOption("output", "target file to be generated.")
.defaultValue("uml.md")
new ValueOption("output" , "target file to be generated.")
.defaultValue("uml.png")
.acceptAnyValue()
.needsValue(false));
optionInputGrammar2Uml = addOption(
new ValueOption("inputGrammar2Uml", "grammar2uml definition file.")
new ValueOption("inputGrammar2Uml" , "grammar2uml definition file.")
.needsValue(true));
optionDefaultFolders = addOption(
new BooleanOption("defaultFolders",
new BooleanOption("defaultFolders" ,
"Creates a default folder per grammar file.")
.defaultValue(false));
optionPrintSource = addOption(
new BooleanOption("printSource", "The output will be the source code instead of a png.")
.defaultValue(false));
optionHelp = addOption(
new BooleanOption("help", "Print usage and exit.")
.defaultValue(false));
new BooleanOption("help" , "Print usage and exit.")
.defaultValue(false));
optionVersion = addOption(
new BooleanOption("version", "Print version and exit.")
.defaultValue(false));
new BooleanOption("version" , "Print version and exit.")
.defaultValue(false));
optionVerbose = addOption(
new BooleanOption("verbose", "Print more messages while compiling.")
.defaultValue(false));
new BooleanOption("verbose" , "Print more messages while compiling.")
.defaultValue(false));
}
private Grammar2Uml parseProgram() throws CompilerException {
......@@ -180,28 +179,43 @@ public class Compiler extends AbstractCompiler {
String sourceCode = grammar2uml.generateAspect();
try {
if (optionPrintSource.isMatched()) {
Files.writeString(destination, sourceCode);
} else {
//
String extension = fileExtensionOf(destination).toUpperCase();
FileFormatOption plantUmlOption = null;
switch (extension) {
case "MD":
try {
Files.writeString(destination, sourceCode);
} catch (Exception e) {
throw new CompilerException("Could not write to file " + destination, e);
}
break;
case "HTML":
case "PNG":
case "PDF":
case "SVG":
plantUmlOption = new FileFormatOption(FileFormat.valueOf(extension));
break;
}
if (plantUmlOption != null) {
try {
SourceStringReader reader = new SourceStringReader(sourceCode);
reader.outputImage(Files.newOutputStream(destination));
reader.outputImage(Files.newOutputStream(destination), plantUmlOption);
} catch (Exception e) {
throw new CompilerException("Could not write to file " + destination, e);
}
} catch (Exception e) {
throw new CompilerException("Could not write to file " + destination, e);
}
return 0;
}
private String fileExtensionOf(Path path) {
String fileName = path.toFile().getName();
int lastIndexOfDot = fileName.lastIndexOf(".");
return fileName.substring(lastIndexOfDot + 1);
}
private Path getDestinationPath() {
final String outputFileName;
if (optionOutputFile.isMatched()) {
outputFileName = optionOutputFile.value();
} else {
outputFileName = optionPrintSource.isMatched() ? "uml.md" : "uml.png";
System.out.println("No output output file is set. Assuming '" + outputFileName + "'.");
}
return Paths.get(outputFileName).toAbsolutePath();
return Paths.get(optionOutputFile.value()).toAbsolutePath();
}
}
#Tue Mar 22 10:45:01 CET 2022
version=0.2.3
#Sat May 21 15:41:29 CEST 2022
version=0.2.4
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment