Skip to content

Commit d3282c6

Browse files
tamaashusymat
authored andcommitted
ZOOKEEPER-3952: Remove commons-lang from ZooKeeper
Removed commons-lang from main project, replaced functionality with standard Java code. Author: Tamas Penzes <tamaas@cloudera.com> Reviewers: Christopher Tubbs <ctubbsii@apache.org>, Enrico Olivelli <eolivelli@apache.org>, Mate Szalay-Beko <symat@apache.org>, tison <wander4096@gmail.com> Closes #1478 from tamaashu/ZOOKEEPER-3952
1 parent ec1503b commit d3282c6

6 files changed

Lines changed: 60 additions & 32 deletions

File tree

‎pom.xml‎

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,10 @@
444444
<kerby.version>2.0.0</kerby.version>
445445
<bouncycastle.version>1.60</bouncycastle.version>
446446
<commons-collections.version>3.2.2</commons-collections.version>
447-
<commons-lang.version>2.6</commons-lang.version>
448447
<dropwizard.version>3.2.5</dropwizard.version>
449448
<spotbugsannotations.version>4.0.2</spotbugsannotations.version>
450449
<checkstyle.version>8.17</checkstyle.version>
450+
<enforcer.version>3.0.0-M3</enforcer.version>
451451

452452
<!-- parameters to pass to C client build -->
453453
<c-client-openssl>yes</c-client-openssl>
@@ -467,11 +467,6 @@
467467
<artifactId>commons-collections</artifactId>
468468
<version>${commons-collections.version}</version>
469469
</dependency>
470-
<dependency>
471-
<groupId>commons-lang</groupId>
472-
<artifactId>commons-lang</artifactId>
473-
<version>${commons-lang.version}</version>
474-
</dependency>
475470
<dependency>
476471
<groupId>org.apache.yetus</groupId>
477472
<artifactId>audience-annotations</artifactId>
@@ -1046,6 +1041,47 @@
10461041
</execution>
10471042
</executions>
10481043
</plugin>
1044+
<plugin>
1045+
<groupId>org.apache.maven.plugins</groupId>
1046+
<artifactId>maven-enforcer-plugin</artifactId>
1047+
<version>${enforcer.version}</version>
1048+
<executions>
1049+
<execution>
1050+
<id>banned-commons-lang</id>
1051+
<goals>
1052+
<goal>enforce</goal>
1053+
</goals>
1054+
<configuration>
1055+
<rules>
1056+
<bannedDependencies>
1057+
<excludes>
1058+
<exclude>commons-lang:commons-lang</exclude>
1059+
</excludes>
1060+
<searchTransitive>false</searchTransitive>
1061+
<message>We don't use commons-lang any more, so do not depend on it directly.</message>
1062+
</bannedDependencies>
1063+
</rules>
1064+
</configuration>
1065+
</execution>
1066+
<execution>
1067+
<id>banned-commons-lang3</id>
1068+
<goals>
1069+
<goal>enforce</goal>
1070+
</goals>
1071+
<configuration>
1072+
<rules>
1073+
<bannedDependencies>
1074+
<excludes>
1075+
<exclude>org.apache.commons:commons-lang3</exclude>
1076+
</excludes>
1077+
<searchTransitive>false</searchTransitive>
1078+
<message>We don't use commons-lang3, so do not depend on it directly.</message>
1079+
</bannedDependencies>
1080+
</rules>
1081+
</configuration>
1082+
</execution>
1083+
</executions>
1084+
</plugin>
10491085
</plugins>
10501086
<resources>
10511087
<resource>

‎zookeeper-contrib/zookeeper-contrib-zooinspector/ivy.xml‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,8 @@
3939

4040
<dependency org="log4j" name="log4j" rev="1.2.17" transitive="false"/>
4141
<dependency org="junit" name="junit" rev="4.12" conf="test->default"/>
42-
<dependency org="org.apache.rat" name="apache-rat-tasks"
43-
rev="0.6" conf="releaseaudit->default"/>
44-
<dependency org="commons-lang" name="commons-lang"
45-
rev="2.4" conf="releaseaudit->default"/>
46-
<dependency org="commons-collections" name="commons-collections"
47-
rev="3.2.2" conf="releaseaudit->default"/>
42+
<dependency org="org.apache.rat" name="apache-rat-tasks" rev="0.6" conf="releaseaudit->default"/>
43+
<dependency org="commons-collections" name="commons-collections" rev="3.2.2" conf="releaseaudit->default"/>
4844
</dependencies>
4945

5046
</ivy-module>

‎zookeeper-contrib/zookeeper-contrib-zooinspector/pom.xml‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
<properties>
3737
<rat.version>0.6</rat.version>
38-
<commons-lang.version>2.4</commons-lang.version>
3938
<guava.version>18.0</guava.version>
4039
</properties>
4140

@@ -84,11 +83,6 @@
8483
<artifactId>apache-rat-tasks</artifactId>
8584
<version>${rat.version}</version>
8685
</dependency>
87-
<dependency>
88-
<groupId>commons-lang</groupId>
89-
<artifactId>commons-lang</artifactId>
90-
<version>${commons-lang.version}</version>
91-
</dependency>
9286
<dependency>
9387
<groupId>commons-collections</groupId>
9488
<artifactId>commons-collections</artifactId>

‎zookeeper-server/pom.xml‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@
4848
<artifactId>commons-collections</artifactId>
4949
<scope>test</scope>
5050
</dependency>
51-
<dependency>
52-
<groupId>commons-lang</groupId>
53-
<artifactId>commons-lang</artifactId>
54-
</dependency>
5551
<dependency>
5652
<groupId>org.apache.zookeeper</groupId>
5753
<artifactId>zookeeper-jute</artifactId>

‎zookeeper-server/src/main/java/org/apache/zookeeper/common/PathTrie.java‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import java.util.concurrent.locks.Lock;
2828
import java.util.concurrent.locks.ReadWriteLock;
2929
import java.util.concurrent.locks.ReentrantReadWriteLock;
30-
import org.apache.commons.lang.StringUtils;
30+
import java.util.stream.Stream;
3131
import org.slf4j.Logger;
3232
import org.slf4j.LoggerFactory;
3333

@@ -203,10 +203,10 @@ public PathTrie() {
203203
public void addPath(final String path) {
204204
Objects.requireNonNull(path, "Path cannot be null");
205205

206-
final String[] pathComponents = StringUtils.split(path, '/');
207-
if (pathComponents.length == 0) {
206+
if (path.length() == 0) {
208207
throw new IllegalArgumentException("Invalid path: " + path);
209208
}
209+
final String[] pathComponents = split(path);
210210

211211
writeLock.lock();
212212
try {
@@ -233,10 +233,11 @@ public void addPath(final String path) {
233233
public void deletePath(final String path) {
234234
Objects.requireNonNull(path, "Path cannot be null");
235235

236-
final String[] pathComponents = StringUtils.split(path, '/');
237-
if (pathComponents.length == 0) {
236+
if (path.length() == 0) {
238237
throw new IllegalArgumentException("Invalid path: " + path);
239238
}
239+
final String[] pathComponents = split(path);
240+
240241

241242
writeLock.lock();
242243
try {
@@ -267,10 +268,10 @@ public void deletePath(final String path) {
267268
public boolean existsNode(final String path) {
268269
Objects.requireNonNull(path, "Path cannot be null");
269270

270-
final String[] pathComponents = StringUtils.split(path, '/');
271-
if (pathComponents.length == 0) {
271+
if (path.length() == 0) {
272272
throw new IllegalArgumentException("Invalid path: " + path);
273273
}
274+
final String[] pathComponents = split(path);
274275

275276
readLock.lock();
276277
try {
@@ -299,7 +300,7 @@ public boolean existsNode(final String path) {
299300
public String findMaxPrefix(final String path) {
300301
Objects.requireNonNull(path, "Path cannot be null");
301302

302-
final String[] pathComponents = StringUtils.split(path, '/');
303+
final String[] pathComponents = split(path);
303304

304305
readLock.lock();
305306
try {
@@ -344,4 +345,10 @@ public void clear() {
344345
}
345346
}
346347

348+
private static String[] split(final String path){
349+
return Stream.of(path.split("/"))
350+
.filter(t -> !t.trim().isEmpty())
351+
.toArray(String[]::new);
352+
}
353+
347354
}

‎zookeeper-server/src/main/java/org/apache/zookeeper/server/FinalRequestProcessor.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.List;
2626
import java.util.Locale;
2727
import java.util.Set;
28-
import org.apache.commons.lang.StringUtils;
2928
import org.apache.jute.Record;
3029
import org.apache.zookeeper.ClientCnxn;
3130
import org.apache.zookeeper.KeeperException;
@@ -554,7 +553,7 @@ public void processRequest(Request request) {
554553
String prefixPath = getEphemerals.getPrefixPath();
555554
Set<String> allEphems = zks.getZKDatabase().getDataTree().getEphemerals(request.sessionId);
556555
List<String> ephemerals = new ArrayList<>();
557-
if (StringUtils.isBlank(prefixPath) || "/".equals(prefixPath.trim())) {
556+
if (prefixPath == null || prefixPath.trim().isEmpty() || "/".equals(prefixPath.trim())) {
558557
ephemerals.addAll(allEphems);
559558
} else {
560559
for (String p : allEphems) {

0 commit comments

Comments
 (0)