From 0be4c7696be2b0b63b7c5da145d15c79dd282d14 Mon Sep 17 00:00:00 2001 From: Tomas Leriche Date: Tue, 2 Jan 2024 19:28:48 -0800 Subject: [PATCH] [ISSUE #1054] Build caching optimizations (#4689) * remove checkstyleMain dependency on spotlessApply spotlessApply was reformatting files on every build causing cache misses. * limit the target of spotlessJava to just src java files * use a TempDir for testing the onChange method, changing file in place caused cache miss * enable gradle build cache --- build.gradle | 3 +-- .../common/file/WatchFileManagerTest.java | 20 +++++++++++++------ gradle.properties | 1 + 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index 6f56a72919..c8b371cf95 100644 --- a/build.gradle +++ b/build.gradle @@ -93,7 +93,6 @@ allprojects { .exclude('**/org/apache/eventmesh/connector/openfunction/client/EventMeshGrpcService**') .exclude('**/org/apache/eventmesh/connector/openfunction/client/CallbackServiceGrpc**') .exclude('**/org/apache/eventmesh/connector/jdbc/antlr**') - .dependsOn(spotlessApply) dependencies { repositories { @@ -110,7 +109,7 @@ allprojects { enforceCheck false java { target project.fileTree(project.projectDir) { - include '**/*.java' + include 'src/*/java/**/*.java' exclude '**/org/apache/eventmesh/**/protos**' exclude '**/org/apache/eventmesh/connector/openfunction/client/EventMeshGrpcService**' exclude '**/org/apache/eventmesh/connector/openfunction/client/CallbackServiceGrpc**' diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/file/WatchFileManagerTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/file/WatchFileManagerTest.java index 77f8baba69..8a3c024ab8 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/file/WatchFileManagerTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/file/WatchFileManagerTest.java @@ -24,37 +24,45 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.nio.file.Files; import java.util.Properties; import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; public class WatchFileManagerTest { + @TempDir + File tempConfigDir; + @Test public void testWatchFile() throws IOException, InterruptedException { String file = WatchFileManagerTest.class.getResource("/configuration.properties").getFile(); File f = new File(file); + File tempConfigFile = new File(tempConfigDir, "configuration.properties"); + Files.copy(f.toPath(), tempConfigFile.toPath()); + final FileChangeListener fileChangeListener = new FileChangeListener() { @Override public void onChanged(FileChangeContext changeContext) { - Assertions.assertEquals(f.getName(), changeContext.getFileName()); - Assertions.assertEquals(f.getParent(), changeContext.getDirectoryPath()); + Assertions.assertEquals(tempConfigFile.getName(), changeContext.getFileName()); + Assertions.assertEquals(tempConfigFile.getParent(), changeContext.getDirectoryPath()); } @Override public boolean support(FileChangeContext changeContext) { - return changeContext.getWatchEvent().context().toString().contains(f.getName()); + return changeContext.getWatchEvent().context().toString().contains(tempConfigFile.getName()); } }; - WatchFileManager.registerFileChangeListener(f.getParent(), fileChangeListener); + WatchFileManager.registerFileChangeListener(tempConfigFile.getParent(), fileChangeListener); Properties properties = new Properties(); - properties.load(new BufferedReader(new FileReader(file))); + properties.load(new BufferedReader(new FileReader(tempConfigFile))); properties.setProperty("eventMesh.server.newAdd", "newAdd"); - FileWriter fw = new FileWriter(file); + FileWriter fw = new FileWriter(tempConfigFile); properties.store(fw, "newAdd"); ThreadUtils.sleep(500, TimeUnit.MILLISECONDS); diff --git a/gradle.properties b/gradle.properties index 2298245ecc..64cfbe2fab 100644 --- a/gradle.properties +++ b/gradle.properties @@ -33,3 +33,4 @@ signEnabled=false org.gradle.warning.mode=none org.gradle.jvmargs=-Xmx4096m -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +org.gradle.caching=true \ No newline at end of file