Skip to content

Commit

Permalink
⬆️ 升级gradle至7.4 (#103)
Browse files Browse the repository at this point in the history
Signed-off-by: henry <[email protected]>
  • Loading branch information
henry-hub authored Mar 5, 2022
1 parent 36eca23 commit 09f5de3
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 20 deletions.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package pub.ihub.process.boot;

import cn.hutool.core.io.file.PathUtil;
import com.google.auto.service.AutoService;
import lombok.Getter;
import net.ltgt.gradle.incap.IncrementalAnnotationProcessor;
Expand All @@ -27,10 +28,12 @@
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.tools.FileObject;
import javax.tools.JavaFileManager;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -42,7 +45,9 @@

import static java.nio.charset.StandardCharsets.UTF_8;
import static javax.lang.model.SourceVersion.RELEASE_11;
import static javax.tools.StandardLocation.CLASS_OUTPUT;
import static javax.tools.StandardLocation.SOURCE_OUTPUT;
import static javax.tools.StandardLocation.SOURCE_PATH;
import static pub.ihub.process.boot.SpringFactoriesProcessor.AUTO_CONFIG_POST_PROCESSOR_ANNOTATION;
import static pub.ihub.process.boot.SpringFactoriesProcessor.CONFIGURATION_ANNOTATION;

Expand Down Expand Up @@ -77,14 +82,26 @@ protected void addFactories(String key, Element element) {

@Override
protected void processingOver() throws IOException {
String resources = mFiler.getResource(CLASS_OUTPUT, "", FACTORIES_RESOURCE).getName()
.replace("classes\\java", "resources");
if (PathUtil.exists(Path.of(resources), true)) {
note("The %s is exists, ignore generate spring.factories.", resources);
return;
}
// 生成spring.factories
List<String> lines = new ArrayList<>();
lines.add("# Generated by ihub-process https://ihub.pub");
factories.forEach((k, v) -> {
lines.add(k + "=\\");
lines.add(String.join(",\\\n", v));
});
FileObject resource = mFiler.createResource(SOURCE_OUTPUT, "", FACTORIES_RESOURCE);
writeFactoriesResource(CLASS_OUTPUT, lines);
// annotationProcessor也保存一份便于代码阅读
writeFactoriesResource(SOURCE_OUTPUT, lines);
}

private void writeFactoriesResource(JavaFileManager.Location location, List<String> lines) throws IOException {
FileObject resource = mFiler.createResource(location, "", FACTORIES_RESOURCE);
try (OutputStream out = resource.openOutputStream()) {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, UTF_8));
for (String line : lines) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@
import com.google.testing.compile.Compilation;
import com.google.testing.compile.Compiler;
import com.google.testing.compile.JavaFileObjects;
import lombok.SneakyThrows;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.mockito.Answers;
import org.mockito.Mockito;

import javax.annotation.processing.Filer;
import javax.annotation.processing.Messager;
import java.io.IOException;

import static com.google.testing.compile.CompilationSubject.assertThat;
import static javax.tools.StandardLocation.SOURCE_OUTPUT;
import static javax.tools.StandardLocation.CLASS_OUTPUT;

/**
* @author liheng
Expand All @@ -45,9 +52,9 @@ void configEnvironment() {
.contains("public final class DemoConfigPostProcessor extends BaseConfigEnvironmentPostProcessor");
}

@DisplayName("自动配置注解处理器测试-成功")
@DisplayName("spring.factories配置处理器-成功")
@Test
void configuration() {
void springFactories() {
Compilation compilation =
Compiler.javac()
.withProcessors(new SpringFactoriesProcessor())
Expand All @@ -57,7 +64,7 @@ void configuration() {
JavaFileObjects.forResource("test/OtherConfigPostProcessor.java"));
assertThat(compilation).succeededWithoutWarnings();
assertThat(compilation)
.generatedFile(SOURCE_OUTPUT, "META-INF/spring.factories")
.generatedFile(CLASS_OUTPUT, "META-INF/spring.factories")
.contentsAsUtf8String()
.containsMatch("# Generated by ihub-process https://ihub.pub[\\S\\s]*" +
"org.springframework.boot.autoconfigure.EnableAutoConfiguration=[\\S\\s]*" +
Expand All @@ -67,4 +74,18 @@ void configuration() {
"test.OtherConfigPostProcessor");
}

@SneakyThrows
@DisplayName("spring.factories配置处理器-配置已存在")
@Test
void springFactoriesExists() {
new SpringFactoriesProcessor() {
@Override
protected void processingOver() throws IOException {
mFiler = Mockito.mock(Filer.class, Answers.RETURNS_MOCKS);
messager = Mockito.mock(Messager.class);
super.processingOver();
}
}.processingOver();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@
public abstract class BaseDocProcessor extends BaseAstProcessor {

protected void processEntity(JCTree ident) {
note(ident.type.toString());
TypeElement element = elementUtils.getTypeElement(ident.type.toString());
note("%s", element);
JCTree.JCClassDecl tree = javacTrees.getTree(element);
if (null != tree) {
appendSchema(element, tree);
Expand Down

This file was deleted.

6 changes: 0 additions & 6 deletions ihub-starter/doc/src/test/resources/META-INF/spring.factories

This file was deleted.

9 changes: 9 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
pluginManagement {
repositories {
gradlePluginPortal()
maven {
url 'https://repo.spring.io/release'
}
}
}

plugins {
id 'pub.ihub.plugin.ihub-settings' version '1.2.2'
}
Expand Down

0 comments on commit 09f5de3

Please sign in to comment.