vraptor-scaffold 0.0.1.rc → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +1 -1
- data/.gitignore +1 -0
- data/Gemfile +3 -3
- data/History.txt +10 -0
- data/README.textile +32 -0
- data/Rakefile +6 -7
- data/VERSION.yml +1 -1
- data/bin/vraptor +1 -1
- data/lib/configuration.rb +31 -0
- data/lib/generators/app_generator/app_generator.rb +75 -126
- data/lib/generators/app_generator/freemarker_template_engine.rb +50 -0
- data/lib/generators/app_generator/jsp_template_engine.rb +21 -0
- data/lib/generators/app_generator/templates/build.properties.erb +16 -0
- data/lib/generators/app_generator/templates/build.xml +109 -0
- data/lib/generators/app_generator/templates/decorators.erb +7 -0
- data/lib/generators/app_generator/templates/eclipse/classpath +23 -0
- data/lib/generators/app_generator/templates/eclipse/project.erb +36 -0
- data/lib/generators/app_generator/templates/eclipse/settings/org.eclipse.jdt.core.prefs +8 -0
- data/lib/generators/app_generator/templates/eclipse/settings/org.eclipse.wst.common.component.tt +10 -0
- data/lib/generators/app_generator/templates/eclipse/settings/org.eclipse.wst.common.project.facet.core.xml +10 -0
- data/lib/generators/app_generator/templates/eclipse/settings/org.eclipse.wst.jsdt.ui.superType.container +1 -0
- data/lib/generators/app_generator/templates/eclipse/settings/org.eclipse.wst.jsdt.ui.superType.name +1 -0
- data/lib/generators/app_generator/templates/freemarker/freemarker-ivy.xml +2 -0
- data/lib/generators/app_generator/templates/freemarker/freemarker-pom.xml +6 -0
- data/lib/generators/app_generator/templates/freemarker/freemarker-web.xml +23 -0
- data/lib/generators/app_generator/templates/freemarker/infrastructure/FreemarkerPathResolver.java.tt +21 -0
- data/lib/generators/app_generator/templates/{macros → freemarker/macros}/html.ftl +0 -0
- data/lib/generators/app_generator/templates/freemarker/main.ftl +14 -0
- data/lib/generators/app_generator/templates/ivy-2.2.0-rc1.jar +0 -0
- data/lib/generators/app_generator/templates/ivy.erb +35 -0
- data/lib/generators/app_generator/templates/jsp/main.jsp +16 -0
- data/lib/generators/app_generator/templates/pom.erb +24 -3
- data/lib/generators/app_generator/templates/{messages.properties → resources-test/.empty_directory} +0 -0
- data/lib/generators/app_generator/templates/{persistence.xml → resources/META-INF/persistence.xml} +0 -0
- data/lib/generators/app_generator/templates/{log4j.properties → resources/log4j.properties} +0 -0
- data/lib/generators/app_generator/templates/resources/messages.properties +0 -0
- data/lib/generators/app_generator/templates/src-test/controllers/.empty_directory +0 -0
- data/lib/generators/app_generator/templates/src-test/models/.empty_directory +0 -0
- data/lib/generators/app_generator/templates/src-test/repositories/.empty_directory +0 -0
- data/lib/generators/app_generator/templates/src/controllers/.empty_directory +0 -0
- data/lib/generators/app_generator/templates/src/models/Entity.java.tt +45 -0
- data/lib/generators/app_generator/templates/src/repositories/Repository.java.tt +43 -0
- data/lib/generators/app_generator/templates/vraptor-scaffold.erb +2 -0
- data/lib/generators/app_generator/templates/webapp/WEB-INF/web.xml +38 -0
- data/lib/generators/app_generator/templates/webapp/images/.empty_directory +0 -0
- data/lib/generators/app_generator/templates/{index.jsp → webapp/index.jsp} +0 -0
- data/lib/generators/app_generator/templates/{javascripts → webapp/javascripts}/jquery-1.4.2.min.js +0 -0
- data/lib/generators/app_generator/templates/{stylesheets → webapp/stylesheets}/scaffold.css +0 -0
- data/lib/generators/scaffold_generator/attribute.rb +14 -6
- data/lib/generators/scaffold_generator/base_scaffold.rb +14 -10
- data/lib/generators/scaffold_generator/controller_generator/controller_generator.rb +6 -6
- data/lib/generators/scaffold_generator/controller_generator/templates/controller.erb +7 -7
- data/lib/generators/scaffold_generator/controller_generator/templates/controller_test.erb +1 -1
- data/lib/generators/scaffold_generator/freemarker_generator/freemarker_generator.rb +5 -5
- data/lib/generators/scaffold_generator/freemarker_generator/templates/index.erb +2 -3
- data/lib/generators/scaffold_generator/jsp_generator/jsp_generator.rb +22 -0
- data/lib/generators/scaffold_generator/jsp_generator/templates/edit.erb +3 -0
- data/lib/generators/scaffold_generator/jsp_generator/templates/form.erb +27 -0
- data/lib/generators/scaffold_generator/jsp_generator/templates/index.erb +36 -0
- data/lib/generators/scaffold_generator/jsp_generator/templates/new.erb +3 -0
- data/lib/generators/scaffold_generator/jsp_generator/templates/show.erb +14 -0
- data/lib/generators/scaffold_generator/model_generator/model_generator.rb +5 -5
- data/lib/generators/scaffold_generator/model_generator/templates/model.erb +1 -1
- data/lib/generators/scaffold_generator/model_generator/templates/model_test.erb +1 -1
- data/lib/generators/scaffold_generator/repository_generator/repository_generator.rb +6 -5
- data/lib/generators/scaffold_generator/repository_generator/templates/repository.erb +17 -9
- data/lib/generators/scaffold_generator/repository_generator/templates/repository_impl.erb +16 -0
- data/lib/generators/scaffold_generator/repository_generator/templates/repository_test.erb +2 -2
- data/lib/generators/scaffold_generator/scaffold_generator.rb +31 -38
- data/lib/load_paths.rb +6 -2
- data/lib/vraptor-scaffold.rb +29 -5
- data/spec/lib/configuration_spec.rb +60 -0
- data/spec/lib/generators/app_generator/app_generator_spec.rb +237 -116
- data/spec/lib/generators/app_generator/freemarker_template_engine_spec.rb +92 -0
- data/spec/lib/generators/app_generator/jsp_template_engine_spec.rb +44 -0
- data/{lib → spec/lib}/generators/app_generator/templates/Entity.java +5 -2
- data/{lib → spec/lib}/generators/app_generator/templates/FreemarkerPathResolver.java +1 -1
- data/{lib → spec/lib}/generators/app_generator/templates/Repository.java +6 -6
- data/spec/lib/generators/app_generator/templates/build.properties +16 -0
- data/spec/lib/generators/app_generator/templates/decorators-jsp.xml +7 -0
- data/{lib → spec/lib}/generators/app_generator/templates/decorators.xml +2 -2
- data/spec/lib/generators/app_generator/templates/ivy.xml +35 -0
- data/spec/lib/generators/app_generator/templates/pom.xml +24 -3
- data/spec/lib/generators/scaffold_generator/attribute_spec.rb +47 -27
- data/spec/lib/generators/scaffold_generator/base_scaffold_spec.rb +31 -27
- data/spec/lib/generators/scaffold_generator/controller_generator/controller_generator_spec.rb +11 -9
- data/spec/lib/generators/scaffold_generator/controller_generator/templates/ProductController.java +2 -2
- data/spec/lib/generators/scaffold_generator/freemarker_generator/freemarker_generator_spec.rb +16 -14
- data/spec/lib/generators/scaffold_generator/jsp_generator/jsp_generator_spec.rb +34 -0
- data/spec/lib/generators/scaffold_generator/model_generator/model_generator_spec.rb +11 -9
- data/spec/lib/generators/scaffold_generator/repository_generator/repository_generator_spec.rb +17 -9
- data/spec/lib/generators/scaffold_generator/repository_generator/templates/ProductRepository.java +15 -7
- data/spec/lib/generators/scaffold_generator/repository_generator/templates/ProductRepositoryImpl.java +16 -0
- data/spec/lib/generators/scaffold_generator/scaffold_generator_spec.rb +55 -57
- data/spec/lib/vraptor-scaffold_spec.rb +77 -24
- data/spec/resources/vraptor-scaffold.properties +2 -0
- data/spec/spec_helper.rb +13 -1
- data/vraptor-scaffold.gemspec +82 -34
- metadata +86 -42
- data/README.rdoc +0 -104
- data/TODO.txt +0 -17
- data/lib/generators/app_generator/templates/main.ftl +0 -14
- data/lib/generators/app_generator/templates/web.xml +0 -61
@@ -1,11 +1,12 @@
|
|
1
1
|
class RepositoryGenerator < BaseScaffold
|
2
|
-
|
2
|
+
|
3
3
|
def self.source_root
|
4
|
-
File.dirname(__FILE__)
|
4
|
+
File.join File.dirname(__FILE__), "templates"
|
5
5
|
end
|
6
|
-
|
6
|
+
|
7
7
|
def build
|
8
|
-
template("
|
9
|
-
template("
|
8
|
+
template("repository.erb", Configuration.main_class_path("repositories", "#{repository_interface_name}.java"))
|
9
|
+
template("repository_impl.erb", Configuration.main_class_path("repositories", "#{repository_impl_name}.java"))
|
10
|
+
template("repository_test.erb", Configuration.test_class_path("repositories", "#{repository_test_class_name}.java"))
|
10
11
|
end
|
11
12
|
end
|
@@ -1,14 +1,22 @@
|
|
1
|
-
package
|
1
|
+
package <%= Configuration.package %>.repositories;
|
2
2
|
|
3
|
-
import
|
3
|
+
import java.util.List;
|
4
4
|
|
5
|
-
import
|
6
|
-
import app.models.<%= class_name %>;
|
5
|
+
import <%= Configuration.package %>.models.<%= class_name %>;
|
7
6
|
|
8
|
-
|
9
|
-
|
7
|
+
public interface <%= repository_interface_name %> {
|
8
|
+
/*
|
9
|
+
* Delete the methods you don't want to expose
|
10
|
+
*/
|
11
|
+
|
12
|
+
void create(<%= class_name %> entity);
|
13
|
+
|
14
|
+
void update(<%= class_name %> entity);
|
15
|
+
|
16
|
+
void destroy(<%= class_name %> entity);
|
17
|
+
|
18
|
+
<%= class_name %> find(Long id);
|
19
|
+
|
20
|
+
List<<%= class_name %>> findAll();
|
10
21
|
|
11
|
-
public <%= repository_class_name %>(EntityManager entityManager) {
|
12
|
-
super(entityManager);
|
13
|
-
}
|
14
22
|
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
package <%= Configuration.package %>.repositories;
|
2
|
+
|
3
|
+
import javax.persistence.EntityManager;
|
4
|
+
|
5
|
+
import br.com.caelum.vraptor.ioc.Component;
|
6
|
+
import <%= Configuration.package %>.models.<%= class_name %>;
|
7
|
+
|
8
|
+
@Component
|
9
|
+
public class <%= repository_impl_name %>
|
10
|
+
extends Repository<<%= class_name %>, Long>
|
11
|
+
implements <%= repository_interface_name %> {
|
12
|
+
|
13
|
+
public <%= repository_impl_name %>(EntityManager entityManager) {
|
14
|
+
super(entityManager);
|
15
|
+
}
|
16
|
+
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
package
|
1
|
+
package <%= Configuration.package %>.repositories;
|
2
2
|
|
3
3
|
import static org.junit.Assert.assertNotNull;
|
4
4
|
|
@@ -7,7 +7,7 @@ import org.junit.Test;
|
|
7
7
|
public class <%= repository_test_class_name %> {
|
8
8
|
|
9
9
|
@Test public void fakeTest() {
|
10
|
-
assertNotNull("put something real.", new <%=
|
10
|
+
assertNotNull("put something real.", new <%= repository_impl_name %>(null));
|
11
11
|
}
|
12
12
|
}
|
13
13
|
|
@@ -1,42 +1,35 @@
|
|
1
|
-
class ScaffoldGenerator
|
2
|
-
|
3
|
-
attr_accessor :
|
4
|
-
|
1
|
+
class ScaffoldGenerator < VraptorScaffold::Base
|
2
|
+
|
3
|
+
attr_accessor :generated_attributes
|
4
|
+
argument :model
|
5
|
+
argument :attributes, :type => :hash, :default => {}, :banner => "field:type field:type"
|
6
|
+
|
7
|
+
def self.banner
|
8
|
+
"vraptor scaffold #{self.arguments.map(&:usage).join(' ')}"
|
9
|
+
end
|
10
|
+
|
5
11
|
def initialize(args)
|
6
|
-
|
7
|
-
@
|
8
|
-
|
12
|
+
super(args)
|
13
|
+
@generated_attributes = []
|
14
|
+
attributes.each { |field, type|
|
15
|
+
@generated_attributes << Attribute.new(field, type)
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def controller_generator
|
20
|
+
ControllerGenerator.new(model, @generated_attributes).build
|
21
|
+
end
|
22
|
+
|
23
|
+
def model_generator
|
24
|
+
ModelGenerator.new(model, @generated_attributes).build
|
25
|
+
end
|
26
|
+
|
27
|
+
def repository_generator
|
28
|
+
RepositoryGenerator.new(model, @generated_attributes).build
|
9
29
|
end
|
10
|
-
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
ControllerGenerator.new(model, attributes).build
|
15
|
-
FreemarkerGenerator.new(model, attributes).build
|
30
|
+
|
31
|
+
def template_engine_generator
|
32
|
+
templates = {"jsp" => JspGenerator, "ftl" => FreemarkerGenerator}
|
33
|
+
templates[Configuration.template_engine].new(model, @generated_attributes).build
|
16
34
|
end
|
17
|
-
|
18
|
-
private
|
19
|
-
def validate_scaffold_command(args)
|
20
|
-
unless File.exist?("pom.xml")
|
21
|
-
puts "To run scaffold please go to the project root folder."
|
22
|
-
Kernel::exit
|
23
|
-
end
|
24
|
-
validate_attributes(args)
|
25
|
-
end
|
26
|
-
|
27
|
-
def validate_attributes(args)
|
28
|
-
args.each do |arg|
|
29
|
-
parsedAttribute = arg.split(":")
|
30
|
-
parse_attribute(parsedAttribute)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def parse_attribute(parsedAttribute)
|
35
|
-
type = parsedAttribute.last.downcase
|
36
|
-
unless Attribute.valid_types.include?(type)
|
37
|
-
puts "Attribute #{type} is not supported. The supported attributes types are: #{Attribute.valid_types.join(" ")}"
|
38
|
-
Kernel::exit
|
39
|
-
end
|
40
|
-
@attributes << Attribute.new(parsedAttribute.first, type)
|
41
|
-
end
|
42
35
|
end
|
data/lib/load_paths.rb
CHANGED
@@ -3,8 +3,13 @@ require 'rubygems'
|
|
3
3
|
require 'thor/actions'
|
4
4
|
require 'thor/group'
|
5
5
|
require 'active_support/inflector'
|
6
|
+
require 'yaml'
|
6
7
|
|
8
|
+
require File.dirname(__FILE__) + '/configuration'
|
7
9
|
require File.dirname(__FILE__) + '/../lib/generators/base'
|
10
|
+
require File.dirname(__FILE__) + '/../lib/generators/app_generator/app_generator'
|
11
|
+
require File.dirname(__FILE__) + '/../lib/generators/app_generator/freemarker_template_engine'
|
12
|
+
require File.dirname(__FILE__) + '/../lib/generators/app_generator/jsp_template_engine'
|
8
13
|
require File.dirname(__FILE__) + '/../lib/generators/scaffold_generator/attribute'
|
9
14
|
require File.dirname(__FILE__) + '/../lib/generators/scaffold_generator/scaffold_generator'
|
10
15
|
require File.dirname(__FILE__) + '/../lib/generators/scaffold_generator/base_scaffold'
|
@@ -12,5 +17,4 @@ require File.dirname(__FILE__) + '/../lib/generators/scaffold_generator/model_ge
|
|
12
17
|
require File.dirname(__FILE__) + '/../lib/generators/scaffold_generator/repository_generator/repository_generator'
|
13
18
|
require File.dirname(__FILE__) + '/../lib/generators/scaffold_generator/controller_generator/controller_generator'
|
14
19
|
require File.dirname(__FILE__) + '/../lib/generators/scaffold_generator/freemarker_generator/freemarker_generator'
|
15
|
-
require File.dirname(__FILE__) + '/../lib/generators/
|
16
|
-
|
20
|
+
require File.dirname(__FILE__) + '/../lib/generators/scaffold_generator/jsp_generator/jsp_generator'
|
data/lib/vraptor-scaffold.rb
CHANGED
@@ -2,11 +2,35 @@ require File.dirname(__FILE__) + '/load_paths'
|
|
2
2
|
|
3
3
|
module VraptorScaffold
|
4
4
|
class Main
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
|
6
|
+
def self.execute(args)
|
7
|
+
action = args.shift
|
8
|
+
print_help(AppGenerator) if help? action
|
9
|
+
run_app_generator(args.shift, args) if action == "new"
|
10
|
+
run_scaffold_generator(args) if action == "scaffold"
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.run_app_generator(project_path, args)
|
14
|
+
print_help(AppGenerator) if help? project_path
|
15
|
+
AppGenerator.new(project_path, args).invoke_all
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.run_scaffold_generator(args)
|
19
|
+
print_help(ScaffoldGenerator) if help? args.first
|
20
|
+
unless File.exist?("src")
|
21
|
+
puts "To run vraptor scaffold please go to the project root folder."
|
22
|
+
Kernel::exit
|
23
|
+
end
|
24
|
+
ScaffoldGenerator.new(args).invoke_all
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.print_help(generator)
|
28
|
+
generator.start(["-h"])
|
29
|
+
Kernel::exit
|
10
30
|
end
|
31
|
+
|
32
|
+
def self.help?(command)
|
33
|
+
[nil, "-h", "--help"].include?(command)
|
34
|
+
end
|
11
35
|
end
|
12
36
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
describe Configuration do
|
4
|
+
|
5
|
+
it "should configure main source" do
|
6
|
+
Configuration::MAIN_SRC.should == "src/main/java"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should configure main resources" do
|
10
|
+
Configuration::MAIN_RESOURCES.should == "src/main/resources"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should configure test source" do
|
14
|
+
Configuration::TEST_SRC.should == "src/test/java"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should configure test resources" do
|
18
|
+
Configuration::TEST_RESOURCES.should == "src/test/resources"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should configure webapp" do
|
22
|
+
Configuration::WEB_APP.should == "src/main/webapp"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should configure web-inf" do
|
26
|
+
Configuration::WEB_INF.should == "#{Configuration::WEB_APP}/WEB-INF"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should configure meta-inf" do
|
30
|
+
Configuration::META_INF.should == "#{Configuration::WEB_APP}/META-INF"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should configure properties name" do
|
34
|
+
Configuration::FILENAME.should == "#{Configuration::META_INF}/vraptor-scaffold.properties"
|
35
|
+
end
|
36
|
+
|
37
|
+
context "load config file" do
|
38
|
+
before(:each) do
|
39
|
+
config = {"template_engine" => "jsp", "package" => "br.com.caelum"}
|
40
|
+
YAML.stub!(:load_file).with(Configuration::FILENAME).and_return(config)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should know template engine" do
|
44
|
+
Configuration.template_engine.should == "jsp"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should know base package" do
|
48
|
+
Configuration.package.should == "br.com.caelum"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should build main class path with base package" do
|
52
|
+
Configuration.main_class_path("models", "Product.java").should == "src/main/java/br/com/caelum/models/Product.java"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should build test class path with base package" do
|
56
|
+
Configuration.test_class_path("models", "Product.java").should == "src/test/java/br/com/caelum/models/Product.java"
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -1,199 +1,320 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper")
|
2
2
|
|
3
3
|
describe AppGenerator do
|
4
|
-
|
5
|
-
before(:all) do
|
6
|
-
@project_path = "src/vraptor-scaffold"
|
7
|
-
AppGenerator.new.build(@project_path)
|
8
|
-
end
|
9
|
-
|
10
|
-
after(:all) do
|
11
|
-
FileUtils.remove_dir("src")
|
12
|
-
end
|
13
|
-
|
4
|
+
|
14
5
|
context "build new application" do
|
6
|
+
before(:all) do
|
7
|
+
@project_path = "src/vraptor-scaffold"
|
8
|
+
AppGenerator.new(@project_path, ["-b=mvn"]).invoke_all
|
9
|
+
end
|
10
|
+
|
11
|
+
after(:all) do
|
12
|
+
FileUtils.remove_dir("src")
|
13
|
+
end
|
14
|
+
|
15
15
|
it "should create directory with project name" do
|
16
16
|
File.exist?(@project_path).should be_true
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
it "should create pom" do
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
source = File.join File.dirname(__FILE__), "templates", "pom.xml"
|
21
|
+
destination = "#{@project_path}/pom.xml"
|
22
|
+
exists_and_identical?(source, destination)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "cannot create ivy.xml" do
|
26
|
+
File.exist?("#{@project_path}/ivy.xml").should be_false
|
23
27
|
end
|
24
28
|
|
29
|
+
it "cannot create eclipse wtp" do
|
30
|
+
File.exist?("#{@project_path}/.classpath").should be_false
|
31
|
+
end
|
32
|
+
|
25
33
|
context "creating main java" do
|
26
34
|
before(:all) do
|
27
|
-
@main_java = "#{@project_path}
|
35
|
+
@main_java = "#{@project_path}/#{Configuration::MAIN_SRC}"
|
28
36
|
@app = "#{@main_java}/app"
|
29
37
|
end
|
30
|
-
|
38
|
+
|
31
39
|
it "should create source folder" do
|
32
40
|
File.exist?(@main_java).should be_true
|
33
41
|
end
|
34
|
-
|
42
|
+
|
35
43
|
it "should create app folder" do
|
36
44
|
File.exist?(@app).should be_true
|
37
45
|
end
|
38
|
-
|
46
|
+
|
39
47
|
it "should create controllers folder" do
|
40
48
|
File.exist?("#{@app}/controllers").should be_true
|
41
49
|
end
|
42
|
-
|
50
|
+
|
43
51
|
it "should create models folder" do
|
44
52
|
File.exist?("#{@app}/models").should be_true
|
45
53
|
end
|
46
|
-
|
54
|
+
|
47
55
|
it "should create generic entity" do
|
48
|
-
|
49
|
-
|
50
|
-
|
56
|
+
source = File.join File.dirname(__FILE__), "templates", "Entity.java"
|
57
|
+
destination = "#{@app}/models/Entity.java"
|
58
|
+
exists_and_identical?(source, destination)
|
51
59
|
end
|
52
|
-
|
53
|
-
it "should create
|
54
|
-
File.
|
55
|
-
|
56
|
-
|
57
|
-
it "should create path resolver" do
|
58
|
-
from = "#{AppGenerator.source_root}/templates/FreemarkerPathResolver.java"
|
59
|
-
to = "#{@app}/infrastructure/FreemarkerPathResolver.java"
|
60
|
-
FileUtils.compare_file(from, to).should be_true
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should create generic repository" do
|
64
|
-
from = "#{AppGenerator.source_root}/templates/Repository.java"
|
65
|
-
to = "#{@app}/repositories/Repository.java"
|
66
|
-
FileUtils.compare_file(from, to).should be_true
|
60
|
+
|
61
|
+
it "should create generic repository" do
|
62
|
+
source = File.join File.dirname(__FILE__), "templates", "Repository.java"
|
63
|
+
destination = "#{@app}/repositories/Repository.java"
|
64
|
+
exists_and_identical?(source, destination)
|
67
65
|
end
|
68
66
|
end
|
69
|
-
|
67
|
+
|
70
68
|
context "creating main resources" do
|
71
69
|
before(:all) do
|
72
|
-
@main_resources = "#{@project_path}
|
70
|
+
@main_resources = "#{@project_path}/#{Configuration::MAIN_RESOURCES}"
|
73
71
|
@meta_inf = "#{@main_resources}/META-INF"
|
74
72
|
end
|
75
|
-
|
73
|
+
|
76
74
|
it "should create resource folder" do
|
77
|
-
|
75
|
+
File.exist?(@main_resources).should be_true
|
78
76
|
end
|
79
|
-
|
77
|
+
|
80
78
|
it "should create log4j" do
|
81
|
-
|
82
|
-
|
83
|
-
|
79
|
+
source = "#{AppGenerator.source_root}/resources/log4j.properties"
|
80
|
+
destination = "#{@main_resources}/log4j.properties"
|
81
|
+
exists_and_identical?(source, destination)
|
84
82
|
end
|
85
|
-
|
83
|
+
|
86
84
|
it "should create messages resource" do
|
87
|
-
|
88
|
-
|
89
|
-
|
85
|
+
source = "#{AppGenerator.source_root}/resources/messages.properties"
|
86
|
+
destination = "#{@main_resources}/messages.properties"
|
87
|
+
exists_and_identical?(source, destination)
|
90
88
|
end
|
91
|
-
|
89
|
+
|
92
90
|
it "should create META-INF" do
|
93
|
-
|
91
|
+
File.exist?(@meta_inf).should be_true
|
94
92
|
end
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
93
|
+
|
94
|
+
it "should create persistence.xml" do
|
95
|
+
source = "#{AppGenerator.source_root}/resources/META-INF/persistence.xml"
|
96
|
+
destination = "#{@meta_inf}/persistence.xml"
|
97
|
+
exists_and_identical?(source, destination)
|
100
98
|
end
|
101
|
-
end
|
99
|
+
end
|
100
|
+
|
102
101
|
context "creating webapp" do
|
103
102
|
before(:all) do
|
104
|
-
@webapp = "#{@project_path}
|
105
|
-
@web_inf = "#{@
|
106
|
-
@decorators = "#{@webapp}/decorators"
|
103
|
+
@webapp = "#{@project_path}/#{Configuration::WEB_APP}"
|
104
|
+
@web_inf = "#{@project_path}/#{Configuration::WEB_INF}"
|
107
105
|
end
|
108
|
-
|
106
|
+
|
109
107
|
it "should create webapp folder" do
|
110
|
-
|
108
|
+
File.exist?(@webapp).should be_true
|
111
109
|
end
|
112
|
-
|
110
|
+
|
113
111
|
it "should create index" do
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
end
|
118
|
-
|
119
|
-
it "should create decorators folder" do
|
120
|
-
File.exist?(@decorators).should be_true
|
121
|
-
end
|
122
|
-
|
123
|
-
it "should create decorator file" do
|
124
|
-
from = "#{AppGenerator.source_root}/templates/main.ftl"
|
125
|
-
to = "#{@decorators}/main.ftl"
|
126
|
-
FileUtils.compare_file(from, to).should be_true
|
112
|
+
source = "#{AppGenerator.source_root}/webapp/index.jsp"
|
113
|
+
destination = "#{@webapp}/index.jsp"
|
114
|
+
exists_and_identical?(source, destination)
|
127
115
|
end
|
128
|
-
|
129
|
-
it "should create html macro file" do
|
130
|
-
from = "#{AppGenerator.source_root}/templates/macros/html.ftl"
|
131
|
-
to = "#{@webapp}/macros/html.ftl"
|
132
|
-
FileUtils.compare_file(from, to).should be_true
|
133
|
-
end
|
134
|
-
|
116
|
+
|
135
117
|
it "should create WEB-INF folder" do
|
136
|
-
|
118
|
+
File.exist?(@web_inf).should be_true
|
137
119
|
end
|
138
|
-
|
139
|
-
it "should create decorators.xml" do
|
140
|
-
from = "#{AppGenerator.source_root}/templates/decorators.xml"
|
141
|
-
to = "#{@web_inf}/decorators.xml"
|
142
|
-
FileUtils.compare_file(from, to).should be_true
|
143
|
-
end
|
144
|
-
|
120
|
+
|
145
121
|
it "should create web.xml" do
|
146
|
-
|
147
|
-
|
148
|
-
|
122
|
+
source = "#{AppGenerator.source_root}/webapp/WEB-INF/web.xml"
|
123
|
+
destination = "#{@web_inf}/web.xml"
|
124
|
+
exists_and_identical?(source, destination)
|
149
125
|
end
|
150
|
-
|
151
|
-
it "should create views folder" do
|
152
|
-
File.exist?("#{@web_inf}/views").should be_true
|
153
|
-
end
|
154
|
-
|
126
|
+
|
155
127
|
it "should create scaffold css" do
|
156
|
-
|
157
|
-
|
158
|
-
|
128
|
+
source = "#{AppGenerator.source_root}/webapp/stylesheets/scaffold.css"
|
129
|
+
destination = "#{@webapp}/stylesheets/scaffold.css"
|
130
|
+
exists_and_identical?(source, destination)
|
159
131
|
end
|
160
|
-
|
132
|
+
|
161
133
|
it "should create jquery js" do
|
162
|
-
|
163
|
-
|
164
|
-
|
134
|
+
source = "#{AppGenerator.source_root}/webapp/javascripts/jquery-1.4.2.min.js"
|
135
|
+
destination = "#{@webapp}/javascripts/jquery-1.4.2.min.js"
|
136
|
+
exists_and_identical?(source, destination)
|
165
137
|
end
|
166
|
-
|
138
|
+
|
167
139
|
it "should create images folder" do
|
168
|
-
|
140
|
+
File.exist?("#{@webapp}/images").should be_true
|
169
141
|
end
|
170
142
|
end
|
143
|
+
|
171
144
|
context "creating test" do
|
172
145
|
before(:all) do
|
173
|
-
@test_java = "#{@project_path}
|
174
|
-
@test_resource = "#{@project_path}
|
146
|
+
@test_java = "#{@project_path}/#{Configuration::TEST_SRC}"
|
147
|
+
@test_resource = "#{@project_path}/#{Configuration::TEST_RESOURCES}"
|
175
148
|
@app = "#{@test_java}/app"
|
176
149
|
end
|
177
|
-
|
150
|
+
|
178
151
|
it "should create test source folder" do
|
179
152
|
File.exist?(@test_java).should be_true
|
180
153
|
end
|
181
|
-
|
154
|
+
|
182
155
|
it "should create app folder" do
|
183
156
|
File.exist?(@app).should be_true
|
184
157
|
end
|
185
|
-
|
158
|
+
|
186
159
|
it "should create controllers folder" do
|
187
160
|
File.exist?("#{@app}/controllers").should be_true
|
188
161
|
end
|
189
|
-
|
162
|
+
|
190
163
|
it "should create models folder" do
|
191
164
|
File.exist?("#{@app}/models").should be_true
|
192
165
|
end
|
193
|
-
|
166
|
+
|
167
|
+
it "should create respositories folder" do
|
168
|
+
File.exist?("#{@app}/repositories").should be_true
|
169
|
+
end
|
170
|
+
|
194
171
|
it "should create test resource folder" do
|
195
172
|
File.exist?(@test_resource).should be_true
|
196
173
|
end
|
197
174
|
end
|
198
175
|
end
|
176
|
+
|
177
|
+
context "build app with complex package" do
|
178
|
+
|
179
|
+
before(:all) do
|
180
|
+
@project_path = "src/vraptor-scaffold"
|
181
|
+
AppGenerator.new(@project_path, ["-p=br.com.caelum"]).invoke_all
|
182
|
+
@main_java = "#{@project_path}/#{Configuration::MAIN_SRC}/br/com/caelum"
|
183
|
+
@test_java = "#{@project_path}/#{Configuration::TEST_SRC}/br/com/caelum"
|
184
|
+
end
|
185
|
+
|
186
|
+
after(:all) do
|
187
|
+
FileUtils.remove_dir("src")
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should create main path" do
|
191
|
+
File.exist?(@main_java).should be_true
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should create test path" do
|
195
|
+
File.exist?(@test_java).should be_true
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
|
200
|
+
context "configuring template engine" do
|
201
|
+
|
202
|
+
before(:each) do
|
203
|
+
@project_path = "src/vraptor-scaffold"
|
204
|
+
end
|
205
|
+
|
206
|
+
after(:each) do
|
207
|
+
FileUtils.remove_dir("src")
|
208
|
+
end
|
209
|
+
|
210
|
+
it "should configure freemarker template engine" do
|
211
|
+
template = mock(FreemarkerTemplateEngine)
|
212
|
+
FreemarkerTemplateEngine.stub!(:new).with(@project_path).and_return(template)
|
213
|
+
template.should_receive(:configure)
|
214
|
+
AppGenerator.new(@project_path, ["--template-engine=ftl"]).invoke_all
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should configure jsp template engine" do
|
218
|
+
template = mock(JspTemplateEngine)
|
219
|
+
JspTemplateEngine.stub!(:new).with(@project_path).and_return(template)
|
220
|
+
template.should_receive(:configure)
|
221
|
+
AppGenerator.new(@project_path).invoke_all
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
context "configuring ant application" do
|
226
|
+
|
227
|
+
before(:all) do
|
228
|
+
@project_path = "vraptor-scaffold"
|
229
|
+
AppGenerator.new(@project_path, ["-b=ant"]).invoke_all
|
230
|
+
end
|
231
|
+
|
232
|
+
after(:all) do
|
233
|
+
FileUtils.remove_dir(@project_path)
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should create build.xml" do
|
237
|
+
source = File.join AppGenerator.source_root, "build.xml"
|
238
|
+
destination = "#{@project_path}/build.xml"
|
239
|
+
exists_and_identical?(source, destination)
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should create build.properties" do
|
243
|
+
source = File.join File.dirname(__FILE__), "templates", "build.properties"
|
244
|
+
destination = "#{@project_path}/build.properties"
|
245
|
+
exists_and_identical?(source, destination)
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should create ivy.xml" do
|
249
|
+
source = File.join File.dirname(__FILE__), "templates", "ivy.xml"
|
250
|
+
destination = "#{@project_path}/ivy.xml"
|
251
|
+
exists_and_identical?(source, destination)
|
252
|
+
end
|
253
|
+
|
254
|
+
it "should copy ivy.jar" do
|
255
|
+
ivy = File.join @project_path, AppGenerator::IVY_JAR
|
256
|
+
File.exist?(ivy).should be_true
|
257
|
+
end
|
258
|
+
|
259
|
+
it "cannot create pom.xml" do
|
260
|
+
File.exist?("#{@project_path}/pom.xml").should be_false
|
261
|
+
end
|
262
|
+
|
263
|
+
context "eclipse wtp configuration" do
|
264
|
+
it "should create .project" do
|
265
|
+
project = File.join @project_path, ".project"
|
266
|
+
File.exist?(project).should be_true
|
267
|
+
end
|
268
|
+
|
269
|
+
it "should create .classpath" do
|
270
|
+
class_path = File.join @project_path, ".classpath"
|
271
|
+
File.exist?(class_path).should be_true
|
272
|
+
end
|
273
|
+
|
274
|
+
it "should create .settings" do
|
275
|
+
settings = File.join @project_path, ".settings"
|
276
|
+
File.exist?(settings).should be_true
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
context "skip eclipse configuration files" do
|
282
|
+
before(:all) do
|
283
|
+
@project_path = "vraptor-scaffold"
|
284
|
+
AppGenerator.new(@project_path, ["--skip-eclipse"]).invoke_all
|
285
|
+
end
|
286
|
+
|
287
|
+
after(:all) do
|
288
|
+
FileUtils.remove_dir(@project_path)
|
289
|
+
end
|
290
|
+
|
291
|
+
it "cannot create .classpath file" do
|
292
|
+
File.exist?("#{@project_path}/.classpath").should be_false
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
context "valid template engines" do
|
297
|
+
it "jsp should be valid" do
|
298
|
+
AppGenerator::TEMPLATE_ENGINES.include?("jsp").should be_true
|
299
|
+
end
|
300
|
+
|
301
|
+
it "freemarker should be valid" do
|
302
|
+
AppGenerator::TEMPLATE_ENGINES.include?("ftl").should be_true
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
context "valid build tools" do
|
307
|
+
it "ant should be valid" do
|
308
|
+
AppGenerator::BUILD_TOOLS.include?("ant").should be_true
|
309
|
+
end
|
310
|
+
|
311
|
+
it "maven should be valid" do
|
312
|
+
AppGenerator::BUILD_TOOLS.include?("mvn").should be_true
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
it "should configure banner" do
|
317
|
+
AppGenerator.banner.should == "vraptor new PROJECT_PATH [options]"
|
318
|
+
end
|
319
|
+
|
199
320
|
end
|