mvnizer 1.1.0 → 1.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1cf0ce88c3a1af4e9dbacfd988d7cd4a7ddd961b6020733e78bcde0285779b80
4
- data.tar.gz: 668289dcbdfce3d7cafe62d5f91cd9ba221dc26c4fa966767f7f762c94287c26
3
+ metadata.gz: 6bf5efb3ab3b0675e036cb927b33c0fedc65b525784b59c4d35aec74bb5f0b27
4
+ data.tar.gz: 0e35fceb9db2f91e1f8cf051653e98f24d6c5449dc2eb839098a63b24f2053b0
5
5
  SHA512:
6
- metadata.gz: a60436e23a7838d110414cc95cd2f8a4ed3603c8cb5af55c9698bce34ee6500a14b24dfaa674824a1c3954d65aebb1b5ef08c25bb547a690e1eb1335ac1d6761
7
- data.tar.gz: 478d0c81ee32e6beaf01bb1237388c19480a99771016f0da7aa49278a973029c106c90befc66510045d0f78ca335c08ae2df25fdc4af1cb34689795ee4d2cca5
6
+ metadata.gz: 22b459abf1bf9abe8d76a21837da8d7a8c87a93d0bf95aea63277289f82f82d57e5c369d7df1d2f5f9655244e5bd9914ecf66b9f8a54bd29de5a92a58e85faee
7
+ data.tar.gz: 0b6ad9ed09c7d90c8447a8608f56a5dadf24d9909377eb5da8347ef4bee4ec81256b38f4fa96e18a934745d52d359c2a33222899d0b1f5de020c3267cd9d1a9d
data/CHANGELOG.org CHANGED
@@ -1,3 +1,14 @@
1
+ * Mvnizer 1.2.0
2
+
3
+ - Add =--docker= option to generate =Dockerfile=
4
+ - Add =--logger= option to add logging dependencies to the project
5
+ - Add =--main=[Main class name]= option to generate main class, and set up =maven-shade-plugin= automatically.
6
+ - Fix bug with patch component of version not supporting multiple digits.
7
+
8
+ * Mvnizer 1.1.0
9
+
10
+ - Update nokogiri dependency to 1.12
11
+
1
12
  * Mvnizer 1.0.0
2
13
 
3
14
  - Release of major version!
data/Dockerfile CHANGED
@@ -10,8 +10,10 @@ RUN apt-get update -q && \
10
10
  apt-get install -qy git vim rvm --no-install-recommends && \
11
11
  apt-get clean
12
12
 
13
- RUN /bin/bash -l -c "rvm autolibs packages && rvm install 2.3.8"
14
- RUN /bin/bash -l -c "gem update --system && gem install bundler"
13
+ RUN /bin/bash -l -c "rvm autolibs packages && rvm install 2.7.0 && rvm use 2.7.0"
14
+ RUN /bin/bash -l -c "gem update -f --no-document --system && gem install bundler"
15
+
16
+ WORKDIR /mvnizer
15
17
 
16
18
  # To run:
17
19
  # docker run -t -i -v $(pwd):/mvnizer mvnizer-build:latest /bin/bash
data/README.org CHANGED
@@ -1,5 +1,4 @@
1
- Bootstraps a Maven project. Because archetypes shouldn't be so
2
- complicated.
1
+ Bootstraps a Maven project. Because archetypes shouldn't be so complicated.
3
2
 
4
3
  [[https://travis-ci.org/tychobrailleur/mvnizer][https://travis-ci.org/tychobrailleur/mvnizer.svg?branch=master]]
5
4
  [[https://badge.fury.io/rb/mvnizer][https://badge.fury.io/rb/mvnizer.svg]]
@@ -7,8 +6,7 @@ complicated.
7
6
 
8
7
  * Introduction
9
8
 
10
- Mvnizer is ideal to create a throwaway Maven project that adds
11
- junit as a dependency and sets up the Maven project structure.
9
+ Mvnizer is ideal to create a throwaway Maven project that adds junit as a dependency and sets up the Maven project structure.
12
10
 
13
11
  * Install
14
12
 
@@ -34,10 +32,7 @@ complicated.
34
32
  <group:>artifact<:version><:type>
35
33
  #+END_EXAMPLE
36
34
 
37
- with the values between angled brackets optional. =type= can only
38
- have one of the following three values: =jar= (default), =war= or
39
- =pom=. This command creates a project in the =artifact= folder,
40
- populating the proper values in the pom file.
35
+ with the values between angled brackets optional. =type= can only have one of the following three values: =jar= (default), =war= or =pom=. This command creates a project in the =artifact= folder, populating the proper values in the pom file.
41
36
 
42
37
  Here are some examples of valid commands:
43
38
 
@@ -52,11 +47,23 @@ Here are some examples of valid commands:
52
47
 
53
48
  The version *must* be of the form =major.minor.patch-classifier=.
54
49
 
50
+ *** Options
51
+
52
+ The following options can be used to add specific files to the project:
53
+
54
+ - =--docker= :: this creates a =Dockerfile= based on the Java 11 distroless base image. It assumes that the jar generated by the build can be executed using the =java -jar= command;
55
+ - =--main=[Main class name] :: this creates a class with a =main= method that can be executed using the =java -jar= command. It also adds the =maven-shade-plugin= to the pom, with this class as the main class.
56
+ - =--logger= :: this adds logging dependencies to the project. The jar added are defined as the =logging_deps= of the configuration file. The default are:
57
+
58
+ #+begin_src
59
+ logging_deps: [ "org.slf4j:slf4j-api:1.7.32:jar",
60
+ "org.slf4j:slf4j-simple:1.7.32:jar",
61
+ "ch.qos.logback:logback-core:1.2.6:jar" ]
62
+ #+end_src
63
+
55
64
  *** WAR Project
56
65
 
57
- If the type of project generated is =war=, a servlet
58
- (=ExampleServlet=) is generated, along with a JSP file and an
59
- empty =web.xml= file.
66
+ If the type of project generated is =war=, a servlet (=ExampleServlet=) is generated, along with a JSP file and an empty =web.xml= file.
60
67
 
61
68
  When running the Jetty plugin, /e.g./:
62
69
 
@@ -64,29 +71,24 @@ The version *must* be of the form =major.minor.patch-classifier=.
64
71
  mvn org.eclipse.jetty:jetty-maven-plugin:9.4.12.v20180830:run-war
65
72
  #+END_EXAMPLE
66
73
 
67
- the example can then be accessed at http://localhost:8080/hello
74
+ The example can then be accessed at http://localhost:8080/hello
68
75
 
69
76
  ** Add Dependency
70
77
 
71
- To add dependencies, you must be in the folder where the pom file
72
- you want to add the dependency to is.
78
+ To add dependencies, you must be in the folder where the pom file you want to add the dependency to is.
73
79
 
74
- To add a dependency, simply pass the coordinates of the dependency,
75
- and add scope if needed (if no scope is given, =compile= is
76
- assumed):
80
+ To add a dependency, simply pass the coordinates of the dependency, and add scope if needed (if no scope is given, =compile= is assumed):
77
81
 
78
82
  #+BEGIN_EXAMPLE
79
83
  mvnizer add org.apache.commons:commons-lang3:3.1:jar
80
84
  mvnizer add org.mockito:mockito-core:1.9.5-rc1:jar:test
81
85
  #+END_EXAMPLE
82
86
 
83
- The =search= features makes it easy to find the coordinates of the
84
- dependencies for you.
87
+ The =search= features makes it easy to find the coordinates of the dependencies for you.
85
88
 
86
89
  ** Dependency Search
87
90
 
88
- You can search for dependencies in the Maven central repository with
89
- the command:
91
+ You can search for dependencies in the Maven central repository with the command:
90
92
 
91
93
  #+BEGIN_EXAMPLE
92
94
  $ mvnizer search <text>
@@ -94,6 +96,6 @@ the command:
94
96
 
95
97
  * License
96
98
 
97
- MIT License.
99
+ MIT License.
98
100
 
99
- © Copyright 2012–2021 — Sébastien Le Callonnec
101
+ © Copyright 2012–2021 — Sébastien Le Callonnec
data/bin/mvnizer CHANGED
@@ -26,7 +26,7 @@ HELP
26
26
 
27
27
  options = {}
28
28
 
29
- opts = OptionParser.new do |opts|
29
+ opt_parser = OptionParser.new do |opts|
30
30
  opts.banner = help
31
31
 
32
32
  opts.on_tail("-h", "--help", "Show this message") do
@@ -38,10 +38,22 @@ opts = OptionParser.new do |opts|
38
38
  puts "Mvnizer " + Mvnizer::Version::STRING
39
39
  exit 0
40
40
  end
41
+
42
+ opts.on("--docker", "Create Dockerfile. Ignored if not `new' command.") do
43
+ options[:docker] = true
44
+ end
45
+
46
+ opts.on("--main [MAIN_CLASS]", "Create a main class with name MAIN_CLASS.") do |main|
47
+ options[:main] = main
48
+ end
49
+
50
+ opts.on("--logger", "Add logging dependencies. Ignored if not `new' command.") do
51
+ options[:logger] = true
52
+ end
41
53
  end
42
54
 
43
55
  # Read command line options into `options` hash
44
- opts.parse!
56
+ opt_parser.parse!
45
57
 
46
58
  if ARGV.size == 2
47
59
  options[:command] = ARGV[0]
data/conf/default.yml CHANGED
@@ -3,3 +3,6 @@ version: 0.0.1-SNAPSHOT
3
3
  type: jar
4
4
  dependencies: [ "org.junit.jupiter:junit-jupiter-engine:5.7.0:jar:test" ]
5
5
  plugins: [ ":maven-compiler-plugin:3.8.1" ]
6
+ logging_deps: [ "org.slf4j:slf4j-api:1.7.32:jar",
7
+ "org.slf4j:slf4j-simple:1.7.32:jar",
8
+ "ch.qos.logback:logback-core:1.2.6:jar" ]
@@ -24,6 +24,19 @@ module Mvnizer
24
24
  "#{project.artifact_id}/.editorconfig",
25
25
  project)
26
26
 
27
+ if project.main
28
+ target_directory = project.package_name.gsub(/\./, File::SEPARATOR)
29
+ generate_file(File.join(TEMPLATE_DIR, "Main.java.erb"),
30
+ "#{project.artifact_id}/src/main/java/#{target_directory}/#{project.main}.java",
31
+ project)
32
+ end
33
+
34
+ if project.docker
35
+ generate_file(File.join(TEMPLATE_DIR, "Dockerfile.erb"),
36
+ "#{project.artifact_id}/Dockerfile",
37
+ project)
38
+ end
39
+
27
40
  end
28
41
 
29
42
  # Returns the list of dependencies to be added for this type of project.
@@ -4,10 +4,10 @@ module Mvnizer
4
4
  def parse(coordinates)
5
5
  p = nil
6
6
  # When no group and type is given
7
- if coordinates =~ /\A([a-zA-Z][\w\.\-]+)(:(\d+\.\d+\.\d(\-\w+)?))?:(war|jar|pom)/
7
+ if coordinates =~ /\A([a-zA-Z][\w\.\-]+)(:(\d+\.\d+\.\d+(\-\w+)?))?:(war|jar|pom)/
8
8
  p = Project.new(nil, $1, $3, $5)
9
9
  else
10
- coordinates.scan(/(([a-zA-Z][\w\.\-]+):)?([a-zA-Z][\w\.\-]+)(:(\d+\.\d+\.\d(\-\w+)?))?(:(war|jar|pom))?/) do
10
+ coordinates.scan(/(([a-zA-Z][\w\.\-]+):)?([a-zA-Z][\w\.\-]+)(:(\d+\.\d+\.\d+(\-\w+)?))?(:(war|jar|pom))?/) do
11
11
  |i,g,a,v0,v,m,t0,t|
12
12
  p = Project.new(g, a, v, t)
13
13
  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):?(test|compile|provided|runtime|system|import)?/
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
@@ -17,19 +17,19 @@ module Mvnizer
17
17
  # passed in +options+.
18
18
  # If the command does not exit, throw an error.
19
19
  def run(options)
20
- raise ArgumentError, "Please give a name to the project." unless options[:name]
20
+ raise ArgumentError, 'Please give a name to the project.' unless options[:name]
21
21
 
22
22
  case options[:command]
23
- when "new"
23
+ when 'new'
24
24
  project_details = define_project(options)
25
- project_command = Mvnizer::Command::ProjectFactory.create(project_details.type)
26
25
 
26
+ project_command = Mvnizer::Command::ProjectFactory.create(project_details.type)
27
27
  project_command.run(project_details)
28
28
  out.puts("Project #{project_details.artifact_id} created successfully.")
29
- when "search"
29
+ when 'search'
30
30
  search_command = Command::SearchArtefact.new
31
31
  search_command.run(options)
32
- when "add"
32
+ when 'add'
33
33
  add_command = Command::AddDependency.new
34
34
  add_command.run(options)
35
35
  else
@@ -51,20 +51,27 @@ module Mvnizer
51
51
  return_project = Project.new(project.group_id || options[:group_id],
52
52
  project.artifact_id,
53
53
  project.version || options[:version],
54
- project.type || options[:type])
54
+ project.type || options[:type],
55
+ [], nil, [],
56
+ options[:main],
57
+ options[:docker] || false)
55
58
 
56
59
 
57
60
  # Get default dependencies, and add them after having parsed their coords.
58
61
  dependencies = options[:dependencies]
59
- dependencies.each do |d|
62
+ dependencies&.each do |d|
60
63
  return_project.add_dependency(@coordinate_parser.parse_scoped_coordinates(d))
61
- end if dependencies
64
+ end
62
65
 
66
+ # If logger is true, add logging dependencies.
67
+ options[:logging_deps]&.each do |d|
68
+ return_project.add_dependency(@coordinate_parser.parse_scoped_coordinates(d))
69
+ end
63
70
 
64
71
  plugins = options[:plugins]
65
- plugins.each do |p|
72
+ plugins&.each do |p|
66
73
  return_project.add_plugin(@coordinate_parser.parse_scoped_coordinates(p))
67
- end if plugins
74
+ end
68
75
 
69
76
  return_project
70
77
  end
@@ -3,9 +3,10 @@ module Mvnizer
3
3
  # The elements of the coordinates are read-only.
4
4
  class Project
5
5
  include Erbicole
6
- attr_reader :group_id, :artifact_id, :version, :type, :dependencies, :scope, :plugins
6
+ attr_reader :group_id, :artifact_id, :version, :type, :dependencies, :scope, :plugins, :main, :docker
7
7
 
8
- def initialize(group_id, artifact_id, version, type, dependencies = [], scope = nil, plugins = [])
8
+ def initialize(group_id, artifact_id, version, type, dependencies = [],
9
+ scope = nil, plugins = [], main = nil, docker = false)
9
10
  @group_id = group_id
10
11
  @artifact_id = artifact_id
11
12
  @version = version
@@ -13,6 +14,8 @@ module Mvnizer
13
14
  @dependencies = dependencies
14
15
  @scope = scope
15
16
  @plugins = plugins
17
+ @main = main
18
+ @docker = docker
16
19
  end
17
20
 
18
21
  def add_dependency(dependency)
@@ -25,11 +28,11 @@ module Mvnizer
25
28
 
26
29
  # Check whether the project coordinates of this project
27
30
  # match the ones of the other project.
28
- def ==(project)
29
- (group_id == project.group_id \
30
- && artifact_id == project.artifact_id \
31
- && version == project.version \
32
- && type == project.type)
31
+ def ==(other)
32
+ (group_id == other.group_id \
33
+ && artifact_id == other.artifact_id \
34
+ && version == other.version \
35
+ && type == other.type)
33
36
  end
34
37
 
35
38
  def package_name
@@ -0,0 +1,7 @@
1
+ FROM gcr.io/distroless/java-debian11:11
2
+ ARG JAR_FILE=<%= artifact_id %>-<%= version %>.<%= type %>
3
+
4
+ COPY --chown=nonroot:nonroot ./target/${JAR_FILE} /app/<%= artifact_id %>.<%= type %>
5
+ WORKDIR /app
6
+
7
+ CMD ["/app/<%= artifact_id %>.<%= type %>"]
@@ -0,0 +1,8 @@
1
+ package <%= package_name %>;
2
+
3
+
4
+ public class <%= main %> {
5
+ public static void main(String... args) {
6
+ System.out.println("Hello World!");
7
+ }
8
+ }
@@ -1,6 +1,6 @@
1
1
  <dependency>
2
2
  <groupId><%= group_id %></groupId>
3
3
  <artifactId><%= artifact_id %></artifactId>
4
- <version><%= version %></version>
5
- <% if scope && scope != "compile" %><scope><%= scope %></scope><% end %>
4
+ <version><%= version %></version><% if scope && scope != "compile" %>
5
+ <scope><%= scope %></scope><% end %>
6
6
  </dependency>
@@ -23,10 +23,29 @@
23
23
  <artifactId>maven-compiler-plugin</artifactId>
24
24
  <version>3.8.1</version>
25
25
  <configuration>
26
- <source>1.8</source>
27
- <target>1.8</target>
26
+ <source>11</source>
27
+ <target>11</target>
28
28
  </configuration>
29
- </plugin><% plugins.each do |p| if p %><%= render('_plugin.xml.erb', p) %><% end; end %>
29
+ </plugin><% if main %>
30
+ <plugin>
31
+ <artifactId>maven-shade-plugin</artifactId>
32
+ <version>3.2.4</version>
33
+ <executions>
34
+ <execution>
35
+ <phase>package</phase>
36
+ <goals>
37
+ <goal>shade</goal>
38
+ </goals>
39
+ <configuration>
40
+ <transformers>
41
+ <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
42
+ <mainClass><%= package_name %>.<%= main %></mainClass>
43
+ </transformer>
44
+ </transformers>
45
+ </configuration>
46
+ </execution>
47
+ </executions>
48
+ </plugin><% end %><% plugins.each do |p| if p %><%= render('_plugin.xml.erb', p) %><% end; end %>
30
49
  </plugins>
31
50
  </build>
32
51
  </project>
@@ -1,5 +1,5 @@
1
1
  module Mvnizer
2
2
  module Version
3
- STRING = '1.1.0'
3
+ STRING = '1.2.0'
4
4
  end
5
5
  end
data/mvnizer.gemspec CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
6
6
 
7
7
  s.require_paths = ["lib"]
8
8
  s.authors = ["S\u{e9}bastien Le Callonnec"]
9
- s.date = "2021-05-23"
10
- s.description = "Bootstrap a Maven project without the pain of archetypes."
9
+ s.date = "2021-11-12"
10
+ s.description = "Generate a Maven project with pre-defined values, including pom file, gitignore, and more."
11
11
  s.email = "sebastien@weblogism.com"
12
12
  s.executables = ["mvnizer"]
13
13
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mvnizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sébastien Le Callonnec
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-23 00:00:00.000000000 Z
11
+ date: 2021-11-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Bootstrap a Maven project without the pain of archetypes.
13
+ description: Generate a Maven project with pre-defined values, including pom file,
14
+ gitignore, and more.
14
15
  email: sebastien@weblogism.com
15
16
  executables:
16
17
  - mvnizer
@@ -47,6 +48,8 @@ files:
47
48
  - lib/mvnizer/plugin.rb
48
49
  - lib/mvnizer/project.rb
49
50
  - lib/mvnizer/task_helper.rb
51
+ - lib/mvnizer/templates/Dockerfile.erb
52
+ - lib/mvnizer/templates/Main.java.erb
50
53
  - lib/mvnizer/templates/_dependency.xml.erb
51
54
  - lib/mvnizer/templates/_plugin.xml.erb
52
55
  - lib/mvnizer/templates/editorconfig.erb
@@ -64,7 +67,7 @@ homepage: http://github.com/tychobrailleur/mvnizer
64
67
  licenses:
65
68
  - MIT
66
69
  metadata: {}
67
- post_install_message:
70
+ post_install_message:
68
71
  rdoc_options: []
69
72
  require_paths:
70
73
  - lib
@@ -79,8 +82,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
82
  - !ruby/object:Gem::Version
80
83
  version: '0'
81
84
  requirements: []
82
- rubygems_version: 3.1.2
83
- signing_key:
85
+ rubygems_version: 3.2.17
86
+ signing_key:
84
87
  specification_version: 4
85
88
  summary: Bootstrap a Maven project without the pain of archetypes.
86
89
  test_files: []