Ignore:
Timestamp:
06/19/12 23:26:01 (12 years ago)
Author:
wschamai
Message:

NEW: evaluation if code should be re-generated depending on last generation and last model modification

Location:
trunk/modelicaml/org.openmodelica.modelicaml.common/src/org/openmodelica/modelicaml/common
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/modelicaml/org.openmodelica.modelicaml.common/src/org/openmodelica/modelicaml/common/services/ModelicaMLServices.java

    r1538 r1548  
    55import java.io.FileNotFoundException;
    66import java.io.FileOutputStream;
    7 import java.io.FileWriter;
    87import java.io.IOException;
    98import java.io.OutputStreamWriter;
    109import java.io.UnsupportedEncodingException;
    11 import java.net.URI;
    1210import java.util.ArrayList;
    1311import java.util.Collections;
    1412import java.util.Comparator;
     13import java.util.HashMap;
    1514import java.util.HashSet;
    1615import java.util.List;
     
    3029import org.eclipse.emf.common.util.EList;
    3130import org.eclipse.emf.ecore.EObject;
     31import org.eclipse.emf.ecore.resource.Resource;
    3232import org.eclipse.papyrus.core.utils.BusinessModelResolver;
    3333import org.eclipse.papyrus.resource.uml.UmlModel;
    34 import org.eclipse.papyrus.resource.uml.UmlUtils;
    3534import org.eclipse.uml2.uml.Element;
    3635import org.eclipse.uml2.uml.NamedElement;
     
    4140public class ModelicaMLServices {
    4241
    43    
     42    /*
     43     * Regeneration of  code
     44     */
     45    public static HashMap<Resource,Long> modelModificationStamp = new HashMap<Resource,Long>();
     46    public static HashMap<Resource,Long> codeGenerationStamp = new HashMap<Resource,Long>();
     47   
     48    public static boolean regenerateCode(Resource resource){
     49       
     50        // TODO: check if the code-gen folder exists in the project
     51       
     52        Long modifiedModelTimeStamp = modelModificationStamp.get(resource);
     53        Long generatedCodeTimeStamp = codeGenerationStamp.get(resource);
     54       
     55//      System.err.println("Checking if it is neccesary to regenerate code for: "+  resource);
     56//      System.err.println("modifiedModelTimeStamp: " + modifiedModelTimeStamp);
     57//      System.err.println("generatedCodeTimeStamp: " + generatedCodeTimeStamp);
     58//      if (generatedCodeTimeStamp != null && modifiedModelTimeStamp != null) {         
     59//          System.err.println("modifiedModelTimeStamp < generatedCodeTimeStamp: " + (modifiedModelTimeStamp < generatedCodeTimeStamp));
     60//      }
     61       
     62        if (generatedCodeTimeStamp != null && modifiedModelTimeStamp != null) {
     63            // if code was generated after the model modification -> no need for regenerating code
     64            if (modifiedModelTimeStamp < generatedCodeTimeStamp) {
     65                System.err.println("Skipping code generation ... ");
     66                return false;
     67               
     68            }
     69        }
     70        return true;
     71    }
     72   
     73   
     74    public static boolean saveModel(UmlModel umlModel){
     75        try {
     76            umlModel.saveModel();
     77            return true;
     78        } catch (IOException e) {
     79            // TODO Auto-generated catch block
     80            e.printStackTrace();
     81        }
     82        return false;
     83    }
     84   
     85    /*
     86     * Element adoption
     87     */
    4488    public static EObject adaptSelectedElement( Object selection) {
     89       
    4590        EObject eObject = null;
    4691        if(selection != null) {
     
    58103    }
    59104   
     105   
     106    /*
     107     * Requirements data
     108     */
    60109    public static String getRequirementID(Element req){
    61110        if (req instanceof NamedElement) {
     
    81130
    82131   
     132    /*
     133     * Utilities
     134     */
    83135    public static List<TreeObject> getSortedByDotPath(HashSet<TreeObject> set){
    84136        if (set == null) { return null; }
     
    219271//  }
    220272   
    221    
     273    /*
     274     * OMC handling
     275     */
    222276    public static boolean containsOMCErrorMessage(String msg){
    223277        if (    msg.contains("Error: ")
     
    287341   
    288342   
     343    /*
     344     * Files handling
     345     */
    289346    public static IStatus deleteFiles(List<String> filesToBeDeleted, IProgressMonitor monitor, String message){
    290347       
Note: See TracChangeset for help on using the changeset viewer.