http://git-wip-us.apache.org/repos/asf/zest-java/blob/0accd2cf/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/FileConfigurationModuleWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/FileConfigurationModuleWriter.java b/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/FileConfigurationModuleWriter.java deleted file mode 100644 index fa6e669..0000000 --- a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/FileConfigurationModuleWriter.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.zest.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 FileConfigurationModuleWriter -{ - - 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.zest.api.common.Visibility;\n" + - "import org.apache.zest.bootstrap.AssemblyException;\n" + - "import org.apache.zest.bootstrap.LayerAssembly;\n" + - "import org.apache.zest.bootstrap.ModuleAssembly;\n" + - "import org.apache.zest.bootstrap.layered.ModuleAssembler;\n" + - "import org.apache.zest.library.fileconfig.FileConfigurationAssembler;\n" + - "\n" + - "public class FileConfigurationModule\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" + - " new FileConfigurationAssembler().visibleIn( Visibility.layer ).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 = "FileConfigurationModule"; - File projectDir = new File( properties.get( "project.dir" ) ); - return new PrintWriter( new FileWriter( new File( projectDir, "bootstrap/src/main/java/" + packagename + classname + ".java" ) ) ); - } -}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/0accd2cf/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/HardCodedSecurityRepositoryMixinWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/HardCodedSecurityRepositoryMixinWriter.java b/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/HardCodedSecurityRepositoryMixinWriter.java deleted file mode 100644 index a29bca4..0000000 --- a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/HardCodedSecurityRepositoryMixinWriter.java +++ /dev/null @@ -1,87 +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.zest.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 HardCodedSecurityRepositoryMixinWriter -{ - - 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.Collections;\n" + - "import java.util.List;\n" + - "import org.apache.zest.api.unitofwork.concern.UnitOfWorkPropagation;\n" + - "\n" + - "public class HardcodedSecurityRepositoryMixin\n" + - " implements SecurityRepository\n" + - "{\n" + - "\n" + - " @Override\n" + - " public boolean verifyPassword( String userName, String password )\n" + - " {\n" + - " if( userName.equals(\"admin\") && password.equals(\"secret\") )" + - " {\n" + - " return true;\n" + - " }\n" + - " if( userName.equals(\"user\") && password.equals(\"123\") )" + - " {\n" + - " return true;\n" + - " }\n" + - " return false;\n" + - " }\n" + - "\n" + - " @UnitOfWorkPropagation\n" + - " public List<String> findRoleNamesOfUser( String name )\n" + - " {\n" + - " if( \"admin\".equals( name ) )\n" + - " {\n" + - " return Collections.singletonList(\"admin\");\n" + - " }\n" + - " return Collections.singletonList(\"user\");\n" + - " }\n" + - "}\n" - ); - } - } - - private PrintWriter createPrinter( Map<String, String> properties ) - throws IOException - { - String packagename = properties.get( "root.package" ).replaceAll( "\\.", "/" ) + "/model/security/"; - String classname = "HardcodedSecurityRepositoryMixin"; - File projectDir = new File( properties.get( "project.dir" ) ); - return new PrintWriter( new FileWriter( new File( projectDir, "model/src/main/java/" + packagename + classname + ".java" ) ) ); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/0accd2cf/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/IndexingModuleWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/IndexingModuleWriter.java b/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/IndexingModuleWriter.java deleted file mode 100644 index bcdc04d..0000000 --- a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/IndexingModuleWriter.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.zest.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 IndexingModuleWriter -{ - - 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.zest.api.common.Visibility;\n" + - "import org.apache.zest.bootstrap.AssemblyException;\n" + - "import org.apache.zest.bootstrap.LayerAssembly;\n" + - "import org.apache.zest.bootstrap.ModuleAssembly;\n" + - "import org.apache.zest.bootstrap.layered.ModuleAssembler;\n" + - "import org.apache.zest.index.rdf.assembly.RdfNativeSesameStoreAssembler;\n" + - "import org.apache.zest.library.rdf.repository.NativeConfiguration;\n" + - "\n" + - "public class IndexingModule\n" + - " implements ModuleAssembler\n" + - "{\n" + - " public static final String NAME = \"Indexing Module\";\n" + - " private final ModuleAssembly configModule;\n" + - "\n" + - " public IndexingModule( ModuleAssembly configModule )\n" + - " {\n" + - " this.configModule = configModule;\n" + - " }\n" + - "\n" + - " @Override\n" + - " public ModuleAssembly assemble( LayerAssembly layer, ModuleAssembly module )\n" + - " throws AssemblyException\n" + - " {\n" + - " module.withDefaultUnitOfWorkFactory();\n" + - "\n" + - " configModule.entities( NativeConfiguration.class ).visibleIn( Visibility.application );\n" + - " new RdfNativeSesameStoreAssembler(Visibility.application, Visibility.module).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 = "IndexingModule"; - File projectDir = new File( properties.get( "project.dir" ) ); - return new PrintWriter( new FileWriter( new File( projectDir, "bootstrap/src/main/java/" + packagename + classname + ".java" ) ) ); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/0accd2cf/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/InfrastructureLayerWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/InfrastructureLayerWriter.java b/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/InfrastructureLayerWriter.java deleted file mode 100644 index c899999..0000000 --- a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/InfrastructureLayerWriter.java +++ /dev/null @@ -1,91 +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.zest.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 InfrastructureLayerWriter -{ - - 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 java.util.function.Function;\n" + - "import org.apache.zest.api.structure.Application;\n" + - "import org.apache.zest.api.structure.Module;\n" + - "import org.apache.zest.bootstrap.AssemblyException;\n" + - "import org.apache.zest.bootstrap.LayerAssembly;\n" + - "import org.apache.zest.bootstrap.ModuleAssembly;\n" + - "import org.apache.zest.bootstrap.layered.LayerAssembler;\n" + - "import org.apache.zest.bootstrap.layered.LayeredLayerAssembler;\n" + - "\n" + - "public class InfrastructureLayer extends LayeredLayerAssembler\n" + - " implements LayerAssembler\n" + - "{\n" + - " public static final String NAME = \"Infrastructure Layer\";\n" + - " private final ModuleAssembly configModule;\n" + - " private final Function<Application, Module> typeFinder;\n" + - "\n" + - " public InfrastructureLayer( ModuleAssembly configModule, Function<Application, Module> typeFinder )\n" + - " {\n" + - " this.configModule = configModule;\n" + - " this.typeFinder = typeFinder;\n" + - " }\n" + - "\n" + - " @Override\n" + - " public LayerAssembly assemble( LayerAssembly layer )\n" + - " throws AssemblyException\n" + - " {\n" + - " createModule( layer, FileConfigurationModule.class );\n" + - "\n" + - " new StorageModule( configModule ).assemble( layer, layer.module( StorageModule.NAME ) );\n" + - " new IndexingModule( configModule ).assemble( layer, layer.module( IndexingModule.NAME ) );\n" + - " new SerializationModule( typeFinder ).assemble( layer, layer.module( SerializationModule.NAME ) );\n" + - "\n" + - " return layer;\n" + - " }\n" + - "}\n" - ); - } - } - - private PrintWriter createPrinter( Map<String, String> properties ) - throws IOException - { - String packagename = properties.get( "root.package" ).replaceAll( "\\.", "/" ) + "/bootstrap/infrastructure/"; - String classname = "InfrastructureLayer"; - File projectDir = new File( properties.get( "project.dir" ) ); - return new PrintWriter( new FileWriter( new File( projectDir, "bootstrap/src/main/java/" + packagename + classname + ".java" ) ) ); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/0accd2cf/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/OrderItemWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/OrderItemWriter.java b/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/OrderItemWriter.java deleted file mode 100644 index 25db54f..0000000 --- a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/OrderItemWriter.java +++ /dev/null @@ -1,66 +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.zest.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 OrderItemWriter -{ - - 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( ".model.orders;" ); - pw.println(); - pw.println("import java.math.BigDecimal;"); - pw.println("import org.apache.zest.api.entity.Identity;"); - pw.println("import org.apache.zest.api.property.Property;"); - pw.println(); - pw.println( - "public interface OrderItem extends Identity\n" + - "{\n" + - " Property<String> partNumber();\n\n" + - " Property<BigDecimal> unitPrice();\n\n" + - " Property<Integer> units();\n\n" + - " Property<BigDecimal> discount();\n\n" + - "}\n"); - } - } - - private PrintWriter createPrinter( Map<String, String> properties ) - throws IOException - { - String packagename = properties.get( "root.package" ).replaceAll( "\\.", "/" ) + "/model/orders/"; - String classname = "OrderItem"; - File projectDir = new File( properties.get( "project.dir" ) ); - return new PrintWriter( new FileWriter( new File( projectDir, "model/src/main/java/" + packagename + classname + ".java" ) ) ); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/0accd2cf/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/OrderModuleWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/OrderModuleWriter.java b/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/OrderModuleWriter.java deleted file mode 100644 index df8a7da..0000000 --- a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/OrderModuleWriter.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.zest.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; - -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.zest.api.common.Visibility;\n" + - "import org.apache.zest.bootstrap.AssemblyException;\n" + - "import org.apache.zest.bootstrap.LayerAssembly;\n" + - "import org.apache.zest.bootstrap.ModuleAssembly;\n" + - "import org.apache.zest.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(); - 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( Customer.class, Order.class, OrderItem.class );\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"; - File projectDir = new File( properties.get( "project.dir" ) ); - return new PrintWriter( new FileWriter( new File( projectDir, "bootstrap/src/main/java/" + packagename + classname + ".java" ) ) ); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/0accd2cf/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/OrderWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/OrderWriter.java b/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/OrderWriter.java deleted file mode 100644 index 63d7003..0000000 --- a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/OrderWriter.java +++ /dev/null @@ -1,71 +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.zest.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 OrderWriter -{ - - 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( ".model.orders;" ); - pw.println(); - pw.println("import java.time.ZonedDateTime;"); - pw.println("import org.apache.zest.api.association.Association;"); - pw.println("import org.apache.zest.api.association.ManyAssociation;"); - pw.println("import org.apache.zest.api.common.Optional;"); - pw.println("import org.apache.zest.api.entity.Identity;"); - pw.println("import org.apache.zest.api.property.Property;"); - pw.println(); - pw.println( - "public interface Order extends Identity\n" + - "{\n" + - " Property<String> orderNumber();\n\n" + - " Property<ZonedDateTime> registered();\n\n" + - " @Optional\n" + - " Property<ZonedDateTime> shipped();\n\n" + - " Association<Customer> customer();\n\n" + - " ManyAssociation<OrderItem> items();\n\n" + - "}\n"); - } - } - - private PrintWriter createPrinter( Map<String, String> properties ) - throws IOException - { - String packagename = properties.get( "root.package" ).replaceAll( "\\.", "/" ) + "/model/orders/"; - String classname = "Order"; - File projectDir = new File( properties.get( "project.dir" ) ); - return new PrintWriter( new FileWriter( new File( projectDir, "model/src/main/java/" + packagename + classname + ".java" ) ) ); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/0accd2cf/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/SecurityModuleWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/SecurityModuleWriter.java b/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/SecurityModuleWriter.java deleted file mode 100644 index bdbd512..0000000 --- a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/SecurityModuleWriter.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.zest.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; - -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.zest.api.common.Visibility;\n" + - "import org.apache.zest.bootstrap.AssemblyException;\n" + - "import org.apache.zest.bootstrap.LayerAssembly;\n" + - "import org.apache.zest.bootstrap.ModuleAssembly;\n" + - "import org.apache.zest.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.withDefaultUnitOfWorkFactory();\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"; - File projectDir = new File( properties.get( "project.dir" ) ); - return new PrintWriter( new FileWriter( new File( projectDir, "bootstrap/src/main/java/" + packagename + classname + ".java" ) ) ); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/0accd2cf/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/SecurityRepositoryWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/SecurityRepositoryWriter.java b/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/SecurityRepositoryWriter.java deleted file mode 100644 index abe5083..0000000 --- a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/SecurityRepositoryWriter.java +++ /dev/null @@ -1,71 +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.zest.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; - -import static java.lang.String.format; - -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.zest.api.concern.Concerns;\n" + - "import org.apache.zest.api.unitofwork.concern.UnitOfWorkConcern;\n" + - "import org.apache.zest.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"; - File projectDir = new File( properties.get( "project.dir" ) ); - return new PrintWriter( new FileWriter( new File( projectDir, "model/src/main/java/" + packagename + classname + ".java" ) ) ); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/0accd2cf/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/SerializationModuleWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/SerializationModuleWriter.java b/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/SerializationModuleWriter.java deleted file mode 100644 index b2e8aa2..0000000 --- a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/SerializationModuleWriter.java +++ /dev/null @@ -1,90 +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.zest.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 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 java.util.function.Function;\n" + - "import org.apache.zest.api.common.Visibility;\n" + - "import org.apache.zest.api.structure.Application;\n" + - "import org.apache.zest.api.structure.Module;\n" + - "import org.apache.zest.bootstrap.AssemblyException;\n" + - "import org.apache.zest.bootstrap.LayerAssembly;\n" + - "import org.apache.zest.bootstrap.ModuleAssembly;\n" + - "import org.apache.zest.bootstrap.layered.ModuleAssembler;\n" + - "import org.apache.zest.spi.uuid.UuidIdentityGeneratorService;\n" + - "import org.apache.zest.valueserialization.jackson.JacksonValueSerializationAssembler;\n" + - "\n" + - "public class SerializationModule\n" + - " implements ModuleAssembler\n" + - "{\n" + - " public static final String NAME = \"Serialization Module\";\n" + - " private final Function<Application, Module> typeFinder;\n" + - "\n" + - " public SerializationModule( Function<Application, Module> typeFinder )\n" + - " {\n" + - " this.typeFinder = typeFinder;\n" + - " }\n" + - "\n" + - " @Override\n" + - " public ModuleAssembly assemble( LayerAssembly layer, ModuleAssembly module )\n" + - " throws AssemblyException\n" + - " {\n" + - " new JacksonValueSerializationAssembler()\n" + - " .visibleIn( Visibility.application )\n" + - " .withValuesModuleFinder( typeFinder )\n" + - " .assemble( module );\n" + - " module.services( UuidIdentityGeneratorService.class ).visibleIn( Visibility.layer );\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"; - File projectDir = new File( properties.get( "project.dir" ) ); - return new PrintWriter( new FileWriter( new File( projectDir, "bootstrap/src/main/java/" + packagename + classname + ".java" ) ) ); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/0accd2cf/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/SettingsWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/SettingsWriter.java b/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/SettingsWriter.java deleted file mode 100644 index abf621b..0000000 --- a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/SettingsWriter.java +++ /dev/null @@ -1,75 +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.zest.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 rootPackage = properties.get( "root.package" ); - 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" ) ); - return new PrintWriter( new FileWriter( new File( projectDir, "settings.gradle" ) ) ); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/0accd2cf/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/StorageModuleWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/StorageModuleWriter.java b/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/StorageModuleWriter.java deleted file mode 100644 index 579b3da..0000000 --- a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/restapp/StorageModuleWriter.java +++ /dev/null @@ -1,87 +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.zest.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 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.zest.api.common.Visibility;\n" + - "import org.apache.zest.bootstrap.AssemblyException;\n" + - "import org.apache.zest.bootstrap.LayerAssembly;\n" + - "import org.apache.zest.bootstrap.ModuleAssembly;\n" + - "import org.apache.zest.bootstrap.layered.ModuleAssembler;\n" + - "import org.apache.zest.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"; - File projectDir = new File( properties.get( "project.dir" ) ); - return new PrintWriter( new FileWriter( new File( projectDir, "bootstrap/src/main/java/" + packagename + classname + ".java" ) ) ); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/0accd2cf/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/singleton/SingletonApplicationAssemblerWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/singleton/SingletonApplicationAssemblerWriter.java b/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/singleton/SingletonApplicationAssemblerWriter.java new file mode 100644 index 0000000..8a125a7 --- /dev/null +++ b/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/singleton/SingletonApplicationAssemblerWriter.java @@ -0,0 +1,105 @@ +/* + * 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.zest.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; + +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.zest.api.structure.Application;" ); + pw.println( "import org.apache.zest.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 Zest\" ) );\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"); + File projectDir = new File( properties.get( "project.dir" ) ); + return new PrintWriter( new FileWriter( new File( projectDir, "src/main/java/" + packagename + classname + ".java" ) ) ); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/0accd2cf/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/singleton/StartupServiceWriter.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/singleton/StartupServiceWriter.java b/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/singleton/StartupServiceWriter.java new file mode 100644 index 0000000..669821c --- /dev/null +++ b/tools/shell/src/main/java/org/apache/zest/tools/shell/create/project/singleton/StartupServiceWriter.java @@ -0,0 +1,70 @@ +/* + * 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.zest.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 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.zest.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( "\\.", "/" ); + String classname = "StartupService"; + File projectDir = new File( properties.get( "project.dir" ) ); + return new PrintWriter( new FileWriter( new File( projectDir, "src/main/java/" + packagename + classname + ".java" ) ) ); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/0accd2cf/tools/shell/src/main/java/org/apache/zest/tools/shell/help/HelpCommand.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/java/org/apache/zest/tools/shell/help/HelpCommand.java b/tools/shell/src/main/java/org/apache/zest/tools/shell/help/HelpCommand.java index 3f52f3b..814a755 100644 --- a/tools/shell/src/main/java/org/apache/zest/tools/shell/help/HelpCommand.java +++ b/tools/shell/src/main/java/org/apache/zest/tools/shell/help/HelpCommand.java @@ -42,7 +42,7 @@ public class HelpCommand extends AbstractCommand { for( Command command : commands ) { - output.println( command.name() + "\t" + command.description() ); + output.println( command.name() + " " + command.description() ); } } http://git-wip-us.apache.org/repos/asf/zest-java/blob/0accd2cf/tools/shell/src/main/resources/templates/default/project.properties ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/resources/templates/default/project.properties b/tools/shell/src/main/resources/templates/default/project.properties index 54f42b7..e66c148 100644 --- a/tools/shell/src/main/resources/templates/default/project.properties +++ b/tools/shell/src/main/resources/templates/default/project.properties @@ -18,3 +18,7 @@ # # + +creator.class=org.apache.zest.tools.shell.create.project.DefaultProjectCreator + +template.dir=etc/templates/default/files \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/0accd2cf/tools/shell/src/main/resources/templates/null/project.properties ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/resources/templates/null/project.properties b/tools/shell/src/main/resources/templates/null/project.properties new file mode 100644 index 0000000..d26b377 --- /dev/null +++ b/tools/shell/src/main/resources/templates/null/project.properties @@ -0,0 +1,25 @@ +# +# 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. + + +# This project template is the absolute minimal project possible. +# Only creates a build file and directory structure for java sources. + + +creator.class=org.apache.zest.tools.shell.create.project.NullProjectCreator + +template.dir=etc/templates/null/files \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/0accd2cf/tools/shell/src/main/resources/templates/restapp/project.properties ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/resources/templates/restapp/project.properties b/tools/shell/src/main/resources/templates/restapp/project.properties index 4c33430..dc97019 100644 --- a/tools/shell/src/main/resources/templates/restapp/project.properties +++ b/tools/shell/src/main/resources/templates/restapp/project.properties @@ -18,6 +18,6 @@ # # -creator.class=org.apache.zest.tools.shell.create.project.RestProjectCreator +creator.class=org.apache.zest.tools.shell.create.project.RestAppProjectCreator -template.dir=etc/templates/restproject/files \ No newline at end of file +template.dir=etc/templates/restapp/files \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/0accd2cf/tools/shell/src/main/resources/templates/singleton/project.properties ---------------------------------------------------------------------- diff --git a/tools/shell/src/main/resources/templates/singleton/project.properties b/tools/shell/src/main/resources/templates/singleton/project.properties new file mode 100644 index 0000000..d504d1d --- /dev/null +++ b/tools/shell/src/main/resources/templates/singleton/project.properties @@ -0,0 +1,24 @@ +# +# 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. + +# This template create a simple project with a single layer and a single module. +# It is based around the SingletonAssembler. + + +creator.class=org.apache.zest.tools.shell.create.project.SingletonProjectCreator + +template.dir=etc/templates/singleton/files \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/0accd2cf/tools/shell/src/test/java/org/apache/zest/tools/shell/FileUtilsTest.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/test/java/org/apache/zest/tools/shell/FileUtilsTest.java b/tools/shell/src/test/java/org/apache/zest/tools/shell/FileUtilsTest.java new file mode 100644 index 0000000..2867041 --- /dev/null +++ b/tools/shell/src/test/java/org/apache/zest/tools/shell/FileUtilsTest.java @@ -0,0 +1,106 @@ +/* + * 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.zest.tools.shell; + +import java.io.File; +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() + { + File f = new File( "habba-zout" ); + if( f.exists() ) + { + FileUtils.removeDir( f ); + } + assertThat( f.exists(), equalTo( false ) ); + FileUtils.createDir( "habba-zout" ); + assertThat( f.exists(), equalTo( true ) ); + if( ! f.delete() ){ + System.err.println( "Unable to remove file. Why???" ); + } + assertThat( f.exists(), equalTo( false ) ); + } + + @Test + public void removeDirTest() throws Exception { + File srcFile = new File("build.gradle"); + File f = new File( "habba-zout" ); + if( f.exists() ) + { + FileUtils.removeDir( f ); + } + 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__") ); + boolean success = FileUtils.removeDir( f ); + assertThat(success, equalTo(true)); + 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() + { + + Map<String, String> map = FileUtils.readPropertiesResource( "templates/restapp/project.properties" ); + assertThat( map, notNullValue() ); + assertThat( map.get( "template.dir" ), equalTo( "etc/templates/restapp/files" ) ); + } + + @Test + public void copyFileTest() + throws Exception + { + File dest = new File( "build.gradle.copy" ); + if( dest.exists() ) // from an earlier aborted run. + { + if( ! dest.delete() ){ + System.err.println( "Unable to remove file. Why???" ); + } + } + File srcFile = new File( "build.gradle" ); + FileUtils.copyFile( srcFile, dest ); + assertThat( dest.exists(), equalTo( true ) ); + if( ! dest.delete() ){ + System.err.println( "Unable to remove file. Why???" ); + } + assertThat( dest.exists(), equalTo( false ) ); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/0accd2cf/tools/shell/src/test/java/org/apache/zest/tools/shell/HelpNeededExceptionTest.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/test/java/org/apache/zest/tools/shell/HelpNeededExceptionTest.java b/tools/shell/src/test/java/org/apache/zest/tools/shell/HelpNeededExceptionTest.java new file mode 100644 index 0000000..bcd871e --- /dev/null +++ b/tools/shell/src/test/java/org/apache/zest/tools/shell/HelpNeededExceptionTest.java @@ -0,0 +1,32 @@ +/* + * 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.zest.tools.shell; + +import org.apache.zest.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/zest-java/blob/0accd2cf/tools/shell/src/test/java/org/apache/zest/tools/shell/TestHelper.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/test/java/org/apache/zest/tools/shell/TestHelper.java b/tools/shell/src/test/java/org/apache/zest/tools/shell/TestHelper.java new file mode 100644 index 0000000..e0389a9 --- /dev/null +++ b/tools/shell/src/test/java/org/apache/zest/tools/shell/TestHelper.java @@ -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 org.apache.zest.tools.shell; + +import java.io.File; + +public class TestHelper +{ + public static void zetZestZome() + { + String cwd = new File( ".").getAbsolutePath(); + if( cwd.endsWith( "/java/." )) // IDEA default runner + { + String zestHome = new File( new File(".").getAbsoluteFile(), "tools/shell/src" ).getAbsolutePath(); + System.setProperty( "zest.home", zestHome ); + } + if( cwd.endsWith( "tools/shell/." )) // Gradle build + { + String zestHome = new File( new File(".").getAbsoluteFile(), "src" ).getAbsolutePath(); + System.setProperty( "zest.home", zestHome ); + } + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/0accd2cf/tools/shell/src/test/java/org/apache/zest/tools/shell/create/CreateProjectTest.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/test/java/org/apache/zest/tools/shell/create/CreateProjectTest.java b/tools/shell/src/test/java/org/apache/zest/tools/shell/create/CreateProjectTest.java new file mode 100644 index 0000000..58b2a83 --- /dev/null +++ b/tools/shell/src/test/java/org/apache/zest/tools/shell/create/CreateProjectTest.java @@ -0,0 +1,69 @@ +/* + * 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.zest.tools.shell.create; + +import java.io.File; +import org.apache.zest.tools.shell.FileUtils; +import org.apache.zest.tools.shell.HelpNeededException; +import org.apache.zest.tools.shell.TestHelper; +import org.junit.Test; + +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +public class CreateProjectTest +{ + private CreateProject underTest = new CreateProject(); + + @Test + public void givenCommandWhenRequestNameExpectName() + { + assertThat( underTest.name(), equalTo( "create-project" ) ); + } + + @Test + public void givenCommandWhenRequestDescriptionExpectDescription() + { + assertThat( underTest.description(), equalTo( "type name package\tCreates a new skeletal project in directory [name]." ) ); + } + + @Test( expected = HelpNeededException.class ) + public void givenCommandWhenTemplateDoesNotExistExpectException() + { + new CreateProject().execute( new String[]{ "habba", "ZestTest", "org.apache.zest" }, null, null ); + } + + @Test + public void givenCommandWhenTemplateExistExpectCreatedProject() + { + TestHelper.zetZestZome(); + File dest = new File( "ZestTest" ); + new CreateProject().execute( new String[]{ "create-project", "null", "ZestTest", "org.apache.zest" }, null, null ); + + assertThat( dest.exists(), equalTo( true ) ); + assertThat( new File(dest, "src/main/java/org/apache/zest/package.html").exists(), equalTo( true ) ); + if( FileUtils.removeDir( dest ) ) + { + System.err.println( "Unable to remove file. Why???" ); + } + assertThat( dest.exists(), equalTo( false ) ); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/0accd2cf/tools/shell/src/test/java/org/apache/zest/tools/shell/create/project/DefaultProjectCreatorTest.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/test/java/org/apache/zest/tools/shell/create/project/DefaultProjectCreatorTest.java b/tools/shell/src/test/java/org/apache/zest/tools/shell/create/project/DefaultProjectCreatorTest.java new file mode 100644 index 0000000..387fc5f --- /dev/null +++ b/tools/shell/src/test/java/org/apache/zest/tools/shell/create/project/DefaultProjectCreatorTest.java @@ -0,0 +1,108 @@ +/* + * 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.zest.tools.shell.create.project; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; +import org.apache.zest.tools.shell.FileUtils; +import org.apache.zest.tools.shell.TestHelper; +import org.junit.Test; + +import static org.apache.zest.tools.shell.FileUtils.removeDir; +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +public class DefaultProjectCreatorTest +{ + private DefaultProjectCreator underTest = new DefaultProjectCreator(); + + @Test + public void givenCorrectInputWhenCreatedProjectExpectCompleteProjectCreated() + throws Exception + { + + TestHelper.zetZestZome(); + File projectDir = new File( "ZestTest" ); + if( projectDir.exists() ) + { + removeDir( projectDir ); + } + Map<String, String> properties = new HashMap<>(); + properties.put( "zest.home", System.getProperty( "zest.home" ) ); + properties.put( "root.package", "org.apache.zest.test" ); + properties.put( "project.dir", "ZestTest" ); + properties.put( "project.name", "ZestTest" ); + properties.put( "template.dir", "etc/templates/restapp/files" ); + underTest.create( "ZestTest", projectDir, properties ); + + assertThat( projectDir.exists(), equalTo( true ) ); + assertThat( new File( projectDir, "app/build.gradle" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "app/src" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "app/src/main/resources" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "app/src/main/java/org/apache/zest/test/app/package.html" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "app/src/main/java/org/apache/zest/test/app/ZestTest.java" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "app/src/test/java/org/apache/zest/test/package.html" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "bootstrap/src/main/resources" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "bootstrap/src/main/java/org/apache/zest/test/bootstrap/config/package.html" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "bootstrap/src/main/java/org/apache/zest/test/bootstrap/config/ConfigModule.java" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "bootstrap/src/main/java/org/apache/zest/test/bootstrap/config/ConfigurationLayer.java" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "bootstrap/src/main/java/org/apache/zest/test/bootstrap/connectivity/ConnectivityLayer.java" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "bootstrap/src/main/java/org/apache/zest/test/bootstrap/connectivity/package.html" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "bootstrap/src/main/java/org/apache/zest/test/bootstrap/domain/package.html" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "bootstrap/src/main/java/org/apache/zest/test/bootstrap/domain/CrudModule.java" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "bootstrap/src/main/java/org/apache/zest/test/bootstrap/domain/DomainLayer.java" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "bootstrap/src/main/java/org/apache/zest/test/bootstrap/domain/OrderModule.java" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "bootstrap/src/main/java/org/apache/zest/test/bootstrap/domain/SecurityModule.java" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "bootstrap/src/main/java/org/apache/zest/test/bootstrap/infrastructure/package.html" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "bootstrap/src/main/java/org/apache/zest/test/bootstrap/infrastructure/FileConfigurationModule.java" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "bootstrap/src/main/java/org/apache/zest/test/bootstrap/infrastructure/IndexingModule.java" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "bootstrap/src/main/java/org/apache/zest/test/bootstrap/infrastructure/InfrastructureLayer.java" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "bootstrap/src/main/java/org/apache/zest/test/bootstrap/infrastructure/SerializationModule.java" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "bootstrap/src/main/java/org/apache/zest/test/bootstrap/infrastructure/StorageModule.java" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "bootstrap/src/main/java/org/apache/zest/test/bootstrap/ZestTestApplicationAssembler.java" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "app/src/test/java/org/apache/zest/test/package.html" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "bootstrap/build.gradle" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "bootstrap/src/main/resources" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "bootstrap/src/test/java/org/apache/zest/test/package.html" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "model/build.gradle" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "model/src/main/resources" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "model/src/main/java/org/apache/zest/test/model/orders/Customer.java" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "model/src/main/java/org/apache/zest/test/model/orders/Order.java" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "model/src/main/java/org/apache/zest/test/model/orders/OrderItem.java" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "model/src/main/java/org/apache/zest/test/model/orders/package.html" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "model/src/main/java/org/apache/zest/test/model/security/HardcodedSecurityRepositoryMixin.java" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "model/src/main/java/org/apache/zest/test/model/security/SecurityRepository.java" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "model/src/main/java/org/apache/zest/test/model/security/package.html" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "model/src/test/java/org/apache/zest/test/package.html" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "gradle/wrapper/gradle-wrapper.jar" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "gradle/wrapper/gradle-wrapper.properties" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "gradlew" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "gradlew.bat" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "build.gradle" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "settings.gradle" ).exists(), equalTo( true ) ); + if( FileUtils.removeDir( projectDir ) ) + { + System.err.println( "Unable to remove file. Why???" ); + } + assertThat( projectDir.exists(), equalTo( false ) ); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/0accd2cf/tools/shell/src/test/java/org/apache/zest/tools/shell/create/project/NullProjectCreatorTest.java ---------------------------------------------------------------------- diff --git a/tools/shell/src/test/java/org/apache/zest/tools/shell/create/project/NullProjectCreatorTest.java b/tools/shell/src/test/java/org/apache/zest/tools/shell/create/project/NullProjectCreatorTest.java new file mode 100644 index 0000000..45f66fb --- /dev/null +++ b/tools/shell/src/test/java/org/apache/zest/tools/shell/create/project/NullProjectCreatorTest.java @@ -0,0 +1,66 @@ +/* + * 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.zest.tools.shell.create.project; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; +import org.apache.zest.tools.shell.FileUtils; +import org.apache.zest.tools.shell.TestHelper; +import org.junit.Test; + +import static org.apache.zest.tools.shell.FileUtils.removeDir; +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +public class NullProjectCreatorTest +{ + private NullProjectCreator underTest = new NullProjectCreator(); + + @Test + public void givenCorrectInputWhenCreatedProjectExpectCompleteProjectCreated() + throws Exception + { + + TestHelper.zetZestZome(); + File projectDir = new File( "ZestTest" ); + if( projectDir.exists() ) + { + removeDir( projectDir ); + } + Map<String, String> properties = new HashMap<>(); + properties.put( "zest.home", System.getProperty( "zest.home" ) ); + properties.put( "root.package", "org.apache.zest.test" ); + properties.put( "template.dir", "etc/templates/null/files" ); + underTest.create( "ZestTest", projectDir, properties ); + + assertThat( projectDir.exists(), equalTo( true ) ); + assertThat( new File( projectDir, "src/main/java/org/apache/zest/test/package.html" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "gradlew" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "gradlew.bat" ).exists(), equalTo( true ) ); + assertThat( new File( projectDir, "build.gradle" ).exists(), equalTo( true ) ); + if( FileUtils.removeDir( projectDir ) ) + { + System.err.println( "Unable to remove file. Why???" ); + } + assertThat( projectDir.exists(), equalTo( false ) ); + } +}
