POLYGENE-158 : A bunch of work on the Yeoman project creator. Still far from complete...
Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/46e02826 Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/46e02826 Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/46e02826 Branch: refs/heads/develop Commit: 46e02826b54771930a89bfa83a344c1f2f5b926e Parents: aeff80d Author: niclas <[email protected]> Authored: Sun Mar 5 21:24:15 2017 +0800 Committer: niclas <[email protected]> Committed: Sun Mar 5 21:24:15 2017 +0800 ---------------------------------------------------------------------- tools/generator-polygene/app/index.js | 566 +++++++++++-------- .../app/templates/CodahaleModule/bootstrap.tmpl | 50 ++ .../app/templates/DomainLayer/bootstrap.tmpl | 2 + .../app/templates/DomainModule/Crud.tmpl | 41 ++ .../app/templates/DomainModule/Entity.tmpl | 41 ++ .../app/templates/DomainModule/Object.tmpl | 33 ++ .../app/templates/DomainModule/Service.tmpl | 36 ++ .../app/templates/DomainModule/Value.tmpl | 41 ++ .../app/templates/DomainModule/bootstrap.tmpl | 85 +++ .../HardcodedSecurityRepositoryMixin.tmpl | 51 -- .../templates/SolrIndexingModule/bootstrap.tmpl | 49 ++ 11 files changed, 709 insertions(+), 286 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/polygene-java/blob/46e02826/tools/generator-polygene/app/index.js ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/index.js b/tools/generator-polygene/app/index.js index be71f4f..7ab5505 100644 --- a/tools/generator-polygene/app/index.js +++ b/tools/generator-polygene/app/index.js @@ -18,302 +18,398 @@ * */ -var generators = require( 'yeoman-generator' ); +var generators = require('yeoman-generator'); +var fs = require('fs'); var polygene = {}; module.exports = generators.Base.extend( { // The name `constructor` is important here - constructor: function () - { + constructor: function () { // Calling the super constructor is important so our generator is correctly set up - generators.Base.apply( this, arguments ); - - // this.option( 'coffee' ); // This method adds support for a `--coffee` flag + generators.Base.apply(this, arguments); + + this.option('import-model'); // --import-model reads model.json in current directory and creates the domain model for it. + + if (this.options.import != null) { + polygene = importModel(this, './imported-model.json'); + polygene.name = polygene.name ? polygene.name : firstUpper(this.appname); + polygene.packageName = polygene.packageName ? polygene.packageName : ("com.acme." + this.appname); + polygene.singletonApp = false; // not supported yet + polygene.features = polygene.features ? polygene.features : ['rest api']; + polygene.modules = polygene.modules ? polygene.modules : {}; + polygene.indexing = polygene.indexing ? polygene.indexing : null; + polygene.entitystore = polygene.entitystore ? polygene.entitystore : null; + polygene.caching = polygene.caching ? polygene.caching : null; + polygene.serialization = polygene.serialization ? polygene.serialization : null; + console.log(JSON.stringify(polygene,null,4)); + } + else { + polygene = { + name: firstUpper(this.appname), + packageName: "com.acme." + this.appname, + singletonApp: false, + entitystore: null, + indexing: null, + serialization: null, + caching: null, + features: ['rest api'], + modules: {} + }; + } }, - method1: function () - { - console.log( 'method 1 just ran' ); - }, - method2: function () - { - console.log( 'method 2 just ran' ); - }, - prompting: function () - { - return this.prompt( - [ - { - type: 'input', - name: 'name', - message: 'Your project name', - default: firstUpper( this.appname ) - }, - { - type: 'input', - name: 'packagename', - message: 'Java package name', - default: "com.acme." + this.appname // Default to current folder name - }, - { - type: 'list', - name: 'entitystore', - choices: [ - 'Cassandra', - 'File', - 'DerbySQL', - 'Geode', - 'H2SQL', - 'Hazelcast', - 'JClouds', - 'Jdbm', - 'LevelDB', - 'Memory', - 'MongoDB', - 'MySQL', - 'Preferences', - 'Redis', - 'Riak', - 'PostgresSQL', - 'SQLite' - ], - message: 'Which entity store do you want to use?' - }, - { - type: 'list', - name: 'indexing', - choices: [ - 'Rdf', - 'ElasticSearch', - 'Solr', - 'SQL' - ], - message: 'Which indexing system do you want to use?' - }, - { - type: 'list', - name: 'caching', - choices: [ - 'none', - 'memcache', - 'ehcache' - ], - message: 'Which caching system do you want to use?' - }, - { - type: 'list', - name: 'serialization', - choices: [ - 'Jackson', - 'Stax', - 'OrgJson' - ], - message: 'Which serialization system do you want to use?' - }, - { - type: 'checkbox', - name: 'features', - choices: [ - 'rest api', - // 'reindexer', - // 'metrics', - // 'jmx', - // 'version migration', - 'sample (heroes) web application' - ], - message: 'Other features?' - } - ] - ).then( function ( answers ) - { - this.log( 'app name', answers.name ); - this.log( 'Entity Stores:', answers.entitystore ); - this.log( 'Indexing:', answers.indexing ); - this.log( 'Caching:', answers.caching ); - this.log( 'Serialization:', answers.serialization ); - this.log( 'Features:', answers.features ); - polygene = answers; - polygene.javaPackageDir = polygene.packagename.replace( '.', '/' ); - polygene.singletonApp = false; - if( hasFeature( 'sample (heroes) web application' ) ) + prompting: function () { + if (this.options.noPrompt != null) { + return this.prompt([]); + } + else { + return this.prompt( + [ + { + type: 'input', + name: 'name', + message: 'Your project name', + default: polygene.name + }, + { + type: 'input', + name: 'packageName', + message: 'Java package name', + default: polygene.packageName + }, { - polygene.features.push( 'rest api' ); + type: 'list', + name: 'entitystore', + choices: [ + 'Cassandra', + 'File', + 'DerbySQL', + 'Geode', + 'H2SQL', + 'Hazelcast', + 'JClouds', + 'Jdbm', + 'LevelDB', + 'Memory', + 'MongoDB', + 'MySQL', + 'Preferences', + 'Redis', + 'Riak', + 'PostgresSQL', + 'SQLite' + ], + message: 'Which entity store do you want to use?', + default: polygene.entitystore + }, + { + type: 'list', + name: 'indexing', + choices: [ + 'Rdf', + 'ElasticSearch', + 'Solr', + 'SQL' + ], + message: 'Which indexing system do you want to use?' + }, + { + type: 'list', + name: 'caching', + choices: [ + 'none', + 'memcache', + 'ehcache' + ], + message: 'Which caching system do you want to use?' + }, + { + type: 'list', + name: 'serialization', + choices: [ + 'Jackson', + // 'Johnzon', + 'Stax' + ], + message: 'Which serialization system do you want to use?' + }, + { + type: 'list', + name: 'metrics', + choices: [ + 'none', + 'codahale' + ], + message: 'Which metrics capturing system do you want to use?' + }, + { + type: 'checkbox', + name: 'features', + choices: [ + 'rest api', + // 'jmx', + // 'version migration', + 'sample (heroes) web application' + ], + message: 'Other features?' } - }.bind( this ) - ); + ] + ).then(function (answers) { + this.log('app name', answers.name); + this.log('Entity Stores:', answers.entitystore); + this.log('Indexing:', answers.indexing); + this.log('Caching:', answers.caching); + this.log('Serialization:', answers.serialization); + this.log('Features:', answers.features); + polygene.name = answers.name; + polygene.entitystore = answers.entitystore; + polygene.indexing = answers.indexing; + polygene.caching = answers.caching; + polygene.serialization = answers.serialization; + polygene.metrics = answers.metrics; + polygene.packageName = answers.packageName; + answers.features.forEach(function (f) { + polygene.features.push(f); + }); + polygene.javaPackageDir = polygene.javaPackageDir ? polygene.javaPackageDir : polygene.packageName.replace(/[.]/g, '/'); + polygene.singletonApp = false; + if (hasFeature('sample (heroes) web application')) { + polygene.features.push('rest api'); + } + }.bind(this) + ); + } }, - writing: function () - { - copyPolygeneBootstrap( this, "config", "ConfigurationLayer", !polygene.singeltonApp ); - copyPolygeneBootstrap( this, "infrastructure", "InfrastructureLayer", !polygene.singeltonApp ); - copyPolygeneBootstrap( this, "domain", "DomainLayer", !polygene.singeltonApp ); - copyPolygeneBootstrap( this, "connectivity", "ConnectivityLayer", !polygene.singeltonApp ); - - copyPolygeneBootstrap( this, "config", "ConfigModule", true ); - - copyPolygeneBootstrap( this, "infrastructure", "FileConfigurationModule", true ); - - copyEntityStore( this, polygene.entitystore ); - - copyPolygeneBootstrap( this, "infrastructure", "RdfIndexingModule", hasIndexing( 'Rdf' ) ); - copyPolygeneBootstrap( this, "infrastructure", "ElasticSearchIndexingModule", hasIndexing( 'Elasticsearch' ) ); - copyPolygeneBootstrap( this, "infrastructure", "SolrIndexingModule", hasIndexing( 'Solr' ) ); - copyPolygeneBootstrap( this, "infrastructure", "SqlIndexingModule", hasIndexing( 'Sql' ) ); - - copyPolygeneBootstrap( this, "infrastructure", "NoCachingModule", hasCaching( 'none' ) ); - copyPolygeneBootstrap( this, "infrastructure", "MemcacheCachingModule", hasCaching( 'Memcache' ) ); - copyPolygeneBootstrap( this, "infrastructure", "EhCacheCachingModule", hasCaching( 'Ehcache' ) ); - - copyPolygeneBootstrap( this, "infrastructure", "JacksonSerializationModule", hasSerialization( 'Jackson' ) ); - copyPolygeneBootstrap( this, "infrastructure", "StaxSerializationModule", hasSerialization( 'Stax' ) ); - copyPolygeneBootstrap( this, "infrastructure", "OrgJsonSerializationModule", hasSerialization( 'Orgjson' ) ); - - copyPolygeneBootstrap( this, "connectivity", "RestApiModule", hasFeature( 'rest api' ) ); - copyPolygeneBootstrap( this, "infrastructure", "ReindexerModule", hasFeature( 'reindexer' ) ); - copyPolygeneBootstrap( this, "infrastructure", "MetricsModule", hasFeature( 'metrics' ) ); - copyPolygeneBootstrap( this, "infrastructure", "JmxModule", hasFeature( 'jmx' ) ); - copyPolygeneBootstrap( this, "infrastructure", "MigrationModule", hasFeature( 'version migration' ) ); - - copyPolygeneBootstrap( this, "domain", "CrudModule", true ); - copyPolygeneBootstrap( this, "domain", "SecurityModule", true ); - copyHeroesSampleApp( this ); - copyPolygeneDomain( this, "security", "RestApiModule", "SecurityRepository", hasFeature( 'rest api' ) ); - - copyRestFeature( this, hasFeature( 'rest api' ) ); - - copyTemplate( this, 'buildtool/gradle-app.tmpl', 'app/build.gradle' ); - copyTemplate( this, 'buildtool/gradle-bootstrap.tmpl', 'bootstrap/build.gradle' ); - copyTemplate( this, 'buildtool/gradle-model.tmpl', 'model/build.gradle' ); - copyTemplate( this, 'buildtool/gradle-rest.tmpl', 'rest/build.gradle' ); - copyTemplate( this, 'buildtool/gradle-root.tmpl', 'build.gradle' ); - copyTemplate( this, 'buildtool/settings.tmpl', 'settings.gradle' ); - copyTemplate( this, 'buildtool/gradlew.tmpl', 'gradlew' ); - copyTemplate( this, 'buildtool/gradlew-bat.tmpl', 'gradlew.bat' ); - this.fs.copy( this.templatePath( 'buildtool/gradle-wrapper.jar_' ), this.destinationPath( 'gradle/wrapper/gradle-wrapper.jar' ) ); - this.fs.copy( this.templatePath( 'buildtool/gradle-wrapper.properties_' ), this.destinationPath( 'gradle/wrapper/gradle-wrapper.properties' ) ); + writing: function () { + copyPolygeneBootstrap(this, "config", "ConfigurationLayer", !polygene.singeltonApp); + copyPolygeneBootstrap(this, "infrastructure", "InfrastructureLayer", !polygene.singeltonApp); + copyPolygeneBootstrap(this, "domain", "DomainLayer", !polygene.singeltonApp); + copyPolygeneBootstrap(this, "connectivity", "ConnectivityLayer", !polygene.singeltonApp); + + copyPolygeneBootstrap(this, "config", "ConfigModule", true); + + copyPolygeneBootstrap(this, "infrastructure", "FileConfigurationModule", true); + + copyEntityStore(this, polygene.entitystore); + + copyPolygeneBootstrap(this, "infrastructure", "RdfIndexingModule", hasIndexing('Rdf')); + copyPolygeneBootstrap(this, "infrastructure", "ElasticSearchIndexingModule", hasIndexing('Elasticsearch')); + copyPolygeneBootstrap(this, "infrastructure", "SolrIndexingModule", hasIndexing('Solr')); + copyPolygeneBootstrap(this, "infrastructure", "SqlIndexingModule", hasIndexing('Sql')); + + copyPolygeneBootstrap(this, "infrastructure", "NoCachingModule", hasCaching('none')); + copyPolygeneBootstrap(this, "infrastructure", "MemcacheCachingModule", hasCaching('Memcache')); + copyPolygeneBootstrap(this, "infrastructure", "EhCacheCachingModule", hasCaching('Ehcache')); + + copyPolygeneBootstrap(this, "infrastructure", "JacksonSerializationModule", hasSerialization('Jackson')); + copyPolygeneBootstrap(this, "infrastructure", "StaxSerializationModule", hasSerialization('Stax')); + copyPolygeneBootstrap(this, "infrastructure", "OrgJsonSerializationModule", hasSerialization('Orgjson')); + + copyPolygeneBootstrap(this, "connectivity", "RestApiModule", hasFeature('rest api')); + copyPolygeneBootstrap(this, "infrastructure", "ReindexerModule", hasFeature('reindexer')); + copyPolygeneBootstrap(this, "infrastructure", "MetricsModule", hasFeature('metrics')); + copyPolygeneBootstrap(this, "infrastructure", "JmxModule", hasFeature('jmx')); + copyPolygeneBootstrap(this, "infrastructure", "MigrationModule", hasFeature('version migration')); + + copyPolygeneBootstrap(this, "domain", "CrudModule", true); + var ctx = this; + Object.keys(polygene.modules).forEach(function (moduleName, index) { + copyPolygeneDomainModule(ctx, moduleName, polygene.modules[moduleName]); + }); + copyPolygeneBootstrap(this, "domain", "CrudModule", hasFeature('rest api')); + // copyPolygeneBootstrap(this, "domain", "SecurityModule", true); + copyHeroesSampleApp(this); + copyPolygeneDomain(this, "security", "RestApiModule", "SecurityRepository", hasFeature('rest api')); + + copyRestFeature(this, hasFeature('rest api')); + + copyTemplate(this, 'buildtool/gradle-app.tmpl', 'app/build.gradle'); + copyTemplate(this, 'buildtool/gradle-bootstrap.tmpl', 'bootstrap/build.gradle'); + copyTemplate(this, 'buildtool/gradle-model.tmpl', 'model/build.gradle'); + copyTemplate(this, 'buildtool/gradle-rest.tmpl', 'rest/build.gradle'); + copyTemplate(this, 'buildtool/gradle-root.tmpl', 'build.gradle'); + copyTemplate(this, 'buildtool/settings.tmpl', 'settings.gradle'); + copyTemplate(this, 'buildtool/gradlew.tmpl', 'gradlew'); + copyTemplate(this, 'buildtool/gradlew-bat.tmpl', 'gradlew.bat'); + this.fs.copy(this.templatePath('buildtool/gradle-wrapper.jar_'), this.destinationPath('gradle/wrapper/gradle-wrapper.jar')); + this.fs.copy(this.templatePath('buildtool/gradle-wrapper.properties_'), this.destinationPath('gradle/wrapper/gradle-wrapper.properties')); + + if (this.options.export != null) { + exportModel(this, "exported-model.json"); + } } } ); -function copyPolygeneBootstrap( ctx, layer, moduleName, condition ) -{ - if( condition ) - { - copyTemplate( ctx, - moduleName + '/bootstrap.tmpl', - 'bootstrap/src/main/java/' + polygene.javaPackageDir + '/bootstrap/' + layer + '/' + moduleName + '.java' ); +function copyPolygeneBootstrap(ctx, layer, moduleName, condition) { + if (condition) { + copyTemplate(ctx, + moduleName + '/bootstrap.tmpl', + 'bootstrap/src/main/java/' + polygene.javaPackageDir + '/bootstrap/' + layer + '/' + moduleName + '.java'); } } -function copyEntityStore( ctx, entityStoreName ) -{ - copyTemplate( ctx, - 'StorageModule/bootstrap.tmpl', - 'bootstrap/src/main/java/' + polygene.javaPackageDir + '/bootstrap/infrastructure/' + entityStoreName + 'StorageModule.java' ); +function copyEntityStore(ctx, entityStoreName) { + copyTemplate(ctx, + 'StorageModule/bootstrap.tmpl', + 'bootstrap/src/main/java/' + polygene.javaPackageDir + '/bootstrap/infrastructure/' + entityStoreName + 'StorageModule.java'); } -function copyPolygeneApp( ctx, name, condition ) -{ - if( condition ) - { - copyTemplate( ctx, - name + '/bootstrap.tmpl', - 'bootstrap/src/main/java/' + polygene.javaPackageDir + '/bootstrap/' + name + 'ApplicationAssembler.java' ); +function copyPolygeneApp(ctx, name, condition) { + if (condition) { + copyTemplate(ctx, + name + '/bootstrap.tmpl', + 'bootstrap/src/main/java/' + polygene.javaPackageDir + '/bootstrap/' + name + 'ApplicationAssembler.java'); - copyTemplate( ctx, - name + '/app.tmpl', - 'app/src/main/java/' + polygene.javaPackageDir + '/app/' + name + '.java' ); + copyTemplate(ctx, + name + '/app.tmpl', + 'app/src/main/java/' + polygene.javaPackageDir + '/app/' + name + '.java'); - copyTemplate( ctx, - name + '/webapp/', - 'app/src/main/webapp/' ); + copyTemplate(ctx, + name + '/webapp/', + 'app/src/main/webapp/'); } } -function copyPolygeneDomain( ctx, model, module, clazz, condition ) -{ - if( condition ) - { - copyTemplate( ctx, - module + '/' + clazz + '.tmpl', - 'model/src/main/java/' + polygene.javaPackageDir + '/model/' + model + '/' + clazz + '.java' ); +function copyPolygeneDomain(ctx, model, module, clazz, condition) { + if (condition) { + copyTemplate(ctx, + module + '/' + clazz + '.tmpl', + 'model/src/main/java/' + polygene.javaPackageDir + '/model/' + model + '/' + clazz + '.java'); } } -function copyRestFeature( ctx, condition ) -{ - if( condition ) - { - copyPolygeneBootstrap( ctx, "domain", "SecurityModule", true ); +function copyPolygeneDomainModule(ctx, moduleName, moduleDef) { + var clazz = firstUpper(moduleName) + "Module"; + polygene.current = moduleDef; + polygene.current.name = moduleName; + copyTemplate(ctx, + 'DomainModule/bootstrap.tmpl', + 'bootstrap/src/main/java/' + polygene.javaPackageDir + '/bootstrap/domain/' + clazz + '.java'); + for (var idx1 in moduleDef.cruds) { + if (moduleDef.cruds.hasOwnProperty(idx1)) { + polygene.current.clazz = moduleDef.cruds[idx1]; + copyTemplate(ctx, + 'DomainModule/Crud.tmpl', + 'model/src/main/java/' + polygene.javaPackageDir + '/model/' + moduleName + '/' + moduleDef.cruds[idx1].name + '.java'); + } + } + for (var idx2 in moduleDef.values) { + if (moduleDef.values.hasOwnProperty(idx2)) { + polygene.current.clazz = moduleDef.values[idx2]; + copyTemplate(ctx, + 'DomainModule/Value.tmpl', + 'model/src/main/java/' + polygene.javaPackageDir + '/model/' + moduleName + '/' + moduleDef.values[idx2].name + '.java'); + } + } + for (var idx3 in moduleDef.entities) { + if (moduleDef.entities.hasOwnProperty(idx3)) { + polygene.current.clazz = moduleDef.entities[idx2]; + copyTemplate(ctx, + 'DomainModule/Entity.tmpl', + 'model/src/main/java/' + polygene.javaPackageDir + '/model/' + moduleName + '/' + moduleDef.entities[idx3].name + '.java'); + } + } + for (var idx4 in moduleDef.transients) { + if (moduleDef.transients.hasOwnProperty(idx4)) { + polygene.current.clazz = moduleDef.transients[idx3]; + copyTemplate(ctx, + 'DomainModule/Transient.tmpl', + 'model/src/main/java/' + polygene.javaPackageDir + '/model/' + moduleName + '/' + moduleDef.transients[idx4].name + '.java'); + } + } + for (var idx5 in moduleDef.objects) { + if (moduleDef.objects.hasOwnProperty(idx5)) { + polygene.current.clazz = moduleDef.objects[idx5]; + copyTemplate(ctx, + 'DomainModule/Object.tmpl', + 'model/src/main/java/' + polygene.javaPackageDir + '/model/' + moduleName + '/' + moduleDef.objects[idx5].name + '.java'); + } + } + for (var idx6 in moduleDef.services) { + if (moduleDef.services.hasOwnProperty(idx6)) { + polygene.current.clazz = moduleDef.services[idx6]; + copyTemplate(ctx, + 'DomainModule/Service.tmpl', + 'model/src/main/java/' + polygene.javaPackageDir + '/model/' + moduleName + '/' + moduleDef.services[idx6].name + '.java'); + } + } +} - copyTemplate( ctx, - 'RestApiModule/SimpleEnroler.tmpl', - 'rest/src/main/java/' + polygene.javaPackageDir + '/rest/security/SimpleEnroler.java' ); +function copyRestFeature(ctx, condition) { + if (condition) { + copyPolygeneBootstrap(ctx, "domain", "SecurityModule", true); - copyTemplate( ctx, - 'RestApiModule/SimpleVerifier.tmpl', - 'rest/src/main/java/' + polygene.javaPackageDir + '/rest/security/SimpleVerifier.java' ); + copyTemplate(ctx, + 'RestApiModule/SimpleEnroler.tmpl', + 'rest/src/main/java/' + polygene.javaPackageDir + '/rest/security/SimpleEnroler.java'); - copyTemplate( ctx, - 'RestApiModule/HardcodedSecurityRepositoryMixin.tmpl', - 'model/src/main/java/' + polygene.javaPackageDir + '/model/security/HardcodedSecurityRepositoryMixin.java' ); + copyTemplate(ctx, + 'RestApiModule/SimpleVerifier.tmpl', + 'rest/src/main/java/' + polygene.javaPackageDir + '/rest/security/SimpleVerifier.java'); + + copyTemplate(ctx, + 'RestApiModule/HardcodedSecurityRepositoryMixin.tmpl', + 'model/src/main/java/' + polygene.javaPackageDir + '/model/security/HardcodedSecurityRepositoryMixin.java'); } } -function copyHeroesSampleApp( ctx ) -{ - copyPolygeneDomain( ctx, "heroes", "Heroes", "Hero", hasFeature( 'sample (heroes) web application' ) ); - copyPolygeneApp( ctx, "Heroes", hasFeature( 'sample (heroes) web application' ) ); - copyTemplate( ctx, - 'Heroes/web.tmpl', - 'app/src/main/webapp/WEB-INF/web.xml' ); +function copyHeroesSampleApp(ctx) { + copyPolygeneDomain(ctx, "heroes", "Heroes", "Hero", hasFeature('sample (heroes) web application')); + copyPolygeneApp(ctx, "Heroes", hasFeature('sample (heroes) web application')); + copyTemplate(ctx, + 'Heroes/web.tmpl', + 'app/src/main/webapp/WEB-INF/web.xml'); } -function copyTemplate( ctx, from, to ) -{ +function copyTemplate(ctx, from, to) { ctx.fs.copyTpl( - ctx.templatePath( from ), - ctx.destinationPath( to ), + ctx.templatePath(from), + ctx.destinationPath(to), { - packageName: polygene.packagename, + packageName: polygene.packageName, hasFeature: hasFeature, hasEntityStore: hasEntityStore, hasIndexing: hasIndexing, hasCaching: hasCaching, + firstUpper: firstUpper, polygene: polygene } ); } -function hasEntityStore( esType ) -{ +function hasEntityStore(esType) { return polygene.entitystore === esType; } -function hasIndexing( indexingType ) -{ +function hasIndexing(indexingType) { return polygene.indexing === indexingType; } -function hasCaching( cachingType ) -{ +function hasCaching(cachingType) { return polygene.caching === cachingType; } -function hasSerialization( serializer ) -{ +function hasSerialization(serializer) { return polygene.serialization === serializer; } -function hasFeature( feature ) -{ - return polygene.features.indexOf( feature ) >= 0; +function hasFeature(feature) { + return polygene.features.indexOf(feature) >= 0; +} + +function firstUpper(text) { + return text.charAt(0).toUpperCase() + text.substring(1); +} + +function importModel(ctx, filename) { + return JSON.parse(fs.readFileSync(filename, 'utf8')); } -function firstUpper( text ) -{ - return text.charAt( 0 ).toUpperCase() + text.substring( 1 ); +function exportModel(ctx, filename) { + delete polygene.current; + return fs.writeFileSync(filename, JSON.stringify(polygene, null, 4) + "\n", 'utf8'); } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/46e02826/tools/generator-polygene/app/templates/CodahaleModule/bootstrap.tmpl ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/CodahaleModule/bootstrap.tmpl b/tools/generator-polygene/app/templates/CodahaleModule/bootstrap.tmpl new file mode 100644 index 0000000..ec826a2 --- /dev/null +++ b/tools/generator-polygene/app/templates/CodahaleModule/bootstrap.tmpl @@ -0,0 +1,50 @@ +<%# + * 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. + * + * +-%> +package <%= packageName %>.bootstrap.infrastructure; + +import org.apache.polygene.api.common.Visibility; +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.metrics.codehale.assembly.CodahaleMetricsAssembler; +import org.apache.polygene.library.rdf.repository.NativeConfiguration; + +public class RdfIndexingModule + implements ModuleAssembler +{ + public static final String NAME = "Rdf Indexing Module"; + private final ModuleAssembly configModule; + + public RdfIndexingModule( ModuleAssembly configModule ) + { + this.configModule = configModule; + } + + @Override + public ModuleAssembly assemble( LayerAssembly layer, ModuleAssembly module ) + throws AssemblyException + { + configModule.entities( NativeConfiguration.class ).visibleIn( Visibility.application ); + new RdfNativeSesameStoreAssembler(Visibility.application, Visibility.module).assemble( module ); + return module; + } +} + http://git-wip-us.apache.org/repos/asf/polygene-java/blob/46e02826/tools/generator-polygene/app/templates/DomainLayer/bootstrap.tmpl ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/DomainLayer/bootstrap.tmpl b/tools/generator-polygene/app/templates/DomainLayer/bootstrap.tmpl index 4e917f0..517942a 100644 --- a/tools/generator-polygene/app/templates/DomainLayer/bootstrap.tmpl +++ b/tools/generator-polygene/app/templates/DomainLayer/bootstrap.tmpl @@ -32,7 +32,9 @@ public class DomainLayer extends LayeredLayerAssembler throws AssemblyException { createModule( layer, CrudModule.class ); +<% if( hasFeature( 'rest api' ) ) { %> createModule( layer, SecurityModule.class ); +<% } %> return layer; } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-java/blob/46e02826/tools/generator-polygene/app/templates/DomainModule/Crud.tmpl ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/DomainModule/Crud.tmpl b/tools/generator-polygene/app/templates/DomainModule/Crud.tmpl new file mode 100644 index 0000000..95eed76 --- /dev/null +++ b/tools/generator-polygene/app/templates/DomainModule/Crud.tmpl @@ -0,0 +1,41 @@ +<%# + * 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. + * + * +-%> +package <%= packageName %>.model.<%= polygene.current.name %>; + +import org.apache.polygene.api.injection.scope.This; +import org.apache.polygene.api.mixin.Mixins; +import org.apache.polygene.api.property.Property; + +@Mixins( { <%= polygene.current.clazz.name %>.Mixin.class } ) +public interface <%= polygene.current.clazz.name %> +{ + interface State + { + Property<String> name(); // Sample hidden property + } + + class Mixin + implements <%= polygene.current.clazz.name %> + { + @This + private State state; // Sample reference to hidden property + + } +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/46e02826/tools/generator-polygene/app/templates/DomainModule/Entity.tmpl ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/DomainModule/Entity.tmpl b/tools/generator-polygene/app/templates/DomainModule/Entity.tmpl new file mode 100644 index 0000000..9262cad --- /dev/null +++ b/tools/generator-polygene/app/templates/DomainModule/Entity.tmpl @@ -0,0 +1,41 @@ +<%# + * 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. + * + * +-%> +package <%= packageName %>.model.<%= polygene.current.name %>; + +import org.apache.polygene.api.injection.scope.This +import org.apache.polygene.api.mixin.Mixins; +import org.apache.polygene.api.property.Property; + +@Mixins( { <%= polygene.current.clazz.name %>.Mixin } ) +public interface <%= polygene.current.clazz.name %> +{ + interface State + { + Property<String> name(); // Sample hidden property + } + + class Mixin + implements <%= polygene.current.clazz.name %> + { + @This + private State state; // Sample reference to hidden property + + } +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/46e02826/tools/generator-polygene/app/templates/DomainModule/Object.tmpl ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/DomainModule/Object.tmpl b/tools/generator-polygene/app/templates/DomainModule/Object.tmpl new file mode 100644 index 0000000..27d6119 --- /dev/null +++ b/tools/generator-polygene/app/templates/DomainModule/Object.tmpl @@ -0,0 +1,33 @@ +<%# + * 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. + * + * +-%> +package <%= packageName %>.model.<%= polygene.current.name %>; + +import org.apache.polygene.api.injection.scope.This +import org.apache.polygene.api.mixin.Mixins; + +public class <%= polygene.current.clazz.name %> +{ + @Uses + private String name; // Sample @Uses injection + + @Structure + private ValueBuilderFactory vbf; // Sample @Structure injection + +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/46e02826/tools/generator-polygene/app/templates/DomainModule/Service.tmpl ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/DomainModule/Service.tmpl b/tools/generator-polygene/app/templates/DomainModule/Service.tmpl new file mode 100644 index 0000000..0edefdc --- /dev/null +++ b/tools/generator-polygene/app/templates/DomainModule/Service.tmpl @@ -0,0 +1,36 @@ +<%# + * 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. + * + * +-%> +package <%= packageName %>.model.<%= polygene.current.name %>; + +import org.apache.polygene.api.injection.scope.Structure; +import org.apache.polygene.api.mixin.Mixins; +import org.apache.polygene.api.value.ValueBuilderFactory; + +@Mixins( { <%= polygene.current.clazz.name %>.Mixin.class } ) +public interface <%= polygene.current.clazz.name %> +{ + class Mixin + implements <%= polygene.current.clazz.name %> + { + @Structure + private ValueBuilderFactory vbf; + } +} + http://git-wip-us.apache.org/repos/asf/polygene-java/blob/46e02826/tools/generator-polygene/app/templates/DomainModule/Value.tmpl ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/DomainModule/Value.tmpl b/tools/generator-polygene/app/templates/DomainModule/Value.tmpl new file mode 100644 index 0000000..9262cad --- /dev/null +++ b/tools/generator-polygene/app/templates/DomainModule/Value.tmpl @@ -0,0 +1,41 @@ +<%# + * 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. + * + * +-%> +package <%= packageName %>.model.<%= polygene.current.name %>; + +import org.apache.polygene.api.injection.scope.This +import org.apache.polygene.api.mixin.Mixins; +import org.apache.polygene.api.property.Property; + +@Mixins( { <%= polygene.current.clazz.name %>.Mixin } ) +public interface <%= polygene.current.clazz.name %> +{ + interface State + { + Property<String> name(); // Sample hidden property + } + + class Mixin + implements <%= polygene.current.clazz.name %> + { + @This + private State state; // Sample reference to hidden property + + } +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/46e02826/tools/generator-polygene/app/templates/DomainModule/bootstrap.tmpl ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/DomainModule/bootstrap.tmpl b/tools/generator-polygene/app/templates/DomainModule/bootstrap.tmpl new file mode 100644 index 0000000..54bc82d --- /dev/null +++ b/tools/generator-polygene/app/templates/DomainModule/bootstrap.tmpl @@ -0,0 +1,85 @@ +<%# + * 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. + * + * +-%> +package <%= packageName %>.bootstrap.domain; + +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; +<% for( var idx in polygene.current.cruds) { %><%= "import " + packageName + ".model." + polygene.current.name + "." + polygene.current.cruds[idx].name + ";" %><% } %> +<% for( var idx in polygene.current.values) { %><%= "import " + packageName + ".model." + polygene.current.name + "." + polygene.current.values[idx].name + ";" %><% } %> +<% for( var idx in polygene.current.entities) { %><%= "import " + packageName + ".model." + polygene.current.name + "." + polygene.current.entities[idx].name + ";" %><% } %> +<% for( var idx in polygene.current.transients) { %><%= "import " + packageName + ".model." + polygene.current.name + "." + polygene.current.transients[idx].name + ";" %><% } %> +<% for( var idx in polygene.current.objects) { %><%= "import " + packageName + ".model." + polygene.current.name + "." + polygene.current.objects[idx].name + ";" %><% } %> +<% for( var idx in polygene.current.services) { %><%= "import " + packageName + ".model." + polygene.current.name + "." + polygene.current.services[idx].name + ";" %><% } %> + +import static org.apache.polygene.api.common.Visibility.layer; +import static org.apache.polygene.api.common.Visibility.application; + +public class <%- firstUpper(polygene.current.name) %>Module + implements ModuleAssembler +{ + @Override + public ModuleAssembly assemble( LayerAssembly layer, ModuleAssembly module ) + throws AssemblyException + { +<% if( polygene.current.cruds ) { %> + <% for( var value in polygene.current.cruds ) { %> + <% var crud1 = polygene.current.cruds[value]; %> + module.values(<%- crud1.name + ".class" %>)<% if( crud1.visibility ) {%><%-".visibleIn(" + crud1.visibility +")"%><% } %>; + <% } %> + <% for( var value in polygene.current.cruds ) { %> + <% var crud2 = polygene.current.cruds[value]; %> + module.entities(<%= crud2.name + ".class" %>)<% if( crud2.visibility ) {%><%-".visibleIn(" + crud2.visibility +")"%><% } %>; + <% } %> +<% } %> +<% if( polygene.current.values ) { %> + <% for( var value in polygene.current.values ) { %> + <% var v = polygene.current.current[value]; %> + module.values(<%= v.name + ".class" %>)<% if( v.visibility ) {%><%-".visibleIn(" + v.visibility +")"%><% } %>; + <% } %> +<% } %> +<% if( polygene.current.entities ) { %> + <% for( var value in polygene.current.entities ) { %> + <% var entity = polygene.current.entities[value]; %> + module.values(<%= entity.name + ".class" %>)<% if( entity.visibility ) {%><%-".visibleIn(" + entity.visibility +")"%><% } %>; + <% } %> +<% } %> +<% if( polygene.current.transients ) { %> + <% for( var value in polygene.current.transients ) { %> + <% var trans = polygene.current.transients[value]; %> + module.values(<%= trans.name + ".class" %>)<% if( trans.visibility ) {%><%-".visibleIn(" + trans.visibility +")"%><% } %>; + <% } %> +<% } %> +<% if( polygene.current.objects ) { %> + <% for( var value in polygene.current.objects ) { %> + <% var obj = polygene.current.objects[value]; %> + module.values(<%= obj.name + ".class" %>)<% if( obj.visibility ) {%><%-".visibleIn(" + obj.visibility +")"%><% } %>; + <% } %> +<% } %> +<% if( polygene.current.services ) { %> + <% for( var value in polygene.current.services ) { %> + <% var service = polygene.current.services[value]; %> + module.values(<%= service.name + ".class" %>)<% if( service.visibility ) {%><%-".visibleIn(" + service.visibility +")"%><% } %>; + <% } %> +<% } %> + return module; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-java/blob/46e02826/tools/generator-polygene/app/templates/SecurityModule/HardcodedSecurityRepositoryMixin.tmpl ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/SecurityModule/HardcodedSecurityRepositoryMixin.tmpl b/tools/generator-polygene/app/templates/SecurityModule/HardcodedSecurityRepositoryMixin.tmpl deleted file mode 100644 index 91c66e6..0000000 --- a/tools/generator-polygene/app/templates/SecurityModule/HardcodedSecurityRepositoryMixin.tmpl +++ /dev/null @@ -1,51 +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. - * - * --%> -package <%= packageName %>.model.security; - -import java.util.Collections; -import java.util.List; -import org.apache.polygene.api.unitofwork.concern.UnitOfWorkPropagation; - -public class HardcodedSecurityRepositoryMixin - implements SecurityRepository -{ - - @Override - public boolean verifyPassword( String userName, String password ) - { - if( userName.equals("admin") && password.equals("secret") ) { - return true; - } - if( userName.equals("user") && password.equals("123") ) { - return true; - } - return false; - } - - @UnitOfWorkPropagation - public List<String> findRoleNamesOfUser( String name ) - { - if( "admin".equals( name ) ) - { - return Collections.singletonList("admin"); - } - return Collections.singletonList("user"); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/46e02826/tools/generator-polygene/app/templates/SolrIndexingModule/bootstrap.tmpl ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/SolrIndexingModule/bootstrap.tmpl b/tools/generator-polygene/app/templates/SolrIndexingModule/bootstrap.tmpl new file mode 100644 index 0000000..2644f78 --- /dev/null +++ b/tools/generator-polygene/app/templates/SolrIndexingModule/bootstrap.tmpl @@ -0,0 +1,49 @@ +<%# + * 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. + * + * +-%> +package <%= packageName %>.bootstrap.infrastructure; + +import org.apache.polygene.api.common.Visibility; +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.index.rdf.assembly.RdfNativeSesameStoreAssembler; +import org.apache.polygene.library.rdf.repository.NativeConfiguration; + +public class SolrIndexingModule + implements ModuleAssembler +{ + public static final String NAME = "Solr Indexing Module"; + private final ModuleAssembly configModule; + + public SolrIndexingModule( ModuleAssembly configModule ) + { + this.configModule = configModule; + } + + @Override + public ModuleAssembly assemble( LayerAssembly layer, ModuleAssembly module ) + throws AssemblyException + { + new SolrAssembler(Visibility.application, Visibility.module).assemble( module ); + return module; + } +} +
