-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Issue #12990 - Introduce static-deploy
module
#12998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 14 commits
d72b287
a598469
c5cb76d
81c1f51
3c7156b
cd2a996
6e9adbb
fa2e720
17ea7ed
7351898
518ea13
499f5b0
5b80a94
60065cc
eb2c5dd
0ee1529
3d5c525
0329896
1f49310
cadf0a5
8149809
532b422
db8f04d
f0a2f3b
b159daf
99174e4
660ae3f
aaab35f
860415b
e3c7ce4
65aaca2
40f0996
6ca1507
32c5507
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -33,6 +33,8 @@ | |||||||||
import java.util.Set; | ||||||||||
import java.util.concurrent.CopyOnWriteArrayList; | ||||||||||
import java.util.function.Predicate; | ||||||||||
import java.util.regex.Matcher; | ||||||||||
import java.util.regex.Pattern; | ||||||||||
import java.util.stream.Collectors; | ||||||||||
import java.util.stream.Stream; | ||||||||||
|
||||||||||
|
@@ -127,6 +129,33 @@ public class DeploymentScanner extends ContainerLifeCycle implements Scanner.Bul | |||||||||
// old attributes prefix, now stripped. | ||||||||||
private static final String ATTRIBUTE_PREFIX = "jetty.deploy.attribute."; | ||||||||||
|
||||||||||
private static final Pattern EE_ENVIRONMENT_NAME_PATTERN = Pattern.compile("ee(\\d+)"); | ||||||||||
|
||||||||||
/** | ||||||||||
* A comparator that ranks names matching EE_ENVIRONMENT_NAME_PATTERN higher than other names, | ||||||||||
* EE names are compared by EE number, otherwise simple name comparison is used. | ||||||||||
*/ | ||||||||||
protected static final Comparator<String> ENVIRONMENT_COMPARATOR = (e1, e2) -> | ||||||||||
{ | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comparator will generate a lot of matchers, so perhaps take the returns where you can:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better yet, why not just create an Index that is case insensitive and maps all the known environment names to an integer. Index<Integer> environmentOrdinals = new Index.Builder<Integer>()
.caseSensitive(false)
.with("static", 1)
.with("core", 2)
.with("ee9", 9)
.with("ee10", 10)
.with("ee11", 11)
.build(); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In a conversation with @sbordet and @lorban this will be fixed in a followup PR. I have an approach that will push the weight of the tracked environments (the ones allowed to be deployed to) via a change to the That way the weights are not hardcoded, and can be adjusted by any user, and even add new environments (with their own weights) without the need to modify code. |
||||||||||
Matcher m1 = EE_ENVIRONMENT_NAME_PATTERN.matcher(e1); | ||||||||||
Matcher m2 = EE_ENVIRONMENT_NAME_PATTERN.matcher(e2); | ||||||||||
|
||||||||||
if (m1.matches()) | ||||||||||
{ | ||||||||||
if (m2.matches()) | ||||||||||
{ | ||||||||||
int n1 = Integer.parseInt(m1.group(1)); | ||||||||||
int n2 = Integer.parseInt(m2.group(1)); | ||||||||||
return Integer.compare(n2, n1); | ||||||||||
} | ||||||||||
return -1; | ||||||||||
} | ||||||||||
if (m2.matches()) | ||||||||||
return 1; | ||||||||||
|
||||||||||
return e1.compareTo(e2); | ||||||||||
}; | ||||||||||
|
||||||||||
private final Server server; | ||||||||||
private final FilenameFilter filenameFilter; | ||||||||||
private final List<Path> monitoredDirs = new CopyOnWriteArrayList<>(); | ||||||||||
|
@@ -292,7 +321,12 @@ void addScannerListener(Scanner.Listener listener) | |||||||||
*/ | ||||||||||
public EnvironmentConfig configureEnvironment(String name) | ||||||||||
{ | ||||||||||
return new EnvironmentConfig(Environment.get(name)); | ||||||||||
Environment environment = Environment.get(name); | ||||||||||
// Check to make sure that the Environment was created before jetty-deploy is involved. | ||||||||||
// This is to ensure that the Environment ClassLoader is setup properly. | ||||||||||
if (environment == null) | ||||||||||
throw new IllegalStateException("Environment [" + name + "] does not exist."); | ||||||||||
return new EnvironmentConfig(environment); | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
|
@@ -314,7 +348,7 @@ public void setActionComparator(Comparator<DeployAction> actionComparator) | |||||||||
* | ||||||||||
* <p> | ||||||||||
* Falls back to {@link Environment#getAll()} list, and returns | ||||||||||
* the first name returned after sorting with {@link Deployable#ENVIRONMENT_COMPARATOR} | ||||||||||
* the first name returned after sorting. | ||||||||||
* </p> | ||||||||||
* | ||||||||||
* @return the default environment name. | ||||||||||
|
@@ -325,7 +359,7 @@ public String getDefaultEnvironmentName() | |||||||||
{ | ||||||||||
return Environment.getAll().stream() | ||||||||||
.map(Environment::getName) | ||||||||||
.max(Deployable.ENVIRONMENT_COMPARATOR) | ||||||||||
.min(ENVIRONMENT_COMPARATOR) | ||||||||||
.orElse(null); | ||||||||||
} | ||||||||||
return defaultEnvironmentName; | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0"?><!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://jetty.org/configure_10_0.dtd"> | ||
|
||
<!-- =============================================================== --> | ||
<!-- Configure the "static" environment deployment defaults --> | ||
<!-- =============================================================== --> | ||
<Configure> | ||
<Ref refid="deploymentScanner"> | ||
<Call name="configureEnvironment"> | ||
<Arg>static</Arg> | ||
<Set name="contextHandlerClass"> | ||
<Property name="contextHandlerClass" default="org.eclipse.jetty.server.handler.StaticContextHandler" /> | ||
</Set> | ||
</Call> | ||
</Ref> | ||
</Configure> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[description] | ||
# tag::description[] | ||
Scans and deploys `static` contexts from `$JETTY_BASE/webapps/` directory. | ||
joakime marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# end::description[] | ||
|
||
[tags] | ||
deployment | ||
|
||
[environment] | ||
static | ||
|
||
[depend] | ||
deployment-scanner | ||
|
||
[xml] | ||
etc/jetty-static-deploy.xml | ||
|
||
[ini-template] | ||
## Default ContextHandler class for "static" environment deployments | ||
# contextHandlerClass=org.eclipse.jetty.server.handler.StaticContextHandler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know we use "ee", but just in case, perhaps this should be