flexpmd 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source :rubygems
2
+
3
+ gem 'sprout', '>= 1.1.15.pre'
4
+
5
+ group :development do
6
+ gem 'rake'
7
+ gem 'shoulda'
8
+ gem 'mocha'
9
+ end
10
+
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ archive-tar-minitar (0.5.2)
5
+ mocha (0.9.12)
6
+ open4 (1.1.0)
7
+ rake (0.9.2)
8
+ rubyzip (0.9.4)
9
+ shoulda (2.11.3)
10
+ sprout (1.1.15.pre)
11
+ archive-tar-minitar (= 0.5.2)
12
+ bundler (>= 0.9.19)
13
+ open4 (>= 0.9.6)
14
+ rake (>= 0.9.2)
15
+ rubyzip (= 0.9.4)
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ mocha
22
+ rake
23
+ shoulda
24
+ sprout (>= 1.1.15.pre)
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # The FlexPMD Sprout Gem
2
+
3
+ This [RubyGem](http://docs.rubygems.org/read/book/7) contains a rake task to add support for [FlexPMD](http://opensource.adobe.com/wiki/display/flexpmd/FlexPMD) in [Project Sprouts](http://projectsprouts.org).
4
+
5
+ Functionality is only tested on OSX, it is *not expected* to work on Windows. You may be ok on Linux.
6
+
7
+ ## Install
8
+
9
+ git clone [this repo]
10
+ cd sprout-flexpmd
11
+ bundle install
12
+ gem build flexpmd.gemspec
13
+ gem install flexpmd
14
+
15
+ #### Or
16
+
17
+ gem install flexpmd
18
+
19
+ ## Usage
20
+
21
+ Add the following to your rake file
22
+
23
+ desc "Use FlexPMD to audit source code"
24
+ flexpmd 'report/pmd' do |t|
25
+ t.src = 'src'
26
+ end
27
+
28
+ desc "Use FlexCPD to detect copy pasted code"
29
+ flexcpd 'report/cpd.xml' do |t|
30
+ t.src = 'src'
31
+ t.minimum_tokens = 50
32
+ end
33
+
34
+ desc "Use FlexMetrics to generate code metrics for this project"
35
+ flexmetrics 'report/metrics.xml' do |t|
36
+ t.src = 'src'
37
+ end
38
+
39
+ task :audit => ['report/pmd', 'report/cpd.xml', 'report/metrics.xml']
40
+
41
+ Then invoke it with
42
+
43
+ rake audit
44
+
45
+ Output can be found in the `report/` directory created in the project root. This is best consumed via the relevant [Jenkins](http://jenkins-ci.org/) plugins.
46
+
47
+ ## MIT License
48
+
49
+ Copyright 2011 Simon Gregory
50
+
51
+ Permission is hereby granted, free of charge, to any person obtaining
52
+ a copy of this software and associated documentation files (the
53
+ 'Software'), to deal in the Software without restriction, including
54
+ without limitation the rights to use, copy, modify, merge, publish,
55
+ distribute, sublicense, and/or sell copies of the Software, and to
56
+ permit persons to whom the Software is furnished to do so, subject to
57
+ the following conditions:
58
+
59
+ The above copyright notice and this permission notice shall be
60
+ included in all copies or substantial portions of the Software.
61
+
62
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
63
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
64
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
65
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
66
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
67
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
68
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ lib = File.expand_path('lib', File.dirname(__FILE__))
2
+ $:.unshift lib unless $:.include?(lib)
3
+
4
+ require 'rubygems'
5
+ require 'rake'
6
+ require 'rake/clean'
7
+ require 'rake/testtask'
8
+ require 'flexpmd'
9
+
10
+ #############################################################################
11
+ #
12
+ # Standard tasks
13
+ #
14
+ #############################################################################
15
+
16
+ Rake::TestTask.new(:test) do |t|
17
+ t.libs << "test/unit"
18
+ t.test_files = FileList["test/unit/*_test.rb"]
19
+ t.verbose = true
20
+ end
21
+
22
+ CLEAN.add '*.gem'
23
+
24
+ #############################################################################
25
+ #
26
+ # Packaging tasks
27
+ #
28
+ #############################################################################
29
+
30
+ task :release do
31
+ puts ""
32
+ print "Are you sure you want to relase FlexPMD #{FlexPMD::VERSION}? [y/N] "
33
+ exit unless STDIN.gets.index(/y/i) == 0
34
+
35
+ unless `git branch` =~ /^\* master$/
36
+ puts "You must be on the master branch to release!"
37
+ exit!
38
+ end
39
+
40
+ # Build gem and upload
41
+ sh "gem build flexpmd.gemspec"
42
+ sh "gem push flexpmd-#{FlexPMD::VERSION}.gem"
43
+ sh "rm flexpmd-#{FlexPMD::VERSION}.gem"
44
+
45
+ # Commit
46
+ sh "git commit --allow-empty -a -m 'v#{FlexPMD::VERSION}'"
47
+ sh "git tag v#{FlexPMD::VERSION}"
48
+ sh "git push origin master"
49
+ sh "git push origin v#{FlexPMD::VERSION}"
50
+ end
@@ -0,0 +1,55 @@
1
+ module Sprout::System
2
+
3
+ ##
4
+ # Monkey patch the base system so we control the output to stderr.
5
+ #
6
+ class BaseSystem
7
+
8
+ ##
9
+ # Creates a new process, executes the command
10
+ # and returns whatever the process wrote to stdout, or stderr.
11
+ #
12
+ def execute(tool, options='')
13
+ Sprout.stdout.puts("#{tool} #{options}")
14
+ runner = get_and_execute_process_runner(tool, options)
15
+ error = runner.read_err
16
+ result = runner.read
17
+
18
+ if(result.size > 0)
19
+ Sprout.stdout.puts result
20
+ end
21
+
22
+ if(error.size > 0)
23
+ # We expect the process to write to stderror so simply print it, we don't want Sprouts
24
+ # to stop executing.
25
+ Sprout.stdout.puts error
26
+ end
27
+
28
+ result || error
29
+ end
30
+
31
+ end
32
+
33
+ ##
34
+ # Monkey patch the unix system so we can run tool with 'java -jar'.
35
+ #
36
+ class UnixSystem < BaseSystem
37
+
38
+ ##
39
+ # Get a process runner and execute the provided +executable+,
40
+ # with the provided +options+.
41
+ #
42
+ # +executable+ String path to the external executable file.
43
+ #
44
+ # +options+ String commandline options to send to the +executable+.
45
+ #
46
+ def get_and_execute_process_runner tool, options=nil
47
+ runner = get_process_runner
48
+ raise Sprout::Errors::ExecutionError.new("[ERROR] Java is required for this tool to run.") unless `which java` =~ /java$/
49
+ runner.execute_open4 "java -Xms64m -Xmx768m -jar "+ clean_path(tool), options
50
+ runner
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,52 @@
1
+ module FlexPMD
2
+
3
+ ##
4
+ # Flex Copy and Paste Detector
5
+ #
6
+ # (-s|--sourceDirectory) <sourceDirectory>
7
+ # (-o|--outputFile) <outputFile>
8
+ # [(-m|--minimumTokens) <minimumTokens>]]
9
+ #
10
+ class FCPD < Sprout::Executable::Base
11
+
12
+ ##
13
+ # The source directory to recursively audit
14
+ #
15
+ add_param :source_directory, Path, { :required => true, :shell_name => '-s' }
16
+
17
+ add_param_alias :s, :source_directory
18
+
19
+ add_param_alias :src, :source_directory
20
+
21
+ ##
22
+ # The file to output results to.
23
+ #
24
+ add_param :output_file, File, { :shell_name => '-o', :file_task_name => true }
25
+
26
+ add_param_alias :o, :output_file
27
+
28
+ add_param_alias :output, :output_file
29
+
30
+ ##
31
+ # The minmum length of matched portions of code. A token roughly translates to a word,
32
+ # method name, operator etc. As this is subjective experiment to find a useful value. 50 to
33
+ # 100 is a reasonable starting point, the lower the better.
34
+ #
35
+ add_param :minimum_tokens, Number, { :shell_name => '-m' }
36
+
37
+ add_param_alias :m, :minimum_tokens
38
+
39
+ ##
40
+ # The default executable target.
41
+ #
42
+ set :executable, :flexcpd
43
+
44
+ end
45
+
46
+ end
47
+
48
+ def flexcpd *args, &block
49
+ exe = FlexPMD::FCPD.new
50
+ exe.to_rake(*args, &block)
51
+ exe
52
+ end
@@ -0,0 +1,38 @@
1
+ module FlexPMD
2
+
3
+ ##
4
+ # FlexMetrics API
5
+ #
6
+ # (-s|--sourceDirectory) <sourceDirectory>
7
+ # (-o|--outputDirectory) <outputDirectory>
8
+ #
9
+ class FlexMetrics < Sprout::Executable::Base
10
+
11
+ ##
12
+ # The source path to run flexpmd against.
13
+ add_param :source_directory, Path, { :required => true, :shell_name => '-s' }
14
+
15
+ add_param_alias :s, :source_directory
16
+
17
+ add_param_alias :src, :source_directory
18
+
19
+ add_param :output_directory, File, { :shell_name => '-o', :file_task_name => true }
20
+
21
+ add_param_alias :o, :output_directory
22
+
23
+ add_param_alias :output, :output_directory
24
+
25
+ ##
26
+ # The default executable target.
27
+ #
28
+ set :executable, :flexmetrics
29
+
30
+ end
31
+
32
+ end
33
+
34
+ def flexmetrics *args, &block
35
+ exe = FlexPMD::FlexMetrics.new
36
+ exe.to_rake(*args, &block)
37
+ exe
38
+ end
@@ -0,0 +1,48 @@
1
+ module FlexPMD
2
+
3
+ ##
4
+ # FlexPMD API
5
+ #
6
+ # (-s|--sourceDirectory) <sourceDirectory>
7
+ # (-o|--outputDirectory) <outputDirectory>
8
+ #[(-r|--ruleSet) <ruleSet>]
9
+ #[(-e|--excludePackage) <excludePackage>]
10
+ #
11
+ class FPMD < Sprout::Executable::Base
12
+
13
+ ##
14
+ # The source path to run flexpmd against.
15
+ add_param :source_directory, Path, { :required => true, :shell_name => '-s' }
16
+
17
+ add_param_alias :s, :source_directory
18
+
19
+ add_param_alias :src, :source_directory
20
+
21
+ add_param :output_directory, File, { :shell_name => '-o', :file_task_name => true }
22
+
23
+ add_param_alias :o, :output_directory
24
+
25
+ add_param_alias :output, :output_directory
26
+
27
+ add_param :rule_set, File, { :shell_name => '-r' }
28
+
29
+ add_param_alias :r, :rule_set
30
+
31
+ add_param :exclude_package, String, { :shell_name => '-e' }
32
+
33
+ add_param_alias :e, :exclude_package
34
+
35
+ ##
36
+ # The default executable target.
37
+ #
38
+ set :executable, :flexpmd
39
+
40
+ end
41
+
42
+ end
43
+
44
+ def flexpmd *args, &block
45
+ exe = FlexPMD::FPMD.new
46
+ exe.to_rake(*args, &block)
47
+ exe
48
+ end
data/lib/flexpmd.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'sprout'
2
+
3
+ require 'flexpmd/pmd'
4
+ require 'flexpmd/cpd'
5
+ require 'flexpmd/metrics'
6
+ require 'flexpmd/base'
7
+
8
+ module FlexPMD
9
+ NAME = 'flexpmd'
10
+ JAR_VERSION = '1.2'
11
+ VERSION = "#{JAR_VERSION}.1"
12
+ MD5 = 'efd3fa459788fa3d32837628dc82e264'
13
+ ZIP = 'http://opensource.adobe.com/svn/opensource/flexpmd/maven-repository/release/com/adobe/ac/flex-pmd/1.2/flex-pmd-all-in-one-bundle-1.2.zip'
14
+ end
15
+
16
+ Sprout::Specification.new do |s|
17
+
18
+ s.name = FlexPMD::NAME
19
+ s.version = FlexPMD::JAR_VERSION
20
+
21
+ s.add_remote_file_target do |t|
22
+ t.platform = :universal
23
+ t.archive_type = :zip
24
+ t.url = FlexPMD::ZIP
25
+ t.md5 = FlexPMD::MD5
26
+ t.add_executable :flexpmd, "flex-pmd-command-line-#{FlexPMD::JAR_VERSION}.jar"
27
+ t.add_executable :flexcpd, "flex-pmd-cpd-command-line-#{FlexPMD::JAR_VERSION}.jar"
28
+ t.add_executable :flexmetrics, "flex-pmd-metrics-command-line-#{FlexPMD::JAR_VERSION}.jar"
29
+ end
30
+ end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ class FlexPMDTest < Test::Unit::TestCase
4
+ include Sprout::TestHelper
5
+
6
+ context "A FlexPMD tool" do
7
+
8
+ setup do
9
+ @fixture = File.join fixtures, 'flexpmd', 'tmp'
10
+ FileUtils.makedirs @fixture
11
+ @ruleset = File.join @fixture, 'ruleset.xml'
12
+ end
13
+
14
+ teardown do
15
+ remove_file @fixture
16
+ end
17
+
18
+ should "accept input" do
19
+ fpmd = FlexPMD::FPMD.new
20
+ fpmd.src = @fixture
21
+ fpmd.output = @app_desc
22
+ fpmd.rule_set = Dir.pwd
23
+
24
+ assert_equal "-s=#{@fixture} -r=#{Dir.pwd}", fpmd.to_shell
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,21 @@
1
+ require "rubygems"
2
+ require "bundler"
3
+ Bundler.require :default, :development
4
+
5
+ # These require statments *must* be in this order:
6
+ # http://bit.ly/bCC0Ew
7
+ # Somewhat surprised they're not being required by Bundler...
8
+ require 'shoulda'
9
+ require 'mocha'
10
+
11
+ lib = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
12
+ $:.unshift lib unless $:.include? lib
13
+
14
+ test = File.expand_path(File.join(File.dirname(__FILE__), '..'))
15
+ $:.unshift test unless $:.include? test
16
+
17
+ require 'sprout'
18
+ require 'sprout/test_helper'
19
+
20
+ require 'flexpmd'
21
+
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flexpmd
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.2.1
6
+ platform: ruby
7
+ authors:
8
+ - Simon Gregory
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-06-26 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: sprout
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.1.15.pre
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake
28
+ requirement: &id002 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: shoulda
39
+ requirement: &id003 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: mocha
50
+ requirement: &id004 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *id004
59
+ description: Project Sprouts support for FlexPMD
60
+ email: projectsprouts@googlegroups.com
61
+ executables: []
62
+
63
+ extensions: []
64
+
65
+ extra_rdoc_files: []
66
+
67
+ files:
68
+ - Gemfile
69
+ - Gemfile.lock
70
+ - lib/flexpmd/base.rb
71
+ - lib/flexpmd/cpd.rb
72
+ - lib/flexpmd/metrics.rb
73
+ - lib/flexpmd/pmd.rb
74
+ - lib/flexpmd.rb
75
+ - Rakefile
76
+ - README.md
77
+ - test/unit/flexpmd_test.rb
78
+ - test/unit/test_helper.rb
79
+ homepage: http://projectsprouts.org
80
+ licenses: []
81
+
82
+ post_install_message:
83
+ rdoc_options: []
84
+
85
+ require_paths:
86
+ - lib
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 73980266876539591
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 1.3.6
103
+ requirements: []
104
+
105
+ rubyforge_project:
106
+ rubygems_version: 1.8.5
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: Code auditing for ActionScript and Flex
110
+ test_files: []
111
+