Skip to content

Commit d3cc7d7

Browse files
committed
Merge branch 'nb80dev'
2 parents d593226 + 6b722d1 commit d3cc7d7

9 files changed

Lines changed: 212 additions & 70 deletions

File tree

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.7.3
5+
OpenIDE-Module-Specification-Version: 0.7.4
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.6
1+
javac.source=1.7
22
javac.compilerargs=-Xlint -Xlint:-serial
33
license.file=license.txt
44
nbm.module.author=junichi11

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ public class WordPressPhpModuleExtender extends PhpModuleExtender {
101101
private static final String WP_CONFIG_PHP = "wp-config.php"; // NOI18N
102102
private NewProjectConfigurationPanel panel;
103103
private static final String WORDPRESS = "wordpress"; // NOI18N
104-
private static final String WP_DL_URL_DEFAULT = "http://wordpress.org/latest.zip"; // NOI18N
105-
private static final String WP_DL_URL_FORMAT = "http://%s.wordpress.org/latest-%s.zip"; // NOI18N
104+
private static final String WP_DL_URL_DEFAULT = "https://wordpress.org/latest.zip"; // NOI18N
106105
private static final String DB_NAME = "DB_NAME"; // NOI18N
107106
private static final String DB_USER = "DB_USER"; // NOI18N
108107
private static final String DB_PASSWORD = "DB_PASSWORD"; // NOI18N

src/org/netbeans/modules/php/wordpress/editor/completion/FilterAndActionCompletion.java

Lines changed: 62 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import java.io.InputStream;
4848
import java.io.InputStreamReader;
4949
import java.io.Reader;
50-
import java.io.UnsupportedEncodingException;
5150
import java.util.ArrayList;
5251
import java.util.List;
5352
import java.util.Set;
@@ -89,6 +88,12 @@
8988
@MimeRegistration(mimeType = FileUtils.PHP_MIME_TYPE, service = CompletionProvider.class)
9089
public final class FilterAndActionCompletion extends WordPressCompletionProvider {
9190

91+
enum Type {
92+
93+
Filter,
94+
Action
95+
}
96+
9297
private static final Logger LOGGER = Logger.getLogger(FilterAndActionCompletion.class.getName());
9398
private static final String CUSTOM_FILTER_CODE_COMPLETION_XML = "nbproject/code-completion-filter.xml"; // NOI18N
9499
private static final String CUSTOM_ACTION_CODE_COMPLETION_XML = "nbproject/code-completion-action.xml"; // NOI18N
@@ -97,15 +102,14 @@ public final class FilterAndActionCompletion extends WordPressCompletionProvider
97102
private int argCount;
98103
private boolean isFilter = false;
99104
private boolean isAction = false;
100-
private List<WordPressCompletionItem> filterItems;
101-
private List<WordPressCompletionItem> actionItems;
105+
private final List<WordPressCompletionItem> filterItems = new ArrayList<>();
106+
private final List<WordPressCompletionItem> actionItems = new ArrayList<>();
102107
private String currentInput;
103108

104109
public FilterAndActionCompletion() {
105110
refresh();
106111
}
107112

108-
@SuppressWarnings("unchecked")
109113
@Override
110114
public CompletionTask createTask(int queryType, JTextComponent component, final PhpModule phpModule) {
111115
return new AsyncCompletionTask(new AsyncCompletionQuery() {
@@ -165,7 +169,7 @@ protected void query(CompletionResultSet completionResultSet, Document doc, int
165169
}
166170

167171
/**
168-
* Check whether funciton is add_filter
172+
* Check whether function is add_filter
169173
*
170174
* @param ts
171175
* @return true if add_filter, otherwise false
@@ -211,7 +215,7 @@ private boolean isAction(String name) {
211215
}
212216

213217
private List<WordPressCompletionItem> getCodeCompletionList(PhpModule phpModule) {
214-
List<WordPressCompletionItem> list = new ArrayList<WordPressCompletionItem>();
218+
List<WordPressCompletionItem> list = new ArrayList<>();
215219
if (argCount == 1) {
216220
if (isFilter) {
217221
list = filterItems;
@@ -225,7 +229,7 @@ private List<WordPressCompletionItem> getCodeCompletionList(PhpModule phpModule)
225229
}
226230

227231
private List<WordPressCompletionItem> getFunctionsList(PhpModule phpModule) {
228-
List<WordPressCompletionItem> list = new ArrayList<WordPressCompletionItem>();
232+
List<WordPressCompletionItem> list = new ArrayList<>();
229233
FileObject sourceDirectory = phpModule.getSourceDirectory();
230234
String rootPath = ""; // NOI18N
231235
if (sourceDirectory != null) {
@@ -252,47 +256,69 @@ private List<WordPressCompletionItem> getFunctionsList(PhpModule phpModule) {
252256

253257
public void refresh() {
254258
// read file for filter
255-
filterItems = new ArrayList<WordPressCompletionItem>();
256-
actionItems = new ArrayList<WordPressCompletionItem>();
257-
FileObject filterXml = null;
258-
FileObject actionXml = null;
259+
filterItems.clear();
260+
actionItems.clear();
261+
FileObject customFilterXml = null;
262+
FileObject customActionXml = null;
259263
PhpModule phpModule = PhpModule.Factory.inferPhpModule();
260-
// TODO improve for each locales
261-
// String locale = "";
264+
262265
// use custom file
263266
if (phpModule != null) {
264267
FileObject projectDirectory = phpModule.getProjectDirectory();
265-
filterXml = projectDirectory.getFileObject(CUSTOM_FILTER_CODE_COMPLETION_XML);
266-
actionXml = projectDirectory.getFileObject(CUSTOM_ACTION_CODE_COMPLETION_XML);
268+
customFilterXml = projectDirectory.getFileObject(CUSTOM_FILTER_CODE_COMPLETION_XML);
269+
customActionXml = projectDirectory.getFileObject(CUSTOM_ACTION_CODE_COMPLETION_XML);
267270
}
268-
// TODO improve loop
269-
InputStream filterInputStream = null;
270-
InputStream actionInputStream = null;
271-
if (filterXml == null) {
272-
filterInputStream = FilterAndActionCompletion.class.getResourceAsStream(DEFAULT_FILTER_CODE_COMPLETION_XML);
273-
} else {
274-
try {
275-
filterInputStream = filterXml.getInputStream();
276-
} catch (FileNotFoundException ex) {
277-
LOGGER.log(Level.WARNING, null, ex);
271+
refresh(customFilterXml, Type.Filter);
272+
refresh(customActionXml, Type.Action);
273+
}
274+
275+
private void refresh(FileObject customXml, Type type) {
276+
try (InputStream inputStream = getInputStream(customXml, type)) {
277+
if (inputStream != null) {
278+
try (Reader reader = new BufferedReader(new InputStreamReader(inputStream, Charset.UTF8))) {
279+
parse(reader, type);
280+
}
278281
}
282+
} catch (IOException ex) {
283+
LOGGER.log(Level.WARNING, null, ex);
279284
}
280-
if (actionXml == null) {
281-
actionInputStream = FilterAndActionCompletion.class.getResourceAsStream(DEFAULT_ACTION_CODE_COMPLETION_XML);
285+
}
286+
287+
private void parse(Reader reader, Type type) {
288+
switch (type) {
289+
case Filter:
290+
WordPressCodeCompletionParser.parse(reader, filterItems);
291+
break;
292+
case Action:
293+
WordPressCodeCompletionParser.parse(reader, actionItems);
294+
break;
295+
default:
296+
throw new AssertionError();
297+
}
298+
}
299+
300+
private InputStream getInputStream(FileObject customXml, Type type) {
301+
InputStream inputStream = null;
302+
if (customXml == null) {
303+
inputStream = getDefaultInputStream(type);
282304
} else {
283305
try {
284-
actionInputStream = actionXml.getInputStream();
306+
inputStream = customXml.getInputStream();
285307
} catch (FileNotFoundException ex) {
286308
LOGGER.log(Level.WARNING, null, ex);
287309
}
288310
}
289-
try {
290-
Reader filterReader = new BufferedReader(new InputStreamReader(filterInputStream, Charset.UTF8));
291-
WordPressCodeCompletionParser.parse(filterReader, filterItems);
292-
Reader actionReader = new BufferedReader(new InputStreamReader(actionInputStream, Charset.UTF8));
293-
WordPressCodeCompletionParser.parse(actionReader, actionItems);
294-
} catch (UnsupportedEncodingException ex) {
295-
LOGGER.log(Level.WARNING, null, ex);
311+
return inputStream;
312+
}
313+
314+
private InputStream getDefaultInputStream(Type type) {
315+
switch (type) {
316+
case Filter:
317+
return FilterAndActionCompletion.class.getResourceAsStream(DEFAULT_FILTER_CODE_COMPLETION_XML);
318+
case Action:
319+
return FilterAndActionCompletion.class.getResourceAsStream(DEFAULT_ACTION_CODE_COMPLETION_XML);
320+
default:
321+
return null;
296322
}
297323
}
298324

@@ -321,9 +347,7 @@ public static void parse(Reader reader, List<WordPressCompletionItem> items) {
321347
try {
322348
WordPressCodeCompletionParser parser = new WordPressCodeCompletionParser(items);
323349
parser.xmlReader.parse(new InputSource(reader));
324-
} catch (SAXException ex) {
325-
Exceptions.printStackTrace(ex);
326-
} catch (IOException ex) {
350+
} catch (SAXException | IOException ex) {
327351
Exceptions.printStackTrace(ex);
328352
} finally {
329353
try {

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

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,40 +42,48 @@
4242
package org.netbeans.modules.php.wordpress.ui.actions;
4343

4444
import java.awt.event.ActionEvent;
45-
import java.awt.event.ActionListener;
4645
import java.io.IOException;
4746
import java.util.logging.Level;
4847
import java.util.logging.Logger;
49-
import org.netbeans.modules.php.wordpress.WordPress;
48+
import javax.swing.AbstractAction;
49+
import javax.swing.Action;
50+
import org.netbeans.modules.php.api.phpmodule.PhpModule;
5051
import org.netbeans.modules.php.wordpress.util.WPFileUtils;
52+
import org.netbeans.modules.php.wordpress.util.WPUtils;
5153
import org.openide.DialogDisplayer;
5254
import org.openide.NotifyDescriptor;
5355
import org.openide.awt.ActionID;
5456
import org.openide.awt.ActionReference;
55-
import org.openide.awt.ActionReferences;
5657
import org.openide.awt.ActionRegistration;
5758
import org.openide.filesystems.FileObject;
5859
import org.openide.loaders.DataObject;
60+
import org.openide.util.ContextAwareAction;
61+
import org.openide.util.Lookup;
5962
import org.openide.util.NbBundle.Messages;
6063

61-
@ActionID(
62-
category = "File",
63-
id = "org.netbeans.modules.php.wordpress.ui.actions.ZipAction")
64-
@ActionRegistration(
65-
iconBase = WordPress.WP_ICON_16,
66-
displayName = "#CTL_ZipAction")
67-
@ActionReferences({
68-
@ActionReference(path = "Menu/File", position = 2700),
69-
@ActionReference(path = "Loaders/folder/any/Actions", position = 1650)
70-
})
64+
@ActionID(category = "File", id = "org.netbeans.modules.php.wordpress.ui.actions.ZipAction")
65+
@ActionRegistration(displayName = "#CTL_ZipAction", lazy = false)
66+
@ActionReference(path = "Loaders/folder/any/Actions", position = 1650)
7167
@Messages("CTL_ZipAction=WordPress Zip compress")
72-
public final class ZipAction implements ActionListener {
68+
public final class ZipAction extends AbstractAction implements ContextAwareAction {
7369

74-
private final DataObject context;
70+
private static final long serialVersionUID = 1781415535743693501L;
71+
72+
private DataObject context;
7573
private static final Logger LOGGER = Logger.getLogger(ZipAction.class.getName());
7674

75+
public ZipAction() {
76+
this(null);
77+
}
78+
7779
public ZipAction(DataObject context) {
7880
this.context = context;
81+
if (context == null) {
82+
putValue(Action.NAME, ""); // NOI18N
83+
} else {
84+
putValue(Action.NAME, Bundle.CTL_ZipAction()); // NOI18N
85+
}
86+
setEnabled(context != null);
7987
}
8088

8189
@Messages({
@@ -84,7 +92,7 @@ public ZipAction(DataObject context) {
8492
})
8593
@Override
8694
public void actionPerformed(ActionEvent ev) {
87-
if (!isValidDirectory()) {
95+
if (!isValidDirectory(getFileObject())) {
8896
return;
8997
}
9098

@@ -114,8 +122,10 @@ private FileObject getFileObject() {
114122
* @return true if parent directory name is "plugins" or "themes", otherwise
115123
* false.
116124
*/
117-
private boolean isValidDirectory() {
118-
FileObject target = getFileObject();
125+
private boolean isValidDirectory(FileObject target) {
126+
if (target == null) {
127+
return false;
128+
}
119129
FileObject parent = target.getParent();
120130
String name = parent.getNameExt();
121131
if (parent.isFolder()) {
@@ -142,4 +152,24 @@ private void showErrorDialog(String errorMessage) {
142152
NotifyDescriptor.Message message = new NotifyDescriptor.Message(errorMessage, NotifyDescriptor.ERROR_MESSAGE);
143153
DialogDisplayer.getDefault().notify(message);
144154
}
155+
156+
@Override
157+
public Action createContextAwareInstance(Lookup actionContext) {
158+
DataObject dataObject = actionContext.lookup(DataObject.class);
159+
if (dataObject == null) {
160+
return this;
161+
}
162+
FileObject fileObject = dataObject.getPrimaryFile();
163+
PhpModule phpModule = PhpModule.Factory.forFileObject(fileObject);
164+
if (phpModule == null) {
165+
return this;
166+
}
167+
if (!WPUtils.isWP(phpModule)) {
168+
return this;
169+
}
170+
if (!isValidDirectory(fileObject)) {
171+
return this;
172+
}
173+
return new ZipAction(dataObject);
174+
}
145175
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright 2015 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 2015 Sun Microsystems, Inc.
41+
*/
42+
package org.netbeans.modules.php.wordpress.update;
43+
44+
import org.openide.DialogDisplayer;
45+
import org.openide.NotifyDescriptor;
46+
import org.openide.util.NbBundle;
47+
48+
/**
49+
*
50+
* @author junichi11
51+
*/
52+
public final class UpgradeUtils {
53+
54+
private UpgradeUtils() {
55+
}
56+
57+
@NbBundle.Messages("UpgradeUtils.invalid.wpcli.message=Not found wp-cli: You can update the WordPress using the update command of wp-cli from this link if wp-cli path and locale are set to the Options.")
58+
public static void showInvalidWpCliDialog() {
59+
NotifyDescriptor.Message message = new NotifyDescriptor.Message(
60+
Bundle.UpgradeUtils_invalid_wpcli_message(),
61+
NotifyDescriptor.INFORMATION_MESSAGE
62+
);
63+
DialogDisplayer.getDefault().notify(message);
64+
}
65+
}

0 commit comments

Comments
 (0)