gjp 0.16.1 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/integration-tests/commons-io.sh +41 -0
- data/lib/gjp.rb +0 -1
- data/lib/gjp/cli.rb +0 -9
- data/lib/gjp/version.rb +1 -1
- metadata +2 -4
- data/lib/gjp/jar_table.rb +0 -160
- data/spec/lib/jar_table_spec.rb +0 -59
data/README.md
CHANGED
@@ -75,7 +75,7 @@ Ceate a new `gjp` project, in this example named "galaxy":
|
|
75
75
|
unzip commons-collections-3.2.1-src.zip
|
76
76
|
rm commons-collections-3.2.1-src.zip
|
77
77
|
|
78
|
-
Now let's move to the kit (which, unsurprisingly, should be placed in the `kit` folder). commons-
|
78
|
+
Now let's move to the kit (which, unsurprisingly, should be placed in the `kit` folder). commons-collections needs Maven 3 to build, so we should simply unzip a copy in `kit`:
|
79
79
|
|
80
80
|
cd ../../kit
|
81
81
|
wget http://apache.fastbull.org/maven/maven-3/3.1.0/binaries/apache-maven-3.1.0-bin.zip
|
@@ -211,7 +211,7 @@ The Fedora community is experimenting with another set of tools, [XMvn](http://m
|
|
211
211
|
|
212
212
|
Building software from a binary blob is unusual for Linux distros, and it surely has some drawbacks. It is anyway believed that benefits outweigh them, in fact using prebuilt software:
|
213
213
|
|
214
|
-
* drastically reduces packaging efforts. A very basic and relatively simple package like [commons-
|
214
|
+
* drastically reduces packaging efforts. A very basic and relatively simple package like [commons-collections](http://commons.apache.org/proper/commons-collections/) needs about [150 jars](https://build.opensuse.org/package/show/home:SilvioMoioli/galaxy-kit) just to be compiled and tested. Those should be packaged, roughly, one-by-one!
|
215
215
|
* is just the way all Java developers out there build, test and use their software — this is how they expect it to work. Any different approach is necessarily error-prone and could result in unexpected bugs;
|
216
216
|
* does not affect the ability of providing patches to Java projects, as only build time requirements are in the kit. In virtually all cases patching a piece of software does not require to patch its build toolchain;
|
217
217
|
* does not affect the ability of complying to software licenses like the GPL. In fact those licenses only require to redistribute a project's source code - not the whole toolchain needed to build it. [Sources can be added](#kit-sources) for GPL'd parts of the kit, if any.
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
# A crude integration test that builds commons-lang
|
4
|
+
|
5
|
+
mkdir galaxy
|
6
|
+
cd galaxy
|
7
|
+
gjp init
|
8
|
+
|
9
|
+
cd src
|
10
|
+
mkdir commons-collections
|
11
|
+
cd commons-collections
|
12
|
+
wget http://archive.apache.org/dist/commons/collections/source/commons-collections-3.2.1-src.zip
|
13
|
+
unzip commons-collections-3.2.1-src.zip
|
14
|
+
rm commons-collections-3.2.1-src.zip
|
15
|
+
|
16
|
+
cd ../../kit
|
17
|
+
wget http://apache.fastbull.org/maven/maven-3/3.1.0/binaries/apache-maven-3.1.0-bin.zip
|
18
|
+
unzip apache-maven-3.1.0-bin.zip
|
19
|
+
rm apache-maven-3.1.0-bin.zip
|
20
|
+
cd ..
|
21
|
+
|
22
|
+
gjp dry-run
|
23
|
+
cd src/commons-collections/commons-collections-3.2.1-src/
|
24
|
+
gjp mvn package
|
25
|
+
|
26
|
+
gjp gather
|
27
|
+
cat >../build.sh << "EOF"
|
28
|
+
#!/bin/sh
|
29
|
+
cd src/commons-collections/commons-collections-3.2.1-src/
|
30
|
+
../../../kit/apache-maven-3.1.0/bin/mvn -Dmaven.repo.local=`readlink -e ../../../kit/m2` -s`readlink -e ../../../kit/m2/settings.xml` package
|
31
|
+
EOF
|
32
|
+
gjp finish
|
33
|
+
cd ../../..
|
34
|
+
|
35
|
+
gjp generate-kit-spec
|
36
|
+
gjp generate-kit-archive
|
37
|
+
|
38
|
+
gjp generate-package-spec commons-collections src/commons-collections/commons-collections-3.2.1-src/pom.xml
|
39
|
+
gjp generate-package-archive commons-collections
|
40
|
+
|
41
|
+
echo "All Done"
|
data/lib/gjp.rb
CHANGED
data/lib/gjp/cli.rb
CHANGED
@@ -218,14 +218,5 @@ module Gjp
|
|
218
218
|
puts Gjp::SourceGetter.new.get_source(address, pom, directory)
|
219
219
|
end
|
220
220
|
end
|
221
|
-
|
222
|
-
subcommand "scaffold-jar-table", "Creates a heuristic version of a project's jar table" do
|
223
|
-
parameter "[DIRECTORY]", "project directory", :default => "."
|
224
|
-
option ["--include-all"], :flag, "include tests and samples in produced jars", :default => false
|
225
|
-
|
226
|
-
def execute
|
227
|
-
puts Gjp::JarTable.new(directory, include_all?).to_s
|
228
|
-
end
|
229
|
-
end
|
230
221
|
end
|
231
222
|
end
|
data/lib/gjp/version.rb
CHANGED
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.17.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -155,10 +155,10 @@ files:
|
|
155
155
|
- Rakefile
|
156
156
|
- bin/gjp
|
157
157
|
- gjp.gemspec
|
158
|
+
- integration-tests/commons-io.sh
|
158
159
|
- lib/gjp.rb
|
159
160
|
- lib/gjp/archiver.rb
|
160
161
|
- lib/gjp/cli.rb
|
161
|
-
- lib/gjp/jar_table.rb
|
162
162
|
- lib/gjp/limited_network_user.rb
|
163
163
|
- lib/gjp/logger.rb
|
164
164
|
- lib/gjp/maven_runner.rb
|
@@ -200,7 +200,6 @@ files:
|
|
200
200
|
- spec/data/struts-apps/pom.xml
|
201
201
|
- spec/data/tomcat/pom.xml
|
202
202
|
- spec/lib/archiver_spec.rb
|
203
|
-
- spec/lib/jar_table_spec.rb
|
204
203
|
- spec/lib/limited_network_user_spec_interactive.rb
|
205
204
|
- spec/lib/maven_runner_spec.rb
|
206
205
|
- spec/lib/maven_website_spec.rb
|
@@ -256,7 +255,6 @@ test_files:
|
|
256
255
|
- spec/data/struts-apps/pom.xml
|
257
256
|
- spec/data/tomcat/pom.xml
|
258
257
|
- spec/lib/archiver_spec.rb
|
259
|
-
- spec/lib/jar_table_spec.rb
|
260
258
|
- spec/lib/limited_network_user_spec_interactive.rb
|
261
259
|
- spec/lib/maven_runner_spec.rb
|
262
260
|
- spec/lib/maven_website_spec.rb
|
data/lib/gjp/jar_table.rb
DELETED
@@ -1,160 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require "text"
|
4
|
-
|
5
|
-
module Gjp
|
6
|
-
# encapsulates information of a project's jar files
|
7
|
-
# assumes the project is in a directory with jar files
|
8
|
-
# in its (possibly nested) subdirectories
|
9
|
-
class JarTable
|
10
|
-
include Logger
|
11
|
-
|
12
|
-
attr_reader :rows, :runtime_required_packages, :source_defined_packages
|
13
|
-
|
14
|
-
# builds a JarTable from a directory (paths relative to the current directory)
|
15
|
-
def initialize(dir, include_all)
|
16
|
-
jars = get_jars(dir)
|
17
|
-
sources = get_sources(dir)
|
18
|
-
statements = get_statements(sources)
|
19
|
-
@runtime_required_packages = get_runtime_required_packages(statements)
|
20
|
-
@source_defined_packages = get_source_defined_packages(statements)
|
21
|
-
|
22
|
-
log.debug "Runtime required packages are:\n#{@runtime_required_packages.join("\n")}"
|
23
|
-
log.debug "Source defined packages are:\n#{@source_defined_packages.join("\n")}"
|
24
|
-
|
25
|
-
@rows = Hash[
|
26
|
-
jars.map do |jar|
|
27
|
-
[jar, get_type(jar, include_all)]
|
28
|
-
end
|
29
|
-
]
|
30
|
-
end
|
31
|
-
|
32
|
-
def to_s
|
33
|
-
"# Key: \n" +
|
34
|
-
"# b - jar is required for building the project\n" +
|
35
|
-
"# r - jar is required runtime by the project\n" +
|
36
|
-
"# p - jar is produced by the project\n" +
|
37
|
-
"# i - jar is ignored\n" +
|
38
|
-
|
39
|
-
(
|
40
|
-
rows = @rows.map do |key, value|
|
41
|
-
pathname = Pathname.new(key)
|
42
|
-
[value.to_s[0], pathname.basename.to_s, pathname.dirname.to_s]
|
43
|
-
end
|
44
|
-
|
45
|
-
max_field_lengths = (0..2).map do |i|
|
46
|
-
rows.map { |row| row[i].length }.max
|
47
|
-
end
|
48
|
-
|
49
|
-
rows.map do |row|
|
50
|
-
row.each_with_index.map do |element, i|
|
51
|
-
"%-#{max_field_lengths[i]+1}s" % element
|
52
|
-
end.join
|
53
|
-
end.sort.join("\n")
|
54
|
-
)
|
55
|
-
end
|
56
|
-
|
57
|
-
# jar files in the project's directory
|
58
|
-
def get_jars(dir)
|
59
|
-
Dir["#{dir}/**/*.jar"]
|
60
|
-
end
|
61
|
-
|
62
|
-
# java source files in the project's directory
|
63
|
-
def get_sources(dir)
|
64
|
-
Dir["#{dir}/**/*.java"]
|
65
|
-
end
|
66
|
-
|
67
|
-
# java statements in java source files
|
68
|
-
def get_statements(sources)
|
69
|
-
sources.map do |source|
|
70
|
-
File.readlines(source)
|
71
|
-
.map { |line| line.split(";") }
|
72
|
-
.flatten
|
73
|
-
.map { |statement| statement.strip }
|
74
|
-
end.flatten
|
75
|
-
end
|
76
|
-
|
77
|
-
# heuristically determined package names that the sources require
|
78
|
-
def get_runtime_required_packages(statements)
|
79
|
-
get_statement_fragments_from(statements, /^import[ \t]+(?:static[ \t]+)?(.+)\..+?$/)
|
80
|
-
end
|
81
|
-
|
82
|
-
# heuristically determined package names that the sources define
|
83
|
-
def get_source_defined_packages(statements)
|
84
|
-
get_statement_fragments_from(statements, /^package[ \t]+(.+)$/)
|
85
|
-
end
|
86
|
-
|
87
|
-
# matches a regex against all source statements
|
88
|
-
def get_statement_fragments_from(statements, regex)
|
89
|
-
statements.map do |statement|
|
90
|
-
if statement =~ regex
|
91
|
-
$1
|
92
|
-
end
|
93
|
-
end.select {|package| package != nil}.flatten.sort.uniq
|
94
|
-
end
|
95
|
-
|
96
|
-
|
97
|
-
# returns :produced if the jar was produced from the project's sources, and
|
98
|
-
# :required or :build_required if it is needed at runtime or build time
|
99
|
-
# (heuristically)
|
100
|
-
def get_type(jar, include_all)
|
101
|
-
if not include_all and (jar =~ /(test)|(sample)/)
|
102
|
-
:ignored
|
103
|
-
else
|
104
|
-
jar_defined_packages = get_jar_defined_packages(jar)
|
105
|
-
|
106
|
-
if source_defined?(jar, jar_defined_packages)
|
107
|
-
:produced
|
108
|
-
elsif runtime_required?(jar, jar_defined_packages)
|
109
|
-
:required
|
110
|
-
else
|
111
|
-
:build_required
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
# returns true if a jar is produced from source code in the project's directory
|
117
|
-
def source_defined?(jar, jar_defined_packages)
|
118
|
-
log.debug "Determining if #{jar} is defined in the sources"
|
119
|
-
log.debug "#{jar} contains:\n#{jar_defined_packages.join("\n")}"
|
120
|
-
|
121
|
-
result = jar_defined_packages.all? { |package| @source_defined_packages.include?(package) }
|
122
|
-
|
123
|
-
log.debug "result is:#{result}"
|
124
|
-
|
125
|
-
return result
|
126
|
-
end
|
127
|
-
|
128
|
-
# returns true if a jar is required runtime, false if it is only needed
|
129
|
-
# at compile time. Current implementation is heuristic (looks for "import" statements
|
130
|
-
# in java code)
|
131
|
-
def runtime_required?(jar, jar_defined_packages)
|
132
|
-
log.debug "Determining if #{jar} is required at runtime"
|
133
|
-
log.debug "#{jar} contains:\n#{jar_defined_packages.join("\n")}"
|
134
|
-
|
135
|
-
result = jar_defined_packages.any? { |package| @runtime_required_packages.include?(package) }
|
136
|
-
|
137
|
-
log.debug "result is:#{result}"
|
138
|
-
|
139
|
-
return result
|
140
|
-
end
|
141
|
-
|
142
|
-
# returns packages defined in a jar file
|
143
|
-
def get_jar_defined_packages(jar)
|
144
|
-
result = []
|
145
|
-
begin
|
146
|
-
Zip::ZipFile.foreach(jar) do |entry|
|
147
|
-
if entry.name =~ /^(.+)\/.+?\.class$/
|
148
|
-
result << $1.gsub("/", ".")
|
149
|
-
end
|
150
|
-
end
|
151
|
-
rescue Zip::ZipError
|
152
|
-
log.info "#{jar} does not seem to be a valid jar archive, skipping"
|
153
|
-
rescue TypeError
|
154
|
-
log.info "#{jar} seems to be a valid jar archive but is corrupt, skipping"
|
155
|
-
end
|
156
|
-
|
157
|
-
return result.sort.uniq
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
data/spec/lib/jar_table_spec.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Gjp::JarTable do
|
6
|
-
let(:dir) { File.join("spec", "data", "ant-super-simple-code") }
|
7
|
-
let(:jar_table) { Gjp::JarTable.new(dir, true) }
|
8
|
-
|
9
|
-
describe "#get_jars" do
|
10
|
-
it "finds jar paths in a directory" do
|
11
|
-
jar_table.get_jars(dir).should include(
|
12
|
-
File.join(dir, "dist", "antsimple-20130618.jar"),
|
13
|
-
File.join(dir, "lib", "junit-4.11.jar"),
|
14
|
-
File.join(dir, "lib", "log4j-1.2.13.jar")
|
15
|
-
)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "#get_jar_defined_packages" do
|
20
|
-
it "finds the package names part of a jar file" do
|
21
|
-
jar_table.get_jar_defined_packages(File.join(dir, "lib", "junit-4.11.jar")).should include(
|
22
|
-
"junit.framework",
|
23
|
-
"junit.extensions",
|
24
|
-
"org.junit.runner",
|
25
|
-
"org.junit.runners.model"
|
26
|
-
)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "#sources" do
|
31
|
-
it "finds source paths in a directory" do
|
32
|
-
jar_table.get_sources(dir).should include(
|
33
|
-
File.join(dir, "src", "mypackage", "HW.java")
|
34
|
-
)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "#source_defined_packages" do
|
39
|
-
it "finds the package names built from this project" do
|
40
|
-
jar_table.source_defined_packages.should include("mypackage")
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "#runtime_required_packages" do
|
45
|
-
it "finds the package names required by this project's sources" do
|
46
|
-
jar_table.runtime_required_packages.should include("org.apache.log4j")
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "#rows" do
|
51
|
-
it "returns jar data" do
|
52
|
-
jar_table.rows.should include(
|
53
|
-
"spec/data/ant-super-simple-code/lib/log4j-1.2.13.jar" => :required,
|
54
|
-
"spec/data/ant-super-simple-code/lib/junit-4.11.jar" => :build_required,
|
55
|
-
"spec/data/ant-super-simple-code/dist/antsimple-20130618.jar" => :produced
|
56
|
-
)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|