http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ea639e83/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/common/SecurityModuleWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/common/SecurityModuleWriter.java b/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/common/SecurityModuleWriter.java deleted file mode 100644 index baebfd6..0000000 --- a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/common/SecurityModuleWriter.java +++ /dev/null @@ -1,85 +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 org.apache.polygene.tools.shell.create.project.common; - -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Map; -import org.apache.polygene.tools.shell.FileUtils; - -import static java.lang.String.format; - -public class SecurityModuleWriter -{ - - public void writeClass( Map<String, String> properties ) - throws IOException - { - String rootPackage = properties.get( "root.package" ); - String projectName = properties.get( "project.name" ); - try (PrintWriter pw = createPrinter( properties )) - { - pw.print( "package " ); - pw.print( properties.get( "root.package" ) ); - pw.println( ".bootstrap.domain;" ); - pw.println(); - pw.println( - "import org.apache.polygene.api.common.Visibility;\n" + - "import org.apache.polygene.bootstrap.AssemblyException;\n" + - "import org.apache.polygene.bootstrap.LayerAssembly;\n" + - "import org.apache.polygene.bootstrap.ModuleAssembly;\n" + - "import org.apache.polygene.bootstrap.layered.ModuleAssembler;"); - pw.println(format("import %s.model.orders.Order;", rootPackage)); - pw.println(format("import %s.model.orders.OrderItem;", rootPackage)); - pw.println(format("import %s.model.orders.Customer;", rootPackage)); - pw.println(format("import %s.model.security.SecurityRepository;", rootPackage)); - pw.println(format("import %s.model.security.HardcodedSecurityRepositoryMixin;", rootPackage)); - pw.println(); - pw.println( - "public class SecurityModule\n" + - " implements ModuleAssembler\n" + - "{\n" + - " public static String NAME;\n" + - "\n" + - " @Override\n" + - " public ModuleAssembly assemble( LayerAssembly layer, ModuleAssembly module )\n" + - " throws AssemblyException\n" + - " {\n" + - " module.services( SecurityRepository.class )\n" + - " .withMixins( HardcodedSecurityRepositoryMixin.class )\n" + - " .visibleIn( Visibility.application )\n" + - " .instantiateOnStartup();\n" + - "\n" + - " return module;\n" + - " }\n" + - "}\n" - ); - } - } - - private PrintWriter createPrinter( Map<String, String> properties ) - throws IOException - { - String packagename = properties.get( "root.package" ).replaceAll( "\\.", "/" ) + "/bootstrap/domain/"; - String classname = "SecurityModule"; - return FileUtils.createJavaClassPrintWriter( properties, "bootstrap", packagename, classname ); - } -}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ea639e83/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/common/SecurityRepositoryWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/common/SecurityRepositoryWriter.java b/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/common/SecurityRepositoryWriter.java deleted file mode 100644 index 013286a..0000000 --- a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/common/SecurityRepositoryWriter.java +++ /dev/null @@ -1,67 +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 org.apache.polygene.tools.shell.create.project.common; - -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Map; -import org.apache.polygene.tools.shell.FileUtils; - -public class SecurityRepositoryWriter -{ - - public void writeClass( Map<String, String> properties ) - throws IOException - { - String rootPackage = properties.get( "root.package" ); - try (PrintWriter pw = createPrinter( properties )) - { - pw.print( "package " ); - pw.print( properties.get( "root.package" ) ); - pw.println( ".model.security;" ); - pw.println(); - pw.println( - "import java.util.List;\n" + - "import org.apache.polygene.api.concern.Concerns;\n" + - "import org.apache.polygene.api.unitofwork.concern.UnitOfWorkConcern;\n" + - "import org.apache.polygene.api.unitofwork.concern.UnitOfWorkPropagation;\n" + - "\n" + - "@Concerns( UnitOfWorkConcern.class )\n" + - "public interface SecurityRepository\n" + - "{\n" + - " @UnitOfWorkPropagation\n" + - " boolean verifyPassword( String user, String password );\n" + - "\n" + - " @UnitOfWorkPropagation\n" + - " List<String> findRoleNamesOfUser( String name );\n" + - "}\n" - ); - } - } - - private PrintWriter createPrinter( Map<String, String> properties ) - throws IOException - { - String packagename = properties.get( "root.package" ).replaceAll( "\\.", "/" ) + "/model/security/"; - String classname = "SecurityRepository"; - return FileUtils.createJavaClassPrintWriter( properties, "model", packagename, classname ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ea639e83/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/common/SerializationModuleWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/common/SerializationModuleWriter.java b/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/common/SerializationModuleWriter.java deleted file mode 100644 index b604916..0000000 --- a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/common/SerializationModuleWriter.java +++ /dev/null @@ -1,76 +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 org.apache.polygene.tools.shell.create.project.common; - -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Map; -import org.apache.polygene.tools.shell.FileUtils; - -public class SerializationModuleWriter -{ - - public void writeClass( Map<String, String> properties ) - throws IOException - { - String rootPackage = properties.get( "root.package" ); - String projectName = properties.get( "project.name" ); - try (PrintWriter pw = createPrinter( properties )) - { - pw.print( "package " ); - pw.print( properties.get( "root.package" ) ); - pw.println( ".bootstrap.infrastructure;" ); - pw.println(); - pw.println( - "import org.apache.polygene.api.common.Visibility;\n" + - "import org.apache.polygene.bootstrap.AssemblyException;\n" + - "import org.apache.polygene.bootstrap.LayerAssembly;\n" + - "import org.apache.polygene.bootstrap.ModuleAssembly;\n" + - "import org.apache.polygene.bootstrap.layered.ModuleAssembler;\n" + - "import org.apache.polygene.valueserialization.jackson.JacksonValueSerializationAssembler;\n" + - "\n" + - "public class SerializationModule\n" + - " implements ModuleAssembler\n" + - "{\n" + - " public static final String NAME = \"Serialization Module\";\n" + - "\n" + - " @Override\n" + - " public ModuleAssembly assemble( LayerAssembly layer, ModuleAssembly module )\n" + - " throws AssemblyException\n" + - " {\n" + - " new JacksonValueSerializationAssembler()\n" + - " .visibleIn( Visibility.application )\n" + - " .assemble( module );\n" + - " return module;\n" + - " }\n" + - "}\n" - ); - } - } - - private PrintWriter createPrinter( Map<String, String> properties ) - throws IOException - { - String packagename = properties.get( "root.package" ).replaceAll( "\\.", "/" ) + "/bootstrap/infrastructure/"; - String classname = "SerializationModule"; - return FileUtils.createJavaClassPrintWriter( properties, "bootstrap", packagename, classname ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ea639e83/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/common/StorageModuleWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/common/StorageModuleWriter.java b/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/common/StorageModuleWriter.java deleted file mode 100644 index 3eaf068..0000000 --- a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/common/StorageModuleWriter.java +++ /dev/null @@ -1,85 +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 org.apache.polygene.tools.shell.create.project.common; - -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Map; -import org.apache.polygene.tools.shell.FileUtils; - -public class StorageModuleWriter -{ - - public void writeClass( Map<String, String> properties ) - throws IOException - { - String rootPackage = properties.get( "root.package" ); - String projectName = properties.get( "project.name" ); - try (PrintWriter pw = createPrinter( properties )) - { - pw.print( "package " ); - pw.print( properties.get( "root.package" ) ); - pw.println( ".bootstrap.infrastructure;" ); - pw.println(); - pw.println( - "import org.apache.polygene.api.common.Visibility;\n" + - "import org.apache.polygene.bootstrap.AssemblyException;\n" + - "import org.apache.polygene.bootstrap.LayerAssembly;\n" + - "import org.apache.polygene.bootstrap.ModuleAssembly;\n" + - "import org.apache.polygene.bootstrap.layered.ModuleAssembler;\n" + - "import org.apache.polygene.entitystore.file.assembly.FileEntityStoreAssembler;\n" + - "\n" + - "public class StorageModule\n" + - " implements ModuleAssembler\n" + - "{\n" + - " public static final String NAME = \"Storage Module\";\n" + - " private final ModuleAssembly configModule;\n" + - "\n" + - " public StorageModule( ModuleAssembly configModule )\n" + - " {\n" + - " this.configModule = configModule;\n" + - " }\n" + - "\n" + - " @Override\n" + - " public ModuleAssembly assemble( LayerAssembly layer, ModuleAssembly module )\n" + - " throws AssemblyException\n" + - " {\n" + - "\n" + - " new FileEntityStoreAssembler()\n" + - " .visibleIn( Visibility.application )\n" + - " .withConfig( configModule, Visibility.application )\n" + - " .identifiedBy( \"filestore\" )\n" + - " .assemble( module );\n" + - " return module;\n" + - " }\n" + - "}\n" - ); - } - } - - private PrintWriter createPrinter( Map<String, String> properties ) - throws IOException - { - String packagename = properties.get( "root.package" ).replaceAll( "\\.", "/" ) + "/bootstrap/infrastructure/"; - String classname = "StorageModule"; - return FileUtils.createJavaClassPrintWriter( properties, "bootstrap", packagename, classname ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ea639e83/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/defaultp/ApplicationWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/defaultp/ApplicationWriter.java b/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/defaultp/ApplicationWriter.java deleted file mode 100644 index cfa0a95..0000000 --- a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/defaultp/ApplicationWriter.java +++ /dev/null @@ -1,102 +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 org.apache.polygene.tools.shell.create.project.defaultp; - -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Map; -import org.apache.polygene.tools.shell.FileUtils; - -import static java.lang.String.format; - -public class ApplicationWriter -{ - - public void writeClass( Map<String, String> properties ) - throws IOException - { - String rootPackage = properties.get( "root.package" ); - String projectName = properties.get( "project.name" ); - try (PrintWriter pw = createPrinter( properties )) - { - pw.print( "package " ); - pw.print( properties.get( "root.package" ) ); - pw.println( ".app;" ); - pw.println(); - pw.println( "import java.lang.reflect.UndeclaredThrowableException;" ); - pw.println( "import org.apache.polygene.api.structure.Application;" ); - pw.println( "import org.apache.polygene.api.structure.Module;" ); - pw.println( "import org.apache.polygene.bootstrap.AssemblyException;" ); - pw.println( "import org.apache.polygene.bootstrap.Energy4Java;" ); - pw.println( "import org.apache.polygene.bootstrap.layered.LayeredApplicationAssembler;" ); - pw.println( "import org.apache.polygene.library.restlet.ZrestApplication;" ); - pw.println( format( "import %s.bootstrap.%sApplicationAssembler;", rootPackage, projectName ) ); - pw.println( format( "import %s.model.security.SecurityRepository;", rootPackage ) ); - pw.println(); - pw.println( format( "public class %s", projectName ) ); - pw.println( "{\n" ); - pw.println( " private static Energy4Java polygene;" ); - pw.println( " private static Application app;" ); - pw.println(); - - pw.println( " private static void registerShutdownHook()" ); - pw.println( " {" ); - pw.println( " Runtime.getRuntime().addShutdownHook( new Thread( new Runnable()\n" + - " {\n" + - " @Override\n" + - " public void run()\n" + - " {\n" + - " try\n" + - " {\n" + - " app.passivate();\n" + - " }\n" + - " catch( Exception e )\n" + - " {\n" + - " System.err.println( \"Clean Shutdown of application failed.\" );\n" + - " e.printStackTrace();\n" + - " }\n" + - " }\n" + - " }, \"Shutdown Hook for Polygene\" ) );\n" ); - pw.println( " }\n" ); - pw.println( " public static void main( String[] args )" ); - pw.println( " {" ); - pw.println( " polygene = new Energy4Java();" ); - pw.println( format(" app = polygene.newApplication( new %sApplicationAssembler() );", projectName) ); - pw.println( " registerShutdownHook();" ); - pw.println( " app.activate();\n" ); - pw.println(); - pw.println( " // Example interfacing" ); - pw.println( " Module securityModule = app.findModule( \"DomainLayer\", \"SecurityModule\" );" ); - pw.println( " SecurityRepository = securityModule.serviceFinder().findService( SecurityRepository.class );" ); - pw.println( " }\n" ); - pw.println( "}" ); - pw.println(); - } - } - - private PrintWriter createPrinter( Map<String, String> properties ) - throws IOException - { - String packagename = properties.get( "root.package" ).replaceAll( "\\.", "/" ) + "/app/"; - String classname = properties.get("project.name"); - return FileUtils.createJavaClassPrintWriter( properties, "app", packagename, classname ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ea639e83/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/defaultp/SettingsWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/defaultp/SettingsWriter.java b/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/defaultp/SettingsWriter.java deleted file mode 100644 index 51fc344..0000000 --- a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/defaultp/SettingsWriter.java +++ /dev/null @@ -1,80 +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 org.apache.polygene.tools.shell.create.project.defaultp; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Map; - -public class SettingsWriter -{ - - public void writeClass( Map<String, String> properties ) - throws IOException - { - String projectName = properties.get( "project.name" ); - try (PrintWriter pw = createPrinter( properties )) - { - pw.println( - String.format( - "\n" + - "include 'app',\n" + - " 'bootstrap',\n" + - " 'model'\n" + - "\n" + - "rootProject.name = \"%s\"\n" + - "\n" + - "validateProject(rootProject, \"\")\n" + - "\n" + - "def validateProject(project, parentName)\n" + - "{\n" + - " assert project.projectDir.isDirectory()\n" + - " if( new File(\"$project.projectDir/src/main/java\").exists() )\n" + - " {\n" + - " assert project.buildFile.isFile()\n" + - " }\n" + - " if( parentName.length() > 0 )\n" + - " println \"Project: \" + project.name\n" + - " project.children.each { child ->\n" + - " validateProject(child, project.name)\n" + - " }\n" + - "}\n" + - "\n", projectName - ) ); - } - } - - private PrintWriter createPrinter( Map<String, String> properties ) - throws IOException - { - File projectDir = new File( properties.get( "project.dir" ) ); - if( !projectDir.exists() ) - { - if( !projectDir.mkdirs() ) - { - System.err.println( "Unable to create directory: " + projectDir.getAbsolutePath() ); - } - } - return new PrintWriter( new FileWriter( new File( projectDir, "settings.gradle" ) ) ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ea639e83/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/ApplicationWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/ApplicationWriter.java b/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/ApplicationWriter.java deleted file mode 100644 index 6b4816a..0000000 --- a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/ApplicationWriter.java +++ /dev/null @@ -1,136 +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 org.apache.polygene.tools.shell.create.project.restapp; - -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Map; -import org.apache.polygene.tools.shell.FileUtils; - -import static java.lang.String.format; - -public class ApplicationWriter -{ - - public void writeClass( Map<String, String> properties ) - throws IOException - { - String rootPackage = properties.get( "root.package" ); - String projectName = properties.get( "project.name" ); - try (PrintWriter pw = createPrinter( properties )) - { - pw.print( "package " ); - pw.print( properties.get( "root.package" ) ); - pw.println( ".app;" ); - pw.println(); - pw.println( "import java.lang.reflect.UndeclaredThrowableException;" ); - pw.println( "import org.apache.polygene.api.structure.Application;" ); - pw.println( "import org.apache.polygene.bootstrap.AssemblyException;" ); - pw.println( "import org.apache.polygene.bootstrap.layered.LayeredApplicationAssembler;" ); - pw.println( "import org.apache.polygene.library.restlet.ZrestApplication;" ); - pw.println( "import org.restlet.Context;" ); - pw.println( "import org.restlet.routing.Filter;" ); - pw.println( "import org.restlet.routing.Router;" ); - pw.println( "import org.restlet.security.Enroler;" ); - pw.println( "import org.restlet.security.Verifier;" ); - pw.println( format( "import %s.bootstrap.%sApplicationAssembler;", rootPackage, projectName ) ); - pw.println( format( "import %s.bootstrap.connectivity.ConnectivityLayer;", rootPackage ) ); - pw.println( format( "import %s.bootstrap.connectivity.RestModule;", rootPackage ) ); - pw.println( format( "import %s.model.orders.Order;", rootPackage ) ); - pw.println( format( "import %s.model.orders.Customer;", rootPackage ) ); - pw.println(format("import %s.rest.security.SimpleEnroler;", rootPackage)); - pw.println(format("import %s.rest.security.SimpleVerifier;", rootPackage)); - pw.println(); - pw.println( format( "public class %s extends ZrestApplication", projectName ) ); - pw.println( "{\n" ); - pw.println( format( " public %s( Context context )", projectName ) ); - pw.println( " throws AssemblyException" ); - pw.println( " {" ); - pw.println( " super( context );" ); - pw.println( " }\n" ); - pw.println( " @Override" ); - pw.println( " protected void addRoutes( Router router )" ); - pw.println( " {" ); - pw.println( " addResourcePath( \"orders\", Order.class, \"/\" );" ); - pw.println( " addResourcePath( \"customers\", Customer.class, \"/\" );" ); - pw.println( " }\n" ); - - pw.println( " @Override" ); - pw.println( " protected LayeredApplicationAssembler createApplicationAssembler( String mode )" ); - pw.println( " throws AssemblyException" ); - pw.println( " {" ); - pw.println( " if( mode != null )" ); - pw.println( " {" ); - pw.println( format(" return new %sApplicationAssembler( Application.Mode.valueOf( mode ) );", projectName) ); - pw.println( " }" ); - pw.println( format(" return new %sApplicationAssembler( Application.Mode.production );", projectName) ); - pw.println( " }" ); - pw.println(); - pw.println( " @Override" ); - pw.println( " protected Verifier createVerifier()" ); - pw.println( " {" ); - pw.println( " return newObject( SimpleVerifier.class );" ); - pw.println( " }" ); - pw.println(); - pw.println( " @Override" ); - pw.println( " protected Enroler createEnroler()" ); - pw.println( " {" ); - pw.println( " return newObject( SimpleEnroler.class, this );" ); - pw.println( " }" ); - pw.println(); - pw.println( " @Override" ); - pw.println( " protected String getConnectivityLayer()" ); - pw.println( " {" ); - pw.println( " return ConnectivityLayer.NAME;" ); - pw.println( " }" ); - pw.println(); - pw.println( " @Override" ); - pw.println( " protected String getConnectivityModule()" ); - pw.println( " {" ); - pw.println( " return RestModule.NAME;" ); - pw.println( " }" ); - pw.println(); - pw.println( " private <T> T newObject( Class<T> type, Object... uses )" ); - pw.println( " {" ); - pw.println( " try" ); - pw.println( " {" ); - pw.println( " T instamce = type.newInstance();" ); - pw.println( " objectFactory.injectTo( instamce, uses );" ); - pw.println( " return instamce;" ); - pw.println( " }" ); - pw.println( " catch( Exception e )" ); - pw.println( " {" ); - pw.println( " throw new UndeclaredThrowableException( e );" ); - pw.println( " }" ); - pw.println( " }" ); - pw.println( "}" ); - pw.println(); - } - } - - private PrintWriter createPrinter( Map<String, String> properties ) - throws IOException - { - String packagename = properties.get( "root.package" ).replaceAll( "\\.", "/" ) + "/app/"; - String classname = properties.get("project.name"); - return FileUtils.createJavaClassPrintWriter( properties, "app", packagename, classname ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ea639e83/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/IndexHtmlWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/IndexHtmlWriter.java b/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/IndexHtmlWriter.java deleted file mode 100644 index 3252b9b..0000000 --- a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/IndexHtmlWriter.java +++ /dev/null @@ -1,68 +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 org.apache.polygene.tools.shell.create.project.restapp; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Map; - -public class IndexHtmlWriter -{ - - public void writeClass( Map<String, String> properties ) - throws IOException - { - String rootPackage = properties.get( "root.package" ); - String projectName = properties.get( "project.name" ); - try (PrintWriter pw = createPrinter( properties )) - { - pw.println( - String.format( - "<!DOCTYPE html>\n" + - "<html>\n" + - "<head>\n" + - "</head>\n" + - "<body>\n" + - "<h1>Welcome to %s</h1>\n" + - "</body></html>\n" + - "\n", projectName ) - ); - } - } - - private PrintWriter createPrinter( Map<String, String> properties ) - throws IOException - { - File projectDir = new File( properties.get( "project.dir" ) ); - File destDir = new File( projectDir, "app/src/main/webapp" ); - if( !destDir.exists() ) - { - if( !destDir.mkdirs() ) - { - System.err.println( "Unable to create directory: " + destDir.getAbsolutePath() ); - } - } - return new PrintWriter( new FileWriter( new File( destDir, "index.html" ) ) ); - } -} - http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ea639e83/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/OrderModuleWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/OrderModuleWriter.java b/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/OrderModuleWriter.java deleted file mode 100644 index f837d9d..0000000 --- a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/OrderModuleWriter.java +++ /dev/null @@ -1,88 +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 org.apache.polygene.tools.shell.create.project.restapp; - -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Map; -import org.apache.polygene.tools.shell.FileUtils; - -import static java.lang.String.format; - -public class OrderModuleWriter -{ - - public void writeClass( Map<String, String> properties ) - throws IOException - { - String rootPackage = properties.get( "root.package" ); - String projectName = properties.get( "project.name" ); - try (PrintWriter pw = createPrinter( properties )) - { - pw.print( "package " ); - pw.print( properties.get( "root.package" ) ); - pw.println( ".bootstrap.domain;" ); - pw.println(); - pw.println( - "import org.apache.polygene.api.common.Visibility;\n" + - "import org.apache.polygene.bootstrap.AssemblyException;\n" + - "import org.apache.polygene.bootstrap.LayerAssembly;\n" + - "import org.apache.polygene.bootstrap.ModuleAssembly;\n" + - "import org.apache.polygene.bootstrap.layered.ModuleAssembler;" + - "import org.apache.polygene.library.restlet.assembly.RestletCrudModuleAssembler;"); - pw.println(format("import %s.model.orders.Order;", rootPackage)); - pw.println(format("import %s.model.orders.OrderItem;", rootPackage)); - pw.println(format("import %s.model.orders.Customer;", rootPackage)); - pw.println(); - pw.println( - "public class OrderModule\n" + - " implements ModuleAssembler\n" + - "{\n" + - " public static String NAME;\n" + - "\n" + - " @Override\n" + - " public ModuleAssembly assemble( LayerAssembly layer, ModuleAssembly module )\n" + - " throws AssemblyException\n" + - " {\n" + - " module.values( /* add value types */ );\n" + - " module.entities( /* add entity types */ );\n\n" + - " // These assemblers sets up CRUD access to the entity types listed.\n" + - " new RestletCrudModuleAssembler( Order.class ).assemble( module );\n" + - " new RestletCrudModuleAssembler( OrderItem.class ).assemble( module );\n" + - " new RestletCrudModuleAssembler( Customer.class ).assemble( module );\n" + - " module.services( /* add services */ )\n" + - " .visibleIn( Visibility.layer )\n" + - " .instantiateOnStartup();\n" + - " return module;\n" + - " }\n" + - "}\n" - ); - } - } - - private PrintWriter createPrinter( Map<String, String> properties ) - throws IOException - { - String packagename = properties.get( "root.package" ).replaceAll( "\\.", "/" ) + "/bootstrap/domain/"; - String classname = "OrderModule"; - return FileUtils.createJavaClassPrintWriter( properties, "bootstrap", packagename, classname ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ea639e83/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/RestModuleWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/RestModuleWriter.java b/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/RestModuleWriter.java deleted file mode 100644 index 3913f59..0000000 --- a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/RestModuleWriter.java +++ /dev/null @@ -1,83 +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 org.apache.polygene.tools.shell.create.project.restapp; - -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Map; -import org.apache.polygene.tools.shell.FileUtils; - -import static java.lang.String.format; - -public class RestModuleWriter -{ - - public void writeClass( Map<String, String> properties ) - throws IOException - { - String rootPackage = properties.get( "root.package" ); - String projectName = properties.get( "project.name" ); - try (PrintWriter pw = createPrinter( properties )) - { - pw.print( "package " ); - pw.print( properties.get( "root.package" ) ); - pw.println( ".bootstrap.connectivity;" ); - pw.println(); - pw.println(format("import %s.rest.security.SimpleEnroler;", rootPackage)); - pw.println(format("import %s.rest.security.SimpleVerifier;", rootPackage)); - pw.println( - "import org.apache.polygene.bootstrap.AssemblyException;\n" + - "import org.apache.polygene.bootstrap.LayerAssembly;\n" + - "import org.apache.polygene.bootstrap.ModuleAssembly;\n" + - "import org.apache.polygene.bootstrap.layered.ModuleAssembler;\n" + - "import org.apache.polygene.library.restlet.assembly.RestletCrudConnectivityAssembler;\n" + - "import org.apache.polygene.library.restlet.resource.EntryPoint;\n" + - "\n" + - "public class RestModule\n" + - " implements ModuleAssembler\n" + - "{\n" + - " public static String NAME;\n" + - "\n" + - " @Override\n" + - " public ModuleAssembly assemble( LayerAssembly layer, ModuleAssembly module )\n" + - " throws AssemblyException\n" + - " {\n" + - " module.objects( SimpleVerifier.class, SimpleEnroler.class);\n" + - "\n" + - " new RestletCrudConnectivityAssembler().assemble( module );\n" + - " module.values( EntryPoint.class );\n" + - " module.values( /* add value types */ );\n" + - " module.services( /* add services */ );\n" + - " return module;\n" + - " }\n" + - "}\n" - ); - } - } - - private PrintWriter createPrinter( Map<String, String> properties ) - throws IOException - { - String packagename = properties.get( "root.package" ).replaceAll( "\\.", "/" ) + "/bootstrap/connectivity/"; - String classname = "RestModule"; - return FileUtils.createJavaClassPrintWriter( properties, "bootstrap", packagename, classname ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ea639e83/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/SettingsWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/SettingsWriter.java b/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/SettingsWriter.java deleted file mode 100644 index 022a272..0000000 --- a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/SettingsWriter.java +++ /dev/null @@ -1,81 +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 org.apache.polygene.tools.shell.create.project.restapp; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Map; - -public class SettingsWriter -{ - - public void writeClass( Map<String, String> properties ) - throws IOException - { - String projectName = properties.get( "project.name" ); - try (PrintWriter pw = createPrinter( properties )) - { - pw.println( - String.format( - "\n" + - "include 'app',\n" + - " 'bootstrap',\n" + - " 'model',\n" + - " 'rest'\n" + - "\n" + - "rootProject.name = \"%s\"\n" + - "\n" + - "validateProject(rootProject, \"\")\n" + - "\n" + - "def validateProject(project, parentName)\n" + - "{\n" + - " assert project.projectDir.isDirectory()\n" + - " if( new File(\"$project.projectDir/src/main/java\").exists() )\n" + - " {\n" + - " assert project.buildFile.isFile()\n" + - " }\n" + - " if( parentName.length() > 0 )\n" + - " println \"Project: \" + project.name\n" + - " project.children.each { child ->\n" + - " validateProject(child, project.name)\n" + - " }\n" + - "}\n" + - "\n", projectName - ) ); - } - } - - private PrintWriter createPrinter( Map<String, String> properties ) - throws IOException - { - File projectDir = new File( properties.get( "project.dir" ) ); - if( !projectDir.exists() ) - { - if( !projectDir.mkdirs() ) - { - System.err.println( "Unable to create directory: " + projectDir.getAbsolutePath() ); - } - } - return new PrintWriter( new FileWriter( new File( projectDir, "settings.gradle" ) ) ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ea639e83/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/SimpleEnrolerWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/SimpleEnrolerWriter.java b/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/SimpleEnrolerWriter.java deleted file mode 100644 index 2abf0c5..0000000 --- a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/SimpleEnrolerWriter.java +++ /dev/null @@ -1,86 +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 org.apache.polygene.tools.shell.create.project.restapp; - -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Map; -import org.apache.polygene.tools.shell.FileUtils; - -import static java.lang.String.format; - -public class SimpleEnrolerWriter -{ - - public void writeClass( Map<String, String> properties ) - throws IOException - { - String rootPackage = properties.get( "root.package" ); - try (PrintWriter pw = createPrinter( properties )) - { - pw.print( "package " ); - pw.print( properties.get( "root.package" ) ); - pw.println( ".rest.security;" ); - pw.println(); - pw.println( - "import java.util.ArrayList;\n" + - "import java.util.List;\n" + - "import org.apache.polygene.api.injection.scope.Service;\n" + - "import org.apache.polygene.api.injection.scope.Uses;\n" + - "import org.restlet.Application;\n" + - "import org.restlet.data.ClientInfo;\n" + - "import org.restlet.security.Enroler;\n" + - "import org.restlet.security.Role;" ); - pw.println( format( "import %s.model.security.SecurityRepository;\n", rootPackage )); - pw.println(); - pw.println( - "public class SimpleEnroler\n" + - " implements Enroler\n" + - "{\n" + - " @Service\n" + - " private SecurityRepository repository;\n" + - "\n" + - " @Uses\n" + - " private Application application;\n" + - "\n" + - " @Override\n" + - " public void enrole( ClientInfo clientInfo )\n" + - " {\n" + - " org.restlet.security.User user = clientInfo.getUser();\n" + - " String name = user.getName();\n" + - " List<String> roleList = repository.findRoleNamesOfUser( name );\n" + - " List<Role> restletRoles = new ArrayList<>();\n" + - " roleList.stream().map( roleName -> Role.get( application, roleName ) );\n" + - " clientInfo.setRoles( restletRoles );\n" + - " }\n" + - "}\n" - ); - } - } - - private PrintWriter createPrinter( Map<String, String> properties ) - throws IOException - { - String packagename = properties.get( "root.package" ).replaceAll( "\\.", "/" ) + "/rest/security/"; - String classname = "SimpleEnroler"; - return FileUtils.createJavaClassPrintWriter( properties, "rest", packagename, classname ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ea639e83/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/SimpleVerifierWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/SimpleVerifierWriter.java b/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/SimpleVerifierWriter.java deleted file mode 100644 index 48a6d0a..0000000 --- a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/SimpleVerifierWriter.java +++ /dev/null @@ -1,80 +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 org.apache.polygene.tools.shell.create.project.restapp; - -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Map; -import org.apache.polygene.tools.shell.FileUtils; - -import static java.lang.String.format; - -public class SimpleVerifierWriter -{ - - public void writeClass( Map<String, String> properties ) - throws IOException - { - String rootPackage = properties.get( "root.package" ); - try (PrintWriter pw = createPrinter( properties )) - { - pw.print( "package " ); - pw.print( properties.get( "root.package" ) ); - pw.println( ".rest.security;" ); - pw.println(); - pw.println( - "import org.apache.polygene.api.injection.scope.Service;\n" + - "import org.restlet.security.SecretVerifier;\n" + - "import org.restlet.security.Verifier;\n" + - format( "import %s.model.security.SecurityRepository;\n", rootPackage ) + - "\n" + - "public class SimpleVerifier extends SecretVerifier\n" + - " implements Verifier\n" + - "{\n" + - " @Service\n" + - " private SecurityRepository repository;\n" + - "\n" + - " @Override\n" + - " public int verify( String user, char[] secret )\n" + - " {\n" + - " if( user == null || secret == null )\n" + - " {\n" + - " return RESULT_UNKNOWN;\n" + - " }\n" + - " if( repository.verifyPassword( user, String.valueOf( secret ) ) )\n" + - " {\n" + - " return RESULT_VALID;\n" + - " }\n" + - " return RESULT_INVALID;\n" + - " }\n" + - "}\n" - ); - } - } - - private PrintWriter createPrinter( Map<String, String> properties ) - throws IOException - { - String packagename = properties.get( "root.package" ).replaceAll( "\\.", "/" ) + "/rest/security/"; - String classname = "SimpleVerifier"; - return FileUtils.createJavaClassPrintWriter( properties, "rest", packagename, classname ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ea639e83/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/WebXmlWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/WebXmlWriter.java b/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/WebXmlWriter.java deleted file mode 100644 index 5a181ec..0000000 --- a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/restapp/WebXmlWriter.java +++ /dev/null @@ -1,93 +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 org.apache.polygene.tools.shell.create.project.restapp; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Map; - -public class WebXmlWriter -{ - - public void writeClass( Map<String, String> properties ) - throws IOException - { - String rootPackage = properties.get( "root.package" ); - String projectName = properties.get( "project.name" ); - try (PrintWriter pw = createPrinter( properties )) - { - pw.println( - String.format( - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + - "\n" + - "<web-app xmlns=\"http://java.sun.com/xml/ns/javaee\"\n" + - " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + - " xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd\"\n" + - " version=\"3.0\">\n" + - "\n" + - " <servlet>\n" + - " <servlet-name>polygenerest</servlet-name>\n" + - " <servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>\n" + - " <init-param>\n" + - " <param-name>org.apache.polygene.runtime.mode</param-name>\n" + - " <param-value>production</param-value>\n" + - " </init-param>\n" + - " <init-param>\n" + - " <!-- Application class name -->\n" + - " <param-name>org.restlet.application</param-name>\n" + - " <param-value>%s</param-value>\n" + - " </init-param>\n" + - " <init-param>\n" + - " <!-- Protocols to be bound to-->\n" + - " <param-name>org.restlet.clients</param-name>\n" + - " <param-value>HTTP HTTPS</param-value>\n" + - " </init-param>\n" + - " <load-on-startup>1</load-on-startup>\n" + - " </servlet>\n" + - "\n" + - " <servlet-mapping>\n" + - " <servlet-name>polygenerest</servlet-name>\n" + - " <url-pattern>/api/*</url-pattern>\n" + - " </servlet-mapping>\n" + - "\n" + - "</web-app>\n", rootPackage + ".app." + projectName ) - ); - } - } - - private PrintWriter createPrinter( Map<String, String> properties ) - throws IOException - { - File projectDir = new File( properties.get( "project.dir" ) ); - File destDir = new File( projectDir, "app/src/main/webapp/WEB-INF" ); - if( !destDir.exists() ) - { - if( !destDir.mkdirs() ) - { - System.err.println( "Unable to create directory: " + destDir.getAbsolutePath() ); - } - } - return new PrintWriter( new FileWriter( new File( destDir, "web.xml" ) ) ); - } -} - http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ea639e83/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/singleton/SettingsWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/singleton/SettingsWriter.java b/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/singleton/SettingsWriter.java deleted file mode 100644 index 8622933..0000000 --- a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/singleton/SettingsWriter.java +++ /dev/null @@ -1,76 +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 org.apache.polygene.tools.shell.create.project.singleton; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Map; - -public class SettingsWriter -{ - - public void writeClass( Map<String, String> properties ) - throws IOException - { - String projectName = properties.get( "project.name" ); - try (PrintWriter pw = createPrinter( properties )) - { - pw.println( - String.format( - "\n" + - "rootProject.name = \"%s\"\n" + - "\n" + - "validateProject(rootProject, \"\")\n" + - "\n" + - "def validateProject(project, parentName)\n" + - "{\n" + - " assert project.projectDir.isDirectory()\n" + - " if( new File(\"$project.projectDir/src/main/java\").exists() )\n" + - " {\n" + - " assert project.buildFile.isFile()\n" + - " }\n" + - " if( parentName.length() > 0 )\n" + - " println \"Project: \" + project.name\n" + - " project.children.each { child ->\n" + - " validateProject(child, project.name)\n" + - " }\n" + - "}\n" + - "\n", projectName - ) ); - } - } - - private PrintWriter createPrinter( Map<String, String> properties ) - throws IOException - { - File projectDir = new File( properties.get( "project.dir" ) ); - if( !projectDir.exists() ) - { - if( !projectDir.mkdirs() ) - { - System.err.println( "Unable to create directory: " + projectDir.getAbsolutePath() ); - } - } - return new PrintWriter( new FileWriter( new File( projectDir, "settings.gradle" ) ) ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ea639e83/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/singleton/SingletonApplicationAssemblerWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/singleton/SingletonApplicationAssemblerWriter.java b/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/singleton/SingletonApplicationAssemblerWriter.java deleted file mode 100644 index 4069841..0000000 --- a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/singleton/SingletonApplicationAssemblerWriter.java +++ /dev/null @@ -1,103 +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 org.apache.polygene.tools.shell.create.project.singleton; - -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Map; -import org.apache.polygene.tools.shell.FileUtils; - -import static java.lang.String.format; - -public class SingletonApplicationAssemblerWriter -{ - - public void writeClass( Map<String, String> properties ) - throws IOException - { - String rootPackage = properties.get( "root.package" ); - String projectName = properties.get( "project.name" ); - try (PrintWriter pw = createPrinter( properties )) - { - pw.print( "package " ); - pw.print( properties.get( "root.package" ) ); - pw.println( ".app;" ); - pw.println(); - pw.println( "import org.apache.polygene.api.structure.Application;" ); - pw.println( "import org.apache.polygene.bootstrap.AssemblyException;" ); - pw.println(); - pw.println( format( "public class %s", projectName ) ); - pw.println( "{\n" ); - pw.println( " public static void main( String[] args )"); - pw.println( " throws Exception" ); - pw.println( " {" ); - pw.println( " SingletonAssembly app = new SingletonAssembly()" ); - pw.println( " {" ); - pw.println( " @Override\n" + - " public void assemble( ModuleAssembly module )\n" + - " throws AssemblyException\n" + - " {\n" + - " module.values( );\n" + - " module.entities( );\n" + - " module.services( StartupService.class );\n" + - " .instantiateOnStartup();\n" + - " }\n" ); - pw.println( " }" ); - pw.println(); - pw.println( " registerShutdownHook();" ); - pw.println( " StartupService startup = app.serviceFinder().findService( StartupService.class );" ); - pw.println(); - pw.println( " // Here the application is ready to do something." ); - pw.println( " // You should add functionality in the StartupService class." ); - pw.println( " }" ); - pw.println( ); - pw.println( " private void registerShutdownHook()" ); - pw.println( " {" ); - pw.println( " Runtime.getRuntime().addShutdownHook( new Thread( new Runnable()\n" + - " {\n" + - " @Override\n" + - " public void run()\n" + - " {\n" + - " try\n" + - " {\n" + - " app.passivate();\n" + - " }\n" + - " catch( Exception e )\n" + - " {\n" + - " System.err.println( \"Clean Shutdown of application failed.\" );\n" + - " e.printStackTrace();\n" + - " }\n" + - " }\n" + - " }, \"Shutdown Hook for Polygene\" ) );\n" ); - pw.println( " }" ); - pw.println( "}" ); - pw.println(); - } - } - - private PrintWriter createPrinter( Map<String, String> properties ) - throws IOException - { - String packagename = properties.get( "root.package" ).replaceAll( "\\.", "/" ); - String classname = properties.get("project.name"); - return FileUtils.createJavaClassPrintWriter( properties, "", packagename, classname ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ea639e83/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/singleton/StartupServiceWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/singleton/StartupServiceWriter.java b/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/singleton/StartupServiceWriter.java deleted file mode 100644 index 9fafd03..0000000 --- a/tools/shell/src/main/java/org/apache/polygene/tools/shell/create/project/singleton/StartupServiceWriter.java +++ /dev/null @@ -1,68 +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 org.apache.polygene.tools.shell.create.project.singleton; - -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Map; -import org.apache.polygene.tools.shell.FileUtils; - -public class StartupServiceWriter -{ - - public void writeClass( Map<String, String> properties ) - throws IOException - { - String rootPackage = properties.get( "root.package" ); - String projectName = properties.get( "project.name" ); - try (PrintWriter pw = createPrinter( properties )) - { - pw.print( "package " ); - pw.print( properties.get( "root.package" ) ); - pw.println( ";" ); - pw.println(); - pw.println("import org.apache.polygene.api.activation.Activation;"); - pw.println(); - pw.println( - "public interface StartupService\n" + - " implements Activation\n" + - "{\n" + - " public void activate()\n" + - " {\n" + - " // TODO This method is called when the application starts.\n" + - " }\n" + - "\n" + - " public void passivate()\n" + - " {\n" + - " // TODO This method is called when the application shutsdown.\n" + - " }\n" + - "}\n"); - } - } - - private PrintWriter createPrinter( Map<String, String> properties ) - throws IOException - { - String packagename = properties.get( "root.package" ).replaceAll( "\\.", "/" ) + "/model/"; - String classname = "StartupService"; - return FileUtils.createJavaClassPrintWriter( properties, "", packagename, classname ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ea639e83/tools/shell/src/main/java/org/apache/polygene/tools/shell/help/HelpCommand.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/polygene/tools/shell/help/HelpCommand.java b/tools/shell/src/main/java/org/apache/polygene/tools/shell/help/HelpCommand.java deleted file mode 100644 index fe61bdc..0000000 --- a/tools/shell/src/main/java/org/apache/polygene/tools/shell/help/HelpCommand.java +++ /dev/null @@ -1,62 +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 org.apache.polygene.tools.shell.help; - -import java.io.BufferedReader; -import java.io.PrintWriter; -import org.apache.polygene.tools.shell.AbstractCommand; -import org.apache.polygene.tools.shell.Command; - -public class HelpCommand extends AbstractCommand -{ - private Iterable<Command> commands; - - public HelpCommand() - { - } - - public void setCommands( Iterable<Command> commands ) - { - this.commands = commands; - } - - @Override - public void execute( String[] args, BufferedReader input, PrintWriter output ) - { - for( Command command : commands ) - { - String text = command.name() + " " + command.description(); - output.println( text ); - output.flush(); - } - } - - @Override - public String description() - { - return "\t\t\t\t\tPrints this help text."; - } - - @Override - public String name() - { - return "help"; - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ea639e83/tools/shell/src/test/java/org/apache/polygene/tools/shell/FileUtilsTest.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/test/java/org/apache/polygene/tools/shell/FileUtilsTest.java b/tools/shell/src/test/java/org/apache/polygene/tools/shell/FileUtilsTest.java deleted file mode 100644 index f2d02b5..0000000 --- a/tools/shell/src/test/java/org/apache/polygene/tools/shell/FileUtilsTest.java +++ /dev/null @@ -1,93 +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 org.apache.polygene.tools.shell; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.util.Map; -import org.junit.Test; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.hamcrest.core.IsNull.notNullValue; -import static org.junit.Assert.assertThat; - -public class FileUtilsTest -{ - @Test - public void createDirectoryTest() throws IOException - { - File f = new File( "habba-zout" ); - assertThat( f.exists(), equalTo( false ) ); - FileUtils.createDir( "habba-zout" ); - assertThat( f.exists(), equalTo( true ) ); - Files.delete( f.toPath() ); - assertThat( f.exists(), equalTo( false ) ); - } - - @Test - public void removeDirTest() throws Exception - { - File srcFile = new File( "build.gradle" ); - Files.write( srcFile.toPath(), "Some content".getBytes() ); - File f = new File( "habba-zout" ); - assertThat( f.exists(), equalTo( false ) ); - File f1 = FileUtils.createDir( "habba-zout" ); - File f2 = FileUtils.createDir( "habba-zout/src" ); - File f3 = FileUtils.createDir( "habba-zout/src/main" ); - File f4 = FileUtils.createDir( "habba-zout/src/test" ); - File f5 = FileUtils.createDir( "habba-zout/src/main/abc" ); - FileUtils.copyFile( srcFile, new File( f1, "build.gradle__" ) ); - FileUtils.copyFile( srcFile, new File( f2, "build.gradle__" ) ); - FileUtils.copyFile( srcFile, new File( f3, "build.gradle__" ) ); - FileUtils.copyFile( srcFile, new File( f4, "build.gradle__" ) ); - FileUtils.copyFile( srcFile, new File( f5, "build.gradle__" ) ); - FileUtils.removeDir( f ); - assertThat( f1.exists(), equalTo( false ) ); - assertThat( f2.exists(), equalTo( false ) ); - assertThat( f3.exists(), equalTo( false ) ); - assertThat( f4.exists(), equalTo( false ) ); - assertThat( f5.exists(), equalTo( false ) ); - } - - @Test - public void readPropertiesResourceTest() - { - TestHelper.setPolygeneZome(); - Map<String, String> map = FileUtils.readTemplateProperties( "restapp" ); - assertThat( map, notNullValue() ); - assertThat( map.get( "template.dir" ), equalTo( "etc/templates/restapp/files" ) ); - } - - @Test - public void copyFileTest() - throws Exception - { - File srcFile = new File( "build.gradle" ); - Files.write( srcFile.toPath(), "Some content".getBytes() ); - File dest = new File( "build.gradle.copy" ); - assertThat( dest.exists(), equalTo( false ) ); - FileUtils.copyFile( srcFile, dest ); - assertThat( dest.exists(), equalTo( true ) ); - Files.delete( dest.toPath() ); - assertThat( dest.exists(), equalTo( false ) ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ea639e83/tools/shell/src/test/java/org/apache/polygene/tools/shell/HelpCommandTest.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/test/java/org/apache/polygene/tools/shell/HelpCommandTest.java b/tools/shell/src/test/java/org/apache/polygene/tools/shell/HelpCommandTest.java deleted file mode 100644 index f2a6c2a..0000000 --- a/tools/shell/src/test/java/org/apache/polygene/tools/shell/HelpCommandTest.java +++ /dev/null @@ -1,43 +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 org.apache.polygene.tools.shell; - -import java.io.ByteArrayOutputStream; -import java.io.PrintWriter; -import java.util.Arrays; -import java.util.List; -import org.apache.polygene.tools.shell.create.CreateProject; -import org.apache.polygene.tools.shell.help.HelpCommand; -import org.junit.Test; - -public class HelpCommandTest -{ - @Test - public void givenTwoCommandsWhenExecutingHelpExpectExplanation(){ - HelpCommand underTest = new HelpCommand(); - List<Command> commands = Arrays.asList( underTest, new CreateProject() ); - underTest.setCommands( commands ); - ByteArrayOutputStream baos = new ByteArrayOutputStream( ); - PrintWriter pw = new PrintWriter( baos ); - underTest.execute( null, null, pw ); - System.out.println(baos.toString()); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ea639e83/tools/shell/src/test/java/org/apache/polygene/tools/shell/HelpNeededExceptionTest.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/test/java/org/apache/polygene/tools/shell/HelpNeededExceptionTest.java b/tools/shell/src/test/java/org/apache/polygene/tools/shell/HelpNeededExceptionTest.java deleted file mode 100644 index 5436502..0000000 --- a/tools/shell/src/test/java/org/apache/polygene/tools/shell/HelpNeededExceptionTest.java +++ /dev/null @@ -1,32 +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 org.apache.polygene.tools.shell; - -import org.apache.polygene.tools.shell.create.CreateProject; -import org.junit.Test; - -public class HelpNeededExceptionTest -{ - @Test(expected = HelpNeededException.class ) - public void helpTest() { - new CreateProject().execute( new String[0], null, null ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ea639e83/tools/shell/src/test/java/org/apache/polygene/tools/shell/TestHelper.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/test/java/org/apache/polygene/tools/shell/TestHelper.java b/tools/shell/src/test/java/org/apache/polygene/tools/shell/TestHelper.java deleted file mode 100644 index c512820..0000000 --- a/tools/shell/src/test/java/org/apache/polygene/tools/shell/TestHelper.java +++ /dev/null @@ -1,46 +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 org.apache.polygene.tools.shell; - -import java.io.File; - -public class TestHelper -{ - public static void setPolygeneZome() - { - String cwd = new File( ".").getAbsolutePath(); - if( cwd.endsWith( "/java/." )) // IDEA default runner - { - String polygeneHome = new File( new File(".").getAbsoluteFile(), "tools/shell/src/dist" ).getAbsolutePath(); - System.setProperty( "polygene.home", polygeneHome ); - } - if( cwd.endsWith( "tools/shell/." )) // Gradle build - { - String polygeneHome = new File( new File(".").getAbsoluteFile(), "src/dist" ).getAbsolutePath(); - System.setProperty( "polygene.home", polygeneHome ); - } - if( cwd.endsWith( "test/work/." ) ) // Parallel Gradle build - { - String polygeneHome = new File( cwd + "./../../../../src/dist" ).getAbsolutePath(); - System.setProperty( "polygene.home", polygeneHome ); - } - } -}
