Merged branch 'jetty-10.0.x' into 'jetty-11.0.x'.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Simone Bordet 2021-04-12 10:45:58 +02:00
commit a711768384
4 changed files with 140 additions and 80 deletions

View File

@ -39,7 +39,7 @@ import org.eclipse.jetty.start.fileinits.TestFileInitializer;
import org.eclipse.jetty.start.fileinits.UriFileInitializer;
/**
* Build a start configuration in <code>${jetty.base}</code>, including
* Build a start configuration in {@code ${jetty.base}}, including
* ini files, directories, and libs. Also handles License management.
*/
public class BaseBuilder
@ -47,7 +47,7 @@ public class BaseBuilder
public static interface Config
{
/**
* Add a module to the start environment in <code>${jetty.base}</code>
* Add a module to the start environment in {@code ${jetty.base}}
*
* @param module the module to add
* @param props The properties to substitute into a template
@ -163,7 +163,7 @@ public class BaseBuilder
}
// generate the files
List<FileArg> files = new ArrayList<FileArg>();
List<FileArg> files = new ArrayList<>();
AtomicReference<BaseBuilder.Config> builder = new AtomicReference<>();
AtomicBoolean modified = new AtomicBoolean();
@ -184,18 +184,21 @@ public class BaseBuilder
if (Files.exists(startd))
{
// Copy start.d files into start.ini
DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>()
DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<>()
{
PathMatcher iniMatcher = PathMatchers.getMatcher("glob:**/start.d/*.ini");
private final PathMatcher iniMatcher = PathMatchers.getMatcher("glob:**/start.d/*.ini");
@Override
public boolean accept(Path entry) throws IOException
public boolean accept(Path entry)
{
return iniMatcher.matches(entry);
}
};
List<Path> paths = new ArrayList<>();
for (Path path : Files.newDirectoryStream(startd, filter))
{
paths.add(path);
}
paths.sort(new NaturalSort.Paths());
// Read config from start.d
@ -212,12 +215,16 @@ public class BaseBuilder
try (FileWriter out = new FileWriter(startini.toFile(), true))
{
for (String line : startLines)
{
out.append(line).append(System.lineSeparator());
}
}
// delete start.d files
for (Path path : paths)
{
Files.delete(path);
}
Files.delete(startd);
}
}
@ -264,56 +271,66 @@ public class BaseBuilder
StartLog.warn("Use of both %s and %s is deprecated", getBaseHome().toShortForm(startd), getBaseHome().toShortForm(startini));
builder.set(useStartD ? new StartDirBuilder(this) : new StartIniBuilder(this));
newlyAdded.stream().map(modules::get).forEach(module ->
{
String ini = null;
try
{
if (module.isSkipFilesValidation())
{
StartLog.debug("Skipping [files] validation on %s", module.getName());
}
else
{
// if (explicitly added and ini file modified)
if (startArgs.getStartModules().contains(module.getName()))
{
ini = builder.get().addModule(module, startArgs.getProperties());
if (ini != null)
modified.set(true);
}
for (String file : module.getFiles())
{
files.add(new FileArg(module, startArgs.getProperties().expand(file)));
}
}
}
catch (Exception e)
{
throw new RuntimeException(e);
}
if (module.isDynamic())
// Collect the filesystem operations to perform,
// only for those modules that are enabled.
newlyAdded.stream()
.map(modules::get)
.filter(Module::isEnabled)
.forEach(module ->
{
for (String s : module.getEnableSources())
String ini = null;
try
{
StartLog.info("%-15s %s", module.getName(), s);
if (module.isSkipFilesValidation())
{
StartLog.debug("Skipping [files] validation on %s", module.getName());
}
else
{
// if (explicitly added and ini file modified)
if (startArgs.getStartModules().contains(module.getName()))
{
ini = builder.get().addModule(module, startArgs.getProperties());
if (ini != null)
modified.set(true);
}
for (String file : module.getFiles())
{
files.add(new FileArg(module, startArgs.getProperties().expand(file)));
}
}
}
catch (Exception e)
{
throw new RuntimeException(e);
}
if (module.isDynamic())
{
for (String s : module.getEnableSources())
{
StartLog.info("%-15s %s", module.getName(), s);
}
}
else if (module.isTransitive())
{
if (module.hasIniTemplate())
{
StartLog.info("%-15s transitively enabled, ini template available with --add-module=%s",
module.getName(),
module.getName());
}
else
{
StartLog.info("%-15s transitively enabled", module.getName());
}
}
}
else if (module.isTransitive())
{
if (module.hasIniTemplate())
StartLog.info("%-15s transitively enabled, ini template available with --add-module=%s",
module.getName(),
module.getName());
else
StartLog.info("%-15s transitively enabled", module.getName());
}
else
{
StartLog.info("%-15s initialized in %s", module.getName(), ini);
}
});
{
StartLog.info("%-15s initialized in %s", module.getName(), ini);
}
});
files.addAll(startArgs.getFiles());
if (!files.isEmpty() && processFileResources(files))
@ -370,7 +387,7 @@ public class BaseBuilder
* @param files the list of {@link FileArg}s to process
* @return true if base directory modified, false if left untouched
*/
private boolean processFileResources(List<FileArg> files) throws IOException
private boolean processFileResources(List<FileArg> files)
{
if ((files == null) || (files.isEmpty()))
{

View File

@ -18,7 +18,6 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
@ -552,7 +551,7 @@ public class Modules implements Iterable<Module>
Set<Module> providers = _provided.get(name);
StartLog.debug("Providers of [%s] are %s", name, providers);
if (providers == null || providers.isEmpty())
return Collections.emptySet();
return Set.of();
providers = new HashSet<>(providers);

View File

@ -52,14 +52,8 @@ import org.eclipse.jetty.util.ManifestUtils;
public class StartArgs
{
public static final String VERSION;
public static final Set<String> ALL_PARTS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
"java",
"opts",
"path",
"main",
"args")));
public static final Set<String> ARG_PARTS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
"args")));
public static final Set<String> ALL_PARTS = Set.of("java", "opts", "path", "main", "args");
public static final Set<String> ARG_PARTS = Set.of("args");
static
{
@ -126,12 +120,12 @@ public class StartArgs
/**
* List of enabled modules
*/
private List<String> modules = new ArrayList<>();
private final List<String> modules = new ArrayList<>();
/**
* List of modules to skip [files] section validation
*/
private Set<String> skipFileValidationModules = new HashSet<>();
private final Set<String> skipFileValidationModules = new HashSet<>();
/**
* Map of enabled modules to the source of where that activation occurred
@ -141,56 +135,56 @@ public class StartArgs
/**
* List of all active [files] sections from enabled modules
*/
private List<FileArg> files = new ArrayList<>();
private final List<FileArg> files = new ArrayList<>();
/**
* List of all active [lib] sections from enabled modules
*/
private Classpath classpath;
private final Classpath classpath;
/**
* List of all active [xml] sections from enabled modules
*/
private List<Path> xmls = new ArrayList<>();
private final List<Path> xmls = new ArrayList<>();
/**
* List of all active [jpms] sections for enabled modules
*/
private Set<String> jmodAdds = new LinkedHashSet<>();
private Map<String, Set<String>> jmodPatch = new LinkedHashMap<>();
private Map<String, Set<String>> jmodOpens = new LinkedHashMap<>();
private Map<String, Set<String>> jmodExports = new LinkedHashMap<>();
private Map<String, Set<String>> jmodReads = new LinkedHashMap<>();
private final Set<String> jmodAdds = new LinkedHashSet<>();
private final Map<String, Set<String>> jmodPatch = new LinkedHashMap<>();
private final Map<String, Set<String>> jmodOpens = new LinkedHashMap<>();
private final Map<String, Set<String>> jmodExports = new LinkedHashMap<>();
private final Map<String, Set<String>> jmodReads = new LinkedHashMap<>();
/**
* JVM arguments, found via command line and in all active [exec] sections from enabled modules
*/
private List<String> jvmArgs = new ArrayList<>();
private final List<String> jvmArgs = new ArrayList<>();
/**
* List of all xml references found directly on command line or start.ini
*/
private List<String> xmlRefs = new ArrayList<>();
private final List<String> xmlRefs = new ArrayList<>();
/**
* List of all property references found directly on command line or start.ini
*/
private List<String> propertyFileRefs = new ArrayList<>();
private final List<String> propertyFileRefs = new ArrayList<>();
/**
* List of all property files
*/
private List<Path> propertyFiles = new ArrayList<>();
private final List<Path> propertyFiles = new ArrayList<>();
private Props properties = new Props();
private Map<String, String> systemPropertySource = new HashMap<>();
private List<String> rawLibs = new ArrayList<>();
private final Props properties = new Props();
private final Map<String, String> systemPropertySource = new HashMap<>();
private final List<String> rawLibs = new ArrayList<>();
// jetty.base - build out commands
/**
* --add-module=[module,[module]]
*/
private List<String> startModules = new ArrayList<>();
private final List<String> startModules = new ArrayList<>();
// module inspection commands
/**

View File

@ -859,4 +859,54 @@ public class DistributionTests extends AbstractJettyHomeTest
}
}
}
@Test
public void testDefaultLoggingProviderNotActiveWhenExplicitProviderIsPresent() throws Exception
{
String jettyVersion = System.getProperty("jettyVersion");
JettyHomeTester distribution1 = JettyHomeTester.Builder.newInstance()
.jettyVersion(jettyVersion)
.mavenLocalRepository(System.getProperty("mavenRepoPath"))
.build();
String[] args1 = {
"--approve-all-licenses",
"--add-modules=logging-logback,http"
};
try (JettyHomeTester.Run run1 = distribution1.start(args1))
{
assertTrue(run1.awaitFor(10, TimeUnit.SECONDS));
assertEquals(0, run1.getExitValue());
Path jettyBase = run1.getConfig().getJettyBase();
assertTrue(Files.exists(jettyBase.resolve("resources/logback.xml")));
// The jetty-logging.properties should be absent.
assertFalse(Files.exists(jettyBase.resolve("resources/jetty-logging.properties")));
}
JettyHomeTester distribution2 = JettyHomeTester.Builder.newInstance()
.jettyVersion(jettyVersion)
.mavenLocalRepository(System.getProperty("mavenRepoPath"))
.build();
// Try the modules in reverse order, since it may execute a different code path.
String[] args2 = {
"--approve-all-licenses",
"--add-modules=http,logging-logback"
};
try (JettyHomeTester.Run run2 = distribution2.start(args2))
{
assertTrue(run2.awaitFor(1000, TimeUnit.SECONDS));
assertEquals(0, run2.getExitValue());
Path jettyBase = run2.getConfig().getJettyBase();
assertTrue(Files.exists(jettyBase.resolve("resources/logback.xml")));
// The jetty-logging.properties should be absent.
assertFalse(Files.exists(jettyBase.resolve("resources/jetty-logging.properties")));
}
}
}