Class: LockJar::Maven

Inherits:
Object
  • Object
show all
Defined in:
lib/lock_jar/maven.rb

Overview

Helper for providing Maven specific operations

Author:

  • Michael Guymon

Class Method Summary collapse

Class Method Details

.dependencies(pom_path, scopes = %w(compile runtime))) ⇒ String

Get dependencies of a Pom

Parameters:

  • pom_path (String)

    path to the pom

  • scopes (Array) (defaults to: %w(compile runtime)))

Returns:

  • (String)

    version of POM



45
46
47
48
# File 'lib/lock_jar/maven.rb', line 45

def dependencies(pom_path, scopes = %w(compile runtime))
  maven = Naether::Maven.create_from_pom(pom_path)
  maven.dependencies(scopes)
end

.deploy_artifact(notation, file_path, url, deploy_opts = {}, lockjar_opts = {}) ⇒ Object

Deploy an artifact to a Maven repository

Parameters:

  • notation (String)

    of artifact

  • file_path (String)

    path to the Jar

  • url (String)

    Maven repository deploying to

  • deploy_opts (Hash) (defaults to: {})

    options for deploying

  • lockjar_opts (Hash) (defaults to: {})

    options for initializing LockJar



94
95
96
97
# File 'lib/lock_jar/maven.rb', line 94

def deploy_artifact(notation, file_path, url, deploy_opts = {}, lockjar_opts = {})
  Runtime.instance.resolver(lockjar_opts).naether.deploy_artifact(
    notation, file_path, url, deploy_opts)
end

.install(notation, pom_path, jar_path, opts = {}) ⇒ Object

Install an artifact to a local repository

Parameters:

  • notation (String)

    of artifact

  • pom_path (String)

    path to the pom

  • jar_path (String)

    path to the jar

  • opts (Hash) (defaults to: {})

    options



107
108
109
# File 'lib/lock_jar/maven.rb', line 107

def install(notation, pom_path, jar_path, opts = {})
  Runtime.instance.resolver(opts).naether.install(notation, pom_path, jar_path)
end

.pom_version(pom_path) ⇒ String

Get the version of a POM

Parameters:

  • pom_path (String)

    path to the pom

Returns:

  • (String)

    version of POM



32
33
34
35
# File 'lib/lock_jar/maven.rb', line 32

def pom_version(pom_path)
  maven = Naether::Maven.create_from_pom(pom_path)
  maven.version
end

.write_pom(notation, file_path, opts = {}) ⇒ Object

Write a POM from list of notations

Parameters:

  • pom (String)

    notation

  • file_path (String)

    path of new pom

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :include_resolved (Boolean)

    to add dependencies of resolve dependencies from Jarfile.lock. Default is true.

  • :dependencies (Array)

    Array of of mixed dependencies:

    • String

      Artifact notation, such as groupId:artifactId:version, e.g. ‘junit:junit:4.7’

    • Hash

      of a single artifaction notation => scope - { ‘junit:junit:4.7’ => ‘test’ }



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/lock_jar/maven.rb', line 62

def write_pom(notation, file_path, opts = {})
  opts = { include_resolved: true }.merge(opts)

  maven = Naether::Maven.create_from_notataion(notation)

  if opts[:include_resolved]
    # Passes in nil to the resolver to get the cache
    maven.load_naether(Runtime.instance.resolver.naether)
  end

  if opts[:dependencies]
    opts[:dependencies].each do |dep|
      if dep.is_a? Array
        maven.add_dependency(dep[0], dep[1])
      else
        maven.add_dependency(dep)
      end
    end
  end

  maven.write_pom(file_path)
end