
com.github.robtimus.maven.plugins.resourcelist.ResourceListClass.template Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of resource-list-maven-plugin Show documentation
Show all versions of resource-list-maven-plugin Show documentation
A Maven plugin that can create lists of resources
The newest version!
package ${package};
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Generated;
@Generated("resource-list-maven-plugin")
${visibility}final class ${className} {
private static final String RESOURCE_LIST_RESOURCE = "/${resourceListFile}";
private static final ${className} ABSOLUTE = new ${className}(s -> "/" + s); //$NON-NLS-1$
private static final ${className} RELATIVE = new ${className}(UnaryOperator.identity());
private final UnaryOperator resourceModifier;
private ${className}(UnaryOperator resourceModifier) {
this.resourceModifier = resourceModifier;
}
${visibility}static ${className} absolute() {
return ABSOLUTE;
}
${visibility}static ${className} relative() {
return RELATIVE;
}
${visibility}Stream stream() {
BufferedReader reader = reader();
return reader.lines()
.onClose(() -> {
try {
reader.close();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
})
.map(resourceModifier);
}
${visibility}List list() {
try (BufferedReader reader = reader()) {
return reader.lines()
.map(resourceModifier)
.collect(Collectors.toList());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
${visibility}void forEach(Consumer super String> action) {
Objects.requireNonNull(action);
try (BufferedReader reader = reader()) {
reader.lines()
.map(resourceModifier)
.forEach(action);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
private BufferedReader reader() {
InputStream inputStream = getClass().getResourceAsStream(RESOURCE_LIST_RESOURCE);
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
return new BufferedReader(inputStreamReader);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy