Skip to content

Commit ef6097f

Browse files
committed
Begin moving XContent to a separate lib/artifact (#29300)
* Begin moving XContent to a separate lib/artifact This commit moves a large portion of the XContent code from the `server` project to the `libs/xcontent` project. For the pieces that have been moved, some helpers have been duplicated to allow them to be decoupled from ES helper classes. In addition, `Booleans` and `CheckedFunction` have been moved to the `elasticsearch-core` project. This decoupling is a move so that we can eventually make things like the high-level REST client not rely on the entire ES jar, only the parts it needs. There are some pieces that are still not decoupled, in particular some of the XContent tests still remain in the server project, this is because they test a large portion of the pluggable xcontent pieces through `XContentElasticsearchException`. They may be decoupled in future work. Additionally, there may be more piecese that we want to move to the xcontent lib in the future that are not part of this PR, this is a starting point. Relates to #28504
1 parent 4349a6c commit ef6097f

File tree

56 files changed

+396
-177
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+396
-177
lines changed

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ subprojects {
200200
"org.elasticsearch:elasticsearch:${version}": ':server',
201201
"org.elasticsearch:elasticsearch-cli:${version}": ':server:cli',
202202
"org.elasticsearch:elasticsearch-core:${version}": ':libs:elasticsearch-core',
203-
"org.elasticsearch:elasticsearch-secure-sm:${version}": ':libs:secure-sm',
203+
"org.elasticsearch:elasticsearch-x-content:${version}": ':libs:x-content',
204+
"org.elasticsearch:elasticsearch-secure-sm:${version}": ':libs:secure-sm',
204205
"org.elasticsearch.client:elasticsearch-rest-client:${version}": ':client:rest',
205206
"org.elasticsearch.client:elasticsearch-rest-client-sniffer:${version}": ':client:sniffer',
206207
"org.elasticsearch.client:elasticsearch-rest-high-level-client:${version}": ':client:rest-high-level',

buildSrc/src/main/resources/checkstyle_suppressions.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,7 @@
248248
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]util[/\\]concurrent[/\\]EsExecutors.java" checks="LineLength" />
249249
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]util[/\\]concurrent[/\\]ThreadBarrier.java" checks="LineLength" />
250250
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]util[/\\]concurrent[/\\]ThreadContext.java" checks="LineLength" />
251-
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]xcontent[/\\]XContentFactory.java" checks="LineLength" />
252251
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]xcontent[/\\]XContentHelper.java" checks="LineLength" />
253-
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]xcontent[/\\]smile[/\\]SmileXContent.java" checks="LineLength" />
254252
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]discovery[/\\]Discovery.java" checks="LineLength" />
255253
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]discovery[/\\]DiscoverySettings.java" checks="LineLength" />
256254
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]discovery[/\\]zen[/\\]ZenDiscovery.java" checks="LineLength" />

server/src/main/java/org/elasticsearch/common/Booleans.java renamed to libs/elasticsearch-core/src/main/java/org/elasticsearch/common/Booleans.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,34 @@ public static boolean parseBoolean(String value) {
7373
throw new IllegalArgumentException("Failed to parse value [" + value + "] as only [true] or [false] are allowed.");
7474
}
7575

76+
private static boolean hasText(CharSequence str) {
77+
if (str == null || str.length() == 0) {
78+
return false;
79+
}
80+
int strLen = str.length();
81+
for (int i = 0; i < strLen; i++) {
82+
if (!Character.isWhitespace(str.charAt(i))) {
83+
return true;
84+
}
85+
}
86+
return false;
87+
}
88+
7689
/**
7790
*
7891
* @param value text to parse.
7992
* @param defaultValue The default value to return if the provided value is <code>null</code>.
8093
* @return see {@link #parseBoolean(String)}
8194
*/
8295
public static boolean parseBoolean(String value, boolean defaultValue) {
83-
if (Strings.hasText(value)) {
96+
if (hasText(value)) {
8497
return parseBoolean(value);
8598
}
8699
return defaultValue;
87100
}
88101

89102
public static Boolean parseBoolean(String value, Boolean defaultValue) {
90-
if (Strings.hasText(value)) {
103+
if (hasText(value)) {
91104
return parseBoolean(value);
92105
}
93106
return defaultValue;
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.common;
21+
22+
/**
23+
* Utility class for glob-like matching
24+
*/
25+
public class Glob {
26+
27+
/**
28+
* Match a String against the given pattern, supporting the following simple
29+
* pattern styles: "xxx*", "*xxx", "*xxx*" and "xxx*yyy" matches (with an
30+
* arbitrary number of pattern parts), as well as direct equality.
31+
*
32+
* @param pattern the pattern to match against
33+
* @param str the String to match
34+
* @return whether the String matches the given pattern
35+
*/
36+
public static boolean globMatch(String pattern, String str) {
37+
if (pattern == null || str == null) {
38+
return false;
39+
}
40+
int firstIndex = pattern.indexOf('*');
41+
if (firstIndex == -1) {
42+
return pattern.equals(str);
43+
}
44+
if (firstIndex == 0) {
45+
if (pattern.length() == 1) {
46+
return true;
47+
}
48+
int nextIndex = pattern.indexOf('*', firstIndex + 1);
49+
if (nextIndex == -1) {
50+
return str.endsWith(pattern.substring(1));
51+
} else if (nextIndex == 1) {
52+
// Double wildcard "**" - skipping the first "*"
53+
return globMatch(pattern.substring(1), str);
54+
}
55+
String part = pattern.substring(1, nextIndex);
56+
int partIndex = str.indexOf(part);
57+
while (partIndex != -1) {
58+
if (globMatch(pattern.substring(nextIndex), str.substring(partIndex + part.length()))) {
59+
return true;
60+
}
61+
partIndex = str.indexOf(part, partIndex + 1);
62+
}
63+
return false;
64+
}
65+
return (str.length() >= firstIndex &&
66+
pattern.substring(0, firstIndex).equals(str.substring(0, firstIndex)) &&
67+
globMatch(pattern.substring(firstIndex), str.substring(firstIndex)));
68+
}
69+
70+
}

libs/x-content/build.gradle

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import org.elasticsearch.gradle.precommit.PrecommitTasks
2+
3+
/*
4+
* Licensed to Elasticsearch under one or more contributor
5+
* license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright
7+
* ownership. Elasticsearch licenses this file to you under
8+
* the Apache License, Version 2.0 (the "License"); you may
9+
* not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
apply plugin: 'elasticsearch.build'
23+
apply plugin: 'nebula.maven-base-publish'
24+
apply plugin: 'nebula.maven-scm'
25+
26+
archivesBaseName = 'elasticsearch-x-content'
27+
28+
publishing {
29+
publications {
30+
nebula {
31+
artifactId = archivesBaseName
32+
}
33+
}
34+
}
35+
36+
dependencies {
37+
compile "org.elasticsearch:elasticsearch-core:${version}"
38+
39+
compile "org.yaml:snakeyaml:${versions.snakeyaml}"
40+
compile "com.fasterxml.jackson.core:jackson-core:${versions.jackson}"
41+
compile "com.fasterxml.jackson.dataformat:jackson-dataformat-smile:${versions.jackson}"
42+
compile "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${versions.jackson}"
43+
compile "com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:${versions.jackson}"
44+
45+
testCompile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
46+
testCompile "junit:junit:${versions.junit}"
47+
testCompile "org.hamcrest:hamcrest-all:${versions.hamcrest}"
48+
49+
if (isEclipse == false || project.path == ":libs:x-content-tests") {
50+
testCompile("org.elasticsearch.test:framework:${version}") {
51+
exclude group: 'org.elasticsearch', module: 'elasticsearch-x-content'
52+
}
53+
}
54+
55+
}
56+
57+
forbiddenApisMain {
58+
// x-content does not depend on server
59+
// TODO: Need to decide how we want to handle for forbidden signatures with the changes to core
60+
signaturesURLs = [PrecommitTasks.getResource('/forbidden/jdk-signatures.txt')]
61+
}
62+
63+
if (isEclipse) {
64+
// in eclipse the project is under a fake root, we need to change around the source sets
65+
sourceSets {
66+
if (project.path == ":libs:x-content") {
67+
main.java.srcDirs = ['java']
68+
main.resources.srcDirs = ['resources']
69+
} else {
70+
test.java.srcDirs = ['java']
71+
test.resources.srcDirs = ['resources']
72+
}
73+
}
74+
}
75+
76+
thirdPartyAudit.excludes = [
77+
// from com.fasterxml.jackson.dataformat.yaml.YAMLMapper (jackson-dataformat-yaml)
78+
'com.fasterxml.jackson.databind.ObjectMapper',
79+
]
80+
81+
dependencyLicenses {
82+
mapping from: /jackson-.*/, to: 'jackson'
83+
}
84+
85+
jarHell.enabled = false
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)