1 | package de.uka.ipd.sdq.cip.workflow.jobs; |
2 | |
3 | import java.util.HashMap; |
4 | |
5 | import org.eclipse.core.resources.IFolder; |
6 | import org.eclipse.core.runtime.IProgressMonitor; |
7 | import org.eclipse.emf.common.util.URI; |
8 | import org.eclipse.emf.ecore.EObject; |
9 | import org.eclipse.xpand2.output.Outlet; |
10 | |
11 | import de.uka.ipd.sdq.cip.ConstantsContainer; |
12 | import de.uka.ipd.sdq.cip.configuration.CompletionConfiguration; |
13 | import de.uka.ipd.sdq.cip.configuration.QVTConfigurationHelper; |
14 | import de.uka.ipd.sdq.cip.configuration.Transformation; |
15 | import de.uka.ipd.sdq.workflow.IBlackboardInteractingJob; |
16 | import de.uka.ipd.sdq.workflow.OrderPreservingBlackboardCompositeJob; |
17 | import de.uka.ipd.sdq.workflow.exceptions.JobFailedException; |
18 | import de.uka.ipd.sdq.workflow.exceptions.RollbackFailedException; |
19 | import de.uka.ipd.sdq.workflow.exceptions.UserCanceledException; |
20 | import de.uka.ipd.sdq.workflow.mdsd.blackboard.MDSDBlackboard; |
21 | import de.uka.ipd.sdq.workflow.mdsd.blackboard.ResourceSetPartition; |
22 | import de.uka.ipd.sdq.workflow.mdsd.emf.qvtr.jobs.QVTRTransformationJobConfiguration; |
23 | import de.uka.ipd.sdq.workflow.mdsd.oaw.XpandGeneratorJob; |
24 | |
25 | public class PrettyPrintQvtJob extends |
26 | OrderPreservingBlackboardCompositeJob<MDSDBlackboard> implements |
27 | IBlackboardInteractingJob<MDSDBlackboard> { |
28 | |
29 | private CompletionConfiguration completionConfiguration = null; |
30 | private Transformation transformation = null; |
31 | private QVTRTransformationJobConfiguration jobConfiguration = null; |
32 | private MDSDBlackboard blackboard = null; |
33 | |
34 | public PrettyPrintQvtJob(QVTRTransformationJobConfiguration jobConfiguration, |
35 | CompletionConfiguration completionConfiguration, Transformation transformation) { |
36 | |
37 | this.jobConfiguration = jobConfiguration; |
38 | this.transformation = transformation; |
39 | this.completionConfiguration = completionConfiguration; |
40 | |
41 | } |
42 | |
43 | private static final String PRETTYPRINT_EXPRESSION = "template::prettyprint::trafo FOR model"; |
44 | @Override |
45 | public void execute(IProgressMonitor monitor) |
46 | throws de.uka.ipd.sdq.workflow.exceptions.JobFailedException, |
47 | de.uka.ipd.sdq.workflow.exceptions.UserCanceledException { |
48 | |
49 | assert (completionConfiguration != null); |
50 | assert (transformation != null); |
51 | assert (jobConfiguration != null); |
52 | |
53 | add(getGeneratorJob(getModelSlot(), PRETTYPRINT_EXPRESSION)); |
54 | |
55 | super.execute(monitor); |
56 | } |
57 | |
58 | |
59 | private HashMap<String, Object> getModelSlot() { |
60 | HashMap<String,Object> sC2 = new HashMap<String, Object>(); |
61 | ResourceSetPartition partition = this.myBlackboard.getPartition(ConstantsContainer.HOT_PARTITION_ID); |
62 | URI modelURI = URI.createURI(PrepareTransformationsJob. |
63 | getModelFolder(completionConfiguration.getProjectID()). |
64 | getFile("qvt.xmi").getFullPath().toPortableString()); |
65 | sC2.put("model",partition.getFirstContentElement(modelURI)); |
66 | return sC2; |
67 | } |
68 | |
69 | |
70 | private Outlet[] getQVTOutlets() throws JobFailedException { |
71 | |
72 | IFolder modelFolder = PrepareTransformationsJob.createFolder( |
73 | PrepareTransformationsJob.getModelFolder(completionConfiguration.getProjectID()).getFolder( |
74 | QVTConfigurationHelper.createTransformationID(completionConfiguration, transformation)), |
75 | logger); |
76 | |
77 | Outlet outlet = new Outlet(modelFolder.getFullPath().toString()); |
78 | outlet.setName("transformation"); |
79 | |
80 | transformation.setQVTFileURI(modelFolder.getFile("trasformation.qvt").getFullPath().toString()); |
81 | |
82 | return new Outlet[]{outlet}; |
83 | } |
84 | |
85 | |
86 | /** |
87 | * @param slots |
88 | * @param monitor |
89 | * @throws JobFailedException |
90 | * @throws JobFailedException |
91 | * @throws UserCanceledException |
92 | */ |
93 | private XpandGeneratorJob getGeneratorJob( |
94 | HashMap<String, Object> slots, |
95 | String expression) throws JobFailedException { |
96 | XpandGeneratorJob job = new XpandGeneratorJob( |
97 | slots, |
98 | ConstantsContainer.HOT_METAMODELS, |
99 | getQVTOutlets(), |
100 | expression); |
101 | //job.getAdvices().add(completionConfiguration.getCodeGenerationAdvicesFile()); |
102 | job.setCheckProtectedRegions(true); |
103 | |
104 | return job; |
105 | } |
106 | |
107 | } |