1 | package de.uka.ipd.sdq.cip.workflow.jobs; |
2 | |
3 | import java.io.FileNotFoundException; |
4 | import java.io.FileOutputStream; |
5 | import java.io.PrintStream; |
6 | import java.util.Collection; |
7 | |
8 | import org.eclipse.core.runtime.CoreException; |
9 | import org.eclipse.core.runtime.IProgressMonitor; |
10 | import org.eclipse.emf.common.util.URI; |
11 | |
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.exceptions.JobFailedException; |
17 | import de.uka.ipd.sdq.workflow.exceptions.RollbackFailedException; |
18 | import de.uka.ipd.sdq.workflow.exceptions.UserCanceledException; |
19 | import de.uka.ipd.sdq.workflow.mdsd.blackboard.MDSDBlackboard; |
20 | import de.uka.ipd.sdq.workflow.mdsd.blackboard.ModelLocation; |
21 | import de.uka.ipd.sdq.workflow.mdsd.emf.qvtr.QVTRScript; |
22 | import de.uka.ipd.sdq.workflow.mdsd.emf.qvtr.jobs.QVTRTransformationJobConfiguration; |
23 | |
24 | public class QVTRConfigurationJob implements |
25 | IBlackboardInteractingJob<MDSDBlackboard> { |
26 | |
27 | private CompletionConfiguration completionConfiguration = null; |
28 | private Transformation transformation = null; |
29 | private QVTRTransformationJobConfiguration jobConfiguration = null; |
30 | private MDSDBlackboard blackboard = null; |
31 | |
32 | public QVTRConfigurationJob(QVTRTransformationJobConfiguration jobConfiguration, |
33 | CompletionConfiguration completionConfiguration, Transformation transformation) { |
34 | |
35 | this.jobConfiguration = jobConfiguration; |
36 | this.transformation = transformation; |
37 | this.completionConfiguration = completionConfiguration; |
38 | |
39 | } |
40 | |
41 | @Override |
42 | public void execute(IProgressMonitor monitor) throws JobFailedException, |
43 | UserCanceledException { |
44 | |
45 | assert (completionConfiguration != null); |
46 | assert (transformation != null); |
47 | assert (jobConfiguration != null); |
48 | |
49 | String modelPartitionID = completionConfiguration.getInputPartitionName(); |
50 | |
51 | // get the models to work with |
52 | ModelLocation[] inputModelLocations = QVTConfigurationHelper.getModelsFromBlackboard(blackboard, modelPartitionID); |
53 | |
54 | // get meta models needed for qvt script |
55 | Collection<Object> metamodels = QVTConfigurationHelper.getMetaModelsFromBlackboard(blackboard, modelPartitionID); |
56 | |
57 | ModelLocation[] outputModelLocations = new ModelLocation[] { |
58 | QVTConfigurationHelper.createResourceToInputPartition( |
59 | blackboard, |
60 | modelPartitionID, |
61 | URI.createURI(PrepareTransformationsJob. |
62 | getModelFolder(completionConfiguration.getProjectID()). |
63 | getFile("output.xmi").getFullPath().toPortableString()))}; |
64 | |
65 | ModelLocation[] configModelLocations = null; |
66 | if(transformation.getConfigFileURI() != null && !transformation.getConfigFileURI().isEmpty()) { |
67 | |
68 | configModelLocations = new ModelLocation[] { |
69 | QVTConfigurationHelper.loadResourceToInputPartition( |
70 | blackboard, |
71 | modelPartitionID, |
72 | URI.createURI(transformation.getConfigFileURI()))}; |
73 | |
74 | metamodels.addAll(QVTConfigurationHelper.getMetaModelsFromFile( |
75 | URI.createURI(transformation.getMetamodelFileURI()))); |
76 | } |
77 | |
78 | QVTRScript qvtrScript = QVTConfigurationHelper.createQVTScript(transformation.getQVTFileURI(), metamodels, null, null); |
79 | |
80 | URI traceFileURI = QVTConfigurationHelper.getTraceFileURI(completionConfiguration.getProjectID()); |
81 | |
82 | Boolean isDebug = completionConfiguration.getDebug(); |
83 | |
84 | PrintStream extendedDebuggingLog = null; |
85 | if(isDebug) { |
86 | try { |
87 | extendedDebuggingLog = new PrintStream( |
88 | new FileOutputStream ( |
89 | PrepareTransformationsJob. |
90 | getLogFolder(completionConfiguration.getProjectID()). |
91 | getFile(QVTConfigurationHelper. |
92 | createTransformationID(completionConfiguration, transformation) + |
93 | ".log"). |
94 | getRawLocation().toOSString()),true); |
95 | |
96 | } catch (FileNotFoundException e) { |
97 | throw new JobFailedException("Could not create extended logging output", e); |
98 | } |
99 | } |
100 | |
101 | |
102 | // set the job configuration |
103 | jobConfiguration.setDebug(isDebug); |
104 | jobConfiguration.addModelLocationSets(inputModelLocations); |
105 | jobConfiguration.addModelLocationSets(outputModelLocations); |
106 | if(configModelLocations != null) |
107 | jobConfiguration.addModelLocationSets(configModelLocations); |
108 | jobConfiguration.setTraceFileURI(traceFileURI); |
109 | jobConfiguration.setExtendedDebuggingLog(extendedDebuggingLog); |
110 | jobConfiguration.setQVTRScript(qvtrScript); |
111 | |
112 | |
113 | } |
114 | |
115 | public QVTRTransformationJobConfiguration getJobConfiguration() { |
116 | return jobConfiguration; |
117 | } |
118 | |
119 | @Override |
120 | public void setBlackboard(MDSDBlackboard blackboard) { |
121 | this.blackboard = blackboard; |
122 | } |
123 | |
124 | @Override |
125 | public String getName() { |
126 | return "Configure QVTR transformation"; |
127 | } |
128 | |
129 | @Override |
130 | public void rollback(IProgressMonitor monitor) |
131 | throws RollbackFailedException { |
132 | if(jobConfiguration.getExtendedDebuggingLog() != null) |
133 | jobConfiguration.getExtendedDebuggingLog().close(); |
134 | |
135 | try { |
136 | PrepareTransformationsJob. |
137 | getLogFolder(completionConfiguration.getProjectID()).refreshLocal(1, monitor); |
138 | } catch (CoreException e) { |
139 | throw new RollbackFailedException("Could not refresh workspace", e); |
140 | } |
141 | } |
142 | |
143 | } |