@@ -35,6 +35,7 @@ import org.silverpeas.setup.api.SilverpeasSetupTask
35
35
import java.nio.file.Files
36
36
import java.nio.file.Paths
37
37
import java.util.regex.Matcher
38
+
38
39
/**
39
40
* A Gradle task to configure a JBoss/Wildfly instance from some CLI scripts to be ready to run
40
41
* Silverpeas.
@@ -81,42 +82,24 @@ class JBossConfigurationTask extends SilverpeasSetupTask {
81
82
server. start(adminOnly : true ) // start in admin only to perform only configuration tasks
82
83
setUpJDBCDriver()
83
84
processConfigurationFiles()
84
- } catch (Exception ex) {
85
+ } catch (Exception ex) {
85
86
log. error ' Error while configuring JBoss/Wildfly' , ex
86
87
throw new TaskExecutionException (this , ex)
87
88
} finally {
88
89
server. stop() // stop the admin mode
89
90
}
90
91
}
91
92
92
- private void setUpJVMOptions () {
93
+ void setUpJVMOptions () {
93
94
log. info ' JVM options setting'
94
95
new File (jboss. jbossHome, ' bin' ). listFiles(new FilenameFilter () {
95
96
@Override
96
97
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' )
98
99
}
99
100
}). 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)
120
103
modifiedConf. setReadable(conf. canRead())
121
104
modifiedConf. setWritable(conf. canWrite())
122
105
modifiedConf. setExecutable(conf. canExecute())
@@ -125,6 +108,63 @@ class JBossConfigurationTask extends SilverpeasSetupTask {
125
108
}
126
109
}
127
110
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
+
128
168
private void installAdditionalModules () {
129
169
log. info ' Additional modules installation'
130
170
project. copy {
@@ -182,7 +222,7 @@ class JBossConfigurationTask extends SilverpeasSetupTask {
182
222
.useSettings(settings)
183
223
.run(jboss : jboss)
184
224
}
185
- } catch (Exception ex) {
225
+ } catch (Exception ex) {
186
226
log. error(" Error while running cli script: ${ ex.message} " , ex)
187
227
throw ex
188
228
}
0 commit comments