heroku-vraptor-scaffold 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.rdoc +188 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +30 -0
- data/LICENSE +22 -0
- data/README.md +23 -0
- data/README.textile +51 -0
- data/Rakefile +20 -0
- data/bin/heroku-vraptor +8 -0
- data/heroku-vraptor-scaffold.gemspec +28 -0
- data/index.sample.html +169 -0
- data/lib/vraptor-scaffold.rb +14 -0
- data/lib/vraptor-scaffold/configuration.rb +54 -0
- data/lib/vraptor-scaffold/execution.rb +22 -0
- data/lib/vraptor-scaffold/generators/app/app_generator.rb +161 -0
- data/lib/vraptor-scaffold/generators/app/dependency.rb +15 -0
- data/lib/vraptor-scaffold/generators/app/dependency_manager.rb +32 -0
- data/lib/vraptor-scaffold/generators/app/templates/angular/angular.js +14327 -0
- data/lib/vraptor-scaffold/generators/app/templates/bootstrap/bootstrap-responsive.css +9 -0
- data/lib/vraptor-scaffold/generators/app/templates/bootstrap/bootstrap.css +9 -0
- data/lib/vraptor-scaffold/generators/app/templates/bootstrap/bootstrap.js +6 -0
- data/lib/vraptor-scaffold/generators/app/templates/bootstrap/glyphicons-halflings-white.png +0 -0
- data/lib/vraptor-scaffold/generators/app/templates/bootstrap/glyphicons-halflings.png +0 -0
- data/lib/vraptor-scaffold/generators/app/templates/eclipse/classpath.erb +18 -0
- data/lib/vraptor-scaffold/generators/app/templates/eclipse/project.erb +36 -0
- data/lib/vraptor-scaffold/generators/app/templates/eclipse/settings/org.eclipse.jdt.core.prefs +8 -0
- data/lib/vraptor-scaffold/generators/app/templates/eclipse/settings/org.eclipse.wst.common.component.tt +10 -0
- data/lib/vraptor-scaffold/generators/app/templates/eclipse/settings/org.eclipse.wst.common.project.facet.core.xml +10 -0
- data/lib/vraptor-scaffold/generators/app/templates/eclipse/settings/org.eclipse.wst.jsdt.ui.superType.container +1 -0
- data/lib/vraptor-scaffold/generators/app/templates/eclipse/settings/org.eclipse.wst.jsdt.ui.superType.name +1 -0
- data/lib/vraptor-scaffold/generators/app/templates/heroku/Main.java +21 -0
- data/lib/vraptor-scaffold/generators/app/templates/heroku/Procfile +1 -0
- data/lib/vraptor-scaffold/generators/app/templates/jquery/jquery.min.js +4 -0
- data/lib/vraptor-scaffold/generators/app/templates/models/Entity.erb +46 -0
- data/lib/vraptor-scaffold/generators/app/templates/orm/Repository-hibernate.java.tt +50 -0
- data/lib/vraptor-scaffold/generators/app/templates/orm/Repository-jpa.java.tt +48 -0
- data/lib/vraptor-scaffold/generators/app/templates/orm/Repository-objectify.java.tt +41 -0
- data/lib/vraptor-scaffold/generators/app/templates/orm/hibernate.cfg.xml +7 -0
- data/lib/vraptor-scaffold/generators/app/templates/orm/persistence.xml +10 -0
- data/lib/vraptor-scaffold/generators/app/templates/pom.erb +110 -0
- data/lib/vraptor-scaffold/generators/app/templates/resources-test/.empty_directory +0 -0
- data/lib/vraptor-scaffold/generators/app/templates/resources/hibernate.properties +16 -0
- data/lib/vraptor-scaffold/generators/app/templates/resources/log4j.properties +4 -0
- data/lib/vraptor-scaffold/generators/app/templates/resources/messages.properties +0 -0
- data/lib/vraptor-scaffold/generators/app/templates/underscore/underscore.min.js +32 -0
- data/lib/vraptor-scaffold/generators/app/templates/vraptor-scaffold.erb +5 -0
- data/lib/vraptor-scaffold/generators/app/templates/webapp/WEB-INF/web.xml.tt +33 -0
- data/lib/vraptor-scaffold/generators/app/templates/webapp/images/.empty_directory +0 -0
- data/lib/vraptor-scaffold/generators/app/templates/webapp/index.html +24 -0
- data/lib/vraptor-scaffold/generators/app/templates/webapp/javascripts/utils.js +7 -0
- data/lib/vraptor-scaffold/generators/base.rb +16 -0
- data/lib/vraptor-scaffold/generators/scaffold/attribute.rb +51 -0
- data/lib/vraptor-scaffold/generators/scaffold/base_scaffold.rb +54 -0
- data/lib/vraptor-scaffold/generators/scaffold/client_generator/client_generator.rb +41 -0
- data/lib/vraptor-scaffold/generators/scaffold/client_generator/templates/controller.erb +75 -0
- data/lib/vraptor-scaffold/generators/scaffold/client_generator/templates/details.erb +16 -0
- data/lib/vraptor-scaffold/generators/scaffold/client_generator/templates/form.erb +39 -0
- data/lib/vraptor-scaffold/generators/scaffold/client_generator/templates/list.erb +40 -0
- data/lib/vraptor-scaffold/generators/scaffold/controller_generator/controller_generator.rb +20 -0
- data/lib/vraptor-scaffold/generators/scaffold/controller_generator/templates/controller.erb +77 -0
- data/lib/vraptor-scaffold/generators/scaffold/controller_generator/templates/controller_test.erb +12 -0
- data/lib/vraptor-scaffold/generators/scaffold/model_generator/model_generator.rb +26 -0
- data/lib/vraptor-scaffold/generators/scaffold/model_generator/templates/model.erb +32 -0
- data/lib/vraptor-scaffold/generators/scaffold/model_generator/templates/model_test.erb +13 -0
- data/lib/vraptor-scaffold/generators/scaffold/repository_generator/repository_generator.rb +32 -0
- data/lib/vraptor-scaffold/generators/scaffold/repository_generator/templates/repository.erb +22 -0
- data/lib/vraptor-scaffold/generators/scaffold/repository_generator/templates/repository_impl.erb +16 -0
- data/lib/vraptor-scaffold/generators/scaffold/repository_generator/templates/repository_test.erb +13 -0
- data/lib/vraptor-scaffold/generators/scaffold/scaffold_generator.rb +35 -0
- data/lib/vraptor-scaffold/runner.rb +9 -0
- data/lib/vraptor-scaffold/runner/commands_help.rb +13 -0
- data/lib/vraptor-scaffold/runner/generator.rb +15 -0
- data/lib/vraptor-scaffold/runner/help.rb +12 -0
- data/lib/vraptor-scaffold/runner/scaffold.rb +16 -0
- data/lib/vraptor-scaffold/version.rb +3 -0
- data/maven/repo/br/com/caelum/vraptor-gae/1.0/vraptor-gae-1.0.jar +0 -0
- data/spec/resources/vraptor-scaffold-objectify.properties +7 -0
- data/spec/resources/vraptor-scaffold.properties +7 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/vraptor-scaffold/configuration_spec.rb +146 -0
- data/spec/vraptor-scaffold/execution_spec.rb +51 -0
- data/spec/vraptor-scaffold/generators/app/app_generator_spec.rb +557 -0
- data/spec/vraptor-scaffold/generators/app/dependency_manager_spec.rb +34 -0
- data/spec/vraptor-scaffold/generators/app/dependency_spec.rb +14 -0
- data/spec/vraptor-scaffold/generators/app/freemarker_template_engine_spec.rb +80 -0
- data/spec/vraptor-scaffold/generators/app/jsp_template_engine_spec.rb +77 -0
- data/spec/vraptor-scaffold/generators/app/templates/Entity.java +45 -0
- data/spec/vraptor-scaffold/generators/app/templates/FreemarkerPathResolver.java +21 -0
- data/spec/vraptor-scaffold/generators/app/templates/ObjectifyFactory.java +30 -0
- data/spec/vraptor-scaffold/generators/app/templates/RepositoryJPA.java +48 -0
- data/spec/vraptor-scaffold/generators/app/templates/RepositoryObjectify.java +41 -0
- data/spec/vraptor-scaffold/generators/app/templates/build.gradle +60 -0
- data/spec/vraptor-scaffold/generators/app/templates/build.properties +18 -0
- data/spec/vraptor-scaffold/generators/app/templates/build.xml +146 -0
- data/spec/vraptor-scaffold/generators/app/templates/classpath-gae +18 -0
- data/spec/vraptor-scaffold/generators/app/templates/decorators-jsp.xml +7 -0
- data/spec/vraptor-scaffold/generators/app/templates/decorators.xml +7 -0
- data/spec/vraptor-scaffold/generators/app/templates/freemarker-web.xml +60 -0
- data/spec/vraptor-scaffold/generators/app/templates/gae-jsp-web.xml +45 -0
- data/spec/vraptor-scaffold/generators/app/templates/ivy-gae.xml +45 -0
- data/spec/vraptor-scaffold/generators/app/templates/ivy.xml +40 -0
- data/spec/vraptor-scaffold/generators/app/templates/jsp-web.xml +45 -0
- data/spec/vraptor-scaffold/generators/app/templates/pom-heroku.xml +182 -0
- data/spec/vraptor-scaffold/generators/app/templates/pom.xml +157 -0
- data/spec/vraptor-scaffold/generators/app/templates/project-gae +47 -0
- data/spec/vraptor-scaffold/generators/app/templates/vraptor-scaffold.properties +7 -0
- data/spec/vraptor-scaffold/generators/plugin/expected_configs/build.gradle +62 -0
- data/spec/vraptor-scaffold/generators/plugin/expected_configs/default_org_build.gradle +62 -0
- data/spec/vraptor-scaffold/generators/plugin/expected_configs/default_org_ivy.xml +41 -0
- data/spec/vraptor-scaffold/generators/plugin/expected_configs/default_org_pom.xml +152 -0
- data/spec/vraptor-scaffold/generators/plugin/expected_configs/ivy.xml +42 -0
- data/spec/vraptor-scaffold/generators/plugin/expected_configs/pom.xml +182 -0
- data/spec/vraptor-scaffold/generators/scaffold/attribute_spec.rb +186 -0
- data/spec/vraptor-scaffold/generators/scaffold/base_scaffold_spec.rb +73 -0
- data/spec/vraptor-scaffold/generators/scaffold/client_controller_generator/controller_generator_spec.rb +62 -0
- data/spec/vraptor-scaffold/generators/scaffold/client_controller_generator/templates/ProductController.java +95 -0
- data/spec/vraptor-scaffold/generators/scaffold/controller_generator/controller_generator_spec.rb +62 -0
- data/spec/vraptor-scaffold/generators/scaffold/controller_generator/templates/ProductController.java +95 -0
- data/spec/vraptor-scaffold/generators/scaffold/freemarker_generator/freemarker_generator_spec.rb +81 -0
- data/spec/vraptor-scaffold/generators/scaffold/freemarker_generator/templates/form.ftl +28 -0
- data/spec/vraptor-scaffold/generators/scaffold/jsp_generator/jsp_generator_spec.rb +81 -0
- data/spec/vraptor-scaffold/generators/scaffold/jsp_generator/templates/form.jsp +61 -0
- data/spec/vraptor-scaffold/generators/scaffold/model_generator/model_generator_spec.rb +54 -0
- data/spec/vraptor-scaffold/generators/scaffold/model_generator/objectify_model_generator_spec.rb +40 -0
- data/spec/vraptor-scaffold/generators/scaffold/model_generator/templates/ObjectifyFactory.java +33 -0
- data/spec/vraptor-scaffold/generators/scaffold/model_generator/templates/Objectify_Product.java +38 -0
- data/spec/vraptor-scaffold/generators/scaffold/model_generator/templates/Product.java +25 -0
- data/spec/vraptor-scaffold/generators/scaffold/model_generator/templates/hibernate.cfg.xml +8 -0
- data/spec/vraptor-scaffold/generators/scaffold/repository_generator/objectify_repository_generator_spec.rb +33 -0
- data/spec/vraptor-scaffold/generators/scaffold/repository_generator/repository_generator_spec.rb +68 -0
- data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/ClientRepository.java +22 -0
- data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/ClientRepositoryImpl.java +16 -0
- data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/Objectify_ProductRepository.java +22 -0
- data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/Objectify_ProductRepositoryImpl.java +16 -0
- data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/ProductRepository.java +22 -0
- data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/ProductRepositoryImpl.java +16 -0
- data/spec/vraptor-scaffold/generators/scaffold/scaffold_generator_spec.rb +79 -0
- data/spec/vraptor-scaffold/http_request_spec.rb +40 -0
- data/spec/vraptor-scaffold/runner/commands_help_spec.rb +12 -0
- data/spec/vraptor-scaffold/runner/configure_spec.rb +12 -0
- data/spec/vraptor-scaffold/runner/generator_spec.rb +31 -0
- data/spec/vraptor-scaffold/runner/help_spec.rb +29 -0
- data/spec/vraptor-scaffold/runner/scaffold_spec.rb +35 -0
- data/spec/vraptor-scaffold/runner/start_spec.rb +51 -0
- data/spec/vraptor-scaffold_spec.rb +4 -0
- metadata +261 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper")
|
2
|
+
|
3
|
+
describe DependencyManager do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
others_dependency = mock(Dependency)
|
7
|
+
others_dependency.stub!(:exclusions).and_return([])
|
8
|
+
Dependency.stub!(:new).and_return(others_dependency)
|
9
|
+
@dependency = mock(Dependency)
|
10
|
+
end
|
11
|
+
|
12
|
+
context "compile scope" do
|
13
|
+
it "should include freemarker dependency when template is freemarker" do
|
14
|
+
options = {:template_engine => "ftl"}
|
15
|
+
Dependency.stub!(:new).with("org.freemarker", "freemarker", "2.3.18").and_return(@dependency)
|
16
|
+
DependencyManager.new(options).compile_scope.include?(@dependency).should be_true
|
17
|
+
end
|
18
|
+
|
19
|
+
context "dependencies for a gae app" do
|
20
|
+
it "should include gae dependencies when gae project option is selected" do
|
21
|
+
options = {:gae => true}
|
22
|
+
Dependency.stub!(:new).with("com.googlecode.objectify", "objectify", "3.1").and_return(@dependency)
|
23
|
+
DependencyManager.new(options).compile_scope.include?(@dependency).should be_true
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should not have hibernate persistence dependencies when gae project option is selected" do
|
27
|
+
options = {:gae => true}
|
28
|
+
Dependency.stub!(:new).with("org.hibernate", "hibernate-entitymanager", "3.6.7.Final").and_return(@dependency)
|
29
|
+
DependencyManager.new(options).compile_scope.include?(@dependency).should be_false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper")
|
2
|
+
|
3
|
+
describe Dependency do
|
4
|
+
|
5
|
+
it "should has exclusions" do
|
6
|
+
dependency = Dependency.new("org.vraptor", "vraptor3", "3.0.0", [Dependency.new("org.vraptor2", "2.0.0")])
|
7
|
+
dependency.has_exclusions?.should be_true
|
8
|
+
end
|
9
|
+
|
10
|
+
it "cannot has exclusions" do
|
11
|
+
dependency = Dependency.new("org.vraptor", "vraptor3", "3.0.0")
|
12
|
+
dependency.has_exclusions?.should be_false
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper")
|
2
|
+
|
3
|
+
describe FreemarkerTemplateEngine do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@project_path = "src/vraptor-scaffold"
|
7
|
+
@webapp = "#{@project_path}/#{Configuration::WEB_APP}"
|
8
|
+
@web_inf = "#{@project_path}/#{Configuration::WEB_INF}"
|
9
|
+
@decorators = "#{@web_inf}/views/decorators"
|
10
|
+
@app = "#{@project_path}/#{Configuration::MAIN_SRC}/br/com/caelum"
|
11
|
+
end
|
12
|
+
|
13
|
+
context "configuring" do
|
14
|
+
before(:all) do
|
15
|
+
AppGenerator.new(@project_path, ["--template-engine=ftl", "-p=br.com.caelum", "--orm=hibernate"]).invoke_all
|
16
|
+
end
|
17
|
+
|
18
|
+
after(:all) do
|
19
|
+
FileUtils.remove_dir(@project_path)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should create decorators.xml" do
|
23
|
+
source = File.join File.dirname(__FILE__), "templates", "decorators.xml"
|
24
|
+
destination = "#{@web_inf}/decorators.xml"
|
25
|
+
exists_and_identical?(source, destination)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should create web.xml" do
|
29
|
+
source = File.join File.dirname(__FILE__), "templates", "freemarker-web.xml"
|
30
|
+
destination = "#{@web_inf}/web.xml"
|
31
|
+
exists_and_identical?(source, destination)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should create views folder" do
|
35
|
+
File.exist?("#{@web_inf}/views").should be_true
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should create infrastructure folder" do
|
39
|
+
File.exist?("#{@app}/infrastructure").should be_true
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should create path resolver" do
|
43
|
+
source = File.join File.dirname(__FILE__), "templates", "FreemarkerPathResolver.java"
|
44
|
+
destination = "#{@app}/infrastructure/FreemarkerPathResolver.java"
|
45
|
+
exists_and_identical?(source, destination)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should create decorator file" do
|
49
|
+
destination = "#{@decorators}/main.ftl"
|
50
|
+
content = File.read(destination)
|
51
|
+
content.include?("bootstrap").should be_false
|
52
|
+
content.empty?.should be_false
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should create html macro file" do
|
56
|
+
source = "#{FreemarkerTemplateEngine.source_root}/macros/html.ftl"
|
57
|
+
destination = "#{@webapp}/macros/html.ftl"
|
58
|
+
exists_and_identical?(source, destination)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "bootstrap setup" do
|
63
|
+
before(:all) do
|
64
|
+
AppGenerator.new(@project_path, ["--template-engine=ftl", "--bootstrap"]).invoke_all
|
65
|
+
end
|
66
|
+
|
67
|
+
after(:all) do
|
68
|
+
FileUtils.remove_dir(@project_path)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should add bootstrap js and css" do
|
72
|
+
main = "#{@decorators}/main.ftl"
|
73
|
+
js_added = '<@html.js "bootstrap"/>'
|
74
|
+
css_added = '<@html.css "bootstrap"/>'
|
75
|
+
content = File.read(main)
|
76
|
+
content.include?(js_added).should be_true
|
77
|
+
content.include?(css_added).should be_true
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper")
|
2
|
+
|
3
|
+
describe JspTemplateEngine do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@project_path = "src/vraptor-scaffold"
|
7
|
+
@web_inf = "#{@project_path}/#{Configuration::WEB_INF}"
|
8
|
+
@decorators = "#{@web_inf}/jsp/decorators"
|
9
|
+
@app = "#{@project_path}/#{Configuration::MAIN_SRC}/app"
|
10
|
+
end
|
11
|
+
|
12
|
+
context "building a jsp application" do
|
13
|
+
before(:all) do
|
14
|
+
AppGenerator.new(@project_path).invoke_all
|
15
|
+
end
|
16
|
+
|
17
|
+
after(:all) do
|
18
|
+
FileUtils.remove_dir(@project_path)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should create decorators.xml" do
|
22
|
+
source = File.join File.dirname(__FILE__), "templates", "decorators-jsp.xml"
|
23
|
+
destination = "#{@web_inf}/decorators.xml"
|
24
|
+
exists_and_identical?(source, destination)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should create views folder" do
|
28
|
+
File.exist?("#{@web_inf}/jsp").should be_true
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should create decorator file" do
|
32
|
+
destination = "#{@decorators}/main.jsp"
|
33
|
+
File.exist?(destination).should be_true
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should not create infrastructure folder" do
|
37
|
+
File.exist?("#{@app}/infrastructure").should be_false
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should not create path resolver" do
|
41
|
+
to = "#{@app}/infrastructure/FreemarkerPathResolver.java"
|
42
|
+
File.exist?(to).should be_false
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should create web.xml" do
|
46
|
+
source = File.join File.dirname(__FILE__), "templates", "jsp-web.xml"
|
47
|
+
destination = "#{@web_inf}/web.xml"
|
48
|
+
exists_and_identical?(source, destination)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should create prelude.jspf" do
|
52
|
+
source = "#{JspTemplateEngine.source_root}/prelude.jspf"
|
53
|
+
destination = "#{@web_inf}/jsp/prelude.jspf"
|
54
|
+
exists_and_identical?(source, destination)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "bootstrap setup" do
|
59
|
+
before(:all) do
|
60
|
+
AppGenerator.new(@project_path, ["--template-engine=jsp", "--bootstrap"]).invoke_all
|
61
|
+
end
|
62
|
+
|
63
|
+
after(:all) do
|
64
|
+
FileUtils.remove_dir(@project_path)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should add bootstrap js and css" do
|
68
|
+
main = "#{@decorators}/main.jsp"
|
69
|
+
js_added = '<script type="text/javascript" src="/javascripts/bootstrap.js"></script>'
|
70
|
+
css_added = '<link rel="stylesheet" type="text/css" href="/stylesheets/bootstrap.css" />'
|
71
|
+
content = File.read(main)
|
72
|
+
content.include?(js_added).should be_true
|
73
|
+
content.include?(css_added).should be_true
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
package app.domain;
|
2
|
+
|
3
|
+
import javax.persistence.GeneratedValue;
|
4
|
+
import javax.persistence.Id;
|
5
|
+
import javax.persistence.MappedSuperclass;
|
6
|
+
|
7
|
+
@MappedSuperclass
|
8
|
+
public class Entity {
|
9
|
+
|
10
|
+
@Id @GeneratedValue
|
11
|
+
private Long id;
|
12
|
+
|
13
|
+
public void setId(Long id) {
|
14
|
+
this.id = id;
|
15
|
+
}
|
16
|
+
|
17
|
+
public Long getId() {
|
18
|
+
return id;
|
19
|
+
}
|
20
|
+
|
21
|
+
@Override
|
22
|
+
public boolean equals(Object obj) {
|
23
|
+
if (obj == null) {
|
24
|
+
return false;
|
25
|
+
}
|
26
|
+
if (this == obj) {
|
27
|
+
return true;
|
28
|
+
}
|
29
|
+
if (getClass() != obj.getClass()) {
|
30
|
+
return false;
|
31
|
+
}
|
32
|
+
final Entity other = (Entity) obj;
|
33
|
+
if (id != other.id && (id == null || !id.equals(other.id))) {
|
34
|
+
return false;
|
35
|
+
}
|
36
|
+
return true;
|
37
|
+
}
|
38
|
+
|
39
|
+
@Override
|
40
|
+
public int hashCode() {
|
41
|
+
int hash = 7;
|
42
|
+
hash = 17 * hash + (this.getId() != null ? this.getId().hashCode() : 0);
|
43
|
+
return hash;
|
44
|
+
}
|
45
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
package br.com.caelum.infrastructure;
|
2
|
+
|
3
|
+
import br.com.caelum.vraptor.http.FormatResolver;
|
4
|
+
import br.com.caelum.vraptor.ioc.Component;
|
5
|
+
import br.com.caelum.vraptor.view.DefaultPathResolver;
|
6
|
+
|
7
|
+
@Component
|
8
|
+
public class FreemarkerPathResolver extends DefaultPathResolver {
|
9
|
+
|
10
|
+
public FreemarkerPathResolver(FormatResolver resolver) {
|
11
|
+
super(resolver);
|
12
|
+
}
|
13
|
+
|
14
|
+
protected String getPrefix() {
|
15
|
+
return "/WEB-INF/views/";
|
16
|
+
}
|
17
|
+
|
18
|
+
protected String getExtension() {
|
19
|
+
return "ftl";
|
20
|
+
}
|
21
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
package app.infra;
|
2
|
+
|
3
|
+
import javax.annotation.PostConstruct;
|
4
|
+
|
5
|
+
import br.com.caelum.vraptor.ioc.Component;
|
6
|
+
import br.com.caelum.vraptor.ioc.ComponentFactory;
|
7
|
+
import br.com.caelum.vraptor.ioc.RequestScoped;
|
8
|
+
|
9
|
+
import com.googlecode.objectify.Objectify;
|
10
|
+
import com.googlecode.objectify.ObjectifyService;
|
11
|
+
|
12
|
+
@Component
|
13
|
+
@RequestScoped
|
14
|
+
public class ObjectifyFactory implements ComponentFactory<Objectify> {
|
15
|
+
|
16
|
+
private Objectify session;
|
17
|
+
|
18
|
+
static {
|
19
|
+
}
|
20
|
+
|
21
|
+
@PostConstruct
|
22
|
+
public void abreSession() {
|
23
|
+
session = ObjectifyService.begin();
|
24
|
+
}
|
25
|
+
|
26
|
+
@Override
|
27
|
+
public Objectify getInstance() {
|
28
|
+
return session;
|
29
|
+
}
|
30
|
+
}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
package app.repository;
|
2
|
+
|
3
|
+
import java.io.Serializable;
|
4
|
+
import java.lang.reflect.ParameterizedType;
|
5
|
+
import java.util.List;
|
6
|
+
|
7
|
+
import javax.persistence.EntityManager;
|
8
|
+
import javax.persistence.Query;
|
9
|
+
|
10
|
+
public abstract class Repository<T, I extends Serializable> {
|
11
|
+
|
12
|
+
protected final EntityManager entityManager;
|
13
|
+
protected final Class<T> clazz;
|
14
|
+
|
15
|
+
protected Repository(EntityManager entityManager) {
|
16
|
+
this.entityManager = entityManager;
|
17
|
+
|
18
|
+
@SuppressWarnings("unchecked")
|
19
|
+
Class<T> clazz = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
|
20
|
+
|
21
|
+
this.clazz = clazz;
|
22
|
+
}
|
23
|
+
|
24
|
+
public void create(T entity) {
|
25
|
+
entityManager.persist(entity);
|
26
|
+
}
|
27
|
+
|
28
|
+
public T update(T entity) {
|
29
|
+
return entityManager.merge(entity);
|
30
|
+
}
|
31
|
+
|
32
|
+
public void destroy(T entity) {
|
33
|
+
entityManager.remove(entity);
|
34
|
+
}
|
35
|
+
|
36
|
+
public T find(I id) {
|
37
|
+
return entityManager.find(clazz, id);
|
38
|
+
}
|
39
|
+
|
40
|
+
public List<T> findAll() {
|
41
|
+
Query query = entityManager.createQuery("from " + clazz.getName());
|
42
|
+
|
43
|
+
@SuppressWarnings("unchecked")
|
44
|
+
List<T> resultList = query.getResultList();
|
45
|
+
|
46
|
+
return resultList;
|
47
|
+
}
|
48
|
+
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
package app.repositories;
|
2
|
+
|
3
|
+
import java.lang.reflect.ParameterizedType;
|
4
|
+
import java.util.List;
|
5
|
+
|
6
|
+
import com.googlecode.objectify.Objectify;
|
7
|
+
|
8
|
+
class Repository<T> {
|
9
|
+
|
10
|
+
protected final Objectify objectify;
|
11
|
+
|
12
|
+
public Repository(Objectify objectify) {
|
13
|
+
this.objectify = objectify;
|
14
|
+
}
|
15
|
+
|
16
|
+
public void create(T entity) {
|
17
|
+
objectify.put(entity);
|
18
|
+
}
|
19
|
+
|
20
|
+
public void update(T entity) {
|
21
|
+
objectify.put(entity);
|
22
|
+
}
|
23
|
+
|
24
|
+
public void destroy(T entity) {
|
25
|
+
objectify.delete(entity);
|
26
|
+
}
|
27
|
+
|
28
|
+
public T find(Long id) {
|
29
|
+
return objectify.get(getParameterizedClass(), id);
|
30
|
+
}
|
31
|
+
|
32
|
+
public List<T> findAll() {
|
33
|
+
return objectify.query(getParameterizedClass()).list();
|
34
|
+
}
|
35
|
+
|
36
|
+
@SuppressWarnings("unchecked")
|
37
|
+
private Class<T> getParameterizedClass() {
|
38
|
+
ParameterizedType parameterizedType = (ParameterizedType) getClass().getGenericSuperclass();
|
39
|
+
return (Class<T>) parameterizedType.getActualTypeArguments()[0];
|
40
|
+
}
|
41
|
+
}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
repositories {
|
2
|
+
mavenCentral()
|
3
|
+
}
|
4
|
+
|
5
|
+
apply plugin: 'java'
|
6
|
+
apply plugin: 'war'
|
7
|
+
apply plugin: 'jetty'
|
8
|
+
apply plugin: 'eclipse'
|
9
|
+
apply plugin: 'project-report'
|
10
|
+
|
11
|
+
sourceCompatibility = 1.6
|
12
|
+
targetCompatibility = 1.6
|
13
|
+
version = '1.0'
|
14
|
+
|
15
|
+
sourceSets {
|
16
|
+
main {
|
17
|
+
java {
|
18
|
+
srcDir 'src/main/java'
|
19
|
+
}
|
20
|
+
resources {
|
21
|
+
srcDir 'src/main/resources'
|
22
|
+
}
|
23
|
+
}
|
24
|
+
test {
|
25
|
+
java {
|
26
|
+
srcDir 'src/test/java'
|
27
|
+
}
|
28
|
+
resources {
|
29
|
+
srcDir 'src/test/resources'
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
sourceSets.main.classesDir = new File('src/main/webapp/WEB-INF/classes')
|
35
|
+
|
36
|
+
jettyRun.scanIntervalSeconds=3
|
37
|
+
jettyRun.contextPath = '/'
|
38
|
+
[jettyRunWar,jettyStop]*.stopPort = 8081
|
39
|
+
[jettyRunWar,jettyStop]*.stopKey = 'stopKey'
|
40
|
+
|
41
|
+
dependencies {
|
42
|
+
compile group: 'br.com.caelum', name: 'vraptor', version: '3.4.0'
|
43
|
+
compile group: 'opensymphony', name: 'sitemesh', version: '2.4.2'
|
44
|
+
compile group: 'javax.servlet', name: 'jstl', version: '1.2'
|
45
|
+
compile group: 'org.hsqldb', name: 'hsqldb', version: '2.2.8'
|
46
|
+
compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '4.0.1.Final'
|
47
|
+
compile group: 'org.hibernate', name: 'hibernate-c3p0', version: '4.0.1.Final'
|
48
|
+
compile group: 'org.hibernate', name: 'hibernate-validator', version: '4.2.0.Final'
|
49
|
+
compile group: 'joda-time', name: 'joda-time', version: '2.0'
|
50
|
+
compile group: 'com.thoughtworks.xstream', name: 'xstream', version: '1.4.1'
|
51
|
+
|
52
|
+
//Provided dependencies
|
53
|
+
providedCompile group: 'javax.servlet', name: 'servlet-api', version: '2.5'
|
54
|
+
providedCompile group: 'javax.servlet.jsp', name: 'jsp-api', version: '2.1'
|
55
|
+
|
56
|
+
//Test dependencies
|
57
|
+
testCompile group: 'junit', name: 'junit', version: '4.10'
|
58
|
+
testCompile group: 'org.hamcrest', name: 'hamcrest-all', version: '1.1'
|
59
|
+
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.9.0'
|
60
|
+
}
|