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 all 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
12 changes: 12 additions & 0 deletions docs/installLiberty.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ This will get version 19.0.0.11 of `com.ibm.websphere.appserver.runtime:wlp-webP
}
```

#### Override installDir

In gradle.properties:
```
liberty.installDir=<path to installed wlp>
```

From the command line:
```
gradle build -Pliberty.installDir=<path to installed wlp>
```

#### Using Maven artifact

Use the [dependencies block](#dependencies) to specify the name of the repository artifact that contains your custom Liberty server or use one of the provided artifacts on [The Central Repository](http://search.maven.org/#search%7Cga%7C1%7Ccom.ibm.websphere.appserver.runtime).
Expand Down
2 changes: 1 addition & 1 deletion docs/libertyExtensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The [deploy](deploy.md), [undeploy](undeploy.md), [libertyPackage](libertyPackag
| --------- | ---- | ----- | ----------- | ---------|
| baseDir | String | 3.0 | The base installation directory. The actual installation directory of WebSphere Liberty server will be `${baseDir}/wlp`. The default value is `${project.buildDir}`. This was moved from the properties in the `install` block in version 3.0.| No |
| cacheDir | String | 3.0 | The directory used for caching downloaded files such as the license or `.jar` files. The default value is `${java.io.tmpdir}/wlp-cache`. This was moved from the properties in the `install` block in version 3.0.| No |
| installDir | String | 1.0 | Path to the WebSphere Liberty server installation `wlp` directory. To use a pre-installed version of Liberty, set this property to the path of the Liberty `wlp` directory, including `wlp` in the path. | No |
| installDir | String | 1.0 | Path to the WebSphere Liberty server installation `wlp` directory. To use a pre-installed version of Liberty, set this property to the path of the Liberty `wlp` directory, including `wlp` in the path. Additionally, `installDir` can be specified in the `gradle.properties` file or from the [command line](installLiberty.md#override-installDir). | No |
| outputDir | String | 1.0 | Deprecated. Value of the `${wlp_output_dir}` variable. The default value is `${installDir}/usr/servers/${serverName}`. This parameter has moved to the `server` block. | No |
| runtime | Properties | 3.0 | For overriding the `group`, `name` or `version` of the `libertyRuntime` installed from The Central Repository. The default runtime artifact is the latest version of `io.openliberty:openliberty-kernel`.
| userDir | String | 1.0 | Value of the `${wlp_user_dir}` variable. The default value is `${installDir}/usr/`. | No |
Expand Down
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.")
}
}