Skip to content

Commit db140db

Browse files
committed
Merge branch 'nb82dev'
2 parents 362dbb8 + c43142c commit db140db

14 files changed

Lines changed: 183 additions & 261 deletions

manifest.mf

Lines changed: 1 addition & 1 deletion
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.9.4
5+
OpenIDE-Module-Specification-Version: 0.9.5
66
OpenIDE-Module-Install: org/netbeans/modules/php/wordpress/WordPressModuleInstall.class

nbproject/project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
javac.source=1.7
1+
javac.source=1.8
22
javac.compilerargs=-Xlint -Xlint:-serial
33
license.file=license.txt
44
nbm.module.author=junichi11

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

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

44+
import org.netbeans.api.annotations.common.StaticResource;
45+
4446
/**
4547
*
4648
* @author junichi11
4749
*/
4850
public final class WordPress {
4951

52+
@StaticResource
5053
public static final String WP_ICON_8 = "org/netbeans/modules/php/wordpress/resources/wordpress_icon_8.png"; // NOI18N
54+
@StaticResource
5155
public static final String WP_ICON_16 = "org/netbeans/modules/php/wordpress/resources/wordpress_icon_16.png"; // NOI18N
5256

5357
private WordPress() {

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

Lines changed: 10 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,4 @@
11
/*
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-
*//*
422
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
433
*
444
* Copyright 2013 Oracle and/or its affiliates. All rights reserved.
@@ -108,23 +68,18 @@ public void restored() {
10868
WordPressOptions options = WordPressOptions.getInstance();
10969
String wpCliPath = options.getWpCliPath();
11070
if (!StringUtils.isEmpty(wpCliPath) && options.getWpCliGetCommandsOnBoot()) {
111-
RequestProcessor.getDefault().post(new Runnable() {
112-
113-
@Override
114-
public void run() {
115-
ProgressHandle handle = ProgressHandle.createHandle(Bundle.WordPressModule_get_commands());
71+
RequestProcessor.getDefault().post(() -> {
72+
ProgressHandle handle = ProgressHandle.createHandle(Bundle.WordPressModule_get_commands());
73+
try {
74+
handle.start();
11675
try {
117-
handle.start();
118-
try {
119-
WordPressCli wpCli = WordPressCli.getDefault(false);
120-
wpCli.getCommands(false);
121-
} catch (InvalidPhpExecutableException ex) {
122-
LOGGER.log(Level.WARNING, ex.getLocalizedMessage());
123-
}
124-
125-
} finally {
126-
handle.finish();
76+
WordPressCli wpCli = WordPressCli.getDefault(false);
77+
wpCli.getCommands(false);
78+
} catch (InvalidPhpExecutableException ex) {
79+
LOGGER.log(Level.WARNING, ex.getLocalizedMessage());
12780
}
81+
} finally {
82+
handle.finish();
12883
}
12984
});
13085
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import java.util.HashSet;
4949
import java.util.Set;
5050
import java.util.concurrent.TimeUnit;
51+
import org.netbeans.api.annotations.common.StaticResource;
5152
import org.netbeans.modules.php.api.framework.BadgeIcon;
5253
import org.netbeans.modules.php.api.phpmodule.PhpModule;
5354
import org.netbeans.modules.php.api.phpmodule.PhpModuleProperties;
@@ -83,6 +84,7 @@ public class WordPressPhpProvider extends PhpFrameworkProvider {
8384

8485
private static final RequestProcessor RP = new RequestProcessor(WordPressPhpProvider.class);
8586
private static final WordPressPhpProvider INSTANCE = new WordPressPhpProvider();
87+
@StaticResource
8688
private static final String ICON_PATH = "org/netbeans/modules/php/wordpress/resources/wordpress_badge_8.png"; // NOI18N
8789
private final BadgeIcon badgeIcon;
8890
public static final Set<String> WP_DIRS = new HashSet<>();

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

Lines changed: 62 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,16 @@
5454
import java.util.List;
5555
import java.util.concurrent.ExecutionException;
5656
import java.util.concurrent.Future;
57+
import static java.util.logging.Level.FINE;
58+
import static java.util.logging.Level.INFO;
5759
import java.util.logging.Logger;
60+
import static java.util.logging.Level.WARNING;
61+
import java.util.regex.Pattern;
5862
import org.netbeans.api.extexecution.ExecutionDescriptor;
5963
import org.netbeans.api.extexecution.base.input.InputProcessor;
6064
import org.netbeans.api.extexecution.base.input.InputProcessors;
6165
import org.netbeans.api.extexecution.base.input.LineProcessor;
66+
import org.netbeans.api.progress.ProgressHandle;
6267
import org.netbeans.modules.php.api.executable.InvalidPhpExecutableException;
6368
import org.netbeans.modules.php.api.executable.PhpExecutable;
6469
import org.netbeans.modules.php.api.executable.PhpExecutableValidator;
@@ -109,18 +114,24 @@ public final class WordPressCli {
109114

110115
// XXX default?
111116
private final List<String> DEFAULT_PARAMS = Collections.emptyList();
112-
private static final List<FrameworkCommand> commandsCache = new ArrayList<>();
117+
private static final List<FrameworkCommand> COMMANDS_CACHE = new ArrayList<>();
118+
119+
private static final Pattern WHITESPACES_PATTERN = Pattern.compile(" +"); // NOI18N
113120

114121
private WordPressCli(String wpCliPath) {
115122
this.wpCliPath = wpCliPath;
116123
}
117124

125+
public static WordPressCli getDefault(boolean warn) throws InvalidPhpExecutableException {
126+
String wpCliPath = WordPressOptions.getInstance().getWpCliPath();
127+
return newInstance(wpCliPath, warn);
128+
}
129+
118130
@NbBundle.Messages({
119131
"# {0} - error message",
120132
"WordPressCli.invalid.wpcli.script=<html>wp-cli is not valid.<br>({0})"
121133
})
122-
public static WordPressCli getDefault(boolean warn) throws InvalidPhpExecutableException {
123-
String wpCliPath = WordPressOptions.getInstance().getWpCliPath();
134+
public static WordPressCli newInstance(String wpCliPath, boolean warn) throws InvalidPhpExecutableException {
124135
String error = validate(wpCliPath);
125136
if (error == null) {
126137
return new WordPressCli(wpCliPath);
@@ -229,7 +240,7 @@ public String getVersion() {
229240
} catch (InterruptedException ex) {
230241
Thread.currentThread().interrupt();
231242
} catch (ExecutionException ex) {
232-
Exceptions.printStackTrace(ex);
243+
LOGGER.log(WARNING, null, ex);
233244
}
234245
return helpLineProcessor.getHelp();
235246
}
@@ -318,10 +329,10 @@ public String getHelp(List<String> commands) {
318329
*/
319330
@NbBundle.Messages("WordPressCli.commands.empty=Please check whether config file and DB settings exist.")
320331
public List<FrameworkCommand> getCommands(boolean isForce) {
321-
if (!isForce && !commandsCache.isEmpty()) {
322-
return commandsCache;
332+
if (!isForce && !COMMANDS_CACHE.isEmpty()) {
333+
return COMMANDS_CACHE;
323334
}
324-
commandsCache.clear();
335+
COMMANDS_CACHE.clear();
325336
if (!isForce) {
326337
// exists xml?
327338
String commandList = WordPressOptions.getInstance().getWpCliCommandList();
@@ -330,53 +341,61 @@ public List<FrameworkCommand> getCommands(boolean isForce) {
330341
File temp = File.createTempFile("nb-wpcli-tmp", ".xml"); // NOI18N
331342
try {
332343
FileOutputStream outputStream = new FileOutputStream(temp);
333-
PrintWriter pw = new PrintWriter(new OutputStreamWriter(outputStream, "UTF-8")); // NOI18N
334-
try {
344+
try (PrintWriter pw = new PrintWriter(new OutputStreamWriter(outputStream, "UTF-8"))) { // NOI18N
335345
pw.println(commandList);
336-
} finally {
337-
pw.close();
338346
}
339347

340348
// parse
341349
FileInputStream fileInputStream = new FileInputStream(temp);
342350
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8"); // NOI18N
343-
WordPressCliCommandsXmlParser.parse(inputStreamReader, commandsCache);
351+
WordPressCliCommandsXmlParser.parse(inputStreamReader, COMMANDS_CACHE);
344352
} finally {
345353
temp.deleteOnExit();
346354
}
347355
} catch (IOException ex) {
348-
Exceptions.printStackTrace(ex);
356+
LOGGER.log(WARNING, null, ex);
349357
}
350-
if (!commandsCache.isEmpty()) {
351-
return commandsCache;
358+
if (!COMMANDS_CACHE.isEmpty()) {
359+
return COMMANDS_CACHE;
352360
}
353361
}
354362
}
355363

356364
// update
357365
updateCommands();
358366

359-
return commandsCache;
367+
return COMMANDS_CACHE;
360368
}
361369

370+
@NbBundle.Messages("WordPressCli.update.command.progress=Updating wp-cli commands...")
362371
public void updateCommands() {
363-
commandsCache.clear();
364-
getCommands(Collections.<String>emptyList(), commandsCache);
365-
if (commandsCache.isEmpty()) {
366-
NotifyDescriptor.Message message = new NotifyDescriptor.Message(Bundle.WordPressCli_commands_empty(), NotifyDescriptor.WARNING_MESSAGE);
367-
DialogDisplayer.getDefault().notify(message);
368-
} else {
369-
WordPressCliCommandListXmlBuilder builder = new WordPressCliCommandListXmlBuilder();
370-
builder.build(commandsCache);
371-
String commadlist = builder.asText();
372-
if (!StringUtils.isEmpty(commadlist)) {
373-
WordPressOptions.getInstance().setWpCliCommandList(commadlist);
372+
ProgressHandle handle = ProgressHandle.createHandle(Bundle.WordPressCli_update_command_progress());
373+
try {
374+
handle.start();
375+
long startTime = System.currentTimeMillis();
376+
COMMANDS_CACHE.clear();
377+
getCommands(Collections.<String>emptyList(), COMMANDS_CACHE, handle);
378+
if (COMMANDS_CACHE.isEmpty()) {
379+
NotifyDescriptor.Message message = new NotifyDescriptor.Message(Bundle.WordPressCli_commands_empty(), NotifyDescriptor.WARNING_MESSAGE);
380+
DialogDisplayer.getDefault().notify(message);
381+
} else {
382+
WordPressCliCommandListXmlBuilder builder = new WordPressCliCommandListXmlBuilder();
383+
builder.build(COMMANDS_CACHE);
384+
String commadlist = builder.asText();
385+
if (!StringUtils.isEmpty(commadlist)) {
386+
WordPressOptions.getInstance().setWpCliCommandList(commadlist);
387+
}
374388
}
389+
long endTime = System.currentTimeMillis();
390+
LOGGER.log(INFO, "Update Commands: took {0}ms", endTime - startTime); // NOI18N
391+
LOGGER.log(INFO, "{0} wp-cli commands.", COMMANDS_CACHE.size()); // NOI18N
392+
} finally {
393+
handle.finish();
375394
}
376395
}
377396

378397
// XXX get help later?
379-
private void getCommands(List<String> subcommands, List<FrameworkCommand> commands) {
398+
private void getCommands(List<String> subcommands, List<FrameworkCommand> commands, ProgressHandle handle) {
380399
ArrayList<String> params = new ArrayList<>(subcommands.size() + 1);
381400
params.add(HELP_COMMAND);
382401
params.addAll(subcommands);
@@ -389,14 +408,18 @@ private void getCommands(List<String> subcommands, List<FrameworkCommand> comman
389408
result.get();
390409
}
391410
} catch (InterruptedException ex) {
392-
Exceptions.printStackTrace(ex);
411+
Thread.currentThread().interrupt();
393412
} catch (ExecutionException ex) {
394-
Exceptions.printStackTrace(ex);
413+
LOGGER.log(WARNING, null, ex);
395414
}
396415
List<String> lines = helpLineProcessor.asLines();
397416

398417
boolean isSubcommands = false;
399418
boolean isFirstEmpty = false;
419+
LOGGER.log(FINE, "{0} WP Command", StringUtils.implode(subcommands, " ")); // NOI18N
420+
if (handle != null) {
421+
handle.progress(StringUtils.implode(subcommands, " ")); // NOI18N
422+
}
400423
for (String line : lines) {
401424
if (isSubcommands) {
402425
if (StringUtils.isEmpty(line)) {
@@ -406,8 +429,13 @@ private void getCommands(List<String> subcommands, List<FrameworkCommand> comman
406429
isFirstEmpty = true;
407430
continue;
408431
}
432+
// XXX just ignore
433+
// in the case of long description
434+
if (line.startsWith(" ")) { // NOI18N
435+
continue;
436+
}
409437
line = line.trim();
410-
line = line.replaceAll(" +", " "); // NOI18N
438+
line = WHITESPACES_PATTERN.matcher(line).replaceAll(" "); // NOI18N
411439
int indexOf = line.indexOf(" "); // NOI18N
412440
if (indexOf == -1) {
413441
continue;
@@ -422,8 +450,8 @@ private void getCommands(List<String> subcommands, List<FrameworkCommand> comman
422450
String help = getHelp(nextSubcommands);
423451
commands.add(new WordPressCliCommand(nextSubcommands.toArray(new String[]{}), description, help)); // NOI18N
424452

425-
// recursive
426-
getCommands(nextSubcommands, commands);
453+
// get commands recursively
454+
getCommands(nextSubcommands, commands, handle);
427455
}
428456

429457
if (line.toLowerCase().startsWith("subcommands")) { // NOI18N
@@ -537,12 +565,7 @@ private List<String> getAllParameters(List<String> parameters) {
537565
* @return InputProcessorFactory
538566
*/
539567
private ExecutionDescriptor.InputProcessorFactory2 getOutputProcessorFactory(final LineProcessor lineProcessor) {
540-
return new ExecutionDescriptor.InputProcessorFactory2() {
541-
@Override
542-
public InputProcessor newInputProcessor(InputProcessor defaultProcessor) {
543-
return InputProcessors.ansiStripping(InputProcessors.bridge(lineProcessor));
544-
}
545-
};
568+
return (InputProcessor defaultProcessor) -> InputProcessors.ansiStripping(InputProcessors.bridge(lineProcessor));
546569
}
547570

548571
@NbBundle.Messages({

src/org/netbeans/modules/php/wordpress/ui/actions/CreateChildThemeAction.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,21 +135,17 @@ protected void actionPerformed(PhpModule phpModule) {
135135
Collections.sort(themes);
136136

137137
// show dialog
138-
SwingUtilities.invokeLater(new Runnable() {
139-
140-
@Override
141-
public void run() {
142-
getDescriptor().setValid(false);
143-
DialogDisplayer displayer = DialogDisplayer.getDefault();
144-
if (displayer.notify(getDescriptor()) == DialogDescriptor.OK_OPTION) {
145-
try {
146-
createChildTheme(themesDirectory);
147-
} catch (IOException ex) {
148-
Exceptions.printStackTrace(ex);
149-
}
138+
SwingUtilities.invokeLater(() -> {
139+
getDescriptor().setValid(false);
140+
DialogDisplayer displayer = DialogDisplayer.getDefault();
141+
if (displayer.notify(getDescriptor()) == DialogDescriptor.OK_OPTION) {
142+
try {
143+
createChildTheme(themesDirectory);
144+
} catch (IOException ex) {
145+
Exceptions.printStackTrace(ex);
150146
}
151-
clear();
152147
}
148+
clear();
153149
});
154150
}
155151

src/org/netbeans/modules/php/wordpress/ui/actions/CreateMinimumBlankThemeAction.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,14 @@ protected void actionPerformed(PhpModule phpModule) {
128128
);
129129

130130
// add ChangeListener
131-
ChangeListener changeListener = new ChangeListener() {
132-
@Override
133-
public void stateChanged(ChangeEvent e) {
134-
String themeDirectoryName = panel.getThemeDirectoryName();
135-
boolean existsDirectory = themes.contains(themeDirectoryName);
136-
dialogDescriptor.setValid(!existsDirectory);
137-
if (existsDirectory) {
138-
panel.setErrorMessage(Bundle.CreateMinimumBlankThemeAction_existing_directoryName());
139-
} else {
140-
panel.setErrorMessage(" "); // NOI18N
141-
}
131+
ChangeListener changeListener = (ChangeEvent e) -> {
132+
String themeDirectoryName = panel.getThemeDirectoryName();
133+
boolean existsDirectory = themes.contains(themeDirectoryName);
134+
dialogDescriptor.setValid(!existsDirectory);
135+
if (existsDirectory) {
136+
panel.setErrorMessage(Bundle.CreateMinimumBlankThemeAction_existing_directoryName());
137+
} else {
138+
panel.setErrorMessage(" "); // NOI18N
142139
}
143140
};
144141
panel.addChangeListener(changeListener);

0 commit comments

Comments
 (0)