Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add installDir project property detection #651

Merged
merged 5 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions src/main/groovy/io/openliberty/tools/gradle/Liberty.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -169,27 +169,28 @@ class Liberty implements Plugin<Project> {
}

private static File getInstallDir(Project project) {
if (project.liberty.installDir == null) {
if (project.liberty.baseDir == null) {
return new File(project.buildDir, 'wlp')
} else {
return new File(project.liberty.baseDir, 'wlp')
}
if (project.hasProperty('liberty.installDir')) {
dshimo marked this conversation as resolved.
Show resolved Hide resolved
File installDir = checkAndAppendWlp(project, new File(project.projectDir, project.getProperties().get('liberty.installDir')))
project.getLogger().info("installDir project property detected. Using ${installDir.getCanonicalPath()}.")
return installDir
} else if (project.liberty.installDir == null) {
if (project.liberty.baseDir == null) {
return new File(project.buildDir, 'wlp')
} else {
return new File(project.liberty.baseDir, 'wlp')
}
} else { // installDir is specified
String installDirPath = checkAndAppendWlp(project)
File installDir = new File(installDirPath)

return installDir;
return checkAndAppendWlp(project, new File(project.liberty.installDir));
}
}

private static String checkAndAppendWlp(Project project) {
String installDir = project.liberty.installDir
if (installDir.endsWith("wlp")) {
private static File checkAndAppendWlp(Project project, File installDir) {
if (installDir.toString().endsWith("wlp")) {
return installDir
} else { // not valid wlp dir
project.getLogger().warn(MessageFormat.format("The installDir {0} path does not reference a wlp folder. Using path {0}/wlp instead.", installDir))
return new File(installDir, 'wlp').toString()
return new File(installDir, 'wlp')
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class InstallLiberty_installDir_missing_wlp_Test extends AbstractIntegrationTest
static File resourceDir = new File("build/resources/test/install-dir-property-test/installDir-missing-wlp")

static File buildDir = new File(integTestDir, "/InstallLiberty_installDir_missing_wlp")
static String expectedPropertyDir = new File(buildDir, 'installDir-valid-install/build/wlp').getCanonicalPath()

static String buildFilename = "build.gradle"

@BeforeClass
Expand All @@ -45,4 +47,29 @@ class InstallLiberty_installDir_missing_wlp_Test extends AbstractIntegrationTest
String output = result.getOutput()
assert output.contains("path does not reference a wlp folder") : "Expected warning about installDir path not containing wlp"
}

@Test
void test_installLiberty_installDir_cli_property_wlp() {
BuildResult result = GradleRunner.create()
.withProjectDir(buildDir)
.forwardOutput()
.withArguments('installLiberty', '-Pliberty.installDir=installDir-valid-install/build/wlp', '-i', '-s')
dshimo marked this conversation as resolved.
Show resolved Hide resolved
.build()

String output = result.getOutput()
assert output.contains("installDir project property detected. Using $expectedPropertyDir")
}

@Test
void test_installLiberty_installDir_cli_property() {
BuildResult result = GradleRunner.create()
.withProjectDir(buildDir)
.forwardOutput()
.withArguments('installLiberty', '-Pliberty.installDir=installDir-valid-install/build', '-i', '-s')
.build()

String output = result.getOutput()
assert output.contains("installDir project property detected. Using $expectedPropertyDir".drop(4))
assert output.contains("Using path $expectedPropertyDir instead.")
}
}