-
Notifications
You must be signed in to change notification settings - Fork 38.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Break dependency between TestCompiler and AOT
This commit improves `TestCompiler` with a `with` function that allows to customize a test compiler instance. Rather than `TestCompiler` knowing about `TestGenerationContext`, the latter implements the function so that it can be passed as is. See gh-29175
- Loading branch information
Showing
17 changed files
with
108 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
.../src/main/java/org/springframework/aot/test/generate/GeneratedFilesTestCompilerUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2002-2022 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 org.springframework.aot.test.generate; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.springframework.aot.generate.GeneratedFiles.Kind; | ||
import org.springframework.aot.generate.InMemoryGeneratedFiles; | ||
import org.springframework.core.test.tools.ClassFile; | ||
import org.springframework.core.test.tools.ResourceFile; | ||
import org.springframework.core.test.tools.SourceFile; | ||
import org.springframework.core.test.tools.TestCompiler; | ||
|
||
/** | ||
* {@link TestCompiler} utilities for generated files. | ||
* | ||
* @author Stephane Nicoll | ||
* @since 6.0 | ||
*/ | ||
public abstract class GeneratedFilesTestCompilerUtils { | ||
|
||
/** | ||
* Apply the specified {@link InMemoryGeneratedFiles} to the specified {@link TestCompiler}. | ||
* @param testCompiler the compiler to configure | ||
* @param generatedFiles the generated files to apply | ||
* @return a new {@link TestCompiler} instance configured with the generated files | ||
*/ | ||
public static TestCompiler configure(TestCompiler testCompiler, InMemoryGeneratedFiles generatedFiles) { | ||
List<SourceFile> sourceFiles = new ArrayList<>(); | ||
generatedFiles.getGeneratedFiles(Kind.SOURCE).forEach( | ||
(path, inputStreamSource) -> sourceFiles.add(SourceFile.of(inputStreamSource))); | ||
List<ResourceFile> resourceFiles = new ArrayList<>(); | ||
generatedFiles.getGeneratedFiles(Kind.RESOURCE).forEach( | ||
(path, inputStreamSource) -> resourceFiles.add(ResourceFile.of(path, inputStreamSource))); | ||
List<ClassFile> classFiles = new ArrayList<>(); | ||
generatedFiles.getGeneratedFiles(Kind.CLASS).forEach( | ||
(path, inputStreamSource) -> classFiles.add(ClassFile.of( | ||
ClassFile.toClassName(path), inputStreamSource))); | ||
return testCompiler.withSources(sourceFiles).withResources(resourceFiles).withClasses(classFiles); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters