instadoc 0.0.1
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/.gitignore +20 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/.travis.yml +2 -0
- data/Changelog.md +3 -0
- data/Gemfile +2 -0
- data/Guardfile +10 -0
- data/LICENSE +22 -0
- data/README.md +34 -0
- data/README.rdoc +6 -0
- data/Rakefile +8 -0
- data/bin/instadoc +76 -0
- data/instadoc.gemspec +29 -0
- data/lib/instadoc.rb +29 -0
- data/lib/instadoc/analyzer.rb +34 -0
- data/lib/instadoc/config.rb +25 -0
- data/lib/instadoc/html_builder.rb +58 -0
- data/lib/instadoc/java/java_code.rb +29 -0
- data/lib/instadoc/java/java_file.rb +67 -0
- data/lib/instadoc/java/pathname_seeker.rb +26 -0
- data/lib/instadoc/version.rb +4 -0
- data/spec/instadoc_toolbox/analyzer_spec.rb +35 -0
- data/spec/instadoc_toolbox/html_builder_spec.rb +37 -0
- data/spec/instadoc_toolbox/instadoc_spec.rb +10 -0
- data/spec/instadoc_toolbox/java/java_code_spec.rb +29 -0
- data/spec/instadoc_toolbox/java/java_file_spec.rb +112 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/exit_code_matcher.rb +42 -0
- data/spec/support/temp_folder_helper.rb +32 -0
- data/spec/support/test_config_helper.rb +32 -0
- data/spec/test_data/java_code/org/company/AnnotatedTestClazz.java +12 -0
- data/spec/test_data/java_code/org/company/AnnotatedTestMethods.java +15 -0
- data/spec/test_data/java_code/org/company/NotAnnotatedDummy.java +13 -0
- metadata +209 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.3@instadoc --create
|
data/.travis.yml
ADDED
data/Changelog.md
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec', :version => 2 do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^spec/.+_helper\.rb$}) { "spec" }
|
7
|
+
watch(%r{^spec/.+_matcher\.rb$}) { "spec" }
|
8
|
+
watch(%r{^lib/(.+)\.rb$}) { "spec" }
|
9
|
+
watch('spec/spec_helper.rb') { "spec" }
|
10
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Markus Hanses
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
[](http://travis-ci.org/marhan/instadoc)
|
2
|
+
|
3
|
+
# Instadoc
|
4
|
+
|
5
|
+
Reads annotated Java code and collects the inserted documentation and creates a summery.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'instadoc'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install instadoc
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
$instadoc -s /path/to/source html -o output.html -l http://server/path/PLACEHOLDER
|
24
|
+
|
25
|
+
Use the upper case string `PLACEHOLDER` is a placeholder for package and Java file name.
|
26
|
+
The placeholder will be created by the relative path from the given source path `-s /path/to/source` as a base path and the Java file itself.
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
1. Fork it
|
31
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
32
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
33
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
34
|
+
5. Create new Pull Request
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
data/bin/instadoc
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'gli'
|
3
|
+
require 'instadoc'
|
4
|
+
|
5
|
+
include GLI::App
|
6
|
+
|
7
|
+
program_desc 'A documentation generation tool for source code'
|
8
|
+
|
9
|
+
version Instadoc::VERSION
|
10
|
+
|
11
|
+
desc 'be verbose'
|
12
|
+
switch [:v, :verbose]
|
13
|
+
|
14
|
+
desc 'The path to Java source'
|
15
|
+
default_value './java'
|
16
|
+
arg_name 'source_path'
|
17
|
+
flag [:s, :source_path]
|
18
|
+
|
19
|
+
desc 'Generates a HTML overview'
|
20
|
+
command :html do |html_command|
|
21
|
+
|
22
|
+
html_command.desc 'HTML output file'
|
23
|
+
html_command.default_value 'overview.html'
|
24
|
+
html_command.arg_name 'output_file'
|
25
|
+
html_command.flag [:o, :output_file]
|
26
|
+
|
27
|
+
html_command.desc 'Link to source in web'
|
28
|
+
html_command.default_value 'file:///'
|
29
|
+
html_command.arg_name 'hyperlink'
|
30
|
+
html_command.flag [:l, :hyperlink]
|
31
|
+
|
32
|
+
html_command.action do |global_options, options, args|
|
33
|
+
|
34
|
+
verbose = !global_options[:v].nil?
|
35
|
+
source_path = global_options[:s]
|
36
|
+
html_output_path = options[:o]
|
37
|
+
hyperlink = options[:l]
|
38
|
+
|
39
|
+
unless verbose
|
40
|
+
puts "I will use following option"
|
41
|
+
puts "Global options:"
|
42
|
+
puts "-v = #{verbose}"
|
43
|
+
puts "-s = #{source_path}"
|
44
|
+
puts ""
|
45
|
+
puts "HTML command options:"
|
46
|
+
puts "-o = #{html_output_path}"
|
47
|
+
puts "-l = #{hyperlink}"
|
48
|
+
puts ""
|
49
|
+
end
|
50
|
+
|
51
|
+
Instadoc.generate_html(verbose, source_path, html_output_path, hyperlink)
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
pre do |global, command, options, args|
|
57
|
+
# Pre logic here
|
58
|
+
# Return true to proceed; false to abourt and not call the
|
59
|
+
# chosen command
|
60
|
+
# Use skips_pre before a command to skip this block
|
61
|
+
# on that command only
|
62
|
+
true
|
63
|
+
end
|
64
|
+
|
65
|
+
post do |global, command, options, args|
|
66
|
+
# Post logic here
|
67
|
+
# Use skips_post before a command to skip this
|
68
|
+
# block on that command only
|
69
|
+
end
|
70
|
+
|
71
|
+
on_error do |exception|
|
72
|
+
puts exception
|
73
|
+
true
|
74
|
+
end
|
75
|
+
|
76
|
+
exit run(ARGV)
|
data/instadoc.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# Ensure we require the local version and not one we might have installed already
|
3
|
+
require File.join([File.dirname(__FILE__), 'lib', 'instadoc', 'version.rb'])
|
4
|
+
|
5
|
+
spec = Gem::Specification.new do |gem|
|
6
|
+
gem.name = 'instadoc'
|
7
|
+
gem.version = Instadoc::VERSION
|
8
|
+
gem.platform = Gem::Platform::RUBY
|
9
|
+
gem.summary = 'A documentation generation tool for source code'
|
10
|
+
|
11
|
+
gem.author = 'Markus Hanses'
|
12
|
+
gem.email = 'me@markushanses.de'
|
13
|
+
gem.homepage = 'https://github.com/marhan/instadoc'
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($\)
|
16
|
+
gem.require_paths << 'lib'
|
17
|
+
gem.bindir = 'bin'
|
18
|
+
gem.executables << 'instadoc'
|
19
|
+
gem.test_files = gem.files.grep(%r{^(spec)/})
|
20
|
+
|
21
|
+
gem.add_development_dependency('rake', '~> 0.9')
|
22
|
+
gem.add_development_dependency('rspec', '~> 2.10')
|
23
|
+
gem.add_development_dependency('guard', '~> 1.0.0')
|
24
|
+
gem.add_development_dependency('guard-rspec', '~> 0.6.0')
|
25
|
+
gem.add_development_dependency('rdoc')
|
26
|
+
|
27
|
+
gem.add_runtime_dependency('gli', '2.2.1')
|
28
|
+
gem.add_runtime_dependency('nokogiri', '~> 1.5.5')
|
29
|
+
end
|
data/lib/instadoc.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "instadoc/version"
|
3
|
+
require "instadoc/java/java_code"
|
4
|
+
require "instadoc/config"
|
5
|
+
require "instadoc/html_builder"
|
6
|
+
require "instadoc/analyzer"
|
7
|
+
require "optparse"
|
8
|
+
|
9
|
+
module Instadoc
|
10
|
+
|
11
|
+
def Instadoc.generate_html(verbose, source_path, output_path, hyperlink)
|
12
|
+
|
13
|
+
config.verbose = verbose
|
14
|
+
config.hyperlink = hyperlink
|
15
|
+
config.input_path = Pathname.new(source_path)
|
16
|
+
|
17
|
+
File.new(output_path, 'w')
|
18
|
+
config.output_path = Pathname.new(output_path)
|
19
|
+
|
20
|
+
analyzer = Instadoc::Analyzer.new(config)
|
21
|
+
analyzer.create_documentation()
|
22
|
+
end
|
23
|
+
|
24
|
+
def Instadoc.config
|
25
|
+
@config ||= Config.new
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
module Instadoc
|
5
|
+
class Analyzer
|
6
|
+
|
7
|
+
def initialize(config = Instadoc.config)
|
8
|
+
@config = config
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_documentation()
|
12
|
+
java_files = java()
|
13
|
+
html_builder = Instadoc::HtmlBuilder.new(@config)
|
14
|
+
html_builder.create(java_files)
|
15
|
+
end
|
16
|
+
|
17
|
+
def java()
|
18
|
+
java_code = Instadoc::Java::JavaCode.new(@config)
|
19
|
+
java_code.search(@config.input_path)
|
20
|
+
java_code.files
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_file(path)
|
24
|
+
Pathname.new(File.new(path, 'w').path)
|
25
|
+
end
|
26
|
+
|
27
|
+
def validate_directory(base_dir)
|
28
|
+
unless FileTest.exists?(base_dir)
|
29
|
+
STDERR.puts "Requires a existing path! Given was => #{base_dir}"
|
30
|
+
exit false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Instadoc
|
4
|
+
class Config
|
5
|
+
|
6
|
+
attr_accessor :output_path
|
7
|
+
attr_accessor :input_path
|
8
|
+
attr_accessor :hyperlink
|
9
|
+
attr_accessor :verbose
|
10
|
+
|
11
|
+
def initialize()
|
12
|
+
@hyperlink = "PLACEHOLDER"
|
13
|
+
end
|
14
|
+
|
15
|
+
def hyperlink_for(file_name)
|
16
|
+
@hyperlink.gsub("PLACEHOLDER",file_name)
|
17
|
+
end
|
18
|
+
|
19
|
+
def open_new_file(pathname)
|
20
|
+
File.new(pathname.realpath, 'w')
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "nokogiri"
|
3
|
+
|
4
|
+
module Instadoc
|
5
|
+
class HtmlBuilder
|
6
|
+
|
7
|
+
def initialize(config)
|
8
|
+
@config = config
|
9
|
+
end
|
10
|
+
|
11
|
+
def build(files)
|
12
|
+
builder = Nokogiri::HTML::Builder.new do |doc|
|
13
|
+
doc.html {
|
14
|
+
doc.body() {
|
15
|
+
doc.table(:border => 1) {
|
16
|
+
doc.th "Documentation"
|
17
|
+
doc.th "Hyperlink to class"
|
18
|
+
doc.th "Line number"
|
19
|
+
files.each { |file|
|
20
|
+
file.documented_lines.keys.each { |line_number|
|
21
|
+
doc.tr {
|
22
|
+
doc.td_ file.documented_lines[line_number]
|
23
|
+
doc.td {
|
24
|
+
doc.a(:href => build_hyperlink(file.name_with_package)) {
|
25
|
+
doc.text file.pathname.basename
|
26
|
+
}
|
27
|
+
}
|
28
|
+
doc.td_ line_number
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
end
|
36
|
+
builder.to_html
|
37
|
+
end
|
38
|
+
|
39
|
+
def create(files, pathname = @config.output_path)
|
40
|
+
html = build(files)
|
41
|
+
write_to_file(html, pathname)
|
42
|
+
unless @config.verbose
|
43
|
+
puts "Documentation summery written to #{pathname.realpath}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def write_to_file(html, pathname)
|
48
|
+
file = @config.open_new_file(pathname)
|
49
|
+
file.puts html
|
50
|
+
file
|
51
|
+
end
|
52
|
+
|
53
|
+
def build_hyperlink(file_name)
|
54
|
+
@config.hyperlink_for(file_name)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "instadoc/java/pathname_seeker"
|
2
|
+
require "instadoc/java/java_file"
|
3
|
+
|
4
|
+
# encoding: utf-8
|
5
|
+
module Instadoc
|
6
|
+
module Java
|
7
|
+
class JavaCode
|
8
|
+
|
9
|
+
def initialize(config)
|
10
|
+
@config = config
|
11
|
+
@files = Array.new
|
12
|
+
@java_file_seeker = PathnameSeeker.new(@config)
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :files
|
16
|
+
|
17
|
+
def search(base_pathname)
|
18
|
+
path_names = @java_file_seeker.search_in(base_pathname)
|
19
|
+
@files.concat(JavaFile.create_files(@config, path_names))
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
"Instadoc::JavaCode"
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Instadoc
|
3
|
+
module Java
|
4
|
+
class JavaFile
|
5
|
+
|
6
|
+
DOC_REGEX = '@InstaDoc\(\"(.*)\"\)'
|
7
|
+
|
8
|
+
def self.create_files(config, path_names)
|
9
|
+
files = Array.new
|
10
|
+
path_names.each { |pathname|
|
11
|
+
java_file = JavaFile.new(config, pathname)
|
12
|
+
java_file.search_documentation
|
13
|
+
files << java_file
|
14
|
+
}
|
15
|
+
return files
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(config, pathname)
|
19
|
+
@config = config
|
20
|
+
@pathname = pathname
|
21
|
+
@documented_lines = Hash.new()
|
22
|
+
valid?
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_accessor :pathname
|
26
|
+
attr_accessor :documented_lines
|
27
|
+
|
28
|
+
def valid?
|
29
|
+
unless @config
|
30
|
+
raise ArgumentError, "#{self} requires a configuration"
|
31
|
+
end
|
32
|
+
unless @pathname.file?
|
33
|
+
raise ArgumentError, "#{self} requires a file Given was => #{@pathname}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
attr_reader :pathname
|
38
|
+
attr_reader :documented_lines
|
39
|
+
|
40
|
+
|
41
|
+
def search_documentation()
|
42
|
+
line_number = 0
|
43
|
+
|
44
|
+
@pathname.each_line { |line|
|
45
|
+
line_number = line_number.succ
|
46
|
+
match = line.match(DOC_REGEX)
|
47
|
+
if (match)
|
48
|
+
@documented_lines[line_number] = match[1]
|
49
|
+
end
|
50
|
+
}
|
51
|
+
|
52
|
+
return @documented_lines
|
53
|
+
end
|
54
|
+
|
55
|
+
def name()
|
56
|
+
@pathname.basename.to_s
|
57
|
+
end
|
58
|
+
|
59
|
+
def name_with_package()
|
60
|
+
@pathname.relative_path_from(@config.input_path).to_s
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Instadoc
|
3
|
+
module Java
|
4
|
+
class PathnameSeeker
|
5
|
+
|
6
|
+
def initialize(config)
|
7
|
+
@config = config
|
8
|
+
end
|
9
|
+
|
10
|
+
def search_in(base_pathname)
|
11
|
+
raise(ArgumentError, "base_pathname must not be null.") if base_pathname.nil?
|
12
|
+
|
13
|
+
path_names = Array.new
|
14
|
+
files_path = File.join(base_pathname, "**", "*.java")
|
15
|
+
Dir.glob(files_path) { |file|
|
16
|
+
path_name = Pathname.new(file).realpath
|
17
|
+
path_names << path_name
|
18
|
+
}
|
19
|
+
|
20
|
+
path_names
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Instadoc::Analyzer do
|
5
|
+
|
6
|
+
context ".validate_directory" do
|
7
|
+
|
8
|
+
let(:subject) { Instadoc::Analyzer.new() }
|
9
|
+
|
10
|
+
context "with an invalid string as path" do
|
11
|
+
|
12
|
+
it "should raise error" do
|
13
|
+
lambda { subject.validate_directory('any/path') }.should terminate.with_code(1)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context ".create_documentation" do
|
20
|
+
|
21
|
+
let(:subject) {
|
22
|
+
Instadoc::Analyzer.new(Helpers::TestConfig.new)
|
23
|
+
}
|
24
|
+
|
25
|
+
context "with an invalid string as path" do
|
26
|
+
|
27
|
+
it "should raise error" do
|
28
|
+
lambda{subject.create_documentation}.should raise_error
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Instadoc::HtmlBuilder do
|
5
|
+
|
6
|
+
context ".build" do
|
7
|
+
|
8
|
+
let(:subject) {Instadoc::HtmlBuilder.new(Helpers::TestConfig.new)}
|
9
|
+
let(:java_files) {
|
10
|
+
java_files = Array.new
|
11
|
+
|
12
|
+
java_file = Instadoc::Java::JavaFile.new(
|
13
|
+
Helpers::TestConfig.new,
|
14
|
+
Helpers::TestConfig.pathname_for_java_file("AnnotatedTestMethods.java"))
|
15
|
+
|
16
|
+
java_file.search_documentation
|
17
|
+
java_files << java_file
|
18
|
+
}
|
19
|
+
|
20
|
+
it "should contain documentation text" do
|
21
|
+
subject.build(java_files).should include("Text that documents the method number one")
|
22
|
+
subject.build(java_files).should include("Text that documents the method number two")
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
context ".write_to_file" do
|
28
|
+
|
29
|
+
let(:subject) {Instadoc::HtmlBuilder.new(Helpers::TestConfig.new)}
|
30
|
+
|
31
|
+
it "should write content to file" do
|
32
|
+
subject.write_to_file("<content/>", Pathname.new("dummy.txt")).string.should eq("<content/>\n")
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Instadoc::Java::JavaCode do
|
5
|
+
|
6
|
+
context ".search" do
|
7
|
+
|
8
|
+
context "with real test_data path" do
|
9
|
+
|
10
|
+
let(:java_code) {Instadoc::Java::JavaCode.new(Instadoc.config)}
|
11
|
+
|
12
|
+
it "should not raise error" do
|
13
|
+
lambda {java_code.search(Helpers::TestConfig.test_data_path)}.should_not raise_error(ArgumentError)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should find all classes in package" do
|
17
|
+
java_code.search(Helpers::TestConfig.test_data_path).should have(3).items
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should add all classes in package to classes variable" do
|
21
|
+
java_code.search(Helpers::TestConfig.test_data_path)
|
22
|
+
java_code.files.should have(3).items
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Instadoc::Java::JavaFile do
|
5
|
+
|
6
|
+
context ".new" do
|
7
|
+
|
8
|
+
context "with valid arguments" do
|
9
|
+
|
10
|
+
let(:pathname) { pathname = Helpers::TestConfig.pathname_for_java_file('AnnotatedTestClazz.java') }
|
11
|
+
let(:subject) { Instadoc::Java::JavaFile.new(Helpers::TestConfig.new, pathname) }
|
12
|
+
|
13
|
+
it "should set pathname" do
|
14
|
+
subject.pathname.should eq(pathname)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should set pathname" do
|
18
|
+
subject.documented_lines.should have(0).items
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "with invalid pathname" do
|
23
|
+
|
24
|
+
it "should raise error" do
|
25
|
+
lambda {
|
26
|
+
Instadoc::Java::JavaFile.new(Helpers::TestConfig.new, Pathname.new("invalid/path"))
|
27
|
+
}.should raise_error(ArgumentError)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "with missing config" do
|
32
|
+
|
33
|
+
it "should raise error" do
|
34
|
+
lambda {
|
35
|
+
Instadoc::Java::JavaFile.new(nil, Helpers::TestConfig.pathname_for_java_file('AnnotatedTestClazz.java'))
|
36
|
+
}.should raise_error(ArgumentError)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
context ".search_documentation" do
|
43
|
+
|
44
|
+
context "for AnnotatedTestClazz.java" do
|
45
|
+
|
46
|
+
let(:subject) do
|
47
|
+
pathname = Helpers::TestConfig.pathname_for_java_file('AnnotatedTestClazz.java')
|
48
|
+
subject = Instadoc::Java::JavaFile.new(Helpers::TestConfig.new, pathname)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should return one line" do
|
52
|
+
subject.search_documentation.should have(1).item
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should return annotation txt" do
|
56
|
+
subject.search_documentation.values.should include("Text that documents the code")
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should return annotation line number" do
|
60
|
+
subject.search_documentation.keys.should include(7)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should set variable documented_lines" do
|
64
|
+
subject.search_documentation.should be(subject.documented_lines)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should return name with package" do
|
68
|
+
subject.name_with_package.should eq('org/company/AnnotatedTestClazz.java')
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
context "for AnnotatedTestMethods.java" do
|
74
|
+
|
75
|
+
let(:subject) do
|
76
|
+
pathname = Helpers::TestConfig.pathname_for_java_file('AnnotatedTestMethods.java')
|
77
|
+
subject = Instadoc::Java::JavaFile.new(Helpers::TestConfig.new, pathname)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should return two lines" do
|
81
|
+
subject.search_documentation.should have(2).item
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should return annotation txt by correct line number" do
|
85
|
+
subject.search_documentation[9].should eq("Text that documents the method number one")
|
86
|
+
subject.search_documentation[12].should eq("Text that documents the method number two")
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should set variable documented_lines" do
|
90
|
+
subject.search_documentation.should be(subject.documented_lines)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "for NotAnnotatedDummy.java" do
|
95
|
+
|
96
|
+
let(:subject) do
|
97
|
+
pathname = Helpers::TestConfig.pathname_for_java_file('NotAnnotatedDummy.java')
|
98
|
+
subject = Instadoc::Java::JavaFile.new(Helpers::TestConfig.new, pathname)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should found no lines" do
|
102
|
+
subject.search_documentation.should have(0).item
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should set variable documented_lines" do
|
106
|
+
subject.documented_lines.should have(0).items
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# require application
|
4
|
+
Dir[File.join(File.dirname(__FILE__),"../lib/**/*.rb")].each { |f| require f }
|
5
|
+
# require helpers
|
6
|
+
Dir[File.join(File.dirname(__FILE__),"support/**/*.rb")].each { |f| require f }
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.include ExitCodeMatchers
|
10
|
+
end
|
11
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rspec/expectations'
|
3
|
+
|
4
|
+
module ExitCodeMatchers
|
5
|
+
extend RSpec::Matchers::DSL
|
6
|
+
|
7
|
+
matcher :terminate do
|
8
|
+
actual = nil
|
9
|
+
|
10
|
+
match do |block|
|
11
|
+
begin
|
12
|
+
block.call
|
13
|
+
rescue SystemExit => e
|
14
|
+
actual = e.status
|
15
|
+
end
|
16
|
+
actual and actual == status_code
|
17
|
+
end
|
18
|
+
|
19
|
+
chain :with_code do |status_code|
|
20
|
+
@status_code = status_code
|
21
|
+
end
|
22
|
+
|
23
|
+
failure_message_for_should do |block|
|
24
|
+
"expected block to call exit(#{status_code}) but exit" +
|
25
|
+
(actual.nil? ? " not called" : "(#{actual}) was called")
|
26
|
+
end
|
27
|
+
|
28
|
+
failure_message_for_should_not do |block|
|
29
|
+
"expected block not to call exit(#{status_code})"
|
30
|
+
end
|
31
|
+
|
32
|
+
description do
|
33
|
+
"expect block to call exit(#{status_code})"
|
34
|
+
end
|
35
|
+
|
36
|
+
def status_code
|
37
|
+
@status_code ||= 0
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Helpers
|
2
|
+
#https://gabebw.wordpress.com/2011/03/21/temp-files-in-rspec/
|
3
|
+
module UsesTempFolder
|
4
|
+
def self.included(example_group)
|
5
|
+
example_group.extend(self)
|
6
|
+
end
|
7
|
+
|
8
|
+
def in_directory_with_file(file)
|
9
|
+
before do
|
10
|
+
@pwd = Dir.pwd
|
11
|
+
@tmp_dir = File.join(File.dirname(__FILE__), 'tmp')
|
12
|
+
FileUtils.mkdir_p(@tmp_dir)
|
13
|
+
Dir.chdir(@tmp_dir)
|
14
|
+
|
15
|
+
FileUtils.mkdir_p(File.dirname(file))
|
16
|
+
FileUtils.touch(file)
|
17
|
+
end
|
18
|
+
|
19
|
+
define_method(:content_for_file) do |content|
|
20
|
+
f = File.new(File.join(@tmp_dir, file), 'a+')
|
21
|
+
f.write(content)
|
22
|
+
f.flush # VERY IMPORTANT
|
23
|
+
f.close
|
24
|
+
end
|
25
|
+
|
26
|
+
after do
|
27
|
+
Dir.chdir(@pwd)
|
28
|
+
FileUtils.rm_rf(@tmp_dir)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Helpers
|
3
|
+
|
4
|
+
class TestConfig < Instadoc::Config
|
5
|
+
|
6
|
+
def initialize()
|
7
|
+
super()
|
8
|
+
@input_path = TestConfig.test_java_code_path
|
9
|
+
end
|
10
|
+
|
11
|
+
def TestConfig.test_data_path
|
12
|
+
Pathname.new(File.join(File.dirname(__FILE__), '..', 'test_data'))
|
13
|
+
end
|
14
|
+
|
15
|
+
def TestConfig.test_java_code_path
|
16
|
+
Pathname.new(File.join(File.dirname(__FILE__), '..', 'test_data', 'java_code'))
|
17
|
+
end
|
18
|
+
|
19
|
+
def TestConfig.java_code_package_path
|
20
|
+
File.join(File.dirname(__FILE__), '..', 'test_data/java_code/org/company/')
|
21
|
+
end
|
22
|
+
|
23
|
+
def TestConfig.pathname_for_java_file(test_file)
|
24
|
+
Pathname.new(File.join(java_code_package_path, test_file))
|
25
|
+
end
|
26
|
+
|
27
|
+
def open_new_file(pathname)
|
28
|
+
StringIO.new
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
package org.company;
|
2
|
+
/**
|
3
|
+
* TestData class for annotation on methods.
|
4
|
+
*
|
5
|
+
* @author markus.hanses
|
6
|
+
*/
|
7
|
+
public class AnnotatedTestMethods {
|
8
|
+
|
9
|
+
@InstaDoc("Text that documents the method number one")
|
10
|
+
public void annotatedMethodNumberOne(){}
|
11
|
+
|
12
|
+
@InstaDoc("Text that documents the method number two")
|
13
|
+
public void annotatedMethodNumberTwo(){}
|
14
|
+
|
15
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
package org.company;
|
2
|
+
/**
|
3
|
+
* TestData class without '@JavaDoc("dummy")' annotation,
|
4
|
+
* but with some other that instadoc has to ignore.
|
5
|
+
*
|
6
|
+
* @author markus.hanses
|
7
|
+
*/
|
8
|
+
@Component
|
9
|
+
public class AnnotatedTestClazz {
|
10
|
+
|
11
|
+
@Transaction
|
12
|
+
public void anyMethod(){}
|
13
|
+
}
|
metadata
ADDED
@@ -0,0 +1,209 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: instadoc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Markus Hanses
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.9'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.9'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.10'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.10'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: guard
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.0.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.0.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: guard-rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.6.0
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.6.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rdoc
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: gli
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - '='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 2.2.1
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - '='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 2.2.1
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: nokogiri
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.5.5
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 1.5.5
|
126
|
+
description:
|
127
|
+
email: me@markushanses.de
|
128
|
+
executables:
|
129
|
+
- instadoc
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- .gitignore
|
134
|
+
- .rspec
|
135
|
+
- .rvmrc
|
136
|
+
- .travis.yml
|
137
|
+
- Changelog.md
|
138
|
+
- Gemfile
|
139
|
+
- Guardfile
|
140
|
+
- LICENSE
|
141
|
+
- README.md
|
142
|
+
- README.rdoc
|
143
|
+
- Rakefile
|
144
|
+
- bin/instadoc
|
145
|
+
- instadoc.gemspec
|
146
|
+
- lib/instadoc.rb
|
147
|
+
- lib/instadoc/analyzer.rb
|
148
|
+
- lib/instadoc/config.rb
|
149
|
+
- lib/instadoc/html_builder.rb
|
150
|
+
- lib/instadoc/java/java_code.rb
|
151
|
+
- lib/instadoc/java/java_file.rb
|
152
|
+
- lib/instadoc/java/pathname_seeker.rb
|
153
|
+
- lib/instadoc/version.rb
|
154
|
+
- spec/instadoc_toolbox/analyzer_spec.rb
|
155
|
+
- spec/instadoc_toolbox/html_builder_spec.rb
|
156
|
+
- spec/instadoc_toolbox/instadoc_spec.rb
|
157
|
+
- spec/instadoc_toolbox/java/java_code_spec.rb
|
158
|
+
- spec/instadoc_toolbox/java/java_file_spec.rb
|
159
|
+
- spec/spec_helper.rb
|
160
|
+
- spec/support/exit_code_matcher.rb
|
161
|
+
- spec/support/temp_folder_helper.rb
|
162
|
+
- spec/support/test_config_helper.rb
|
163
|
+
- spec/test_data/java_code/org/company/AnnotatedTestClazz.java
|
164
|
+
- spec/test_data/java_code/org/company/AnnotatedTestMethods.java
|
165
|
+
- spec/test_data/java_code/org/company/NotAnnotatedDummy.java
|
166
|
+
homepage: https://github.com/marhan/instadoc
|
167
|
+
licenses: []
|
168
|
+
post_install_message:
|
169
|
+
rdoc_options: []
|
170
|
+
require_paths:
|
171
|
+
- lib
|
172
|
+
- lib
|
173
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
174
|
+
none: false
|
175
|
+
requirements:
|
176
|
+
- - ! '>='
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0'
|
179
|
+
segments:
|
180
|
+
- 0
|
181
|
+
hash: -4380620093360648879
|
182
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
|
+
none: false
|
184
|
+
requirements:
|
185
|
+
- - ! '>='
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
segments:
|
189
|
+
- 0
|
190
|
+
hash: -4380620093360648879
|
191
|
+
requirements: []
|
192
|
+
rubyforge_project:
|
193
|
+
rubygems_version: 1.8.24
|
194
|
+
signing_key:
|
195
|
+
specification_version: 3
|
196
|
+
summary: A documentation generation tool for source code
|
197
|
+
test_files:
|
198
|
+
- spec/instadoc_toolbox/analyzer_spec.rb
|
199
|
+
- spec/instadoc_toolbox/html_builder_spec.rb
|
200
|
+
- spec/instadoc_toolbox/instadoc_spec.rb
|
201
|
+
- spec/instadoc_toolbox/java/java_code_spec.rb
|
202
|
+
- spec/instadoc_toolbox/java/java_file_spec.rb
|
203
|
+
- spec/spec_helper.rb
|
204
|
+
- spec/support/exit_code_matcher.rb
|
205
|
+
- spec/support/temp_folder_helper.rb
|
206
|
+
- spec/support/test_config_helper.rb
|
207
|
+
- spec/test_data/java_code/org/company/AnnotatedTestClazz.java
|
208
|
+
- spec/test_data/java_code/org/company/AnnotatedTestMethods.java
|
209
|
+
- spec/test_data/java_code/org/company/NotAnnotatedDummy.java
|