openhab-scripting 2.9.1 → 2.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/openhab/core/dsl/gems.rb +1 -26
- data/lib/openhab/core/dsl/rule/item.rb +1 -0
- data/lib/openhab/core/dsl/rule/rule.rb +18 -1
- data/lib/openhab/core/duration.rb +9 -0
- data/lib/openhab/version.rb +1 -1
- metadata +21 -67
- data/.github/workflows/workflow.yml +0 -327
- data/.gitignore +0 -17
- data/.java-version +0 -1
- data/.rspec +0 -1
- data/.yardopts +0 -1
- data/CHANGELOG.md +0 -113
- data/Gemfile +0 -28
- data/Gemfile.lock +0 -245
- data/Guardfile +0 -35
- data/LICENSE +0 -277
- data/README.md +0 -23
- data/Rakefile +0 -406
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/config/userdata/config/org/openhab/restauth.config +0 -3
- data/cucumber.yml +0 -1
- data/docs/_config.yml +0 -135
- data/docs/contributing/index.md +0 -47
- data/docs/examples/conversions.md +0 -123
- data/docs/examples/index.md +0 -61
- data/docs/index.md +0 -19
- data/docs/installation/index.md +0 -26
- data/docs/motivation/index.md +0 -27
- data/docs/usage/execution.md +0 -9
- data/docs/usage/execution/delay.md +0 -48
- data/docs/usage/execution/otherwise.md +0 -30
- data/docs/usage/execution/run.md +0 -70
- data/docs/usage/execution/triggered.md +0 -48
- data/docs/usage/guards.md +0 -51
- data/docs/usage/guards/between.md +0 -30
- data/docs/usage/guards/not_if.md +0 -41
- data/docs/usage/guards/only_if.md +0 -40
- data/docs/usage/index.md +0 -11
- data/docs/usage/items.md +0 -66
- data/docs/usage/items/contact.md +0 -84
- data/docs/usage/items/dimmer.md +0 -147
- data/docs/usage/items/groups.md +0 -76
- data/docs/usage/items/number.md +0 -225
- data/docs/usage/items/string.md +0 -49
- data/docs/usage/items/switch.md +0 -85
- data/docs/usage/misc.md +0 -7
- data/docs/usage/misc/actions.md +0 -108
- data/docs/usage/misc/duration.md +0 -21
- data/docs/usage/misc/gems.md +0 -25
- data/docs/usage/misc/logging.md +0 -21
- data/docs/usage/misc/metadata.md +0 -128
- data/docs/usage/misc/store_states.md +0 -42
- data/docs/usage/misc/time_of_day.md +0 -69
- data/docs/usage/misc/timers.md +0 -67
- data/docs/usage/rule.md +0 -43
- data/docs/usage/things.md +0 -29
- data/docs/usage/triggers.md +0 -8
- data/docs/usage/triggers/changed.md +0 -57
- data/docs/usage/triggers/channel.md +0 -54
- data/docs/usage/triggers/command.md +0 -69
- data/docs/usage/triggers/cron.md +0 -19
- data/docs/usage/triggers/every.md +0 -76
- data/docs/usage/triggers/updated.md +0 -78
- data/openhab-scripting.gemspec +0 -30
- data/openhab_rules/warmup.rb +0 -5
data/LICENSE
DELETED
@@ -1,277 +0,0 @@
|
|
1
|
-
Eclipse Public License - v 2.0
|
2
|
-
|
3
|
-
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
|
4
|
-
PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION
|
5
|
-
OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
|
6
|
-
|
7
|
-
1. DEFINITIONS
|
8
|
-
|
9
|
-
"Contribution" means:
|
10
|
-
|
11
|
-
a) in the case of the initial Contributor, the initial content
|
12
|
-
Distributed under this Agreement, and
|
13
|
-
|
14
|
-
b) in the case of each subsequent Contributor:
|
15
|
-
i) changes to the Program, and
|
16
|
-
ii) additions to the Program;
|
17
|
-
where such changes and/or additions to the Program originate from
|
18
|
-
and are Distributed by that particular Contributor. A Contribution
|
19
|
-
"originates" from a Contributor if it was added to the Program by
|
20
|
-
such Contributor itself or anyone acting on such Contributor's behalf.
|
21
|
-
Contributions do not include changes or additions to the Program that
|
22
|
-
are not Modified Works.
|
23
|
-
|
24
|
-
"Contributor" means any person or entity that Distributes the Program.
|
25
|
-
|
26
|
-
"Licensed Patents" mean patent claims licensable by a Contributor which
|
27
|
-
are necessarily infringed by the use or sale of its Contribution alone
|
28
|
-
or when combined with the Program.
|
29
|
-
|
30
|
-
"Program" means the Contributions Distributed in accordance with this
|
31
|
-
Agreement.
|
32
|
-
|
33
|
-
"Recipient" means anyone who receives the Program under this Agreement
|
34
|
-
or any Secondary License (as applicable), including Contributors.
|
35
|
-
|
36
|
-
"Derivative Works" shall mean any work, whether in Source Code or other
|
37
|
-
form, that is based on (or derived from) the Program and for which the
|
38
|
-
editorial revisions, annotations, elaborations, or other modifications
|
39
|
-
represent, as a whole, an original work of authorship.
|
40
|
-
|
41
|
-
"Modified Works" shall mean any work in Source Code or other form that
|
42
|
-
results from an addition to, deletion from, or modification of the
|
43
|
-
contents of the Program, including, for purposes of clarity any new file
|
44
|
-
in Source Code form that contains any contents of the Program. Modified
|
45
|
-
Works shall not include works that contain only declarations,
|
46
|
-
interfaces, types, classes, structures, or files of the Program solely
|
47
|
-
in each case in order to link to, bind by name, or subclass the Program
|
48
|
-
or Modified Works thereof.
|
49
|
-
|
50
|
-
"Distribute" means the acts of a) distributing or b) making available
|
51
|
-
in any manner that enables the transfer of a copy.
|
52
|
-
|
53
|
-
"Source Code" means the form of a Program preferred for making
|
54
|
-
modifications, including but not limited to software source code,
|
55
|
-
documentation source, and configuration files.
|
56
|
-
|
57
|
-
"Secondary License" means either the GNU General Public License,
|
58
|
-
Version 2.0, or any later versions of that license, including any
|
59
|
-
exceptions or additional permissions as identified by the initial
|
60
|
-
Contributor.
|
61
|
-
|
62
|
-
2. GRANT OF RIGHTS
|
63
|
-
|
64
|
-
a) Subject to the terms of this Agreement, each Contributor hereby
|
65
|
-
grants Recipient a non-exclusive, worldwide, royalty-free copyright
|
66
|
-
license to reproduce, prepare Derivative Works of, publicly display,
|
67
|
-
publicly perform, Distribute and sublicense the Contribution of such
|
68
|
-
Contributor, if any, and such Derivative Works.
|
69
|
-
|
70
|
-
b) Subject to the terms of this Agreement, each Contributor hereby
|
71
|
-
grants Recipient a non-exclusive, worldwide, royalty-free patent
|
72
|
-
license under Licensed Patents to make, use, sell, offer to sell,
|
73
|
-
import and otherwise transfer the Contribution of such Contributor,
|
74
|
-
if any, in Source Code or other form. This patent license shall
|
75
|
-
apply to the combination of the Contribution and the Program if, at
|
76
|
-
the time the Contribution is added by the Contributor, such addition
|
77
|
-
of the Contribution causes such combination to be covered by the
|
78
|
-
Licensed Patents. The patent license shall not apply to any other
|
79
|
-
combinations which include the Contribution. No hardware per se is
|
80
|
-
licensed hereunder.
|
81
|
-
|
82
|
-
c) Recipient understands that although each Contributor grants the
|
83
|
-
licenses to its Contributions set forth herein, no assurances are
|
84
|
-
provided by any Contributor that the Program does not infringe the
|
85
|
-
patent or other intellectual property rights of any other entity.
|
86
|
-
Each Contributor disclaims any liability to Recipient for claims
|
87
|
-
brought by any other entity based on infringement of intellectual
|
88
|
-
property rights or otherwise. As a condition to exercising the
|
89
|
-
rights and licenses granted hereunder, each Recipient hereby
|
90
|
-
assumes sole responsibility to secure any other intellectual
|
91
|
-
property rights needed, if any. For example, if a third party
|
92
|
-
patent license is required to allow Recipient to Distribute the
|
93
|
-
Program, it is Recipient's responsibility to acquire that license
|
94
|
-
before distributing the Program.
|
95
|
-
|
96
|
-
d) Each Contributor represents that to its knowledge it has
|
97
|
-
sufficient copyright rights in its Contribution, if any, to grant
|
98
|
-
the copyright license set forth in this Agreement.
|
99
|
-
|
100
|
-
e) Notwithstanding the terms of any Secondary License, no
|
101
|
-
Contributor makes additional grants to any Recipient (other than
|
102
|
-
those set forth in this Agreement) as a result of such Recipient's
|
103
|
-
receipt of the Program under the terms of a Secondary License
|
104
|
-
(if permitted under the terms of Section 3).
|
105
|
-
|
106
|
-
3. REQUIREMENTS
|
107
|
-
|
108
|
-
3.1 If a Contributor Distributes the Program in any form, then:
|
109
|
-
|
110
|
-
a) the Program must also be made available as Source Code, in
|
111
|
-
accordance with section 3.2, and the Contributor must accompany
|
112
|
-
the Program with a statement that the Source Code for the Program
|
113
|
-
is available under this Agreement, and informs Recipients how to
|
114
|
-
obtain it in a reasonable manner on or through a medium customarily
|
115
|
-
used for software exchange; and
|
116
|
-
|
117
|
-
b) the Contributor may Distribute the Program under a license
|
118
|
-
different than this Agreement, provided that such license:
|
119
|
-
i) effectively disclaims on behalf of all other Contributors all
|
120
|
-
warranties and conditions, express and implied, including
|
121
|
-
warranties or conditions of title and non-infringement, and
|
122
|
-
implied warranties or conditions of merchantability and fitness
|
123
|
-
for a particular purpose;
|
124
|
-
|
125
|
-
ii) effectively excludes on behalf of all other Contributors all
|
126
|
-
liability for damages, including direct, indirect, special,
|
127
|
-
incidental and consequential damages, such as lost profits;
|
128
|
-
|
129
|
-
iii) does not attempt to limit or alter the recipients' rights
|
130
|
-
in the Source Code under section 3.2; and
|
131
|
-
|
132
|
-
iv) requires any subsequent distribution of the Program by any
|
133
|
-
party to be under a license that satisfies the requirements
|
134
|
-
of this section 3.
|
135
|
-
|
136
|
-
3.2 When the Program is Distributed as Source Code:
|
137
|
-
|
138
|
-
a) it must be made available under this Agreement, or if the
|
139
|
-
Program (i) is combined with other material in a separate file or
|
140
|
-
files made available under a Secondary License, and (ii) the initial
|
141
|
-
Contributor attached to the Source Code the notice described in
|
142
|
-
Exhibit A of this Agreement, then the Program may be made available
|
143
|
-
under the terms of such Secondary Licenses, and
|
144
|
-
|
145
|
-
b) a copy of this Agreement must be included with each copy of
|
146
|
-
the Program.
|
147
|
-
|
148
|
-
3.3 Contributors may not remove or alter any copyright, patent,
|
149
|
-
trademark, attribution notices, disclaimers of warranty, or limitations
|
150
|
-
of liability ("notices") contained within the Program from any copy of
|
151
|
-
the Program which they Distribute, provided that Contributors may add
|
152
|
-
their own appropriate notices.
|
153
|
-
|
154
|
-
4. COMMERCIAL DISTRIBUTION
|
155
|
-
|
156
|
-
Commercial distributors of software may accept certain responsibilities
|
157
|
-
with respect to end users, business partners and the like. While this
|
158
|
-
license is intended to facilitate the commercial use of the Program,
|
159
|
-
the Contributor who includes the Program in a commercial product
|
160
|
-
offering should do so in a manner which does not create potential
|
161
|
-
liability for other Contributors. Therefore, if a Contributor includes
|
162
|
-
the Program in a commercial product offering, such Contributor
|
163
|
-
("Commercial Contributor") hereby agrees to defend and indemnify every
|
164
|
-
other Contributor ("Indemnified Contributor") against any losses,
|
165
|
-
damages and costs (collectively "Losses") arising from claims, lawsuits
|
166
|
-
and other legal actions brought by a third party against the Indemnified
|
167
|
-
Contributor to the extent caused by the acts or omissions of such
|
168
|
-
Commercial Contributor in connection with its distribution of the Program
|
169
|
-
in a commercial product offering. The obligations in this section do not
|
170
|
-
apply to any claims or Losses relating to any actual or alleged
|
171
|
-
intellectual property infringement. In order to qualify, an Indemnified
|
172
|
-
Contributor must: a) promptly notify the Commercial Contributor in
|
173
|
-
writing of such claim, and b) allow the Commercial Contributor to control,
|
174
|
-
and cooperate with the Commercial Contributor in, the defense and any
|
175
|
-
related settlement negotiations. The Indemnified Contributor may
|
176
|
-
participate in any such claim at its own expense.
|
177
|
-
|
178
|
-
For example, a Contributor might include the Program in a commercial
|
179
|
-
product offering, Product X. That Contributor is then a Commercial
|
180
|
-
Contributor. If that Commercial Contributor then makes performance
|
181
|
-
claims, or offers warranties related to Product X, those performance
|
182
|
-
claims and warranties are such Commercial Contributor's responsibility
|
183
|
-
alone. Under this section, the Commercial Contributor would have to
|
184
|
-
defend claims against the other Contributors related to those performance
|
185
|
-
claims and warranties, and if a court requires any other Contributor to
|
186
|
-
pay any damages as a result, the Commercial Contributor must pay
|
187
|
-
those damages.
|
188
|
-
|
189
|
-
5. NO WARRANTY
|
190
|
-
|
191
|
-
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT
|
192
|
-
PERMITTED BY APPLICABLE LAW, THE PROGRAM IS PROVIDED ON AN "AS IS"
|
193
|
-
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
|
194
|
-
IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF
|
195
|
-
TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR
|
196
|
-
PURPOSE. Each Recipient is solely responsible for determining the
|
197
|
-
appropriateness of using and distributing the Program and assumes all
|
198
|
-
risks associated with its exercise of rights under this Agreement,
|
199
|
-
including but not limited to the risks and costs of program errors,
|
200
|
-
compliance with applicable laws, damage to or loss of data, programs
|
201
|
-
or equipment, and unavailability or interruption of operations.
|
202
|
-
|
203
|
-
6. DISCLAIMER OF LIABILITY
|
204
|
-
|
205
|
-
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT
|
206
|
-
PERMITTED BY APPLICABLE LAW, NEITHER RECIPIENT NOR ANY CONTRIBUTORS
|
207
|
-
SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
208
|
-
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST
|
209
|
-
PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
210
|
-
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
211
|
-
ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
|
212
|
-
EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE
|
213
|
-
POSSIBILITY OF SUCH DAMAGES.
|
214
|
-
|
215
|
-
7. GENERAL
|
216
|
-
|
217
|
-
If any provision of this Agreement is invalid or unenforceable under
|
218
|
-
applicable law, it shall not affect the validity or enforceability of
|
219
|
-
the remainder of the terms of this Agreement, and without further
|
220
|
-
action by the parties hereto, such provision shall be reformed to the
|
221
|
-
minimum extent necessary to make such provision valid and enforceable.
|
222
|
-
|
223
|
-
If Recipient institutes patent litigation against any entity
|
224
|
-
(including a cross-claim or counterclaim in a lawsuit) alleging that the
|
225
|
-
Program itself (excluding combinations of the Program with other software
|
226
|
-
or hardware) infringes such Recipient's patent(s), then such Recipient's
|
227
|
-
rights granted under Section 2(b) shall terminate as of the date such
|
228
|
-
litigation is filed.
|
229
|
-
|
230
|
-
All Recipient's rights under this Agreement shall terminate if it
|
231
|
-
fails to comply with any of the material terms or conditions of this
|
232
|
-
Agreement and does not cure such failure in a reasonable period of
|
233
|
-
time after becoming aware of such noncompliance. If all Recipient's
|
234
|
-
rights under this Agreement terminate, Recipient agrees to cease use
|
235
|
-
and distribution of the Program as soon as reasonably practicable.
|
236
|
-
However, Recipient's obligations under this Agreement and any licenses
|
237
|
-
granted by Recipient relating to the Program shall continue and survive.
|
238
|
-
|
239
|
-
Everyone is permitted to copy and distribute copies of this Agreement,
|
240
|
-
but in order to avoid inconsistency the Agreement is copyrighted and
|
241
|
-
may only be modified in the following manner. The Agreement Steward
|
242
|
-
reserves the right to publish new versions (including revisions) of
|
243
|
-
this Agreement from time to time. No one other than the Agreement
|
244
|
-
Steward has the right to modify this Agreement. The Eclipse Foundation
|
245
|
-
is the initial Agreement Steward. The Eclipse Foundation may assign the
|
246
|
-
responsibility to serve as the Agreement Steward to a suitable separate
|
247
|
-
entity. Each new version of the Agreement will be given a distinguishing
|
248
|
-
version number. The Program (including Contributions) may always be
|
249
|
-
Distributed subject to the version of the Agreement under which it was
|
250
|
-
received. In addition, after a new version of the Agreement is published,
|
251
|
-
Contributor may elect to Distribute the Program (including its
|
252
|
-
Contributions) under the new version.
|
253
|
-
|
254
|
-
Except as expressly stated in Sections 2(a) and 2(b) above, Recipient
|
255
|
-
receives no rights or licenses to the intellectual property of any
|
256
|
-
Contributor under this Agreement, whether expressly, by implication,
|
257
|
-
estoppel or otherwise. All rights in the Program not expressly granted
|
258
|
-
under this Agreement are reserved. Nothing in this Agreement is intended
|
259
|
-
to be enforceable by any entity that is not a Contributor or Recipient.
|
260
|
-
No third-party beneficiary rights are created under this Agreement.
|
261
|
-
|
262
|
-
Exhibit A - Form of Secondary Licenses Notice
|
263
|
-
|
264
|
-
"This Source Code may also be made available under the following
|
265
|
-
Secondary Licenses when the conditions for such availability set forth
|
266
|
-
in the Eclipse Public License, v. 2.0 are satisfied: {name license(s),
|
267
|
-
version(s), and exceptions or additional permissions here}."
|
268
|
-
|
269
|
-
Simply including a copy of this Agreement, including this Exhibit A
|
270
|
-
is not sufficient to license the Source Code under Secondary Licenses.
|
271
|
-
|
272
|
-
If it is not possible or desirable to put the notice in a particular
|
273
|
-
file, then You may include the notice in a location (such as a LICENSE
|
274
|
-
file in a relevant directory) where a recipient would be likely to
|
275
|
-
look for such a notice.
|
276
|
-
|
277
|
-
You may add additional accurate notices of copyright ownership.
|
data/README.md
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# JRuby OpenHAB Scripting Library
|
2
|
-
|
3
|
-
|
4
|
-
<p align="center">
|
5
|
-
<img alt="GitHub release (latest SemVer including pre-releases)" src="https://img.shields.io/github/v/release/boc-tothefuture/openhab-jruby?include_prereleases"/>
|
6
|
-
<img alt="GitHub Workflow Status" src="https://img.shields.io/github/workflow/status/boc-tothefuture/openhab-jruby/Openhab-JRuby-Scripting"/>
|
7
|
-
<img alt="GitHub contributors" src="https://img.shields.io/github/contributors/boc-tothefuture/openhab-jruby"/>
|
8
|
-
<img alt="GitHub commit activity" src="https://img.shields.io/github/commit-activity/m/boc-tothefuture/openhab-jruby">
|
9
|
-
<img alt="SemVer version observance" src="https://img.shields.io/badge/semver-2.0.0-blue"/>
|
10
|
-
<a href="https://conventionalcommits.org"/>
|
11
|
-
<img alt="Convention commits observance" src="https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg"/>
|
12
|
-
</a>
|
13
|
-
</p>
|
14
|
-
|
15
|
-
|
16
|
-
## Usage
|
17
|
-
Usage documentation is located [here](https://boc-tothefuture.github.io/openhab-jruby/).
|
18
|
-
|
19
|
-
## Discussion
|
20
|
-
Please see [this thread](https://community.openhab.org/t/jruby-openhab-rules-system/110598) on the OpenHAB forum for further discussion. Ideas and suggestions are welcome.
|
21
|
-
|
22
|
-
## Library Status
|
23
|
-
This is an alpha and syntax and all elements are subject to change as the library evolves.
|
data/Rakefile
DELETED
@@ -1,406 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rake/packagetask'
|
4
|
-
require 'rubocop/rake_task'
|
5
|
-
require 'bundler/gem_tasks'
|
6
|
-
require 'yard'
|
7
|
-
require 'English'
|
8
|
-
require 'time'
|
9
|
-
require 'cucumber'
|
10
|
-
require 'cucumber/rake/task'
|
11
|
-
require 'open-uri'
|
12
|
-
require 'tty-command'
|
13
|
-
require 'process_exists'
|
14
|
-
require 'cuke_linter'
|
15
|
-
require 'erb'
|
16
|
-
|
17
|
-
require_relative 'lib/openhab/version'
|
18
|
-
|
19
|
-
PACKAGE_DIR = 'pkg'
|
20
|
-
TMP_DIR = 'tmp'
|
21
|
-
OPENHAB_DIR = File.join(TMP_DIR, 'openhab')
|
22
|
-
DOCS_DIR = 'doc'
|
23
|
-
OPENHAB_VERSION = '3.0.0'
|
24
|
-
JRUBY_BUNDLE = File.realpath(Dir.glob('bundle/*.jar').first)
|
25
|
-
KARAF_CLIENT_PATH = File.join(OPENHAB_DIR, 'runtime/bin/client')
|
26
|
-
KARAF_CLIENT_ARGS = [KARAF_CLIENT_PATH, '-p', 'habopen'].freeze
|
27
|
-
KARAF_CLIENT = KARAF_CLIENT_ARGS.join(' ')
|
28
|
-
|
29
|
-
DEPLOY_DIR = File.join(OPENHAB_DIR, 'conf/automation/jsr223/ruby/personal')
|
30
|
-
LIB_DIR = File.join(OPENHAB_DIR, 'conf/automation/lib/ruby/lib/')
|
31
|
-
STATE_DIR = File.join(OPENHAB_DIR, 'rake_state')
|
32
|
-
YARD_DIR = File.join('docs', 'yard')
|
33
|
-
CUCUMBER_LOGS = File.join(TMP_DIR, 'cucumber_logs')
|
34
|
-
SERVICES_CONFIG = File.join(OPENHAB_DIR, 'conf/services/jruby.cfg')
|
35
|
-
|
36
|
-
CLEAN << PACKAGE_DIR
|
37
|
-
CLEAN << DEPLOY_DIR
|
38
|
-
CLEAN << CUCUMBER_LOGS
|
39
|
-
CLEAN << YARD_DIR
|
40
|
-
CLEAN << '.yardoc'
|
41
|
-
|
42
|
-
CLOBBER << OPENHAB_DIR
|
43
|
-
|
44
|
-
desc 'Generate Yard docs'
|
45
|
-
task :yard do
|
46
|
-
YARD::Rake::YardocTask.new do |t|
|
47
|
-
t.files = ['lib/**/*.rb'] # optional
|
48
|
-
t.stats_options = ['--list-undoc'] # optional
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
RuboCop::RakeTask.new do |task|
|
53
|
-
task.patterns = ['lib/**/*.rb', 'test/**/*.rb']
|
54
|
-
task.fail_on_error = false
|
55
|
-
end
|
56
|
-
|
57
|
-
desc 'Lint Code'
|
58
|
-
task :lint do
|
59
|
-
Rake::Task['rubocop'].invoke
|
60
|
-
CukeLinter.lint
|
61
|
-
end
|
62
|
-
|
63
|
-
desc 'Start Documentation Server'
|
64
|
-
task docs: :yard do
|
65
|
-
sh 'bundle exec jekyll clean'
|
66
|
-
sh 'bundle exec jekyll server --config docs/_config.yml'
|
67
|
-
end
|
68
|
-
|
69
|
-
task :yard_server do
|
70
|
-
sh 'bundle exec guard'
|
71
|
-
end
|
72
|
-
|
73
|
-
desc 'Run Cucumber Features'
|
74
|
-
task :features, [:feature] => ['openhab:warmup', 'openhab:deploy', CUCUMBER_LOGS] do |_, args|
|
75
|
-
# Rake::Task['openhab:warmup'].execute
|
76
|
-
Cucumber::Rake::Task.new(:features) do |t|
|
77
|
-
t.cucumber_opts = "--tags 'not @wip and not @not_implemented' --format pretty #{args[:feature]}"
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
desc 'Get OpenHAB-JRuby Version'
|
82
|
-
task :version do
|
83
|
-
puts OpenHAB::VERSION
|
84
|
-
end
|
85
|
-
|
86
|
-
namespace :gh do
|
87
|
-
zip_path = ''
|
88
|
-
|
89
|
-
directory PACKAGE_DIR
|
90
|
-
|
91
|
-
desc 'Package for release'
|
92
|
-
task package: [PACKAGE_DIR] do
|
93
|
-
zip_filename = "OpenHABJRuby-#{OpenHAB::VERSION}.zip"
|
94
|
-
zip_path = File.join(PACKAGE_DIR, zip_filename)
|
95
|
-
target_dir = 'lib/'
|
96
|
-
sh 'zip', '-r', zip_path, target_dir
|
97
|
-
end
|
98
|
-
|
99
|
-
desc 'Package for release'
|
100
|
-
task release: :package do
|
101
|
-
sh 'gh', 'release', 'create', OpenHAB::VERSION, '-p', '-F', 'CHANGELOG.md', zip_path, JRUBY_BUNDLE
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
namespace :openhab do
|
106
|
-
def command_success?(command)
|
107
|
-
cmd = TTY::Command.new(printer: :null)
|
108
|
-
cmd.run!(command).success?
|
109
|
-
end
|
110
|
-
|
111
|
-
def running?(fail_on_error: false)
|
112
|
-
karaf_status = File.join(OPENHAB_DIR, 'runtime/bin/status')
|
113
|
-
|
114
|
-
return false unless File.exist? karaf_status
|
115
|
-
|
116
|
-
if fail_on_error
|
117
|
-
fail_on_error(karaf_status)
|
118
|
-
true
|
119
|
-
else
|
120
|
-
command_success? karaf_status
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
# There can be a delay between when OpenHAB is running and ready to process commands
|
125
|
-
def ready?(fail_on_error: false)
|
126
|
-
return unless running?
|
127
|
-
|
128
|
-
if fail_on_error
|
129
|
-
fail_on_error("#{KARAF_CLIENT} 'system:version'")
|
130
|
-
true
|
131
|
-
else
|
132
|
-
cmd = TTY::Command.new(printer: :null)
|
133
|
-
cmd.run!("#{KARAF_CLIENT} 'system:version'").success?
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
def ensure_openhab_running
|
138
|
-
abort('Openhab not running') unless running?
|
139
|
-
end
|
140
|
-
|
141
|
-
def print_and_flush(string)
|
142
|
-
print string
|
143
|
-
$stdout.flush
|
144
|
-
end
|
145
|
-
|
146
|
-
def fail_on_error(command, env = {})
|
147
|
-
cmd = TTY::Command.new
|
148
|
-
out, = cmd.run(command, env: env, only_output_on_error: true)
|
149
|
-
out
|
150
|
-
end
|
151
|
-
|
152
|
-
def karaf(command)
|
153
|
-
fail_on_error("#{KARAF_CLIENT} '#{command}'")
|
154
|
-
end
|
155
|
-
|
156
|
-
def wait_for(duration, task)
|
157
|
-
print_and_flush "Waiting for up to #{duration} seconds for #{task}"
|
158
|
-
duration.times do
|
159
|
-
if yield
|
160
|
-
puts ''
|
161
|
-
return true
|
162
|
-
end
|
163
|
-
|
164
|
-
print_and_flush '.'
|
165
|
-
sleep 1
|
166
|
-
end
|
167
|
-
puts ''
|
168
|
-
false
|
169
|
-
end
|
170
|
-
|
171
|
-
def gem_home
|
172
|
-
full_path = File.realpath OPENHAB_DIR
|
173
|
-
File.join(full_path, '/conf/automation/lib/ruby/gem_home')
|
174
|
-
end
|
175
|
-
|
176
|
-
def ruby_env
|
177
|
-
# { 'RUBYLIB' => File.join(full_path, '/conf/automation/lib/ruby/lib'),
|
178
|
-
{ 'GEM_HOME' => gem_home }
|
179
|
-
end
|
180
|
-
|
181
|
-
def state(task)
|
182
|
-
Rake::Task[STATE_DIR.to_s].execute
|
183
|
-
task_file = File.join(STATE_DIR, task)
|
184
|
-
if File.exist? task_file
|
185
|
-
puts "Skipping task(#{task}), task already up to date"
|
186
|
-
else
|
187
|
-
yield
|
188
|
-
touch task_file
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
directory OPENHAB_DIR
|
193
|
-
directory DEPLOY_DIR
|
194
|
-
directory LIB_DIR
|
195
|
-
directory STATE_DIR
|
196
|
-
directory CUCUMBER_LOGS
|
197
|
-
|
198
|
-
desc 'Download Openhab and unzip it'
|
199
|
-
task download: [OPENHAB_DIR] do |task|
|
200
|
-
state(task.name) do
|
201
|
-
openhab_zip = "openhab-#{OPENHAB_VERSION}.zip"
|
202
|
-
Dir.chdir(OPENHAB_DIR) do
|
203
|
-
puts "Downloading #{openhab_zip}"
|
204
|
-
IO.copy_stream(
|
205
|
-
open("https://openhab.jfrog.io/openhab/libs-release/org/openhab/distro/openhab/#{OPENHAB_VERSION}/openhab-#{OPENHAB_VERSION}.zip"), openhab_zip
|
206
|
-
)
|
207
|
-
fail_on_error("unzip #{openhab_zip}")
|
208
|
-
rm openhab_zip
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
desc 'Add RubyLib and GEM_HOME to start.sh'
|
214
|
-
task rubylib: :download do |task|
|
215
|
-
# state(task.name) do
|
216
|
-
# paths = ruby_env
|
217
|
-
# Dir.chdir(OPENHAB_DIR) do
|
218
|
-
# start_file = 'start.sh'
|
219
|
-
#
|
220
|
-
# settings = {
|
221
|
-
# /^export RUBYLIB=/ => "export RUBYLIB=#{paths['RUBYLIB']}\n",
|
222
|
-
# /^export GEM_HOME=/ => "export GEM_HOME=#{paths['GEM_HOME']}\n"
|
223
|
-
# }
|
224
|
-
#
|
225
|
-
# settings.each do |regex, line|
|
226
|
-
# lines = File.readlines(start_file)
|
227
|
-
# unless lines.grep(regex).any?
|
228
|
-
# lines.insert(-2, line)
|
229
|
-
# File.write(start_file, lines.join)
|
230
|
-
# end
|
231
|
-
# end
|
232
|
-
# end
|
233
|
-
# end
|
234
|
-
end
|
235
|
-
|
236
|
-
desc 'Setup services config'
|
237
|
-
task services: :download do |task|
|
238
|
-
state(task.name) do
|
239
|
-
services_config = ERB.new <<~EOF
|
240
|
-
org.openhab.automation.jrubyscripting:gem_home=<%= gem_home %>
|
241
|
-
EOF
|
242
|
-
File.write(SERVICES_CONFIG, services_config.result)
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
def bundle_id
|
247
|
-
karaf('bundle:list --no-format org.openhab.automation.jrubyscripting').lines.last[/^\d\d\d/].chomp
|
248
|
-
end
|
249
|
-
|
250
|
-
desc 'Install JRuby Bundle'
|
251
|
-
task install: [:download, :rubylib, :services, DEPLOY_DIR] do |task|
|
252
|
-
state(task.name) do
|
253
|
-
start
|
254
|
-
if karaf('bundle:list --no-format org.openhab.automation.jrubyscripting').include?('Active')
|
255
|
-
puts 'Bundle Active, no action taken'
|
256
|
-
else
|
257
|
-
unless karaf('bundle:list --no-format org.openhab.automation.jrubyscripting').include?('Installed')
|
258
|
-
karaf("bundle:install file://#{JRUBY_BUNDLE}")
|
259
|
-
end
|
260
|
-
karaf("bundle:start #{bundle_id}")
|
261
|
-
end
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
desc 'Upgrade JRuby Bundle'
|
266
|
-
task :upgrade, [:file] do |_, args|
|
267
|
-
start
|
268
|
-
if karaf('bundle:list --no-format org.openhab.automation.jrubyscripting').include?('Active')
|
269
|
-
karaf("bundle:update #{bundle_id} file://#{args[:file]}")
|
270
|
-
else
|
271
|
-
abort "Bundle not installed, can't upgrade"
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
desc 'Configure'
|
276
|
-
task configure: %i[download] do |task|
|
277
|
-
# Set log levels
|
278
|
-
state(task.name) do
|
279
|
-
start
|
280
|
-
karaf('log:set TRACE jsr223')
|
281
|
-
karaf('log:set TRACE org.openhab.core.automation')
|
282
|
-
karaf('log:set TRACE org.openhab.binding.jrubyscripting')
|
283
|
-
karaf('openhab:users add foo foo administrator')
|
284
|
-
sh 'rsync', '-aih', 'config/userdata/', File.join(OPENHAB_DIR, 'userdata')
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
def start
|
289
|
-
if running?
|
290
|
-
puts 'OpenHAB already running'
|
291
|
-
return
|
292
|
-
end
|
293
|
-
|
294
|
-
env = ruby_env
|
295
|
-
env = env.merge({ 'KARAF_REDIRECT' => File.join(File.realpath(TMP_DIR), 'karaf.log'),
|
296
|
-
'EXTRA_JAVA_OPTS' => '-Xmx4g' })
|
297
|
-
|
298
|
-
Dir.chdir(OPENHAB_DIR) do
|
299
|
-
puts 'Starting OpenHAB'
|
300
|
-
pid = spawn(env, 'runtime/bin/start')
|
301
|
-
Process.detach(pid)
|
302
|
-
end
|
303
|
-
|
304
|
-
wait_for(20, 'OpenHAB to start') { running? }
|
305
|
-
abort 'Unable to start OpenHAB' unless running?(fail_on_error: true)
|
306
|
-
|
307
|
-
wait_for(20, 'OpenHAB to become ready') { ready? }
|
308
|
-
abort 'OpenHAB did not become ready' unless ready?(fail_on_error: true)
|
309
|
-
|
310
|
-
puts 'OpenHAB started and ready'
|
311
|
-
end
|
312
|
-
|
313
|
-
desc 'Start OpenHAB'
|
314
|
-
task start: %i[download] do
|
315
|
-
start
|
316
|
-
end
|
317
|
-
|
318
|
-
def stop
|
319
|
-
if running?
|
320
|
-
pid = File.read(File.join(OPENHAB_DIR, 'userdata/tmp/karaf.pid')).chomp.to_i
|
321
|
-
Dir.chdir(OPENHAB_DIR) do
|
322
|
-
fail_on_error('runtime/bin/stop')
|
323
|
-
end
|
324
|
-
stopped = wait_for(20, 'OpenHAB to stop') { Process.exists?(pid) == false }
|
325
|
-
abort 'Unable to stop OpenHAB' unless stopped
|
326
|
-
end
|
327
|
-
|
328
|
-
puts 'OpenHAB Stopped'
|
329
|
-
end
|
330
|
-
|
331
|
-
desc 'Stop OpenHAB'
|
332
|
-
task :stop do
|
333
|
-
stop
|
334
|
-
end
|
335
|
-
|
336
|
-
def restart
|
337
|
-
puts 'Restarting OpenHAB'
|
338
|
-
stop
|
339
|
-
start
|
340
|
-
puts 'OpenHAB Restarted'
|
341
|
-
end
|
342
|
-
|
343
|
-
desc 'Clobber local Openhab'
|
344
|
-
task :clobber do
|
345
|
-
stop if running?
|
346
|
-
|
347
|
-
rm_rf OPENHAB_DIR
|
348
|
-
end
|
349
|
-
|
350
|
-
desc 'Create a Dev Dump in OpenHAB and wait until its complete'
|
351
|
-
task :dump do
|
352
|
-
dumps = File.join(OPENHAB_DIR, 'userdata', '*.zip')
|
353
|
-
|
354
|
-
puts 'Deleting any existing dumps'
|
355
|
-
dump = Dir[dumps].each { |dump_file| rm dump_file }
|
356
|
-
|
357
|
-
karaf('dev:dump-create')
|
358
|
-
|
359
|
-
wait_for(30, 'Dump to be created') do
|
360
|
-
Dir[dumps].any?
|
361
|
-
end
|
362
|
-
dump = Dir[dumps].first
|
363
|
-
puts "Found dev dump #{dump}"
|
364
|
-
dump_sizes = Array.new(10)
|
365
|
-
wait_for(120, 'Dump size to not increase for 10 seconds') do
|
366
|
-
dump_sizes << File.size(dump)
|
367
|
-
dump_sizes.last(10).uniq.length == 1
|
368
|
-
end
|
369
|
-
end
|
370
|
-
|
371
|
-
desc 'Warmup OpenHab environment'
|
372
|
-
task warmup: [:prepare, DEPLOY_DIR] do
|
373
|
-
start
|
374
|
-
openhab_log = File.join(OPENHAB_DIR, 'userdata/logs/openhab.log')
|
375
|
-
|
376
|
-
file = File.join('openhab_rules', 'warmup.rb')
|
377
|
-
dest_file = File.join(DEPLOY_DIR, "#{File.basename(file, '.rb')}_#{Time.now.to_i}.rb")
|
378
|
-
cp file, dest_file
|
379
|
-
wait_for(20, 'OpenHAB to warmup') do
|
380
|
-
File.foreach(openhab_log).grep(/OpenHAB warmup complete/).any?
|
381
|
-
end
|
382
|
-
rm dest_file
|
383
|
-
end
|
384
|
-
|
385
|
-
desc 'Prepare local Openhab'
|
386
|
-
task prepare: [:download, :rubylib, :install, :configure, :deploy, CUCUMBER_LOGS]
|
387
|
-
|
388
|
-
desc 'Setup local Openhab'
|
389
|
-
task setup: %i[prepare stop]
|
390
|
-
|
391
|
-
desc 'Deploy to local Openhab'
|
392
|
-
task deploy: %i[download build] do |_task|
|
393
|
-
gem_file = File.join(PACKAGE_DIR, "openhab-scripting-#{OpenHAB::VERSION}.gem")
|
394
|
-
fail_on_error("gem install #{gem_file}", ruby_env)
|
395
|
-
end
|
396
|
-
|
397
|
-
desc 'Deploy adhoc test Openhab'
|
398
|
-
task adhoc: :deploy do
|
399
|
-
mkdir_p DEPLOY_DIR
|
400
|
-
Dir.glob(File.join(DEPLOY_DIR, '*.rb')) { |file| rm file }
|
401
|
-
Dir.glob(File.join('test/', '*.rb')) do |file|
|
402
|
-
dest_name = "#{File.basename(file, '.rb')}_#{Time.now.to_i}.rb"
|
403
|
-
cp file, File.join(deploy_dir, dest_name)
|
404
|
-
end
|
405
|
-
end
|
406
|
-
end
|