Skip to content

Commit

Permalink
Handle subdirectories and composite builds for gme-repos inclusion
Browse files Browse the repository at this point in the history
  • Loading branch information
rnc committed May 28, 2024
1 parent 9e01b77 commit 5189fd8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,12 @@ public void ensureAlignmentFileCreated() throws IOException, URISyntaxException,
});
});

//verify that dummy.gradle now includes the gme-repos.gradle injection
final File extraGradleFile = projectRoot.toPath().resolve("gradle/dummy.gradle").toFile();
//verify that dummy.gradle and another.gradle now includes the gme-repos.gradle injection
File extraGradleFile = projectRoot.toPath().resolve("gradle/dummy.gradle").toFile();
assertThat(extraGradleFile).exists();
assertThat(FileUtils.readLines(extraGradleFile, Charset.defaultCharset()))
.filteredOn(l -> l.trim().equals(AlignmentTask.APPLY_GME_REPOS)).hasSize(1);
extraGradleFile = projectRoot.toPath().resolve("gradle/subdirectory/another.gradle").toFile();
assertThat(extraGradleFile).exists();
assertThat(FileUtils.readLines(extraGradleFile, Charset.defaultCharset()))
.filteredOn(l -> l.trim().equals(AlignmentTask.APPLY_GME_REPOS)).hasSize(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// this is used in order to test that gme-repos.gradle gets injected
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'de.thetaphi:forbiddenapis:2.5'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,11 @@ public class AlignmentTask extends DefaultTask {
/**
* The groovy code to apply the {@link AlignmentTask#GME_REPOS gme-repos.gradle} build script.
*/
public static final String APPLY_GME_REPOS = "buildscript { apply from: new File(buildscript.getSourceFile().getParentFile(), \""
+ GME_REPOS + "\"), to: buildscript }";
// Can't use the path of the build script as it may be in a subdirectory. Further it may be included from via
// a composite build which alters the root path.
public static final String APPLY_GME_REPOS = "buildscript { apply from: new File((gradle.getParent() == null ? gradle : gradle.getParent()).startParameter.getCurrentDir(), \"gradle/"
+ GME_REPOS
+ "\"), to: buildscript }";
/**
* The task name {@code generateAlignmentMetadata}.
*/
Expand Down

0 comments on commit 5189fd8

Please sign in to comment.