Skip to content

Commit

Permalink
Issue #7064 - Fix (null) for source output in --list-config (#7065)
Browse files Browse the repository at this point in the history
Improved start handling of output so that testcases
can now validate the output if they need to.

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
  • Loading branch information
joakime authored Nov 16, 2021
1 parent 6bfab6e commit edaead4
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 123 deletions.
57 changes: 29 additions & 28 deletions jetty-start/src/main/java/org/eclipse/jetty/start/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.ConnectException;
Expand Down Expand Up @@ -137,26 +138,26 @@ public void run()
}).start();
}

private void dumpClasspathWithVersions(Classpath classpath)
private void dumpClasspathWithVersions(PrintStream out, Classpath classpath)
{
StartLog.endStartLog();
System.out.println();
System.out.println("Jetty Server Classpath:");
System.out.println("-----------------------");
out.println();
out.println("Jetty Server Classpath:");
out.println("-----------------------");
if (classpath.count() == 0)
{
System.out.println("No classpath entries and/or version information available show.");
out.println("No classpath entries and/or version information available show.");
return;
}

System.out.println("Version Information on " + classpath.count() + " entr" + ((classpath.count() > 1) ? "ies" : "y") + " in the classpath.");
System.out.println("Note: order presented here is how they would appear on the classpath.");
System.out.println(" changes to the --module=name command line options will be reflected here.");
out.println("Version Information on " + classpath.count() + " entr" + ((classpath.count() > 1) ? "ies" : "y") + " in the classpath.");
out.println("Note: order presented here is how they would appear on the classpath.");
out.println(" changes to the --module=name command line options will be reflected here.");

int i = 0;
for (File element : classpath.getElements())
{
System.out.printf("%2d: %24s | %s\n", i++, getVersion(element), baseHome.toShortForm(element));
out.printf("%2d: %24s | %s\n", i++, getVersion(element), baseHome.toShortForm(element));
}
}

Expand Down Expand Up @@ -227,51 +228,51 @@ public void invokeMain(ClassLoader classloader, StartArgs args) throws IllegalAc
main.invoke(null, methodParams);
}

public void listConfig(StartArgs args)
public void listConfig(PrintStream out, StartArgs args)
{
StartLog.endStartLog();
Modules modules = args.getAllModules();

// Dump Enabled Modules
modules.listEnabled();
modules.listEnabled(out);

// Dump Jetty Home / Base
args.dumpEnvironment();
args.dumpEnvironment(out);

// Dump JVM Args
args.dumpJvmArgs();
args.dumpJvmArgs(out);

// Dump System Properties
args.dumpSystemProperties();
args.dumpSystemProperties(out);

// Dump Properties
args.dumpProperties();
args.dumpProperties(out);

// Dump Classpath
dumpClasspathWithVersions(args.getClasspath());
dumpClasspathWithVersions(out, args.getClasspath());

// Dump Resolved XMLs
args.dumpActiveXmls();
args.dumpActiveXmls(out);
}

public void listModules(StartArgs args)
public void listModules(PrintStream out, StartArgs args)
{
final List<String> tags = args.getListModules();
StartLog.endStartLog();
String t = tags.toString();
System.out.printf("%nModules %s:%n", t);
System.out.printf("=========%s%n", "=".repeat(t.length()));
args.getAllModules().listModules(tags);
out.printf("%nModules %s:%n", t);
out.printf("=========%s%n", "=".repeat(t.length()));
args.getAllModules().listModules(out, tags);

// for default module listings, also show enabled modules
if ("[-internal]".equals(t) || "[*]".equals(t))
args.getAllModules().listEnabled();
args.getAllModules().listEnabled(out);
}

public void showModules(StartArgs args)
public void showModules(PrintStream out, StartArgs args)
{
StartLog.endStartLog();
args.getAllModules().showModules(args.getShowModules());
args.getAllModules().showModules(out, args.getShowModules());
}

/**
Expand Down Expand Up @@ -393,25 +394,25 @@ public void start(StartArgs args) throws IOException, InterruptedException
// Show the version information and return
if (args.isListClasspath())
{
dumpClasspathWithVersions(classpath);
dumpClasspathWithVersions(System.out, classpath);
}

// Show configuration
if (args.isListConfig())
{
listConfig(args);
listConfig(System.out, args);
}

// List modules
if (args.getListModules() != null)
{
listModules(args);
listModules(System.out, args);
}

// Show modules
if (args.getShowModules() != null)
{
showModules(args);
showModules(System.out, args);
}

// Generate Module Graph File
Expand Down
55 changes: 28 additions & 27 deletions jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand Down Expand Up @@ -78,7 +79,7 @@ public Modules(BaseHome basehome, StartArgs args)
}
}

public void showModules(List<String> modules)
public void showModules(PrintStream out, List<String> modules)
{
Stream<Module> stream = (modules.contains("*") || modules.isEmpty())
? _modules.stream().sorted()
Expand All @@ -92,81 +93,81 @@ public void showModules(List<String> modules)
String label;
Set<String> provides = module.getProvides();
provides.remove(module.getName());
System.out.printf("%n Module: %s %s%n", module.getName(), provides.size() > 0 ? provides : "");
out.printf("%n Module: %s %s%n", module.getName(), provides.size() > 0 ? provides : "");
for (String description : module.getDescription())
{
System.out.printf(" : %s%n", description);
out.printf(" : %s%n", description);
}
if (!module.getTags().isEmpty())
{
label = " Tags: %s";
for (String t : module.getTags())
{
System.out.printf(label, t);
out.printf(label, t);
label = ", %s";
}
System.out.println();
out.println();
}
if (!module.getDepends().isEmpty())
{
label = " Depend: %s";
for (String parent : module.getDepends())
{
parent = Module.normalizeModuleName(parent);
System.out.printf(label, parent);
out.printf(label, parent);
if (Module.isConditionalDependency(parent))
System.out.print(" [conditional]");
out.print(" [conditional]");
label = ", %s";
}
System.out.println();
out.println();
}
if (!module.getBefore().isEmpty())
{
label = " Before: %s";
for (String before : module.getBefore())
{
System.out.printf(label, before);
out.printf(label, before);
label = ", %s";
}
System.out.println();
out.println();
}
if (!module.getAfter().isEmpty())
{
label = " After: %s";
for (String after : module.getAfter())
{
System.out.printf(label, after);
out.printf(label, after);
label = ", %s";
}
System.out.println();
out.println();
}
for (String lib : module.getLibs())
{
System.out.printf(" LIB: %s%n", lib);
out.printf(" LIB: %s%n", lib);
}
for (String xml : module.getXmls())
{
System.out.printf(" XML: %s%n", xml);
out.printf(" XML: %s%n", xml);
}
for (String jpms : module.getJPMS())
{
System.out.printf(" JPMS: %s%n", jpms);
out.printf(" JPMS: %s%n", jpms);
}
for (String jvm : module.getJvmArgs())
{
System.out.printf(" JVM: %s%n", jvm);
out.printf(" JVM: %s%n", jvm);
}
if (module.isEnabled())
{
for (String selection : module.getEnableSources())
{
System.out.printf(" Enabled: %s%n", selection);
out.printf(" Enabled: %s%n", selection);
}
}
});
}

public void listModules(List<String> tags)
public void listModules(PrintStream out, List<String> tags)
{
if (tags.contains("-*"))
return;
Expand Down Expand Up @@ -199,20 +200,20 @@ public void listModules(List<String> tags)
if (!wild && !module.getPrimaryTag().equals(tag.get()))
{
tag.set(module.getPrimaryTag());
System.out.printf("%n%s modules:", module.getPrimaryTag());
System.out.printf("%n%s---------%n", "-".repeat(module.getPrimaryTag().length()));
out.printf("%n%s modules:", module.getPrimaryTag());
out.printf("%n%s---------%n", "-".repeat(module.getPrimaryTag().length()));
}

List<String> description = module.getDescription();
System.out.printf(format, module.getName(), description != null && description.size() > 0 ? description.get(0) : "");
out.printf(format, module.getName(), description != null && description.size() > 0 ? description.get(0) : "");
});
}

public void listEnabled()
public void listEnabled(PrintStream out)
{
System.out.println();
System.out.println("Enabled Modules:");
System.out.println("----------------");
out.println();
out.println("Enabled Modules:");
out.println("----------------");

int i = 0;
List<Module> enabled = getEnabled();
Expand All @@ -222,12 +223,12 @@ public void listEnabled()
String index = (i++) + ")";
for (String s : module.getEnableSources())
{
System.out.printf(" %4s %-15s %s%n", index, name, s);
out.printf(" %4s %-15s %s%n", index, name, s);
index = "";
name = "";
}
if (module.isTransitive() && module.hasIniTemplate())
System.out.printf(" init template available with --add-module=%s%n", module.getName());
out.printf(" init template available with --add-module=%s%n", module.getName());
}
}

Expand Down
Loading

0 comments on commit edaead4

Please sign in to comment.