Module: LockJar

Defined in:
lib/lock_jar.rb,
lib/lock_jar/cli.rb,
lib/lock_jar/maven.rb,
lib/lock_jar/config.rb,
lib/lock_jar/bundler.rb,
lib/lock_jar/logging.rb,
lib/lock_jar/runtime.rb,
lib/lock_jar/version.rb,
lib/lock_jar/registry.rb,
lib/lock_jar/resolver.rb,
lib/lock_jar/domain/dsl.rb,
lib/lock_jar/class_loader.rb,
lib/lock_jar/runtime/list.rb,
lib/lock_jar/runtime/load.rb,
lib/lock_jar/runtime/lock.rb,
lib/lock_jar/domain/gem_dsl.rb,
lib/lock_jar/domain/artifact.rb,
lib/lock_jar/domain/lockfile.rb,
lib/lock_jar/runtime/install.rb,
lib/lock_jar/domain/dsl_merger.rb,
lib/lock_jar/domain/jarfile_dsl.rb

Overview

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

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.

Defined Under Namespace

Modules: Domain Classes: Bundler, CLI, ClassLoader, Config, Logging, Maven, Registry, Resolver, Runtime

Constant Summary collapse

VERSION =

still the version

'0.15.2'.freeze

Class Method Summary collapse

Class Method Details

.config(opts) ⇒ Object

Override LockJar configuration



36
37
38
# File 'lib/lock_jar.rb', line 36

def config(opts)
  Runtime.instance.resolver(opts)
end

.extract_args(type, args, &blk) ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/lock_jar.rb', line 174

def extract_args(type, args, &blk)
  lockfile_or_path = nil
  opts = {}
  groups = ['default']
  args.each do |arg|
    case arg
    when Hash
      opts.merge!(arg)
    when String
      lockfile_or_path = arg
    when LockJar::Domain::Lockfile
      lockfile_or_path = arg if type == :lockfile
    when LockJar::Domain::Dsl
      lockfile_or_path = arg if type == :jarfile
    when Array
      groups = arg
    end
  end
  if blk.nil? && lockfile_or_path.nil?
    if type == :lockfile
      lockfile_or_path = opts.fetch(:lockfile, 'Jarfile.lock')
    elsif type == :jarfile
      lockfile_or_path = 'Jarfile'
    end
  end
  [lockfile_or_path, groups, opts]
end

.install(*args, &blk) ⇒ Object



40
41
42
43
# File 'lib/lock_jar.rb', line 40

def install(*args, &blk)
  lockfile, groups, opts = extract_args :lockfile, args, &blk
  Runtime.instance.install(lockfile, groups, opts, &blk)
end

.list(*args, &blk) ⇒ Array

Lists all dependencies as notations for groups from the Jarfile.lock. Depending on the type of arg, a different configuration is set.

  • An arg of a String will set the Jarfile.lock, e.g. ‘Better.lock’. Default lock file is Jarfile.lock.

  • An arg of an Array will set the groups, e.g. [‘development’,‘test’]. Defaults group is default

  • An arg of a Hash will set the options, e.g. { :local_repo => ‘path’ }

    • :local_repo [String] sets the local repo path

    • :local_paths [Boolean] to true converts the notations to paths to jars

      in the local repo path
      
    • :resolve [Boolean] to true will make transitive dependences resolve

      before loading to classpath
      

A block can be passed in, overriding values from a Jarfile.lock.

Returns:

  • (Array)

    of jar and mapped path



62
63
64
65
# File 'lib/lock_jar.rb', line 62

def list(*args, &blk)
  lockfile, groups, opts = extract_args :lockfile, args, &blk
  Runtime.instance.list(lockfile, groups, opts, &blk)
end

.load(*args, &blk) ⇒ Array

LockJar.load(*args): Loads all dependencies to the classpath for groups from the Jarfile.lock. Depending on the type of arg, a different configuration is set.

  • An arg of a String will set the Jarfile.lock, e.g. ‘Better.lock’. Default lock file is Jarfile.lock.

  • An arg of an Array will set the groups, e.g. [‘development’,‘test’]. Defaults group is default.

  • An arg of a Hash will set the options, e.g. { :local_repo => ‘path’ }

    * :local_repo [String] sets the local repo path
    * :resolve [Boolean] to true will make transitive dependences resolve
                         before loading to classpath
    * :disable [Boolean] to true will disable any additional calls to load and lock
    

A block can be passed in, overriding values from a Jarfile.lock.

Returns:

  • (Array)

    of absolute paths of jars and mapped paths loaded into claspath



82
83
84
85
86
87
88
89
90
# File 'lib/lock_jar.rb', line 82

def load(*args, &blk)
  if Runtime.instance.opts.nil? || !Runtime.instance.opts[:disable]
    lockfile, groups, opts = extract_args(:lockfile, args, &blk)
    Runtime.instance.load(lockfile, groups, opts, &blk)
  else
    puts 'LockJar#load has been disabled'
    []
  end
end

.lock(*args, &blk) ⇒ Hash

A block can be passed in, overriding values from a Jarfile.

Returns:

  • (Hash)

    Lock data



108
109
110
111
112
113
114
115
116
# File 'lib/lock_jar.rb', line 108

def lock(*args, &blk)
  if Runtime.instance.opts.nil? || !Runtime.instance.opts[:disable]
    jarfile, _, opts = extract_args(:jarfile, args, &blk)
    Runtime.instance.lock(jarfile, opts, &blk)
  else
    puts 'LockJar#lock has been disabled'
    []
  end
end

.lock_registered_jarfiles(*args, &blk) ⇒ Hash

Lock the registered Jarfiles and generate a Jarfile.lock.

Options and groups are passed through to the LockJar.lock method, but if a Jarfile is specified, it will be ignored. Use LockJar.register_jarfile to add dependencies.

A block can be passed in, overriding values from the Jarfiles.

Returns:

  • (Hash)

    Lock data



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/lock_jar.rb', line 156

def lock_registered_jarfiles(*args, &blk)
  jarfiles = registered_jarfiles
  return if jarfiles.empty?
  instances = jarfiles.map do |jarfile, spec|
    if spec
      LockJar::Domain::GemDsl.create spec, jarfile
    else
      LockJar::Domain::JarfileDsl.create jarfile
    end
  end
  combined = instances.reduce do |result, inst|
    LockJar::Domain::DslMerger.new(result, inst).merge
  end
  args = args.reject { |arg| arg.is_a? String }
  lock(combined, *args, &blk)
end

.read(lockfile) ⇒ Hash

Read a Jafile.lock and convert it to a LockJar::Domain::Lockfile

Parameters:

  • lockfile (String)

    path to lockfile

Returns:

  • (Hash)

    Lock Data



123
124
125
# File 'lib/lock_jar.rb', line 123

def read(lockfile)
  LockJar::Domain::Lockfile.read(lockfile)
end

.register_jarfile(jarfile, gem_spec = nil) ⇒ Array

Add a Jarfile to be included when LockJar.lock_registered_jarfiles is called.

Parameters:

  • jarfile (String)

    path to register

  • gem (GemSpec)

    spec if the Jarfile is from a gem

Returns:

  • (Array)

    All registered jarfiles



132
133
134
135
# File 'lib/lock_jar.rb', line 132

def register_jarfile(jarfile, gem_spec = nil)
  fail "Jarfile not found: #{jarfile}" unless File.exist? jarfile
  registered_jarfiles[jarfile] = gem_spec
end

.registered_jarfilesObject

Hash of registered jarfiles



143
144
145
# File 'lib/lock_jar.rb', line 143

def registered_jarfiles
  @registered_jarfiles ||= {}
end

.reset_registered_jarfilesObject

Clear all registered jarfiles



138
139
140
# File 'lib/lock_jar.rb', line 138

def reset_registered_jarfiles
  @registered_jarfiles = {}
end