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

Configure clean to depend on libertyStop #824

Merged
merged 1 commit into from
May 19, 2023
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corporation 2018, 2021.
* (C) Copyright IBM Corporation 2018, 2023.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -79,6 +79,13 @@ public class LibertyTasks {
project.cleanDirs {
dependsOn 'libertyStop'
}

// The war, ear and java plugins all apply the base plugin which defines the clean task.
// This code ensures the libertyStop task is invoked before clean so that a Liberty server is not orphaned.
if (project.plugins.hasPlugin('base')) {
def tasks = project.tasks
tasks.getByName('clean').dependsOn 'libertyStop'
}

project.prepareFeature {
dependsOn 'installLiberty'
Expand Down
33 changes: 22 additions & 11 deletions src/main/groovy/io/openliberty/tools/gradle/tasks/CleanTask.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corporation 2015, 2019.
* (C) Copyright IBM Corporation 2015, 2023.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,15 +29,26 @@ class CleanTask extends AbstractServerTask {

@TaskAction
void cleanDirectories() {
def params = buildLibertyMap(project);
params.put('logs', server.cleanDir.logs)
params.put('workarea', server.cleanDir.workarea)
params.put('dropins', server.cleanDir.dropins)
params.put('apps', server.cleanDir.apps)
params.remove('timeout')
project.ant.taskdef(name: 'cleanDir',
classname: 'io.openliberty.tools.ant.CleanTask',
classpath: project.buildscript.configurations.classpath.asPath)
project.ant.cleanDir(params)
// first make sure there is a Liberty installation that needs cleaning as a previous clean may have occurred
File installDir = getInstallDir(project)
if (isLibertyInstalled(installDir)) {
def params = buildLibertyMap(project);
params.put('logs', server.cleanDir.logs)
params.put('workarea', server.cleanDir.workarea)
params.put('dropins', server.cleanDir.dropins)
params.put('apps', server.cleanDir.apps)
params.remove('timeout')
project.ant.taskdef(name: 'cleanDir',
classname: 'io.openliberty.tools.ant.CleanTask',
classpath: project.buildscript.configurations.classpath.asPath)
project.ant.cleanDir(params)
} else {
logger.info("There is no Liberty server to clean. The runtime has not been installed.")
}
}

private boolean isLibertyInstalled(File installDir) {
boolean installationExists = installDir.exists() && new File(installDir,"lib/ws-launch.jar").exists()
return installationExists
}
}
41 changes: 38 additions & 3 deletions src/test/groovy/io/openliberty/tools/gradle/LibertyTest.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corporation 2015, 2017.
* (C) Copyright IBM Corporation 2015, 2023.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -147,9 +147,44 @@ class LibertyTest extends AbstractIntegrationTest{
try{
runTasks(buildDir, 'cleanDirs')
} catch (Exception e) {
throw new AssertionError ("Fail on task Clean. "+e)
throw new AssertionError ("Fail on task cleanDirs. "+e)
}

try{
runTasks(buildDir, 'libertyStart')
} catch (Exception e) {
throw new AssertionError ("Fail on task libertyStart after cleanDirs. "+e)
}

try{
runTasks(buildDir, 'clean')
} catch (Exception e) {
throw new AssertionError ("Fail on task clean while Liberty server is running "+e)
}

try{
runTasks(buildDir, 'clean')
} catch (Exception e) {
throw new AssertionError ("Fail on task clean after clean. "+e)
}
}

try{
runTasks(buildDir, 'cleanDirs')
} catch (Exception e) {
throw new AssertionError ("Fail on task cleanDirs after clean. "+e)
}

try{
runTasks(buildDir, 'libertyStart')
} catch (Exception e) {
throw new AssertionError ("Fail on task libertyStart after second clean. "+e)
}

try{
runTasks(buildDir, 'libertyStop')
} catch (Exception e) {
throw new AssertionError ("Fail on task libertyStop after libertyStart. "+e)
}
}

}
2 changes: 0 additions & 2 deletions src/test/resources/dev-test/basic-dev-project/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,3 @@ dependencies {
testImplementation "org.glassfish:javax.json:1.0.4"
testImplementation "javax.xml.bind:jaxb-api:2.3.1"
}

clean.dependsOn "libertyStop"
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,3 @@ dependencies {
testImplementation "org.glassfish:javax.json:1.0.4"
testImplementation "javax.xml.bind:jaxb-api:2.3.1"
}

clean.dependsOn "libertyStop"
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,3 @@ dependencies {
testImplementation "org.glassfish:javax.json:1.0.4"
testImplementation "javax.xml.bind:jaxb-api:2.3.1"
}

clean.dependsOn "libertyStop"
1 change: 1 addition & 0 deletions src/test/resources/liberty-test/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'liberty'
apply plugin: 'java'

buildscript {
repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,5 @@ liberty {
}
}

clean.dependsOn 'libertyStop'
deploy.dependsOn 'ear'
ear.dependsOn ':SampleEJB:jar', ':SampleWAR:war', ':SampleWAR2:war'
1 change: 0 additions & 1 deletion src/test/resources/loose-ear-test/ejb-ear/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,5 @@ liberty {
}
}

clean.dependsOn 'libertyStop'
deploy.dependsOn 'ear'
ear.dependsOn ':ejb-war:jar', ':ejb-war:war'
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,5 @@ liberty {
}
}

clean.dependsOn 'libertyStop'
deploy.dependsOn 'ear'
ear.dependsOn ':ejb-war:jar', ':ejb-war:war'