1 | package de.uka.ipd.sdq.cip.workflow.jobs; |
2 | |
3 | import org.apache.log4j.Logger; |
4 | import org.eclipse.core.resources.IFolder; |
5 | import org.eclipse.core.resources.IProject; |
6 | import org.eclipse.core.resources.ResourcesPlugin; |
7 | import org.eclipse.core.runtime.CoreException; |
8 | import org.eclipse.core.runtime.IProgressMonitor; |
9 | |
10 | import de.uka.ipd.sdq.cip.ConstantsContainer; |
11 | import de.uka.ipd.sdq.cip.configuration.CompletionConfiguration; |
12 | import de.uka.ipd.sdq.workflow.IJob; |
13 | import de.uka.ipd.sdq.workflow.exceptions.JobFailedException; |
14 | import de.uka.ipd.sdq.workflow.exceptions.RollbackFailedException; |
15 | import de.uka.ipd.sdq.workflow.exceptions.UserCanceledException; |
16 | |
17 | public class PrepareTransformationsJob implements IJob{ |
18 | |
19 | /** The logger for this class */ |
20 | private Logger logger = Logger.getLogger(PrepareTransformationsJob.class); |
21 | |
22 | /** The project id where to create folders */ |
23 | private String projectID; |
24 | |
25 | public PrepareTransformationsJob(CompletionConfiguration configuration) { |
26 | this.projectID = configuration.getProjectID(); |
27 | } |
28 | |
29 | @Override |
30 | public void execute(IProgressMonitor monitor) throws JobFailedException, |
31 | UserCanceledException { |
32 | |
33 | // Create necessary folders for completion |
34 | |
35 | createFolder(getModelFolder(projectID), logger); |
36 | createFolder(getTracesFolder(projectID), logger); |
37 | createFolder(getHOTTracesFolder(projectID), logger); |
38 | createFolder(getLogFolder(projectID), logger); |
39 | } |
40 | |
41 | |
42 | /** |
43 | * returns a new project to be used for the simulation |
44 | * |
45 | * @return a handle to the project to be used for the simulation |
46 | */ |
47 | protected static IProject getProject(String projectId) { |
48 | return ResourcesPlugin.getWorkspace().getRoot().getProject( |
49 | projectId); |
50 | } |
51 | |
52 | public static IFolder getModelFolder(String projectID) { |
53 | return getProject(projectID).getFolder(ConstantsContainer.MODELFOLDER); |
54 | } |
55 | |
56 | public static IFolder getTracesFolder(String projectID) { |
57 | return getProject(projectID).getFolder(ConstantsContainer.TRACESFOLDER); |
58 | } |
59 | |
60 | public static IFolder getHOTTracesFolder(String projectID) { |
61 | return getProject(projectID).getFolder(ConstantsContainer.HOTTRACESFOLDER); |
62 | } |
63 | |
64 | public static IFolder getLogFolder(String projectID) { |
65 | return getProject(projectID).getFolder(ConstantsContainer.LOGFOLDER); |
66 | } |
67 | |
68 | public static IFolder createFolder(IFolder folder,Logger logger) throws JobFailedException { |
69 | if (folder.getProject().isOpen() && !folder.exists()) { |
70 | logger.debug("Creating folder " + folder.getName()); |
71 | try { |
72 | folder.create(false, true, null); |
73 | } catch (CoreException e) { |
74 | logger.error("unable to create model folder"); |
75 | throw new JobFailedException(e); |
76 | } |
77 | } |
78 | return folder; |
79 | } |
80 | |
81 | @Override |
82 | public String getName() { |
83 | return "Prepare project for completion"; |
84 | } |
85 | |
86 | @Override |
87 | public void rollback(IProgressMonitor monitor) |
88 | throws RollbackFailedException {} // nothing to roll back |
89 | |
90 | |
91 | } |