gjp 0.30.0 → 0.31.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -114,7 +114,13 @@ The remaining (mostly very outdated) jars will be listed by `gjp` when the downl
114
114
 
115
115
  to get pointers to relevant sites if available in the pom itself.
116
116
 
117
- A list of commonly used jars can be found [below](#frequently-used-jar-sources).
117
+ A list of commonly used jars can be found [below](#frequently-used-sources).
118
+
119
+ You can also use:
120
+
121
+ gjp list-kit-missing-sources
122
+
123
+ To get a list of jars that have one or more `.class` file which does not have a corresponding `.java` file in `kit/` (or zip files in `kit/`).
118
124
 
119
125
  ### Ant builds
120
126
 
@@ -158,11 +164,27 @@ If you want to be 100% sure your package builds without network access, you can
158
164
 
159
165
  * if packages build at first but then fail after a few days because Maven tries to connect to the Internet, add the `--option` flag to the `mvn` line in `build.sh`;
160
166
 
161
- ### Frequently used jar sources
162
-
163
- * ant-launcher-1.6.5: is included in ant-1.6.5 sources, you most prbably have it already in `kit/m2/ant/ant/1.6.5`;
164
- * doxia-sink-api-1.0-alpha-4: use `svn checkout http://svn.apache.org/repos/asf/maven/doxia/doxia/tags/doxia-sink-api-1.0-alpha-4/ doxia-sink-api-1.0-alpha-4`;
165
- * kxml2-2.2.2: use http://downloads.sourceforge.net/project/kxml/kxml2/2.2.2/kxml2-src-2.2.2.zip;
167
+ ### Frequently used sources
168
+
169
+ * antlr-2.7.7: `wget http://www.antlr2.org/download/antlr-2.7.7.tar.gz -O kit/m2/antlr/antlr/2.7.7/antlr-2.7.7-sources.tar.gz`;
170
+ * ant-launcher-1.6.5: sources included in ant-1.6.5;
171
+ * asm-3.3.1: `wget http://download.forge.ow2.org/asm/asm-3.3.1.tar.gz -O kit/m2/asm/asm/3.3.1/asm-3.3.1-sources.tar.gz`;
172
+ * jsr305-1.3.9: sources included in jar;
173
+ * jsr305-2.0.1: sources included in jar;
174
+ * commons-lang-1.0: `wget http://archive.apache.org/dist/commons/lang/source/lang-1.0-src.tar.gz -O kit/m2/commons-lang/commons-lang/1.0/commons-lang-1.0-sources.tar.gz`;
175
+ * commons-logging-api-1.1: `wget http://archive.apache.org/dist/commons/logging/source/commons-logging-1.1-src.tar.gz -O kit/m2/commons-logging/commons-logging/1.1/commons-logging-1.1-sources.tar.gz` (included in commons-logging-1.1);
176
+ * commons-logging-1.0: `wget http://archive.apache.org/dist/commons/logging/source/commons-logging-1.0-src.tar.gz -O kit/m2/commons-logging/commons-logging/1.0/commons-logging-1.0-sources.tar.gz`;
177
+ * dom4j-1.1: `wget http://dom4j.cvs.sourceforge.net/viewvc/dom4j/dom4j/?view=tar&pathrev=dom4j-1-1 -O kit/m2/dom4j/dom4j/1.1/dom4j-1.1-sources.tar.gz`;
178
+ * doxia-sink-api-1.0-alpha-4: use `svn export http://svn.apache.org/repos/asf/maven/doxia/doxia/tags/doxia-sink-api-1.0-alpha-4/ kit/m2/doxia/doxia-sink-api/1.0-alpha-4/doxia-sink-api-1.0-alpha-4-sources`;
179
+ * kxml2-2.2.2: use `wget http://sourceforge.net/projects/kxml/files/kxml2/2.2.2/kxml2-src-2.2.2.zip/download -O kit/m2/net/sf/kxml/kxml2/2.2.2/kxml2-2.2.2-sources.zip`;
180
+ * log4j-1.2.12: `wget http://archive.apache.org/dist/logging/log4j/1.2.12/logging-log4j-1.2.12.tar.gz -O kit/m2/log4j/log4j/1.2.12/log4j-1.2.12-sources.tar.gz`;
181
+ * stringtemplate-3.2: `wget http://www.stringtemplate.org/download/stringtemplate-3.2.tar.gz -O kit/m2/org/antlr/stringtemplate/3.2/stringtemplate-3.2-sources.tar.gz`;
182
+ * velocity-tools-2.0: `wget http://archive.apache.org/dist/velocity/tools/2.0/velocity-tools-2.0-src.tar.gz -O kit/m2/org/apache/velocity/velocity-tools/2.0/velocity-tools-2.0-sources.tar.gz`;
183
+ * velocity-1.5: `wget http://archive.apache.org/dist/velocity/engine/1.5/velocity-1.5.tar.gz -O kit/m2/org/apache/velocity/velocity/1.5/velocity-1.5-sources.tar.gz`;
184
+ * trilead-ssh2-build213-svnkit-1.3: `svn export http://svn.svnkit.com/repos/svnkit/tags/1.3.5/ kit/m2/org/tmatesoft/svnkit/svnkit/1.3.5/svnkit-1.3.5-sources` (included in svnkit 1.3.5 full sources because of custom patch);
185
+ * xercesImpl-2.9.1: `wget http://archive.apache.org/dist/xerces/j/source/Xerces-J-src.2.9.1.tar.gz -O kit/m2/xerces/xercesImpl/2.9.1/xercesImpl-2.9.1-sources.tar.gz`;
186
+ * xmlpull-1.1.3.1: wget `http://www.extreme.indiana.edu/xmlpull-website/v1/download/xmlpull_1_1_3_4c_src.tgz -O kit/m2/xmlpull/xmlpull/1.1.3.1/xmlpull-1.1.3.1-sources.tar.gz`
187
+ * xmlunit-1.3: `wget http://sourceforge.net/projects/xmlunit/files/xmlunit%20for%20Java/XMLUnit%20for%20Java%201.3/xmlunit-1.3-src.zip/download -O kit/m2/xmlunit/xmlunit/1.3/xmlunit-1.3-sources.zip`;
166
188
 
167
189
  ## Motivation
168
190
 
data/lib/gjp.rb CHANGED
@@ -17,5 +17,6 @@ require "gjp/kit_spec_adapter"
17
17
  require "gjp/package_spec_adapter"
18
18
  require "gjp/spec_generator"
19
19
  require "gjp/archiver"
20
+ require "gjp/kit_checker"
20
21
 
21
22
  require "gjp/cli"
@@ -339,6 +339,23 @@ module Gjp
339
339
  end
340
340
  end
341
341
 
342
+ subcommand "list-kit-missing-sources", "Locates jars in kit/ that have no source files" do
343
+ def execute
344
+ checking_exceptions do
345
+ project = Gjp::Project.new(".")
346
+ kit_checker = Gjp::KitChecker.new(project)
347
+
348
+ ensure_dry_running(false, project) do
349
+ puts "Some source files were not found in these archives:"
350
+ kit_checker.get_unsourced.each do |archive|
351
+ percentage = "%.2f" % (100.0 * archive[:unsourced_class_names].length()/archive[:class_names].length())
352
+ puts "#{format_path(archive[:archive], project)} (~#{percentage}% missing)"
353
+ end
354
+ end
355
+ end
356
+ end
357
+ end
358
+
342
359
  private
343
360
 
344
361
  def ensure_dry_running(state, project)
@@ -0,0 +1,107 @@
1
+ # encoding: UTF-8
2
+
3
+ require "find"
4
+
5
+ module Gjp
6
+ # checks kits for errors
7
+ class KitChecker
8
+ include Logger
9
+
10
+ def initialize(project)
11
+ @project = project
12
+ end
13
+
14
+ # returns an array of [path, archive] couples found in kit/
15
+ # archive is not nil if path is inside a zip file
16
+ def kit_file_paths
17
+ @project.from_directory("kit") do
18
+ plain_file_paths = Dir[File.join("**", "*")].select do |path|
19
+ File.file?(path)
20
+ end.map do |path|
21
+ [path, nil]
22
+ end
23
+
24
+ archived_file_paths = plain_file_paths.select do |path, archive|
25
+ path. =~ /\.(zip)|([jwe]ar)$/
26
+ end.map do |path, archive|
27
+ result = []
28
+ Zip::ZipFile.foreach(path) do |entry|
29
+ if entry.file?
30
+ result << [entry.to_s, path]
31
+ end
32
+ end
33
+ result
34
+ end.flatten(1)
35
+
36
+ plain_file_paths + archived_file_paths
37
+ end
38
+ end
39
+
40
+ # returns a list of class names for which
41
+ # we have source files in kit/
42
+ def get_source_class_names(paths)
43
+ source_paths = paths.select do |path, archive|
44
+ path =~ /\.java$/
45
+ end
46
+
47
+ # heuristically add all possible package names, walking
48
+ # back the directory tree all the way back to root.
49
+ # This could add non-existent names, but allows not looking
50
+ # in the file at all
51
+ class_names = source_paths.map do |path, archive|
52
+ class_name = path_to_class(path)
53
+ parts = class_name.split(".")
54
+ last_index = parts.length() -1
55
+ (0..last_index).map do |i|
56
+ parts[i..last_index].join(".")
57
+ end
58
+ end.flatten
59
+
60
+ Set.new(class_names)
61
+ end
62
+
63
+ # returns a list of class names for which
64
+ # we have binary files in kit/
65
+ def get_compiled_classes(paths)
66
+ result = {}
67
+ compiled_paths = paths.select do |path, archive|
68
+ path =~ /\.class$/
69
+ end.each do |path, archive|
70
+ class_name = path_to_class(path)
71
+ if result[archive] == nil
72
+ result[archive] = [class_name]
73
+ else
74
+ result[archive] << class_name
75
+ end
76
+ end
77
+
78
+ result
79
+ end
80
+
81
+ # returns a hash that associates archive names and
82
+ # the unsourced classes within them
83
+ def get_unsourced
84
+ paths = kit_file_paths
85
+ source_class_names = get_source_class_names(paths)
86
+ archive_paths_to_class_names = get_compiled_classes(paths)
87
+
88
+ result = archive_paths_to_class_names.map do |archive, class_names|
89
+ unsourced_class_names = class_names.select do |class_name|
90
+ source_class_names.include?(class_name) == false
91
+ end
92
+ {:archive => archive, :class_names => class_names, :unsourced_class_names => unsourced_class_names}
93
+ end.select do |archive|
94
+ archive[:unsourced_class_names].any?
95
+ end
96
+ end
97
+
98
+ private
99
+ # attempts to turn a .java/.class file name into a class name
100
+ def path_to_class(path)
101
+ path
102
+ .gsub(/\$.+?\./, ".") # remove $InnerClasses
103
+ .gsub(/\..+?$/, "") # remove .extension
104
+ .gsub("/", ".") # convert paths in package names
105
+ end
106
+ end
107
+ end
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module Gjp
4
- VERSION = "0.30.0"
4
+ VERSION = "0.31.0"
5
5
  end
@@ -0,0 +1,119 @@
1
+ # encoding: UTF-8
2
+
3
+ require "spec_helper"
4
+ require "rubygems"
5
+ require "zip/zip"
6
+
7
+ describe Gjp::KitChecker do
8
+ include Gjp::Mockers
9
+
10
+ before(:each) do
11
+ create_mock_project
12
+ @kit_checker = Gjp::KitChecker.new(@project)
13
+ end
14
+
15
+ after(:each) do
16
+ delete_mock_project
17
+ end
18
+
19
+ describe "#kit_file_paths" do
20
+ it "returns an array of paths found in kit" do
21
+ @project.from_directory("kit") do
22
+ FileUtils.touch("top_level")
23
+ FileUtils.mkdir_p("directory")
24
+ FileUtils.touch(File.join("directory","in_directory"))
25
+ Zip::ZipFile.open("zipped.zip", Zip::ZipFile::CREATE) do |zipfile|
26
+ Dir[File.join("directory", "**", "**")].each do |file|
27
+ zipfile.add(file.sub("/directory", ""), file)
28
+ end
29
+ end
30
+ end
31
+
32
+ all_files = @kit_checker.kit_file_paths
33
+
34
+ all_files.should include ["top_level", nil]
35
+ all_files.should_not include ["directory", nil]
36
+ all_files.should include ["directory/in_directory", nil]
37
+ all_files.should include ["zipped.zip", nil]
38
+ all_files.should include ["directory/in_directory", "zipped.zip"]
39
+ end
40
+ end
41
+
42
+ describe "#get_source_classes" do
43
+ it "distills source class names in kit" do
44
+ all_files = [
45
+ ["path/to/ClassOne.java", nil],
46
+ ["path/to/ClassTwo.java", "path/to/archive.jar"],
47
+ ["ClassThree.java", "another_archive.jar"],
48
+ ["path/to/CompiledClass.class", "yet_another.jar"],
49
+ ]
50
+
51
+ class_names = @kit_checker.get_source_class_names(all_files)
52
+
53
+ class_names.should include "path.to.ClassOne"
54
+ class_names.should include "path.to.ClassTwo"
55
+ class_names.should include "ClassThree"
56
+ class_names.should_not include "path.to.CompiledClass"
57
+ end
58
+ end
59
+
60
+ describe "#get_compiled_classes" do
61
+ it "distills source class names in kit" do
62
+ all_files = [
63
+ ["path/to/ClassOne.class", nil],
64
+ ["path/to/ClassTwo.class", "path/to/archive.jar"],
65
+ ["ClassThree.class", "another_archive.jar"],
66
+ ["path/to/SourceClass.java", "yet_another.jar"],
67
+ ]
68
+
69
+ classes = @kit_checker.get_compiled_classes(all_files)
70
+
71
+ classes[nil].should include "path.to.ClassOne"
72
+ classes["path/to/archive.jar"].should include "path.to.ClassTwo"
73
+ classes["another_archive.jar"].should include "ClassThree"
74
+ classes["yet_another.jar"].should be_nil
75
+ end
76
+ end
77
+
78
+ describe "#get_unsourced" do
79
+ it "returns a list of jars wich source files are missing" do
80
+ @project.from_directory("kit") do
81
+ FileUtils.mkdir_p("package1")
82
+ FileUtils.touch(File.join("package1","UnsourcedClass.class"))
83
+
84
+ FileUtils.mkdir_p("package2")
85
+ FileUtils.touch(File.join("package2","SourcedClass.java"))
86
+ Zip::ZipFile.open("zipped-source-2.jar", Zip::ZipFile::CREATE) do |zipfile|
87
+ Dir[File.join("package2", "**", "**")].each do |file|
88
+ zipfile.add(file.sub("/package2", ""), file)
89
+ end
90
+ end
91
+ FileUtils.rm(File.join("package2","SourcedClass.java"))
92
+ FileUtils.touch(File.join("package2","SourcedClass.class"))
93
+ Zip::ZipFile.open("zipped-2.jar", Zip::ZipFile::CREATE) do |zipfile|
94
+ Dir[File.join("package2", "**", "**")].each do |file|
95
+ zipfile.add(file.sub("/package2", ""), file)
96
+ end
97
+ end
98
+
99
+ FileUtils.mkdir_p("package3")
100
+ FileUtils.touch(File.join("package3","SourcedSameArchive.java"))
101
+ FileUtils.touch(File.join("package3","SourcedSameArchive.class"))
102
+ Zip::ZipFile.open("zipped-3.zip", Zip::ZipFile::CREATE) do |zipfile|
103
+ Dir[File.join("package3", "**", "**")].each do |file|
104
+ zipfile.add(file.sub("/package3", ""), file)
105
+ end
106
+ end
107
+ end
108
+
109
+ unsourced = @kit_checker.get_unsourced
110
+ unsourced.length().should eq 1
111
+
112
+ unsourced.first[:archive].should be_nil
113
+ unsourced.first[:class_names].should include "package1.UnsourcedClass"
114
+ unsourced.first[:class_names].should include "package2.SourcedClass"
115
+ unsourced.first[:class_names].should include "package3.SourcedSameArchive"
116
+ unsourced.first[:unsourced_class_names].should include "package1.UnsourcedClass"
117
+ end
118
+ end
119
+ 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.30.0
4
+ version: 0.31.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-27 00:00:00.000000000 Z
12
+ date: 2013-12-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -161,6 +161,7 @@ files:
161
161
  - lib/gjp/archiver.rb
162
162
  - lib/gjp/cli.rb
163
163
  - lib/gjp/git.rb
164
+ - lib/gjp/kit_checker.rb
164
165
  - lib/gjp/kit_runner.rb
165
166
  - lib/gjp/kit_spec_adapter.rb
166
167
  - lib/gjp/limited_network_user.rb
@@ -204,6 +205,7 @@ files:
204
205
  - spec/lib/ant_runner_spec.rb
205
206
  - spec/lib/archiver_spec.rb
206
207
  - spec/lib/git_spec.rb
208
+ - spec/lib/kit_checker_spec.rb
207
209
  - spec/lib/kit_runner_spec.rb
208
210
  - spec/lib/limited_network_user_spec_interactive.rb
209
211
  - spec/lib/maven_runner_spec.rb
@@ -262,6 +264,7 @@ test_files:
262
264
  - spec/lib/ant_runner_spec.rb
263
265
  - spec/lib/archiver_spec.rb
264
266
  - spec/lib/git_spec.rb
267
+ - spec/lib/kit_checker_spec.rb
265
268
  - spec/lib/kit_runner_spec.rb
266
269
  - spec/lib/limited_network_user_spec_interactive.rb
267
270
  - spec/lib/maven_runner_spec.rb