Class: JavaClass::Classpath::MavenArtefact

Inherits:
Object
  • Object
show all
Defined in:
lib/javaclass/classpath/maven_artefact.rb

Overview

A reference to a Maven artefact. This is a group/artefact/version tuple that points to a single Jar in the Maven repository.

Author

Peter Kofler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group, name, version, title = nil) ⇒ MavenArtefact

Create a Maven artefact with given group , name and version .



13
14
15
16
17
18
# File 'lib/javaclass/classpath/maven_artefact.rb', line 13

def initialize(group, name, version, title=nil)
  @group = group
  @name = name
  @version = version
  @title = title || make_title
end

Instance Attribute Details

#groupObject (readonly)

Returns the value of attribute group.



10
11
12
# File 'lib/javaclass/classpath/maven_artefact.rb', line 10

def group
  @group
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/javaclass/classpath/maven_artefact.rb', line 10

def name
  @name
end

#titleObject (readonly)

Returns the value of attribute title.



10
11
12
# File 'lib/javaclass/classpath/maven_artefact.rb', line 10

def title
  @title
end

#versionObject (readonly)

Returns the value of attribute version.



10
11
12
# File 'lib/javaclass/classpath/maven_artefact.rb', line 10

def version
  @version
end

Instance Method Details

#classpathObject

Return this Maven artefact’s JavaClass::Classpath. This is a single Jar in the Maven repository.



28
29
30
31
32
# File 'lib/javaclass/classpath/maven_artefact.rb', line 28

def classpath
  cp = CompositeClasspath.new(basename)
  cp.add_file_name(repository_path)
  cp
end

#download_if_neededObject

Kind of hack function to call Maven to download the current artefact if it does not exist.



21
22
23
24
25
# File 'lib/javaclass/classpath/maven_artefact.rb', line 21

def download_if_needed
  unless File.exist? repository_path
    puts `#{download_command}`
  end
end

#repository_pathObject

Return the Jar’s file path of this artefact inside ~/.m2/repository



35
36
37
# File 'lib/javaclass/classpath/maven_artefact.rb', line 35

def repository_path
  File.join(ENV['HOME'], '.m2', 'repository', @group.gsub(/\./, '/'),  @name, @version, "#{basename}.jar" )
end