Skip to content

Commit df485ff

Browse files
committed
Merge branch 'bug-9981'
2 parents ad44b86 + 415ba33 commit df485ff

File tree

7 files changed

+164
-30
lines changed

7 files changed

+164
-30
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class SilverpeasSetupPlugin implements Plugin<Project> {
122122

123123
project.tasks.create(INSTALL.name, SilverpeasInstallationTask) {
124124
it.deploymentDir = extension.deploymentDir
125+
it.settings = extension.config.settings
125126
it.distDir = extension.distDir
126127
it.developmentMode = extension.developmentMode
127128
it.jboss = jBossServer

src/main/groovy/org/silverpeas/setup/api/JBossServer.groovy

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import org.apache.commons.io.FilenameUtils
2727
import org.apache.commons.lang3.SystemUtils
2828

2929
import java.nio.file.Files
30+
import java.nio.file.Path
3031
import java.nio.file.Paths
3132
import java.util.concurrent.TimeoutException
3233
import java.util.regex.Matcher
@@ -337,9 +338,11 @@ class JBossServer {
337338

338339
/**
339340
* Adds the artifact located at the specified path into the deployment repository of this JBoss
340-
* server under the specified name and deploys it by using the Management API. If it is already
341-
* registered, nothing is done.
342-
* Once added, the artifact can be undeployed and deployed again on demand.
341+
* server and deploys it by using the Management API. The unique name with which the artifact
342+
* will be identified is the name of the artifact itself. The name of the runtime context under
343+
* which the artifact could be accessed once deployed is the name of the artifact itself.
344+
* If it is already registered, nothing is done.
345+
* Once added, the artifact can be deployed and undeployed again on demand.
343346
* A JBoss/Wildfly instance should be running.
344347
* @param artifactPath the path of the artifact to add.
345348
* @throws RuntimeException if the adding of the artifact failed.
@@ -351,27 +354,46 @@ class JBossServer {
351354

352355
/**
353356
* Adds the artifact located at the specified path into the deployment repository of this JBoss
354-
* server under the specified name and deploys it by using the Management API. If it is already
355-
* registered, nothing is done.
357+
* server under the specified runtime context by using the Management API. The unique name with
358+
* which the artifact will be identified is the name of the artifact itself.
359+
* If it is already registered, nothing is done.
360+
* Once added, the artifact can be undeployed and deployed again on demand.
361+
* A JBoss/Wildfly instance should be running.
362+
* @param artifactPath the path of the artifact to add.
363+
* @param context the runtime context under which the artifact could be accessed once deployed.
364+
* @throws RuntimeException if the adding of the artifact failed.
365+
*/
366+
void add(String artifactPath, String context) throws RuntimeException {
367+
String artifactName = FilenameUtils.getName(artifactPath)
368+
add(artifactPath, artifactName, context)
369+
}
370+
371+
/**
372+
* Adds the artifact located at the specified path into the deployment repository of this JBoss
373+
* server under the specified runtime context and with the specified unique name by using the
374+
* Management API. If it
375+
* is already registered, nothing is done.
356376
* Once added, the artifact can be undeployed and deployed again on demand.
357377
* A JBoss/Wildfly instance should be running.
358378
* @param artifactPath the path of the artifact to add.
379+
* @param context the runtime context under which the artifact will be deployed into this server.
359380
* @throws RuntimeException if the adding of the artifact failed.
360381
*/
361-
void add(String artifactPath, String artifactName) throws RuntimeException {
362-
String unixArtifactPath = FilenameUtils.separatorsToUnix(artifactPath);
363-
boolean archive = Files.isRegularFile(Paths.get(unixArtifactPath))
364-
if (!isInDeployments(artifactName)) {
382+
void add(String artifactPath, String name, String context) throws RuntimeException {
383+
String normalizedArtifactPath = FilenameUtils.separatorsToUnix(artifactPath);
384+
Path artifactTruePath = Paths.get(normalizedArtifactPath)
385+
boolean archive = Files.isRegularFile(artifactTruePath)
386+
if (!isInDeployments(name)) {
365387
Process proc = executeCliCommand(
366-
"/deployment=${artifactName}:add(runtime-name=${artifactName},content=[{path=>${unixArtifactPath},archive=${archive}}])",
388+
"/deployment=${name}:add(runtime-name=${context},content=[{path=>${normalizedArtifactPath},archive=${archive}}])",
367389
SystemUtils.IS_OS_WINDOWS);
368390
proc.waitFor()
369-
if (proc.exitValue() != 0 || !isInDeployments(artifactName)) {
370-
throw new RuntimeException("Adding of ${artifactName} in JBoss failed with exit code " +
391+
if (proc.exitValue() != 0 || !isInDeployments(name)) {
392+
throw new RuntimeException("Adding of ${name} in JBoss failed with exit code " +
371393
"${proc.exitValue()} and message ${proc.in.text}")
372394
}
373395
} else {
374-
logger.info "${artifactName} is already added in JBoss"
396+
logger.info "${name} is already added in JBoss"
375397
}
376398
}
377399

src/main/groovy/org/silverpeas/setup/installation/SilverpeasInstallationTask.groovy

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import org.silverpeas.setup.api.FileLogger
3232
import org.silverpeas.setup.api.JBossServer
3333

3434
import static org.silverpeas.setup.construction.SilverpeasConstructionTask.SILVERPEAS_WAR
35-
3635
/**
3736
* A Gradle task to install the Web archive of the Silverpeas application into the JEE application
3837
* server.
@@ -44,6 +43,7 @@ class SilverpeasInstallationTask extends DefaultTask {
4443
File deploymentDir
4544
final Property<File> distDir = project.objects.property(File)
4645
final Property<Boolean> developmentMode = project.objects.property(Boolean)
46+
Map settings
4747
final FileLogger log = FileLogger.getLogger(this.name)
4848

4949
SilverpeasInstallationTask() {
@@ -76,22 +76,37 @@ class SilverpeasInstallationTask extends DefaultTask {
7676
it.into deploymentDir
7777
}
7878
try {
79-
deploymentDir.listFiles().sort().each { artifact ->
80-
log.info "(Re)Installation of ${artifact.name}"
81-
server.remove(artifact.name)
82-
server.add(artifact.path)
83-
server.deploy(artifact.name)
84-
log.info "(Re)Installation of ${artifact.name}: [OK]"
85-
}
86-
if (developmentMode.get()) {
87-
log.info '(Re)Installation of silverpeas.war as exploded (dev mode)'
88-
server.remove(SILVERPEAS_WAR)
89-
server.add(distDir.get().path, SILVERPEAS_WAR)
90-
server.deploy(SILVERPEAS_WAR)
91-
log.info '(Re)Installation of silverpeas.war as exploded (dev mode): [OK]'
92-
}
79+
installAdditionalArtifacts(server)
80+
installSilverpeas(server)
9381
} finally {
9482
server.stop()
9583
}
9684
}
85+
86+
private void installAdditionalArtifacts(final JBossServer server) {
87+
deploymentDir.listFiles().sort().findAll { artifact ->
88+
artifact.name != SILVERPEAS_WAR
89+
}.each { artifact ->
90+
log.info "(Re)Installation of ${artifact.name}"
91+
server.remove(artifact.name)
92+
server.add(artifact.path)
93+
server.deploy(artifact.name)
94+
log.info "(Re)Installation of ${artifact.name}: [OK]"
95+
}
96+
}
97+
98+
private void installSilverpeas(final JBossServer server) {
99+
String name = 'silverpeas.war'
100+
String context = settings.SILVERPEAS_CONTEXT + '.war'
101+
File silverpeas = new File(deploymentDir.path, SILVERPEAS_WAR)
102+
if (developmentMode.get()) {
103+
name += ' as exploded (dev mode)'
104+
silverpeas = distDir.get()
105+
}
106+
log.info "(Re)Installation of ${name}"
107+
server.remove(SILVERPEAS_WAR)
108+
server.add(silverpeas.path, SILVERPEAS_WAR, context)
109+
server.deploy(SILVERPEAS_WAR)
110+
log.info "(Re)Installation of ${name}: [OK]"
111+
}
97112
}

src/main/resources/default_config.properties

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ SILVERPEAS_CONTENT_LANGUAGES=fr
8080
## WARNING, ERROR.
8181
SILVERPEAS_LOGGING_LEVEL=WARNING
8282

83+
## The name of the application context under which Silverpeas will be deployed.
84+
## It defines the path in the URL at which Silverpeas is accessible in the Web. For instance:
85+
### ${SERVER_URL}/${SILVERPEAS_CONTEXT} (http://localhost:8000/silverpeas with the default values).
86+
## Usually, you don't need to change this value.
87+
SILVERPEAS_CONTEXT = silverpeas
88+
8389
####################################################################################################
8490
## The properties to initialize the JVM.
8591
####################################################################################################
@@ -91,7 +97,7 @@ JVM_OPTS=
9197
## Application Server configuration.
9298
####################################################################################################
9399

94-
## The URL of the platform to identify itself when it cannot do it itself (used when behind a proxy)
100+
## The URL of the platform to use by itself when it cannot identify it (used when behind a proxy)
95101
SERVER_URL=http://localhost:8000
96102

97103
## The HTTP port at which incoming requests are listened by the application server

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.gradle.testfixtures.ProjectBuilder
55
import org.silverpeas.setup.test.TestSetUp
66

77
import static org.silverpeas.setup.api.SilverpeasSetupTaskNames.CONFIGURE_SILVERPEAS
8+
89
/**
910
* Test the case of the configuration of Silverpeas performed by a dedicated Gradle task.
1011
* @author mmoquillon
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package org.silverpeas.setup.installation
2+
3+
import groovy.mock.interceptor.MockFor
4+
import org.gradle.api.Project
5+
import org.gradle.testfixtures.ProjectBuilder
6+
import org.silverpeas.setup.api.JBossServer
7+
import org.silverpeas.setup.test.TestSetUp
8+
9+
import static org.silverpeas.setup.api.SilverpeasSetupTaskNames.INSTALL
10+
/**
11+
* Test the case of the installation of Silverpeas performed by a dedicated Gradle task.
12+
* @author mmoquillon
13+
*/
14+
class SilverpeasInstallationTaskTest extends GroovyTestCase {
15+
16+
private Project project
17+
protected TestSetUp testSetUp
18+
19+
@Override
20+
void setUp() {
21+
super.setUp()
22+
23+
testSetUp = TestSetUp.setUp()
24+
25+
System.setProperty('SILVERPEAS_HOME', testSetUp.resourcesDir)
26+
System.setProperty('JBOSS_HOME', testSetUp.resourcesDir)
27+
28+
project = ProjectBuilder.builder().build()
29+
project.apply plugin: 'silversetup'
30+
31+
project.silversetup.logging.logDir = new File(project.buildDir, 'log')
32+
project.silversetup.logging.useLogger = false
33+
}
34+
35+
void testInstallJustSilverpeas() {
36+
SilverpeasInstallationTask task = project.tasks.findByPath(INSTALL.name)
37+
def mock = new MockFor(JBossServer)
38+
39+
mock.demand.with {
40+
isStartingOrRunning { false }
41+
start { }
42+
remove { a -> a == 'silverpeas.war' }
43+
add { a, b, c -> b == 'silverpeas.war' }
44+
deploy { a -> a == 'silverpeas.war' }
45+
stop { }
46+
}
47+
48+
def jboss = mock.proxyInstance()
49+
task.jboss.set(jboss)
50+
task.install()
51+
52+
mock.verify(jboss)
53+
}
54+
55+
void testInstall() {
56+
SilverpeasInstallationTask task = project.tasks.findByPath(INSTALL.name)
57+
58+
File jackrabbit = new File(task.deploymentDir, 'jackrabbit-jca.rar')
59+
jackrabbit.createNewFile()
60+
61+
def mock = new MockFor(JBossServer)
62+
mock.demand.with {
63+
isStartingOrRunning { false }
64+
start { }
65+
66+
remove { a -> a == jackrabbit.name }
67+
add { a -> a == jackrabbit.path }
68+
deploy { a -> a == jackrabbit.name }
69+
70+
remove { a -> a == 'silverpeas.war' }
71+
add { a, b, c -> b == 'silverpeas.war' }
72+
deploy { a -> a == 'silverpeas.war' }
73+
74+
stop { }
75+
}
76+
77+
def jboss = mock.proxyInstance()
78+
task.jboss.set(jboss)
79+
task.install()
80+
81+
mock.verify(jboss)
82+
}
83+
}

src/test/resources/configuration/config.properties

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@
8080
## WARNING, ERROR.
8181
#SILVERPEAS_LOGGING_LEVEL=WARNING
8282

83+
## The name of the application context under which Silverpeas will be deployed.
84+
## It defines the path in the URL at which Silverpeas is accessible in the Web. For instance:
85+
### ${SERVER_URL}/${SILVERPEAS_CONTEXT} (http://localhost:8000/silverpeas with the default values).
86+
## Usually, you don't need to change this value.
87+
#SILVERPEAS_CONTEXT = silverpeas
88+
8389
####################################################################################################
8490
## The properties to initialize the JVM.
8591
####################################################################################################
@@ -91,7 +97,7 @@
9197
## Application Server configuration.
9298
####################################################################################################
9399

94-
## The URL of the platform to identify itself when it cannot do it itself (used when behind a proxy)
100+
## The URL of the platform to use by itself when it cannot identify it (used when behind a proxy)
95101
#SERVER_URL=http://localhost:8000
96102

97103
## The HTTP port at which incoming requests are listened by the application server

0 commit comments

Comments
 (0)