Start environments
Generate XMLs in start.jar to communicate environments
This commit is contained in:
parent
428a9d568f
commit
0681210518
|
@ -13,9 +13,12 @@
|
|||
|
||||
package org.eclipse.jetty.start;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
|
@ -79,6 +82,9 @@ public class Environment
|
|||
|
||||
public void addUniquePropertyFile(String propertyFileRef, Path propertyFile) throws IOException
|
||||
{
|
||||
if (!"core".equalsIgnoreCase(getName()))
|
||||
throw new IllegalStateException("Property files not supported in non core environments");
|
||||
|
||||
if (!FS.canReadFile(propertyFile))
|
||||
{
|
||||
throw new IOException("Cannot read file: " + propertyFileRef);
|
||||
|
@ -287,6 +293,67 @@ public class Environment
|
|||
return _propertyFiles;
|
||||
}
|
||||
|
||||
public void generateXml(Environment coreEnvironment, Path envPath) throws IOException
|
||||
{
|
||||
try (OutputStream out = Files.newOutputStream(envPath))
|
||||
{
|
||||
String todo = """
|
||||
<Put name="propertyA">valueA</Put>
|
||||
<Item>lib/feature/foo.jar</Item>
|
||||
<Item>etc/foo.xml</Item>
|
||||
""";
|
||||
|
||||
StringBuilder properties = new StringBuilder();
|
||||
for (Props.Prop prop: coreEnvironment.getProperties())
|
||||
properties.append(" <Put name=\"").append(prop.key).append("\">").append(prop.value).append("</Put>\n");
|
||||
properties.append(" <!-- Environment properties -->\n");
|
||||
for (Props.Prop prop: getProperties())
|
||||
properties.append(" <Put name=\"").append(prop.key).append("\">").append(prop.value).append("</Put>\n");
|
||||
|
||||
StringBuilder classpaths = new StringBuilder();
|
||||
for (File classpath : getClasspath().getElements())
|
||||
classpaths.append(" <Item>").append(classpath.getAbsolutePath()).append("</Item>\n");
|
||||
|
||||
StringBuilder xmls = new StringBuilder();
|
||||
for (Path xml : getXmlFiles())
|
||||
xmls.append(" <Item>").append(xml.toAbsolutePath()).append("</Item>\n");
|
||||
|
||||
out.write("""
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10.dtd">
|
||||
<Configure id="Server" class="org.eclipse.jetty.server.Server">
|
||||
<New class="org.eclipse.jetty.xml.EnvironmentBuilder">
|
||||
<Arg name="name">%s</Arg>
|
||||
<Call name="putId">
|
||||
<Arg>Server</Arg>
|
||||
<Arg><Ref id="Server"/></Arg>
|
||||
</Call>
|
||||
|
||||
<!-- Core Properties -->
|
||||
%s
|
||||
<Call name="addClassPath">
|
||||
<Arg>
|
||||
<Array type="String">
|
||||
%s </Array>
|
||||
</Arg>
|
||||
</Call>
|
||||
|
||||
<Call name="addXml">
|
||||
<Arg>
|
||||
<Array type="String">
|
||||
%s </Array>
|
||||
</Arg>
|
||||
</Call>
|
||||
<Call id="%s" name="build"/>
|
||||
</New>
|
||||
<Call name="addEnvironment">
|
||||
<Arg><Ref id="%s"/></Arg>
|
||||
</Call>
|
||||
</Configure>
|
||||
""".formatted(getName(), properties, classpaths, xmls, getName(), getName()).getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
|
|
@ -51,7 +51,7 @@ import org.eclipse.jetty.util.ManifestUtils;
|
|||
public class StartArgs
|
||||
{
|
||||
public static final String VERSION;
|
||||
public static final Set<String> ALL_PARTS = Set.of("java", "opts", "path", "main", "args");
|
||||
public static final Set<String> ALL_PARTS = Set.of("java", "opts", "path", "main", "args", "envs");
|
||||
public static final Set<String> ARG_PARTS = Set.of("args");
|
||||
|
||||
private static final String JETTY_VERSION_KEY = "jetty.version";
|
||||
|
@ -483,7 +483,6 @@ public class StartArgs
|
|||
parts = ALL_PARTS;
|
||||
|
||||
CommandLineBuilder cmd = new CommandLineBuilder();
|
||||
Environment environment = getCoreEnvironment();
|
||||
|
||||
// Special Stop/Shutdown properties
|
||||
ensureSystemPropertySet("STOP.PORT");
|
||||
|
@ -508,11 +507,11 @@ public class StartArgs
|
|||
String value = assign.length == 1 ? "" : assign[1];
|
||||
|
||||
Prop p = processSystemProperty(key, value, null);
|
||||
cmd.addRawArg("-D" + p.key + "=" + environment.getProperties().expand(p.value));
|
||||
cmd.addRawArg("-D" + p.key + "=" + coreEnvironment.getProperties().expand(p.value));
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd.addRawArg(environment.getProperties().expand(x));
|
||||
cmd.addRawArg(coreEnvironment.getProperties().expand(x));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -528,7 +527,7 @@ public class StartArgs
|
|||
{
|
||||
if (isJPMS())
|
||||
{
|
||||
Map<Boolean, List<File>> dirsAndFiles = StreamSupport.stream(environment.getClasspath().spliterator(), false)
|
||||
Map<Boolean, List<File>> dirsAndFiles = StreamSupport.stream(coreEnvironment.getClasspath().spliterator(), false)
|
||||
.collect(Collectors.groupingBy(File::isDirectory));
|
||||
List<File> files = dirsAndFiles.get(false);
|
||||
if (files != null && !files.isEmpty())
|
||||
|
@ -554,7 +553,7 @@ public class StartArgs
|
|||
else
|
||||
{
|
||||
cmd.addRawArg("--class-path");
|
||||
cmd.addRawArg(environment.getClasspath().toString());
|
||||
cmd.addRawArg(coreEnvironment.getClasspath().toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -565,18 +564,20 @@ public class StartArgs
|
|||
cmd.addRawArg(getMainClassname());
|
||||
}
|
||||
|
||||
// pass properties as args or as a file
|
||||
// do properties and xmls
|
||||
if (parts.contains("args"))
|
||||
{
|
||||
if (dryRun && execProperties == null)
|
||||
{
|
||||
for (Prop p : environment.getProperties())
|
||||
// pass properties as args
|
||||
for (Prop p : coreEnvironment.getProperties())
|
||||
{
|
||||
cmd.addRawArg(CommandLineBuilder.quote(p.key) + "=" + CommandLineBuilder.quote(p.value));
|
||||
}
|
||||
}
|
||||
else if (environment.getProperties().size() > 0)
|
||||
else if (coreEnvironment.getProperties().size() > 0)
|
||||
{
|
||||
// pass properties as a temp property file
|
||||
Path propPath;
|
||||
if (execProperties == null)
|
||||
{
|
||||
|
@ -588,22 +589,37 @@ public class StartArgs
|
|||
|
||||
try (OutputStream out = Files.newOutputStream(propPath))
|
||||
{
|
||||
environment.getProperties().store(out, "start.jar properties");
|
||||
coreEnvironment.getProperties().store(out, "start.jar properties");
|
||||
}
|
||||
cmd.addRawArg(propPath.toAbsolutePath().toString());
|
||||
}
|
||||
|
||||
for (Path xml : environment.getXmlFiles())
|
||||
for (Path xml : coreEnvironment.getXmlFiles())
|
||||
{
|
||||
cmd.addRawArg(xml.toAbsolutePath().toString());
|
||||
}
|
||||
|
||||
for (Path propertyFile : environment.getPropertyFiles())
|
||||
for (Path propertyFile : coreEnvironment.getPropertyFiles())
|
||||
{
|
||||
cmd.addRawArg(propertyFile.toAbsolutePath().toString());
|
||||
}
|
||||
}
|
||||
|
||||
if (parts.contains("envs"))
|
||||
{
|
||||
for (Environment environment : getEnvironments())
|
||||
{
|
||||
if (environment == coreEnvironment)
|
||||
continue;
|
||||
|
||||
Path envPath = Files.createTempFile("env_%s_".formatted(environment.getName()), ".xml");
|
||||
environment.generateXml(coreEnvironment, envPath);
|
||||
if (!isDryRun())
|
||||
envPath.toFile().deleteOnExit();
|
||||
cmd.addRawArg(envPath.toAbsolutePath().toString());
|
||||
}
|
||||
}
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@ Report Commands:
|
|||
o "path" - the JVM class-path and/or the JPMS module-path
|
||||
o "main" - the main class to run
|
||||
o "args" - the arguments passed to the main class
|
||||
o "envs" - the generated XML files to create the environments
|
||||
|
||||
Configure Commands:
|
||||
-------------------
|
||||
|
|
|
@ -32,43 +32,6 @@ import org.eclipse.jetty.util.resource.Resource;
|
|||
/**
|
||||
* A Builder of {@link Environment}s intended to be used in XML
|
||||
* files generated by <code>start.jar</code>.
|
||||
* <pre>
|
||||
* <Configure id="Server" class="org.eclipse.jetty.server.Server">
|
||||
* <New class="org.eclipse.jetty.xml.EnvironmentBuilder">
|
||||
* <Arg name="name">ee10</Arg>
|
||||
* <Call name="putId">
|
||||
* <Arg>Server</Arg>
|
||||
* <Arg><Ref id="Server"/></Arg>
|
||||
* </Call>
|
||||
* <Put name="propertyA">valueA</Put>
|
||||
* <Put name="propertyB">valueB</Put>
|
||||
* <Put name="propertyC">valueC</Put>
|
||||
*
|
||||
* <Call name="addClassPath">
|
||||
* <Arg>
|
||||
* <Array type="String">
|
||||
* <Item>lib/feature/foo.jar</Item>
|
||||
* <Item>lib/feature/bar.jar</Item>
|
||||
* </Array>
|
||||
* </Arg>
|
||||
* </Call>
|
||||
*
|
||||
* <Call name="addXml">
|
||||
* <Arg>
|
||||
* <Array type="String">
|
||||
* <Item>etc/foo.xml</Item>
|
||||
* <Item>etc/bar.jar</Item>
|
||||
* </Array>
|
||||
* </Arg>
|
||||
* </Call>
|
||||
*
|
||||
* <Call id="EnvironmentEE10" name="build"/>
|
||||
* </New>
|
||||
* <Call name="addEnvironment">
|
||||
* <Arg><Ref id="EnvironmentEE10"/></Arg>
|
||||
* </Call>
|
||||
* </Configure>
|
||||
* </pre>
|
||||
*
|
||||
*/
|
||||
public class EnvironmentBuilder extends AbstractMap<String, String>
|
||||
|
|
Loading…
Reference in New Issue