mvnizer 0.0.1 → 0.0.2

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.
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ module Mvnizer
5
+ module Command
6
+ describe NewProject do
7
+ let(:options) { { name: "foobar", group_id: "com.example", version: "1.0.0", type: "jar" } }
8
+ let(:project) { Mvnizer::Project.new(nil, "foobar", nil, nil) }
9
+
10
+ let(:generator) { double("generator") }
11
+ let(:coordinate_parser) { double("coordinate_parser") }
12
+ let(:dir_creator) { double("dir_creator") }
13
+ subject { Mvnizer::Command::NewProject.new(generator, dir_creator, coordinate_parser) }
14
+
15
+ before do
16
+ FakeFS.activate!
17
+ FileUtils.mkdir_p("foobar")
18
+ end
19
+
20
+ it "reads the configuration" do
21
+ generator.should_receive(:generate)
22
+ coordinate_parser.should_receive(:parse).and_return(project)
23
+ dir_creator.should_receive(:create)
24
+ subject.should_receive(:conf).with(options).and_return(options)
25
+
26
+ subject.run(options)
27
+ end
28
+
29
+ it "creates a project from the provided coordinates" do
30
+ o = { name: "foobar"}
31
+
32
+ subject.should_receive(:conf).with(o).and_return(options)
33
+ generator.should_receive(:generate)
34
+ dir_creator.should_receive(:create)
35
+
36
+ p = Mvnizer::Project.new("group", "foobar", "version", "type")
37
+ coordinate_parser.should_receive(:parse).with("foobar").and_return(p)
38
+
39
+ subject.run(o)
40
+ end
41
+
42
+ it "creates the project directory" do
43
+ subject.should_receive(:conf).with(options).and_return(options)
44
+ coordinate_parser.should_receive(:parse).and_return(project)
45
+ generator.should_receive(:generate)
46
+ dir_creator.should_receive(:create).with("foobar/src/main/java", "foobar/src/test/java")
47
+
48
+ subject.run(options)
49
+ end
50
+
51
+ it "generates the pom file" do
52
+ p = Mvnizer::Project.new("com.example", "foobar", "1.0.0-SNAPSHOT", "war")
53
+
54
+ subject.should_receive(:conf).with(options).and_return(options)
55
+ coordinate_parser.should_receive(:parse).and_return(p)
56
+ generator.should_receive(:generate).with(p)
57
+ dir_creator.should_receive(:create)
58
+ subject.run(options)
59
+
60
+ File.exists?("foobar/pom.xml").should be_true
61
+ end
62
+
63
+ after do
64
+ FileUtils.rm_rf("foobar")
65
+ FakeFS.deactivate!
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+ require 'mvnizer/commands/new_war_project'
3
+
4
+ module Mvnizer
5
+ module Command
6
+ describe NewWarProject do
7
+
8
+ let(:project) { Mvnizer::Project.new(nil, "foobar", nil, nil) }
9
+ let(:generator) { double("generator") }
10
+ let(:coordinate_parser) { double("coordinate_parser") }
11
+ let(:dir_creator) { double("dir_creator") }
12
+
13
+ subject { Mvnizer::Command::NewWarProject.new(generator, dir_creator, coordinate_parser) }
14
+
15
+ before do
16
+ $run = false
17
+ class NewProject
18
+ alias old_run run
19
+ def run(options)
20
+ $run = true
21
+ end
22
+ end
23
+
24
+ subject.instance_variable_set(:@project, project)
25
+ FakeFS.activate!
26
+ FileUtils.mkdir_p("foobar")
27
+
28
+ templates_dir = File.join(File.dirname(__FILE__), '..', '..', 'lib', 'mvnizer', 'templates')
29
+ FileUtils.mkdir_p(templates_dir)
30
+ FileUtils.touch(File.join(templates_dir, "web.xml.erb"))
31
+ end
32
+
33
+ it "creates a basic project" do
34
+ options = {}
35
+ dir_creator.should_receive(:create)
36
+ subject.run(options)
37
+ $run.should be_true
38
+ end
39
+
40
+ it "creates the webapp directory" do
41
+ options = {name: "foobar"}
42
+ dir_creator.should_receive(:create).with("foobar/src/main/webapp/WEB-INF")
43
+ subject.run(options)
44
+ end
45
+
46
+ it "generates the web.xml file" do
47
+ options = {name: "foobar"}
48
+ dir_creator.should_receive(:create)
49
+
50
+ subject.run(options)
51
+ File.exists?("foobar/src/main/webapp/WEB-INF/web.xml").should be_true
52
+ end
53
+
54
+ after do
55
+ FileUtils.rm_rf("foobar")
56
+ FakeFS.deactivate!
57
+ class NewProject
58
+ alias run old_run
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ module Mvnizer
5
+ module Command
6
+ describe ProjectFactory do
7
+ it "returns an instance of NewProject when passing jar" do
8
+ ProjectFactory.create("jar").should be_a(NewProject)
9
+ ProjectFactory.create("jar").should_not be_a(NewWarProject)
10
+ end
11
+
12
+ it "returns an instance of NewWarProject when passing war" do
13
+ ProjectFactory.create("war").should be_a(NewWarProject)
14
+ end
15
+
16
+ it "throws an error when unknown type is passed" do
17
+ lambda { ProjectFactory.create("foo") }.should raise_error(ArgumentError, "Don’t know how to create foo.")
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,28 +1,28 @@
1
- require 'spec_helper'
2
-
3
- describe Mvnizer::Configuration do
4
- include Mvnizer::Configuration
5
- let (:conf_path) { File.join(File.dirname(__FILE__), '..', 'conf', 'default.yml') }
6
-
7
- it "loads configuration from default.yml" do
8
- YAML.should_receive(:load_file).with(be_same_path_as(conf_path)).and_return({ foo: "bar" })
9
-
10
- config = conf(Hash.new)
11
- config[:foo].should == "bar"
12
- end
13
-
14
- it "should replace default values" do
15
- YAML.should_receive(:load_file).with(be_same_path_as(conf_path)).and_return({ foo: "bar" })
16
-
17
- config = conf({ foo: "qux", baz: "buz" })
18
- config[:foo].should == "qux"
19
- config[:baz].should == "buz"
20
- end
21
-
22
- it "should symbolize configuration keys" do
23
- YAML.should_receive(:load_file).with(be_same_path_as(conf_path)).and_return({ "foo" => "bar" })
24
-
25
- config = conf(Hash.new)
26
- config[:foo].should == "bar"
27
- end
28
- end
1
+ require 'spec_helper'
2
+
3
+ describe Mvnizer::Configuration do
4
+ include Mvnizer::Configuration
5
+ let (:conf_path) { File.join(File.dirname(__FILE__), '..', 'conf', 'default.yml') }
6
+
7
+ it "loads configuration from default.yml" do
8
+ YAML.should_receive(:load_file).with(be_same_path_as(conf_path)).and_return({ foo: "bar" })
9
+
10
+ config = conf(Hash.new)
11
+ config[:foo].should == "bar"
12
+ end
13
+
14
+ it "should replace default values" do
15
+ YAML.should_receive(:load_file).with(be_same_path_as(conf_path)).and_return({ foo: "bar" })
16
+
17
+ config = conf({ foo: "qux", baz: "buz" })
18
+ config[:foo].should == "qux"
19
+ config[:baz].should == "buz"
20
+ end
21
+
22
+ it "should symbolize configuration keys" do
23
+ YAML.should_receive(:load_file).with(be_same_path_as(conf_path)).and_return({ "foo" => "bar" })
24
+
25
+ config = conf(Hash.new)
26
+ config[:foo].should == "bar"
27
+ end
28
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mvnizer::CoordinateParser do
4
+ subject { Mvnizer::CoordinateParser.new }
5
+
6
+ it "can read the project name" do
7
+ project = subject.parse("name")
8
+ project.artifact_id.should == "name"
9
+ end
10
+
11
+ it "can read the group and artifact ids" do
12
+ project = subject.parse("com.example:name")
13
+ project.artifact_id.should == "name"
14
+ project.group_id.should == "com.example"
15
+ end
16
+
17
+ it "can read the group and artifact ids and version and type" do
18
+ project = subject.parse("com.example:name:1.0.0-rc2:war")
19
+ project.artifact_id.should == "name"
20
+ project.group_id.should == "com.example"
21
+ project.version.should == "1.0.0-rc2"
22
+ project.type.should == "war"
23
+ end
24
+
25
+ it "can read the group and artifact ids and version" do
26
+ project = subject.parse("com.example:name:1.0.0-rc2")
27
+ project.artifact_id.should == "name"
28
+ project.group_id.should == "com.example"
29
+ project.version.should == "1.0.0-rc2"
30
+ end
31
+
32
+ it "can read the artifact id and version" do
33
+ project = subject.parse("name:1.0.0-SNAPSHOT")
34
+ project.artifact_id.should == "name"
35
+ project.version.should == "1.0.0-SNAPSHOT"
36
+ end
37
+
38
+ it "can read the artifact id and type" do
39
+ project = subject.parse("name:jar")
40
+ project.artifact_id.should == "name"
41
+ project.type.should == "jar"
42
+ end
43
+
44
+ it "can read the artifact id, version and type" do
45
+ project = subject.parse("name:1.0.0-rc2:war")
46
+ project.artifact_id.should == "name"
47
+ project.version.should == "1.0.0-rc2"
48
+ project.type.should == "war"
49
+ end
50
+
51
+ it "can parse the scope" do
52
+ project = subject.parse_scoped_coordinates("name:1.0.0-rc2:war:runtime")
53
+ project.artifact_id.should == "name"
54
+ project.scope.should == "runtime"
55
+
56
+ project = subject.parse_scoped_coordinates("com.weblogism:name:1.0.0-rc2:jar:runtime")
57
+ project.artifact_id.should == "name"
58
+ project.scope.should == "runtime"
59
+ end
60
+
61
+ it "can parse the junit dependency" do
62
+ project = subject.parse_scoped_coordinates("junit:junit:4.10:jar:test")
63
+ project.group_id.should == "junit"
64
+ project.artifact_id.should == "junit"
65
+ project.version.should == "4.10"
66
+ project.type.should == "jar"
67
+ project.scope.should == "test"
68
+ end
69
+ end
@@ -1,17 +1,17 @@
1
- require 'spec_helper'
2
- require 'fileutils'
3
-
4
- describe Mvnizer::DirCreator do
5
- subject { Mvnizer::DirCreator.new }
6
- # Make use of fakefs explicit by using activate! / deactivate!
7
- before { FakeFS.activate! }
8
-
9
- it "creates a list of directories" do
10
- subject.create("/tmp/blah/blah", "/tmp/foo/bar")
11
- Dir.exists?("/tmp/blah/blah").should == true
12
- Dir.exists?("/tmp/foo/bar").should == true
13
- end
14
-
15
- after { FakeFS.deactivate! }
16
- # after { ["/tmp/blah", "/tmp/foo"].each { |d| FileUtils.rm_rf(d) } }
17
- end
1
+ require 'spec_helper'
2
+ require 'fileutils'
3
+
4
+ describe Mvnizer::DirCreator do
5
+ subject { Mvnizer::DirCreator.new }
6
+ # Make use of fakefs explicit by using activate! / deactivate!
7
+ before { FakeFS.activate! }
8
+
9
+ it "creates a list of directories" do
10
+ subject.create("/tmp/blah/blah", "/tmp/foo/bar")
11
+ Dir.exists?("/tmp/blah/blah").should == true
12
+ Dir.exists?("/tmp/foo/bar").should == true
13
+ end
14
+
15
+ after { FakeFS.deactivate! }
16
+ # after { ["/tmp/blah", "/tmp/foo"].each { |d| FileUtils.rm_rf(d) } }
17
+ end
@@ -1,19 +1,46 @@
1
- require 'spec_helper'
2
- require 'nokogiri'
3
-
4
- describe Mvnizer::PomGenerator do
5
- subject { Mvnizer::PomGenerator.new }
6
-
7
- it "generates a pom" do
8
- options = { group_id: "test", version: "1.0.0-SNAPSHOT", name: "mvnizer" }
9
- output = subject.generate(options)
10
-
11
- # TODO: Ain't that a bit overkill for test?
12
- doc = Nokogiri::XML(output)
13
- doc.remove_namespaces!
14
- doc.xpath("/project/groupId").first.text().should == "test"
15
- doc.xpath("/project/artifactId").first.text().should == "mvnizer"
16
- doc.xpath("/project/version").first.text().should == "1.0.0-SNAPSHOT"
17
- doc.xpath("/project/name").first.text().should == "mvnizer"
18
- end
19
- end
1
+ require 'spec_helper'
2
+ require 'nokogiri'
3
+
4
+ # TODO Refactor when dealing with packaging-specific tasks.
5
+ module Mvnizer
6
+ describe PomGenerator do
7
+
8
+ let (:project) { Mvnizer::Project.new("test", "mvnizer", "1.0.0-SNAPSHOT", "jar")}
9
+ subject { Mvnizer::PomGenerator.new }
10
+
11
+ it "generates a pom" do
12
+ output = subject.generate(project)
13
+
14
+ # TODO: Ain't that a bit overkill for test?
15
+ doc = Nokogiri::XML(output)
16
+ doc.remove_namespaces!
17
+ doc.xpath("/project/groupId").first.text().should == "test"
18
+ doc.xpath("/project/artifactId").first.text().should == "mvnizer"
19
+ doc.xpath("/project/version").first.text().should == "1.0.0-SNAPSHOT"
20
+ doc.xpath("/project/name").first.text().should == "mvnizer"
21
+ doc.xpath("/project/packaging").first.should be_nil
22
+ end
23
+
24
+ it "adds the packaging when the type is not jar" do
25
+ project = Mvnizer::Project.new("test", "mvnizer", "1.0.0", "war")
26
+ output = subject.generate(project)
27
+
28
+ doc = Nokogiri::XML(output)
29
+ doc.remove_namespaces!
30
+ doc.xpath("/project/packaging").first.text().should == "war"
31
+ end
32
+
33
+ it "adds the dependencies" do
34
+ dependency = Mvnizer::Project.new("junit", "junit", "4.8.2", "jar", [], "test")
35
+ project.add_dependency(dependency)
36
+ output = subject.generate(project)
37
+
38
+ doc = Nokogiri::XML(output)
39
+ doc.remove_namespaces!
40
+ doc.xpath("/project/dependencies/dependency/groupId").first.text().should == "junit"
41
+ doc.xpath("/project/dependencies/dependency/artifactId").first.text().should == "junit"
42
+ doc.xpath("/project/dependencies/dependency/version").first.text().should == "4.8.2"
43
+ doc.xpath("/project/dependencies/dependency/scope").first.text().should == "test"
44
+ end
45
+ end
46
+ end
data/spec/mvnize_spec.rb CHANGED
@@ -1,37 +1,51 @@
1
- require 'spec_helper'
2
-
3
- describe Mvnizer::Mvnize do
4
- let(:generator) { double("generator") }
5
- subject { Mvnizer::Mvnize.new(generator) }
6
-
7
- before { FakeFS.activate! }
8
-
9
- it "reads the configuration" do
10
- options = { name: "foobar" }
11
- generator.should_receive(:generate)
12
- subject.should_receive(:conf).with(options).and_return(options)
13
-
14
- subject.run(options)
15
- end
16
-
17
- it "creates the project directory" do
18
- options = { name: "foobar" }
19
- subject.should_receive(:conf).with(options).and_return(options)
20
- generator.should_receive(:generate)
21
- subject.run(options)
22
-
23
- File.exists?("foobar/src/main/java").should be_true
24
- File.exists?("foobar/src/test/java").should be_true
25
- end
26
-
27
- it "generates the pom file" do
28
- options = { name: "foobar" }
29
- subject.should_receive(:conf).with(options).and_return(options)
30
- generator.should_receive(:generate).with(options)
31
- subject.run(options)
32
-
33
- File.exists?("foobar/pom.xml").should be_true
34
- end
35
-
36
- after { FakeFS.deactivate! }
37
- end
1
+ require 'spec_helper'
2
+
3
+ module Mvnizer
4
+ describe Mvnize do
5
+
6
+ let (:new_project) { double("new_project") }
7
+ subject { Mvnizer::Mvnize.new }
8
+
9
+ it "chooses what command to run depending on the options" do
10
+ options = {name: "quxbaz", command: "new"}
11
+ Command::ProjectFactory.should_receive(:create).and_return(new_project)
12
+ new_project.should_receive(:run).with(options)
13
+ subject.run(options)
14
+ end
15
+
16
+ it "throws an error when no name is given" do
17
+ lambda { subject.run(Hash.new) }.should raise_error(ArgumentError, "Please give a name to the project.")
18
+ end
19
+
20
+ it "displays a success message when done" do
21
+ Command::ProjectFactory.should_receive(:create).and_return(new_project)
22
+ new_project.should_receive(:run)
23
+ # For some obscure reason, this does not work:
24
+ # $stdout.should_receive(:write).with("Project created successfully.")
25
+ # It fails properly when message is incorrect:
26
+ # #<IO:0x774d4142> received :write with unexpected arguments
27
+ # expected: ("success")
28
+ # got: ("Project created successfully.")
29
+ # But throws an error when the message is correct:
30
+ # undefined method `write' for #<IO:fd 1>
31
+ # So instead, I have to resort to adding an `out` instance variable in Mvnize:
32
+ string_io = StringIO.new
33
+ subject.out = string_io
34
+
35
+ subject.run(name: "quxbaz", command: "new")
36
+ string_io.string.should match(/success/i)
37
+ end
38
+
39
+ it "performs war tasks if name ends with :war" do
40
+ options = {name: "quxbaz:war", command: "new"}
41
+ Command::ProjectFactory.should_receive(:create).with("war").and_return(new_project)
42
+ new_project.should_receive(:run).with(options)
43
+ subject.run(options)
44
+ end
45
+
46
+ it "throws an error if the command to run is not valid" do
47
+ lambda { subject.run(name: "quxbaz", command: "foobar") }.should raise_error(ArgumentError, "foobar is not a valid command.")
48
+ end
49
+
50
+ end
51
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,11 @@
1
- $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
2
- require 'mvnizer'
3
- require 'rspec/mocks'
4
- require 'rspec/expectations'
5
- require 'fakefs/safe'
6
-
7
- RSpec::Matchers.define :be_same_path_as do |expected|
8
- match do |actual|
9
- Pathname.new(expected).cleanpath == Pathname.new(actual).cleanpath
10
- end
11
- end
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
2
+ require 'mvnizer'
3
+ require 'rspec/mocks'
4
+ require 'rspec/expectations'
5
+ require 'fakefs/safe'
6
+
7
+ RSpec::Matchers.define :be_same_path_as do |expected|
8
+ match do |actual|
9
+ Pathname.new(expected).cleanpath == Pathname.new(actual).cleanpath
10
+ end
11
+ end
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: mvnizer
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sébastien Le Callonnec
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-13 00:00:00.000000000 Z
12
+ date: 2012-09-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -106,18 +106,34 @@ files:
106
106
  - LICENSE.txt
107
107
  - README.md
108
108
  - Rakefile
109
+ - TODO.md
109
110
  - bin/mvnizer
110
111
  - conf/default.yml
111
112
  - lib/mvnizer.rb
113
+ - lib/mvnizer/commands.rb
114
+ - lib/mvnizer/commands/new_project.rb
115
+ - lib/mvnizer/commands/new_war_project.rb
116
+ - lib/mvnizer/commands/project_factory.rb
112
117
  - lib/mvnizer/configuration.rb
118
+ - lib/mvnizer/coordinate_parser.rb
113
119
  - lib/mvnizer/dir_creator.rb
120
+ - lib/mvnizer/erb_helper.rb
114
121
  - lib/mvnizer/mvnize.rb
115
122
  - lib/mvnizer/pom_generator.rb
116
123
  - lib/mvnizer/project.rb
124
+ - lib/mvnizer/templates/_dependency.xml.erb
117
125
  - lib/mvnizer/templates/pom.xml.erb
126
+ - lib/mvnizer/templates/web.xml.erb
118
127
  - lib/mvnizer/version.rb
119
128
  - mvnizer.gemspec
129
+ - ragel/coordinate.rb
130
+ - ragel/coordinate.rl
131
+ - ragel/test_coord.rb
132
+ - spec/commands/new_project_spec.rb
133
+ - spec/commands/new_war_project_spec.rb
134
+ - spec/commands/project_factory_spec.rb
120
135
  - spec/configuration_spec.rb
136
+ - spec/coordinate_parser_spec.rb
121
137
  - spec/dir_creator_spec.rb
122
138
  - spec/generator_spec.rb
123
139
  - spec/mvnize_spec.rb
@@ -133,11 +149,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
149
  requirements:
134
150
  - - ! '>='
135
151
  - !ruby/object:Gem::Version
136
- version: !binary |-
137
- MA==
138
152
  segments:
139
153
  - 0
140
154
  hash: 2
155
+ version: !binary |-
156
+ MA==
141
157
  none: false
142
158
  required_rubygems_version: !ruby/object:Gem::Requirement
143
159
  requirements: