mvnizer 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +18 -0
- data/Gemfile +2 -1
- data/README.md +12 -0
- data/bin/mvnizer +3 -0
- data/lib/mvnizer.rb +1 -0
- data/lib/mvnizer/commands.rb +1 -0
- data/lib/mvnizer/commands/add_dependency.rb +22 -0
- data/lib/mvnizer/commands/new_project.rb +9 -0
- data/lib/mvnizer/commands/new_war_project.rb +15 -4
- data/lib/mvnizer/coordinate_parser.rb +1 -1
- data/lib/mvnizer/exceptions.rb +6 -0
- data/lib/mvnizer/mvnize.rb +3 -0
- data/lib/mvnizer/project.rb +6 -0
- data/lib/mvnizer/task_helper.rb +35 -0
- data/lib/mvnizer/templates/_dependency.xml.erb +1 -1
- data/lib/mvnizer/templates/war/ExampleServlet.java.erb +19 -0
- data/lib/mvnizer/templates/war/index.jsp.erb +11 -0
- data/lib/mvnizer/version.rb +1 -1
- data/mvnizer.gemspec +14 -5
- data/spec/commands/add_dependency_spec.rb +25 -0
- data/spec/commands/new_project_spec.rb +13 -1
- data/spec/commands/new_war_project_spec.rb +12 -4
- data/spec/commands/project_factory_spec.rb +1 -0
- data/spec/commands/search_artefact_spec.rb +1 -5
- data/spec/coordinate_parser_spec.rb +75 -52
- data/spec/dummy.txt.erb +1 -0
- data/spec/dummy_pom.xml +30 -0
- data/spec/mvnize_spec.rb +9 -0
- data/spec/project_spec.rb +23 -0
- data/spec/task_helper_spec.rb +30 -13
- metadata +24 -15
data/CHANGELOG.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
# Mvnizer 0.0.4
|
3
|
+
|
4
|
+
* Added sample servlet and JSP in new war project,
|
5
|
+
* Add dependency using the `mvnizer add` command.
|
6
|
+
|
7
|
+
# Mvnizer 0.0.3
|
8
|
+
|
9
|
+
* Search dependencies in Maven central repo
|
10
|
+
|
11
|
+
# Mvnizer 0.0.2
|
12
|
+
|
13
|
+
* Coordinate parsing
|
14
|
+
* Project creation depending on the project type (jar or war)
|
15
|
+
|
16
|
+
# Mvnizer 0.0.1
|
17
|
+
|
18
|
+
* Basic Maven project creation
|
data/Gemfile
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
source 'http://rubygems.org'
|
2
2
|
|
3
3
|
gem 'httparty', '~> 0.9.0'
|
4
|
+
gem 'nokogiri', '~> 1.5.5'
|
5
|
+
|
4
6
|
|
5
7
|
group :development do
|
6
8
|
gem 'rspec', '~> 2.11.0'
|
7
9
|
gem 'rspec-mocks', '~> 2.11.2'
|
8
10
|
gem 'fakefs', '~> 0.4.0'
|
9
|
-
gem 'nokogiri', '~> 1.5.5'
|
10
11
|
gem 'jeweler', '~> 1.8.4'
|
11
12
|
gem 'aruba', '~> 0.4.11'
|
12
13
|
end
|
data/README.md
CHANGED
@@ -27,6 +27,18 @@ Here are some examples of valid commands:
|
|
27
27
|
mvnizer new com.example:foo:war
|
28
28
|
mvnizer new com.example:foo:1.0:war
|
29
29
|
|
30
|
+
## Add Dependency
|
31
|
+
|
32
|
+
To add dependencies, you must be in the folder where the pom file you want to add the dependency to is.
|
33
|
+
|
34
|
+
To add a dependency, simply pass the coordinates of the dependency, and add scope if needed (if no scope is given, `compile` is assumed):
|
35
|
+
|
36
|
+
mvnizer add org.apache.commons:commons-lang3:3.1:jar
|
37
|
+
mvnizer add org.mockito:mockito-core:1.9.5-rc1:jar:test
|
38
|
+
|
39
|
+
The `search` features makes it easy to find the coordinates of the dependencies for you.
|
40
|
+
|
41
|
+
|
30
42
|
## Dependency Search
|
31
43
|
|
32
44
|
You can search for dependencies in the Maven central repository with the command:
|
data/bin/mvnizer
CHANGED
@@ -17,6 +17,9 @@ Mvnizer bootstraps a Maven project without the pain of archetypes.
|
|
17
17
|
mvnizer new com.example:foo:war
|
18
18
|
mvnizer new com.example:foo:1.0:war
|
19
19
|
|
20
|
+
mvnizer add <coordinates>
|
21
|
+
Adds a dependency to the project.
|
22
|
+
|
20
23
|
mvnizer search <text>
|
21
24
|
Searches for artefacts in the Maven central repository.
|
22
25
|
HELP
|
data/lib/mvnizer.rb
CHANGED
data/lib/mvnizer/commands.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Mvnizer
|
2
|
+
module Command
|
3
|
+
class AddDependency
|
4
|
+
include TaskHelper
|
5
|
+
|
6
|
+
def run(options)
|
7
|
+
raise Mvnizer::FileNotFoundError, "The pom.xml file cannot be found." unless pom_present?
|
8
|
+
|
9
|
+
dependency = options[:name]
|
10
|
+
content = add_dependency([dependency])
|
11
|
+
File.open("pom.xml", "w") do |f|
|
12
|
+
f.write(content)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def pom_present?
|
18
|
+
File.exists?(File.join(Dir.pwd, "pom.xml"))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -11,10 +11,19 @@ module Mvnizer
|
|
11
11
|
create_dir("#{project.artifact_id}/src/main/java",
|
12
12
|
"#{project.artifact_id}/src/test/java")
|
13
13
|
|
14
|
+
coordinate_parser = CoordinateParser.new
|
15
|
+
get_dependencies.each { |d| project.add_dependency(coordinate_parser.parse_scoped_coordinates(d)) }
|
16
|
+
|
14
17
|
generate_file(File.join(TEMPLATE_DIR, "pom.xml.erb"),
|
15
18
|
"#{project.artifact_id}/pom.xml",
|
16
19
|
project)
|
17
20
|
end
|
21
|
+
|
22
|
+
# Returns the list of dependencies to be added for this type of project.
|
23
|
+
# Override this method if extra dependencies are needed.
|
24
|
+
def get_dependencies
|
25
|
+
[]
|
26
|
+
end
|
18
27
|
|
19
28
|
end
|
20
29
|
end
|
@@ -8,14 +8,25 @@ module Mvnizer
|
|
8
8
|
|
9
9
|
# web.xml is optional in Servlet 3.0
|
10
10
|
# Do we keep its generation here?
|
11
|
-
generate_file(File.join(TEMPLATE_DIR, "web.xml.erb"),
|
11
|
+
generate_file(File.join(TEMPLATE_DIR, "web.xml.erb"),
|
12
12
|
"#{project.artifact_id}/src/main/webapp/WEB-INF/web.xml",
|
13
13
|
project)
|
14
14
|
|
15
15
|
|
16
|
-
#
|
17
|
-
#
|
18
|
-
|
16
|
+
# The Java class will be generated in the groupId/artifactId folder
|
17
|
+
# with the dots replaced by path separators.
|
18
|
+
target_directory = project.package_name.gsub(/\./, File::SEPARATOR)
|
19
|
+
|
20
|
+
generate_file(File.join(TEMPLATE_DIR, "war", "ExampleServlet.java.erb"),
|
21
|
+
"#{project.artifact_id}/src/main/java/#{target_directory}/ExampleServlet.java",
|
22
|
+
project)
|
23
|
+
generate_file(File.join(TEMPLATE_DIR, "war", "index.jsp.erb"),
|
24
|
+
"#{project.artifact_id}/src/main/webapp/WEB-INF/index.jsp",
|
25
|
+
project)
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_dependencies
|
29
|
+
["javax:javaee-web-api:6.0:jar:provided"]
|
19
30
|
end
|
20
31
|
end
|
21
32
|
end
|
@@ -20,7 +20,7 @@ module Mvnizer
|
|
20
20
|
# the scope (test, compile, provided, runtime, system or import)
|
21
21
|
def parse_scoped_coordinates(coordinates)
|
22
22
|
p = nil
|
23
|
-
if coordinates =~ /\A(([a-zA-Z][\w\.\-]+):)?([a-zA-Z][\w\.\-]+)(:(\d+\.\d+(\.\d)?(\-\w+)?))?:(war|jar|pom)
|
23
|
+
if coordinates =~ /\A(([a-zA-Z][\w\.\-]+):)?([a-zA-Z][\w\.\-]+)(:(\d+\.\d+(\.\d)?(\-\w+)?))?:(war|jar|pom):?(test|compile|provided|runtime|system|import)?/
|
24
24
|
p = Project.new($2, $3, $5, $8, [], $9)
|
25
25
|
end
|
26
26
|
p
|
data/lib/mvnizer/mvnize.rb
CHANGED
@@ -28,6 +28,9 @@ module Mvnizer
|
|
28
28
|
when "search"
|
29
29
|
search_command = Command::SearchArtefact.new
|
30
30
|
search_command.run(options)
|
31
|
+
when "add"
|
32
|
+
add_command = Command::AddDependency.new
|
33
|
+
add_command.run(options)
|
31
34
|
else
|
32
35
|
raise ArgumentError, "#{options[:command]} is not a valid command."
|
33
36
|
end
|
data/lib/mvnizer/project.rb
CHANGED
@@ -27,6 +27,12 @@ module Mvnizer
|
|
27
27
|
&& type == project.type)
|
28
28
|
end
|
29
29
|
|
30
|
+
def package_name
|
31
|
+
package = artifact_id
|
32
|
+
package = "#{group_id}.#{package}" unless group_id == nil
|
33
|
+
package.gsub(/\-/, "")
|
34
|
+
end
|
35
|
+
|
30
36
|
# Converts project into its coordinates representation.
|
31
37
|
def to_s
|
32
38
|
"#{group_id}:#{artifact_id}:#{version}:#{type}:#{scope}"
|
data/lib/mvnizer/task_helper.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'fileutils'
|
2
|
+
require 'nokogiri'
|
2
3
|
|
3
4
|
module Mvnizer
|
4
5
|
# The +TaskHelper+ provides different functions that can be used in tasks,
|
@@ -28,5 +29,39 @@ module Mvnizer
|
|
28
29
|
f.write(ERB.new(template).result(binding.get_binding))
|
29
30
|
end
|
30
31
|
end
|
32
|
+
|
33
|
+
# adds a list of dependencies to the pom file whose location
|
34
|
+
# can be given as +pom_location+. By default, this function
|
35
|
+
# looks up the pom in the current directory.
|
36
|
+
def add_dependency(dependency, pom_location = File.join(Dir.pwd, "pom.xml"))
|
37
|
+
raise FileNotFoundError, "The pom.xml file cannot be found." unless File.exists?(pom_location)
|
38
|
+
|
39
|
+
coordinate_parser = CoordinateParser.new
|
40
|
+
|
41
|
+
pom = Nokogiri::XML(File.open(pom_location)) do |c|
|
42
|
+
c.noblanks
|
43
|
+
end
|
44
|
+
dependencies_node = pom.xpath("/pom:project/pom:dependencies", {"pom" => "http://maven.apache.org/POM/4.0.0"}).first
|
45
|
+
|
46
|
+
dependency.each do |d|
|
47
|
+
# First parse the dependency coordinates
|
48
|
+
dep_project = coordinate_parser.parse_scoped_coordinates(d)
|
49
|
+
|
50
|
+
Nokogiri::XML::Builder.with(dependencies_node) do |xml|
|
51
|
+
xml.dependency {
|
52
|
+
xml.groupId dep_project.group_id
|
53
|
+
xml.artifactId dep_project.artifact_id
|
54
|
+
xml.version dep_project.version
|
55
|
+
xml.scope dep_project.scope if dep_project.scope != nil && dep_project.scope != "compile"
|
56
|
+
xml.type dep_project.type if dep_project.type != "jar"
|
57
|
+
}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Requires sparklemotion/nokogiri#772 to produce
|
62
|
+
# identical pom files in both MRI and JRuby.
|
63
|
+
pom.to_xml(indent: 2)
|
64
|
+
end
|
31
65
|
end
|
66
|
+
|
32
67
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
package <%= package_name %>;
|
2
|
+
|
3
|
+
import java.io.IOException;
|
4
|
+
import javax.servlet.GenericServlet;
|
5
|
+
import javax.servlet.ServletException;
|
6
|
+
import javax.servlet.ServletRequest;
|
7
|
+
import javax.servlet.ServletResponse;
|
8
|
+
import javax.servlet.annotation.WebServlet;
|
9
|
+
|
10
|
+
@WebServlet("/hello")
|
11
|
+
public class ExampleServlet extends GenericServlet {
|
12
|
+
|
13
|
+
@Override
|
14
|
+
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
|
15
|
+
|
16
|
+
request.setAttribute("greeting", "Hello World");
|
17
|
+
request.getRequestDispatcher("/WEB-INF/index.jsp").forward(request, response);
|
18
|
+
}
|
19
|
+
}
|
data/lib/mvnizer/version.rb
CHANGED
data/mvnizer.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "mvnizer"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["S\u{e9}bastien Le Callonnec"]
|
12
|
-
s.date = "2012-09-
|
12
|
+
s.date = "2012-09-29"
|
13
13
|
s.description = "Bootstrap a Maven project without the pain of archetypes."
|
14
14
|
s.email = "sebastien@weblogism.com"
|
15
15
|
s.executables = ["mvnizer"]
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
]
|
20
20
|
s.files = [
|
21
21
|
".rspec",
|
22
|
+
"CHANGELOG.md",
|
22
23
|
"Gemfile",
|
23
24
|
"Gemfile.lock",
|
24
25
|
"LICENSE.txt",
|
@@ -33,6 +34,7 @@ Gem::Specification.new do |s|
|
|
33
34
|
"features/support/env.rb",
|
34
35
|
"lib/mvnizer.rb",
|
35
36
|
"lib/mvnizer/commands.rb",
|
37
|
+
"lib/mvnizer/commands/add_dependency.rb",
|
36
38
|
"lib/mvnizer/commands/new_project.rb",
|
37
39
|
"lib/mvnizer/commands/new_war_project.rb",
|
38
40
|
"lib/mvnizer/commands/project_factory.rb",
|
@@ -40,24 +42,31 @@ Gem::Specification.new do |s|
|
|
40
42
|
"lib/mvnizer/configuration.rb",
|
41
43
|
"lib/mvnizer/coordinate_parser.rb",
|
42
44
|
"lib/mvnizer/erb_helper.rb",
|
45
|
+
"lib/mvnizer/exceptions.rb",
|
43
46
|
"lib/mvnizer/mvnize.rb",
|
44
47
|
"lib/mvnizer/project.rb",
|
45
48
|
"lib/mvnizer/task_helper.rb",
|
46
49
|
"lib/mvnizer/templates/_dependency.xml.erb",
|
47
50
|
"lib/mvnizer/templates/pom.xml.erb",
|
51
|
+
"lib/mvnizer/templates/war/ExampleServlet.java.erb",
|
52
|
+
"lib/mvnizer/templates/war/index.jsp.erb",
|
48
53
|
"lib/mvnizer/templates/web.xml.erb",
|
49
54
|
"lib/mvnizer/version.rb",
|
50
55
|
"mvnizer.gemspec",
|
51
56
|
"ragel/coordinate.rb",
|
52
57
|
"ragel/coordinate.rl",
|
53
58
|
"ragel/test_coord.rb",
|
59
|
+
"spec/commands/add_dependency_spec.rb",
|
54
60
|
"spec/commands/new_project_spec.rb",
|
55
61
|
"spec/commands/new_war_project_spec.rb",
|
56
62
|
"spec/commands/project_factory_spec.rb",
|
57
63
|
"spec/commands/search_artefact_spec.rb",
|
58
64
|
"spec/configuration_spec.rb",
|
59
65
|
"spec/coordinate_parser_spec.rb",
|
66
|
+
"spec/dummy.txt.erb",
|
67
|
+
"spec/dummy_pom.xml",
|
60
68
|
"spec/mvnize_spec.rb",
|
69
|
+
"spec/project_spec.rb",
|
61
70
|
"spec/spec_helper.rb",
|
62
71
|
"spec/task_helper_spec.rb"
|
63
72
|
]
|
@@ -72,27 +81,27 @@ Gem::Specification.new do |s|
|
|
72
81
|
|
73
82
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
74
83
|
s.add_runtime_dependency(%q<httparty>, ["~> 0.9.0"])
|
84
|
+
s.add_runtime_dependency(%q<nokogiri>, ["~> 1.5.5"])
|
75
85
|
s.add_development_dependency(%q<rspec>, ["~> 2.11.0"])
|
76
86
|
s.add_development_dependency(%q<rspec-mocks>, ["~> 2.11.2"])
|
77
87
|
s.add_development_dependency(%q<fakefs>, ["~> 0.4.0"])
|
78
|
-
s.add_development_dependency(%q<nokogiri>, ["~> 1.5.5"])
|
79
88
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
80
89
|
s.add_development_dependency(%q<aruba>, ["~> 0.4.11"])
|
81
90
|
else
|
82
91
|
s.add_dependency(%q<httparty>, ["~> 0.9.0"])
|
92
|
+
s.add_dependency(%q<nokogiri>, ["~> 1.5.5"])
|
83
93
|
s.add_dependency(%q<rspec>, ["~> 2.11.0"])
|
84
94
|
s.add_dependency(%q<rspec-mocks>, ["~> 2.11.2"])
|
85
95
|
s.add_dependency(%q<fakefs>, ["~> 0.4.0"])
|
86
|
-
s.add_dependency(%q<nokogiri>, ["~> 1.5.5"])
|
87
96
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
88
97
|
s.add_dependency(%q<aruba>, ["~> 0.4.11"])
|
89
98
|
end
|
90
99
|
else
|
91
100
|
s.add_dependency(%q<httparty>, ["~> 0.9.0"])
|
101
|
+
s.add_dependency(%q<nokogiri>, ["~> 1.5.5"])
|
92
102
|
s.add_dependency(%q<rspec>, ["~> 2.11.0"])
|
93
103
|
s.add_dependency(%q<rspec-mocks>, ["~> 2.11.2"])
|
94
104
|
s.add_dependency(%q<fakefs>, ["~> 0.4.0"])
|
95
|
-
s.add_dependency(%q<nokogiri>, ["~> 1.5.5"])
|
96
105
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
97
106
|
s.add_dependency(%q<aruba>, ["~> 0.4.11"])
|
98
107
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Mvnizer
|
4
|
+
module Command
|
5
|
+
describe AddDependency do
|
6
|
+
let (:file) { double("file") }
|
7
|
+
|
8
|
+
subject { AddDependency.new }
|
9
|
+
it "checks the pom can be found in the current directory" do
|
10
|
+
lambda { subject.run({}) }.should raise_error(FileNotFoundError, "The pom.xml file cannot be found.")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "adds a dependency" do
|
14
|
+
options = { name: "test" }
|
15
|
+
|
16
|
+
File.should_receive(:exists?).and_return(true)
|
17
|
+
subject.should_receive(:add_dependency).with(["test"]).and_return("out")
|
18
|
+
File.should_receive(:open).with("pom.xml", "w").and_yield(file)
|
19
|
+
file.should_receive(:write).with("out")
|
20
|
+
|
21
|
+
subject.run(options)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -4,10 +4,10 @@ require 'spec_helper'
|
|
4
4
|
module Mvnizer
|
5
5
|
module Command
|
6
6
|
describe NewProject do
|
7
|
+
let(:coordinate_parser) { double("parser") }
|
7
8
|
let(:project) { Mvnizer::Project.new("com.example", "foobar", "1.0.0-SNAPSHOT", "war") }
|
8
9
|
subject { Mvnizer::Command::NewProject.new }
|
9
10
|
|
10
|
-
|
11
11
|
it "creates the project directory" do
|
12
12
|
subject.should_receive(:generate_file)
|
13
13
|
subject.should_receive(:create_dir).with("foobar/src/main/java", "foobar/src/test/java")
|
@@ -15,6 +15,18 @@ module Mvnizer
|
|
15
15
|
subject.run(project)
|
16
16
|
end
|
17
17
|
|
18
|
+
it "parses the extra dependencies and adds them" do
|
19
|
+
subject.should_receive(:get_dependencies).and_return(["foo:bar:1.0:jar:test"])
|
20
|
+
CoordinateParser.should_receive(:new).and_return(coordinate_parser)
|
21
|
+
coordinate_parser.should_receive(:parse_scoped_coordinates).with("foo:bar:1.0:jar:test").and_return("Blah")
|
22
|
+
subject.should_receive(:generate_file)
|
23
|
+
subject.should_receive(:create_dir)
|
24
|
+
|
25
|
+
subject.run(project)
|
26
|
+
|
27
|
+
project.dependencies.first.should == "Blah"
|
28
|
+
end
|
29
|
+
|
18
30
|
it "generates the pom file" do
|
19
31
|
subject.should_receive(:generate_file).with(File.join(TaskHelper::TEMPLATE_DIR, "pom.xml.erb"), "foobar/pom.xml", project)
|
20
32
|
subject.run(project)
|
@@ -5,7 +5,7 @@ module Mvnizer
|
|
5
5
|
module Command
|
6
6
|
describe NewWarProject do
|
7
7
|
|
8
|
-
let(:project) { Mvnizer::Project.new(
|
8
|
+
let(:project) { Mvnizer::Project.new("test", "foobar", nil, nil) }
|
9
9
|
subject { Mvnizer::Command::NewWarProject.new }
|
10
10
|
|
11
11
|
before do
|
@@ -22,24 +22,32 @@ module Mvnizer
|
|
22
22
|
|
23
23
|
it "creates a basic project" do
|
24
24
|
subject.should_receive(:create_dir)
|
25
|
-
subject.should_receive(:generate_file)
|
25
|
+
subject.should_receive(:generate_file).exactly(3).times
|
26
26
|
subject.run(project)
|
27
27
|
$run.should be_true
|
28
28
|
end
|
29
29
|
|
30
30
|
it "creates the webapp directory" do
|
31
31
|
subject.should_receive(:create_dir).with("foobar/src/main/webapp/WEB-INF")
|
32
|
-
subject.should_receive(:generate_file)
|
32
|
+
subject.should_receive(:generate_file).exactly(3).times
|
33
33
|
subject.run(project)
|
34
34
|
end
|
35
35
|
|
36
|
-
it "generates the
|
36
|
+
it "generates all the webapp files file" do
|
37
37
|
subject.should_receive(:create_dir)
|
38
38
|
subject.should_receive(:generate_file).with(File.join(TaskHelper::TEMPLATE_DIR, "web.xml.erb"), "foobar/src/main/webapp/WEB-INF/web.xml", project)
|
39
|
+
subject.should_receive(:generate_file).with(File.join(TaskHelper::TEMPLATE_DIR, "war", "ExampleServlet.java.erb"), "foobar/src/main/java/test/foobar/ExampleServlet.java", project)
|
40
|
+
subject.should_receive(:generate_file).with(File.join(TaskHelper::TEMPLATE_DIR, "war", "index.jsp.erb"), "foobar/src/main/webapp/WEB-INF/index.jsp", project)
|
41
|
+
|
39
42
|
|
40
43
|
subject.run(project)
|
41
44
|
end
|
42
45
|
|
46
|
+
it "adds the dependencies needed for a war file" do
|
47
|
+
deps = subject.get_dependencies
|
48
|
+
deps.include?("javax:javaee-web-api:6.0:jar:provided").should be_true
|
49
|
+
end
|
50
|
+
|
43
51
|
after do
|
44
52
|
class NewProject
|
45
53
|
alias run old_run
|
@@ -6,11 +6,7 @@ module Mvnizer
|
|
6
6
|
describe SearchArtefact do
|
7
7
|
|
8
8
|
subject { SearchArtefact.new }
|
9
|
-
before
|
10
|
-
subject.out = StringIO.new
|
11
|
-
|
12
|
-
end
|
13
|
-
|
9
|
+
before { subject.out = StringIO.new }
|
14
10
|
|
15
11
|
def httparty_response_mock(mock_response_content)
|
16
12
|
request_object = HTTParty::Request.new Net::HTTP::Get, '/'
|
@@ -3,67 +3,90 @@ require 'spec_helper'
|
|
3
3
|
describe Mvnizer::CoordinateParser do
|
4
4
|
subject { Mvnizer::CoordinateParser.new }
|
5
5
|
|
6
|
-
|
7
|
-
project
|
8
|
-
|
9
|
-
|
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
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
49
51
|
end
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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"
|
55
58
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
60
82
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
68
91
|
end
|
69
92
|
end
|
data/spec/dummy.txt.erb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Test
|
data/spec/dummy_pom.xml
ADDED
@@ -0,0 +1,30 @@
|
|
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
CHANGED
@@ -87,5 +87,14 @@ module Mvnizer
|
|
87
87
|
subject.run(options)
|
88
88
|
end
|
89
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
|
+
|
90
99
|
end
|
91
100
|
end
|
@@ -0,0 +1,23 @@
|
|
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
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/task_helper_spec.rb
CHANGED
@@ -12,13 +12,6 @@ module Mvnizer
|
|
12
12
|
let (:file) { double("file") }
|
13
13
|
subject { Dummy.new }
|
14
14
|
|
15
|
-
# Make use of fakefs explicit by using activate! / deactivate!
|
16
|
-
before do
|
17
|
-
FakeFS.activate!
|
18
|
-
FileUtils.mkdir("foobar")
|
19
|
-
FileUtils.touch("dummy.txt.erb")
|
20
|
-
end
|
21
|
-
|
22
15
|
describe "#create_dir" do
|
23
16
|
it "creates a list of directories" do
|
24
17
|
subject.create_dir("/tmp/blah/blah", "/tmp/foo/bar")
|
@@ -29,12 +22,22 @@ module Mvnizer
|
|
29
22
|
|
30
23
|
describe "#generate_file" do
|
31
24
|
it "generates a file from a template into a given directory" do
|
25
|
+
|
26
|
+
# This checks ERB is called properly.
|
32
27
|
ERB.should_receive(:new).and_return(erb)
|
33
28
|
binding.should_receive(:get_binding)
|
34
|
-
erb.should_receive(:result).and_return("")
|
35
|
-
|
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")
|
36
39
|
|
37
|
-
|
40
|
+
subject.generate_file("dummy.txt.erb", "foobar/dummy.txt", binding)
|
38
41
|
end
|
39
42
|
|
40
43
|
it "creates the output directory if it does not exist" do
|
@@ -45,9 +48,23 @@ module Mvnizer
|
|
45
48
|
end
|
46
49
|
end
|
47
50
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
+
describe "#add_dependency" do
|
52
|
+
|
53
|
+
# This test fails because of sparklemotion/nokogiri#771
|
54
|
+
# Remove pending when nokogiri is fixed.
|
55
|
+
it "adds a new dependency to an existing pom file" do
|
56
|
+
pending("Awaiting sparklemotion/nokogiri#771")
|
57
|
+
dependencies = ["org.apache.commons:commons-lang3:3.1:jar",
|
58
|
+
"org.apache.commons:commons-collections:3.2.1:jar"]
|
59
|
+
|
60
|
+
pom_location = File.join(File.dirname(__FILE__), "dummy_pom.xml")
|
61
|
+
output = subject.add_dependency(dependencies, pom_location)
|
62
|
+
output.should match("<groupId>org.apache.commons</groupId>")
|
63
|
+
end
|
64
|
+
|
65
|
+
it "throws an error if the pom cannot be found in the current directory" do
|
66
|
+
lambda { subject.add_dependency(nil) }.should raise_error(FileNotFoundError, "The pom.xml file cannot be found.")
|
67
|
+
end
|
51
68
|
end
|
52
69
|
end
|
53
70
|
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.
|
5
|
+
version: 0.0.4
|
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-
|
12
|
+
date: 2012-09-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -28,66 +28,66 @@ dependencies:
|
|
28
28
|
prerelease: false
|
29
29
|
type: :runtime
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
31
|
+
name: nokogiri
|
32
32
|
version_requirements: !ruby/object:Gem::Requirement
|
33
33
|
requirements:
|
34
34
|
- - ~>
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version:
|
36
|
+
version: 1.5.5
|
37
37
|
none: false
|
38
38
|
requirement: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - ~>
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version:
|
42
|
+
version: 1.5.5
|
43
43
|
none: false
|
44
44
|
prerelease: false
|
45
|
-
type: :
|
45
|
+
type: :runtime
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name: rspec
|
47
|
+
name: rspec
|
48
48
|
version_requirements: !ruby/object:Gem::Requirement
|
49
49
|
requirements:
|
50
50
|
- - ~>
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: 2.11.
|
52
|
+
version: 2.11.0
|
53
53
|
none: false
|
54
54
|
requirement: !ruby/object:Gem::Requirement
|
55
55
|
requirements:
|
56
56
|
- - ~>
|
57
57
|
- !ruby/object:Gem::Version
|
58
|
-
version: 2.11.
|
58
|
+
version: 2.11.0
|
59
59
|
none: false
|
60
60
|
prerelease: false
|
61
61
|
type: :development
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
63
|
+
name: rspec-mocks
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 2.11.2
|
69
69
|
none: false
|
70
70
|
requirement: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
72
|
- - ~>
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version:
|
74
|
+
version: 2.11.2
|
75
75
|
none: false
|
76
76
|
prerelease: false
|
77
77
|
type: :development
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
79
|
+
name: fakefs
|
80
80
|
version_requirements: !ruby/object:Gem::Requirement
|
81
81
|
requirements:
|
82
82
|
- - ~>
|
83
83
|
- !ruby/object:Gem::Version
|
84
|
-
version:
|
84
|
+
version: 0.4.0
|
85
85
|
none: false
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
88
|
- - ~>
|
89
89
|
- !ruby/object:Gem::Version
|
90
|
-
version:
|
90
|
+
version: 0.4.0
|
91
91
|
none: false
|
92
92
|
prerelease: false
|
93
93
|
type: :development
|
@@ -133,6 +133,7 @@ extra_rdoc_files:
|
|
133
133
|
- README.md
|
134
134
|
files:
|
135
135
|
- .rspec
|
136
|
+
- CHANGELOG.md
|
136
137
|
- Gemfile
|
137
138
|
- Gemfile.lock
|
138
139
|
- LICENSE.txt
|
@@ -147,6 +148,7 @@ files:
|
|
147
148
|
- features/support/env.rb
|
148
149
|
- lib/mvnizer.rb
|
149
150
|
- lib/mvnizer/commands.rb
|
151
|
+
- lib/mvnizer/commands/add_dependency.rb
|
150
152
|
- lib/mvnizer/commands/new_project.rb
|
151
153
|
- lib/mvnizer/commands/new_war_project.rb
|
152
154
|
- lib/mvnizer/commands/project_factory.rb
|
@@ -154,24 +156,31 @@ files:
|
|
154
156
|
- lib/mvnizer/configuration.rb
|
155
157
|
- lib/mvnizer/coordinate_parser.rb
|
156
158
|
- lib/mvnizer/erb_helper.rb
|
159
|
+
- lib/mvnizer/exceptions.rb
|
157
160
|
- lib/mvnizer/mvnize.rb
|
158
161
|
- lib/mvnizer/project.rb
|
159
162
|
- lib/mvnizer/task_helper.rb
|
160
163
|
- lib/mvnizer/templates/_dependency.xml.erb
|
161
164
|
- lib/mvnizer/templates/pom.xml.erb
|
165
|
+
- lib/mvnizer/templates/war/ExampleServlet.java.erb
|
166
|
+
- lib/mvnizer/templates/war/index.jsp.erb
|
162
167
|
- lib/mvnizer/templates/web.xml.erb
|
163
168
|
- lib/mvnizer/version.rb
|
164
169
|
- mvnizer.gemspec
|
165
170
|
- ragel/coordinate.rb
|
166
171
|
- ragel/coordinate.rl
|
167
172
|
- ragel/test_coord.rb
|
173
|
+
- spec/commands/add_dependency_spec.rb
|
168
174
|
- spec/commands/new_project_spec.rb
|
169
175
|
- spec/commands/new_war_project_spec.rb
|
170
176
|
- spec/commands/project_factory_spec.rb
|
171
177
|
- spec/commands/search_artefact_spec.rb
|
172
178
|
- spec/configuration_spec.rb
|
173
179
|
- spec/coordinate_parser_spec.rb
|
180
|
+
- spec/dummy.txt.erb
|
181
|
+
- spec/dummy_pom.xml
|
174
182
|
- spec/mvnize_spec.rb
|
183
|
+
- spec/project_spec.rb
|
175
184
|
- spec/spec_helper.rb
|
176
185
|
- spec/task_helper_spec.rb
|
177
186
|
homepage: http://github.com/tychobrailleur/mvnizer
|