Configuration can not be Optional, although the individual elements can be.
Signed-off-by: niclas <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/c782f071 Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/c782f071 Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/c782f071 Branch: refs/heads/develop Commit: c782f0713212792eb39b5a73265ab53e1327f078 Parents: 7e83d0b Author: niclas <[email protected]> Authored: Sun Jun 4 17:30:03 2017 +0800 Committer: niclas <[email protected]> Committed: Sun Jun 4 17:30:03 2017 +0800 ---------------------------------------------------------------------- .../cache/memcache/MemcachePoolMixin.java | 69 ++++----- tools/generator-polygene/app/index.js | 147 ++++++++++++------- .../DomainLayer/DomainModule/Configuration.tmpl | 10 +- .../DomainLayer/DomainModule/bootstrap.tmpl | 19 ++- .../DomainModule/config.properties.tmpl | 22 +++ .../DomainLayer/DomainModule/config.yaml.tmpl | 23 --- .../DomainLayer/DomainModule/module.js | 12 +- .../DomainLayer/JmxModule/bootstrap.tmpl | 2 +- .../StorageModule/bootstrap.tmpl | 13 +- .../InfrastructureLayer/StorageModule/module.js | 13 +- .../DevelopmentKeyManagement.java.tmpl | 28 +++- .../RestAPIApplication/Launcher.java.tmpl | 6 + .../app/templates/RestAPIApplication/app.js | 4 +- .../RestAPIApplication/bootstrap-test.tmpl | 17 ++- .../app/templates/buildtool/gradle-app.tmpl | 37 +++++ .../app/templates/buildtool/gradle-root.tmpl | 4 + .../src/docs/yeoman_polygene.txt | 76 ++++++++-- 17 files changed, 329 insertions(+), 173 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/extensions/cache-memcache/src/main/java/org/apache/polygene/cache/memcache/MemcachePoolMixin.java ---------------------------------------------------------------------- diff --git a/extensions/cache-memcache/src/main/java/org/apache/polygene/cache/memcache/MemcachePoolMixin.java b/extensions/cache-memcache/src/main/java/org/apache/polygene/cache/memcache/MemcachePoolMixin.java index dabaea0..3184865 100644 --- a/extensions/cache-memcache/src/main/java/org/apache/polygene/cache/memcache/MemcachePoolMixin.java +++ b/extensions/cache-memcache/src/main/java/org/apache/polygene/cache/memcache/MemcachePoolMixin.java @@ -28,7 +28,6 @@ import net.spy.memcached.ConnectionFactoryBuilder.Protocol; import net.spy.memcached.MemcachedClient; import net.spy.memcached.auth.AuthDescriptor; import net.spy.memcached.auth.PlainCallbackHandler; -import org.apache.polygene.api.common.Optional; import org.apache.polygene.api.configuration.Configuration; import org.apache.polygene.api.injection.scope.This; import org.apache.polygene.spi.cache.Cache; @@ -40,8 +39,10 @@ public class MemcachePoolMixin implements MemcachePoolService { private final Map<String, MemcacheImpl<?>> caches = new HashMap<>(); - @This @Optional + + @This private Configuration<MemcacheConfiguration> configuration; + private MemcachedClient client; private int expiration; @@ -49,41 +50,32 @@ public class MemcachePoolMixin public void activateService() throws Exception { - if( configuration != null ) - { - MemcacheConfiguration config = configuration.get(); - expiration = ( config.expiration().get() == null ) - ? 3600 - : config.expiration().get(); - String addresses = ( config.addresses().get() == null ) - ? "localhost:11211" - : config.addresses().get(); - Protocol protocol = ( config.protocol().get() == null ) - ? Protocol.TEXT - : Protocol.valueOf( config.protocol().get().toUpperCase() ); - String username = config.username().get(); - String password = config.password().get(); - String authMech = config.authMechanism().get() == null - ? "PLAIN" - : config.authMechanism().get(); - - ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder(); - builder.setProtocol( protocol ); - if( username != null && !username.isEmpty() ) - { - builder.setAuthDescriptor( - new AuthDescriptor( - new String[] - { - authMech - }, - new PlainCallbackHandler( username, password ) - ) - ); - } + MemcacheConfiguration config = configuration.get(); + expiration = ( config.expiration().get() == null ) + ? 3600 + : config.expiration().get(); + String addresses = ( config.addresses().get() == null ) + ? "localhost:11211" + : config.addresses().get(); + Protocol protocol = ( config.protocol().get() == null ) + ? Protocol.TEXT + : Protocol.valueOf( config.protocol().get().toUpperCase() ); + String username = config.username().get(); + String password = config.password().get(); + String authMech = config.authMechanism().get() == null + ? "PLAIN" + : config.authMechanism().get(); - client = new MemcachedClient( builder.build(), AddrUtil.getAddresses( addresses ) ); + ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder(); + builder.setProtocol( protocol ); + if( username != null && !username.isEmpty() ) + { + String[] authType = { authMech }; + AuthDescriptor to = new AuthDescriptor( authType, new PlainCallbackHandler( username, password ) ); + builder.setAuthDescriptor( to ); } + + client = new MemcachedClient( builder.build(), AddrUtil.getAddresses( addresses ) ); } @Override @@ -107,12 +99,7 @@ public class MemcachePoolMixin } synchronized( caches ) { - MemcacheImpl<?> cache = caches.get( cacheId ); - if( cache == null ) - { - cache = new MemcacheImpl<>( client, cacheId, valueType, expiration ); - caches.put( cacheId, cache ); - } + MemcacheImpl<?> cache = caches.computeIfAbsent( cacheId, identity -> new MemcacheImpl<>( client, identity, valueType, expiration ) ); cache.incRefCount(); return (Cache<T>) cache; } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/index.js ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/index.js b/tools/generator-polygene/app/index.js index cb9d214..b933c27 100644 --- a/tools/generator-polygene/app/index.js +++ b/tools/generator-polygene/app/index.js @@ -130,9 +130,8 @@ module.exports = generators.Base.extend( choices: [ 'BoneCP', 'DBCP' - // 'HikariCP' ], - message: 'Which entity store do you want to use?', + message: 'Which connection pool do you want to use?', default: polygene.dbpool ? polygene.dbpool : "DBCP", when: function (answers) { return answers.entitystore.indexOf('SQL') > -1; @@ -245,7 +244,7 @@ module.exports = generators.Base.extend( if (this.options.export) { exportModel(this.options.export); } - } catch( exception ) { + } catch (exception) { console.log(exception); throw exception; } @@ -282,6 +281,21 @@ function assignFunctions(polygene) { return polygene.features.indexOf(feature) >= 0; }; + polygene.copyToConfig = function (ctx, from, toName) { + polygene.copyTemplate(ctx, + from, + 'app/src/main/config/development/' + toName); + polygene.copyTemplate(ctx, + from, + 'app/src/main/config/qa/' + toName); + polygene.copyTemplate(ctx, + from, + 'app/src/main/config/staging/' + toName); + polygene.copyTemplate(ctx, + from, + 'app/src/main/config/production/' + toName); + }; + polygene.copyTemplate = function (ctx, from, to) { try { @@ -347,12 +361,16 @@ function assignFunctions(polygene) { var state = []; var imported = {}; var props = current.clazz.properties; + var idx; + var assoc; if (props) { imported["org.apache.polygene.api.property.Property"] = true; - for (var idx in props) { - var prop = props[idx]; - state.push('Property' + '<' + polygene.typeNameOnly(prop.type) + "> " + prop.name + "();"); - imported[prop.type] = true; + for (idx in props) { + if( props.hasOwnProperty(idx)) { + var prop = props[idx]; + state.push('Property' + '<' + polygene.typeNameOnly(prop.type) + "> " + prop.name + "();"); + imported[prop.type] = true; + } } } else { imported["org.apache.polygene.api.property.Property"] = true; @@ -361,76 +379,101 @@ function assignFunctions(polygene) { var assocs = current.clazz.associations; if (assocs) { imported["org.apache.polygene.api.association.Association"] = true; - for (var idx in assocs) { - var assoc = assocs[idx]; - state.push("Association" + '<' + polygene.typeNameOnly(assoc.type) + "> " + assoc.name + "();"); - imported[assoc.type] = true; + for (idx in assocs) { + if( assocs.hasOwnProperty(idx)) { + assoc = assocs[idx]; + state.push("Association" + '<' + polygene.typeNameOnly(assoc.type) + "> " + assoc.name + "();"); + imported[assoc.type] = true; + } } } assocs = current.clazz.manyassociations; if (assocs) { imported["org.apache.polygene.api.association.ManyAssociation"] = true; - for (var idx in assocs) { - var assoc = assocs[idx]; - state.push("ManyAssociation<" + polygene.typeNameOnly(assoc.type) + "> " + assoc.name + "();"); - imported[assoc.type] = true; + for (idx in assocs) { + if( assocs.hasOwnProperty(idx)) { + assoc = assocs[idx]; + state.push("ManyAssociation<" + polygene.typeNameOnly(assoc.type) + "> " + assoc.name + "();"); + imported[assoc.type] = true; + } } } assocs = current.clazz.namedassociations; if (assocs) { imported["org.apache.polygene.api.association.NamedAssociation"] = true; - for (var idx in assocs) { - var assoc = assocs[idx]; - state.push("NamedAssociation<" + polygene.typeNameOnly(assoc.type) + "> " + assoc.name + "();"); - imported[assoc.type] = true; + for (idx in assocs) { + if( assocs.hasOwnProperty(idx)){ + assoc = assocs[idx]; + state.push("NamedAssociation<" + polygene.typeNameOnly(assoc.type) + "> " + assoc.name + "();"); + imported[assoc.type] = true; + } } } current.state = state; current.imported = imported; }; - polygene.prepareConfigClazz = function (current) { + polygene.prepareConfigClazz = function (currentModule, composite) { var state = []; - var yaml = []; + var propertyFile = []; var imported = {}; - var props = current.clazz.configuration; + var props = composite.configuration; if (props) { imported["org.apache.polygene.api.property.Property"] = true; for (var idx in props) { - var prop = props[idx]; - state.push('Property' + '<' + polygene.typeNameOnly(prop.type) + "> " + prop.name + "();"); - imported[prop.type] = true; - var yamlDefault; - if (prop.type === "java.lang.String") { - yamlDefault = '""'; - } - else if (prop.type === "java.lang.Boolean") { - yamlDefault = 'false'; - } - else if (prop.type === "java.lang.Long") { - yamlDefault = '0'; - } - else if (prop.type === "java.lang.Integer") { - yamlDefault = '0'; - } - else if (prop.type === "java.lang.Double") { - yamlDefault = '0.0'; - } - else if (prop.type === "java.lang.Float") { - yamlDefault = '0.0'; - } - else { - yamlDefault = '\n # TODO: complex configuration type. '; + if (props.hasOwnProperty(idx)) { + var prop = props[idx]; + imported[prop.type] = true; + var propertyDefault; + if (prop.default !== undefined) { + propertyDefault = prop.default; + } else { + if (prop.type === "java.lang.String") { + propertyDefault = ''; + } + else if (prop.type === "java.lang.Boolean") { + propertyDefault = 'false'; + } + else if (prop.type === "java.lang.Long") { + propertyDefault = '0'; + } + else if (prop.type === "java.lang.Integer") { + propertyDefault = '0'; + } + else if (prop.type === "java.lang.Double") { + propertyDefault = '0.0'; + } + else if (prop.type === "java.lang.Float") { + propertyDefault = '0.0'; + } + else { + propertyDefault = '\n # TODO: complex configuration type. '; + } + } + state.push("/**"); + for( var idxDesc in prop.description ){ + if( prop.description.hasOwnProperty(idxDesc)){ + var desc = prop.description[idxDesc]; + propertyFile.push("# " + desc); + state.push(" * " + desc ) + } + } + state.push(" */"); + propertyFile.push(prop.name + "=" + propertyDefault +"\n"); + state.push('Property' + '<' + polygene.typeNameOnly(prop.type) + "> " + prop.name + "();\n"); } - yaml.push(prop.name + " : " + yamlDefault); } } else { imported["org.apache.polygene.api.property.Property"] = true; - state.push('Property<String> name(); // TODO: remove sample property'); - yaml.push('name : "sample config value"'); + state.push('/** TODO: remove sample property'); + state.push(' */'); + state.push('Property<String> name();'); + propertyFile.push("# This is just the sample configuration value. " ); + propertyFile.push("# TODO: Remove this config value " ); + propertyFile.push('name=sample config value'); } - current.state = state; - current.yaml = yaml; - current.imported = imported; + currentModule.state = state; + currentModule.propertyLines = propertyFile; + currentModule.imported = imported; }; } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/DomainLayer/DomainModule/Configuration.tmpl ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/DomainLayer/DomainModule/Configuration.tmpl b/tools/generator-polygene/app/templates/DomainLayer/DomainModule/Configuration.tmpl index b7acd94..e36bffb 100644 --- a/tools/generator-polygene/app/templates/DomainLayer/DomainModule/Configuration.tmpl +++ b/tools/generator-polygene/app/templates/DomainLayer/DomainModule/Configuration.tmpl @@ -18,6 +18,7 @@ * -%> package <%= polygene.packageName %>.model.<%= polygene.current.name %>; + <% for( var imp in polygene.current.imported ) { if( !imp.startsWith( "java.lang" ) @@ -26,10 +27,11 @@ for( var imp in polygene.current.imported ) { <% } } %> - public interface <%= polygene.current.clazz.name %> { -<% for( var idx in polygene.current.state ) { -%> <%- polygene.current.state[idx]; %> -<% } %> +<% +for( var idx in polygene.current.state ) { +%> + <%- polygene.current.state[idx]; %><% } +%>} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/DomainLayer/DomainModule/bootstrap.tmpl ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/DomainLayer/DomainModule/bootstrap.tmpl b/tools/generator-polygene/app/templates/DomainLayer/DomainModule/bootstrap.tmpl index 092d683..5afbdd7 100644 --- a/tools/generator-polygene/app/templates/DomainLayer/DomainModule/bootstrap.tmpl +++ b/tools/generator-polygene/app/templates/DomainLayer/DomainModule/bootstrap.tmpl @@ -69,8 +69,8 @@ if( polygene.current.cruds ) { for( var value in polygene.current.cruds ) { var crud = polygene.current.cruds[value]; %> - <%- "module.values( " + crud.name + ".class )" + (crud.visibility ? ".visibleIn(" + crud.visibility +")" : "" ) %>; - <%- "module.entities( " + crud.name + ".class )" + (crud.visibility ? ".visibleIn(" + crud.visibility +")" : "" ) %>; + <%- "module.values( " + crud.name + ".class )" + (crud.visibility ? ".visibleIn( " + crud.visibility +" )" : "" ) %>; + <%- "module.entities( " + crud.name + ".class )" + (crud.visibility ? ".visibleIn( " + crud.visibility +" )" : "" ) %>; <% } } @@ -78,7 +78,7 @@ if( polygene.current.values ) { for( var value in polygene.current.values ) { var v = polygene.current.values[value]; %> - <%- "module.values( " + v.name + ".class )" + (v.visibility ? ".visibleIn(" + v.visibility +")" : "" ) %>; + <%- "module.values( " + v.name + ".class )" + (v.visibility ? ".visibleIn(" + v.visibility +" )" : "" ) %>; <% } } @@ -86,7 +86,7 @@ if( polygene.current.entities ) { for( var value in polygene.current.entities ) { var entity = polygene.current.entities[value]; %> - <%- "module.entities( " + entity.name + ".class )" + (entity.visibility ? ".visibleIn(" + entity.visibility +")" : "" ) %>; + <%- "module.entities( " + entity.name + ".class )" + (entity.visibility ? ".visibleIn( " + entity.visibility +" )" : "" ) %>; <% } } @@ -94,7 +94,7 @@ if( polygene.current.transients ) { for( var value in polygene.current.transients ) { var trans = polygene.current.transients[value]; %> - <%- "module.transients( " + trans.name + ".class )" + (trans.visibility ? ".visibleIn(" + trans.visibility +")" : "" ) %>; + <%- "module.transients( " + trans.name + ".class )" + (trans.visibility ? ".visibleIn( " + trans.visibility +" )" : "" ) %>; <% } } @@ -102,7 +102,7 @@ if( polygene.current.objects ) { for( var value in polygene.current.objects ) { var obj = polygene.current.objects[value]; %> - <%- "module.objects( " + obj.name + ".class )" + (obj.visibility ? ".visibleIn(" + obj.visibility +")" : "" ) %>; + <%- "module.objects( " + obj.name + ".class )" + (obj.visibility ? ".visibleIn( " + obj.visibility +" )" : "" ) %>; <% } } @@ -110,8 +110,11 @@ if( polygene.current.services ) { for( var value in polygene.current.services ) { var service = polygene.current.services[value]; %> - <%- "module.services( " + service.name + ".class )" + (service.visibility ? ".visibleIn(" + service.visibility + ")" : "" ) %>; - <%- "module.entities( " + polygene.configurationClassName(service.name) + ".class )" %>; + module.services( <%- service.name %>.class ) + .identifiedBy("<%- service.name %>") + <%- (service.visibility ? " .visibleIn( " + service.visibility + " )" : "" ) +%>; + <%- "module.configurations( " + polygene.configurationClassName(service.name) + ".class )" %>; <% } } %> http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/DomainLayer/DomainModule/config.properties.tmpl ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/DomainLayer/DomainModule/config.properties.tmpl b/tools/generator-polygene/app/templates/DomainLayer/DomainModule/config.properties.tmpl new file mode 100644 index 0000000..a20c784 --- /dev/null +++ b/tools/generator-polygene/app/templates/DomainLayer/DomainModule/config.properties.tmpl @@ -0,0 +1,22 @@ +<%# + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * +-%> +<% for( var idx in polygene.current.propertyLines ) { +%><%- polygene.current.propertyLines[idx]; %> +<% } %> http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/DomainLayer/DomainModule/config.yaml.tmpl ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/DomainLayer/DomainModule/config.yaml.tmpl b/tools/generator-polygene/app/templates/DomainLayer/DomainModule/config.yaml.tmpl deleted file mode 100644 index e2629d5..0000000 --- a/tools/generator-polygene/app/templates/DomainLayer/DomainModule/config.yaml.tmpl +++ /dev/null @@ -1,23 +0,0 @@ -<%# - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * --%> -- -<% for( var idx in polygene.current.yaml ) { -%> <%- polygene.current.yaml[idx]; %> -<% } %> http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/DomainLayer/DomainModule/module.js ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/DomainLayer/DomainModule/module.js b/tools/generator-polygene/app/templates/DomainLayer/DomainModule/module.js index 8855bc3..f511c0f 100644 --- a/tools/generator-polygene/app/templates/DomainLayer/DomainModule/module.js +++ b/tools/generator-polygene/app/templates/DomainLayer/DomainModule/module.js @@ -49,7 +49,7 @@ function copyPolygeneDomainModule(p, moduleName, moduleDef) { copyComposites(p, moduleDef.plainTypes, "Plain"); copyComposites(p, moduleDef.services, "Configuration"); - copyConfigurationYaml(p, moduleDef.services ) + copyConfigurationPropertiesFile(p, moduleDef.services ) } function copyComposites(p, composites, type) { @@ -57,7 +57,9 @@ function copyComposites(p, composites, type) { if (composites.hasOwnProperty(idx)) { if( type === "Configuration"){ p.current.clazz.name = p.configurationClassName(composites[idx].name); - p.prepareConfigClazz(p.current); + delete p.current.type; + delete p.current.value; + p.prepareConfigClazz(p.current, composites[idx]); } else { p.current.clazz = composites[idx]; p.prepareClazz(p.current); @@ -69,14 +71,12 @@ function copyComposites(p, composites, type) { } } -function copyConfigurationYaml(p, composites) { +function copyConfigurationPropertiesFile(p, composites) { for (var idx in composites) { if (composites.hasOwnProperty(idx)) { p.current.clazz = composites[idx]; p.prepareClazz(p.current); - p.copyTemplate(p.ctx, - 'DomainLayer/DomainModule/config.yaml.tmpl', - 'model/src/main/resources/' + p.javaPackageDir + '/model/' + p.current.name + '/' + p.current.clazz.name + '.yaml'); + p.copyToConfig(p.ctx,'DomainLayer/DomainModule/config.properties.tmpl', p.current.clazz.name + '.properties'); } } } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/DomainLayer/JmxModule/bootstrap.tmpl ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/DomainLayer/JmxModule/bootstrap.tmpl b/tools/generator-polygene/app/templates/DomainLayer/JmxModule/bootstrap.tmpl index 8a9a96f..b53529f 100644 --- a/tools/generator-polygene/app/templates/DomainLayer/JmxModule/bootstrap.tmpl +++ b/tools/generator-polygene/app/templates/DomainLayer/JmxModule/bootstrap.tmpl @@ -36,7 +36,7 @@ public class JmxModule { new JMXAssembler().assemble( module ); module.services( JMXConnectorService.class ).instantiateOnStartup(); - module.entities( JMXConnectorConfiguration.class ); + module.configurations( JMXConnectorConfiguration.class ); module.forMixin( JMXConnectorConfiguration.class ).declareDefaults().port().set( 1099 ); return module; } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/InfrastructureLayer/StorageModule/bootstrap.tmpl ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/InfrastructureLayer/StorageModule/bootstrap.tmpl b/tools/generator-polygene/app/templates/InfrastructureLayer/StorageModule/bootstrap.tmpl index b2ebb64..ce33d13 100644 --- a/tools/generator-polygene/app/templates/InfrastructureLayer/StorageModule/bootstrap.tmpl +++ b/tools/generator-polygene/app/templates/InfrastructureLayer/StorageModule/bootstrap.tmpl @@ -26,6 +26,7 @@ import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.LayerAssembly; import org.apache.polygene.bootstrap.ModuleAssembly; import org.apache.polygene.bootstrap.layered.ModuleAssembler; +import org.apache.polygene.entitystore.<%- polygene.entitystoremodule %>.<%- polygene.entitystore %>EntityStoreConfiguration; import org.apache.polygene.entitystore.<%- polygene.entitystoremodule %>.assembly.<%- polygene.entitystore %>EntityStoreAssembler; <% if( polygene.entitystore.indexOf('SQL') >= 0 ) { @@ -73,9 +74,17 @@ if( polygene.entitystore.indexOf( 'SQL' ) >= 0 ) { .withConfig( configModule, Visibility.application ) .identifiedBy( "es-<%- polygene.entitystore.toLowerCase() %>" ) .assemble( module ); +<% +if( polygene.entitystore === 'Cassandra' ) { +%> configModule.forMixin( CassandraEntityStoreConfiguration.class ) + .declareDefaults() + .createIfMissing().set( true ); +<% +} +%> module.services( IdentityGenerator.class ) - .visibleIn( Visibility.application ) - .withMixins( UuidGeneratorMixin.class ); + .visibleIn( Visibility.application ) + .withMixins( UuidGeneratorMixin.class ); return module; } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/InfrastructureLayer/StorageModule/module.js ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/InfrastructureLayer/StorageModule/module.js b/tools/generator-polygene/app/templates/InfrastructureLayer/StorageModule/module.js index a9790bb..d26c454 100644 --- a/tools/generator-polygene/app/templates/InfrastructureLayer/StorageModule/module.js +++ b/tools/generator-polygene/app/templates/InfrastructureLayer/StorageModule/module.js @@ -31,21 +31,14 @@ module.exports = { if (p.entitystore.indexOf('SQL') < 0) { fs.stat(__dirname + "/../../" + configurationFile, function (err, stat) { if (err === null) { - p.copyTemplate(p.ctx, - configurationFile, - 'app/src/main/resources/' + esFileName); + p.copyToConfig(p.ctx, configurationFile, esFileName); } }); } else { - p.copyTemplate(p.ctx, - 'InfrastructureLayer/StorageModule/storage/es-sql.properties', - 'app/src/main/resources/' + esFileName); - + p.copyToConfig(p.ctx, 'InfrastructureLayer/StorageModule/storage/es-sql.properties', esFileName); var dsFileName = 'ds-es-' + p.entitystore.toLowerCase() + '.properties'; var datasourceFile = 'InfrastructureLayer/StorageModule/storage/' + dsFileName; - p.copyTemplate(p.ctx, - datasourceFile, - 'app/src/main/resources/' + dsFileName); + p.copyToConfig(p.ctx, datasourceFile, dsFileName); } } }; http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/RestAPIApplication/DevelopmentKeyManagement.java.tmpl ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/RestAPIApplication/DevelopmentKeyManagement.java.tmpl b/tools/generator-polygene/app/templates/RestAPIApplication/DevelopmentKeyManagement.java.tmpl index d82eec5..d724253 100644 --- a/tools/generator-polygene/app/templates/RestAPIApplication/DevelopmentKeyManagement.java.tmpl +++ b/tools/generator-polygene/app/templates/RestAPIApplication/DevelopmentKeyManagement.java.tmpl @@ -71,16 +71,17 @@ class DevelopmentKeyManagement @SuppressWarnings( "unused" ) KeyStore trustStore = loadKeyStore( new File(TRUSTSTORE_FILENAME), TRUSTSTORE_TYPE, KS_PASSWORD ); - KeyStore keyStore = loadKeyStore( new File(SERVER_KEYSTORE_FILENAME), SERVER_KEYSTORE_TYPE, KS_PASSWORD ); + File keyFile = new File( SERVER_KEYSTORE_FILENAME ); + KeyStore keyStore = loadKeyStore( keyFile, SERVER_KEYSTORE_TYPE, KS_PASSWORD ); initializeKeyManager( keyStore, KS_PASSWORD ); - createKeyStoreData( keyStore ); + createKeyStoreData( keyStore, keyFile, SERVER_KEYSTORE_TYPE, KS_PASSWORD ); } private static KeyStore loadKeyStore( File keyFile, String type, String password ) { if( !keyFile.exists() ) { - return createKeyStore(keyFile, type, password); + createKeyStore(keyFile, type, password); } try( FileInputStream fis = new FileInputStream( keyFile ) ) { @@ -96,7 +97,7 @@ class DevelopmentKeyManagement } @SuppressWarnings( "ResultOfMethodCallIgnored" ) - private static KeyStore createKeyStore( File keyFile, String type, String password ) + private static void createKeyStore( File keyFile, String type, String password ) throws AssemblyException { if( !keyFile.getParentFile().exists() ) @@ -109,7 +110,6 @@ class DevelopmentKeyManagement char[] pwd = password.toCharArray(); ks.load( null, pwd ); ks.store( fos, pwd ); - return ks; } catch( Exception e ) { @@ -130,7 +130,7 @@ class DevelopmentKeyManagement } } - private static void createKeyStoreData( KeyStore keyStore ) + private static void createKeyStoreData( KeyStore keyStore, File keyFile, String type, String password ) { try { @@ -141,6 +141,7 @@ class DevelopmentKeyManagement KeyPair keyPair = generateKeyPair(); X509Certificate certificate = selfSignedCertificate( keyPair, COMMON_NAME, 30 ); keyStore.setCertificateEntry( COMMON_NAME, certificate ); + storeKeyStore(keyStore, keyFile, password, type); System.out.println("Created Self-signed certificated:"); System.out.println(convertCertificateToPEM( certificate )); @@ -151,6 +152,21 @@ class DevelopmentKeyManagement } } + private static void storeKeyStore( KeyStore keyStore, File keyFile, String password, String type ) + { + try( FileOutputStream fos = new FileOutputStream( keyFile ) ) + { + KeyStore ks = KeyStore.getInstance( type ); + char[] pwd = password.toCharArray(); + ks.load( null, pwd ); + ks.store( fos, pwd ); + } + catch( Exception e ) + { + throw new AssemblyException( "Unable to create keystore.", e ); + } + } + private static KeyPair generateKeyPair() { try http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/RestAPIApplication/Launcher.java.tmpl ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/RestAPIApplication/Launcher.java.tmpl b/tools/generator-polygene/app/templates/RestAPIApplication/Launcher.java.tmpl index 3a66952..2acdca1 100644 --- a/tools/generator-polygene/app/templates/RestAPIApplication/Launcher.java.tmpl +++ b/tools/generator-polygene/app/templates/RestAPIApplication/Launcher.java.tmpl @@ -54,6 +54,12 @@ public class <%= polygene.name %>Launcher extends PolygeneRestApplicationLaunche %> return new <%= polygene.name %>ApplicationAssembler( name, version, mode, none -> {} ); } + @Override + public void shutdown() + { + super.shutdown(); + } + protected String entryLayer() { return ConnectivityLayer.NAME; http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/RestAPIApplication/app.js ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/RestAPIApplication/app.js b/tools/generator-polygene/app/templates/RestAPIApplication/app.js index c016bec..ceed39e 100644 --- a/tools/generator-polygene/app/templates/RestAPIApplication/app.js +++ b/tools/generator-polygene/app/templates/RestAPIApplication/app.js @@ -36,9 +36,7 @@ module.exports = { p.copyTemplate(p.ctx, 'RestAPIApplication/DevelopmentKeyManagement.java.tmpl', 'app/src/main/java/' + p.javaPackageDir + '/app/DevelopmentKeyManagement.java'); - p.copyTemplate(p.ctx, - 'RestAPIApplication/web-shiro.ini.tmpl', - 'app/src/main/resources/web-shiro.ini'); + p.copyToConfig(p.ctx, 'RestAPIApplication/web-shiro.ini.tmpl', 'web-shiro.ini'); } p.copyTemplate(p.ctx, http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/RestAPIApplication/bootstrap-test.tmpl ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/RestAPIApplication/bootstrap-test.tmpl b/tools/generator-polygene/app/templates/RestAPIApplication/bootstrap-test.tmpl index 0eac743..ae03cd6 100644 --- a/tools/generator-polygene/app/templates/RestAPIApplication/bootstrap-test.tmpl +++ b/tools/generator-polygene/app/templates/RestAPIApplication/bootstrap-test.tmpl @@ -35,6 +35,8 @@ import org.apache.polygene.bootstrap.layered.LayeredApplicationAssembler; import org.apache.polygene.tools.model.descriptor.ApplicationDetailDescriptor; import org.apache.polygene.tools.model.descriptor.ApplicationDetailDescriptorBuilder; <% +polygene.needsDelayChecker = false; + if( polygene.entitystore === 'MySQL' ) { %>import java.util.HashMap; <% @@ -89,6 +91,8 @@ public class BootstrapTest }; launcher.initialize(); System.out.println("Application Launched..."); + // Thread.sleep( 3600000L ); + launcher.shutdown(); } private void setupTest( ApplicationAssembly assembly ) @@ -186,6 +190,7 @@ if( polygene.entitystore === 'MongoDB' ) { } <% } if( polygene.entitystore === 'MySQL' ) { + polygene.needsDelayChecker = true; %> private void entityStoreSetup(ApplicationAssembly assembly ) { @@ -205,6 +210,7 @@ if( polygene.entitystore === 'MySQL' ) { .build(); <% } if( polygene.entitystore === 'PostgreSQL' ) { + polygene.needsDelayChecker = true; %> private void entityStoreSetup(ApplicationAssembly assembly ) { @@ -264,6 +270,7 @@ if( polygene.caching === 'Memcache' ) { .imageName( "memcached:latest" ) .expose( "11211", "11211" ) .waitForTimeout( 120 ) + .waitFor( WaitFor.tcpPort(11211) ) .build(); <% } @@ -272,8 +279,9 @@ if( polygene.caching === 'EhCache' ) { @ClassRule public static final DockerRule CACHE_DOCKER = DockerRule.builder() .imageName( "terracotta/terracotta-server-oss:latest" ) - .publishAllPorts( true ) + .expose( "9510", "9510" ) .waitForTimeout( 120 ) + .waitFor( WaitFor.tcpPort(9510) ) .build(); <% } if( polygene.indexing === 'ElasticSearch' ) { @@ -286,7 +294,8 @@ if( polygene.indexing === 'ElasticSearch' ) { .build(); <% } %> - +<% if( polygene.needsDelayChecker ) { +%> private static class DelayChecker implements StartCondition { @@ -304,7 +313,6 @@ if( polygene.indexing === 'ElasticSearch' ) { { return new StartConditionCheck() { - @Override public boolean check() { @@ -324,4 +332,5 @@ if( polygene.indexing === 'ElasticSearch' ) { }; } } -} +<% } +%>} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/buildtool/gradle-app.tmpl ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/buildtool/gradle-app.tmpl b/tools/generator-polygene/app/templates/buildtool/gradle-app.tmpl index 0d8431a..14b3510 100644 --- a/tools/generator-polygene/app/templates/buildtool/gradle-app.tmpl +++ b/tools/generator-polygene/app/templates/buildtool/gradle-app.tmpl @@ -18,6 +18,24 @@ * -%> + +apply plugin: 'application' + +mainClassName="<%= polygene.packageName %>.app.<%= polygene.name %>Launcher" + +applicationDefaultJvmArgs=[] +// GC Tuning strategies, see https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/ +// Strict memory bound +// applicationDefaultJvmArgs << "-Xmx512M -Xms512M" +// +// Goal oriented, "throughput" and "max pause" +// applicationDefaultJvmArgs << "-XX:MaxGCPauseMillis=300 -XX:GCTimeRatio=19" +// +// Garbage Collector +// OneOf; -XX:+UseG1GC, -XX:+UseConcMarkSweepGC, -XX:-UseParallelOldGC, -XX:+UseSerialGC +applicationDefaultJvmArgs << "-XX:+UseG1GC" + + dependencies { implementation project( ":bootstrap" ) implementation project( ":model" ) @@ -89,3 +107,22 @@ if( polygene.entitystore == 'SQLite' ) { testImplementation "org.apache.polygene.core:org.apache.polygene.core.testsupport:$polygeneVersion" testImplementation "com.github.tdomzal:junit-docker-rule:0.3" } + + +task createConfigs { + def config = file("src/main/config") + outputs.dir config + doLast { + config.mkdirs() + } +} + +distributions { + main { + contents { + from(createConfigs) { + into "config" + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/buildtool/gradle-root.tmpl ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/buildtool/gradle-root.tmpl b/tools/generator-polygene/app/templates/buildtool/gradle-root.tmpl index d8f215e..357b607 100644 --- a/tools/generator-polygene/app/templates/buildtool/gradle-root.tmpl +++ b/tools/generator-polygene/app/templates/buildtool/gradle-root.tmpl @@ -25,7 +25,11 @@ if( project.version == 'unspecified' ) rootProject.ext { polygeneVersion = "<%= polygene.version %>" +<% if( polygene.applicationtype === "Rest API" ) { +%> jettyVersion = "9.2.17.v20160517" +<% } +%>} allprojects() { apply plugin: 'java-library' http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/src/docs/yeoman_polygene.txt ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/src/docs/yeoman_polygene.txt b/tools/generator-polygene/src/docs/yeoman_polygene.txt index cff7882..19cca52 100644 --- a/tools/generator-polygene/src/docs/yeoman_polygene.txt +++ b/tools/generator-polygene/src/docs/yeoman_polygene.txt @@ -19,8 +19,8 @@ [[tools-shell,Command Line Shell]] = Polygene Generator = -Apache Polygene comes with a Yeoman code generator, to quickly set up a development -environment for Polygene applications. +Apache Polygene comes with a Yeoman code generator, to quickly set up a +project for Polygene applications. [source,shell] ---- @@ -90,6 +90,15 @@ number of implementations to choose from. Not that "memory" is not persistent, b SQLite ---- +If one of the SQL options are given, then a question of connection pool will pop up. + +[source,shell] +---- +? Which connection pool do you want to use? + BoneCP +> DBCP +---- + === Indexing/Query system === Select of a pluggable Indexing and Query subsystem. @@ -272,7 +281,11 @@ where the content of the +../model.json+ is as follows, "visibility": "application", "configuration" : [ { "name": "backend", "type": "java.lang.String" }, - { "name": "connectString", "type": "java.lang.String" } + { "name": "connectString", "type": "java.lang.String", + "description": [ + "The connection string to the authentication and authorization backend system." + ] + } ] } ] @@ -325,11 +338,19 @@ we will create a complete project, like this [source,shell] ---- - create bootstrap/src/main/java/com/sensetif/sink/bootstrap/config/ConfigurationLayer.java + create bootstrap/src/main/java/com/sensetif/sink/bootstrap/config/ConfigurationLayer.java create bootstrap/src/main/java/com/sensetif/sink/bootstrap/infrastructure/InfrastructureLayer.java create bootstrap/src/main/java/com/sensetif/sink/bootstrap/domain/DomainLayer.java create bootstrap/src/main/java/com/sensetif/sink/bootstrap/connectivity/ConnectivityLayer.java - create app/src/main/webapp/WEB-INF/web.xml + create rest/src/main/java/com/sensetif/sink/rest/FloodRestApplication.java + create app/src/main/java/com/sensetif/sink/app/FloodLauncher.java + create app/src/main/java/com/sensetif/sink/app/DevelopmentKeyManagement.java + create app/src/main/config/development/web-shiro.ini + create app/src/main/config/qa/web-shiro.ini + create app/src/main/config/staging/web-shiro.ini + create app/src/main/config/production/web-shiro.ini + create app/src/test/java/com/sensetif/sink/app/BootstrapTest.java + create bootstrap/src/main/java/com/sensetif/sink/bootstrap/FloodApplicationAssembler.java create app/build.gradle create bootstrap/build.gradle create model/build.gradle @@ -343,34 +364,53 @@ we will create a complete project, like this create bootstrap/src/main/java/com/sensetif/sink/bootstrap/config/ConfigModule.java create bootstrap/src/main/java/com/sensetif/sink/bootstrap/infrastructure/MemcacheCachingModule.java create bootstrap/src/main/java/com/sensetif/sink/bootstrap/infrastructure/FileConfigurationModule.java - create bootstrap/src/main/java/com/sensetif/sink/bootstrap/infrastructure/SQLIndexingModule.java + create bootstrap/src/main/java/com/sensetif/sink/bootstrap/infrastructure/RdfIndexingModule.java create bootstrap/src/main/java/com/sensetif/sink/bootstrap/infrastructure/CodahaleMetricsModule.java create bootstrap/src/main/java/com/sensetif/sink/bootstrap/infrastructure/JavaxJsonSerializationModule.java create bootstrap/src/main/java/com/sensetif/sink/bootstrap/infrastructure/CassandraStorageModule.java create bootstrap/src/main/java/com/sensetif/sink/bootstrap/domain/CrudModule.java create bootstrap/src/main/java/com/sensetif/sink/bootstrap/domain/UserModule.java - create model/src/main/java/com/sensetif/sink/model/user/Users.java - create model/src/main/java/com/sensetif/sink/model/user/Roles.java create model/src/main/java/com/sensetif/sink/model/user/User.java + create model/src/main/java/com/sensetif/sink/model/user/Users.java create model/src/main/java/com/sensetif/sink/model/user/Role.java + create model/src/main/java/com/sensetif/sink/model/user/Roles.java create model/src/main/java/com/sensetif/sink/model/user/Permission.java + create model/src/main/java/com/sensetif/sink/model/user/Permissions.java create model/src/main/java/com/sensetif/sink/model/user/Group.java create model/src/main/java/com/sensetif/sink/model/user/Groups.java create model/src/main/java/com/sensetif/sink/model/user/AuthService.java + create model/src/main/java/com/sensetif/sink/model/user/AuthBackend.java create model/src/main/java/com/sensetif/sink/model/user/AuthConfiguration.java - create model/src/main/resources/com/sensetif/sink/model/user/AuthConfiguration.yaml + create app/src/main/config/development/AuthService.properties + create app/src/main/config/qa/AuthService.properties + create app/src/main/config/staging/AuthService.properties + create app/src/main/config/production/AuthService.properties create bootstrap/src/main/java/com/sensetif/sink/bootstrap/domain/OrganizationModule.java - create model/src/main/java/com/sensetif/sink/model/organization/Organizations.java create model/src/main/java/com/sensetif/sink/model/organization/Organization.java create model/src/main/java/com/sensetif/sink/model/organization/Project.java + create model/src/main/java/com/sensetif/sink/model/organization/Contract.java + create model/src/main/java/com/sensetif/sink/model/organization/ContractPart.java + create model/src/main/java/com/sensetif/sink/model/organization/Order.java + create model/src/main/java/com/sensetif/sink/model/organization/OrderConfirmation.java create model/src/main/java/com/sensetif/sink/model/organization/Invoice.java create model/src/main/java/com/sensetif/sink/model/organization/CreditLimit.java - create model/src/main/java/com/sensetif/sink/model/organization/OrderConfirmation.java + create model/src/main/java/com/sensetif/sink/model/organization/Label.java create model/src/main/java/com/sensetif/sink/model/organization/PaypalNotification.java create bootstrap/src/main/java/com/sensetif/sink/bootstrap/domain/SensorModule.java - create model/src/main/java/com/sensetif/sink/model/sensor/SensorData.java - create model/src/main/java/com/sensetif/sink/model/sensor/Sensor.java + create model/src/main/java/com/sensetif/sink/model/sensor/SensorDetails.java + create model/src/main/java/com/sensetif/sink/model/sensor/SensorPoll.java + create model/src/main/java/com/sensetif/sink/model/sensor/Access.java + create model/src/main/java/com/sensetif/sink/model/sensor/JsonDocumentAddress.java + create model/src/main/java/com/sensetif/sink/model/sensor/XmlDocumentAddress.java + create model/src/main/java/com/sensetif/sink/model/sensor/ModbusDeviceAddress.java + create model/src/main/java/com/sensetif/sink/model/sensor/JsonPathSelector.java + create model/src/main/java/com/sensetif/sink/model/sensor/XPathSelector.java + create model/src/main/java/com/sensetif/sink/model/sensor/ModbusSelector.java create model/src/main/java/com/sensetif/sink/model/sensor/PollSchedule.java + create model/src/main/java/com/sensetif/sink/model/sensor/AccessType.java + create model/src/main/java/com/sensetif/sink/model/sensor/Address.java + create model/src/main/java/com/sensetif/sink/model/sensor/Selector.java + create bootstrap/src/main/java/com/sensetif/sink/bootstrap/domain/JmxModule.java create bootstrap/src/main/java/com/sensetif/sink/bootstrap/domain/SecurityModule.java create model/src/main/java/com/sensetif/sink/model/security/CryptoConfiguration.java create model/src/main/java/com/sensetif/sink/model/security/CryptoException.java @@ -381,8 +421,18 @@ we will create a complete project, like this create model/src/main/java/com/sensetif/sink/model/security/SecurityRepository.java create model/src/main/java/com/sensetif/sink/model/security/User.java create model/src/main/java/com/sensetif/sink/model/security/UserFactory.java + create bootstrap/src/main/java/com/sensetif/sink/bootstrap/connectivity/HttpServerModule.java create bootstrap/src/main/java/com/sensetif/sink/bootstrap/connectivity/RestApiModule.java create rest/src/main/java/com/sensetif/sink/rest/security/DefaultEnroler.java create rest/src/main/java/com/sensetif/sink/rest/security/DefaultVerifier.java + create app/src/main/config/development/es-cassandra.properties + create app/src/main/config/qa/es-cassandra.properties + create app/src/main/config/staging/es-cassandra.properties + create app/src/main/config/production/es-cassandra.properties ---- +Notice that there is a ++app/src/main/config++ directory with 4 sub-directories. Each of those subdirectories +represents one of the modes in ++Application.Mode++. The start script will look for the environment variable +SYS_ENVIRONMENT and select the ++Application.Mode++ accordingly and set the configuration directory +(i.e. make it part of the CLASSPATH) to such. +
