|
1 /** |
|
2 * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Symbian Foundation - initial contribution. |
|
11 * Contributors: |
|
12 * Description: |
|
13 * Overview: |
|
14 * Details: |
|
15 * Platforms/Drives/Compatibility: |
|
16 * Assumptions/Requirement/Pre-requisites: |
|
17 * Failures and causes: |
|
18 */ |
|
19 package org.symbian.tools.tmw.internal.ui.project; |
|
20 |
|
21 import java.lang.reflect.InvocationTargetException; |
|
22 |
|
23 import org.eclipse.core.resources.IProject; |
|
24 import org.eclipse.core.resources.IResource; |
|
25 import org.eclipse.core.resources.IResourceVisitor; |
|
26 import org.eclipse.core.resources.IncrementalProjectBuilder; |
|
27 import org.eclipse.core.resources.ResourcesPlugin; |
|
28 import org.eclipse.core.runtime.CoreException; |
|
29 import org.eclipse.core.runtime.IProgressMonitor; |
|
30 import org.eclipse.core.runtime.IStatus; |
|
31 import org.eclipse.core.runtime.NullProgressMonitor; |
|
32 import org.eclipse.core.runtime.Status; |
|
33 import org.eclipse.core.runtime.jobs.Job; |
|
34 import org.eclipse.jface.operation.IRunnableWithProgress; |
|
35 import org.eclipse.swt.widgets.Display; |
|
36 import org.symbian.tools.tmw.ui.TMWCoreUI; |
|
37 |
|
38 public class PrepareProjectJob extends Job { |
|
39 private final IProject project; |
|
40 private final IRunnableWithProgress action; |
|
41 |
|
42 public PrepareProjectJob(IProject project, IRunnableWithProgress action) { |
|
43 super(String.format("Preparing project", project.getName())); |
|
44 this.project = project; |
|
45 this.action = action; |
|
46 setUser(false); |
|
47 setRule(ResourcesPlugin.getWorkspace().getRoot()); |
|
48 } |
|
49 |
|
50 @Override |
|
51 protected IStatus run(IProgressMonitor monitor) { |
|
52 monitor.beginTask("Prepare project files", 200); |
|
53 try { |
|
54 touchFiles(); |
|
55 } catch (CoreException e) { |
|
56 TMWCoreUI.log(e); |
|
57 } |
|
58 if (action != null) { |
|
59 Display.getDefault().asyncExec(new Runnable() { |
|
60 public void run() { |
|
61 try { |
|
62 action.run(new NullProgressMonitor()); |
|
63 } catch (InvocationTargetException e) { |
|
64 TMWCoreUI.log(e); |
|
65 } catch (InterruptedException e) { |
|
66 TMWCoreUI.log(e); |
|
67 } |
|
68 } |
|
69 }); |
|
70 } |
|
71 monitor.done(); |
|
72 return Status.OK_STATUS; |
|
73 } |
|
74 |
|
75 protected void touchFiles() throws CoreException { |
|
76 try { |
|
77 Thread.sleep(4000); // This is plain wrong. But we have concurrency issues in JSDT/Eclipse build system |
|
78 } catch (InterruptedException e) { |
|
79 TMWCoreUI.log(e); |
|
80 } |
|
81 project.accept(new IResourceVisitor() { |
|
82 public boolean visit(IResource resource) throws CoreException { |
|
83 if (resource.isAccessible() && resource.getType() == IResource.FILE |
|
84 && resource.getFileExtension().equals("js")) { |
|
85 resource.touch(new NullProgressMonitor()); |
|
86 } |
|
87 return true; |
|
88 } |
|
89 }); |
|
90 try { |
|
91 Thread.sleep(1000); // This is plain wrong. But we have concurrency issues in JSDT/Eclipse build system |
|
92 } catch (InterruptedException e) { |
|
93 TMWCoreUI.log(e); |
|
94 } |
|
95 project.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor()); |
|
96 } |
|
97 |
|
98 } |