Skip to content

Commit d87c656

Browse files
committed
Run Bake action added
1 parent 67cee86 commit d87c656

File tree

10 files changed

+209
-3
lines changed

10 files changed

+209
-3
lines changed

manifest.mf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Manifest-Version: 1.0
22
OpenIDE-Module: org.cakephp.netbeans
3+
OpenIDE-Module-Layer: org/cakephp/netbeans/resources/layer.xml
34
OpenIDE-Module-Localizing-Bundle: org/cakephp/netbeans/resources/Bundle.properties
45
OpenIDE-Module-Specification-Version: 0.1

nbproject/genfiles.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
build.xml.data.CRC32=dd468412
1+
build.xml.data.CRC32=9138ee77
22
build.xml.script.CRC32=509b06b8
33
build.xml.stylesheet.CRC32=[email protected]
44
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
55
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
6-
nbproject/build-impl.xml.data.CRC32=dd468412
6+
nbproject/build-impl.xml.data.CRC32=9138ee77
77
nbproject/build-impl.xml.script.CRC32=66d0a2dd
88
nbproject/build-impl.xml.stylesheet.CRC32=[email protected]

nbproject/project.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
<code-name-base>org.cakephp.netbeans</code-name-base>
77
<standalone/>
88
<module-dependencies>
9+
<dependency>
10+
<code-name-base>org.netbeans.modules.extexecution</code-name-base>
11+
<build-prerequisite/>
12+
<compile-dependency/>
13+
<run-dependency>
14+
<release-version>2</release-version>
15+
<specification-version>1.22</specification-version>
16+
</run-dependency>
17+
</dependency>
918
<dependency>
1019
<code-name-base>org.netbeans.modules.php.api.phpmodule</code-name-base>
1120
<build-prerequisite/>
@@ -14,6 +23,14 @@
1423
<specification-version>1.41</specification-version>
1524
</run-dependency>
1625
</dependency>
26+
<dependency>
27+
<code-name-base>org.openide.dialogs</code-name-base>
28+
<build-prerequisite/>
29+
<compile-dependency/>
30+
<run-dependency>
31+
<specification-version>7.16</specification-version>
32+
</run-dependency>
33+
</dependency>
1734
<dependency>
1835
<code-name-base>org.openide.filesystems</code-name-base>
1936
<build-prerequisite/>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
# TODO: add license
22

3+
# provider
34
LBL_CakePhpFramework=Cake PHP Web Framework
45
LBL_CakePhpDescription=TODO: provide better description
6+
7+
# actions
8+
LBL_MenuName=CakePHP
9+
10+
# script
11+
MSG_CakeNotFound=Cake Tool not found
12+
LBL_CakeTool=Cake Tool
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* TODO: add license
3+
*/
4+
5+
package org.cakephp.netbeans;
6+
7+
import java.util.Collections;
8+
import java.util.List;
9+
import javax.swing.Action;
10+
import org.cakephp.netbeans.ui.actions.RunBakeAction;
11+
import org.netbeans.modules.php.spi.phpmodule.PhpModuleActionsExtender;
12+
import org.openide.util.NbBundle;
13+
14+
public class CakePhpActionsExtender extends PhpModuleActionsExtender {
15+
private static final List<Action> ACTIONS = Collections.<Action>singletonList(RunBakeAction.getInstance());
16+
17+
@Override
18+
public String getMenuName() {
19+
return NbBundle.getMessage(CakePhpActionsExtender.class, "LBL_MenuName");
20+
}
21+
22+
@Override
23+
public List<? extends Action> getActions() {
24+
return ACTIONS;
25+
}
26+
}

src/org/cakephp/netbeans/CakePhpFrameworkProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public PhpModuleProperties getPhpModuleProperties(PhpModule phpModule) {
9898

9999
@Override
100100
public PhpModuleActionsExtender getActionsExtender(PhpModule phpModule) {
101-
return null;
101+
return new CakePhpActionsExtender();
102102
}
103103

104104
@Override
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* TODO: add license
3+
*/
4+
5+
package org.cakephp.netbeans;
6+
7+
import org.netbeans.api.extexecution.ExecutionDescriptor;
8+
import org.netbeans.api.extexecution.ExternalProcessBuilder;
9+
import org.netbeans.modules.php.api.phpmodule.PhpModule;
10+
import org.netbeans.modules.php.api.phpmodule.PhpProgram;
11+
import org.netbeans.modules.php.api.util.FileUtils;
12+
import org.openide.filesystems.FileObject;
13+
import org.openide.filesystems.FileUtil;
14+
import org.openide.util.NbBundle;
15+
16+
public class CakeScript extends PhpProgram {
17+
public static final String SCRIPT_NAME = "cake"; // NOI18N
18+
public static final String SCRIPT_NAME_LONG = SCRIPT_NAME + FileUtils.getScriptExtension(true);
19+
20+
private static final String SCRIPT_DIRECTORY = "cake/console/"; // NOI18N
21+
private static final String CMD_BAKE = "bake"; // NOI18N
22+
23+
private final PhpModule phpModule;
24+
25+
private CakeScript(String command) {
26+
this(command, null);
27+
}
28+
29+
private CakeScript(String command, PhpModule phpModule) {
30+
super(command);
31+
this.phpModule = phpModule;
32+
}
33+
34+
/**
35+
* Get the project specific, <b>valid only</b> Cake script. If not found, the {@link InvalidPhpProgramException} is thrown.
36+
* @param phpModule PHP module for which Cake script is taken
37+
* @return the project specific, <b>valid only</b> Cake script
38+
* @throws InvalidPhpProgramException if Zend script is not valid or missing completely
39+
*/
40+
public static CakeScript forPhpModule(PhpModule phpModule) throws InvalidPhpProgramException {
41+
FileObject sourceDirectory = phpModule.getSourceDirectory();
42+
43+
// locate
44+
FileObject cake = sourceDirectory.getFileObject(SCRIPT_DIRECTORY + SCRIPT_NAME);
45+
if (cake == null) {
46+
cake = sourceDirectory.getFileObject(SCRIPT_DIRECTORY + SCRIPT_NAME_LONG);
47+
}
48+
if (cake == null) {
49+
throw new InvalidPhpProgramException(NbBundle.getMessage(CakeScript.class, "MSG_CakeNotFound"));
50+
}
51+
52+
// validate
53+
String cakePath = FileUtil.toFile(cake).getAbsolutePath();
54+
String error = validate(cakePath);
55+
if (error != null) {
56+
throw new InvalidPhpProgramException(error);
57+
}
58+
return new CakeScript(cakePath, phpModule);
59+
}
60+
61+
@Override
62+
public String validate() {
63+
return FileUtils.validateScript(getProgram(), NbBundle.getMessage(CakeScript.class, "LBL_CakeTool"));
64+
}
65+
66+
public static String validate(String command) {
67+
return new CakeScript(command).validate();
68+
}
69+
70+
// TODO: later, run it via FrameworkCommandSupport
71+
public void runBake() {
72+
ExecutionDescriptor executionDescriptor = getExecutionDescriptor()
73+
.outProcessorFactory(ANSI_STRIPPING_FACTORY)
74+
.errProcessorFactory(ANSI_STRIPPING_FACTORY);
75+
76+
ExternalProcessBuilder processBuilder = getProcessBuilder()
77+
.addArgument(CMD_BAKE);
78+
assert phpModule != null;
79+
if (phpModule != null) {
80+
processBuilder = processBuilder
81+
.workingDirectory(FileUtil.toFile(phpModule.getSourceDirectory()));
82+
}
83+
executeLater(processBuilder, executionDescriptor, CMD_BAKE);
84+
}
85+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
TODO: add license
4+
-->
5+
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN" "http://www.netbeans.org/dtds/filesystem-1_2.dtd">
6+
<filesystem>
7+
<folder name="Actions">
8+
<folder name="PHP">
9+
<file name="org-cakephp-netbeans-ui-actions-RunBakeAction.instance">
10+
<attr name="instanceCreate" methodvalue="org.cakephp.netbeans.ui.actions.RunBakeAction.getInstance"/>
11+
</file>
12+
</folder>
13+
</folder>
14+
</filesystem>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# TODO: add license
2+
3+
# bake
4+
LBL_CakePhpAction=CakePHP: {0}
5+
LBL_RunBake=Bake...
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* TODO: add license
3+
*/
4+
5+
package org.cakephp.netbeans.ui.actions;
6+
7+
import org.cakephp.netbeans.CakePhpFrameworkProvider;
8+
import org.cakephp.netbeans.CakeScript;
9+
import org.netbeans.modules.php.api.phpmodule.PhpModule;
10+
import org.netbeans.modules.php.api.phpmodule.PhpProgram.InvalidPhpProgramException;
11+
import org.netbeans.modules.php.spi.actions.BaseAction;
12+
import org.openide.DialogDisplayer;
13+
import org.openide.NotifyDescriptor;
14+
import org.openide.util.NbBundle;
15+
16+
public final class RunBakeAction extends BaseAction {
17+
private static final long serialVersionUID = 534878564698977L;
18+
private static final RunBakeAction INSTANCE = new RunBakeAction();
19+
20+
private RunBakeAction() {
21+
}
22+
23+
public static RunBakeAction getInstance() {
24+
return INSTANCE;
25+
}
26+
27+
@Override
28+
public void actionPerformed(PhpModule phpModule) {
29+
if (!CakePhpFrameworkProvider.getInstance().isInPhpModule(phpModule)) {
30+
// called via shortcut
31+
return;
32+
}
33+
try {
34+
CakeScript.forPhpModule(phpModule).runBake();
35+
} catch (InvalidPhpProgramException ex) {
36+
NotifyDescriptor descriptor = new NotifyDescriptor.Message(ex.getLocalizedMessage(), NotifyDescriptor.ERROR_MESSAGE);
37+
DialogDisplayer.getDefault().notifyLater(descriptor);
38+
}
39+
}
40+
41+
@Override
42+
protected String getPureName() {
43+
return NbBundle.getMessage(RunBakeAction.class, "LBL_RunBake");
44+
}
45+
46+
@Override
47+
protected String getFullName() {
48+
return NbBundle.getMessage(RunBakeAction.class, "LBL_CakePhpAction", getPureName());
49+
}
50+
}

0 commit comments

Comments
 (0)