Skip to content

Commit 3e04924

Browse files
committed
Update to take into account changes in the way the memory setting is
performed now in Wildfly 24. JVM_OPTS is now by default set with some parameters to optimize the execution of Wildfly.
1 parent 488e6d6 commit 3e04924

File tree

3 files changed

+67
-27
lines changed

3 files changed

+67
-27
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class SilverpeasSetupPlugin implements Plugin<Project> {
6262

6363
@Override
6464
void apply(Project project) {
65-
SilverpeasSetupExtension extension = createSilverpeasSetupExtention(project)
65+
SilverpeasSetupExtension extension = createSilverpeasSetupExtension(project)
6666

6767
// once the whole asked Silverpeas setup's tasks are done, the configuration context is saved
6868
project.gradle.buildFinished {
@@ -191,7 +191,7 @@ class SilverpeasSetupPlugin implements Plugin<Project> {
191191
* @param project the Gradle project that uses the plugin to setup a Silverpeas distribution
192192
* @return the project extension of the plugin
193193
*/
194-
private SilverpeasSetupExtension createSilverpeasSetupExtention(Project project) {
194+
private SilverpeasSetupExtension createSilverpeasSetupExtension(Project project) {
195195
SilverpeasSetupExtension extension = project.extensions.create(EXTENSION, SilverpeasSetupExtension, project)
196196
extension.settings = loadConfigurationProperties(extension.config.configurationHome.get())
197197
completeSettings(extension.settings, extension)

src/main/groovy/org/silverpeas/setup/configuration/JBossConfigurationTask.groovy

Lines changed: 64 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import org.silverpeas.setup.api.SilverpeasSetupTask
3535
import java.nio.file.Files
3636
import java.nio.file.Paths
3737
import java.util.regex.Matcher
38+
3839
/**
3940
* A Gradle task to configure a JBoss/Wildfly instance from some CLI scripts to be ready to run
4041
* Silverpeas.
@@ -81,42 +82,24 @@ class JBossConfigurationTask extends SilverpeasSetupTask {
8182
server.start(adminOnly: true) // start in admin only to perform only configuration tasks
8283
setUpJDBCDriver()
8384
processConfigurationFiles()
84-
} catch(Exception ex) {
85+
} catch (Exception ex) {
8586
log.error 'Error while configuring JBoss/Wildfly', ex
8687
throw new TaskExecutionException(this, ex)
8788
} finally {
8889
server.stop() // stop the admin mode
8990
}
9091
}
9192

92-
private void setUpJVMOptions() {
93+
void setUpJVMOptions() {
9394
log.info 'JVM options setting'
9495
new File(jboss.jbossHome, 'bin').listFiles(new FilenameFilter() {
9596
@Override
9697
boolean accept(final File dir, final String name) {
97-
return name.endsWith('.conf') || name.endsWith('.conf.bat')
98+
return name.startsWith('standalone.conf') || name.startsWith('domain.conf')
9899
}
99100
}).each { conf ->
100-
String jvmOpts; def regexp
101-
if (conf.name.endsWith('.bat')) {
102-
jvmOpts = "set \"JAVA_OPTS=-Xmx${settings.JVM_RAM_MAX} ${settings.JVM_OPTS}"
103-
regexp = /\s*set\s+"JAVA_OPTS=-Xm.+/
104-
} else {
105-
jvmOpts =
106-
"JAVA_OPTS=\"-Xmx${settings.JVM_RAM_MAX} -Djava.net.preferIPv4Stack=true ${settings.JVM_OPTS}"
107-
regexp = /\s*JAVA_OPTS="-Xm.+/
108-
}
109-
jvmOpts += '"'
110-
conf.withReader {
111-
it.transformLine(new FileWriter("${conf.path}.tmp")) { line ->
112-
Matcher matcher = line =~ regexp
113-
if (matcher.matches()) {
114-
line = jvmOpts
115-
}
116-
line
117-
}
118-
}
119-
File modifiedConf = new File("${conf.path}.tmp")
101+
File modifiedConf = conf.text.contains('JBOSS_JAVA_SIZING') ?
102+
replaceJavaOpts(conf) : replaceOldJavaOpts(conf)
120103
modifiedConf.setReadable(conf.canRead())
121104
modifiedConf.setWritable(conf.canWrite())
122105
modifiedConf.setExecutable(conf.canExecute())
@@ -125,6 +108,63 @@ class JBossConfigurationTask extends SilverpeasSetupTask {
125108
}
126109
}
127110

111+
protected File replaceJavaOpts(File conf) {
112+
String jvmOpts, jvmSize
113+
def regexpOpts, regexpSize
114+
String optsToSet = settings.JVM_OPTS ? " ${settings.JVM_OPTS}" : ''
115+
if (conf.name.endsWith('.bat')) {
116+
jvmSize = " set \"JBOSS_JAVA_SIZING=-Xmx${settings.JVM_RAM_MAX}\""
117+
jvmOpts = "set \"JAVA_OPTS=%JBOSS_JAVA_SIZING%${optsToSet}\""
118+
regexpSize = /\s*set\s+"JBOSS_JAVA_SIZING=-Xm.+/
119+
regexpOpts = /\s*set\s+"JAVA_OPTS=%JBOSS_JAVA_SIZING%"/
120+
} else {
121+
jvmSize = " JBOSS_JAVA_SIZING=\"-Xmx${settings.JVM_RAM_MAX}\""
122+
jvmOpts = " JAVA_OPTS=\"\$JBOSS_JAVA_SIZING -Djava.net.preferIPv4Stack=true${optsToSet}\""
123+
regexpSize = /\s*JBOSS_JAVA_SIZING="-Xm.+/
124+
regexpOpts = /\s*JAVA_OPTS="[$]JBOSS_JAVA_SIZING.+/
125+
126+
}
127+
String destFilename = "${conf.path}.tmp"
128+
conf.withReader {
129+
it.transformLine(new FileWriter(destFilename)) { line ->
130+
Matcher sizeMatcher = line =~ regexpSize
131+
Matcher optsMatcher = line =~ regexpOpts
132+
if (sizeMatcher.matches()) {
133+
line = jvmSize
134+
} else if (optsMatcher.matches()) {
135+
line = jvmOpts
136+
}
137+
line
138+
}
139+
}
140+
return new File(destFilename)
141+
}
142+
143+
protected File replaceOldJavaOpts(File conf) {
144+
String jvmOpts
145+
def regexp
146+
String optsToSet = settings.JVM_OPTS ? " ${settings.JVM_OPTS}" : ''
147+
if (conf.name.endsWith('.bat')) {
148+
jvmOpts = "set \"JAVA_OPTS=-Xmx${settings.JVM_RAM_MAX}${optsToSet}\""
149+
regexp = /\s*set\s+"JAVA_OPTS=-Xm.+/
150+
} else {
151+
jvmOpts =
152+
"JAVA_OPTS=\"-Xmx${settings.JVM_RAM_MAX} -Djava.net.preferIPv4Stack=true${optsToSet}\""
153+
regexp = /\s*JAVA_OPTS="-Xm.+/
154+
}
155+
String destFilename = "${conf.path}.tmp"
156+
conf.withReader {
157+
it.transformLine(new FileWriter("${conf.path}.tmp")) { line ->
158+
Matcher matcher = line =~ regexp
159+
if (matcher.matches()) {
160+
line = jvmOpts
161+
}
162+
line
163+
}
164+
}
165+
return new File(destFilename)
166+
}
167+
128168
private void installAdditionalModules() {
129169
log.info 'Additional modules installation'
130170
project.copy {
@@ -182,7 +222,7 @@ class JBossConfigurationTask extends SilverpeasSetupTask {
182222
.useSettings(settings)
183223
.run(jboss: jboss)
184224
}
185-
} catch(Exception ex) {
225+
} catch (Exception ex) {
186226
log.error("Error while running cli script: ${ex.message}", ex)
187227
throw ex
188228
}

src/main/resources/default_config.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ SILVERPEAS_CONTEXT = silverpeas
9595
####################################################################################################
9696

9797
JVM_RAM_MAX=2048m
98-
JVM_OPTS=
98+
JVM_OPTS=-XX:+UseG1GC -XX:+UseStringDeduplication -XX:+UseCompressedOops
9999

100100
####################################################################################################
101101
## Application Server configuration.

0 commit comments

Comments
 (0)