Merge branch '1.5.x'
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -68,6 +68,7 @@ import org.springframework.boot.configurationsample.specific.InnerClassRootConfi
|
||||
import org.springframework.boot.configurationsample.specific.InvalidAccessorProperties;
|
||||
import org.springframework.boot.configurationsample.specific.InvalidDoubleRegistrationProperties;
|
||||
import org.springframework.boot.configurationsample.specific.SimplePojo;
|
||||
import org.springframework.boot.junit.compiler.TestCompiler;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -1,126 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2015 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
|
||||
*
|
||||
* http://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 org.springframework.boot.configurationprocessor;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.annotation.processing.Processor;
|
||||
import javax.tools.JavaCompiler;
|
||||
import javax.tools.JavaCompiler.CompilationTask;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.StandardJavaFileManager;
|
||||
import javax.tools.StandardLocation;
|
||||
import javax.tools.ToolProvider;
|
||||
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
/**
|
||||
* Wrapper to make the {@link JavaCompiler} easier to use in tests.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class TestCompiler {
|
||||
|
||||
public static final File ORIGINAL_SOURCE_FOLDER = new File("src/test/java");
|
||||
|
||||
private final JavaCompiler compiler;
|
||||
|
||||
private final StandardJavaFileManager fileManager;
|
||||
|
||||
private final File outputLocation;
|
||||
|
||||
public TestCompiler(TemporaryFolder temporaryFolder) throws IOException {
|
||||
this(ToolProvider.getSystemJavaCompiler(), temporaryFolder);
|
||||
}
|
||||
|
||||
public TestCompiler(JavaCompiler compiler, TemporaryFolder temporaryFolder)
|
||||
throws IOException {
|
||||
this.compiler = compiler;
|
||||
this.fileManager = compiler.getStandardFileManager(null, null, null);
|
||||
this.outputLocation = temporaryFolder.newFolder();
|
||||
Iterable<? extends File> temp = Arrays.asList(this.outputLocation);
|
||||
this.fileManager.setLocation(StandardLocation.CLASS_OUTPUT, temp);
|
||||
this.fileManager.setLocation(StandardLocation.SOURCE_OUTPUT, temp);
|
||||
}
|
||||
|
||||
public TestCompilationTask getTask(Collection<File> sourceFiles) {
|
||||
Iterable<? extends JavaFileObject> javaFileObjects = this.fileManager
|
||||
.getJavaFileObjectsFromFiles(sourceFiles);
|
||||
return getTask(javaFileObjects);
|
||||
}
|
||||
|
||||
public TestCompilationTask getTask(Class<?>... types) {
|
||||
Iterable<? extends JavaFileObject> javaFileObjects = getJavaFileObjects(types);
|
||||
return getTask(javaFileObjects);
|
||||
}
|
||||
|
||||
private TestCompilationTask getTask(
|
||||
Iterable<? extends JavaFileObject> javaFileObjects) {
|
||||
return new TestCompilationTask(this.compiler.getTask(null, this.fileManager, null,
|
||||
null, null, javaFileObjects));
|
||||
}
|
||||
|
||||
public File getOutputLocation() {
|
||||
return this.outputLocation;
|
||||
}
|
||||
|
||||
private Iterable<? extends JavaFileObject> getJavaFileObjects(Class<?>... types) {
|
||||
File[] files = new File[types.length];
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
files[i] = getFile(types[i]);
|
||||
}
|
||||
return this.fileManager.getJavaFileObjects(files);
|
||||
}
|
||||
|
||||
protected File getFile(Class<?> type) {
|
||||
return new File(getSourceFolder(), sourcePathFor(type));
|
||||
}
|
||||
|
||||
public static String sourcePathFor(Class<?> type) {
|
||||
return type.getName().replace(".", "/") + ".java";
|
||||
}
|
||||
|
||||
protected File getSourceFolder() {
|
||||
return ORIGINAL_SOURCE_FOLDER;
|
||||
}
|
||||
|
||||
/**
|
||||
* A compilation task.
|
||||
*/
|
||||
public static class TestCompilationTask {
|
||||
|
||||
private final CompilationTask task;
|
||||
|
||||
public TestCompilationTask(CompilationTask task) {
|
||||
this.task = task;
|
||||
}
|
||||
|
||||
public void call(Processor... processors) {
|
||||
this.task.setProcessors(Arrays.asList(processors));
|
||||
if (!this.task.call()) {
|
||||
throw new IllegalStateException("Compilation failed");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -33,16 +33,14 @@ import java.util.Set;
|
||||
import org.junit.Assert;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import org.springframework.boot.configurationprocessor.TestCompiler.TestCompilationTask;
|
||||
import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata;
|
||||
import org.springframework.boot.configurationsample.ConfigurationProperties;
|
||||
import org.springframework.boot.configurationsample.NestedConfigurationProperty;
|
||||
import org.springframework.boot.junit.compiler.TestCompiler;
|
||||
import org.springframework.boot.junit.compiler.TestCompiler.TestCompilationTask;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
|
||||
import static org.springframework.boot.configurationprocessor.TestCompiler.ORIGINAL_SOURCE_FOLDER;
|
||||
import static org.springframework.boot.configurationprocessor.TestCompiler.sourcePathFor;
|
||||
|
||||
/**
|
||||
* A TestProject contains a copy of a subset of test sample code.
|
||||
* <p>
|
||||
@@ -96,7 +94,7 @@ public class TestProject {
|
||||
}
|
||||
|
||||
public File getSourceFile(Class<?> type) {
|
||||
return new File(this.sourceFolder, sourcePathFor(type));
|
||||
return new File(this.sourceFolder, TestCompiler.sourcePathFor(type));
|
||||
}
|
||||
|
||||
public ConfigurationMetadata fullBuild() {
|
||||
@@ -192,7 +190,7 @@ public class TestProject {
|
||||
* code.
|
||||
*/
|
||||
private File getOriginalSourceFile(Class<?> type) {
|
||||
return new File(ORIGINAL_SOURCE_FOLDER, sourcePathFor(type));
|
||||
return new File(TestCompiler.SOURCE_FOLDER, TestCompiler.sourcePathFor(type));
|
||||
}
|
||||
|
||||
private static void putContents(File targetFile, String contents)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -33,8 +33,8 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import org.springframework.boot.configurationprocessor.TestCompiler;
|
||||
import org.springframework.boot.configurationsample.fieldvalues.FieldValues;
|
||||
import org.springframework.boot.junit.compiler.TestCompiler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user