Merge remote-tracking branch 'origin/jetty-10.0.x' into jetty-11.0.x

This commit is contained in:
Joakim Erdfelt 2022-03-02 06:09:55 -06:00
commit ea7a934050
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
2 changed files with 61 additions and 9 deletions

View File

@ -29,6 +29,8 @@ public class ModuleGraphWriter
{
private String colorModuleBg;
private String colorEnabledBg;
private String colorEdgeBefore;
private String colorEdgeAfter;
private String colorTransitiveBg;
private String colorCellBg;
private String colorHeaderBg;
@ -38,6 +40,8 @@ public class ModuleGraphWriter
{
colorModuleBg = "#B8FFB8";
colorEnabledBg = "#66FFCC";
colorEdgeAfter = "#00CC33";
colorEdgeAfter = "#33CC00";
colorTransitiveBg = "#66CC66";
colorCellBg = "#FFFFFF80";
colorHeaderBg = "#00000020";
@ -49,6 +53,8 @@ public class ModuleGraphWriter
String prefix = "jetty.graph.";
colorModuleBg = getProperty(props, prefix + "color.module.bg", colorModuleBg);
colorEnabledBg = getProperty(props, prefix + "color.enabled.bg", colorEnabledBg);
colorEdgeBefore = getProperty(props, prefix + "color.edge.before", colorEdgeBefore);
colorEdgeAfter = getProperty(props, prefix + "color.edge.after", colorEdgeAfter);
colorTransitiveBg = getProperty(props, prefix + "color.transitive.bg", colorTransitiveBg);
colorCellBg = getProperty(props, prefix + "color.cell.bg", colorCellBg);
colorHeaderBg = getProperty(props, prefix + "color.header.bg", colorHeaderBg);
@ -73,7 +79,7 @@ public class ModuleGraphWriter
public void write(Modules modules, Path outputFile) throws IOException
{
try (BufferedWriter writer = Files.newBufferedWriter(outputFile, StandardCharsets.UTF_8, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE);
PrintWriter out = new PrintWriter(writer);)
PrintWriter out = new PrintWriter(writer))
{
writeHeaderMessage(out, outputFile);
@ -245,13 +251,13 @@ public class ModuleGraphWriter
depends = Module.normalizeModuleName(depends);
out.printf(" \"%s\" -> \"%s\";%n", module.getName(), depends);
}
for (String optional : module.getAfter())
{
out.printf(" \"%s\" -> \"%s\" [ color=\"%s\" ];%n", module.getName(), optional, colorEdgeAfter);
}
for (String before : module.getBefore())
{
out.printf(" \"%s\" << \"%s\";%n", module.getName(), before);
}
for (String after : module.getAfter())
{
out.printf(" \"%s\" >> \"%s\";%n", module.getName(), after);
out.printf(" \"%s\" -> \"%s\" [ color=\"%s\" ];%n", before, module.getName(), colorEdgeBefore);
}
}
}

View File

@ -13,8 +13,12 @@
package org.eclipse.jetty.start;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.time.Duration;
import org.eclipse.jetty.start.config.CommandLineConfigSource;
import org.eclipse.jetty.start.config.ConfigSources;
@ -28,6 +32,8 @@ import org.junit.jupiter.api.extension.ExtendWith;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertTimeout;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(WorkDirExtension.class)
public class ModuleGraphWriterTest
@ -58,11 +64,51 @@ public class ModuleGraphWriterTest
Modules modules = new Modules(basehome, args);
modules.registerAll();
Path outputFile = basehome.getBasePath("graph.dot");
Path dotFile = basehome.getBasePath("graph.dot");
ModuleGraphWriter writer = new ModuleGraphWriter();
writer.write(modules, outputFile);
writer.write(modules, dotFile);
assertThat("Output File Exists", FS.exists(outputFile), is(true));
assertThat("Output File Exists", FS.exists(dotFile), is(true));
assertTimeout(Duration.ofSeconds(3), () ->
{
if (execDotCmd("dot", "-V"))
{
Path outputPng = testdir.getPath().resolve("output.png");
assertTrue(execDotCmd("dot", "-Tpng", "-o" + outputPng, dotFile.toString()));
assertThat("PNG File does not exist", FS.exists(outputPng));
}
});
}
private boolean execDotCmd(String... args)
{
try
{
Process p = Runtime.getRuntime().exec(args);
try (BufferedReader bri = new BufferedReader(new InputStreamReader(p.getInputStream(), StandardCharsets.UTF_8));
BufferedReader bre = new BufferedReader(new InputStreamReader(p.getErrorStream(), StandardCharsets.UTF_8)))
{
String line;
while ((line = bri.readLine()) != null)
{
System.out.printf("[STDIN] %s%n", line);
}
while ((line = bre.readLine()) != null)
{
System.out.printf("[STDERR] %s%n", line);
}
}
p.waitFor();
return true;
}
catch (IOException | InterruptedException e)
{
e.printStackTrace();
return false;
}
}
}