Permalink
Browse files

CMake Unit Generation

-- Implemented CMake unit generation for CPP model.
  • Loading branch information...
1 parent 7dafbb2 commit d9c991ab1e07b895012813b6ab9baab4e53ddabb @ahmedvc ahmedvc committed Nov 2, 2016
@@ -0,0 +1,71 @@
+namespace cruise.umple.cpp.gen;
+
+class GenerationTemplate {
+ depend cruise.umple.core.GenerationPolicyRegistry;
+ depend java.util.stream.Collectors;
+
+ immutable GenerationPolicyRegistry g;
+
+ String join(String id, Object... element){
+ return this.getG().getValues(id, element).stream().map(Object::toString).collect(Collectors.joining("\n"));
+ }
+
+ String string(String id, Object element){
+ return this.getG().getString(element, id);
+ }
+}
+
+class Header {
+ isA GenerationTemplate;
+ depend cruise.umple.core.GenerationPolicyRegistry;
+ depend cruise.umple.modeling.handlers.IModelingElementDefinitions;
+ depend cruise.umple.modeling.handlers.cpp.ICppDefinitions;
+ depend cruise.umple.core.Generator;
+ depend cruise.umple.cpp.core.IGenerationCommonConstants;
+ depend java.util.stream.Collectors;
+ depend cruise.umple.cpp.core.ContentsDescriptor;
+
+//////////////////////////////////////////////////////////////////////////
+cMakeFoldersT <<!include_directories(<<=directory>>)
+!>>
+////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+cMakeT <<!cmake_minimum_required(VERSION 3.6)
+project(<<=projectName>>)
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+include_directories(${CMAKE_SOURCE_DIR})
+<<=this.getG().generator.generate(Generator.HEADER_CMAKE_FOLDER, element)>>
+set(SOURCE_FILES
+ <<=includes>>)
+
+add_executable(<<=projectName>> ${SOURCE_FILES})!>>
+////////////////////////////////////////////////////////////////////////
+
+ emit cMake(Object element, String projectName, String includes)(cMakeT);
+ String cMake(Object element){
+ String directory= this.string(IModelingElementDefinitions.NAME, element);
+
+ String collect = this.getG().getValues(IGenerationCommonConstants.CONTENTS_DESCRIPTORS).stream().map(t -> {
+ ContentsDescriptor descriptor= (ContentsDescriptor) t;
+ String path = descriptor.getPath();
+ if(path.isEmpty()){
+ return descriptor.getFileName();
+ }
+ return path+ "/"+ descriptor.getFileName();
+ }).collect(Collectors.joining("\n"));
+
+ return cMake(element, directory, collect);
+ }
+
+ emit cMakeFolders(String directory)(cMakeFoldersT);
+ String cMakeFolders(){
+ StringBuilder sb= new StringBuilder();
+ this.getG().getValues(ICppDefinitions.MAKE_FOLDERS).stream().forEach(directory -> {
+ _cMakeFolders(0, sb, directory.toString());
+ });
+
+ return sb.toString();
+ }
+}
@@ -0,0 +1,15 @@
+/*
+
+Copyright: All contributers to the Umple Project
+
+This file is made available subject to the open source license found at:
+http://umple.org/license
+
+This is the Umple php template master files that calls all major php template files.
+By compiling this file, Umple will regenerate all Php generator files
+
+*/
+
+generate Java "../src-gen-UmpleTL";
+
+use CMake.ump;
@@ -234,7 +234,11 @@ private static String getActivityCode(State element, GenerationPolicyRegistry ge
@GenerationValueAnnotation(fieldName= ICppStatemachinesDefinitions.STATE_DO_ACTIVITY_ON_COMPLETION_EVENT)
public static String getStateDoActivityOnCompletionEvent(@GenerationBaseElement State element){
- Activity activity = element.getActivity(0);
+ List<Activity> activities = element.getActivities();
+ if(activities.isEmpty()){
+ return CommonConstants.BLANK;
+ }
+ Activity activity = activities.get(0);
if(activity== null){
return CommonConstants.BLANK;
}
@@ -22,6 +22,7 @@
import java.util.List;
import cruise.umple.core.GenerationPolicyRegistry;
+import cruise.umple.core.Generator;
import cruise.umple.core.IPoliciesProcessor;
import cruise.umple.cpp.core.ContentsDescriptor;
import cruise.umple.cpp.core.IGenerationCommonConstants;
@@ -49,25 +50,28 @@
import cruise.umple.modeling.handlers.cpp.CPPDependsPointsHandler;
import cruise.umple.modeling.handlers.cpp.CppCustomGetterFunctionsPointsHandler;
import cruise.umple.modeling.handlers.cpp.CppStatemachinePointsHandler;
-import cruise.umple.modeling.handlers.cpp.CppTestsPointsHandler;
import cruise.umple.modeling.handlers.cpp.ICppModelingPriorityHandler;
import cruise.umple.modeling.handlers.cpp.StlGenerationPointsHandler;
import cruise.umple.modeling.handlers.cpp.StructurePointsHandler;
abstract public class CppPoliciesProcessor implements IPoliciesProcessor{
+
private GenerationPolicyRegistry generationPolicyRegistry = new GenerationPolicyRegistry();
+ private Generator generator;
public void generateRootElement(Object rootElement) {
this.getGenerationPolicyRegistry().process(rootElement);
this.handleGeneratedContents(getContentDescriptors());
-
//this.generationPolicyRegistry.getGenerationLogger().showLogDetails();
}
abstract public void handleGeneratedContents(List<ContentsDescriptor> contentsDescriptor);
public CppPoliciesProcessor() {
+ generator= new Generator(generationPolicyRegistry);
+ generationPolicyRegistry.generator= generator;
+
registerGenerationLanguages();
registerTypesPolicies();
registerGenerationPoints();
@@ -115,7 +119,7 @@ public void registerGenerationPoints(){
this.getGenerationPolicyRegistry().register(new CppStatemachinePointsHandler());
this.getGenerationPolicyRegistry().register(new StructurePointsHandler());
- this.getGenerationPolicyRegistry().register(new CppTestsPointsHandler());
+ //this.getGenerationPolicyRegistry().register(new CppTestsPointsHandler());
}
public List<ContentsDescriptor> getContentDescriptors(){
@@ -129,6 +133,7 @@ public void registerGenerationPoints(){
}
return descriptors;
}
+
return descriptors;
}
@@ -41,6 +41,7 @@
<delete dir="${project.path}/src-gen-umple" failonerror="false" />
<delete dir="${project.path}/src-gen-umpleTL" failonerror="false" />
<delete dir="${project.path}/src-gen-umpletl" failonerror="false" />
+ <delete dir="UmpleToRTCpp/src-gen-UmpleTL" failonerror="false" />
<delete dir="cruise.umplificator/src-gen-umple" failonerror="false" />
<delete dir="cruise.umple.validator/src-gen-umple" failonerror="false" />
</target>
@@ -144,6 +145,9 @@
<arg value="UmpleToJava/UmpleTLTemplates/Master.ump"/>
</java>
<java jar="${umple.stable.jar}" fork="true" failonerror="true">
+ <arg value="UmpleToRTCpp/UmpleTLTemplates/Master.ump"/>
+ </java>
+ <java jar="${umple.stable.jar}" fork="true" failonerror="true">
<arg value="UmpleToPhp/UmpleTLTemplates/Master.ump"/>
</java>
<java jar="${umple.stable.jar}" fork="true" failonerror="true">
@@ -157,6 +161,8 @@
<copy todir="cruise.umple/src-gen-umpletl/cruise/umple/compiler/java" overwrite="true">
<fileset dir="UmpleToJava/src-gen-UmpleTL/cruise/umple/compiler/java" excludes=".git* UmpleToJava.java" />
</copy>
+ <fileset dir="UmpleToRTCpp/src-gen-UmpleTL" excludes=".git*" />
+ </copy>
<copy todir="cruise.umple/src-gen-umpletl/cruise/umple/compiler/php" overwrite="true">
<fileset dir="UmpleToPhp/src-gen-UmpleTL/cruise/umple/compiler/php" excludes=".git* UmpleToPhp.java" />
</copy>
@@ -37,8 +37,9 @@ public void showLogDetails(){
StringBuffer contents= new StringBuffer();
contents.append("Errors:"+ CommonConstants.NEW_LINE); //$NON-NLS-1$
for(LogDescriptor descriptor: this.errors){
- contents.append(CommonConstants.NEW_LINE+ descriptor.getMessage());
- contents.append(CommonConstants.NEW_LINE+ descriptor.getExceptionDetails());
+ descriptor.fException.printStackTrace();
+ //contents.append(CommonConstants.NEW_LINE+ descriptor.getMessage());
+ //contents.append(CommonConstants.NEW_LINE+ descriptor.getExceptionDetails());
}
contents.append("-----------------------------------------------------"+ CommonConstants.NEW_LINE); //$NON-NLS-1$
@@ -1239,6 +1239,7 @@ public void addUniqueValue(String id, Object values, Object... element){
}
private ArgumentsRetrieval argumentRetriever= new ArgumentsRetrieval();
+ public Generator generator;
public void addList(String id, Object values, boolean unique, Object... element){
if(values instanceof Collection<?> == false){
@@ -0,0 +1,29 @@
+package cruise.umple.core;
+
+import cruise.umple.cpp.gen.Header;
+
+public class Generator {
+
+ public static final String HEADER_CMAKE= "Header#cMake";
+ public static final String HEADER_CMAKE_FOLDER= "Header#cMakeFolder";
+
+ Header header;
+
+ public Generator(GenerationPolicyRegistry generationPolicyRegistry) {
+ header= new Header(generationPolicyRegistry);
+ }
+
+ public String generate(String id, Object element, Object... args){
+ switch (id) {
+ case Generator.HEADER_CMAKE:
+ return header.cMake(element);
+ case Generator.HEADER_CMAKE_FOLDER:
+ return header.cMakeFolders();
+ default:
+ break;
+ }
+
+ return null;
+ }
+
+}
Oops, something went wrong.
@@ -1,139 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2013 Ahmed M.Orabi, Mahmoud M.Orabi.
-* All rights reserved. This program and the accompanying materials
-* are made available under the terms of the Eclipse Public License v1.0
-* which accompanies this distribution, and is available at
-* http://www.eclipse.org/legal/epl-v10.html
-*
-* Contributors:
-* Ahmed M.Orabi
-* Mahmoud M.Orabi
-*
-* Please refer to the code authors before making any changes.
-* For any code reuse or copy, contact the authors and it is a MUST
-* to refer author names.
-*
-* @author -Ahmed M.Orabi {@link ahmedvc@hotmail.com}
-* @author Mahmoud M.Orabi {@link mahmoud_3rabi@hotmail.com}
-*******************************************************************************/
-package cruise.umple.cpp.processors;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import cruise.umple.core.GenerationPolicyRegistry;
-import cruise.umple.core.IPoliciesProcessor;
-import cruise.umple.cpp.core.ContentsDescriptor;
-import cruise.umple.cpp.core.IGenerationCommonConstants;
-import cruise.umple.cpp.jet.CppHeader;
-import cruise.umple.cpp.jet.CppStatemachine;
-import cruise.umple.cpp.jet.CppStructure;
-import cruise.umple.cpp.jet.util.CppAddHandler;
-import cruise.umple.cpp.jet.util.CppAttributeGetterImpl;
-import cruise.umple.cpp.jet.util.CppAttributeSetterImpl;
-import cruise.umple.cpp.jet.util.CppConstructor;
-import cruise.umple.cpp.jet.util.CppNameHelper;
-import cruise.umple.cpp.jet.util.CppStlTemplateHelper;
-import cruise.umple.cpp.jet.util.CppTemplateHelper;
-import cruise.umple.cpp.jet.util.CppTestsHelper;
-import cruise.umple.cpp.utils.CPPCommonConstants;
-import cruise.umple.modeling.handlers.IModelingConstants;
-import cruise.umple.modeling.handlers.IModelingPriorityHandler;
-import cruise.umple.modeling.handlers.IModelingStatemachinePriorityHandler;
-import cruise.umple.modeling.handlers.ModelingAssociationsGenerationPointsHandler;
-import cruise.umple.modeling.handlers.ModelingBaseDecisionPointsHandler;
-import cruise.umple.modeling.handlers.ModelingBaseGenerationPointsHandler;
-import cruise.umple.modeling.handlers.ModelingConstructorPointsHandler;
-import cruise.umple.modeling.handlers.cpp.CPPBaseGenerationPointsHandler;
-import cruise.umple.modeling.handlers.cpp.CPPContentsPointsHandler;
-import cruise.umple.modeling.handlers.cpp.CPPDependsPointsHandler;
-import cruise.umple.modeling.handlers.cpp.CppCustomGetterFunctionsPointsHandler;
-import cruise.umple.modeling.handlers.cpp.CppStatemachinePointsHandler;
-import cruise.umple.modeling.handlers.cpp.ICppModelingPriorityHandler;
-import cruise.umple.modeling.handlers.cpp.StlGenerationPointsHandler;
-import cruise.umple.modeling.handlers.cpp.StructurePointsHandler;
-
-abstract public class CppPoliciesProcessor implements IPoliciesProcessor{
-
- private GenerationPolicyRegistry generationPolicyRegistry = new GenerationPolicyRegistry();
-
- public void generateRootElement(Object rootElement) {
- this.getGenerationPolicyRegistry().process(rootElement);
- this.handleGeneratedContents(getContentDescriptors());
-
- //this.generationPolicyRegistry.getGenerationLogger().showLogDetails();
- }
-
- abstract public void handleGeneratedContents(List<ContentsDescriptor> contentsDescriptor);
-
- public CppPoliciesProcessor() {
- registerGenerationLanguages();
- registerTypesPolicies();
- registerGenerationPoints();
- registerHelperTemplates();
- }
-
- @Override
- public void registerGenerationLanguages() {
- this.generationPolicyRegistry.addUniqueValue(IModelingConstants.GENERATION_LANGUAGE, CPPCommonConstants.CPP_LANGUAGE);
- }
-
- @Override
- public void registerHelperTemplates(){
- new CppTemplateHelper().init(this.getGenerationPolicyRegistry());
- new CppAttributeGetterImpl().init(this.getGenerationPolicyRegistry());
- new CppNameHelper().init(this.getGenerationPolicyRegistry());
- new CppAddHandler().init(this.getGenerationPolicyRegistry());
- new CppAttributeSetterImpl().init(this.getGenerationPolicyRegistry());
- new CppHeader().init(this.getGenerationPolicyRegistry());
- new CppStatemachine().init(this.getGenerationPolicyRegistry());
- new CppStructure().init(this.getGenerationPolicyRegistry());
- new CppConstructor().init(this.getGenerationPolicyRegistry());
- new CppStlTemplateHelper().init(this.getGenerationPolicyRegistry());
-
- new CppTestsHelper().init(this.getGenerationPolicyRegistry());
- }
-
- @Override
- public void registerGenerationPoints(){
- this.getGenerationPolicyRegistry().register(IModelingPriorityHandler.class);
- this.getGenerationPolicyRegistry().register(ICppModelingPriorityHandler.class);
- this.getGenerationPolicyRegistry().register(IModelingStatemachinePriorityHandler.class);
-
- this.getGenerationPolicyRegistry().register(new ModelingConstructorPointsHandler());
- this.getGenerationPolicyRegistry().register(new ModelingAssociationsGenerationPointsHandler());
- this.getGenerationPolicyRegistry().register(new ModelingBaseDecisionPointsHandler());
- this.getGenerationPolicyRegistry().register(new ModelingBaseGenerationPointsHandler());
-
- this.getGenerationPolicyRegistry().register(new CPPBaseGenerationPointsHandler());
- this.getGenerationPolicyRegistry().register(new StlGenerationPointsHandler());
- this.getGenerationPolicyRegistry().register(new CppCustomGetterFunctionsPointsHandler());
- this.getGenerationPolicyRegistry().register(new CPPDependsPointsHandler());
- this.getGenerationPolicyRegistry().register(new CPPContentsPointsHandler());
-
- this.getGenerationPolicyRegistry().register(new CppStatemachinePointsHandler());
- this.getGenerationPolicyRegistry().register(new StructurePointsHandler());
-
- //this.getGenerationPolicyRegistry().register(new CppTestsPointsHandler());
- }
-
- public List<ContentsDescriptor> getContentDescriptors(){
- List<Object> values = this.generationPolicyRegistry.getValues(IGenerationCommonConstants.CONTENTS_DESCRIPTORS);
- List<ContentsDescriptor> descriptors= new ArrayList<ContentsDescriptor>();
- if(values!= null){
- for(Object obj: values){
- if(obj instanceof ContentsDescriptor){
- descriptors.add((ContentsDescriptor) obj);
- }
- }
- return descriptors;
- }
- return descriptors;
- }
-
- @Override
- public GenerationPolicyRegistry getGenerationPolicyRegistry() {
- return this.generationPolicyRegistry;
- }
-
-}
Oops, something went wrong.

0 comments on commit d9c991a

Please sign in to comment.