Lines 39-58
Link Here
|
39 |
|
39 |
|
40 |
package org.netbeans.modules.php.project.ui.actions.support; |
40 |
package org.netbeans.modules.php.project.ui.actions.support; |
41 |
|
41 |
|
|
|
42 |
import java.io.IOException; |
42 |
import java.util.logging.Logger; |
43 |
import java.util.logging.Logger; |
|
|
44 |
import org.apache.tools.ant.module.api.AntProjectCookie; |
45 |
import org.apache.tools.ant.module.api.AntTargetExecutor; |
46 |
import org.apache.tools.ant.module.api.AntTargetExecutor.Env; |
43 |
import org.netbeans.modules.php.project.PhpProject; |
47 |
import org.netbeans.modules.php.project.PhpProject; |
44 |
import org.netbeans.modules.php.project.ProjectPropertiesSupport; |
48 |
import org.netbeans.modules.php.project.ProjectPropertiesSupport; |
45 |
import org.netbeans.modules.php.project.ui.customizer.CompositePanelProviderImpl; |
49 |
import org.netbeans.modules.php.project.ui.customizer.CompositePanelProviderImpl; |
46 |
import org.netbeans.modules.php.project.ui.customizer.CustomizerProviderImpl; |
50 |
import org.netbeans.modules.php.project.ui.customizer.CustomizerProviderImpl; |
47 |
import org.netbeans.modules.php.project.ui.customizer.PhpProjectProperties; |
51 |
import org.netbeans.modules.php.project.ui.customizer.PhpProjectProperties; |
|
|
52 |
import org.netbeans.spi.project.ui.support.BuildExecutionSupport; |
53 |
import org.openide.execution.ExecutorTask; |
48 |
import org.openide.filesystems.FileObject; |
54 |
import org.openide.filesystems.FileObject; |
|
|
55 |
import org.openide.loaders.DataObject; |
56 |
import org.openide.loaders.DataObjectNotFoundException; |
57 |
import org.openide.util.Exceptions; |
49 |
import org.openide.util.Lookup; |
58 |
import org.openide.util.Lookup; |
|
|
59 |
import org.openide.util.Task; |
60 |
import org.openide.util.TaskListener; |
50 |
|
61 |
|
51 |
/** |
62 |
/** |
52 |
* Common action for all the possible Run Configurations of a PHP project. |
63 |
* Common action for all the possible Run Configurations of a PHP project. |
53 |
* <p> |
64 |
* <p> |
54 |
* Meant to be stateless, so thread safe. |
65 |
* Meant to be stateless, so thread safe. |
55 |
* @author Tomas Mysik |
66 |
* @author Tomas Mysik, Phil Lello |
56 |
*/ |
67 |
*/ |
57 |
public abstract class ConfigAction { |
68 |
public abstract class ConfigAction { |
58 |
public static enum Type { |
69 |
public static enum Type { |
Lines 123-128
Link Here
|
123 |
return XDebugStarterFactory.getInstance() != null; |
134 |
return XDebugStarterFactory.getInstance() != null; |
124 |
} |
135 |
} |
125 |
|
136 |
|
|
|
137 |
// TODO: Decide how much effort these should put into detecting targets. |
138 |
// Testing for build.xml is cheap and easy, probing build.xml via XPath |
139 |
// to detect targets would be better, but then opens up a can of worms over |
140 |
// includes, etc. |
141 |
// It would probably be good to support Maven too. |
142 |
private DataObject getBuildXmlDataObject() { |
143 |
FileObject buildXml = project.getHelper().getProjectDirectory().getFileObject("build.xml"); |
144 |
DataObject buildXmlDO = null; |
145 |
try { |
146 |
if (buildXml != null) buildXmlDO = DataObject.find(buildXml); |
147 |
} catch (DataObjectNotFoundException ex) { |
148 |
} |
149 |
return buildXmlDO; |
150 |
} |
151 |
|
152 |
private boolean isBuildXmlPresent() { |
153 |
return getBuildXmlDataObject() != null; |
154 |
} |
155 |
|
156 |
public boolean isBuildProjectEnabled() { |
157 |
return isBuildXmlPresent(); |
158 |
} |
159 |
|
160 |
public boolean isRebuildProjectEnabled() { |
161 |
return isBuildXmlPresent(); |
162 |
} |
163 |
|
164 |
public void buildProject() { |
165 |
try { |
166 |
new AntBuildExecutionSupportItem(getBuildXmlDataObject(), new String[]{"build"}).startRunning(); |
167 |
} catch (IOException ex) { |
168 |
Exceptions.printStackTrace(ex); |
169 |
} |
170 |
} |
171 |
|
172 |
public void rebuildProject() { |
173 |
try { |
174 |
new AntBuildExecutionSupportItem(getBuildXmlDataObject(), new String[]{"rebuild"}).startRunning(); |
175 |
} catch (IOException ex) { |
176 |
Exceptions.printStackTrace(ex); |
177 |
} |
178 |
} |
179 |
|
126 |
public abstract boolean isValid(boolean indexFileNeeded); |
180 |
public abstract boolean isValid(boolean indexFileNeeded); |
127 |
|
181 |
|
128 |
public abstract boolean isRunFileEnabled(Lookup context); |
182 |
public abstract boolean isRunFileEnabled(Lookup context); |
Lines 146-149
Link Here
|
146 |
} |
200 |
} |
147 |
return true; |
201 |
return true; |
148 |
} |
202 |
} |
|
|
203 |
|
204 |
private class AntBuildExecutionSupportItem implements BuildExecutionSupport.Item, TaskListener { |
205 |
private final AntTargetExecutor mTargetExecutor; |
206 |
private final String[] mTargets; |
207 |
private final AntProjectCookie mProjectCookie; |
208 |
private ExecutorTask mExecutorTask; |
209 |
|
210 |
AntBuildExecutionSupportItem(DataObject buildFileObject, String[] targets) { |
211 |
mProjectCookie = buildFileObject.getCookie(AntProjectCookie.class); |
212 |
mTargets = targets; |
213 |
mTargetExecutor = AntTargetExecutor.createTargetExecutor(new Env()); |
214 |
} |
215 |
|
216 |
@Override |
217 |
public String getDisplayName() { |
218 |
return "Running Ant Build"; |
219 |
} |
220 |
|
221 |
@Override |
222 |
public void repeatExecution() { |
223 |
stopRunning(); |
224 |
try { |
225 |
startRunning(); |
226 |
} catch (IOException ex) { |
227 |
Exceptions.printStackTrace(ex); |
228 |
} |
229 |
} |
230 |
|
231 |
@Override |
232 |
public boolean isRunning() { |
233 |
return (mExecutorTask == null)?false:true; |
234 |
} |
235 |
|
236 |
@Override |
237 |
public void stopRunning() { |
238 |
if (mExecutorTask != null) mExecutorTask.stop(); |
239 |
mExecutorTask.waitFinished(); |
240 |
taskFinished(mExecutorTask); |
241 |
} |
242 |
|
243 |
public void startRunning() throws IOException { |
244 |
mExecutorTask = mTargetExecutor.execute(mProjectCookie, mTargets); |
245 |
mExecutorTask.addTaskListener(this); |
246 |
BuildExecutionSupport.registerRunningItem(this); |
247 |
} |
248 |
|
249 |
@Override |
250 |
public void taskFinished(Task task) { |
251 |
mExecutorTask = null; |
252 |
BuildExecutionSupport.registerFinishedItem(this); |
253 |
} |
254 |
} |
149 |
} |
255 |
} |