Commit 6ff666c3 authored by Dennis Hendriks's avatar Dennis Hendriks
Browse files

Merge branch...

Merge branch '111-generate-railroad-diagrams-during-build-rather-than-committing-them-to-git-repo-4' into 'develop'

#111 Build railroad diagrams during the build

Closes #111

See merge request !311
parents 36a83bfd f75cd356
Pipeline #3998 passed with stage
in 0 seconds
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
......
......@@ -56,6 +56,11 @@
<version>3.6.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.escet</groupId>
<artifactId>org.eclipse.escet.common.raildiagrams</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
......
//////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2022 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available
// under the terms of the MIT License which is available at
// https://opensource.org/licenses/MIT
//
// SPDX-License-Identifier: MIT
//////////////////////////////////////////////////////////////////////////////
package org.eclipse.escet.common.asciidoc.generate.raildiagrams;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Locale;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.eclipse.escet.common.raildiagrams.OutputFormat;
import org.eclipse.escet.common.raildiagrams.RailRoadDiagramGenerator;
/**
* Railroad diagram generator Maven mojo.
*
* @see RailRoadDiagramGenerator
*/
@Mojo(name = "generate-railroad-diagrams")
public class RailRoadDiagramGeneratorMojo extends AbstractMojo {
/** The path to the root directory that contains the railroad diagram specification files. */
@Parameter(required = true)
private File rootPath;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
Log log = getLog();
// Search for AsciiDoc files.
List<Path> inputPaths;
try {
Predicate<Path> isRailRoadFile = p -> p.getFileName().toString().toLowerCase(Locale.US).endsWith(".rr");
inputPaths = Files.walk(rootPath.toPath()).filter(Files::isRegularFile).filter(isRailRoadFile)
.collect(Collectors.toList());
} catch (IOException e) {
log.error(e);
throw new MojoExecutionException("Failed to search for railroad diagram specification files.", e);
}
// Generate images for the railroad diagram specifications.
log.info(String.format(Locale.US, "Generating %d railroad diagram image(s).", inputPaths.size()));
for (Path inputPath: inputPaths) {
// Derive paths.
Path configPath = inputPath.resolveSibling(inputPath.getFileName().toString() + ".props");
if (!Files.isRegularFile(configPath)) {
configPath = null;
}
Path outputPath = inputPath.resolveSibling(inputPath.getFileName().toString() + ".png");
// Generate image.
try {
RailRoadDiagramGenerator.generate(inputPath, configPath, outputPath, OutputFormat.IMAGES,
log.isDebugEnabled() ? log::debug : null, log::warn);
} catch (Throwable e) {
log.error(e);
throw new MojoExecutionException("Error while executing Maven plugin.", e);
}
}
}
}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/org.eclipse.escet.common.asciidoc"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=org.eclipse.escet.common.asciidoc"/>
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_CLASSPATH_ONLY_JAR" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.escet.common.asciidoc"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea"/>
</launchConfiguration>
......@@ -8,14 +8,12 @@ Bundle-RequiredExecutionEnvironment: JavaSE-11
Bundle-ActivationPolicy: lazy
Bundle-Vendor: Eclipse ESCET
Require-Bundle: org.eclipse.escet.common.java;bundle-version="0.6.0",
org.eclipse.escet.common.app.framework;bundle-version="0.6.0",
org.eclipse.escet.setext.runtime;bundle-version="0.6.0",
org.eclipse.jface.text;bundle-version="3.17.0",
org.eclipse.core.resources;bundle-version="3.14.0",
org.eclipse.escet.common.eclipse.ui;bundle-version="0.6.0"
org.eclipse.jface.text;bundle-version="3.17.0"
Export-Package: org.eclipse.escet.common.raildiagrams,
org.eclipse.escet.common.raildiagrams.config,
org.eclipse.escet.common.raildiagrams.graphics,
org.eclipse.escet.common.raildiagrams.output,
org.eclipse.escet.common.raildiagrams.parser,
org.eclipse.escet.common.raildiagrams.railroad,
org.eclipse.escet.common.raildiagrams.solver,
......
......@@ -14,7 +14,4 @@ source.. = src/,\
src-gen/
output.. = target/classes/
bin.includes = META-INF/,\
.,\
plugin.xml,\
icons/
src.includes = icons/
.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File: rail_diagram_generator.png
Source: https://www.iconfinder.com/icons/211751/gear_icon
License: MIT
Adapted: no
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<!--
Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation
See the NOTICE file(s) distributed with this work for additional
information regarding copyright ownership.
This program and the accompanying materials are made available under the terms
of the MIT License which is available at https://opensource.org/licenses/MIT
SPDX-License-Identifier: MIT
-->
<plugin>
<extension point="org.eclipse.ui.commands">
<category
id="org.eclipse.escet.common.commands.category"
name="Eclipse ESCET common commands">
</category>
<command
categoryId="org.eclipse.escet.common.commands.category"
defaultHandler="org.eclipse.escet.common.raildiagrams.RailRoadDiagramCommandHandler"
id="org.eclipse.escet.common.raildiagrams.RailRoadDiagramCommand"
name="Generate diagram(s)">
</command>
</extension>
<extension point="org.eclipse.core.expressions.definitions">
<definition id="org.eclipse.escet.common.raildiagrams.singleFile">
<and>
<iterate>
<adapt type="org.eclipse.core.resources.IFile">
<test property="org.eclipse.core.resources.name"
value="*.rr"/>
</adapt>
</iterate>
<count value="1"/>
</and>
</definition>
<definition id="org.eclipse.escet.common.raildiagrams.multipleFiles">
<and>
<iterate>
<adapt type="org.eclipse.core.resources.IFile">
<test property="org.eclipse.core.resources.name"
value="*.rr"/>
</adapt>
</iterate>
<count value="+"/> <!-- One or more files. -->
</and>
</definition>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:org.eclipse.ui.popup.any">
<command
commandId="org.eclipse.escet.common.raildiagrams.RailRoadDiagramCommand"
icon="icons/rail_diagram_generator.png"
label="&amp;Generate diagram(s)...">
<visibleWhen>
<or>
<with variable="activeMenuSelection">
<reference definitionId="org.eclipse.escet.common.raildiagrams.multipleFiles"/>
</with>
<with variable="activeMenuEditorInput">
<reference definitionId="org.eclipse.escet.common.raildiagrams.singleFile"/>
</with>
</or>
</visibleWhen>
</command>
</menuContribution>
</extension>
</plugin>
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation
See the NOTICE file(s) distributed with this work for additional
information regarding copyright ownership.
This program and the accompanying materials are made available under the terms
of the MIT License which is available at https://opensource.org/licenses/MIT
SPDX-License-Identifier: MIT
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.escet</groupId>
<artifactId>org.eclipse.escet.root</artifactId>
<version>0.6.0-SNAPSHOT</version>
<relativePath>../../</relativePath>
</parent>
<artifactId>org.eclipse.escet.common.raildiagrams</artifactId>
<packaging>eclipse-plugin</packaging>
</project>
......@@ -22,6 +22,9 @@ import static org.junit.Assert.assertEquals;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.function.Consumer;
import org.eclipse.escet.common.raildiagrams.config.Configuration;
import org.eclipse.escet.common.raildiagrams.graphics.Arc;
......@@ -40,6 +43,9 @@ public class DebugImageOutputTest {
/** If not {@code null} the directory to dump arc test images for manual inspection. */
private final String testDumpDir = null;
/** The debug logger to use. */
private final Consumer<String> debugLogger = null;
/** Output generator instance for testing. */
private ImageOutput output;
......@@ -72,9 +78,9 @@ public class DebugImageOutputTest {
@Test
@SuppressWarnings("javadoc")
public void testEmptyHorLine() {
public void testEmptyHorLine() throws IOException {
final int lineWidth = 1;
Configuration config = new Configuration(output);
Configuration config = new Configuration(output, debugLogger);
output.prepareOutputFile(64, 32, Color.WHITE);
HorLine hLine = new HorLine(solver, "prefix", Color.BLACK, lineWidth);
......@@ -84,7 +90,7 @@ public class DebugImageOutputTest {
BufferedImage result = output.getOutput();
if (testDumpDir != null) {
String fname = fmt("%s%stestHLineimg0_%d.png", testDumpDir, File.separator, lineWidth);
output.writeOutputFile(fname);
output.writeOutputFile(Paths.get(fname));
}
assertEquals(convertRGB(CONNECT_POINT), convertRGB(result.getRGB(2, 5)));
......@@ -93,9 +99,9 @@ public class DebugImageOutputTest {
@Test
@SuppressWarnings("javadoc")
public void testHorLineOneDistance() {
public void testHorLineOneDistance() throws IOException {
final int lineWidth = 1;
Configuration config = new Configuration(output);
Configuration config = new Configuration(output, debugLogger);
output.prepareOutputFile(64, 32, Color.WHITE);
HorLine hLine = new HorLine(solver, "prefix", Color.BLACK, lineWidth);
......@@ -106,7 +112,7 @@ public class DebugImageOutputTest {
BufferedImage result = output.getOutput();
if (testDumpDir != null) {
String fname = fmt("%s%stestHLineimg1_%d.png", testDumpDir, File.separator, lineWidth);
output.writeOutputFile(fname);
output.writeOutputFile(Paths.get(fname));
}
assertEquals(convertRGB(CONNECT_POINT), convertRGB(result.getRGB(2, 5)));
......@@ -116,9 +122,9 @@ public class DebugImageOutputTest {
@Test
@SuppressWarnings("javadoc")
public void testHorLineTwoDistance() {
public void testHorLineTwoDistance() throws IOException {
final int lineWidth = 1;
Configuration config = new Configuration(output);
Configuration config = new Configuration(output, debugLogger);
output.prepareOutputFile(64, 32, Color.WHITE);
HorLine hLine = new HorLine(solver, "prefix", Color.BLACK, lineWidth);
......@@ -129,7 +135,7 @@ public class DebugImageOutputTest {
BufferedImage result = output.getOutput();
if (testDumpDir != null) {
String fname = fmt("%s%stestHLineimg2_%d.png", testDumpDir, File.separator, lineWidth);
output.writeOutputFile(fname);
output.writeOutputFile(Paths.get(fname));
}
assertEquals(convertRGB(CONNECT_POINT), convertRGB(result.getRGB(2, 5)));
......@@ -140,9 +146,9 @@ public class DebugImageOutputTest {
@Test
@SuppressWarnings("javadoc")
public void testEmptyVertLine() {
public void testEmptyVertLine() throws IOException {
final int lineWidth = 1;
Configuration config = new Configuration(output);
Configuration config = new Configuration(output, debugLogger);
output.prepareOutputFile(64, 32, Color.WHITE);
VertLine vLine = new VertLine(solver, "prefix", Color.BLACK, lineWidth);
......@@ -152,7 +158,7 @@ public class DebugImageOutputTest {
BufferedImage result = output.getOutput();
if (testDumpDir != null) {
String fname = fmt("%s%stestVLineimg0_%d.png", testDumpDir, File.separator, lineWidth);
output.writeOutputFile(fname);
output.writeOutputFile(Paths.get(fname));
}
assertEquals(convertRGB(CONNECT_POINT), convertRGB(result.getRGB(3, 4)));
......@@ -161,9 +167,9 @@ public class DebugImageOutputTest {
@Test
@SuppressWarnings("javadoc")
public void testVertLineOneDistance() {
public void testVertLineOneDistance() throws IOException {
final int lineWidth = 1;
Configuration config = new Configuration(output);
Configuration config = new Configuration(output, debugLogger);
output.prepareOutputFile(64, 32, Color.WHITE);
VertLine vLine = new VertLine(solver, "prefix", Color.BLACK, lineWidth);
......@@ -174,7 +180,7 @@ public class DebugImageOutputTest {
BufferedImage result = output.getOutput();
if (testDumpDir != null) {
String fname = fmt("%s%stestVLineimg1_%d.png", testDumpDir, File.separator, lineWidth);
output.writeOutputFile(fname);
output.writeOutputFile(Paths.get(fname));
}
assertEquals(convertRGB(CONNECT_POINT), convertRGB(result.getRGB(3, 4)));
......@@ -184,9 +190,9 @@ public class DebugImageOutputTest {
@Test
@SuppressWarnings("javadoc")
public void testVertLineTwoDistance() {
public void testVertLineTwoDistance() throws IOException {
final int lineWidth = 1;
Configuration config = new Configuration(output);
Configuration config = new Configuration(output, debugLogger);
output.prepareOutputFile(64, 32, Color.WHITE);
VertLine vLine = new VertLine(solver, "prefix", Color.BLACK, lineWidth);
......@@ -197,7 +203,7 @@ public class DebugImageOutputTest {
BufferedImage result = output.getOutput();
if (testDumpDir != null) {
String fname = fmt("%s%stestVLineimg2_%d.png", testDumpDir, File.separator, lineWidth);
output.writeOutputFile(fname);
output.writeOutputFile(Paths.get(fname));
}
assertEquals(convertRGB(CONNECT_POINT), convertRGB(result.getRGB(3, 4)));
......@@ -208,25 +214,25 @@ public class DebugImageOutputTest {
@Test
@SuppressWarnings("javadoc")
public void testBottomRightArc11w1() {
public void testBottomRightArc11w1() throws IOException {
tryBottomRightArc(11, 1);
}
@Test
@SuppressWarnings("javadoc")
public void testBottomRightArc10w2() {
public void testBottomRightArc10w2() throws IOException {
tryBottomRightArc(10, 2);
}
@Test
@SuppressWarnings("javadoc")
public void testBottomRightArc14w3() {
public void testBottomRightArc14w3() throws IOException {
tryBottomRightArc(14, 3);
}
@Test
@SuppressWarnings("javadoc")
public void testBottomRightArc15w4() {
public void testBottomRightArc15w4() throws IOException {
tryBottomRightArc(15, 4);
}
......@@ -235,9 +241,10 @@ public class DebugImageOutputTest {
*
* @param size Size of the arc.
* @param lineWidth Width of the line.
* @throws IOException In case of an I/O error.
*/
private void tryBottomRightArc(int size, int lineWidth) {
Configuration config = new Configuration(output);
private void tryBottomRightArc(int size, int lineWidth) throws IOException {
Configuration config = new Configuration(output, debugLogger);
output.prepareOutputFile(64, 32, Color.WHITE);
final int xpos = 3;
......@@ -255,7 +262,7 @@ public class DebugImageOutputTest {
BufferedImage result = output.getOutput();
if (testDumpDir != null) {
String fname = fmt("%s%stestBRimg_%d_%d.png", testDumpDir, File.separator, size, lineWidth);
output.writeOutputFile(fname);
output.writeOutputFile(Paths.get(fname));
}
for (int i = 0; i < lineWidth; i++) {
......@@ -268,25 +275,25 @@ public class DebugImageOutputTest {
@Test
@SuppressWarnings("javadoc")
public void testTopLeftArc11w1() {
public void testTopLeftArc11w1() throws IOException {
tryTopLeftArc(11, 1);
}
@Test
@SuppressWarnings("javadoc")
public void testTopLeftArc10w2() {
public void testTopLeftArc10w2() throws IOException {
tryTopLeftArc(10, 2);
}
@Test
@SuppressWarnings("javadoc")
public void testTopLeftArc14w3() {
public void testTopLeftArc14w3() throws IOException {
tryTopLeftArc(14, 3);
}
@Test
@SuppressWarnings("javadoc")
public void testTopLeftArc15w4() {
public void testTopLeftArc15w4() throws IOException {
tryTopLeftArc(15, 4);
}
......@@ -295,9 +302,10 @@ public class DebugImageOutputTest {
*
* @param size Size of the arc.
* @param lineWidth Width of the line.
* @throws IOException In case of an I/O error.
*/
private void tryTopLeftArc(int size, int lineWidth) {
Configuration config = new Configuration(output);
private void tryTopLeftArc(int size, int lineWidth) throws IOException {
Configuration config = new Configuration(output, debugLogger);
output.prepareOutputFile(64, 32, Color.WHITE);
final int xpos = 3;
......@@ -315,7 +323,7 @@ public class DebugImageOutputTest {
BufferedImage result = output.getOutput();
if (testDumpDir != null) {
String fname = fmt("%s%stestTLimg_%d_%d.png", testDumpDir, File.separator, size, lineWidth);
output.writeOutputFile(fname);
output.writeOutputFile(Paths.get(fname));
}
for (int i = 0; i < lineWidth; i++) {
......@@ -328,25 +336,25 @@ public class DebugImageOutputTest {
@Test
@SuppressWarnings("javadoc")
public void testBottomLeftArc11w1() {
public void testBottomLeftArc11w1() throws IOException {
tryBottomLeftArc(11, 1);
}
@Test
@SuppressWarnings("javadoc")
public void testBottomLeftArc10w2() {
public void testBottomLeftArc10w2() throws IOException {
tryBottomLeftArc(10, 2);
}
@Test
@SuppressWarnings("javadoc")
public void testBottomLeftArc14w3() {
public void testBottomLeftArc14w3() throws IOException {
tryBottomLeftArc(14, 3);
}
@Test
@SuppressWarnings("javadoc")
public void testBottomLeftArc15w4() {
public void testBottomLeftArc15w4() throws IOException {
tryBottomLeftArc(15, 4);
}
......@@ -355,9 +363,10 @@ public class DebugImageOutputTest {
*
* @param size Size of the arc.
* @param lineWidth Width of the line.
* @throws IOException In case of an I/O error.
*/
private void tryBottomLeftArc(int size, int lineWidth) {
Configuration config = new Configuration(output);
private void tryBottomLeftArc(int size, int lineWidth) throws IOException {
Configuration config = new Configuration(output, debugLogger);
output.prepareOutputFile(64, 32, Color.WHITE);
final int xpos = 3;
......@@ -375,7 +384,7 @@ public class DebugImageOutputTest {
BufferedImage result = output.getOutput();
if (testDumpDir != null) {
String fname = fmt("%s%stestBLimg_%d_%d.png", testDumpDir, File.separator, size, lineWidth);