Skip to content

Commit abc9c1e

Browse files
authored
fix(gradle): fix typo in gradle build script (#127)
Substitution macro for gradle user home in gradle build script did not have a matching replacer value. Added replacer value and updated test.
1 parent cd94ae1 commit abc9c1e

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

rockcraft/src/main/java/com/canonical/rockcraft/builder/BuildRockCrafter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ private void writeResourceFiles() throws IOException {
171171

172172
private String replaceMacros(String content) {
173173
HashMap<String, String> replacements = new HashMap<>();
174+
replacements.put("gradle-user-home", "export GRADLE_USER_HOME=${WORKDIR}/.gradle");
174175
replacements.put("goal",
175176
Arrays.stream(((BuildRockcraftOptions) getOptions()).getBuildGoals()).
176177
collect(Collectors.joining(" ")));

rockcraft/src/test/java/com/canonical/rockcraft/builder/BuildRockCrafterTest.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.List;
2525
import java.util.Map;
2626

27+
import static org.junit.jupiter.api.Assertions.assertFalse;
2728
import static org.junit.jupiter.api.Assertions.assertTrue;
2829
import org.junit.jupiter.api.Test;
2930
import org.junit.jupiter.api.io.TempDir;
@@ -61,16 +62,25 @@ public void testGenerateRock() throws IOException {
6162
assertTrue(parts.containsKey("maven-cache"));
6263
assertTrue(parts.containsKey("build-tool"));
6364
}
64-
Path buildFile = tempDir.toPath().resolve("build-maven.sh");
65+
String result = readFile("build-maven.sh");
66+
assertTrue(result.contains("GOAL=package"), "Goals should be replaced");
67+
assertFalse(result.contains("!!"));
68+
69+
result = readFile("build-gradle.sh");
70+
assertFalse(result.contains("!!"));
71+
72+
assertTrue(true, "The build should succeed");
73+
}
74+
75+
private String readFile(String file) throws IOException {
76+
Path buildFile = tempDir.toPath().resolve(file);
77+
StringBuilder result = new StringBuilder();
6578
try (BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(buildFile.toFile())))) {
66-
StringBuilder result = new StringBuilder();
6779
String line;
6880
while ((line = r.readLine())!= null){
6981
result.append(line);
7082
}
71-
assertTrue(result.toString().contains("GOAL=package"), "Goals should be replaced");
7283
}
73-
74-
assertTrue(true, "The build should succeed");
84+
return result.toString();
7585
}
7686
}

0 commit comments

Comments
 (0)