Skip to content

Commit a3e3f28

Browse files
committed
Improve the task construct by specifying its ultimate goal: generate the web.xml descriptor (among others JEE ones)
1 parent da036f6 commit a3e3f28

File tree

5 files changed

+38
-20
lines changed

5 files changed

+38
-20
lines changed

src/main/groovy/org/silverpeas/setup/SilverpeasSetupPlugin.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class SilverpeasSetupPlugin implements Plugin<Project> {
182182
/**
183183
* Setup the predefined Build Gradle task to the peculiar behaviour of the plugin that is to
184184
* generate the Silverpeas Collaborative portal application from the extracted content of the
185-
* software bundles that made up a Silverpeas distribution.
185+
* software bundles that make up a Silverpeas distribution.
186186
* @param project the Gradle project
187187
* @param extension the project extension of the plugin
188188
*/
@@ -196,8 +196,8 @@ class SilverpeasSetupPlugin implements Plugin<Project> {
196196
extension.installation.distDir.get().exists()
197197
}
198198
outputs.upToDateWhen {
199-
boolean ok = extension.installation.distDir.get().exists() &&
200-
Files.exists(Paths.get(extension.installation.distDir.get().path, 'WEB-INF', 'web.xml'))
199+
Path webDescriptor = Paths.get(extension.installation.distDir.get().path, 'WEB-INF', 'web.xml')
200+
boolean ok = Files.exists(webDescriptor)
201201
if (!extension.installation.developmentMode.get()) {
202202
ok = ok && Files.exists(
203203
Paths.get(project.buildDir.path, SilverpeasConstructionTask.SILVERPEAS_WAR))

src/main/groovy/org/silverpeas/setup/construction/SilverpeasBuilder.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ class SilverpeasBuilder {
220220
fileName.endsWith('war.xml')
221221
}
222222
})
223-
if (mainWebXmlFiles.size() != 1) {
223+
if (mainWebXmlFiles == null || mainWebXmlFiles.size() != 1) {
224224
throw new IllegalStateException('No main web descriptor found!')
225225
}
226226

src/main/groovy/org/silverpeas/setup/construction/SilverpeasConstructionTask.groovy

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@
2323
*/
2424
package org.silverpeas.setup.construction
2525

26-
27-
import org.gradle.api.tasks.Internal
28-
import org.gradle.api.tasks.Nested
29-
import org.gradle.api.tasks.TaskAction
26+
import org.gradle.api.tasks.*
3027
import org.silverpeas.setup.SilverpeasInstallationProperties
3128
import org.silverpeas.setup.api.FileLogger
3229
import org.silverpeas.setup.api.SilverpeasSetupTask
3330

3431
import java.nio.file.Files
32+
import java.nio.file.Path
3533
import java.nio.file.Paths
3634

3735
/**
@@ -54,25 +52,34 @@ class SilverpeasConstructionTask extends SilverpeasSetupTask {
5452
description = 'Assemble and build the Silverpeas Collaborative Web Application'
5553
group = 'Build'
5654
onlyIf {
57-
precondition()
55+
preconditionSatisfied()
5856
}
5957
outputs.upToDateWhen {
60-
isUpToDate()
58+
allIsGenerated()
6159
}
6260
}
6361

64-
def precondition() {
65-
!installation.distDir.get().exists() && !installation.dsDriversDir.get().exists()
62+
def preconditionSatisfied() {
63+
!areBundlesAssembled() || !isWebDescriptorGenerated()
6664
}
6765

68-
def isUpToDate() {
69-
boolean ok = installation.distDir.get().exists() && installation.dsDriversDir.get().exists()
66+
def allIsGenerated() {
67+
boolean ok = areBundlesAssembled() && isWebDescriptorGenerated()
7068
if (!installation.developmentMode.get()) {
7169
ok = ok && Files.exists(Paths.get(project.buildDir.path, SILVERPEAS_WAR))
7270
}
7371
return ok
7472
}
7573

74+
private boolean isWebDescriptorGenerated() {
75+
Path webDescriptor = Paths.get(installation.distDir.get().path, 'WEB-INF', 'web.xml')
76+
return Files.exists(webDescriptor)
77+
}
78+
79+
private boolean areBundlesAssembled() {
80+
return installation.distDir.get().exists() && installation.dsDriversDir.get().exists()
81+
}
82+
7683
@TaskAction
7784
void construct() {
7885
if (!installation.distDir.get().exists()) {
@@ -81,11 +88,13 @@ class SilverpeasConstructionTask extends SilverpeasSetupTask {
8188
if (!installation.dsDriversDir.get().exists()) {
8289
installation.dsDriversDir.get().mkdirs()
8390
}
91+
8492
SilverpeasBuilder builder = new SilverpeasBuilder(project, log)
8593
builder.driversDir = installation.dsDriversDir.get()
8694
builder.silverpeasHome = silverpeasHome
8795
builder.developmentMode = installation.developmentMode.get()
8896
builder.settings = settings
97+
8998
builder.extractSoftwareBundles(installation.bundles, installation.distDir.get())
9099
builder.generateSilverpeasApplication(installation.distDir.get())
91100
}

src/test/groovy/org/silverpeas/setup/configuration/SilverpeasConfigurationTaskTest.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class SilverpeasConfigurationTaskTest {
1919

2020
@Before
2121
void setUp() {
22-
context = TestContext.create().setUpSystemEnv().initGradleProject()
22+
context = TestContext.create().setUpSystemEnv().initGradleProject(['construct'])
2323
}
2424

2525
@After
@@ -43,7 +43,7 @@ class SilverpeasConfigurationTaskTest {
4343
assertTheConfigContextIsCorrectlySaved(testProperties)
4444
}
4545

46-
void assertTheCustomerWorkflowIsCorrectlyConfigured(TestProperties props) {
46+
static void assertTheCustomerWorkflowIsCorrectlyConfigured(TestProperties props) {
4747
def before = props.xmlconf.before
4848
def after = props.xmlconf.after
4949
assert after.adefCreateSupplier.actions.action.find { it.@name == 'Archiver'}
@@ -127,7 +127,7 @@ class SilverpeasConfigurationTaskTest {
127127
after.scheduler['timeoutSchedule'] != before.scheduler['timeoutSchedule']
128128
}
129129

130-
void assertTheConfigContextIsCorrectlySaved(TestProperties props) {
130+
static void assertTheConfigContextIsCorrectlySaved(TestProperties props) {
131131
assert props.configContext.before['status is'] == props.configContext.after['status is']
132132
assert props.configContext.before['installed at'] == props.configContext.after['installed at']
133133
assert props.configContext.before['updated at'] == props.configContext.after['updated at']

src/test/groovy/org/silverpeas/setup/test/TestContext.groovy

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,20 @@ class TestContext {
8181
/**
8282
* Initializes in the filesystem a Gradle project that uses the plugin. The Gradle project
8383
* can then be ran by using the Gradle runner returned by the TestContext#getGradleRunner method.
84+
* @param previousInvokedTasks a list of task names that have to be considered as yet invoked. As such, the resources
85+
* these tasks should created will be set up in order to avoid them to be again invoked through tasks dependency
86+
* graph.
8487
* @return itself.
8588
*/
86-
TestContext initGradleProject() {
87-
Files.createDirectories(Paths.get(resourcesDir, 'build', 'drivers'))
88-
Files.createDirectories(Paths.get(resourcesDir, 'build', 'dist'))
89+
TestContext initGradleProject(List<String> previousInvokedTasks) {
90+
if (previousInvokedTasks.contains("assemble") || previousInvokedTasks.contains("construct")) {
91+
Files.createDirectories(Paths.get(resourcesDir, 'build', 'drivers'))
92+
Files.createDirectories(Paths.get(resourcesDir, 'build', 'dist', 'WEB-INF'))
93+
}
94+
if (previousInvokedTasks.contains("build") || previousInvokedTasks.contains("construct")) {
95+
Files.createFile(Paths.get(resourcesDir, 'build', 'dist', 'WEB-INF', 'web.xml'))
96+
}
97+
8998
Files.createFile(Paths.get(resourcesDir, 'settings.gradle'))
9099
.toFile()
91100
.text = """

0 commit comments

Comments
 (0)