gjp 0.27.0 → 0.28.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.
- data/README.md +25 -23
- data/lib/gjp/cli.rb +32 -5
- data/lib/gjp/kit_runner.rb +1 -0
- data/lib/gjp/source_getter.rb +30 -1
- data/lib/gjp/version.rb +1 -1
- data/spec/lib/kit_runner_spec.rb +8 -18
- data/spec/lib/source_getter_spec.rb +31 -0
- data/spec/spec_helper.rb +14 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -6,7 +6,7 @@ The project objective is to strongly reduce manual packaging efforts by enabling
|
|
6
6
|
|
7
7
|
## Status
|
8
8
|
|
9
|
-
`gjp` is a research project currently in
|
9
|
+
`gjp` is a research project currently in beta state. All basic features have been coded, non-essential ones are being planned, packages are currently being built. If you are a packager you can try to use it, any feedback would be **very** welcome!
|
10
10
|
|
11
11
|
At the moment `gjp` is tested on openSUSE and can only output RPMs for the openSUSE and SLES distributions. Fedora, RHEL and other distros could be supported in the future.
|
12
12
|
|
@@ -50,7 +50,7 @@ Note that:
|
|
50
50
|
* a `gjp` project can be used to build a number of packages that share one binary kit. This can help if the kit becomes big in size;
|
51
51
|
* `gjp` will take advantage of Maven's pom files to generate its specs if they are available. This allows to precompile most spec fields automatically.
|
52
52
|
|
53
|
-
###
|
53
|
+
### A sample Maven project (commons-collections)
|
54
54
|
|
55
55
|
#### Initialization and project setup
|
56
56
|
|
@@ -146,7 +146,24 @@ OBS users: note that the output/ directory created by gjp can be submitted or us
|
|
146
146
|
gjp finish
|
147
147
|
gjp generate-all
|
148
148
|
|
149
|
-
####
|
149
|
+
#### Kit sources
|
150
|
+
|
151
|
+
If you want to redistribute your RPMs, chances are that you need source files for kit contents.
|
152
|
+
|
153
|
+
If you use Maven, most sources for binary jars in your kit can be automatically downloaded:
|
154
|
+
|
155
|
+
gjp get-maven-source-jars
|
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:
|
158
|
+
|
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
|
+
* `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
|
+
* `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
|
+
* `gjp get-source POM ADDRESS` downloads the source of a pom.xml's project from its SCM at ADDRESS;
|
163
|
+
|
164
|
+
More comprehensive support is planned in future releases.
|
165
|
+
|
166
|
+
#### Optional: Ant packages
|
150
167
|
|
151
168
|
Building Ant packages is not really different from Maven ones, as `gjp ant` will operate exactly like `gjp mvn`.
|
152
169
|
|
@@ -170,30 +187,15 @@ Once built, you are advised to grab an "informational" pom.xml (via `gjp get-pom
|
|
170
187
|
|
171
188
|
The above is not mandatory, but it can be useful for debugging purposes.
|
172
189
|
|
173
|
-
#### Optional: kit sources
|
174
190
|
|
175
|
-
|
176
|
-
|
177
|
-
If the project you are packaging uses Maven, you can ask Maven itself to find source jars for dependencies. Running the following command will add them to the kit:
|
178
|
-
|
179
|
-
gjp mvn dependency:sources
|
180
|
-
|
181
|
-
Unfortunately this will not take care of Maven itself, Maven's plugins and their dependencies so some extra work might be needed.
|
182
|
-
|
183
|
-
At the moment `gjp`'s supprort to kit source retrieval is limited to the following subcommands:
|
184
|
-
|
185
|
-
* `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;
|
186
|
-
* `gjp get-parent-pom POM` will attempt to download a pom's parent from search.maven.org, where `POM` is a filename or URI;
|
187
|
-
* `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;
|
188
|
-
* `gjp get-source POM ADDRESS` downloads the source of a pom.xml's project from its SCM at ADDRESS;
|
189
|
-
|
190
|
-
More comprehensive support is planned in future releases.
|
191
|
+
### Gotchas
|
191
192
|
|
192
|
-
|
193
|
+
* `gjp` internally uses `git` to keep track of files, any gjp project is actually also a `git` repo. Feel free to navigate it, you can commit, push and pull as long as the `gjp` tags are preserved. You can also delete commits and tags, effectively rewinding gjp history (just make sure to delete all tags pointing to a certain commit when you discard it);
|
194
|
+
* if your sources come from a Git repo, be sure to remove any `.git`/`.gitignore` files, otherwise `gjp` might get confused;
|
195
|
+
* if OBS complains that jars in your kit or package are compiled for a JDK version higher than 1.5, add the following line after `%install` to squelch the error:
|
193
196
|
|
194
|
-
|
197
|
+
export NO_BRP_CHECK_BYTECODE_VERSION=true
|
195
198
|
|
196
|
-
`gjp` internally uses `git` to keep track of files, any gjp project is actually also a `git` repo. Feel free to navigate it, you can commit, push and pull freely as long as the `gjp` tags are preserved. You can also delete commits and tags, effectively rewinding gjp history (just make sure to delete all tags pointing to a certain commit when you discard it).
|
197
199
|
|
198
200
|
## Motivation
|
199
201
|
|
data/lib/gjp/cli.rb
CHANGED
@@ -216,11 +216,38 @@ module Gjp
|
|
216
216
|
|
217
217
|
subcommand "purge-jars", "Locates jars in src/ and moves them to kit/" do
|
218
218
|
def execute
|
219
|
-
|
219
|
+
checking_exceptions do
|
220
|
+
project = Gjp::Project.new(".")
|
221
|
+
|
222
|
+
ensure_dry_running(false, project) do
|
223
|
+
project.purge_jars.each do |original, final|
|
224
|
+
puts "Replaced #{original} with symlink pointing to to #{final}"
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
220
230
|
|
221
|
-
|
222
|
-
|
223
|
-
|
231
|
+
subcommand "get-maven-source-jars", "Attempts to download Maven kit/ sources" do
|
232
|
+
def execute
|
233
|
+
checking_exceptions do
|
234
|
+
project = Gjp::Project.new(".")
|
235
|
+
source_getter = Gjp::SourceGetter.new
|
236
|
+
|
237
|
+
ensure_dry_running(false, project) do
|
238
|
+
puts "Getting sources from Maven..."
|
239
|
+
succeeded, failed = source_getter.get_maven_source_jars(project)
|
240
|
+
|
241
|
+
puts "\n**SUMMARY**\n"
|
242
|
+
puts "Sources found for:"
|
243
|
+
succeeded.each do |path|
|
244
|
+
puts " #{format_path(path, project)}"
|
245
|
+
end
|
246
|
+
|
247
|
+
puts "\nSources not found for:"
|
248
|
+
failed.each do |path|
|
249
|
+
puts " #{format_path(path, project)}"
|
250
|
+
end
|
224
251
|
end
|
225
252
|
end
|
226
253
|
end
|
@@ -337,7 +364,7 @@ module Gjp
|
|
337
364
|
rescue Errno::EEXIST => e
|
338
365
|
$stderr.puts e
|
339
366
|
rescue NoProjectDirectoryError => e
|
340
|
-
$stderr.puts "#{e.directory} not a gjp project directory, see gjp init"
|
367
|
+
$stderr.puts "#{e.directory} is not a gjp project directory, see gjp init"
|
341
368
|
rescue NoPackageDirectoryError => e
|
342
369
|
$stderr.puts "#{e.directory} is not a gjp package directory, see README"
|
343
370
|
rescue GitAlreadyInitedError => e
|
data/lib/gjp/kit_runner.rb
CHANGED
data/lib/gjp/source_getter.rb
CHANGED
@@ -3,10 +3,29 @@
|
|
3
3
|
require "rest_client"
|
4
4
|
|
5
5
|
module Gjp
|
6
|
-
# attempts to get java projects' sources
|
6
|
+
# attempts to get java projects' sources
|
7
7
|
class SourceGetter
|
8
8
|
include Logger
|
9
9
|
|
10
|
+
# looks for jars in maven's local repo and downloads corresponding
|
11
|
+
# source jars
|
12
|
+
def get_maven_source_jars(project)
|
13
|
+
kit_runner = Gjp::KitRunner.new(project)
|
14
|
+
|
15
|
+
project.from_directory do
|
16
|
+
paths = Find.find(".").reject {|path| artifact_from_path(path) == nil}.sort
|
17
|
+
|
18
|
+
succeded_paths = paths.select.with_index do |path, i|
|
19
|
+
artifact = artifact_from_path(path)
|
20
|
+
log.info("attempting source download for #{path} (#{artifact})")
|
21
|
+
status = kit_runner.mvn(["dependency:get", "-Dartifact=#{artifact}", "-Dtransitive=false"])
|
22
|
+
status.exitstatus == 0
|
23
|
+
end
|
24
|
+
|
25
|
+
[succeded_paths, (paths - succeded_paths)]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
10
29
|
# downloads a project's source into a specified directory
|
11
30
|
def get_source(address, pomfile, directory)
|
12
31
|
log.info("downloading: #{address} in #{directory}, pomfile: #{pomfile}")
|
@@ -81,5 +100,15 @@ module Gjp
|
|
81
100
|
best_version = version_matcher.best_match(version, versions_to_tags.keys)
|
82
101
|
versions_to_tags[best_version]
|
83
102
|
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
# if possible, turn path into a Maven artifact name, otherwise return nil
|
107
|
+
def artifact_from_path(path)
|
108
|
+
match = path.match(/\.\/kit\/m2\/(.+)\/(.+)\/(.+)\/\2-\3.*\.jar$/)
|
109
|
+
if match != nil
|
110
|
+
"#{match[1].gsub("/", ".")}:#{match[2]}:#{match[3]}:jar:sources"
|
111
|
+
end
|
112
|
+
end
|
84
113
|
end
|
85
114
|
end
|
data/lib/gjp/version.rb
CHANGED
data/spec/lib/kit_runner_spec.rb
CHANGED
@@ -19,8 +19,8 @@ describe Gjp::KitRunner do
|
|
19
19
|
|
20
20
|
describe "#find_executable" do
|
21
21
|
it "finds an executable in kit" do
|
22
|
-
mock_executable("mvn")
|
23
|
-
@kit_runner.find_executable("mvn").should eq
|
22
|
+
executable_path = mock_executable("mvn", @project_path)
|
23
|
+
@kit_runner.find_executable("mvn").should eq executable_path
|
24
24
|
end
|
25
25
|
it "doesn't find a Maven executable in kit" do
|
26
26
|
@kit_runner.find_executable("mvn").should be_nil
|
@@ -29,11 +29,11 @@ describe Gjp::KitRunner do
|
|
29
29
|
|
30
30
|
describe "#get_maven_commandline" do
|
31
31
|
it "returns commandline options for running maven" do
|
32
|
-
mock_executable("mvn")
|
32
|
+
executable_path = mock_executable("mvn", @project_path)
|
33
33
|
|
34
34
|
@project.from_directory do
|
35
35
|
commandline = @kit_runner.get_maven_commandline(".")
|
36
|
-
commandline.should eq "./#{
|
36
|
+
commandline.should eq "./#{executable_path} -Dmaven.repo.local=./kit/m2 -s./kit/m2/settings.xml"
|
37
37
|
end
|
38
38
|
end
|
39
39
|
it "doesn't return commandline options if Maven is not available" do
|
@@ -43,7 +43,7 @@ describe Gjp::KitRunner do
|
|
43
43
|
|
44
44
|
describe "#mvn" do
|
45
45
|
it "runs maven" do
|
46
|
-
mock_executable("mvn")
|
46
|
+
mock_executable("mvn", @project_path)
|
47
47
|
@project.from_directory do
|
48
48
|
@kit_runner.mvn(["extra-option"])
|
49
49
|
File.read("test_out").strip.should match /extra-option$/
|
@@ -59,11 +59,11 @@ describe Gjp::KitRunner do
|
|
59
59
|
|
60
60
|
describe "#get_ant_commandline" do
|
61
61
|
it "returns commandline options for running Ant" do
|
62
|
-
mock_executable("ant")
|
62
|
+
executable_path = mock_executable("ant", @project_path)
|
63
63
|
|
64
64
|
@project.from_directory do
|
65
65
|
commandline = @kit_runner.get_ant_commandline(".")
|
66
|
-
commandline.should eq "./#{
|
66
|
+
commandline.should eq "./#{executable_path}"
|
67
67
|
end
|
68
68
|
end
|
69
69
|
it "doesn't return commandline options if Ant is not available" do
|
@@ -73,7 +73,7 @@ describe Gjp::KitRunner do
|
|
73
73
|
|
74
74
|
describe "#ant" do
|
75
75
|
it "runs Ant" do
|
76
|
-
mock_executable("ant")
|
76
|
+
mock_executable("ant", @project_path)
|
77
77
|
@project.from_directory do
|
78
78
|
@kit_runner.ant(["extra-option"])
|
79
79
|
File.read("test_out").strip.should match /extra-option$/
|
@@ -85,14 +85,4 @@ describe Gjp::KitRunner do
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
end
|
88
|
-
|
89
|
-
def mock_executable(executable)
|
90
|
-
Dir.chdir(@project_path) do
|
91
|
-
@bin_dir = File.join("kit", executable, "bin")
|
92
|
-
FileUtils.mkdir_p(@bin_dir)
|
93
|
-
@executable = File.join(@bin_dir, executable)
|
94
|
-
File.open(@executable, "w") { |io| io.puts "echo $0 $*>test_out" }
|
95
|
-
File.chmod(0777, @executable)
|
96
|
-
end
|
97
|
-
end
|
98
88
|
end
|
@@ -6,6 +6,37 @@ require "fileutils"
|
|
6
6
|
describe Gjp::SourceGetter do
|
7
7
|
let(:source_getter) { Gjp::SourceGetter.new }
|
8
8
|
|
9
|
+
describe "#get_maven_source_jars" do
|
10
|
+
before(:each) do
|
11
|
+
@project_path = File.join("spec", "data", "test-project")
|
12
|
+
Dir.mkdir(@project_path)
|
13
|
+
|
14
|
+
Gjp::Project.init(@project_path)
|
15
|
+
@project = Gjp::Project.new(@project_path)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "gets sources for jars in the Maven repo through Maven itself" do
|
19
|
+
mock_executable("mvn", @project_path)
|
20
|
+
|
21
|
+
@project.from_directory(File.join("kit", "m2")) do
|
22
|
+
jar_dir_path = File.join("net", "test", "artifact", "1.0")
|
23
|
+
jar_path = File.join(jar_dir_path, "artifact-1.0-blabla.jar")
|
24
|
+
FileUtils.mkdir_p(jar_dir_path)
|
25
|
+
FileUtils.touch(jar_path)
|
26
|
+
|
27
|
+
successes, failures = source_getter.get_maven_source_jars(@project)
|
28
|
+
commandline = File.read(File.join("..", "..", "test_out")).strip
|
29
|
+
commandline.should match /-Dartifact=net.test:artifact:1.0:jar:sources -Dtransitive=false$/
|
30
|
+
successes.should include File.join(".", "kit", "m2", jar_path)
|
31
|
+
failures.should eq []
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
after(:each) do
|
36
|
+
FileUtils.rm_rf(@project_path)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
9
40
|
describe "#get_source_from_git" do
|
10
41
|
it "gets the sources from a git repo" do
|
11
42
|
dir_path = File.join("spec", "data", "nailgun")
|
data/spec/spec_helper.rb
CHANGED
@@ -4,3 +4,17 @@ require "gjp"
|
|
4
4
|
require "gjp/logger"
|
5
5
|
|
6
6
|
Gjp::Logger.log.level = ::Logger::DEBUG
|
7
|
+
|
8
|
+
# creates an executable in kit that will print its parameters
|
9
|
+
# in a test_out file for checking. Returns mocked executable
|
10
|
+
# full path
|
11
|
+
def mock_executable(executable_name, project_path)
|
12
|
+
Dir.chdir(project_path) do
|
13
|
+
bin_dir = File.join("kit", executable_name, "bin")
|
14
|
+
FileUtils.mkdir_p(bin_dir)
|
15
|
+
executable_path = File.join(bin_dir, executable_name)
|
16
|
+
File.open(executable_path, "w") { |io| io.puts "echo $0 $*>test_out" }
|
17
|
+
File.chmod(0777, executable_path)
|
18
|
+
executable_path
|
19
|
+
end
|
20
|
+
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.
|
4
|
+
version: 0.28.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: 2013-
|
12
|
+
date: 2013-12-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|