mvnizer 0.9.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +52 -0
- data/CHANGELOG.org +11 -0
- data/Gemfile +7 -11
- data/Gemfile.lock +35 -102
- data/README.org +8 -7
- data/Rakefile +1 -23
- data/conf/default.yml +2 -2
- data/lib/mvnizer/version.rb +1 -1
- data/mvnizer.gemspec +15 -100
- metadata +8 -136
- data/features/new_project.feature +0 -39
- data/features/search_artefact.feature +0 -14
- data/features/step_definitions/pom_steps.rb +0 -18
- data/features/support/env.rb +0 -24
- data/spec/commands/add_dependency_spec.rb +0 -25
- data/spec/commands/new_project_spec.rb +0 -38
- data/spec/commands/new_war_project_spec.rb +0 -58
- data/spec/commands/project_factory_spec.rb +0 -22
- data/spec/commands/search_artefact_spec.rb +0 -94
- data/spec/configuration_spec.rb +0 -28
- data/spec/coordinate_parser_spec.rb +0 -92
- data/spec/dummy.txt.erb +0 -1
- data/spec/dummy_pom.xml +0 -30
- data/spec/mvnize_spec.rb +0 -100
- data/spec/project_spec.rb +0 -29
- data/spec/spec_helper.rb +0 -11
- data/spec/task_helper_spec.rb +0 -66
data/spec/configuration_spec.rb
DELETED
@@ -1,28 +0,0 @@
|
|
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,92 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mvnizer::CoordinateParser do
|
4
|
-
subject { Mvnizer::CoordinateParser.new }
|
5
|
-
|
6
|
-
describe "#parse" do
|
7
|
-
it "can read the project name" do
|
8
|
-
project = subject.parse("name")
|
9
|
-
project.artifact_id.should == "name"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "can read the group and artifact ids" do
|
13
|
-
project = subject.parse("com.example:name")
|
14
|
-
project.artifact_id.should == "name"
|
15
|
-
project.group_id.should == "com.example"
|
16
|
-
end
|
17
|
-
|
18
|
-
it "can read the group and artifact ids and version and type" do
|
19
|
-
project = subject.parse("com.example:name:1.0.0-rc2:war")
|
20
|
-
project.artifact_id.should == "name"
|
21
|
-
project.group_id.should == "com.example"
|
22
|
-
project.version.should == "1.0.0-rc2"
|
23
|
-
project.type.should == "war"
|
24
|
-
end
|
25
|
-
|
26
|
-
it "can read the group and artifact ids and version" do
|
27
|
-
project = subject.parse("com.example:name:1.0.0-rc2")
|
28
|
-
project.artifact_id.should == "name"
|
29
|
-
project.group_id.should == "com.example"
|
30
|
-
project.version.should == "1.0.0-rc2"
|
31
|
-
end
|
32
|
-
|
33
|
-
it "can read the artifact id and version" do
|
34
|
-
project = subject.parse("name:1.0.0-SNAPSHOT")
|
35
|
-
project.artifact_id.should == "name"
|
36
|
-
project.version.should == "1.0.0-SNAPSHOT"
|
37
|
-
end
|
38
|
-
|
39
|
-
it "can read the artifact id and type" do
|
40
|
-
project = subject.parse("name:jar")
|
41
|
-
project.artifact_id.should == "name"
|
42
|
-
project.type.should == "jar"
|
43
|
-
end
|
44
|
-
|
45
|
-
it "can read the artifact id, version and type" do
|
46
|
-
project = subject.parse("name:1.0.0-rc2:war")
|
47
|
-
project.artifact_id.should == "name"
|
48
|
-
project.version.should == "1.0.0-rc2"
|
49
|
-
project.type.should == "war"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "#parse_scoped_coordinates" do
|
54
|
-
it "can parse the scope" do
|
55
|
-
project = subject.parse_scoped_coordinates("name:1.0.0-rc2:war:runtime")
|
56
|
-
project.artifact_id.should == "name"
|
57
|
-
project.scope.should == "runtime"
|
58
|
-
|
59
|
-
project = subject.parse_scoped_coordinates("com.weblogism:name:1.0.0-rc2:jar:runtime")
|
60
|
-
project.artifact_id.should == "name"
|
61
|
-
project.scope.should == "runtime"
|
62
|
-
end
|
63
|
-
|
64
|
-
it "can parse the junit dependency" do
|
65
|
-
project = subject.parse_scoped_coordinates("junit:junit:4.10:jar:test")
|
66
|
-
project.group_id.should == "junit"
|
67
|
-
project.artifact_id.should == "junit"
|
68
|
-
project.version.should == "4.10"
|
69
|
-
project.type.should == "jar"
|
70
|
-
project.scope.should == "test"
|
71
|
-
end
|
72
|
-
|
73
|
-
it "can parse the java EE dependency" do
|
74
|
-
project = subject.parse_scoped_coordinates("javax:javaee-web-api:6.0:jar:provided")
|
75
|
-
project.group_id.should == "javax"
|
76
|
-
project.artifact_id.should == "javaee-web-api"
|
77
|
-
project.version.should == "6.0"
|
78
|
-
project.type.should == "jar"
|
79
|
-
project.scope.should == "provided"
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
it "can parse a dependency without scope" do
|
84
|
-
project = subject.parse_scoped_coordinates("junit:junit:4.10:jar")
|
85
|
-
project.group_id.should == "junit"
|
86
|
-
project.artifact_id.should == "junit"
|
87
|
-
project.version.should == "4.10"
|
88
|
-
project.type.should == "jar"
|
89
|
-
project.scope.should be_nil
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
data/spec/dummy.txt.erb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Test
|
data/spec/dummy_pom.xml
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
2
|
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
3
|
-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
4
|
-
<modelVersion>4.0.0</modelVersion>
|
5
|
-
|
6
|
-
<groupId>com.weblogism</groupId>
|
7
|
-
<artifactIdd>dummy</artifactIdd>
|
8
|
-
<version>1.0.0-SNAPSHOT</version>
|
9
|
-
|
10
|
-
<properties>
|
11
|
-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
12
|
-
</properties>
|
13
|
-
|
14
|
-
<dependencies>
|
15
|
-
</dependencies>
|
16
|
-
|
17
|
-
<build>
|
18
|
-
<plugins>
|
19
|
-
<plugin>
|
20
|
-
<artifactId>maven-compiler-plugin</artifactId>
|
21
|
-
<version>2.3.2</version>
|
22
|
-
<configuration>
|
23
|
-
<source>1.6</source>
|
24
|
-
<target>1.6</target>
|
25
|
-
</configuration>
|
26
|
-
</plugin>
|
27
|
-
</plugins>
|
28
|
-
</build>
|
29
|
-
|
30
|
-
</project>
|
data/spec/mvnize_spec.rb
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Mvnizer
|
4
|
-
describe Mvnize do
|
5
|
-
|
6
|
-
let (:project) { Project.new(nil, "quxbaz", nil, nil) }
|
7
|
-
let (:new_project) { double("new_project") }
|
8
|
-
let (:search) { double("search") }
|
9
|
-
|
10
|
-
let(:coordinate_parser) { double("coordinate_parser") }
|
11
|
-
subject { Mvnizer::Mvnize.new(coordinate_parser) }
|
12
|
-
|
13
|
-
before { subject.out = StringIO.new }
|
14
|
-
|
15
|
-
it "reads the configuration" do
|
16
|
-
options = {name: "foobar", command: "new"}
|
17
|
-
subject.should_receive(:conf).with(options).and_return(options)
|
18
|
-
|
19
|
-
p = Mvnizer::Project.new("group", "foobar", "version", "jar")
|
20
|
-
coordinate_parser.should_receive(:parse).and_return(project)
|
21
|
-
Command::ProjectFactory.should_receive(:create).and_return(new_project)
|
22
|
-
new_project.should_receive(:run)
|
23
|
-
|
24
|
-
subject.run(options)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "creates a project from the provided coordinates" do
|
28
|
-
options = {name: "foobar", command: "new"}
|
29
|
-
|
30
|
-
subject.should_receive(:conf).with(options).and_return(options)
|
31
|
-
|
32
|
-
p = Mvnizer::Project.new("group", "foobar", "version", "jar")
|
33
|
-
coordinate_parser.should_receive(:parse).with("foobar").and_return(p)
|
34
|
-
Command::ProjectFactory.should_receive(:create).and_return(new_project)
|
35
|
-
new_project.should_receive(:run)
|
36
|
-
|
37
|
-
subject.run(options)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "chooses what command to run depending on the options" do
|
41
|
-
options = {name: "quxbaz", command: "new"}
|
42
|
-
|
43
|
-
subject.should_receive(:conf).and_return(Hash.new)
|
44
|
-
|
45
|
-
p = Mvnizer::Project.new("group", "foobar", "version", "pom")
|
46
|
-
coordinate_parser.should_receive(:parse).and_return(p)
|
47
|
-
Command::ProjectFactory.should_receive(:create).with("pom").and_return(new_project)
|
48
|
-
new_project.should_receive(:run)
|
49
|
-
|
50
|
-
subject.run(options)
|
51
|
-
end
|
52
|
-
|
53
|
-
it "throws an error when no name is given" do
|
54
|
-
lambda { subject.run(Hash.new) }.should raise_error(ArgumentError, "Please give a name to the project.")
|
55
|
-
end
|
56
|
-
|
57
|
-
it "displays a success message when done" do
|
58
|
-
subject.should_receive(:define_project).and_return(project)
|
59
|
-
Command::ProjectFactory.should_receive(:create).and_return(new_project)
|
60
|
-
new_project.should_receive(:run)
|
61
|
-
# For some obscure reason, this does not work:
|
62
|
-
# $stdout.should_receive(:write).with("Project created successfully.")
|
63
|
-
# It fails properly when message is incorrect:
|
64
|
-
# #<IO:0x774d4142> received :write with unexpected arguments
|
65
|
-
# expected: ("success")
|
66
|
-
# got: ("Project created successfully.")
|
67
|
-
# But throws an error when the message is correct:
|
68
|
-
# undefined method `write' for #<IO:fd 1>
|
69
|
-
# So instead, I have to resort to adding an `out` instance variable in Mvnize:
|
70
|
-
string_io = StringIO.new
|
71
|
-
subject.out = string_io
|
72
|
-
|
73
|
-
subject.run(name: "quxbaz", command: "new")
|
74
|
-
string_io.string.should match(/success/i)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "throws an error if the command to run is not valid" do
|
78
|
-
lambda { subject.run(name: "quxbaz", command: "foobar") }.should raise_error(ArgumentError, "foobar is not a valid command.")
|
79
|
-
end
|
80
|
-
|
81
|
-
it "calls the search command when doing a search" do
|
82
|
-
options = { command:"search", name: "junit" }
|
83
|
-
|
84
|
-
Command::SearchArtefact.should_receive(:new).and_return(search)
|
85
|
-
search.should_receive(:run).with(options)
|
86
|
-
|
87
|
-
subject.run(options)
|
88
|
-
end
|
89
|
-
|
90
|
-
it "calls the add command when adding a dependency" do
|
91
|
-
options = { command:"add", name: "junit" }
|
92
|
-
|
93
|
-
Command::AddDependency.should_receive(:new).and_return(search)
|
94
|
-
search.should_receive(:run).with(options)
|
95
|
-
|
96
|
-
subject.run(options)
|
97
|
-
end
|
98
|
-
|
99
|
-
end
|
100
|
-
end
|
data/spec/project_spec.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Mvnizer
|
4
|
-
describe Project do
|
5
|
-
|
6
|
-
describe "#package_name" do
|
7
|
-
it "returns the package name based on coordinates" do
|
8
|
-
project = Project.new("foo", "bar", nil, nil)
|
9
|
-
project.package_name.should == "foo.bar"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "ignores nil group id" do
|
13
|
-
project = Project.new(nil, "bar", nil, nil)
|
14
|
-
project.package_name.should == "bar"
|
15
|
-
end
|
16
|
-
|
17
|
-
it "removes invalid characters in package name" do
|
18
|
-
project = Project.new("f-oo", "b-ar", nil, nil)
|
19
|
-
project.package_name.should == "foo.bar"
|
20
|
-
end
|
21
|
-
|
22
|
-
it "can have plugins" do
|
23
|
-
project = Project.new("foo", "bar", nil, nil)
|
24
|
-
project.add_plugin(Plugin.new("qux", "baz", nil, nil))
|
25
|
-
project.plugins.size.should == 1
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,11 +0,0 @@
|
|
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
|
data/spec/task_helper_spec.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'erb'
|
3
|
-
|
4
|
-
module Mvnizer
|
5
|
-
class Dummy
|
6
|
-
include TaskHelper
|
7
|
-
end
|
8
|
-
|
9
|
-
describe TaskHelper do
|
10
|
-
let (:binding) { double("binding") }
|
11
|
-
let (:erb) { double("erb") }
|
12
|
-
let (:file) { double("file") }
|
13
|
-
subject { Dummy.new }
|
14
|
-
|
15
|
-
describe "#create_dir" do
|
16
|
-
it "creates a list of directories" do
|
17
|
-
subject.create_dir("/tmp/blah/blah", "/tmp/foo/bar")
|
18
|
-
Dir.exists?("/tmp/blah/blah").should be true
|
19
|
-
Dir.exists?("/tmp/foo/bar").should be true
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "#generate_file" do
|
24
|
-
it "generates a file from a template into a given directory" do
|
25
|
-
|
26
|
-
# This checks ERB is called properly.
|
27
|
-
ERB.should_receive(:new).and_return(erb)
|
28
|
-
binding.should_receive(:get_binding)
|
29
|
-
erb.should_receive(:result).and_return("Blah")
|
30
|
-
|
31
|
-
# This checks that the template is being read
|
32
|
-
File.should_receive(:open).with("dummy.txt.erb", "r").and_return(file)
|
33
|
-
file.should_receive(:read)
|
34
|
-
|
35
|
-
# This checks that the output is being written.
|
36
|
-
f = double("output_file")
|
37
|
-
File.should_receive(:open).with("foobar/dummy.txt", "w").and_yield(f)
|
38
|
-
f.should_receive(:write).with("Blah")
|
39
|
-
|
40
|
-
subject.generate_file("dummy.txt.erb", "foobar/dummy.txt", binding)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "creates the output directory if it does not exist" do
|
44
|
-
subject.should_receive(:create_dir).with("foo")
|
45
|
-
File.should_receive(:open).at_least(1).times.and_return(file)
|
46
|
-
file.should_receive(:read)
|
47
|
-
subject.generate_file("dummy.txt.erb", "foo/dummy.txt", binding)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "#add_dependency" do
|
52
|
-
it "adds a new dependency to an existing pom file" do
|
53
|
-
dependencies = ["org.apache.commons:commons-lang3:3.1:jar",
|
54
|
-
"org.apache.commons:commons-collections:3.2.1:jar"]
|
55
|
-
|
56
|
-
pom_location = File.join(File.dirname(__FILE__), "dummy_pom.xml")
|
57
|
-
output = subject.add_dependency(dependencies, pom_location)
|
58
|
-
output.should match("<groupId>org.apache.commons</groupId>")
|
59
|
-
end
|
60
|
-
|
61
|
-
it "throws an error if the pom cannot be found in the current directory" do
|
62
|
-
lambda { subject.add_dependency(nil) }.should raise_error(FileNotFoundError, "The pom.xml file cannot be found.")
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|