EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.cip.workflow.jobs]

COVERAGE SUMMARY FOR SOURCE FILE [CreateWorkingCopyOfModelsJob.java]

nameclass, %method, %block, %line, %
CreateWorkingCopyOfModelsJob.java0%   (0/1)0%   (0/6)0%   (0/155)0%   (0/37)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CreateWorkingCopyOfModelsJob0%   (0/1)0%   (0/6)0%   (0/155)0%   (0/37)
<static initializer> 0%   (0/1)0%   (0/4)0%   (0/2)
CreateWorkingCopyOfModelsJob (CompletionConfiguration, Transformation): void 0%   (0/1)0%   (0/36)0%   (0/8)
execute (IProgressMonitor): void 0%   (0/1)0%   (0/105)0%   (0/22)
getName (): String 0%   (0/1)0%   (0/2)0%   (0/1)
rollback (IProgressMonitor): void 0%   (0/1)0%   (0/4)0%   (0/2)
setBlackboard (MDSDBlackboard): void 0%   (0/1)0%   (0/4)0%   (0/2)

1package de.uka.ipd.sdq.cip.workflow.jobs;
2 
3import java.io.IOException;
4import java.util.HashMap;
5 
6import org.apache.log4j.Logger;
7import org.eclipse.core.resources.IFolder;
8import org.eclipse.core.runtime.IProgressMonitor;
9import org.eclipse.emf.common.util.URI;
10import org.eclipse.emf.ecore.resource.Resource;
11import org.eclipse.emf.ecore.resource.ResourceSet;
12 
13import de.uka.ipd.sdq.cip.configuration.CompletionConfiguration;
14import de.uka.ipd.sdq.cip.configuration.Transformation;
15import de.uka.ipd.sdq.workflow.IBlackboardInteractingJob;
16import de.uka.ipd.sdq.workflow.IJob;
17import de.uka.ipd.sdq.workflow.exceptions.JobFailedException;
18import de.uka.ipd.sdq.workflow.exceptions.RollbackFailedException;
19import de.uka.ipd.sdq.workflow.exceptions.UserCanceledException;
20import de.uka.ipd.sdq.workflow.mdsd.blackboard.MDSDBlackboard;
21import de.uka.ipd.sdq.workflow.mdsd.blackboard.ResourceSetPartition;
22 
23/**
24 * Job to create a working copy of the models to simulate.
25 * This ensures that any downstream job changing the models 
26 * does not modify the original models.
27 * 
28 * Prerequisite of this job:
29 * This job copies the models to the configured project created in
30 * the workflow. It has to exist to be able to store the model copy
31 * into it.
32 * 
33 * @author Benjamin Klatt
34 *
35 */
36public class CreateWorkingCopyOfModelsJob implements IJob,
37        IBlackboardInteractingJob<MDSDBlackboard> {
38 
39        /** The logger for this class */
40        private static final Logger logger = Logger.getLogger(CreateWorkingCopyOfModelsJob.class);
41        
42        /** The blackboard to interact with */
43        private MDSDBlackboard blackboard = null;
44 
45        /** The work flow configuration to get the required information from */
46        //private SimuComWorkflowConfiguration configuration;
47 
48        private String projectID;
49 
50        private String modelPartitionID;
51 
52        private String transformationID;
53 
54        /**
55         * Constructor requiring the necessary configuration object.
56         * 
57         * @param configuration The configuration for this job.
58         */
59        public CreateWorkingCopyOfModelsJob(CompletionConfiguration completionConfiguration,
60                        Transformation transformation) {
61                this.projectID = completionConfiguration.getProjectID();
62                this.modelPartitionID = completionConfiguration.getInputPartitionName();
63                
64                URI qvtFileURI = URI.createURI(transformation.getQVTFileURI());
65                this.transformationID = qvtFileURI.lastSegment().replace(qvtFileURI.fileExtension(), "") + 
66                        completionConfiguration.getTransformations().indexOf(transformation);
67        }
68        
69        /**
70         * Execute this job and create the model copy.
71         */
72        @Override
73        public void execute(IProgressMonitor monitor) throws JobFailedException,
74                        UserCanceledException {
75 
76                IFolder modelFolder = PrepareTransformationsJob.createFolder(
77                                PrepareTransformationsJob.getModelFolder(projectID).getFolder(
78                                                transformationID),
79                                logger);
80                
81                String modelBasePath = "file:/"+modelFolder.getLocation().toOSString();
82                
83                // access the resources
84                ResourceSetPartition partition = (ResourceSetPartition) this.blackboard.getPartition(modelPartitionID);
85                ResourceSet resourceSet = partition.getResourceSet();
86                for (Resource ressource : resourceSet.getResources()) {
87                        
88                        // we only need to copy the file models
89                        if (ressource.getURI().isFile()) {
90 
91                                URI uri = ressource.getURI();
92                                String relativePath = uri.lastSegment();
93                                URI newURI = URI.createURI(modelBasePath +"/"+ relativePath);
94                                ressource.setURI(newURI);
95                                
96                                try {
97                                        ressource.save(new HashMap());
98                                        partition.setContents(ressource.getURI(), ressource.getContents());
99                                } catch (IOException e) {
100                                        logger.error("Unable to store resource "+ressource.getURI(),e);
101                                }
102                        }
103                }
104                try {
105                        partition.storeAllResources();
106                } catch (IOException e) {
107                        logger.error("unable to store all resources",e);
108                        throw new JobFailedException("Unable to store all Resources",e);
109                }
110//                partition.resolveAllProxies();
111//                this.blackboard.removePartition(LoadPCMModelsIntoBlackboardJob.PCM_MODELS_PARTITION_ID);
112//                this.blackboard.addPartition(LoadPCMModelsIntoBlackboardJob.PCM_MODELS_PARTITION_ID, partition);
113        }
114 
115        @Override
116        public String getName() {
117                return "Create working copy of models";
118        }
119 
120        @Override
121        public void rollback(IProgressMonitor monitor)
122                        throws RollbackFailedException {
123                logger.warn("Unable to perform rollback for this job");
124 
125        }
126 
127        @Override
128        public void setBlackboard(MDSDBlackboard blackboard) {
129                this.blackboard = blackboard;
130        }
131 
132}

[all classes][de.uka.ipd.sdq.cip.workflow.jobs]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov