-
Notifications
You must be signed in to change notification settings - Fork 8
/
SilverpeasSetupExtension.groovy
147 lines (127 loc) · 5.57 KB
/
SilverpeasSetupExtension.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
Copyright (C) 2000 - 2019 Silverpeas
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
As a special exception to the terms and conditions of version 3.0 of
the GPL, you may redistribute this Program in connection with Free/Libre
Open Source Software ("FLOSS") applications as described in Silverpeas's
FLOSS exception. You should have recieved a copy of the text describing
the FLOSS exception, and it is also available here:
"http://www.silverpeas.org/docs/core/legal/floss_exception.html"
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.silverpeas.setup
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.provider.Property
import org.silverpeas.setup.api.JBossServer
import org.silverpeas.setup.api.SystemWrapper
/**
* Extension of the plugin in which are defined the different properties required by the plugin to
* work. Some of the properties are already valued whereas others have to be set by the Gradle
* build.
* <p>
* Some other properties are defined directly in the bootstrapping of this plugin and those are only
* for readonly use by the Gradle script. Such properties are:
* </p>
* <ul>
* <li><code>logging</code>: an object to set some logging properties to be used by this plugin.
* It has the following attributes:
* <ul>
* <li><code>logDir</code> to value with the path of the directory in which the logging files
* will be generated.</li>
* <li><code>defaultLevel</code> to set the default logging level when running the Gradle build.
* </li>
* <li><code>scriptTasks</code> an array with the tasks specific the Gradle build.
* </ul>
* <li>silverpeas
* @author mmoquillon
*/
class SilverpeasSetupExtension {
/**
* The Silverpeas home directory. Defaulted with the SILVERPEAS_HOME environment
* variable.
*/
final File silverpeasHome
/**
* The JBoss home directory. Defaulted with the JBOSS_HOME environment variable.
*/
final File jbossHome
/**
* The properties required by the configuration execution of a Silverpeas distribution.
*/
final SilverpeasConfigurationProperties config
/**
* The properties required by the build of a given version of Silverpeas and its deployment
* in a JBoss server.
*/
final SilverpeasInstallationProperties installation
/**
* The properties required to perform a data source migration when upgrading Silverpeas to a newer
* version or when installing a fresh Silverpeas version.
*/
final SilverpeasMigrationProperties migration
/**
* The properties to configure the logging. They define the location of the logging file, the
* logging level and so on.
*/
final SilverpeasLoggingProperties logging
/**
* The time out when waiting JBoss answering to our requests. Defaulted to 5mn.
*/
final Property<Long> timeout
/**
* The Silverpeas settings as defined in the <code>config.properties</code> file.
* Some of them are computed from the properties in the file <code>config.properties</code>.
* Tasks can overwrite some of the settings as well as add their own properties.
*/
final Map settings = [:]
/**
* Constructs a new silverpeas configuration extension. It checks the environment variables
* SILVERPEAS_HOME and JBOSS_HOME are correctly set.
*/
SilverpeasSetupExtension(Project project) {
String silverpeasHomePath = SystemWrapper.getenv('SILVERPEAS_HOME')
String jbossHomePath = SystemWrapper.getenv('JBOSS_HOME')
if (!silverpeasHomePath || !jbossHomePath) {
println 'The environment variables SILVERPEAS_HOME or JBOSS_HOME aren\'t set!'
throw new IllegalStateException()
}
silverpeasHome = project.file(silverpeasHomePath)
jbossHome = project.file(jbossHomePath)
if (!(silverpeasHome.exists() && silverpeasHome.isDirectory()) ||
!(jbossHome.exists() && jbossHome.isDirectory())) {
println 'The path referred by SILVERPEAS_HOME or by JBOSS_HOME doesn\'t exist or isn\'t a directory!'
throw new IllegalStateException()
}
config = project.objects.newInstance(SilverpeasConfigurationProperties, project, silverpeasHome)
installation = project.objects.newInstance(SilverpeasInstallationProperties, project, silverpeasHome)
migration = project.objects.newInstance(SilverpeasMigrationProperties, project, silverpeasHome)
logging = project.objects.newInstance(SilverpeasLoggingProperties)
timeout = project.objects.property(Long)
timeout.set(300000l)
JBossServer.DEFAULT_TIMEOUT = timeout.get()
}
void setSettings(final Map configProperties) {
this.settings.putAll(configProperties)
}
void logging(Action<? extends SilverpeasLoggingProperties> action) {
action.execute(logging)
}
void config(Action<? extends SilverpeasConfigurationProperties> action) {
action.execute(config)
}
void installation(Action<? extends SilverpeasInstallationProperties> action) {
action.execute(installation)
}
void migration(Action<? extends SilverpeasMigrationProperties> action) {
action.execute(migration)
}
}