mirror of
https://gitee.com/dcren/initializr.git
synced 2025-05-16 13:09:39 +08:00
Merge pull request #964 from tgeens
* pr/964: Polish "Clean root resource path if necessary" Clean root resource path if necessary Closes gh-964
This commit is contained in:
commit
d8a5be76f5
@ -24,6 +24,7 @@ import java.util.function.Predicate;
|
|||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||||
import org.springframework.util.FileCopyUtils;
|
import org.springframework.util.FileCopyUtils;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link ProjectContributor} that contributes all of the resources found beneath a root
|
* A {@link ProjectContributor} that contributes all of the resources found beneath a root
|
||||||
@ -45,7 +46,7 @@ public class MultipleResourcesProjectContributor implements ProjectContributor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MultipleResourcesProjectContributor(String rootResource, Predicate<String> executable) {
|
public MultipleResourcesProjectContributor(String rootResource, Predicate<String> executable) {
|
||||||
this.rootResource = rootResource;
|
this.rootResource = StringUtils.trimTrailingCharacter(rootResource, '/');
|
||||||
this.executable = executable;
|
this.executable = executable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.spring.initializr.generator.project.contributor;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link MultipleResourcesProjectContributor}.
|
||||||
|
*
|
||||||
|
* @author Toon Geens
|
||||||
|
* @author Stephane Nicoll
|
||||||
|
*/
|
||||||
|
class MultipleResourcesProjectContributorTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void contribute(@TempDir Path directory) throws IOException {
|
||||||
|
new MultipleResourcesProjectContributor("classpath:/data/multi").contribute(directory);
|
||||||
|
assertThat(directory.resolve("one.properties")).exists().isRegularFile();
|
||||||
|
assertThat(directory.resolve("two.xml")).exists().isRegularFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void contributeWithTrailingSlash(@TempDir Path directory) throws IOException {
|
||||||
|
new MultipleResourcesProjectContributor("classpath:/data/multi/").contribute(directory);
|
||||||
|
assertThat(directory.resolve("one.properties")).exists().isRegularFile();
|
||||||
|
assertThat(directory.resolve("two.xml")).exists().isRegularFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
test=1
|
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<test>
|
||||||
|
<two/>
|
||||||
|
</test>
|
Loading…
Reference in New Issue
Block a user