mvnizer 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec CHANGED
@@ -1 +1 @@
1
- --color
1
+ --color
data/Gemfile CHANGED
@@ -1,9 +1,9 @@
1
- source 'http://rubygems.org'
2
-
3
- group :development do
4
- gem 'rspec', '~> 2.11.0'
5
- gem 'rspec-mocks', '~> 2.11.2'
6
- gem 'fakefs', '~> 0.4.0'
7
- gem 'nokogiri', '~> 1.5.5'
8
- gem 'jeweler', '~> 1.8.4'
9
- end
1
+ source 'http://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'rspec', '~> 2.11.0'
5
+ gem 'rspec-mocks', '~> 2.11.2'
6
+ gem 'fakefs', '~> 0.4.0'
7
+ gem 'nokogiri', '~> 1.5.5'
8
+ gem 'jeweler', '~> 1.8.4'
9
+ end
data/LICENSE.txt CHANGED
@@ -1,20 +1,20 @@
1
- Copyright (c) 2012 Sebastien Le Callonnec
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2012 Sebastien Le Callonnec
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,5 +1,23 @@
1
- Bootstraps a Maven project. Because archetypes shouldn't be so complicated.
2
-
3
- # Introduction
4
-
5
- Mvnizer is ideal to create a throw-away Maven project that adds junit as a dependency and sets up the Maven project structure.
1
+ Bootstraps a Maven project. Because archetypes shouldn't be so complicated.
2
+
3
+ # Introduction
4
+
5
+ Mvnizer is ideal to create a throw-away Maven project that adds junit as a dependency and sets up the Maven project structure.
6
+
7
+ # Command
8
+
9
+ Mvnizer is used as follows:
10
+
11
+ $ mvnizer new <coordinates>
12
+
13
+ The coordinates can have the following format:
14
+
15
+ <group:>artifact<:version><:type>
16
+
17
+ with the values between angled brackets optional. `type` can only have one of the following three values: `jar` (default), `war` or `pom`.
18
+
19
+ This command creates a project in the `artifact` folder, populating the proper values in the pom file.
20
+
21
+ # License
22
+
23
+ MIT License.
data/Rakefile CHANGED
@@ -1,55 +1,55 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
-
14
- require 'jeweler'
15
- require './lib/mvnizer/version.rb'
16
- Jeweler::Tasks.new do |gem|
17
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
18
- gem.name = "mvnizer"
19
- gem.version = Mvnizer::Version::STRING
20
- gem.homepage = "http://github.com/tychobrailleur/mvnizer"
21
- gem.license = "MIT"
22
- gem.summary = %Q{Bootstrap a Maven project without the pain of archetypes.}
23
- gem.description = %Q{Bootstrap a Maven project without the pain of archetypes.}
24
- gem.email = "sebastien@weblogism.com"
25
- gem.authors = ["Sébastien Le Callonnec"]
26
-
27
- gem.executables = ['mvnizer']
28
- # dependencies defined in Gemfile
29
- end
30
- Jeweler::RubygemsDotOrgTasks.new
31
-
32
- require 'rspec/core'
33
- require 'rspec/core/rake_task'
34
- RSpec::Core::RakeTask.new(:spec) do |spec|
35
- spec.pattern = FileList['spec/**/*_spec.rb']
36
- end
37
-
38
- RSpec::Core::RakeTask.new(:rcov) do |spec|
39
- spec.pattern = 'spec/**/*_spec.rb'
40
- spec.rcov = true
41
- end
42
-
43
- task :default => :spec
44
-
45
- require 'rdoc/task'
46
- Rake::RDocTask.new do |rdoc|
47
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
-
49
- rdoc.rdoc_dir = 'rdoc'
50
- rdoc.title = "helloworld #{version}"
51
- rdoc.rdoc_files.include('README*')
52
- rdoc.rdoc_files.include('lib/**/*.rb')
53
- end
54
-
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ require './lib/mvnizer/version.rb'
16
+ Jeweler::Tasks.new do |gem|
17
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
18
+ gem.name = "mvnizer"
19
+ gem.version = Mvnizer::Version::STRING
20
+ gem.homepage = "http://github.com/tychobrailleur/mvnizer"
21
+ gem.license = "MIT"
22
+ gem.summary = %Q{Bootstrap a Maven project without the pain of archetypes.}
23
+ gem.description = %Q{Bootstrap a Maven project without the pain of archetypes.}
24
+ gem.email = "sebastien@weblogism.com"
25
+ gem.authors = ["Sébastien Le Callonnec"]
26
+
27
+ gem.executables = ['mvnizer']
28
+ # dependencies defined in Gemfile
29
+ end
30
+ Jeweler::RubygemsDotOrgTasks.new
31
+
32
+ require 'rspec/core'
33
+ require 'rspec/core/rake_task'
34
+ RSpec::Core::RakeTask.new(:spec) do |spec|
35
+ spec.pattern = FileList['spec/**/*_spec.rb']
36
+ end
37
+
38
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
39
+ spec.pattern = 'spec/**/*_spec.rb'
40
+ spec.rcov = true
41
+ end
42
+
43
+ task :default => :spec
44
+
45
+ require 'rdoc/task'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "helloworld #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
54
+
55
55
  # -*- coding: utf-8 -*-
data/TODO.md ADDED
@@ -0,0 +1,14 @@
1
+ - Provide full or partial coordinates to define project coordinates. e.g. here are a list of valid values for mvnizer:
2
+
3
+ blah
4
+ blah:1.0.0-SNAPSHOT
5
+ blah:war
6
+ com.weblogism:blah
7
+ com.weblogism:blah:1.0.0-SNAPSHOT
8
+ com.weblogism:blah:war
9
+ - Depending on type of artifact (jar, war, etc.), generate appropriate pom and structure.
10
+ - Provide way to add dependency to pom given coordinates, e.g.:
11
+
12
+ mvnizer add org.junit:junit:4.10
13
+ - Provide dependency search facility.
14
+ - Support external config file (e.g. ~/.mvnizerrc) to override current defaults.
data/bin/mvnizer CHANGED
@@ -1,35 +1,41 @@
1
- #!/usr/bin/env ruby
2
-
3
- $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
4
- require 'mvnizer'
5
- require 'optparse'
6
-
7
-
8
- help = <<HELP
9
- Mvnizer bootstraps a Maven project without the pain of archetypes.
10
-
11
- mvnizer <project_name>
12
- HELP
13
-
14
- options = {}
15
-
16
- opts = OptionParser.new do |opts|
17
- opts.banner = help
18
-
19
- opts.on("--version", "Display current version") do
20
- puts "Mvnizer " + Mvnizer::Version::STRING
21
- exit 0
22
- end
23
- end
24
-
25
- # Read command line options into `options` hash
26
- opts.parse!
27
-
28
- if ARGV.size == 1
29
- options[:name] = ARGV[0]
30
- else
31
- puts "Incorrect parameters. Please `mvnizer --help` for usage."
32
- exit(1)
33
- end
34
-
35
- Mvnizer::Mvnize.new.run(options)
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
4
+ require 'mvnizer'
5
+ require 'optparse'
6
+
7
+
8
+ help = <<HELP
9
+ Mvnizer bootstraps a Maven project without the pain of archetypes.
10
+
11
+ mvnizer new <project_name>
12
+ HELP
13
+
14
+ options = {}
15
+
16
+ opts = OptionParser.new do |opts|
17
+ opts.banner = help
18
+
19
+ opts.on_tail("-h", "--help", "Show this message") do
20
+ puts opts
21
+ exit
22
+ end
23
+
24
+ opts.on("--version", "Display current version") do
25
+ puts "Mvnizer " + Mvnizer::Version::STRING
26
+ exit 0
27
+ end
28
+ end
29
+
30
+ # Read command line options into `options` hash
31
+ opts.parse!
32
+
33
+ if ARGV.size == 2
34
+ options[:command] = ARGV[0]
35
+ options[:name] = ARGV[1]
36
+ else
37
+ puts "Incorrect parameters. Please `mvnizer --help` for usage."
38
+ exit(1)
39
+ end
40
+
41
+ Mvnizer::Mvnize.new.run(options)
data/conf/default.yml CHANGED
@@ -1,2 +1,4 @@
1
- group_id: com.weblogism
2
- version: 0.0.1-SNAPSHOT
1
+ group_id: com.example
2
+ version: 0.0.1-SNAPSHOT
3
+ type: jar
4
+ dependencies: [ "junit:junit:4.10:jar:test" ]
@@ -0,0 +1,49 @@
1
+ module Mvnizer
2
+ module Command
3
+ class NewProject
4
+ include Mvnizer::Configuration
5
+
6
+ def initialize(generator = Mvnizer::PomGenerator.new,
7
+ dir_creator = Mvnizer::DirCreator.new,
8
+ coordinate_parser = Mvnizer::CoordinateParser.new)
9
+ @generator = generator
10
+ @dir_creator = dir_creator
11
+ @coordinate_parser = coordinate_parser
12
+ end
13
+
14
+ # Creates the Maven project structure, and creates the pom file
15
+ # from the options
16
+ def run(options)
17
+ @project = define_project(options)
18
+
19
+ @dir_creator.create("#{@project.artifact_id}/src/main/java",
20
+ "#{@project.artifact_id}/src/test/java")
21
+
22
+ File.open("#{@project.artifact_id}/pom.xml", "w") do |f|
23
+ f.write(@generator.generate(@project))
24
+ end
25
+ end
26
+
27
+ private
28
+ # Creates an instance of +Project+ class populated with the coordinates
29
+ # set with the user’s definition, or default values if not set.
30
+ def define_project(options)
31
+ coordinates = options[:name]
32
+ options = conf(options)
33
+
34
+ project = @coordinate_parser.parse(coordinates)
35
+ return_project = Project.new(project.group_id || options[:group_id],
36
+ project.artifact_id,
37
+ project.version || options[:version],
38
+ project.type || options[:type])
39
+
40
+ dependencies = options[:dependencies]
41
+ dependencies.each do |d|
42
+ return_project.add_dependency(@coordinate_parser.parse_scoped_coordinates(d))
43
+ end if dependencies
44
+
45
+ return_project
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,20 @@
1
+ module Mvnizer
2
+ module Command
3
+ class NewWarProject < NewProject
4
+ def run(options)
5
+ super
6
+
7
+ @dir_creator.create("#{@project.artifact_id}/src/main/webapp/WEB-INF")
8
+
9
+ # web.xml is optional in Servlet 3.0
10
+ # Do we keep its generation here?
11
+ web_xml = File.join(File.dirname(__FILE__), '..', 'templates', 'web.xml.erb')
12
+ FileUtils.cp(web_xml, "#{@project.artifact_id}/src/main/webapp/WEB-INF/web.xml")
13
+
14
+ # TODO:
15
+ # Create sample @WebServlet?
16
+ # Add JEE dependencies into pom.
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+ module Mvnizer
3
+ module Command
4
+ class ProjectFactory
5
+ def self.create(type)
6
+ case type
7
+ when "jar"
8
+ return NewProject.new
9
+ when "war"
10
+ require 'mvnizer/commands/new_war_project'
11
+ return NewWarProject.new
12
+ else
13
+ raise ArgumentError, "Don’t know how to create #{type}."
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,2 @@
1
+ require 'mvnizer/commands/new_project'
2
+ require 'mvnizer/commands/project_factory'
@@ -1,21 +1,24 @@
1
- require 'yaml'
2
-
3
- module Mvnizer
4
- module Configuration
5
- def conf(options)
6
- config_file = File.join(File.dirname(__FILE__), "..", "..", "conf", "default.yml")
7
- default_config = YAML.load_file(config_file)
8
-
9
- symbolize_keys(default_config.merge(symbolize_keys(options)))
10
- end
11
-
12
- private
13
- def symbolize_keys(hash)
14
- h = hash.dup
15
- h.keys.each do |key|
16
- h[(key.to_sym rescue key) || key] = h.delete(key)
17
- end
18
- h
19
- end
20
- end
21
- end
1
+ require 'yaml'
2
+
3
+ module Mvnizer
4
+ module Configuration
5
+ # Loads configuration from config/default.yml
6
+ # and merges the values into the passed options hash.
7
+ def conf(options)
8
+ config_file = File.join(File.dirname(__FILE__), "..", "..", "conf", "default.yml")
9
+
10
+ default_config = YAML.load_file(config_file)
11
+ symbolize_keys(default_config.merge(symbolize_keys(options)))
12
+ end
13
+
14
+ private
15
+ # Transforms all the keys in the hash into symbols
16
+ def symbolize_keys(hash)
17
+ h = hash.dup
18
+ h.keys.each do |key|
19
+ h[(key.to_sym rescue key) || key] = h.delete(key)
20
+ end
21
+ h
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,29 @@
1
+ module Mvnizer
2
+ class CoordinateParser
3
+ # Parse the coordinates of an artifact.
4
+ def parse(coordinates)
5
+ p = nil
6
+ # When no group and type is given
7
+ if coordinates =~ /\A([a-zA-Z][\w\.\-]+)(:(\d+\.\d+\.\d(\-\w+)?))?:(war|jar|pom)/
8
+ p = Project.new(nil, $1, $3, $5)
9
+ else
10
+ coordinates.scan(/(([a-zA-Z][\w\.\-]+):)?([a-zA-Z][\w\.\-]+)(:(\d+\.\d+\.\d(\-\w+)?))?(:(war|jar|pom))?/) do
11
+ |i,g,a,v0,v,m,t0,t|
12
+ p = Project.new(g, a, v, t)
13
+ end
14
+ end
15
+
16
+ p
17
+ end
18
+
19
+ # Parse the coordinates of a dependency, i.e. that include
20
+ # the scope (test, compile, provided, runtime, system or import)
21
+ def parse_scoped_coordinates(coordinates)
22
+ p = nil
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
+ p = Project.new($2, $3, $5, $8, [], $9)
25
+ end
26
+ p
27
+ end
28
+ end
29
+ end
@@ -1,10 +1,10 @@
1
- require 'fileutils'
2
-
3
- module Mvnizer
4
- class DirCreator
5
- # creates recursively all directories passed as a param.
6
- def create(*dir)
7
- dir.each { |d| FileUtils.mkdir_p d }
8
- end
9
- end
10
- end
1
+ require 'fileutils'
2
+
3
+ module Mvnizer
4
+ class DirCreator
5
+ # creates recursively all directories passed as a param.
6
+ def create(*dir)
7
+ dir.each { |d| FileUtils.mkdir_p d }
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,27 @@
1
+ module Mvnizer
2
+
3
+ # ERB utilities that needs to be brought into a class
4
+ # used as an ERB binding.
5
+ module Erbicole
6
+ # Path to folder storing all templates.
7
+ TEMPLATE_PATH = File.join(File.dirname(__FILE__), 'templates')
8
+
9
+ # Renders a template named `name` located in the templates
10
+ # folder.
11
+ def render(name, object = nil)
12
+ binding = get_binding
13
+
14
+ if object.respond_to?(:get_binding)
15
+ binding = object.get_binding
16
+ end
17
+
18
+ content = File.read(File.join(TEMPLATE_PATH, name))
19
+ ERB.new(content).result(binding)
20
+ end
21
+
22
+ # Return the ERB binding.
23
+ def get_binding
24
+ binding
25
+ end
26
+ end
27
+ end
@@ -1,23 +1,36 @@
1
- module Mvnizer
2
- class Mvnize
3
- include Configuration
4
-
5
- def initialize(generator = Mvnizer::PomGenerator.new, dir_creator = Mvnizer::DirCreator.new)
6
- @generator = generator
7
- @dir_creator = dir_creator
8
- end
9
-
10
- # Creates the Maven project structure, and creates the pom file
11
- # from the options
12
- def run(options)
13
- options = conf(options)
14
-
15
- @dir_creator.create("#{options[:name]}/src/main/java",
16
- "#{options[:name]}/src/test/java")
17
-
18
- File.open("#{options[:name]}/pom.xml", "w") do |f|
19
- f.write(@generator.generate(options))
20
- end
21
- end
22
- end
23
- end
1
+ module Mvnizer
2
+ # Mvnize is the main entry point into Mvnizer.
3
+ class Mvnize
4
+ attr_writer :out
5
+
6
+ def out
7
+ @out ||= $stdout
8
+ end
9
+
10
+ def self.new_project
11
+ @new_project ||= Mvnizer::Command::NewProject.new
12
+ end
13
+
14
+ # Execute the right command depending on the :command parameter
15
+ # passed in +options+.
16
+ # If the command does not exit, throw an error.
17
+ def run(options)
18
+ raise ArgumentError, "Please give a name to the project." unless options[:name]
19
+ if options[:command] == "new"
20
+ # FIXME: coordinates should be parsed here to check type.
21
+ # and pass to the factory, rather than doing this if,
22
+ # and parse coordinates later down in NewProject.
23
+ if options[:name] =~ /:war$/
24
+ project = Mvnizer::Command::ProjectFactory.create("war")
25
+ else
26
+ project = Mvnizer::Command::ProjectFactory.create("jar")
27
+ end
28
+
29
+ project.run(options)
30
+ out.puts("Project created successfully.")
31
+ else
32
+ raise ArgumentError, "#{options[:command]} is not a valid command."
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,25 +1,10 @@
1
- require 'erb'
2
-
3
- module Mvnizer
4
- class Project
5
- attr_reader :group_id, :artifact_id, :version
6
- def initialize(group_id, artifact_id, version)
7
- @group_id = group_id
8
- @artifact_id = artifact_id
9
- @version = version
10
- end
11
-
12
- def get_binding
13
- binding
14
- end
15
- end
16
-
17
- class PomGenerator
18
- # Creates the pom content by reading the erb template.
19
- def generate(options)
20
- template = File.open(File.join(File.dirname(__FILE__), 'templates', 'pom.xml.erb'), 'r').read
21
- project = Project.new(options[:group_id], options[:name], options[:version])
22
- ERB.new(template).result(project.get_binding)
23
- end
24
- end
25
- end
1
+ module Mvnizer
2
+ # This class handles the generation of the content of the pom file.
3
+ class PomGenerator
4
+ # Creates the pom content by reading the erb template.
5
+ def generate(project)
6
+ template = File.open(File.join(File.dirname(__FILE__), 'templates', 'pom.xml.erb'), 'r').read
7
+ ERB.new(template).result(project.get_binding)
8
+ end
9
+ end
10
+ end