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:
Stephane Nicoll 2019-07-25 13:47:02 +02:00
commit d8a5be76f5
4 changed files with 56 additions and 1 deletions

View File

@ -24,6 +24,7 @@ import java.util.function.Predicate;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.util.FileCopyUtils;
import org.springframework.util.StringUtils;
/**
* 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) {
this.rootResource = rootResource;
this.rootResource = StringUtils.trimTrailingCharacter(rootResource, '/');
this.executable = executable;
}

View File

@ -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();
}
}

View File

@ -0,0 +1 @@
test=1

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<test>
<two/>
</test>