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

COVERAGE SUMMARY FOR SOURCE FILE [CreateWorkingCopyOfModelsJob.java]

nameclass, %method, %block, %line, %
CreateWorkingCopyOfModelsJob.java0%   (0/1)0%   (0/6)0%   (0/178)0%   (0/39)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CreateWorkingCopyOfModelsJob0%   (0/1)0%   (0/6)0%   (0/178)0%   (0/39)
<static initializer> 0%   (0/1)0%   (0/11)0%   (0/2)
CreateWorkingCopyOfModelsJob (AbstractPCMWorkflowRunConfiguration): void 0%   (0/1)0%   (0/9)0%   (0/4)
execute (IProgressMonitor): void 0%   (0/1)0%   (0/151)0%   (0/29)
getName (): String 0%   (0/1)0%   (0/2)0%   (0/1)
rollback (IProgressMonitor): void 0%   (0/1)0%   (0/1)0%   (0/1)
setBlackboard (MDSDBlackboard): void 0%   (0/1)0%   (0/4)0%   (0/2)

1package de.uka.ipd.sdq.workflow.pcm.jobs;
2 
3import java.io.IOException;
4 
5import org.apache.log4j.Logger;
6import org.eclipse.core.resources.IFolder;
7import org.eclipse.core.resources.IProject;
8import org.eclipse.core.runtime.CoreException;
9import org.eclipse.core.runtime.IProgressMonitor;
10import org.eclipse.emf.common.util.URI;
11import org.eclipse.emf.ecore.resource.Resource;
12import org.eclipse.emf.ecore.resource.ResourceSet;
13 
14import de.uka.ipd.sdq.workflow.IBlackboardInteractingJob;
15import de.uka.ipd.sdq.workflow.IJob;
16import de.uka.ipd.sdq.workflow.exceptions.JobFailedException;
17import de.uka.ipd.sdq.workflow.exceptions.RollbackFailedException;
18import de.uka.ipd.sdq.workflow.exceptions.UserCanceledException;
19import de.uka.ipd.sdq.workflow.mdsd.blackboard.MDSDBlackboard;
20import de.uka.ipd.sdq.workflow.pcm.blackboard.PCMResourceSetPartition;
21import de.uka.ipd.sdq.workflow.pcm.configurations.AbstractPCMWorkflowRunConfiguration;
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 AbstractPCMWorkflowRunConfiguration configuration;
47 
48        /**
49         * Constructor requiring the necessary configuration object.
50         *
51         * @param configuration The configuration for this job.
52         */
53        public CreateWorkingCopyOfModelsJob(AbstractPCMWorkflowRunConfiguration configuration) {
54                this.configuration = configuration;
55        }
56 
57        /**
58         * Execute this job and create the model copy.
59         */
60        public void execute(IProgressMonitor monitor) throws JobFailedException,
61                        UserCanceledException {
62 
63                assert (this.configuration != null);
64                IProject project = CreatePluginProjectJob.getProject(this.configuration
65                                .getStoragePluginID());
66                assert (project != null);
67 
68                // prepare the target path
69                IFolder modelFolder = project.getFolder("model");
70                if (project.isOpen() && !modelFolder.exists()) {
71                        logger.debug("Creating folder " + modelFolder.getName());
72                        try {
73                                modelFolder.create(false, true, null);
74                        } catch (CoreException e) {
75                                logger.error("unable to create model folder");
76                                throw new JobFailedException(e);
77                        }
78                }
79                String modelBasePath = "file:/"+modelFolder.getLocation().toOSString();
80 
81                // access the resources
82                PCMResourceSetPartition partition = (PCMResourceSetPartition) this.blackboard.getPartition(LoadPCMModelsIntoBlackboardJob.PCM_MODELS_PARTITION_ID);
83                ResourceSet resourceSet = partition.getResourceSet();
84                for (Resource ressource : resourceSet.getResources()) {
85 
86                        // we only need to copy the file models
87                        if (ressource.getURI().scheme() != "pathmap") {
88                                URI uri = ressource.getURI();
89                                String relativePath = uri.lastSegment();
90                                URI newURI = URI.createURI(modelBasePath +"/"+ relativePath);
91                                ressource.setURI(newURI);
92 
93                                try {
94                                        ressource.save(null);
95                                        partition.setContents(ressource.getURI(), ressource.getContents());
96                                } catch (IOException e) {
97                                        logger.error("Unable to store resource "+ressource.getURI(),e);
98                                }
99                        }
100                }
101                try {
102                        partition.storeAllResources();
103                } catch (IOException e) {
104                        logger.error("unable to store all resources",e);
105                        throw new JobFailedException("Unable to store all Resources",e);
106                }
107//                partition.resolveAllProxies();
108//                this.blackboard.removePartition(LoadPCMModelsIntoBlackboardJob.PCM_MODELS_PARTITION_ID);
109//                this.blackboard.addPartition(LoadPCMModelsIntoBlackboardJob.PCM_MODELS_PARTITION_ID, partition);
110        }
111 
112        public String getName() {
113                return "Create working copy of models";
114        }
115 
116        public void rollback(IProgressMonitor monitor)
117                        throws RollbackFailedException {
118                // nothing to roll back
119        }
120 
121        public void setBlackboard(MDSDBlackboard blackboard) {
122                this.blackboard = blackboard;
123        }
124 
125}

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