lock_jar 0.6.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/lock_jar/dsl.rb DELETED
@@ -1,184 +0,0 @@
1
- # Licensed to the Apache Software Foundation (ASF) under one or more
2
- # contributor license agreements. See the NOTICE file distributed with this
3
- # work for additional information regarding copyright ownership. The ASF
4
- # licenses this file to you under the Apache License, Version 2.0 (the
5
- # "License"); you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
- # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
- # License for the specific language governing permissions and limitations under
14
- # the License.
15
-
16
- require 'lock_jar/maven'
17
-
18
- module LockJar
19
- class Dsl
20
-
21
- attr_reader :notations
22
- attr_reader :repositories
23
- attr_reader :local_repository
24
- attr_reader :scopes
25
- attr_reader :maps
26
- attr_reader :excludes
27
-
28
- class << self
29
-
30
- def evaluate(jarfile = nil, &blk)
31
- if jarfile.nil? && blk.nil?
32
- raise "jarfile or block must be set"
33
- end
34
-
35
-
36
- builder = new
37
-
38
- if jarfile
39
- builder.instance_eval(builder.read_file(jarfile.to_s), jarfile.to_s, 1)
40
- end
41
-
42
- if blk
43
- builder.instance_eval(&blk)
44
- end
45
-
46
- builder
47
- end
48
-
49
- def scopes
50
- ['compile', 'runtime', 'test']
51
- end
52
- end
53
-
54
- def initialize
55
-
56
- @repositories = []
57
- @notations = {}
58
-
59
- @scope_changed = false
60
-
61
- LockJar::Dsl.scopes.each do |scope|
62
- @notations[scope] = []
63
- end
64
-
65
- @present_scope = 'compile'
66
-
67
- @local_repository = nil
68
- @maps = {}
69
- @excludes = []
70
- end
71
-
72
- def exclude(*notations)
73
- @excludes += notations
74
- end
75
-
76
- def jar(notation, *args)
77
- opts = {}
78
- if args.last.is_a? Hash
79
- opts.merge!( args.last )
80
- end
81
-
82
- artifact( notation, opts )
83
- end
84
-
85
- def local( path )
86
- @local_repository = path
87
- end
88
-
89
- def merge( dsl )
90
- @repositories = (@repositories + dsl.repositories).uniq
91
-
92
- dsl.notations.each do |scope, notations|
93
- @notations[scope] = (@notations[scope] + notations).uniq
94
- end
95
-
96
- dsl.maps.each do |notation,paths|
97
- existing_map = @maps[notation]
98
- if existing_map
99
- @maps[notation] = (existing_map + paths).uniq
100
- else
101
- @maps[notation] = paths
102
- end
103
- end
104
-
105
- dsl.excludes.each do |exclude|
106
- @excludes << exclude
107
- end
108
-
109
- self
110
- end
111
-
112
- # Map a dependency to another dependency or local directory.
113
- def map( notation, *args )
114
- @maps[notation] = args
115
- end
116
-
117
- # Pom default to all scopes, unless nested in a scope
118
- def pom(path, *args)
119
- opts = { }
120
-
121
- if args.last.is_a? Hash
122
- opts.merge!( args.last )
123
- end
124
-
125
- # if not scope opts and default scope, set to all
126
- unless opts[:scope] || opts[:scopes] || @scope_changed
127
- opts[:scope] = Dsl.scopes
128
- end
129
-
130
- artifact( path, opts )
131
- end
132
-
133
- def read_file(file)
134
- File.open(file, "rb") { |f| f.read }
135
- end
136
-
137
- def repository( url, opts = {} )
138
- @repositories << url
139
- end
140
-
141
- def scope(*scopes, &blk)
142
- @scope_changed = true
143
- scopes.each do |scope|
144
- @present_scope = scope.to_s
145
- yield
146
- end
147
- @scope_changed = false
148
- @present_scope = 'compile'
149
- end
150
-
151
- private
152
- def artifact(artifact, opts)
153
-
154
- scopes = opts[:scope] || opts[:scopes] || opts[:group]
155
-
156
- if scopes
157
-
158
- unless scopes.is_a? Array
159
- scopes = [scopes]
160
- end
161
-
162
- # include present scope if within a scope block
163
- if @scope_changed
164
- scopes << @present_scope
165
- end
166
-
167
- else
168
- scopes = [@present_scope]
169
- end
170
-
171
- if artifact
172
- scopes.uniq.each do |scope|
173
- scope = 'compile' if scope.to_s == 'development'
174
-
175
- if @notations[scope.to_s]
176
- @notations[scope.to_s] << artifact
177
- end
178
- end
179
- end
180
-
181
- end
182
-
183
- end
184
- end
@@ -1,21 +0,0 @@
1
- require 'lock_jar/registry'
2
-
3
- module LockJar::Rubygems
4
- module Kernel
5
- unless respond_to? :lock_jar_registry
6
- def lock_jar_registry
7
- LockJar::Registry.instance
8
- end
9
-
10
- alias :_pre_lockjar_require :require
11
-
12
- def require( filename )
13
- spec = Gem::Specification.find_by_path( filename )
14
- if spec
15
- lock_jar_registry.load_gem( spec )
16
- end
17
- _pre_lockjar_require( filename )
18
- end
19
- end
20
- end
21
- end
@@ -1,84 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__),'../spec_helper'))
2
-
3
- describe LockJar::Dsl do
4
- context "Instance" do
5
- it "should load a Jarfile" do
6
- jarfile = LockJar::Dsl.evaluate( "spec/Jarfile" )
7
-
8
- jarfile.local_repository.should eql '~/.m2/repository'
9
- jarfile.notations.should eql( {
10
- "compile"=>["org.apache.mina:mina-core:2.0.4", "spec/pom.xml"],
11
- "runtime"=>["spec/pom.xml", "com.typesafe:config:jar:0.5.0"],
12
- "test"=>["spec/pom.xml", "junit:junit:jar:4.10"]} )
13
- jarfile.repositories.should eql( ['http://mirrors.ibiblio.org/pub/mirrors/maven2'] )
14
- end
15
-
16
- it "should load a block" do
17
- block = LockJar::Dsl.evaluate do
18
- local '~/.m2'
19
- repository 'http://repository.jboss.org/nexus/content/groups/public-jboss'
20
-
21
- jar "org.apache.mina:mina-core:2.0.4"
22
- pom 'spec/pom.xml'
23
-
24
- scope 'runtime' do
25
- jar 'org.apache.tomcat:servlet-api:jar:6.0.35'
26
- end
27
-
28
- scope 'test' do
29
- jar 'junit:junit:jar:4.10'
30
- end
31
- end
32
-
33
- block.local_repository.should eql '~/.m2'
34
- block.notations.should eql( {"compile"=>["org.apache.mina:mina-core:2.0.4", "spec/pom.xml"], "runtime"=>["spec/pom.xml", "org.apache.tomcat:servlet-api:jar:6.0.35"], "test"=>["spec/pom.xml", "junit:junit:jar:4.10"]} )
35
- block.repositories.should eql( ["http://repository.jboss.org/nexus/content/groups/public-jboss"] )
36
-
37
- end
38
-
39
- it "should raise an error without arguments" do
40
- lambda { LockJar::Dsl.evaluate }.should raise_error
41
- end
42
-
43
- it "should merge dsl" do
44
- block1 = LockJar::Dsl.evaluate do
45
- repository 'http://repository.jboss.org/nexus/content/groups/public-jboss'
46
-
47
- jar "org.apache.mina:mina-core:2.0.4"
48
- pom 'spec/pom.xml'
49
-
50
- scope 'runtime' do
51
- jar 'org.apache.tomcat:servlet-api:jar:6.0.35'
52
- end
53
-
54
- scope 'test' do
55
- jar 'junit:junit:jar:4.10'
56
- end
57
- end
58
-
59
- block2 = LockJar::Dsl.evaluate do
60
- repository 'http://repository.jboss.org/nexus/content/groups/public-jboss'
61
- repository 'http://new-repo'
62
-
63
- jar "org.apache.mina:mina-core:2.0.4"
64
- jar "compile-jar"
65
-
66
- scope 'runtime' do
67
- jar 'runtime-jar'
68
- pom 'runtime-pom'
69
- end
70
-
71
- scope 'test' do
72
- jar 'test-jar'
73
- pom 'test-pom'
74
- end
75
- end
76
-
77
- dsl = block1.merge( block2 )
78
-
79
- dsl.notations.should eql( {"compile"=>["org.apache.mina:mina-core:2.0.4", "spec/pom.xml", "compile-jar"], "runtime"=>["spec/pom.xml", "org.apache.tomcat:servlet-api:jar:6.0.35", "runtime-jar", "runtime-pom"], "test"=>["spec/pom.xml", "junit:junit:jar:4.10", "test-jar", "test-pom"]} )
80
- dsl.repositories.should eql( ["http://repository.jboss.org/nexus/content/groups/public-jboss", 'http://new-repo'] )
81
-
82
- end
83
- end
84
- end
@@ -1,43 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__),'../spec_helper'))
2
- require 'lib/lock_jar/rubygems'
3
-
4
-
5
- describe LockJar::Rubygems do
6
-
7
- include LockJar::Rubygems::Kernel
8
-
9
-
10
- it "should set Registry" do
11
- lock_jar_registry.is_a?( LockJar::Registry ).should be_true
12
- end
13
-
14
- context "with require" do
15
- before(:all) do
16
- require 'solr_sail'
17
- end
18
-
19
- it "should have only loaded jars for solr_sail" do
20
- lock_jar_registry.loaded_gems.keys.should eql(
21
- ["solr_sail"] )
22
- end
23
-
24
- it "should set classpath" do
25
- # XXX: Need a better assertion than this. The count will include previous tests
26
- $CLASSPATH.size.should eql( 71 )
27
- end
28
-
29
- it "should have correctly loaded SolrSail" do
30
- # manually load the jar packaged with the gem
31
- $CLASSPATH << SolrSail::DEFAULT_JAR
32
-
33
- # Start and stop solr
34
- # XXX: an assertion that the java is properly being called
35
- config = com.tobedevoured.solrsail.SolrConfig.new( 'tmp/solr')
36
- config.install
37
-
38
- server = com.tobedevoured.solrsail.JettyServer.new( 'tmp/solr' )
39
- server.start
40
- server.stop
41
- end
42
- end
43
- end