Skip to content

Commit 064b212

Browse files
committed
Merge branch 'nb74dev'
2 parents 84fd83e + 08e8c39 commit 064b212

16 files changed

Lines changed: 750 additions & 107 deletions

manifest.mf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ Manifest-Version: 1.0
22
OpenIDE-Module: org.netbeans.modules.php.wordpress
33
OpenIDE-Module-Layer: org/netbeans/modules/php/wordpress/resources/layer.xml
44
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/php/wordpress/Bundle.properties
5-
OpenIDE-Module-Specification-Version: 0.6.0
6-
5+
OpenIDE-Module-Specification-Version: 0.6.1
6+
OpenIDE-Module-Install: org/netbeans/modules/php/wordpress/WordPressModule.class

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=c16cf6ec
1+
build.xml.data.CRC32=f6605689
22
build.xml.script.CRC32=f6cbff90
33
build.xml.stylesheet.CRC32=a56c6a5b@2.62.1
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=c16cf6ec
6+
nbproject/build-impl.xml.data.CRC32=f6605689
77
nbproject/build-impl.xml.script.CRC32=bfa38a5f
88
nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.62.1

nbproject/project.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,14 @@
214214
<specification-version>7.44.1</specification-version>
215215
</run-dependency>
216216
</dependency>
217+
<dependency>
218+
<code-name-base>org.openide.modules</code-name-base>
219+
<build-prerequisite/>
220+
<compile-dependency/>
221+
<run-dependency>
222+
<specification-version>7.39.1</specification-version>
223+
</run-dependency>
224+
</dependency>
217225
<dependency>
218226
<code-name-base>org.openide.nodes</code-name-base>
219227
<build-prerequisite/>
@@ -222,6 +230,14 @@
222230
<specification-version>7.33.1</specification-version>
223231
</run-dependency>
224232
</dependency>
233+
<dependency>
234+
<code-name-base>org.openide.text</code-name-base>
235+
<build-prerequisite/>
236+
<compile-dependency/>
237+
<run-dependency>
238+
<specification-version>6.58.1</specification-version>
239+
</run-dependency>
240+
</dependency>
225241
<dependency>
226242
<code-name-base>org.openide.util</code-name-base>
227243
<build-prerequisite/>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
OpenIDE-Module-Display-Category=PHP
22
OpenIDE-Module-Long-Description=\
33
Support for WordPress.This plugin provides the following features.\n\
4-
<ul>\n<li>New Wordpress Project wizard</li>\n<li>Create theme(Underscores, Barebones) action</li>\n<li>Create plugin action</li>\n<li>Hyperlink navigation and code completion for filter and action function</li>\n<li>Shortcut nodes for theme and plugin directory</li>\n<li>Zip compress for your custom theme and plugin directory</li>\n</ul>
4+
<ul>\n<li>New Wordpress Project wizard</li>\n<li>Create theme(Underscores, Barebones) action</li>\n<li>Create plugin action</li>\n<li>Hyperlink navigation and code completion for filter and action function</li>\n<li>Shortcut nodes for theme and plugin directory</li>\n<li>Zip compress for your custom theme and plugin directory</li>\n<li>wp-cli support</li>\n</ul>
55
OpenIDE-Module-Name=PHP WordPress Blog/CMS
66
OpenIDE-Module-Short-Description=Support for WordPress
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7+
* Other names may be trademarks of their respective owners.
8+
*
9+
* The contents of this file are subject to the terms of either the GNU
10+
* General Public License Version 2 only ("GPL") or the Common
11+
* Development and Distribution License("CDDL") (collectively, the
12+
* "License"). You may not use this file except in compliance with the
13+
* License. You can obtain a copy of the License at
14+
* http://www.netbeans.org/cddl-gplv2.html
15+
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16+
* specific language governing permissions and limitations under the
17+
* License. When distributing the software, include this License Header
18+
* Notice in each file and include the License file at
19+
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
20+
* particular file as subject to the "Classpath" exception as provided
21+
* by Oracle in the GPL Version 2 section of the License file that
22+
* accompanied this code. If applicable, add the following below the
23+
* License Header, with the fields enclosed by brackets [] replaced by
24+
* your own identifying information:
25+
* "Portions Copyrighted [year] [name of copyright owner]"
26+
*
27+
* If you wish your version of this file to be governed by only the CDDL
28+
* or only the GPL Version 2, indicate your decision by adding
29+
* "[Contributor] elects to include this software in this distribution
30+
* under the [CDDL or GPL Version 2] license." If you do not indicate a
31+
* single choice of license, a recipient has the option to distribute
32+
* your version of this file under either the CDDL, the GPL Version 2 or
33+
* to extend the choice of license to its licensees as provided above.
34+
* However, if you add GPL Version 2 code and therefore, elected the GPL
35+
* Version 2 license, then the option applies only if the new code is
36+
* made subject to such option by the copyright holder.
37+
*
38+
* Contributor(s):
39+
*
40+
* Portions Copyrighted 2013 Sun Microsystems, Inc.
41+
*/
42+
package org.netbeans.modules.php.wordpress;
43+
44+
import java.util.logging.Level;
45+
import java.util.logging.Logger;
46+
import org.netbeans.api.progress.ProgressHandle;
47+
import org.netbeans.api.progress.ProgressHandleFactory;
48+
import org.netbeans.modules.php.api.executable.InvalidPhpExecutableException;
49+
import org.netbeans.modules.php.api.util.StringUtils;
50+
import org.netbeans.modules.php.wordpress.commands.WordPressCli;
51+
import org.netbeans.modules.php.wordpress.ui.options.WordPressOptions;
52+
import org.openide.modules.ModuleInstall;
53+
import org.openide.util.NbBundle;
54+
import org.openide.util.RequestProcessor;
55+
56+
/**
57+
*
58+
* @author junichi11
59+
*/
60+
public class WordPressModule extends ModuleInstall {
61+
62+
private static final Logger LOGGER = Logger.getLogger(WordPressModule.class.getName());
63+
64+
@NbBundle.Messages("WordPressModule.get.commands=Getting wp-cli commands...")
65+
@Override
66+
public void restored() {
67+
super.restored();
68+
WordPressOptions options = WordPressOptions.getInstance();
69+
String wpCliPath = options.getWpCliPath();
70+
if (!StringUtils.isEmpty(wpCliPath) && options.getWpCliGetCommandsOnBoot()) {
71+
RequestProcessor.getDefault().post(new Runnable() {
72+
73+
@Override
74+
public void run() {
75+
ProgressHandle handle = ProgressHandleFactory.createHandle(Bundle.WordPressModule_get_commands());
76+
try {
77+
handle.start();
78+
try {
79+
WordPressCli wpCli = WordPressCli.getDefault(false);
80+
wpCli.getCommands(false);
81+
} catch (InvalidPhpExecutableException ex) {
82+
LOGGER.log(Level.WARNING, ex.getLocalizedMessage());
83+
}
84+
85+
} finally {
86+
handle.finish();
87+
}
88+
}
89+
});
90+
}
91+
}
92+
93+
}

src/org/netbeans/modules/php/wordpress/WordPressPhpModuleExtender.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ public Set<FileObject> extend(PhpModule pm) throws ExtendingException {
240240
} catch (ExecutionException ex) {
241241
throw new ExtendingException(ex.getLocalizedMessage());
242242
}
243+
// #18
244+
sourceDirectory.refresh(true);
243245
} else {
244246
// do nothing
245247
return Collections.emptySet();

src/org/netbeans/modules/php/wordpress/commands/WordPressCli.java

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@
4141
*/
4242
package org.netbeans.modules.php.wordpress.commands;
4343

44+
import java.io.File;
45+
import java.io.FileInputStream;
46+
import java.io.FileOutputStream;
47+
import java.io.IOException;
48+
import java.io.InputStreamReader;
49+
import java.io.OutputStreamWriter;
50+
import java.io.PrintWriter;
4451
import java.util.ArrayList;
4552
import java.util.Arrays;
4653
import java.util.Collections;
@@ -93,6 +100,7 @@ public final class WordPressCli {
93100

94101
// XXX default?
95102
private final List<String> DEFAULT_PARAMS = Collections.emptyList();
103+
private static final List<FrameworkCommand> commandsCache = new ArrayList<FrameworkCommand>();
96104

97105
private WordPressCli(String wpCliPath) {
98106
this.wpCliPath = wpCliPath;
@@ -162,18 +170,17 @@ public String getVersion() {
162170
/**
163171
* Get help.
164172
*
165-
* @param phpModule
166173
* @param commands
167174
* @return help for command
168175
*/
169-
public String getHelp(PhpModule phpModule, List<String> commands) {
176+
public String getHelp(List<String> commands) {
170177
List<String> params = new ArrayList<String>(commands.size() + 1);
171178
params.addAll(commands);
172179
params.add(HELP_PARAM);
173180

174181
HelpLineProcessor helpLineProcessor = new HelpLineProcessor();
175182

176-
Future<Integer> result = getExecutable(phpModule)
183+
Future<Integer> result = createExecutable()
177184
.additionalParameters(params)
178185
.run(getSilentDescriptor(), getOutputProcessorFactory(helpLineProcessor));
179186
try {
@@ -191,27 +198,74 @@ public String getHelp(PhpModule phpModule, List<String> commands) {
191198
/**
192199
* Get commands from help. Also get subcommands, so, take a little time.
193200
*
194-
* @param phpModule
201+
* @param isForce clear cache
195202
* @return commands
196203
*/
197204
@NbBundle.Messages("WordPressCli.commands.empty=Please check whether config file and DB settings exist.")
198-
public List<FrameworkCommand> getCommands(PhpModule phpModule) {
199-
List<FrameworkCommand> commands = new ArrayList<FrameworkCommand>();
200-
getCommands(phpModule, Collections.<String>emptyList(), commands);
201-
if (commands.isEmpty()) {
205+
public List<FrameworkCommand> getCommands(boolean isForce) {
206+
if (!isForce && !commandsCache.isEmpty()) {
207+
return commandsCache;
208+
}
209+
commandsCache.clear();
210+
if (!isForce) {
211+
// exists xml?
212+
String commandList = WordPressOptions.getInstance().getWpCliCommandList();
213+
if (!StringUtils.isEmpty(commandList)) {
214+
try {
215+
File temp = File.createTempFile("nb-wpcli-tmp", ".xml"); // NOI18N
216+
try {
217+
FileOutputStream outputStream = new FileOutputStream(temp);
218+
PrintWriter pw = new PrintWriter(new OutputStreamWriter(outputStream, "UTF-8")); // NOI18N
219+
try {
220+
pw.println(commandList);
221+
} finally {
222+
pw.close();
223+
}
224+
225+
// parse
226+
FileInputStream fileInputStream = new FileInputStream(temp);
227+
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8"); // NOI18N
228+
WordPressCliCommandsXmlParser.parse(inputStreamReader, commandsCache);
229+
} finally {
230+
temp.deleteOnExit();
231+
}
232+
} catch (IOException ex) {
233+
Exceptions.printStackTrace(ex);
234+
}
235+
if (!commandsCache.isEmpty()) {
236+
return commandsCache;
237+
}
238+
}
239+
}
240+
241+
// update
242+
updateCommands();
243+
244+
return commandsCache;
245+
}
246+
247+
public void updateCommands() {
248+
getCommands(Collections.<String>emptyList(), commandsCache);
249+
if (commandsCache.isEmpty()) {
202250
NotifyDescriptor.Message message = new NotifyDescriptor.Message(Bundle.WordPressCli_commands_empty(), NotifyDescriptor.WARNING_MESSAGE);
203251
DialogDisplayer.getDefault().notify(message);
252+
} else {
253+
WordPressCliCommandListXmlBuilder builder = new WordPressCliCommandListXmlBuilder();
254+
builder.build(commandsCache);
255+
String commadlist = builder.asText();
256+
if (!StringUtils.isEmpty(commadlist)) {
257+
WordPressOptions.getInstance().setWpCliCommandList(commadlist);
258+
}
204259
}
205-
return commands;
206260
}
207261

208262
// XXX get help later?
209-
private void getCommands(PhpModule phpModule, List<String> subcommands, List<FrameworkCommand> commands) {
263+
private void getCommands(List<String> subcommands, List<FrameworkCommand> commands) {
210264
ArrayList<String> params = new ArrayList<String>(subcommands.size() + 1);
211265
params.add(HELP_COMMAND);
212266
params.addAll(subcommands);
213267
HelpLineProcessor helpLineProcessor = new HelpLineProcessor();
214-
Future<Integer> result = getExecutable(phpModule)
268+
Future<Integer> result = createExecutable()
215269
.additionalParameters(params)
216270
.run(getSilentDescriptor(), getOutputProcessorFactory(helpLineProcessor));
217271
try {
@@ -249,11 +303,11 @@ private void getCommands(PhpModule phpModule, List<String> subcommands, List<Fra
249303
ArrayList<String> nextSubcommands = new ArrayList<String>(subcommands.size() + 1);
250304
nextSubcommands.addAll(subcommands);
251305
nextSubcommands.add(subcommand);
252-
String help = getHelp(phpModule, nextSubcommands);
306+
String help = getHelp(nextSubcommands);
253307
commands.add(new WordPressCliCommand(nextSubcommands.toArray(new String[]{}), description, help)); // NOI18N
254308

255309
// recursive
256-
getCommands(phpModule, nextSubcommands, commands);
310+
getCommands(nextSubcommands, commands);
257311
}
258312

259313
if (line.toLowerCase().startsWith("subcommands")) { // NOI18N
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7+
* Other names may be trademarks of their respective owners.
8+
*
9+
* The contents of this file are subject to the terms of either the GNU
10+
* General Public License Version 2 only ("GPL") or the Common
11+
* Development and Distribution License("CDDL") (collectively, the
12+
* "License"). You may not use this file except in compliance with the
13+
* License. You can obtain a copy of the License at
14+
* http://www.netbeans.org/cddl-gplv2.html
15+
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16+
* specific language governing permissions and limitations under the
17+
* License. When distributing the software, include this License Header
18+
* Notice in each file and include the License file at
19+
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
20+
* particular file as subject to the "Classpath" exception as provided
21+
* by Oracle in the GPL Version 2 section of the License file that
22+
* accompanied this code. If applicable, add the following below the
23+
* License Header, with the fields enclosed by brackets [] replaced by
24+
* your own identifying information:
25+
* "Portions Copyrighted [year] [name of copyright owner]"
26+
*
27+
* If you wish your version of this file to be governed by only the CDDL
28+
* or only the GPL Version 2, indicate your decision by adding
29+
* "[Contributor] elects to include this software in this distribution
30+
* under the [CDDL or GPL Version 2] license." If you do not indicate a
31+
* single choice of license, a recipient has the option to distribute
32+
* your version of this file under either the CDDL, the GPL Version 2 or
33+
* to extend the choice of license to its licensees as provided above.
34+
* However, if you add GPL Version 2 code and therefore, elected the GPL
35+
* Version 2 license, then the option applies only if the new code is
36+
* made subject to such option by the copyright holder.
37+
*
38+
* Contributor(s):
39+
*
40+
* Portions Copyrighted 2013 Sun Microsystems, Inc.
41+
*/
42+
package org.netbeans.modules.php.wordpress.commands;
43+
44+
import java.util.List;
45+
import org.netbeans.modules.php.spi.framework.commands.FrameworkCommand;
46+
47+
/**
48+
*
49+
* @author junichi11
50+
*/
51+
public interface WordPressCliCommandListBuilder {
52+
53+
public void build(List<FrameworkCommand> commands);
54+
55+
public String asText();
56+
57+
}

0 commit comments

Comments
 (0)