gjp 0.10.0 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gjp (0.5.0)
4
+ gjp (0.10.2)
5
5
  clamp
6
6
  json
7
7
  nokogiri
@@ -16,7 +16,9 @@ GEM
16
16
  diff-lcs (1.2.4)
17
17
  json (1.8.0)
18
18
  mime-types (1.23)
19
- nokogiri (1.5.9)
19
+ mini_portile (0.5.1)
20
+ nokogiri (1.6.0)
21
+ mini_portile (~> 0.5.0)
20
22
  rake (10.0.4)
21
23
  rest-client (1.6.7)
22
24
  mime-types (>= 1.16)
data/README.md CHANGED
@@ -15,10 +15,17 @@ Easiest install is via RubyGems:
15
15
  ## Usage
16
16
 
17
17
  Currently available tools:
18
+ * `gjp init` inits a new gjp project in the current directory, generating minimal directories and files;
19
+ * `gjp gather` starts a new gathering phase, to add files to the packages you want to create. You should place source files in src/<orgId_artifactId_version>, and binary dependency files in kit/;
18
20
  * `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;
19
21
  * `gjp get-parent-pom POM` will attempt to download a pom's parent from search.maven.org, where `POM` is a filename or URI;
20
22
  * `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;
21
23
  * `gjp get-source POM ADDRESS` downloads the source of a pom.xml's project from its SCM at ADDRESS;
24
+ * `gjp finish` marks the end of a phase;
25
+ * `gjp dry-run` starts a new dry-run phase, where you attempt to build your package. Any change to src/ will be reverted after you call `gjp finish`;
26
+ * `gjp mvn` locates and runs Maven from any directory in kit/, using options to force repository in kit/m2 and settings in kit/m2/settings.xml;
27
+ * `gjp set-up-nonet-user` sets up a user named `nonet` without Internet access using `iptables`, needs superuser privileges. You can then use it for networkless dry-runs;
28
+ * `gjp tear-down-nonet-user` removes a user previously created by gjp;
22
29
  * `gjp scaffold-jar-table DIRECTORY` looks for jars in the project's DIRECTORY and classifies them as build-time dependencies (b), run-time dependencies (r) or products (p);
23
30
 
24
31
  ## Source
data/lib/gjp.rb CHANGED
@@ -1,12 +1,15 @@
1
- require "gjp/logger"
2
1
  require "gjp/version"
3
2
  require "gjp/logger"
4
- require "gjp/cli"
3
+ require "gjp/project"
5
4
  require "gjp/pom"
6
5
  require "gjp/version_matcher"
7
6
  require "gjp/maven_website"
8
- require "gjp/get_pom"
9
- require "gjp/get_parent_pom"
10
- require "gjp/get_source_address"
11
- require "gjp/get_source"
12
7
  require "gjp/jar_table"
8
+ require "gjp/limited_network_user"
9
+ require "gjp/pom_getter"
10
+ require "gjp/source_address_getter"
11
+ require "gjp/source_getter"
12
+ require "gjp/parent_pom_getter"
13
+ require "gjp/maven_runner"
14
+
15
+ require "gjp/cli"
@@ -43,6 +43,96 @@ module Gjp
43
43
  end
44
44
 
45
45
  # Subcommands
46
+ subcommand "init", "Inits a gjp project in the current directory" do
47
+ def execute
48
+ Gjp::Project.init(".")
49
+ puts "Project inited."
50
+ puts "Use \"gjp gather\" before adding files to have gjp track them."
51
+ end
52
+ end
53
+
54
+ subcommand "gather", "Starts a gathering phase, add source and kit files to project" do
55
+ def execute
56
+ result = Gjp::Project.new(".").gather
57
+ if result == :done
58
+ puts "Now gathering."
59
+ puts "Any file added to kit/ will be added to the kit package."
60
+ puts "Any file added to src/<orgId_artifactId_version> will be added to the corresponding package."
61
+ puts "Note that .gitignore files are honored!"
62
+ puts "To finalize this gathering, use \"gjp finish\"."
63
+ else
64
+ puts "Cannot begin gathering while #{result}, use \"gjp finish\" first."
65
+ end
66
+ end
67
+ end
68
+
69
+ subcommand "dry-run", "Starts a dry-run phase, attempt build to add dependencies to kit." do
70
+ def execute
71
+ result = Gjp::Project.new(".").dry_run
72
+ if result == :done
73
+ puts "Now dry-running, please start your build."
74
+ puts "Any file added to kit/, presumably downloaded dependencies, will be added to the kit package."
75
+ puts "The src/ directory and all files in it will be brought back to the current state when finished."
76
+ puts "Note that .gitignore files are honored!"
77
+ puts "To run a Maven from the kit, use \"gjp mvn\"."
78
+ puts "To finalize this dry run, use \"gjp finish\"."
79
+ else
80
+ puts "Cannot begin a dry run while #{result}, use \"gjp finish\" first."
81
+ end
82
+ end
83
+ end
84
+
85
+ subcommand "mvn", "Runs Maven from the kit" do
86
+ parameter "[MAVEN OPTIONS] ...", "mvn options", :attribute_name => "dummy"
87
+
88
+ # override parsing in order to pipe everything to mvn
89
+ def parse(args)
90
+ @maven_options = args
91
+ end
92
+
93
+ def execute
94
+ project = Gjp::Project.new(".")
95
+ Gjp::MavenRunner.new(project).mvn(@maven_options)
96
+ end
97
+ end
98
+
99
+
100
+ subcommand "finish", "Finishes the current phase" do
101
+ def execute
102
+ result = Gjp::Project.new(".").finish
103
+ if result == :gathering
104
+ puts "Gathering finished."
105
+ puts "New files have been added to gjp_file_list files in respective directories."
106
+ puts "Feel free to edit them if needed."
107
+ puts "You can start a dry run build with \"gjp dry-run\" or add more files with \"gjp gather\"."
108
+ end
109
+ end
110
+ end
111
+
112
+ subcommand "set-up-nonet-user", "Sets up a \"nonet\" user that cannot access the network" do
113
+ def execute
114
+ user = Gjp::LimitedNetworkUser.new("nonet")
115
+ user.set_up
116
+
117
+ "sudo #{user.get_path("useradd")} nonet\n" +
118
+ "sudo #{user.get_path("iptables")} -A OUTPUT -m owner --uid-owner nonet -j DROP\n" +
119
+ "User \"nonet\" set up, you can use \"sudo nonet\" to dry-run your build with no network access.\n" +
120
+ "Note that the above iptables rule will be cleared at next reboot, you can use your distribution " +
121
+ "tools to make it persistent or run \"gjp set-up-limited-nertwork-user\" again next time."
122
+ end
123
+ end
124
+
125
+ subcommand "tear-down-nonet-user", "Deletes a user previously created by gjp" do
126
+ def execute
127
+ user = Gjp::LimitedNetworkUser.new("nonet")
128
+
129
+ user.tear_down
130
+
131
+ "sudo #{user.get_path("iptables")} -D OUTPUT -m owner --uid-owner nonet -j DROP\n" +
132
+ "sudo #{user.get_path("userdel")} nonet\n"
133
+ end
134
+ end
135
+
46
136
  subcommand "get-pom", "Retrieves a pom corresponding to a filename" do
47
137
  parameter "NAME", "a jar file path, a project directory path or a non-existing filename in the `project-version` form"
48
138
  def execute
@@ -32,14 +32,28 @@ module Gjp
32
32
  end
33
33
 
34
34
  def to_s
35
- "# Legend: "
36
- "#b - jar is required for building the project"
37
- "#r - jar is required runtime by the project"
38
- "#p - jar is produced by the project"
39
- "#i - jar is ignored"
40
- @rows.map do |key, value|
41
- "#{value.to_s[0]} #{key}"
42
- end.sort
35
+ "# Key: \n" +
36
+ "# b - jar is required for building the project\n" +
37
+ "# r - jar is required runtime by the project\n" +
38
+ "# p - jar is produced by the project\n" +
39
+ "# i - jar is ignored\n" +
40
+
41
+ (
42
+ rows = @rows.map do |key, value|
43
+ pathname = Pathname.new(key)
44
+ [value.to_s[0], pathname.basename.to_s, pathname.dirname.to_s]
45
+ end
46
+
47
+ max_field_lengths = (0..2).map do |i|
48
+ rows.map { |row| row[i].length }.max
49
+ end
50
+
51
+ rows.map do |row|
52
+ row.each_with_index.map do |element, i|
53
+ "%-#{max_field_lengths[i]+1}s" % element
54
+ end.join
55
+ end.sort.join("\n")
56
+ )
43
57
  end
44
58
 
45
59
  # jar files in the project's directory
@@ -0,0 +1,66 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'find'
4
+
5
+ module Gjp
6
+ # encapsulates a Linux user that cannot access the Internet
7
+ # assumes root access (sudo) and iptables are available
8
+ class LimitedNetworkUser
9
+ def log
10
+ Gjp.logger
11
+ end
12
+
13
+ def initialize(name)
14
+ @name = name
15
+ end
16
+
17
+ # creates a new Linux user without Internet access,
18
+ # if it does not exists
19
+ def set_up
20
+ log.debug "checking #{@name} user existence..."
21
+ if not user_exists?
22
+ log.debug "...not found. Setting up..."
23
+ `sudo #{get_path("useradd")} #{@name}`
24
+ `sudo #{get_path("passwd")} #{@name}`
25
+ log.debug "...set up"
26
+ end
27
+
28
+ if not firewall_rule_exists?
29
+ log.debug "...not found. Setting up..."
30
+ `sudo #{get_path("iptables")} -A OUTPUT -m owner --uid-owner #{@name} -j DROP`
31
+ log.debug "...set up"
32
+ end
33
+ end
34
+
35
+ # deletes a Linux user previously created by this class
36
+ def tear_down
37
+ if firewall_rule_exists?
38
+ `sudo #{get_path("iptables")} -D OUTPUT -m owner --uid-owner #{@name} -j DROP`
39
+ end
40
+
41
+ if user_exists?
42
+ `sudo #{get_path("userdel")} #{@name}`
43
+ end
44
+ end
45
+
46
+ # determines if a user without Internet access exists
47
+ def set_up?
48
+ user_exists? and firewall_rule_exists?
49
+ end
50
+
51
+ # checks user existence
52
+ def user_exists?
53
+ `id #{@name} 2>&1`.match(/no such user$/) == nil
54
+ end
55
+
56
+ # checks firewall rule existence
57
+ def firewall_rule_exists?
58
+ `sudo #{get_path("iptables")} -L`.match(/owner UID match #{@name}/) != nil
59
+ end
60
+
61
+ # returns a command's full path
62
+ def get_path(command)
63
+ `sudo which #{command}`.strip
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,55 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'find'
4
+ require 'pathname'
5
+
6
+ module Gjp
7
+ # runs Maven from a gjp kit with gjp-specific options
8
+ class MavenRunner
9
+ def log
10
+ Gjp.logger
11
+ end
12
+
13
+ def initialize(project)
14
+ @project = project
15
+ end
16
+
17
+ # finds mvn in kit
18
+ def find_maven_executable
19
+ @project.from_directory do
20
+ Find.find("kit") do |path|
21
+ if path =~ /bin\/mvn$/
22
+ log.debug("found Maven executable: #{path}")
23
+ return path
24
+ end
25
+ end
26
+ end
27
+
28
+ nil
29
+ end
30
+
31
+ # returns a command line for running Maven
32
+ def get_maven_commandline(kit_full_path, running_full_path)
33
+ prefix = path_from running_full_path, kit_full_path
34
+ maven_executable = find_maven_executable
35
+
36
+ mvn_path = File.join(prefix, maven_executable)
37
+ repo_path = File.join(prefix, "kit", "m2")
38
+ config_path = File.join(prefix, "kit", "m2", "settings.xml")
39
+
40
+ "#{mvn_path} -Dmaven.repo.local=`readlink -e #{repo_path}` -s`readlink -e #{config_path}`"
41
+ end
42
+
43
+ # returns a path from origin to destination, provided they are both absolute
44
+ def path_from(origin, destination)
45
+ (Pathname.new(destination).relative_path_from Pathname.new(origin)).split.first
46
+ end
47
+
48
+ # runs mvn in a subprocess
49
+ def mvn(options)
50
+ kit_full_path = File.join(@project.full_path, "kit")
51
+ running_full_path = File.expand_path(".")
52
+ Process.wait(Process.spawn("#{get_maven_commandline(kit_full_path, running_full_path)} #{options.join(' ')}"))
53
+ end
54
+ end
55
+ end
@@ -3,7 +3,7 @@
3
3
  require "pathname"
4
4
 
5
5
  module Gjp
6
- # implements the get-parent-pom subcommand
6
+ # attempts to get a pom's parent pom
7
7
  class ParentPomGetter
8
8
 
9
9
  def self.log
@@ -9,7 +9,7 @@ require "pathname"
9
9
  require "gjp/version_matcher"
10
10
 
11
11
  module Gjp
12
- # implements the get-pom subcommand
12
+ # attempts to get java projects' pom file
13
13
  class PomGetter
14
14
 
15
15
  def self.log
@@ -0,0 +1,216 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'find'
4
+
5
+ module Gjp
6
+ # encapsulates a Gjp project directory
7
+ class Project
8
+ def log
9
+ Gjp.logger
10
+ end
11
+
12
+ attr_accessor :full_path
13
+
14
+ def initialize(path)
15
+ @full_path = Gjp::Project.find_project_dir(File.expand_path(path))
16
+ end
17
+
18
+ # finds the project directory up in the tree, like git does
19
+ def self.find_project_dir(starting_dir)
20
+ result = starting_dir
21
+ while is_project(result) == false and result != "/"
22
+ result = File.expand_path("..", result)
23
+ end
24
+
25
+ raise ArgumentError, "This is not a gjp project directory" if result == "/"
26
+
27
+ result
28
+ end
29
+
30
+ # returns true if the specified directory is a valid gjp project
31
+ def self.is_project(dir)
32
+ File.directory?(File.join(dir, "src")) and
33
+ File.directory?(File.join(dir, "kit")) and
34
+ File.directory?(File.join(dir, ".git"))
35
+ end
36
+
37
+ # inits a new project directory structure
38
+ def self.init(dir)
39
+ Dir.chdir(dir) do
40
+ `git init`
41
+
42
+ Dir.mkdir("src")
43
+ File.open(File.join("src", "README"), "w") do |file|
44
+ file.puts "Sources are to be placed in subdirectories named after Maven names: orgId_artifactId_version"
45
+ end
46
+ Dir.mkdir("kit")
47
+ File.open(File.join("kit", "README"), "w") do |file|
48
+ file.puts "Build tool binaries are to be placed here"
49
+ end
50
+
51
+ `git add .`
52
+ `git commit -m "Project initialized"`
53
+ `git tag init`
54
+ end
55
+ end
56
+
57
+ # starts a gathering phase, all files added to the project
58
+ # will be added to packages (including kit)
59
+ def gather
60
+ from_directory do
61
+ if get_status(:gathering)
62
+ return :gathering
63
+ elsif get_status(:dry_running)
64
+ return :dry_running
65
+ end
66
+
67
+ set_status(:gathering)
68
+ commit_all("Gathering started")
69
+ end
70
+
71
+ :done
72
+ end
73
+
74
+ # starts a dry running phase: files added to the kit will
75
+ # be added to packages, while sources will be reset at the
76
+ # end
77
+ def dry_run
78
+ from_directory do
79
+ if get_status(:gathering)
80
+ return :gathering
81
+ elsif get_status(:dry_running)
82
+ return :dry_running
83
+ end
84
+
85
+ set_status(:dry_running)
86
+ commit_all("Dry-run started")
87
+ end
88
+
89
+ :done
90
+ end
91
+
92
+ # ends any phase that was previously started,
93
+ # generating file lists
94
+ def finish
95
+ from_directory do
96
+ if get_status(:gathering)
97
+ commit_all("Changes during gathering")
98
+
99
+ update_changed_file_list("kit", "gjp_kit_file_list")
100
+ update_changed_src_file_list(:file_list)
101
+ commit_all("File list updates")
102
+
103
+ clear_status(:gathering)
104
+ commit_all("Gathering finished")
105
+
106
+ :gathering
107
+ elsif get_status(:dry_running)
108
+ commit_all("Changes during dry-run")
109
+
110
+ update_changed_file_list("kit", "gjp_kit_file_list")
111
+ update_changed_src_file_list(:produced_file_list)
112
+ commit_all("File list updates")
113
+
114
+ revert("src", 2)
115
+ commit_all("Sources reverted as before dry-run")
116
+
117
+ clear_status(:dry_running)
118
+ commit_all("Dry run finished")
119
+
120
+ :dry_running
121
+ end
122
+ end
123
+ end
124
+
125
+ def update_changed_src_file_list(list_name)
126
+ Dir.foreach("src") do |entry|
127
+ if File.directory?(File.join(Dir.getwd, "src", entry)) and entry =~ /([^_\/]+_[^_]+_[^_]+)$/
128
+ update_changed_file_list(File.join("src", entry), "gjp_#{$1}_#{list_name.to_s}")
129
+ end
130
+ end
131
+ end
132
+
133
+ def update_changed_file_list(directory, list_file)
134
+ existing_files = if File.exists?(list_file)
135
+ File.readlines(list_file)
136
+ else
137
+ []
138
+ end
139
+
140
+ files = (
141
+ `git diff-tree --no-commit-id --name-only -r HEAD`.split("\n")
142
+ .select { |file| file.start_with?(directory) }
143
+ .map { |file|file[directory.length + 1, file.length] }
144
+ .concat(existing_files)
145
+ .sort
146
+ .uniq
147
+ )
148
+
149
+ log.debug("writing file list for #{directory}: #{files.to_s}")
150
+
151
+
152
+ File.open(list_file, "w+") do |file_list|
153
+ files.each do |file|
154
+ file_list.puts file
155
+ end
156
+ end
157
+ end
158
+
159
+ # adds the project's whole contents to git
160
+ def commit_all(message)
161
+ Find.find(".") do |path|
162
+ if path =~ /.gitignore$/
163
+ puts "Deleting #{path} to preserve all files..."
164
+ File.delete(path)
165
+ end
166
+ end
167
+
168
+ log.debug "committing with message: #{message}"
169
+
170
+ `git rm -r --cached .`
171
+ `git add .`
172
+ `git commit -m "#{message}"`
173
+ end
174
+
175
+ # reverts dir contents as commit_count commits ago
176
+ def revert(dir, commit_count)
177
+ `git rm -rf --ignore-unmatch #{dir}`
178
+ `git checkout -f HEAD~#{commit_count} -- #{dir}`
179
+
180
+ `git clean -f -d #{dir}`
181
+ end
182
+
183
+ # gets a project status flag
184
+ def get_status(status)
185
+ file_name = status_file_name(status)
186
+ File.exists?(file_name)
187
+ end
188
+
189
+ # sets a project status flag
190
+ def set_status(status)
191
+ file_name = status_file_name(status)
192
+ if File.exists?(file_name) == false
193
+ FileUtils.touch(file_name)
194
+ end
195
+ end
196
+
197
+ # sets a project status flag
198
+ def clear_status(status)
199
+ file_name = status_file_name(status)
200
+ if File.exists?(file_name)
201
+ File.delete(file_name)
202
+ end
203
+ end
204
+
205
+ def status_file_name(status)
206
+ ".#{status.to_s}"
207
+ end
208
+
209
+ # runs a block from the project directory
210
+ def from_directory
211
+ Dir.chdir(@full_path) do
212
+ yield
213
+ end
214
+ end
215
+ end
216
+ end
@@ -5,7 +5,7 @@ require "json"
5
5
  require "open-uri"
6
6
 
7
7
  module Gjp
8
- # implements the get-source-address subcommand
8
+ # attempts to get java projects' scm addresses
9
9
  class SourceAddressGetter
10
10
  def self.log
11
11
  Gjp.logger
@@ -3,7 +3,7 @@
3
3
  require "rest_client"
4
4
 
5
5
  module Gjp
6
- # implements the get-source subcommand
6
+ # attempts to get java projects' sources from scm
7
7
  class SourceGetter
8
8
  def self.log
9
9
  Gjp.logger
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module Gjp
4
- VERSION = "0.10.0"
4
+ VERSION = "0.11.1"
5
5
  end
@@ -0,0 +1,40 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Gjp::LimitedNetworkUser do
6
+
7
+ let(:user) { Gjp::LimitedNetworkUser.new("nonet_test") }
8
+
9
+ before(:each) do
10
+ user.set_up
11
+ end
12
+
13
+ after(:each) do
14
+ if user.set_up?
15
+ user.tear_down
16
+ end
17
+ end
18
+
19
+ describe ".set_up" do
20
+ it "set_ups a limited network user" do
21
+ user.set_up?.should be_true
22
+ end
23
+ end
24
+
25
+ describe ".tear_down" do
26
+ it "tears down a limited network user" do
27
+ user.tear_down
28
+ user.set_up?.should be_false
29
+ end
30
+ end
31
+
32
+ describe ".set_up?" do
33
+ it "checks if a limited network user has been set up" do
34
+ user.set_up?.should be_true
35
+
36
+ user.tear_down
37
+ user.set_up?.should be_false
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,56 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Gjp::MavenRunner do
6
+
7
+ before(:each) do
8
+ @project_path = File.join("spec", "data", "test-project")
9
+ Dir.mkdir(@project_path)
10
+
11
+ Gjp::Project.init(@project_path)
12
+ @project = Gjp::Project.new(@project_path)
13
+ @project.gather
14
+
15
+ # mock a Maven executable
16
+ Dir.chdir(@project_path) do
17
+ @bin_dir = File.join("kit", "mvn", "bin")
18
+ FileUtils.mkdir_p(@bin_dir)
19
+ @maven_executable = File.join(@bin_dir, "mvn")
20
+ File.open(@maven_executable, "w") { |io| io.puts "echo $0 $*>test_out" }
21
+ File.chmod(0777, @maven_executable)
22
+ end
23
+
24
+ @project.finish
25
+
26
+ @maven_runner = Gjp::MavenRunner.new(@project)
27
+ end
28
+
29
+ after(:each) do
30
+ FileUtils.rm_rf(@project_path)
31
+ end
32
+
33
+ describe "#find_maven_executable" do
34
+ it "looks for Maven in kit" do
35
+ @maven_runner.find_maven_executable.should eq @maven_executable
36
+ end
37
+ end
38
+
39
+ describe "#get_maven_commandline" do
40
+ it "returns commandline options for running maven" do
41
+ kit_full_path = File.join(@project.full_path, "kit")
42
+ commandline = @maven_runner.get_maven_commandline(kit_full_path, @project.full_path)
43
+
44
+ commandline.should eq "./#{@maven_executable} -Dmaven.repo.local=`readlink -e ./kit/m2` -s`readlink -e ./kit/m2/settings.xml`"
45
+ end
46
+ end
47
+
48
+ describe "#mvn" do
49
+ it "runs maven" do
50
+ @project.from_directory do
51
+ @maven_runner.mvn(["extra-option"])
52
+ File.read("test_out").strip.should match /extra-option$/
53
+ end
54
+ end
55
+ end
56
+ end
@@ -27,9 +27,9 @@ describe Gjp::MavenWebsite do
27
27
 
28
28
  describe "#search_by_group_id_and_artifact_id" do
29
29
  it "uses search.maven.org to look for poms by group and artifact id" do
30
- result = site.search_by_group_id_and_artifact_id("antlr", "antlrall")
30
+ results = site.search_by_group_id_and_artifact_id("antlr", "antlrall")
31
31
 
32
- result.should include({"id"=>"antlr:antlrall:2.7.2", "g"=>"antlr", "a"=>"antlrall", "v"=>"2.7.2", "p"=>"jar", "timestamp"=>1182142732000, "ec"=>[".jar", ".pom"]}, {"id"=>"antlr:antlrall:2.7.4", "g"=>"antlr", "a"=>"antlrall", "v"=>"2.7.4", "p"=>"jar", "timestamp"=>1131488123000, "ec"=>[".jar", ".pom"]}, {"id"=>"antlr:antlrall:2.7.1", "g"=>"antlr", "a"=>"antlrall", "v"=>"2.7.1", "p"=>"jar", "timestamp"=>1131488123000, "ec"=>[".jar", ".pom"]})
32
+ results.any? { |result| result["id"] == "antlr:antlrall:2.7.2" }.should be_true
33
33
  end
34
34
  end
35
35
 
@@ -0,0 +1,190 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Gjp::Project do
6
+ before(:each) do
7
+ @project_path = File.join("spec", "data", "test-project")
8
+ Dir.mkdir(@project_path)
9
+
10
+ Gjp::Project.init(@project_path)
11
+ @project = Gjp::Project.new(@project_path)
12
+ end
13
+
14
+ after(:each) do
15
+ FileUtils.rm_rf(@project_path)
16
+ end
17
+
18
+ describe "#is_project" do
19
+ it "checks if a directory is a gjp project or not" do
20
+ Gjp::Project.is_project(@project_path).should be_true
21
+ Gjp::Project.is_project(File.join(@project_path, "..")).should be_false
22
+ end
23
+ end
24
+
25
+ describe "#find_project_dir" do
26
+ it "recursively the parent project directory" do
27
+ expanded_path = File.expand_path(@project_path)
28
+ Gjp::Project.find_project_dir(expanded_path).should eq expanded_path
29
+ Gjp::Project.find_project_dir(File.expand_path("src", @project_path)).should eq expanded_path
30
+ Gjp::Project.find_project_dir(File.expand_path("kit", @project_path)).should eq expanded_path
31
+
32
+ expect {
33
+ Gjp::Project.find_project_dir(File.expand_path("..", @project_path)).should raise_error
34
+ }.to raise_error(ArgumentError)
35
+ end
36
+ end
37
+
38
+ describe "full_path" do
39
+ it "returns the project's full path" do
40
+ @project.full_path.should eq File.expand_path(@project_path)
41
+ end
42
+ end
43
+
44
+ describe "#init" do
45
+ it "inits a new project" do
46
+ kit_path = File.join(@project_path, "kit")
47
+ Dir.exists?(kit_path).should be_true
48
+
49
+ src_path = File.join(@project_path, "src")
50
+ Dir.exists?(src_path).should be_true
51
+
52
+ @project.from_directory do
53
+ `git tag`.strip.should eq("init")
54
+ `git rev-list --all`.split("\n").length.should eq 1
55
+ end
56
+ end
57
+ end
58
+
59
+ describe ".set_status" do
60
+ it "stores a project's status flag" do
61
+ @project.from_directory do
62
+ @project.set_status(:gathering)
63
+ File.exists?(".gathering").should be_true
64
+ end
65
+ end
66
+ end
67
+
68
+ describe ".get_status" do
69
+ it "gets a project's status flag" do
70
+ @project.from_directory do
71
+ @project.get_status(:gathering).should be_false
72
+ `touch .gathering`
73
+ @project.get_status(:gathering).should be_true
74
+ end
75
+ end
76
+ end
77
+
78
+ describe ".clear_status" do
79
+ it "clears a project's status flag" do
80
+ @project.from_directory do
81
+ `touch .gathering`
82
+ @project.get_status(:gathering).should be_true
83
+
84
+ @project.clear_status(:gathering)
85
+ @project.get_status(:gathering).should be_false
86
+ end
87
+ end
88
+ end
89
+
90
+ describe ".commit_all" do
91
+ it "commits the project contents to git for later use" do
92
+ @project.from_directory do
93
+ `touch kit/test`
94
+
95
+ @project.commit_all "test"
96
+
97
+ `git rev-list --all`.split("\n").length.should eq 2
98
+ end
99
+ end
100
+ end
101
+
102
+ describe ".gather" do
103
+ it "starts a gathering phase" do
104
+
105
+ @project.from_directory do
106
+ `touch src/test`
107
+ end
108
+
109
+ @project.gather.should eq :done
110
+
111
+ @project.from_directory do
112
+ @project.get_status(:gathering).should be_true
113
+ `git rev-list --all`.split("\n").length.should eq 2
114
+ `git diff-tree --no-commit-id --name-only -r HEAD`.split("\n").should include("src/test")
115
+ end
116
+ end
117
+ end
118
+
119
+ describe ".finish" do
120
+ it "ends the current gathering phase" do
121
+ @project.gather.should eq :done
122
+
123
+ @project.from_directory do
124
+ Dir.mkdir("src/a_b_c")
125
+ `touch src/a_b_c/test`
126
+ `touch kit/test`
127
+ end
128
+
129
+ @project.finish.should eq :gathering
130
+ @project.get_status(:gathering).should be_false
131
+
132
+ @project.from_directory do
133
+ `git rev-list --all`.split("\n").length.should eq 5
134
+ `git diff-tree --no-commit-id --name-only -r HEAD~2`.split("\n").should include("src/a_b_c/test")
135
+ File.readlines("gjp_a_b_c_file_list").should include("test\n")
136
+ File.readlines("gjp_kit_file_list").should include("test\n")
137
+ end
138
+ end
139
+
140
+ it "ends the current dry-run phase" do
141
+ @project.gather.should eq :done
142
+
143
+ @project.from_directory do
144
+ Dir.mkdir("src/a_b_c")
145
+ `echo A > src/a_b_c/test`
146
+ end
147
+
148
+ @project.finish.should eq :gathering
149
+
150
+ @project.dry_run.should eq :done
151
+
152
+ @project.from_directory do
153
+ `echo B > src/a_b_c/test`
154
+ `touch src/a_b_c/test2`
155
+ `touch kit/test`
156
+ end
157
+
158
+ @project.finish.should eq :dry_running
159
+ @project.get_status(:dry_running).should be_false
160
+
161
+ @project.from_directory do
162
+ `git rev-list --all`.split("\n").length.should eq 10
163
+ File.read("src/a_b_c/test").should eq "A\n"
164
+ File.readlines("gjp_a_b_c_produced_file_list").should include("test2\n")
165
+ File.readlines("gjp_a_b_c_file_list").should_not include("test2\n")
166
+
167
+ `git diff-tree --no-commit-id --name-only -r HEAD~2`.split("\n").should_not include("src/a_b_c/test2")
168
+ File.exists?("src/a_b_c/test2").should be_false
169
+ File.readlines("gjp_kit_file_list").should include("test\n")
170
+ end
171
+ end
172
+ end
173
+
174
+ describe ".dry_run" do
175
+ it "starts a dry running phase" do
176
+
177
+ @project.from_directory do
178
+ `touch src/test`
179
+ end
180
+
181
+ @project.dry_run.should eq :done
182
+
183
+ @project.from_directory do
184
+ @project.get_status(:dry_running).should be_true
185
+ `git rev-list --all`.split("\n").length.should eq 2
186
+ `git diff-tree --no-commit-id --name-only -r HEAD`.split("\n").should include("src/test")
187
+ end
188
+ end
189
+ end
190
+ 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.10.0
4
+ version: 0.11.1
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: 2013-06-19 00:00:00.000000000 Z
12
+ date: 2013-08-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -157,14 +157,17 @@ files:
157
157
  - gjp.gemspec
158
158
  - lib/gjp.rb
159
159
  - lib/gjp/cli.rb
160
- - lib/gjp/get_parent_pom.rb
161
- - lib/gjp/get_pom.rb
162
- - lib/gjp/get_source.rb
163
- - lib/gjp/get_source_address.rb
164
160
  - lib/gjp/jar_table.rb
161
+ - lib/gjp/limited_network_user.rb
165
162
  - lib/gjp/logger.rb
163
+ - lib/gjp/maven_runner.rb
166
164
  - lib/gjp/maven_website.rb
165
+ - lib/gjp/parent_pom_getter.rb
167
166
  - lib/gjp/pom.rb
167
+ - lib/gjp/pom_getter.rb
168
+ - lib/gjp/project.rb
169
+ - lib/gjp/source_address_getter.rb
170
+ - lib/gjp/source_getter.rb
168
171
  - lib/gjp/version.rb
169
172
  - lib/gjp/version_matcher.rb
170
173
  - spec/data/ant-super-simple-code/build.xml
@@ -183,13 +186,16 @@ files:
183
186
  - spec/data/nailgun/pom.xml
184
187
  - spec/data/struts-apps/pom.xml
185
188
  - spec/data/tomcat/pom.xml
186
- - spec/lib/get_parent_pom_spec.rb
187
- - spec/lib/get_pom_spec.rb
188
- - spec/lib/get_source_address_spec.rb
189
- - spec/lib/get_source_spec.rb
190
189
  - spec/lib/jar_table_spec.rb
190
+ - spec/lib/limited_network_user_spec_interactive.rb
191
+ - spec/lib/maven_runner_spec.rb
191
192
  - spec/lib/maven_website_spec.rb
193
+ - spec/lib/parent_pom_getter_spec.rb
194
+ - spec/lib/pom_getter_spec.rb
192
195
  - spec/lib/pom_spec.rb
196
+ - spec/lib/project_spec.rb
197
+ - spec/lib/source_address_getter_spec.rb
198
+ - spec/lib/source_getter_spec.rb
193
199
  - spec/lib/version_matcher_spec.rb
194
200
  - spec/spec_helper.rb
195
201
  homepage: https://github.com/SilvioMoioli/gjp
@@ -233,12 +239,15 @@ test_files:
233
239
  - spec/data/nailgun/pom.xml
234
240
  - spec/data/struts-apps/pom.xml
235
241
  - spec/data/tomcat/pom.xml
236
- - spec/lib/get_parent_pom_spec.rb
237
- - spec/lib/get_pom_spec.rb
238
- - spec/lib/get_source_address_spec.rb
239
- - spec/lib/get_source_spec.rb
240
242
  - spec/lib/jar_table_spec.rb
243
+ - spec/lib/limited_network_user_spec_interactive.rb
244
+ - spec/lib/maven_runner_spec.rb
241
245
  - spec/lib/maven_website_spec.rb
246
+ - spec/lib/parent_pom_getter_spec.rb
247
+ - spec/lib/pom_getter_spec.rb
242
248
  - spec/lib/pom_spec.rb
249
+ - spec/lib/project_spec.rb
250
+ - spec/lib/source_address_getter_spec.rb
251
+ - spec/lib/source_getter_spec.rb
243
252
  - spec/lib/version_matcher_spec.rb
244
253
  - spec/spec_helper.rb