|
|
@ -18,6 +18,7 @@ package org.springframework.boot.maven;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.function.Predicate;
|
|
|
|
|
|
|
|
|
|
|
|
import org.w3c.dom.Document;
|
|
|
|
import org.w3c.dom.Document;
|
|
|
|
import org.w3c.dom.Element;
|
|
|
|
import org.w3c.dom.Element;
|
|
|
@ -27,6 +28,7 @@ import org.w3c.dom.NodeList;
|
|
|
|
import org.springframework.boot.loader.tools.Layer;
|
|
|
|
import org.springframework.boot.loader.tools.Layer;
|
|
|
|
import org.springframework.boot.loader.tools.layer.CustomLayers;
|
|
|
|
import org.springframework.boot.loader.tools.layer.CustomLayers;
|
|
|
|
import org.springframework.boot.loader.tools.layer.application.FilteredResourceStrategy;
|
|
|
|
import org.springframework.boot.loader.tools.layer.application.FilteredResourceStrategy;
|
|
|
|
|
|
|
|
import org.springframework.boot.loader.tools.layer.application.LocationFilter;
|
|
|
|
import org.springframework.boot.loader.tools.layer.application.ResourceFilter;
|
|
|
|
import org.springframework.boot.loader.tools.layer.application.ResourceFilter;
|
|
|
|
import org.springframework.boot.loader.tools.layer.application.ResourceStrategy;
|
|
|
|
import org.springframework.boot.loader.tools.layer.application.ResourceStrategy;
|
|
|
|
import org.springframework.boot.loader.tools.layer.library.CoordinateFilter;
|
|
|
|
import org.springframework.boot.loader.tools.layer.library.CoordinateFilter;
|
|
|
@ -51,91 +53,77 @@ public class CustomLayersProvider {
|
|
|
|
for (int i = 0; i < nl.getLength(); i++) {
|
|
|
|
for (int i = 0; i < nl.getLength(); i++) {
|
|
|
|
Node node = nl.item(i);
|
|
|
|
Node node = nl.item(i);
|
|
|
|
if (node instanceof Element) {
|
|
|
|
if (node instanceof Element) {
|
|
|
|
Element ele = (Element) node;
|
|
|
|
processNode(layers, libraryStrategies, resourceStrategies, (Element) node);
|
|
|
|
String nodeName = ele.getNodeName();
|
|
|
|
|
|
|
|
if ("layers".equals(nodeName)) {
|
|
|
|
|
|
|
|
layers.addAll(getLayers(ele));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ("libraries".equals(nodeName)) {
|
|
|
|
|
|
|
|
libraryStrategies.addAll(getLibraryStrategies(ele.getChildNodes()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ("classes".equals(nodeName)) {
|
|
|
|
|
|
|
|
resourceStrategies.addAll(getResourceStrategies(ele.getChildNodes()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new CustomLayers(layers, resourceStrategies, libraryStrategies);
|
|
|
|
return new CustomLayers(layers, resourceStrategies, libraryStrategies);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<LibraryStrategy> getLibraryStrategies(NodeList nodes) {
|
|
|
|
private void processNode(List<Layer> layers, List<LibraryStrategy> libraryStrategies,
|
|
|
|
List<LibraryStrategy> strategy = new ArrayList<>();
|
|
|
|
List<ResourceStrategy> resourceStrategies, Element node) {
|
|
|
|
for (int i = 0; i < nodes.getLength(); i++) {
|
|
|
|
String nodeName = node.getNodeName();
|
|
|
|
Node item = nodes.item(i);
|
|
|
|
if ("layers".equals(nodeName)) {
|
|
|
|
if (item instanceof Element) {
|
|
|
|
layers.addAll(getLayers(node));
|
|
|
|
Element element = (Element) item;
|
|
|
|
}
|
|
|
|
String layer = element.getAttribute("layer");
|
|
|
|
NodeList contents = node.getChildNodes();
|
|
|
|
if ("layer-content".equals(element.getTagName())) {
|
|
|
|
if ("libraries".equals(nodeName)) {
|
|
|
|
List<LibraryFilter> filters = new ArrayList<>();
|
|
|
|
libraryStrategies.addAll(getStrategies(contents,
|
|
|
|
NodeList filterList = item.getChildNodes();
|
|
|
|
(StrategyFactory<LibraryFilter, LibraryStrategy>) FilteredLibraryStrategy::new,
|
|
|
|
if (filterList.getLength() == 0) {
|
|
|
|
CoordinateFilter::new, "coordinates"::equals));
|
|
|
|
throw new IllegalArgumentException("Filters for layer-content must not be empty.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ("classes".equals(nodeName)) {
|
|
|
|
for (int k = 0; k < filterList.getLength(); k++) {
|
|
|
|
resourceStrategies.addAll(getStrategies(contents,
|
|
|
|
Node filter = filterList.item(k);
|
|
|
|
(StrategyFactory<ResourceFilter, ResourceStrategy>) FilteredResourceStrategy::new,
|
|
|
|
if (filter instanceof Element) {
|
|
|
|
LocationFilter::new, "locations"::equals));
|
|
|
|
List<String> includeList = getPatterns((Element) filter, "include");
|
|
|
|
|
|
|
|
List<String> excludeList = getPatterns((Element) filter, "exclude");
|
|
|
|
|
|
|
|
addLibraryFilter(filters, filter, includeList, excludeList);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
strategy.add(new FilteredLibraryStrategy(layer, filters));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return strategy;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void addLibraryFilter(List<LibraryFilter> filters, Node filter, List<String> includeList,
|
|
|
|
private List<Layer> getLayers(Element element) {
|
|
|
|
List<String> excludeList) {
|
|
|
|
List<Layer> layers = new ArrayList<>();
|
|
|
|
if ("coordinates".equals(filter.getNodeName())) {
|
|
|
|
NodeList nodes = element.getChildNodes();
|
|
|
|
filters.add(new CoordinateFilter(includeList, excludeList));
|
|
|
|
for (int i = 0; i < nodes.getLength(); i++) {
|
|
|
|
|
|
|
|
Node node = nodes.item(i);
|
|
|
|
|
|
|
|
if (node instanceof Element) {
|
|
|
|
|
|
|
|
Element ele = (Element) node;
|
|
|
|
|
|
|
|
String nodeName = ele.getNodeName();
|
|
|
|
|
|
|
|
if ("layer".equals(nodeName)) {
|
|
|
|
|
|
|
|
layers.add(new Layer(ele.getTextContent()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return layers;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<ResourceStrategy> getResourceStrategies(NodeList strategies) {
|
|
|
|
private <T, E> List<T> getStrategies(NodeList nodes, StrategyFactory<E, T> strategyFactory,
|
|
|
|
List<ResourceStrategy> strategy = new ArrayList<>();
|
|
|
|
FilterFactory<E> filterFactory, Predicate<String> filterPredicate) {
|
|
|
|
for (int i = 0; i < strategies.getLength(); i++) {
|
|
|
|
List<T> contents = new ArrayList<>();
|
|
|
|
Node item = strategies.item(i);
|
|
|
|
for (int i = 0; i < nodes.getLength(); i++) {
|
|
|
|
List<ResourceFilter> filters = new ArrayList<>();
|
|
|
|
Node item = nodes.item(i);
|
|
|
|
if (item instanceof Element) {
|
|
|
|
if (item instanceof Element) {
|
|
|
|
Element element = (Element) item;
|
|
|
|
Element element = (Element) item;
|
|
|
|
String layer = element.getAttribute("layer");
|
|
|
|
|
|
|
|
if ("layer-content".equals(element.getTagName())) {
|
|
|
|
if ("layer-content".equals(element.getTagName())) {
|
|
|
|
NodeList filterList = item.getChildNodes();
|
|
|
|
NodeList filterList = item.getChildNodes();
|
|
|
|
if (filterList.getLength() == 0) {
|
|
|
|
if (filterList.getLength() == 0) {
|
|
|
|
throw new IllegalArgumentException("Filters for layer-content must not be empty.");
|
|
|
|
throw new IllegalArgumentException("Filters for layer-content must not be empty.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int k = 0; k < filterList.getLength(); k++) {
|
|
|
|
List<E> filters = new ArrayList<>();
|
|
|
|
Node filter = filterList.item(k);
|
|
|
|
for (int j = 0; j < filterList.getLength(); j++) {
|
|
|
|
if (filter instanceof Element) {
|
|
|
|
Node filterNode = filterList.item(j);
|
|
|
|
List<String> includeList = getPatterns((Element) filter, "include");
|
|
|
|
if (filterNode instanceof Element) {
|
|
|
|
List<String> excludeList = getPatterns((Element) filter, "exclude");
|
|
|
|
List<String> includeList = getPatterns((Element) filterNode, "include");
|
|
|
|
addFilter(filters, filter, includeList, excludeList);
|
|
|
|
List<String> excludeList = getPatterns((Element) filterNode, "exclude");
|
|
|
|
|
|
|
|
if (filterPredicate.test(filterNode.getNodeName())) {
|
|
|
|
|
|
|
|
E filter = filterFactory.getFilter(includeList, excludeList);
|
|
|
|
|
|
|
|
filters.add(filter);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
strategy.add(new FilteredResourceStrategy(layer, filters));
|
|
|
|
String layer = element.getAttribute("layer");
|
|
|
|
|
|
|
|
contents.add(strategyFactory.getStrategy(layer, filters));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return strategy;
|
|
|
|
return contents;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void addFilter(List<ResourceFilter> filters, Node filter, List<String> includeList,
|
|
|
|
|
|
|
|
List<String> excludeList) {
|
|
|
|
|
|
|
|
if ("locations".equals(filter.getNodeName())) {
|
|
|
|
|
|
|
|
filters.add(
|
|
|
|
|
|
|
|
new org.springframework.boot.loader.tools.layer.application.LocationFilter(includeList, excludeList));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<String> getPatterns(Element element, String key) {
|
|
|
|
private List<String> getPatterns(Element element, String key) {
|
|
|
@ -150,20 +138,16 @@ public class CustomLayersProvider {
|
|
|
|
return values;
|
|
|
|
return values;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<Layer> getLayers(Element element) {
|
|
|
|
interface StrategyFactory<E, T> {
|
|
|
|
List<Layer> layers = new ArrayList<>();
|
|
|
|
|
|
|
|
NodeList nl = element.getChildNodes();
|
|
|
|
T getStrategy(String layer, List<E> filters);
|
|
|
|
for (int i = 0; i < nl.getLength(); i++) {
|
|
|
|
|
|
|
|
Node node = nl.item(i);
|
|
|
|
}
|
|
|
|
if (node instanceof Element) {
|
|
|
|
|
|
|
|
Element ele = (Element) node;
|
|
|
|
interface FilterFactory<E> {
|
|
|
|
String nodeName = ele.getNodeName();
|
|
|
|
|
|
|
|
if ("layer".equals(nodeName)) {
|
|
|
|
E getFilter(List<String> includes, List<String> excludes);
|
|
|
|
layers.add(new Layer(ele.getTextContent()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return layers;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|