Skip to content

Commit

Permalink
Merge branch '2.5.x' into 3.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
jameskleeh committed Apr 27, 2021
2 parents 51fb418 + 4b5138a commit 4802797
Show file tree
Hide file tree
Showing 81 changed files with 2,438 additions and 669 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/corretto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:
- name: Install tar && gzip
run: yum install -y tar gzip
- uses: actions/checkout@v2
- uses: actions/cache@v2.1.4
- uses: actions/cache@v2.1.5
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-micronaut-core-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: |
${{ runner.os }}-micronaut-core-gradle-
- uses: actions/cache@v2.1.4
- uses: actions/cache@v2.1.5
with:
path: ~/.gradle/wrapper
key: ${{ runner.os }}-micronaut-core-wrapper-${{ hashFiles('**/*.gradle') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependency-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2.1.4
- uses: actions/cache@v2.1.5
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
java: ['8', '11', '15']
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2.1.4
- uses: actions/cache@v2.1.5
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2.1.4
- uses: actions/cache@v2.1.5
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
Expand Down
7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:6.1.0'
classpath "io.micronaut.build.internal:micronaut-gradle-plugins:3.0.3"
classpath "io.micronaut.build.internal:micronaut-gradle-plugins:3.0.4"
classpath "gradle.plugin.org.aim42:htmlSanityCheck:$htmlSanityCheckVersion"
classpath 'javax.xml.bind:jaxb-api:2.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
Expand Down Expand Up @@ -519,6 +519,11 @@ ext {
group : 'io.micronaut.reactor',
name : 'micronaut-reactor'
],
'micronaut.problem': [
version: micronautProblemJsonVersion,
group : 'io.micronaut.problem',
modules: ['micronaut-problem-json']
],
reactor : [
version: reactorVersion,
group : 'io.projectreactor',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
Expand Down Expand Up @@ -74,10 +75,57 @@ public DefaultClassPathResourceLoader(ClassLoader classLoader, String basePath)
*/
@Override
public Optional<InputStream> getResourceAsStream(String path) {
if (!isDirectory(path)) {
return Optional.ofNullable(classLoader.getResourceAsStream(prefixPath(path)));
URL url = classLoader.getResource(prefixPath(path));
if (url != null) {
try {
URI uri = url.toURI();
if (uri.getScheme().equals("jar")) {
synchronized (DefaultClassPathResourceLoader.class) {
FileSystem fileSystem = null;
try {
try {
fileSystem = FileSystems.getFileSystem(uri);
} catch (FileSystemNotFoundException e) {
//no-op
}
if (fileSystem == null || !fileSystem.isOpen()) {
fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap(), classLoader);
}
Path pathObject = fileSystem.getPath(path);
if (Files.isDirectory(pathObject)) {
return Optional.empty();
}
return Optional.of(new ByteArrayInputStream(Files.readAllBytes(pathObject)));
} finally {
if (fileSystem != null && fileSystem.isOpen()) {
try {
fileSystem.close();
} catch (IOException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Error shutting down JAR file system [" + fileSystem + "]: " + e.getMessage(), e);
}
}
}
}
}
} else if (uri.getScheme().equals("file")) {
Path pathObject = Paths.get(uri);
if (Files.isDirectory(pathObject)) {
return Optional.empty();
}
return Optional.of(Files.newInputStream(pathObject));
}
} catch (URISyntaxException | IOException | ProviderNotFoundException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Error establishing whether path is a directory: " + e.getMessage(), e);
}
}
}
return Optional.empty();
// fallback to less sophisticated approach
if (path.indexOf('.') == -1) {
return Optional.empty();
}
return Optional.ofNullable(classLoader.getResourceAsStream(prefixPath(path)));
}

/**
Expand Down Expand Up @@ -160,9 +208,8 @@ private boolean isDirectory(String path) {
try {
URI uri = url.toURI();
Path pathObject;
synchronized (DefaultClassPathResourceLoader.class) {

if (uri.getScheme().equals("jar")) {
if (uri.getScheme().equals("jar")) {
synchronized (DefaultClassPathResourceLoader.class) {
FileSystem fileSystem = null;
try {
try {
Expand All @@ -187,11 +234,10 @@ private boolean isDirectory(String path) {
}
}
}
} else if (uri.getScheme().equals("file")) {
pathObject = Paths.get(uri);
return pathObject == null || Files.isDirectory(pathObject);
}

} else if (uri.getScheme().equals("file")) {
pathObject = Paths.get(uri);
return pathObject == null || Files.isDirectory(pathObject);
}
} catch (URISyntaxException | IOException | ProviderNotFoundException e) {
if (LOG.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.ServiceConfigurationError;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
* <p>Variation of {@link java.util.ServiceLoader} that allows soft loading and conditional loading of
Expand Down Expand Up @@ -200,19 +200,25 @@ public boolean hasNext() {
URL url = serviceConfigs.nextElement();
try {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()))) {
List<String> lines = reader.lines()
.filter(line -> line.length() != 0 && line.charAt(0) != '#')
.filter(condition)
.map(line -> {
int i = line.indexOf('#');
if (i > -1) {
line = line.substring(0, i);
}
return line;
})
.collect(Collectors.toList());
List<String> lines = new LinkedList<>();
while (true) {
String line = reader.readLine();
if (line == null) {
break;
}
if (line.length() == 0 || line.charAt(0) == '#') {
continue;
}
if (!condition.test(line)) {
continue;
}
int i = line.indexOf('#');
if (i > -1) {
line = line.substring(0, i);
}
lines.add(line);
}
unprocessed = lines.iterator();

}
} catch (IOException | UncheckedIOException e) {
// ignore, can't do anything here and can't log because class used in compiler
Expand Down
18 changes: 10 additions & 8 deletions core/src/main/java/io/micronaut/core/naming/NameUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,16 @@ public static String hyphenate(String name, boolean lowerCase) {
* @return The camel case form
*/
public static String dehyphenate(String name) {
return Arrays.stream(name.split("-"))
.map(str -> {
if (str.length() > 0 && Character.isLetter(str.charAt(0))) {
return Character.toUpperCase(str.charAt(0)) + str.substring(1);
}
return str;
})
.collect(Collectors.joining(""));
StringBuilder sb = new StringBuilder(name.length());
for (String token : StringUtils.splitOmitEmptyStrings(name, '-')) {
if (token.length() > 0 && Character.isLetter(token.charAt(0))) {
sb.append(Character.toUpperCase(token.charAt(0)));
sb.append(token.substring(1));
} else {
sb.append(token);
}
}
return sb.toString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public AnnotationMetadata getAnnotationMetadata() {
@Override
public Optional<Argument<?>> getFirstTypeVariable() {
if (!typeParameters.isEmpty()) {
return typeParameters.values().stream().findFirst();
return Optional.of(typeParameters.values().iterator().next());
}
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ final class RuntimeTypeInformation {
* @return True if does
*/
static boolean isSpecifiedSingle(AnnotationMetadataProvider annotationMetadata) {
return TYPE_INFORMATION_PROVIDERS.stream().anyMatch(provider -> provider.isSpecifiedSingle(annotationMetadata));
for (TypeInformationProvider provider : TYPE_INFORMATION_PROVIDERS) {
if (provider.isSpecifiedSingle(annotationMetadata)) {
return true;
}
}
return false;
}

/**
Expand All @@ -55,7 +60,12 @@ static boolean isSpecifiedSingle(AnnotationMetadataProvider annotationMetadata)
* @return True if it is single
*/
static boolean isSingle(Class<?> type) {
return TYPE_INFORMATION_PROVIDERS.stream().anyMatch(provider -> provider.isSingle(type));
for (TypeInformationProvider provider : TYPE_INFORMATION_PROVIDERS) {
if (provider.isSingle(type)) {
return true;
}
}
return false;
}

/**
Expand All @@ -64,7 +74,12 @@ static boolean isSingle(Class<?> type) {
* @return True if it is reactive
*/
static boolean isReactive(Class<?> type) {
return TYPE_INFORMATION_PROVIDERS.stream().anyMatch(provider -> provider.isReactive(type));
for (TypeInformationProvider provider : TYPE_INFORMATION_PROVIDERS) {
if (provider.isReactive(type)) {
return true;
}
}
return false;
}

/**
Expand All @@ -73,7 +88,12 @@ static boolean isReactive(Class<?> type) {
* @return True if it is completable
*/
static boolean isCompletable(Class<?> type) {
return TYPE_INFORMATION_PROVIDERS.stream().anyMatch(provider -> provider.isCompletable(type));
for (TypeInformationProvider provider : TYPE_INFORMATION_PROVIDERS) {
if (provider.isCompletable(type)) {
return true;
}
}
return false;
}

/**
Expand All @@ -84,6 +104,11 @@ static boolean isCompletable(Class<?> type) {
* @see TypeInformation#isWrapperType()
*/
static <T> boolean isWrapperType(Class<T> type) {
return TYPE_INFORMATION_PROVIDERS.stream().anyMatch(provider -> provider.isWrapperType(type));
for (TypeInformationProvider provider : TYPE_INFORMATION_PROVIDERS) {
if (provider.isWrapperType(type)) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ default Argument[] getTypeParameters() {
* @return Return the first type parameter if it is present
*/
default Optional<Argument<?>> getFirstTypeVariable() {
return getTypeVariables().values().stream().findFirst();
Map<String, Argument<?>> typeVariables = getTypeVariables();
if (!typeVariables.isEmpty()) {
return Optional.of(typeVariables.values().iterator().next());
}
return Optional.empty();
}

/**
Expand Down
13 changes: 13 additions & 0 deletions core/src/main/java/io/micronaut/core/util/ArrayUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.micronaut.core.annotation.Nullable;
import java.lang.reflect.Array;
import java.util.*;
import java.util.function.IntFunction;

/**
* Utility methods for working with arrays.
Expand Down Expand Up @@ -158,6 +159,18 @@ public static <T> Iterator<T> reverseIterator(T...array) {
}
}

/**
* Returns an array containing all of the elements in this collection, using the provided generator function to allocate the returned array.
*
* @param collection The collection
* @param <T> The create array function
* @return The array
*/
public static <T> T[] toArray(Collection<T> collection, IntFunction<T[]> createArrayFn) {
T[] array = createArrayFn.apply(collection.size());
return collection.toArray(array);
}

/**
* Iterator implementation used to efficiently expose contents of an
* Array as read-only iterator.
Expand Down
Loading

0 comments on commit 4802797

Please sign in to comment.