Skip to content
Open

Cleanup #1488

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions framework/patches/pgjdbc.9.0.patch

This file was deleted.

27 changes: 4 additions & 23 deletions framework/src/play/classloading/ApplicationClassloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static java.util.Collections.unmodifiableList;
import static java.util.Collections.unmodifiableMap;
import static org.apache.commons.io.IOUtils.closeQuietly;

import java.io.File;
import java.io.IOException;
Expand All @@ -22,15 +21,11 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;

import play.Logger;
import play.Play;
import play.cache.Cache;
Expand Down Expand Up @@ -222,12 +217,10 @@ byte[] getClassDefinition(String name) {
if (is == null) {
return null;
}
try {
return IOUtils.toByteArray(is);
try (is) {
return is.readAllBytes();
} catch (Exception e) {
throw new UnexpectedException(e);
} finally {
closeQuietly(is);
}
}

Expand All @@ -239,7 +232,6 @@ public InputStream getResourceAsStream(String name) {
return res.inputstream();
}
}
URL url = getResource(name);

return super.getResourceAsStream(name);
}
Expand Down Expand Up @@ -294,19 +286,8 @@ public Enumeration<URL> getResources(String name) throws IOException {
urls.add(next);
}
}
final Iterator<URL> it = urls.iterator();
return new Enumeration<URL>() {

@Override
public boolean hasMoreElements() {
return it.hasNext();
}

@Override
public URL nextElement() {
return it.next();
}
};
return Collections.enumeration(urls);
}

/**
Expand Down Expand Up @@ -453,7 +434,7 @@ public List<Class<?>> getAllClasses() {
for (ApplicationClass clazz : Play.classes.all()) {
byNormalizedName.put(clazz.name.toLowerCase(), clazz);
if (clazz.name.contains("$")) {
byNormalizedName.put(StringUtils.replace(clazz.name.toLowerCase(), "$", "."), clazz);
byNormalizedName.put(clazz.name.toLowerCase().replace('$', '.'), clazz);
}
}

Expand Down
2 changes: 1 addition & 1 deletion framework/src/play/data/validation/Validation.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static void removeErrors(String field) {
*/
public static boolean hasErrors() {
Validation validation = current.get();
return validation != null && validation.errors.size() > 0;
return validation != null && !validation.errors.isEmpty();
}

/**
Expand Down
65 changes: 34 additions & 31 deletions framework/src/play/libs/Codec.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package play.libs;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;

import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;

import play.exceptions.UnexpectedException;
Expand Down Expand Up @@ -33,18 +33,18 @@ public static String UUID() {
* @return The base64 encoded String
*/
public static String encodeBASE64(String value) {
return new String(Base64.encodeBase64(value.getBytes(UTF_8)));
return java.util.Base64.getEncoder().encodeToString(value.getBytes(UTF_8));
}

/**
* Encode binary data to base64
*
*
* @param value
* The binary data
* @return The base64 encoded String
*/
public static String encodeBASE64(byte[] value) {
return new String(Base64.encodeBase64(value));
return java.util.Base64.getEncoder().encodeToString(value);
}

/**
Expand All @@ -55,50 +55,34 @@ public static String encodeBASE64(byte[] value) {
* @return decoded binary data
*/
public static byte[] decodeBASE64(String value) {
return Base64.decodeBase64(value.getBytes(UTF_8));
return java.util.Base64.getDecoder().decode(value);
}

/**
* Build an hexadecimal MD5 hash for a String
* Build a hexadecimal MD5 hash for a String
*
* @param value
* The String to hash
* @return An hexadecimal Hash
* @return A hexadecimal Hash
*/
public static String hexMD5(String value) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.reset();
messageDigest.update(value.getBytes(UTF_8));
byte[] digest = messageDigest.digest();
return byteToHexString(digest);
} catch (Exception ex) {
throw new UnexpectedException(ex);
}
return hashToHexString("MD5", value);
}

/**
* Build an hexadecimal SHA1 hash for a String
*
* Build a hexadecimal SHA1 hash for a String
*
* @param value
* The String to hash
* @return An hexadecimal Hash
* @return A hexadecimal Hash
*/
public static String hexSHA1(String value) {
try {
MessageDigest md;
md = MessageDigest.getInstance("SHA-1");
md.update(value.getBytes(UTF_8));
byte[] digest = md.digest();
return byteToHexString(digest);
} catch (Exception ex) {
throw new UnexpectedException(ex);
}
return hashToHexString("SHA-1", value);
}

/**
* Write a byte array as hexadecimal String.
*
*
* @param bytes
* byte array
* @return The hexadecimal String
Expand All @@ -108,8 +92,8 @@ public static String byteToHexString(byte[] bytes) {
}

/**
* Transform an hexadecimal String to a byte array.
*
* Transform a hexadecimal String to a byte array.
*
* @param hexString
* Hexadecimal string to transform
* @return The byte array
Expand All @@ -122,4 +106,23 @@ public static byte[] hexStringToByte(String hexString) {
}
}

/**
* Build a hexadecimal hash specified by {@code algorithm} for a given {@code value}.
*
* @param algorithm The hash name
* @param value The String to hash
*
* @return A hexadecimal hash
*/
private static String hashToHexString(String algorithm, String value) {
try {
return byteToHexString(
MessageDigest.getInstance(algorithm)
.digest(value.getBytes(UTF_8))
);
} catch (NoSuchAlgorithmException ex) {
throw new UnexpectedException(ex);
}
}

}
30 changes: 23 additions & 7 deletions framework/src/play/libs/F.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Consumer;

import org.jboss.netty.channel.ChannelHandlerContext;

import play.Logger;
Expand All @@ -27,14 +29,14 @@ public class F {
/**
* A Function with no arguments.
*/
public static interface Function0<R> {
public R apply() throws Throwable;
@FunctionalInterface
public interface Function0<R> {
R apply() throws Throwable;
}

public static class Promise<V> implements Future<V>, F.Action<V> {

protected final CountDownLatch taskLock = new CountDownLatch(1);
protected boolean cancelled = false;

@Override
public boolean cancel(boolean mayInterruptIfRunning) {
Expand Down Expand Up @@ -739,14 +741,28 @@ public boolean trigger() {
}
}

public static interface Action0 {
@FunctionalInterface
public interface Action0 extends Runnable {

void invoke();

@Override
default void run() {
invoke();
}

}

public static interface Action<T> {
@FunctionalInterface
public interface Action<T> extends Consumer<T> {

void invoke(T result);

@Override
default void accept(T result) {
invoke(result);
}

}

public abstract static class Option<T> implements Iterable<T> {
Expand All @@ -756,7 +772,7 @@ public abstract static class Option<T> implements Iterable<T> {
public abstract T get();

public static <T> None<T> None() {
return (None<T>) (Object) None;
return (None<T>) None;
}

public static <T> Some<T> Some(T value) {
Expand All @@ -782,7 +798,7 @@ public T get() {

@Override
public Iterator<T> iterator() {
return Collections.<T>emptyList().iterator();
return Collections.emptyIterator();
}

@Override
Expand Down
21 changes: 10 additions & 11 deletions framework/src/play/libs/Files.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

import play.Logger;
import play.exceptions.UnexpectedException;

Expand Down Expand Up @@ -74,7 +72,7 @@ public static void copy(File from, File to) {
}

try {
FileUtils.copyFile(from, to);
java.nio.file.Files.copy(from.toPath(), to.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -118,9 +116,9 @@ public static boolean deleteDirectory(File path) {

public static boolean copyDir(File from, File to) {
try {
FileUtils.copyDirectory(from, to);
IO.copyDirectory(from, to);
return true;
} catch (IOException e) {
} catch (Exception e) {
return false;
}
}
Expand Down Expand Up @@ -151,10 +149,11 @@ public static void unzip(File from, File to) {

public static void zip(File directory, File zipFile) {
try {
try (FileOutputStream os = new FileOutputStream(zipFile)) {
try (ZipOutputStream zos = new ZipOutputStream(os)) {
zipDirectory(directory, directory, zos);
}
try (
FileOutputStream os = new FileOutputStream(zipFile);
ZipOutputStream zos = new ZipOutputStream(os)
) {
zipDirectory(directory, directory, zos);
}
} catch (Exception e) {
throw new UnexpectedException(e);
Expand Down Expand Up @@ -221,7 +220,7 @@ static void zipDirectory(File root, File directory, ZipOutputStream zos) throws
String path = item.getAbsolutePath().substring(root.getAbsolutePath().length() + 1);
ZipEntry anEntry = new ZipEntry(path);
zos.putNextEntry(anEntry);
IOUtils.copyLarge(fis, zos);
fis.transferTo(zos);
}
}
}
Expand Down
Loading