gjp 0.28.0 → 0.29.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -154,9 +154,14 @@ If you use Maven, most sources for binary jars in your kit can be automatically
154
154
 
155
155
  gjp get-maven-source-jars
156
156
 
157
- For non-Maven jars, or Maven jars that have no available sources, some extra manual work is needed. At the moment `gjp` can help you with the following utility subcommands:
157
+ For non-Maven jars, or Maven jars that have no available sources, some extra manual work is needed. First of all, you should get a `pom.xml` file for your jar, if you don't have it already:
158
+
159
+ gjp get-pom jarname.jar
160
+
161
+ This will create a `jarname.pom` file (if it can be found in Maven Central, otherwise you will need to search the Internet manually).
162
+
163
+ If you are lucky, the pom file will contain an URL to a site where sources can be downloaded, or even an SCM address. At the moment automatic source retrieval is not automated, but `gjp` can help you with the following utility subcommands:
158
164
 
159
- * `gjp get-pom NAME` will attempt to find a pom. `NAME` can be a jar file on your disk, a project directory, or simply a `name-version` string. `gjp` will get the pom either from the package itself or through search.maven.org using heuristic searching;
160
165
  * `gjp get-parent-pom POM` will attempt to download a pom's parent from search.maven.org, where `POM` is a filename or URI;
161
166
  * `gjp get-source-address POM` will attempt to find the SCM Internet address of a pom.xml from the file itself or through api.github.com. `POM` can either be a filename or a URI;
162
167
  * `gjp get-source POM ADDRESS` downloads the source of a pom.xml's project from its SCM at ADDRESS;
@@ -169,7 +174,7 @@ Building Ant packages is not really different from Maven ones, as `gjp ant` will
169
174
 
170
175
  Sometimes you will have jar files distributed along with the source archive that will end up in `src/`: you don't want that, just run `gjp purge-jars` to have them moved to the kit. The command will generate a symlink back to the original, so builds will not fail.
171
176
 
172
- Once built, you are advised to grab an "informational" pom.xml (via `gjp get-pom` or Maven Central) in order to generate its spec.
177
+ Once built, you should get a pom.xml file (via `gjp get-pom`, see above) in order to generate its spec.
173
178
 
174
179
  #### Optional: running networkless dry-run builds
175
180
 
data/lib/gjp/cli.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # encoding: UTF-8
2
2
  require "gjp/logger"
3
3
  require "clamp"
4
+ require "open-uri"
4
5
 
5
6
  module Gjp
6
7
  class MainCommand < Clamp::Command
@@ -281,11 +282,27 @@ module Gjp
281
282
  end
282
283
  end
283
284
 
284
- subcommand "get-pom", "Retrieves a pom corresponding to a filename" do
285
- parameter "NAME", "a jar file path, a project directory path or a non-existing filename in the `project-version` form"
285
+ subcommand "get-pom", "Retrieves a pom file" do
286
+ parameter "NAME", "a jar file name or a `name-version` string (heuristic)"
286
287
  def execute
287
- checking_exceptions do
288
- puts Gjp::PomGetter.new.get_pom(name)
288
+ checking_exceptions do
289
+ project = Gjp::Project.new(".")
290
+ pom_getter = Gjp::PomGetter.new
291
+
292
+ path, status = pom_getter.get_pom(name)
293
+ if path
294
+ text_status = if status == :found_in_jar
295
+ "was inside the jar"
296
+ elsif status == :found_via_sha1
297
+ "found by sha1 search from search.maven.org"
298
+ elsif status == :found_via_heuristic
299
+ "found by heuristic search from search.maven.org"
300
+ end
301
+
302
+ puts "#{format_path(path, project)} written, #{text_status}"
303
+ else
304
+ puts "#{name} not found. Try http://google.com/#q=#{URI::encode(pom_getter.cleanup_name(name))}"
305
+ end
289
306
  end
290
307
  end
291
308
  end
@@ -293,7 +310,7 @@ module Gjp
293
310
  subcommand "get-parent-pom", "Retrieves a pom that is the parent of an existing pom" do
294
311
  parameter "POM", "a pom file path or URI"
295
312
  def execute
296
- checking_exceptions do
313
+ checking_exceptions do
297
314
  puts Gjp::ParentPomGetter.new.get_parent_pom(pom)
298
315
  end
299
316
  end
@@ -13,35 +13,30 @@ module Gjp
13
13
  class PomGetter
14
14
  include Logger
15
15
 
16
- # returns the pom corresponding to a filename
16
+ # saves a jar poms in <jar_filename>.pom
17
+ # returns filename and status if found, else nil
17
18
  def get_pom(filename)
18
- (get_pom_from_dir(filename) or get_pom_from_jar(filename) or get_pom_from_sha1(filename) or get_pom_from_heuristic(filename))
19
- end
20
-
21
- # returns the pom in a project directory
22
- def get_pom_from_dir(dir)
23
- if File.directory?(dir)
24
- pom_path = File.join(dir, "pom.xml")
25
- if File.file?(pom_path)
26
- log.info("pom.xml found in #{dir}/pom.xml")
27
- return File.read(pom_path)
28
- end
19
+ content, status = (get_pom_from_jar(filename) or get_pom_from_sha1(filename) or get_pom_from_heuristic(filename))
20
+ if content
21
+ pom_filename = filename.sub(/(\.jar)?$/, ".pom")
22
+ File.open(pom_filename, "w") { |io| io.write(content) }
23
+ [pom_filename, status]
29
24
  end
30
25
  end
31
-
26
+
32
27
  # returns a pom embedded in a jar file
33
28
  def get_pom_from_jar(file)
34
29
  begin
35
30
  Zip::ZipFile.foreach(file) do |entry|
36
31
  if entry.name =~ /\/pom.xml$/
37
32
  log.info("pom.xml found in #{file}##{entry.name}")
38
- return entry.get_input_stream.read
33
+ return entry.get_input_stream.read, :found_in_jar
39
34
  end
40
35
  end
41
36
  rescue Zip::ZipError
42
- log.info "#{file} does not seem to be a valid jar archive, skipping"
37
+ log.warn("#{file} does not seem to be a valid jar archive, skipping")
43
38
  rescue TypeError
44
- log.info "#{file} seems to be a valid jar archive but is corrupt, skipping"
39
+ log.warn("#{file} seems to be a valid jar archive but is corrupt, skipping")
45
40
  end
46
41
  return nil
47
42
  end
@@ -57,12 +52,12 @@ module Gjp
57
52
  if result != nil
58
53
  log.info("pom.xml for #{file} found on search.maven.org for sha1 #{sha1} (#{result["g"]}:#{result["a"]}:#{result["v"]})")
59
54
  group_id, artifact_id, version = site.get_maven_id_from result
60
- return site.download_pom(group_id, artifact_id, version)
55
+ return site.download_pom(group_id, artifact_id, version), :found_via_sha1
61
56
  end
62
57
  end
63
58
  return nil
64
59
  rescue RestClient::ResourceNotFound
65
- $stderr.puts "Got an error while looking for #{file}'s SHA1 in search.maven.org"
60
+ log.error("Got an error while looking for #{file}'s SHA1 in search.maven.org")
66
61
  end
67
62
  end
68
63
 
@@ -70,7 +65,7 @@ module Gjp
70
65
  def get_pom_from_heuristic(filename)
71
66
  begin
72
67
  site = MavenWebsite.new
73
- filename = Pathname.new(filename).basename.to_s.sub(/.jar$/, "")
68
+ filename = cleanup_name(filename)
74
69
  version_matcher = VersionMatcher.new
75
70
  my_artifact_id, my_version = version_matcher.split_version(filename)
76
71
 
@@ -85,11 +80,16 @@ module Gjp
85
80
  group_id, artifact_id, version = site.get_maven_id_from(best_matched_result)
86
81
  log.warn("pom.xml for #{filename} found on search.maven.org with heuristic search (#{group_id}:#{artifact_id}:#{version})")
87
82
 
88
- return site.download_pom(group_id, artifact_id, version)
83
+ return site.download_pom(group_id, artifact_id, version), :found_via_heuristic
89
84
  end
90
85
  rescue RestClient::ResourceNotFound
91
- $stderr.puts "Got an error while looking for #{filename} in search.maven.org"
86
+ log.error("Got an error while looking for #{filename}'s SHA1 in search.maven.org")
92
87
  end
93
88
  end
89
+
90
+ # get a heuristic name from a path
91
+ def cleanup_name(path)
92
+ Pathname.new(path).basename.to_s.sub(/.jar$/, "")
93
+ end
94
94
  end
95
95
  end
data/lib/gjp/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module Gjp
4
- VERSION = "0.28.0"
4
+ VERSION = "0.29.0"
5
5
  end
@@ -6,31 +6,25 @@ describe Gjp::PomGetter do
6
6
  let(:pom_getter) { Gjp::PomGetter.new }
7
7
 
8
8
  describe "#get_pom" do
9
- it "gets the pom from a directory" do
10
- dir_path = File.join("spec", "data", "commons-logging")
11
- pom_path = File.join(dir_path, "pom.xml")
12
- pom_getter.get_pom(dir_path).should eq(File.read(pom_path))
13
- end
14
-
15
9
  it "gets the pom from a jar" do
16
10
  dir_path = File.join("spec", "data", "commons-logging")
17
- pom_path = File.join(dir_path, "pom.xml")
18
11
  jar_path = File.join(dir_path, "commons-logging-1.1.1.jar")
19
- pom_getter.get_pom(jar_path).should eq(File.read(pom_path))
12
+ path, status = pom_getter.get_pom(jar_path)
13
+ status.should eq :found_in_jar
20
14
  end
21
15
 
22
16
  it "gets the pom from sha1" do
23
17
  dir_path = File.join("spec", "data", "antlr")
24
- pom_path = File.join(dir_path, "pom.xml")
25
18
  jar_path = File.join(dir_path, "antlr-2.7.2.jar")
26
- pom_getter.get_pom(jar_path).should eq(File.read(pom_path))
19
+ path, status = pom_getter.get_pom(jar_path)
20
+ status.should eq :found_via_sha1
27
21
  end
28
22
 
29
23
  it "gets the pom from a heuristic" do
30
24
  dir_path = File.join("spec", "data", "nailgun")
31
- pom_path = File.join(dir_path, "pom.xml")
32
25
  jar_path = File.join(dir_path, "nailgun-0.7.1.jar")
33
- pom_getter.get_pom(jar_path).should eq(File.read(pom_path))
26
+ path, status = pom_getter.get_pom(jar_path)
27
+ status.should eq :found_via_heuristic
34
28
  end
35
29
  end
36
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gjp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.28.0
4
+ version: 0.29.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: