lib/maven/tools/dsl/jarfile.rb in maven-tools-1.0.5 vs lib/maven/tools/dsl/jarfile.rb in maven-tools-1.0.6
- old
+ new
@@ -16,55 +16,110 @@
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
-require 'maven/tools/dsl/jruby_dsl'
require 'maven/tools/dsl/dependency_dsl'
+require 'maven/tools/dsl/jarfile_lock'
module Maven
module Tools
module DSL
class Jarfile
extend Options
- class Data
+ class ParentWithLock
+
+ class Guarded < SimpleDelegator
+ def initialize(deps, lock_file)
+ super deps
+ @lock = lock_file
+ end
+
+ def <<( d )
+ unless @lock.locked?( "#{d.group_id}:#{d.artifact_id}" )
+ super d
+ end
+ end
+ end
+
+ attr_reader :lock, :parent
+
+ def initialize( parent, lock_file )
+ @lock = lock_file
+ @parent = parent
+ # TODO remove case when parent is nil
+ @deps = Guarded.new( parent ? parent.dependencies : [],
+ lock_file )
+ end
+
def dependencies
- @dependencies ||= []
+ @deps
end
end
def artifacts
# TODO remove this part
@artifacts ||= []
end
def repositories
+ # TODO remove this part
@repositories ||= []
end
def snapshot_repositories
+ # TODO remove this part
@snapshot_repositories ||= []
end
- def initialize( file = 'Jarfile', parent = Data.new )
- @parent = parent
+ def initialize( parent, file = 'Jarfile', skip_lock = false )
+ warn "DEPRECATED to have nil as parent" unless parent
+ lockfile = JarfileLock.new( skip_lock ? nil : file )
+
+ # the dependencies are only add if they are not locked
+ @parent = ParentWithLock.new( parent, lockfile )
+
+ # parse jarfile DSL
eval( File.read( file ) )
+
+ # fill dependencies from lockfile
+ lockfile.coordinates.each do |d|
+ a = Maven::Tools::Artifact.from_coordinate( d )
+ add( a ) unless a[:systemPath]
+ end
+ scope( :test ) do
+ lockfile.coordinates( :test ).each do |d|
+ a = Maven::Tools::Artifact.from_coordinate( d )
+ add( a ) unless a[:systemPath]
+ end
+ end
end
- attr_reader :parent
-
+
+ def add( artifact )
+ dep = Dependency.new
+
+ # use the fill_options to fill up the dependency
+ self.class.fill_options( dep, artifact, :type )
+
+ # adjust the scope
+ dep.scope = @scope if @scope
+
+ # use the original parent if present
+ (@parent.parent || @parent ).dependencies << dep
+ end
+
def help
warn "\n# Jarfile DSL #\n"
- warn self.class.help_block( :local => "path-to-local-jar", :jar => nil, :pom => nil, :repository => nil, :snapshot_repository => nil, :jruby => nil, :scope => nil)[0..-2]
+ warn self.class.help_block( :local => "path-to-local-jar", :jar => nil, :pom => nil, :repository => nil, :snapshot_repository => nil, :scope => nil)[0..-2]
end
def local( path )
a = Artifact.new_local( ::File.expand_path( path ), :jar )
- dep = Dependency.new
- self.class.fill_options( dep, a )
- @parent.dependencies << dep
+ add( a )
# TODO remove this part
artifacts << a
+ a
end
def jar( *args, &block )
a = DependencyDSL.create( @parent, :jar, @scope, *args, &block )
# TODO remove this part
@@ -100,14 +155,15 @@
ensure
@scope = nil
end
def jruby( *args, &block )
- if args.empty? && !block
- @jruby ? @jruby.legacy_version : nil
- else
- @jruby = JRubyDSL.create( @parent, :provided, *args, &block )
- end
+ warn "DEPRECATED jruby declaration has no effect anymore"
+ # if args.empty? && !block
+ # @jruby ? @jruby.legacy_version : nil
+ # else
+ # @jruby = JRubyDSL.create( @parent, :provided, *args, &block )
+ # end
end
end
end
end
end