gjp 0.36.0 → 0.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. data/.gitignore +4 -0
  2. data/.rubocop.yml +7 -0
  3. data/.rubocop_todo.yml +241 -0
  4. data/SPECIAL_CASES.md +2 -5
  5. data/integration-tests/commons.sh +2 -0
  6. data/lib/gjp.rb +22 -1
  7. data/lib/gjp/ant_runner.rb +1 -1
  8. data/lib/gjp/archiver.rb +11 -11
  9. data/lib/gjp/commands/ant.rb +21 -0
  10. data/lib/gjp/commands/base.rb +94 -0
  11. data/lib/gjp/commands/download-maven-source-jars.rb +28 -0
  12. data/lib/gjp/commands/dry-run.rb +16 -0
  13. data/lib/gjp/commands/finish.rb +22 -0
  14. data/lib/gjp/commands/generate-all.rb +38 -0
  15. data/lib/gjp/commands/generate-kit-archive.rb +18 -0
  16. data/lib/gjp/commands/generate-kit-spec.rb +16 -0
  17. data/lib/gjp/commands/generate-package-archive.rb +19 -0
  18. data/lib/gjp/commands/generate-package-script.rb +21 -0
  19. data/lib/gjp/commands/generate-package-spec.rb +22 -0
  20. data/lib/gjp/commands/get-pom.rb +31 -0
  21. data/lib/gjp/commands/get-source.rb +35 -0
  22. data/lib/gjp/commands/init.rb +15 -0
  23. data/lib/gjp/commands/list-kit-missing-sources.rb +21 -0
  24. data/lib/gjp/commands/move-jars-to-kit.rb +18 -0
  25. data/lib/gjp/commands/mvn.rb +22 -0
  26. data/lib/gjp/git.rb +18 -8
  27. data/lib/gjp/kit_checker.rb +6 -6
  28. data/lib/gjp/kit_runner.rb +2 -2
  29. data/lib/gjp/kit_spec_adapter.rb +1 -1
  30. data/lib/gjp/main.rb +103 -0
  31. data/lib/gjp/maven_runner.rb +1 -1
  32. data/lib/gjp/maven_website.rb +8 -6
  33. data/lib/gjp/package_spec_adapter.rb +1 -1
  34. data/lib/gjp/pom.rb +3 -1
  35. data/lib/gjp/pom_getter.rb +12 -4
  36. data/lib/gjp/project.rb +4 -2
  37. data/lib/gjp/script_generator.rb +2 -1
  38. data/lib/gjp/spec_generator.rb +2 -2
  39. data/lib/gjp/version.rb +1 -1
  40. data/lib/gjp/version_matcher.rb +3 -3
  41. data/lib/template/kit.spec +1 -0
  42. data/lib/template/package.spec +1 -0
  43. data/spec/lib/ant_runner_spec.rb +3 -3
  44. data/spec/lib/archiver_spec.rb +1 -1
  45. data/spec/lib/git_spec.rb +25 -3
  46. data/spec/lib/kit_checker_spec.rb +6 -6
  47. data/spec/lib/kit_runner_spec.rb +1 -1
  48. data/spec/lib/maven_runner_spec.rb +6 -5
  49. data/spec/lib/maven_website_spec.rb +2 -2
  50. data/spec/lib/pom_getter_spec.rb +1 -1
  51. data/spec/lib/pom_spec.rb +5 -3
  52. data/spec/lib/project_spec.rb +15 -14
  53. data/spec/lib/script_generator_spec.rb +4 -2
  54. data/spec/lib/source_getter_spec.rb +1 -1
  55. data/spec/lib/spec_generator_spec.rb +2 -2
  56. data/spec/lib/template_manager_spec.rb +6 -6
  57. data/spec/lib/version_matcher_spec.rb +1 -1
  58. data/spec/spec_helper.rb +25 -23
  59. metadata +22 -3
  60. data/lib/gjp/cli.rb +0 -384
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
5
  shared_examples_for Gjp::KitRunner do
6
6
  include Gjp::Mockers
@@ -1,7 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'spec_helper'
4
- require 'lib/kit_runner_spec'
3
+ require "spec_helper"
4
+ require "lib/kit_runner_spec"
5
5
 
6
6
  describe Gjp::MavenRunner do
7
7
  it_behaves_like Gjp::KitRunner
@@ -35,7 +35,7 @@ describe Gjp::MavenRunner do
35
35
  create_mock_executable("mvn")
36
36
  @project.from_directory do
37
37
  @kit_runner.mvn(["extra-option"])
38
- File.read("test_out").strip.should match /extra-option$/
38
+ File.read("test_out").strip.should match(/extra-option$/)
39
39
  end
40
40
  end
41
41
  it "doesn't run Maven if it is not available" do
@@ -50,7 +50,8 @@ describe Gjp::MavenRunner do
50
50
  create_mock_executable("mvn")
51
51
  @project.from_directory do
52
52
  @kit_runner.get_source_jar("test_group", "test_artifact_id", "test_version")
53
- File.read("test_out").strip.should match /dependency:get -Dartifact=test_group:test_artifact_id:test_version:jar:sources -Dtransitive=false$/
53
+ expected = /dependency:get -Dartifact=test_group:test_artifact_id:test_version:jar:sources -Dtransitive=false$/
54
+ File.read("test_out").strip.should match expected
54
55
  end
55
56
  end
56
57
  end
@@ -60,7 +61,7 @@ describe Gjp::MavenRunner do
60
61
  create_mock_executable("mvn")
61
62
  @project.from_directory do
62
63
  @kit_runner.get_effective_pom("test.pom").should eq "test.pom.effective"
63
- File.read("test_out").strip.should match /help:effective-pom -ftest.pom -Doutput=test.pom.effective$/
64
+ File.read("test_out").strip.should match(/help:effective-pom -ftest.pom -Doutput=test.pom.effective$/)
64
65
  end
65
66
  end
66
67
  end
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
5
  describe Gjp::MavenWebsite do
6
6
  let(:site) { Gjp::MavenWebsite.new }
@@ -42,7 +42,7 @@ describe Gjp::MavenWebsite do
42
42
 
43
43
  describe "#get_maven_id_from" do
44
44
  it "uses search.maven.org to look for poms" do
45
- site.get_maven_id_from({"g" => 1, "a" => 2, "v" => 3}).should eq([1, 2, 3])
45
+ site.get_maven_id_from("g" => 1, "a" => 2, "v" => 3).should eq([1, 2, 3])
46
46
  end
47
47
  end
48
48
 
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
5
  describe Gjp::PomGetter do
6
6
  let(:pom_getter) { Gjp::PomGetter.new }
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
5
  describe Gjp::Pom do
6
6
  let(:pom) { Gjp::Pom.new(File.join("spec", "data", "commons-logging", "pom.xml")) }
@@ -31,7 +31,8 @@ describe Gjp::Pom do
31
31
 
32
32
  describe "#description" do
33
33
  it "reads the description" do
34
- pom.description.should eq "Commons Logging is a thin adapter allowing configurable bridging to other,\n well known logging systems."
34
+ pom.description.should eq "Commons Logging is a thin adapter allowing configurable bridging to other,\n " +
35
+ "well known logging systems."
35
36
  end
36
37
  end
37
38
 
@@ -55,7 +56,8 @@ describe Gjp::Pom do
55
56
 
56
57
  describe "#scm_connection" do
57
58
  it "reads the SCM connection address" do
58
- pom.scm_connection.should eq "scm:svn:http://svn.apache.org/repos/asf/commons/proper/logging/tags/commons-logging-1.1.1"
59
+ pom.scm_connection.should eq "scm:svn:http://svn.apache.org/repos/asf/commons/proper/" +
60
+ "logging/tags/commons-logging-1.1.1"
59
61
  end
60
62
  end
61
63
 
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
5
  describe Gjp::Project do
6
6
  before(:each) do
@@ -29,41 +29,41 @@ describe Gjp::Project do
29
29
  Gjp::Project.find_project_dir(File.expand_path("src", @project_path)).should eq expanded_path
30
30
  Gjp::Project.find_project_dir(File.expand_path("kit", @project_path)).should eq expanded_path
31
31
 
32
- expect {
32
+ expect do
33
33
  Gjp::Project.find_project_dir(File.expand_path("..", @project_path)).should raise_error
34
- }.to raise_error(Gjp::NoProjectDirectoryError)
34
+ end.to raise_error(Gjp::NoProjectDirectoryError)
35
35
  end
36
36
  end
37
37
 
38
38
  describe ".get_package_name" do
39
39
  it "raises an error with a directory outside a gjp project" do
40
- expect {
40
+ expect do
41
41
  @project.get_package_name("/")
42
- }.to raise_error(Gjp::NoPackageDirectoryError)
42
+ end.to raise_error(Gjp::NoPackageDirectoryError)
43
43
  end
44
44
 
45
45
  it "raises an error with a gjp project directory" do
46
- expect {
46
+ expect do
47
47
  @project.get_package_name(@project_path)
48
- }.to raise_error(Gjp::NoPackageDirectoryError)
48
+ end.to raise_error(Gjp::NoPackageDirectoryError)
49
49
  end
50
50
 
51
51
  it "raises an error with a gjp kit directory" do
52
- expect {
52
+ expect do
53
53
  @project.get_package_name(File.join(@project_path, "kit"))
54
- }.to raise_error(Gjp::NoPackageDirectoryError)
54
+ end.to raise_error(Gjp::NoPackageDirectoryError)
55
55
  end
56
56
 
57
57
  it "raises an error with a gjp src directory" do
58
- expect {
58
+ expect do
59
59
  @project.get_package_name(File.join(@project_path, "src"))
60
- }.to raise_error(Gjp::NoPackageDirectoryError)
60
+ end.to raise_error(Gjp::NoPackageDirectoryError)
61
61
  end
62
62
 
63
63
  it "raises an error with a nonexisting package directory" do
64
- expect {
64
+ expect do
65
65
  @project.get_package_name(File.join(@project_path, "src", "test_package"))
66
- }.to raise_error(Gjp::NoPackageDirectoryError)
66
+ end.to raise_error(Gjp::NoPackageDirectoryError)
67
67
  end
68
68
 
69
69
  it "returns the package on an existing package directory" do
@@ -78,7 +78,8 @@ describe Gjp::Project do
78
78
 
79
79
  it "returns the package on an existing package subsubdirectory" do
80
80
  FileUtils.mkdir_p(File.join(@project_path, "src", "test_package", "subdir1", "subdir2"))
81
- @project.get_package_name(File.join(@project_path, "src", "test_package", "subdir1", "subdir2")).should eq "test_package"
81
+ @project.get_package_name(File.join(@project_path, "src", "test_package", "subdir1", "subdir2"))
82
+ .should eq "test_package"
82
83
  end
83
84
  end
84
85
 
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
5
  describe Gjp::ScriptGenerator do
6
6
  before(:each) do
@@ -41,7 +41,9 @@ describe Gjp::ScriptGenerator do
41
41
 
42
42
  lines.should include("#!/bin/bash\n")
43
43
  lines.should include("cd somewhere significant\n")
44
- lines.should include("$PROJECT_PREFIX/kit/mvn/bin/mvn -Dmaven.repo.local=$PROJECT_PREFIX/kit/m2 -s$PROJECT_PREFIX/kit/m2/settings.xml -o --options\n")
44
+ lines.should include("$PROJECT_PREFIX/kit/mvn/bin/mvn -Dmaven.repo.local=$PROJECT_PREFIX/kit/m2 " +
45
+ "-s$PROJECT_PREFIX/kit/m2/settings.xml -o --options\n"
46
+ )
45
47
 
46
48
  lines.should_not include("some earlier command\n")
47
49
  lines.should_not include("gjp dry-run --unwanted-options\n")
@@ -27,7 +27,7 @@ describe Gjp::SourceGetter do
27
27
 
28
28
  successes, failures = source_getter.get_maven_source_jars(@project)
29
29
  commandline = File.read(File.join("..", "..", "test_out")).strip
30
- commandline.should match /-Dartifact=net.test:artifact:1.0:jar:sources -Dtransitive=false$/
30
+ commandline.should match(/-Dartifact=net.test:artifact:1.0:jar:sources -Dtransitive=false$/)
31
31
  successes.should include File.join(".", "kit", "m2", jar_path)
32
32
  failures.should eq []
33
33
  end
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
5
  describe Gjp::SpecGenerator do
6
6
  before(:each) do
@@ -68,7 +68,7 @@ describe Gjp::SpecGenerator do
68
68
  spec_path = File.join("output", "test-project-kit", "test-project-kit.spec")
69
69
  spec_contents = File.read spec_path
70
70
 
71
- spec_contents.gsub! /^Version:.*$/, "CONFLICTING!"
71
+ spec_contents.gsub!(/^Version:.*$/, "CONFLICTING!")
72
72
 
73
73
  File.open(spec_path, "w+") do |io|
74
74
  io.write(spec_contents)
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
5
  describe Gjp::TemplateManager do
6
6
  let(:template_manager) { Gjp::TemplateManager.new }
@@ -8,8 +8,8 @@ describe Gjp::TemplateManager do
8
8
  describe "#template_path" do
9
9
  it "returns the pathname where all templates are stored" do
10
10
  relative_path = template_manager.template_path
11
-
12
- File.expand_path(relative_path).should eq File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "lib", "template"))
11
+ expected_path = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "lib", "template"))
12
+ File.expand_path(relative_path).should eq expected_path
13
13
  end
14
14
  end
15
15
 
@@ -39,12 +39,12 @@ describe Gjp::TemplateManager do
39
39
  "World!"
40
40
  end
41
41
 
42
- def get_binding
43
- binding
42
+ def public_binding
43
+ binding
44
44
  end
45
45
  end
46
46
 
47
- template_manager.generate("test.erb", WorldClass.new.get_binding, destination_path)
47
+ template_manager.generate("test.erb", WorldClass.new.public_binding, destination_path)
48
48
  File.unlink(template_path)
49
49
 
50
50
  File.read(destination_path).should eq "Hello World!\n"
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
5
  describe Gjp::VersionMatcher do
6
6
  let(:version_matcher) { Gjp::VersionMatcher.new }
@@ -6,32 +6,34 @@ require "gjp/logger"
6
6
  Gjp::Logger.log.level = ::Logger::DEBUG
7
7
 
8
8
  # custom mock methods
9
- module Gjp::Mockers
10
- # creates a minimal gjp project
11
- def create_mock_project
12
- @project_path = File.join("spec", "data", "test-project")
13
- Dir.mkdir(@project_path)
9
+ module Gjp
10
+ module Mockers
11
+ # creates a minimal gjp project
12
+ def create_mock_project
13
+ @project_path = File.join("spec", "data", "test-project")
14
+ Dir.mkdir(@project_path)
14
15
 
15
- Gjp::Project.init(@project_path)
16
- @project = Gjp::Project.new(@project_path)
17
- end
16
+ Gjp::Project.init(@project_path)
17
+ @project = Gjp::Project.new(@project_path)
18
+ end
18
19
 
19
- # deletes the mock project and all contents
20
- def delete_mock_project
21
- FileUtils.rm_rf(@project_path)
22
- end
20
+ # deletes the mock project and all contents
21
+ def delete_mock_project
22
+ FileUtils.rm_rf(@project_path)
23
+ end
23
24
 
24
- # creates an executable in kit that will print its parameters
25
- # in a test_out file for checking. Returns mocked executable
26
- # full path
27
- def create_mock_executable(executable_name)
28
- Dir.chdir(@project_path) do
29
- bin_dir = File.join("kit", executable_name, "bin")
30
- FileUtils.mkdir_p(bin_dir)
31
- executable_path = File.join(bin_dir, executable_name)
32
- File.open(executable_path, "w") { |io| io.puts "echo $0 $*>test_out" }
33
- File.chmod(0777, executable_path)
34
- executable_path
25
+ # creates an executable in kit that will print its parameters
26
+ # in a test_out file for checking. Returns mocked executable
27
+ # full path
28
+ def create_mock_executable(executable_name)
29
+ Dir.chdir(@project_path) do
30
+ bin_dir = File.join("kit", executable_name, "bin")
31
+ FileUtils.mkdir_p(bin_dir)
32
+ executable_path = File.join(bin_dir, executable_name)
33
+ File.open(executable_path, "w") { |io| io.puts "echo $0 $*>test_out" }
34
+ File.chmod(0777, executable_path)
35
+ executable_path
36
+ end
35
37
  end
36
38
  end
37
39
  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.36.0
4
+ version: 0.37.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-02 00:00:00.000000000 Z
12
+ date: 2014-05-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -148,6 +148,8 @@ extensions: []
148
148
  extra_rdoc_files: []
149
149
  files:
150
150
  - .gitignore
151
+ - .rubocop.yml
152
+ - .rubocop_todo.yml
151
153
  - Gemfile
152
154
  - LICENSE
153
155
  - MOTIVATION.md
@@ -160,12 +162,29 @@ files:
160
162
  - lib/gjp.rb
161
163
  - lib/gjp/ant_runner.rb
162
164
  - lib/gjp/archiver.rb
163
- - lib/gjp/cli.rb
165
+ - lib/gjp/commands/ant.rb
166
+ - lib/gjp/commands/base.rb
167
+ - lib/gjp/commands/download-maven-source-jars.rb
168
+ - lib/gjp/commands/dry-run.rb
169
+ - lib/gjp/commands/finish.rb
170
+ - lib/gjp/commands/generate-all.rb
171
+ - lib/gjp/commands/generate-kit-archive.rb
172
+ - lib/gjp/commands/generate-kit-spec.rb
173
+ - lib/gjp/commands/generate-package-archive.rb
174
+ - lib/gjp/commands/generate-package-script.rb
175
+ - lib/gjp/commands/generate-package-spec.rb
176
+ - lib/gjp/commands/get-pom.rb
177
+ - lib/gjp/commands/get-source.rb
178
+ - lib/gjp/commands/init.rb
179
+ - lib/gjp/commands/list-kit-missing-sources.rb
180
+ - lib/gjp/commands/move-jars-to-kit.rb
181
+ - lib/gjp/commands/mvn.rb
164
182
  - lib/gjp/git.rb
165
183
  - lib/gjp/kit_checker.rb
166
184
  - lib/gjp/kit_runner.rb
167
185
  - lib/gjp/kit_spec_adapter.rb
168
186
  - lib/gjp/logger.rb
187
+ - lib/gjp/main.rb
169
188
  - lib/gjp/maven_runner.rb
170
189
  - lib/gjp/maven_website.rb
171
190
  - lib/gjp/package_spec_adapter.rb
@@ -1,384 +0,0 @@
1
- # encoding: UTF-8
2
- require "gjp/logger"
3
- require "clamp"
4
- require "open-uri"
5
-
6
- module Gjp
7
- class MainCommand < Clamp::Command
8
- include Logger
9
-
10
- # Common logging options
11
- option ["-v", "--verbose"], :flag, "verbose output"
12
- option ["--very-verbose"], :flag, "very verbose output"
13
- option ["--very-very-verbose"], :flag, "very very verbose output"
14
-
15
- def very_very_verbose=(flag)
16
- configure_log_level(verbose?, very_verbose?, flag)
17
- end
18
-
19
- def very_verbose=(flag)
20
- configure_log_level(verbose?, flag, very_very_verbose?)
21
- end
22
-
23
- def verbose=(flag)
24
- configure_log_level(flag, very_verbose?, very_very_verbose?)
25
- end
26
-
27
- def configure_log_level(v, vv, vvv)
28
- if vvv
29
- log.level = ::Logger::DEBUG
30
- elsif vv
31
- log.level = ::Logger::INFO
32
- elsif v
33
- log.level = ::Logger::WARN
34
- else
35
- log.level = ::Logger::ERROR
36
- end
37
- end
38
-
39
- # Subcommands
40
- subcommand "init", "Inits a gjp project in the current directory" do
41
- def execute
42
- checking_exceptions do
43
- Gjp::Project.init(".")
44
- puts "Project inited."
45
- puts "Add sources to src/<package name>, binary dependencies to kit/."
46
- puts "When you are ready to test a build, use \"gjp dry-run\"."
47
- end
48
- end
49
- end
50
-
51
- subcommand "dry-run", "Starts a dry-run build" do
52
- def execute
53
- checking_exceptions do
54
- if Gjp::Project.new(".").dry_run
55
- puts "Now dry-running, please start your build."
56
- puts "To run a Maven installation from the kit, use \"gjp mvn\"."
57
- puts "If the build succeedes end this dry run with \"gjp finish\"."
58
- puts "If the build does not succeed use \"gjp finish --abort\" to restore files."
59
- end
60
- end
61
- end
62
- end
63
-
64
- subcommand "mvn", "Locates and runs Maven from any directory in kit/" do
65
- parameter "[MAVEN OPTIONS] ...", "mvn options", :attribute_name => "dummy"
66
-
67
- # override parsing in order to pipe everything to mvn
68
- def parse(args)
69
- @options = args
70
- end
71
-
72
- def execute
73
- checking_exceptions do
74
- project = Gjp::Project.new(".")
75
- ensure_dry_running(true, project) do
76
- Gjp::MavenRunner.new(project).mvn(@options)
77
- end
78
- end
79
- end
80
- end
81
-
82
- subcommand "ant", "Locates and runs Ant from any directory in kit/" do
83
- parameter "[ANT OPTIONS] ...", "ant options", :attribute_name => "dummy"
84
-
85
- # override parsing in order to pipe everything to mvn
86
- def parse(args)
87
- @options = args
88
- end
89
-
90
- def execute
91
- checking_exceptions do
92
- project = Gjp::Project.new(".")
93
- ensure_dry_running(true, project) do
94
- Gjp::AntRunner.new(project).ant(@options)
95
- end
96
- end
97
- end
98
- end
99
-
100
- subcommand "finish", "Ends the current dry-run" do
101
- option ["-a", "--abort"], :flag, "build abort, restore files as before dry-run"
102
- def execute
103
- checking_exceptions do
104
- if Gjp::Project.new(".").finish(abort?)
105
- if abort?
106
- puts "Project reverted as before dry-run."
107
- else
108
- puts "Dry-run finished."
109
- end
110
- else
111
- puts "No dry-run is in progress."
112
- end
113
- end
114
- end
115
- end
116
-
117
- subcommand "generate-kit-archive", "Create or refresh the kit tarball" do
118
- option ["-f", "--full"], :flag, "create a full archive (not incremental)"
119
- def execute
120
- checking_exceptions do
121
- project = Gjp::Project.new(".")
122
- ensure_dry_running(false, project) do
123
- result_path = Gjp::Archiver.new(project).archive_kit(full?)
124
- print_generation_result(project, result_path)
125
- end
126
- end
127
- end
128
- end
129
-
130
- subcommand "generate-kit-spec", "Create or refresh a spec file for the kit" do
131
- def execute
132
- checking_exceptions do
133
- project = Gjp::Project.new(".")
134
- ensure_dry_running(false, project) do
135
- result_path, conflict_count = Gjp::SpecGenerator.new(project).generate_kit_spec
136
- print_generation_result(project, result_path, conflict_count)
137
- end
138
- end
139
- end
140
- end
141
-
142
- subcommand "generate-package-script", "Create or refresh a build.sh file for a package" do
143
- parameter "[DIRECTORY]", "path to a package directory (src/<package name>)", :default => "."
144
- def execute
145
- checking_exceptions do
146
- project = Gjp::Project.new(".")
147
- ensure_dry_running(false, project) do
148
- package_name = project.get_package_name(directory)
149
- history_file = File.join(Dir.home, ".bash_history")
150
- result_path, conflict_count = Gjp::ScriptGenerator.new(project, history_file).generate_build_script(package_name)
151
- print_generation_result(project, result_path, conflict_count)
152
- end
153
- end
154
- end
155
- end
156
-
157
- subcommand "generate-package-archive", "Create or refresh a package tarball" do
158
- parameter "[DIRECTORY]", "path to a package directory (src/<package name>)", :default => "."
159
- def execute
160
- checking_exceptions do
161
- project = Gjp::Project.new(".")
162
- ensure_dry_running(false, project) do
163
- package_name = project.get_package_name(directory)
164
- result_path = Gjp::Archiver.new(project).archive_package package_name
165
- print_generation_result(project, result_path)
166
- end
167
- end
168
- end
169
- end
170
-
171
- subcommand "generate-package-spec", "Create or refresh a spec file for a package" do
172
- option ["-f", "--filter"], "FILTER", "filter files to be installed by this spec", :default => "*.jar"
173
- parameter "[DIRECTORY]", "path to a package directory (src/<package name>)", :default => "."
174
- parameter "[POM]", "a pom file path", :default => "pom.xml"
175
- def execute
176
- checking_exceptions do
177
- project = Gjp::Project.new(".")
178
- ensure_dry_running(false, project) do
179
- package_name = project.get_package_name(directory)
180
- result_path, conflict_count = Gjp::SpecGenerator.new(project).generate_package_spec package_name, pom, filter
181
- print_generation_result(project, result_path, conflict_count)
182
- end
183
- end
184
- end
185
- end
186
-
187
- subcommand "generate-all", "Create or refresh specs, archives, scripts for a package and the kit" do
188
- option ["-f", "--filter"], "FILTER", "filter files to be installed by this package spec", :default => "*.jar"
189
- option ["-f", "--full"], :flag, "create a full archive (not incremental)"
190
- parameter "[DIRECTORY]", "path to a package directory (src/<package name>)", :default => "."
191
- parameter "[POM]", "a package pom file path", :default => "pom.xml"
192
- def execute
193
- checking_exceptions do
194
- project = Gjp::Project.new(".")
195
- ensure_dry_running(false, project) do
196
- package_name = project.get_package_name(directory)
197
-
198
- result_path = Gjp::Archiver.new(project).archive_kit(full?)
199
- print_generation_result(project, result_path)
200
-
201
- result_path, conflict_count = Gjp::SpecGenerator.new(project).generate_kit_spec
202
- print_generation_result(project, result_path, conflict_count)
203
-
204
- history_file = File.join(Dir.home, ".bash_history")
205
- result_path, conflict_count = Gjp::ScriptGenerator.new(project, history_file).generate_build_script(package_name)
206
- print_generation_result(project, result_path, conflict_count)
207
-
208
- result_path = Gjp::Archiver.new(project).archive_package package_name
209
- print_generation_result(project, result_path)
210
-
211
- result_path, conflict_count = Gjp::SpecGenerator.new(project).generate_package_spec package_name, pom, filter
212
- print_generation_result(project, result_path, conflict_count)
213
- end
214
- end
215
- end
216
- end
217
-
218
- subcommand "move-jars-to-kit", "Locates jars in src/ and moves them to kit/" do
219
- def execute
220
- checking_exceptions do
221
- project = Gjp::Project.new(".")
222
-
223
- ensure_dry_running(false, project) do
224
- project.purge_jars.each do |original, final|
225
- puts "Replaced #{original} with symlink pointing to to #{final}"
226
- end
227
- end
228
- end
229
- end
230
- end
231
-
232
- subcommand "download-maven-source-jars", "Attempts to download Maven kit/ sources" do
233
- def execute
234
- checking_exceptions do
235
- project = Gjp::Project.new(".")
236
- source_getter = Gjp::SourceGetter.new
237
-
238
- ensure_dry_running(false, project) do
239
- puts "Getting sources from Maven..."
240
- succeeded, failed = source_getter.get_maven_source_jars(project)
241
-
242
- puts "\n**SUMMARY**\n"
243
- puts "Sources found for:"
244
- succeeded.each do |path|
245
- puts " #{format_path(path, project)}"
246
- end
247
-
248
- puts "\nSources not found for:"
249
- failed.each do |path|
250
- puts " #{format_path(path, project)}"
251
- end
252
- end
253
- end
254
- end
255
- end
256
-
257
- subcommand "get-pom", "Retrieves a pom file" do
258
- parameter "NAME", "a jar file name or a `name-version` string (heuristic)"
259
- def execute
260
- checking_exceptions do
261
- project = Gjp::Project.new(".")
262
- pom_getter = Gjp::PomGetter.new
263
-
264
- path, status = pom_getter.get_pom(name)
265
- if path
266
- text_status = if status == :found_in_jar
267
- "was inside the jar"
268
- elsif status == :found_via_sha1
269
- "found by sha1 search from search.maven.org"
270
- elsif status == :found_via_heuristic
271
- "found by heuristic search from search.maven.org"
272
- end
273
-
274
- puts "#{format_path(path, project)} written, #{text_status}"
275
- else
276
- puts "#{name}'s pom not found. Try:"
277
- puts "http://google.com/#q=#{URI::encode(pom_getter.cleanup_name(name) + " pom")}"
278
- end
279
- end
280
- end
281
- end
282
-
283
- subcommand "get-source", "Attempts to retrieve a project's sources" do
284
- parameter "POM", "a pom file path or URI"
285
-
286
- def execute
287
- checking_exceptions do
288
- project = Gjp::Project.new(".")
289
- source_getter = Gjp::SourceGetter.new
290
-
291
- puts "Attempting to find source through Maven..."
292
- if source_getter.get_maven_source_jar(project, pom)
293
- puts "Source jar found and added to Maven repository."
294
- else
295
- effective_pom_path = Gjp::MavenRunner.new(project).get_effective_pom(pom)
296
- puts "Source jar not found in Maven. Try looking here:"
297
- pom = Gjp::Pom.new(effective_pom_path)
298
- if pom.url && !pom.url.empty?
299
- puts "Website: #{pom.url}"
300
- end
301
- if pom.scm_connection && !pom.scm_connection.empty?
302
- puts "SCM connection: #{pom.scm_connection}"
303
- end
304
- if pom.scm_url && !pom.scm_url.empty?
305
- puts "SCM connection: #{pom.scm_url}"
306
- end
307
- puts "The effective POM: #{effective_pom_path}"
308
- puts "Google: http://google.com/#q=#{URI::encode(pom.name + ' sources')}"
309
- end
310
- end
311
- end
312
- end
313
-
314
- subcommand "list-kit-missing-sources", "Locates jars in kit/ that have no source files" do
315
- def execute
316
- checking_exceptions do
317
- project = Gjp::Project.new(".")
318
- kit_checker = Gjp::KitChecker.new(project)
319
-
320
- ensure_dry_running(false, project) do
321
- puts "Some source files were not found in these archives:"
322
- kit_checker.get_unsourced.each do |archive|
323
- percentage = "%.2f" % (100.0 * archive[:unsourced_class_names].length()/archive[:class_names].length())
324
- puts "#{format_path(archive[:archive], project)} (~#{percentage}% missing)"
325
- end
326
- end
327
- end
328
- end
329
- end
330
-
331
- private
332
-
333
- def ensure_dry_running(state, project)
334
- if project.is_dry_running == state
335
- yield
336
- else
337
- if state == true
338
- puts "Please start a dry-run first, use \"gjp dry-run\""
339
- else
340
- puts "Please finish or abort this dry-run first, use \"gjp finish\" or \"gjp finish --abort\""
341
- end
342
- end
343
- end
344
-
345
- # outputs output of a file generation
346
- def print_generation_result(project, result_path, conflict_count = 0)
347
- puts "#{format_path(result_path, project)} generated"
348
- if conflict_count > 0
349
- puts "Warning: #{conflict_count} unresolved conflicts"
350
- end
351
- end
352
-
353
- # generates a version of path relative to the current directory
354
- def format_path(path, project)
355
- full_path = if Pathname.new(path).relative?
356
- File.join(project.full_path, path)
357
- else
358
- path
359
- end
360
- Pathname.new(full_path).relative_path_from(Pathname.new(Dir.pwd))
361
- end
362
-
363
- # handles most fatal exceptions
364
- def checking_exceptions
365
- begin
366
- yield
367
- rescue Errno::EACCES => e
368
- $stderr.puts e
369
- rescue Errno::ENOENT => e
370
- $stderr.puts e
371
- rescue Errno::EEXIST => e
372
- $stderr.puts e
373
- rescue NoProjectDirectoryError => e
374
- $stderr.puts "#{e.directory} is not a gjp project directory, see gjp init"
375
- rescue NoPackageDirectoryError => e
376
- $stderr.puts "#{e.directory} is not a gjp package directory, see README"
377
- rescue GitAlreadyInitedError => e
378
- $stderr.puts "This directory is already a gjp project"
379
- rescue ExecutableNotFoundError => e
380
- $stderr.puts "Executable #{e.executable} not found in kit/ or any of its subdirectories"
381
- end
382
- end
383
- end
384
- end