-
Notifications
You must be signed in to change notification settings - Fork 9
/
buildr.rb
151 lines (130 loc) · 4.57 KB
/
buildr.rb
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
148
149
150
151
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with this
# work for additional information regarding copyright ownership. The ASF
# licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
require 'lock_jar'
require 'lock_jar/domain/dsl'
#
module Buildr
class << self
attr_accessor :global_lockjar_dsl
def project_to_lockfile(project)
"#{project.name.tr(':', '-')}.lock"
end
end
def lock_jar(&blk)
Buildr.global_lockjar_dsl = ::LockJar::Domain::Dsl.create(&blk)
end
namespace 'lock_jar' do
desc 'Lock dependencies for each project'
task('lock') do
projects.each do |project|
next if project.lockjar_dsl.nil?
# add buildr repos
repositories.remote.each do |repo|
project.lockjar_dsl.repository repo
end
::LockJar.lock(project.lockjar_dsl, lockfile: Buildr.project_to_lockfile(project))
end
end
end
module LockJar
#
module ProjectExtension
include Extension
def lock_jar(&blk)
@lockjar_dsl = ::LockJar::Domain::Dsl.create(&blk)
@lockjar_dsl.merge(Buildr.global_lockjar_dsl) unless Buildr.global_lockjar_dsl.nil?
end
def lock_jars(*args)
lockfile = Buildr.project_to_lockfile(project)
opts = {}
groups = ['default']
args.each do |arg|
if arg.is_a?(Hash)
opts.merge!(arg)
elsif arg.is_a?(String)
lockfile = arg
elsif arg.is_a?(Array)
groups = arg
end
end
::LockJar.list(lockfile, groups, opts)
end
def lockjar_dsl
@lockjar_dsl || Buildr.global_lockjar_dsl
end
after_define do |project|
task compile: 'lock_jar:compile'
task 'test:compile' => 'lock_jar:test:compile'
task 'eclipse' => 'lock_jar:eclipse'
namespace 'lock_jar' do
desc 'Lock dependencies to JarFile'
task('lock') do
dsl = project.lockjar_dsl
if dsl
# add buildr repos
repositories.remote do |repo|
puts repo
dsl.repository repo
end
::LockJar.lock(dsl, lockfile: "#{project.name}.lock")
else
# XXX: output that there were no dependencies to lock
puts "No lock_jar dependencies to lock for #{project.name}"
end
end
task('compile') do
if project.lockjar_dsl && !File.exist?(Buildr.project_to_lockfile(project))
fail(
"#{project.name}.lock does not exist, run "\
"#{project.name}:lockjar:lock first"
)
end
jars = ::LockJar.list(Buildr.project_to_lockfile(project), ['default'])
project.compile.with(jars)
end
task('test:compile') do
if project.lockjar_dsl && !File.exist?(Buildr.project_to_lockfile(project))
fail(
"#{Buildr.project_to_lockfile(project)} does not exist, run"\
" #{project.name}:lockjar:lock first"
)
end
jars = ::LockJar.list(Buildr.project_to_lockfile(project), ['test'])
project.test.compile.with(jars)
project.test.with(jars)
end
task('eclipse') do
if project.lockjar_dsl && !File.exist?(Buildr.project_to_lockfile(project))
fail(
"#{Buildr.project_to_lockfile(project)} does not exist, run "\
"#{project.name}:lockjar:lock first"
)
end
jars = ::LockJar.list(Buildr.project_to_lockfile(project), ['default'])
project.compile.with(jars)
jars = ::LockJar.list(Buildr.project_to_lockfile(project), ['test'])
project.test.compile.with(jars)
end
end
end
end
end
end
module Buildr
# Patch Builder::Project to include Buildr::LockJar::ProjectExtension
class Project
include Buildr::LockJar::ProjectExtension
end
end