Skip to content

Commit

Permalink
[ISSUE apache#1054] Build caching optimizations (apache#4689)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
samotleriche authored Jan 3, 2024
1 parent 3642be0 commit 0be4c76
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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**'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0be4c76

Please sign in to comment.