Skip to content

Commit 3cc84e8

Browse files
committed
Merge branch 'nb82dev'
2 parents b779265 + eeda2e2 commit 3cc84e8

9 files changed

Lines changed: 122 additions & 16 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.9.0
5+
OpenIDE-Module-Specification-Version: 0.9.1
66
OpenIDE-Module-Install: org/netbeans/modules/php/wordpress/WordPressModuleInstall.class

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
import org.netbeans.modules.php.wordpress.util.NetUtils;
8383
import org.netbeans.modules.php.wordpress.util.WPFileUtils;
8484
import org.netbeans.modules.php.wordpress.util.WPZipEntryFilter;
85+
import org.netbeans.modules.php.wordpress.util.WordPressUnzipException;
8586
import org.netbeans.modules.php.wordpress.wpapis.WordPressVersionCheckApi;
8687
import org.openide.filesystems.FileObject;
8788
import org.openide.filesystems.FileUtil;
@@ -203,7 +204,8 @@ public Set<FileObject> extend(PhpModule pm) throws ExtendingException {
203204
WPFileUtils.unzip(urlPath, FileUtil.toFile(sourceDirectory), new WPZipEntryFilter(panel.getUnzipStatusTextField()));
204205
} catch (MalformedURLException ex) {
205206
Exceptions.printStackTrace(ex);
206-
} catch (IOException ex) {
207+
} catch (IOException | WordPressUnzipException ex) {
208+
LOGGER.log(Level.WARNING, ex.getMessage());
207209
throw new ExtendingException(ex.getLocalizedMessage());
208210
}
209211
} else if (panel.useLocalFile()) {
@@ -252,6 +254,8 @@ public Set<FileObject> extend(PhpModule pm) throws ExtendingException {
252254
WordPressPreferences.setWordPressFormat(pm);
253255
}
254256

257+
WordPressPreferences.setEnabled(pm, true);
258+
255259
Set<FileObject> files = new HashSet<>();
256260
if (sourceDirectory != null) {
257261
// create wp-config.php
@@ -297,6 +301,9 @@ private String getDownloadUrl() {
297301
try {
298302
versionCheckApi.parse();
299303
downloadUrl = versionCheckApi.getDownload();
304+
// follow a redirect url
305+
// it seems that the redirect url is used https
306+
downloadUrl = downloadUrl.replace("http://", "https://"); // NOI18N
300307
} catch (IOException ex) {
301308
downloadUrl = WP_DL_URL_DEFAULT;
302309
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@
4747
import org.netbeans.modules.php.spi.framework.actions.BaseAction;
4848
import org.openide.util.NbBundle;
4949
import org.openide.util.actions.Presenter;
50+
import org.openide.util.actions.Presenter.Popup;
5051

5152
/**
5253
*
5354
* @author junichi11
5455
*/
55-
public class CreateThemeAction extends BaseAction implements Presenter.Menu {
56+
public class CreateThemeAction extends BaseAction implements Presenter.Menu, Popup {
5657

5758
private static final long serialVersionUID = -1533566813298547558L;
5859
private static final CreateThemeAction INSTANCE = new CreateThemeAction();
@@ -81,6 +82,15 @@ protected void actionPerformed(PhpModule pm) {
8182

8283
@Override
8384
public JMenuItem getMenuPresenter() {
85+
return createMenuItem();
86+
}
87+
88+
@Override
89+
public JMenuItem getPopupPresenter() {
90+
return createMenuItem();
91+
}
92+
93+
private JMenuItem createMenuItem() {
8494
JMenu menu = new JMenu(getPureName());
8595
JMenuItem underscores = new JMenuItem(CreateUnderscoresThemeAction.getInstance());
8696
JMenuItem barebones = new JMenuItem(CreateBarebonesThemeAction.getInstance());

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@
5353
import javax.swing.event.DocumentListener;
5454
import javax.swing.text.Document;
5555
import org.netbeans.api.progress.ProgressHandle;
56-
import org.netbeans.api.progress.ProgressHandleFactory;
5756
import org.netbeans.modules.php.api.phpmodule.PhpModule;
5857
import org.netbeans.modules.php.api.util.StringUtils;
5958
import org.netbeans.modules.php.spi.framework.actions.BaseAction;
6059
import org.netbeans.modules.php.wordpress.modules.WordPressModule;
6160
import org.netbeans.modules.php.wordpress.util.GithubZipEntryFilter;
6261
import org.netbeans.modules.php.wordpress.util.WPFileUtils;
6362
import org.netbeans.modules.php.wordpress.util.WPUtils;
63+
import org.netbeans.modules.php.wordpress.util.WordPressUnzipException;
6464
import org.netbeans.modules.php.wordpress.util.ZipEntryFilter;
6565
import org.openide.DialogDisplayer;
6666
import org.openide.NotifyDescriptor;
@@ -187,8 +187,8 @@ public boolean cancel() {
187187
WPFileUtils.unzip(url, themeDirectory, entryFilter);
188188
} catch (MalformedURLException ex) {
189189
Exceptions.printStackTrace(ex);
190-
} catch (IOException ex) {
191-
Exceptions.printStackTrace(ex);
190+
} catch (IOException | WordPressUnzipException ex) {
191+
LOGGER.log(Level.WARNING, null, ex);
192192
} finally {
193193
handle.finish();
194194
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import java.util.logging.Level;
5252
import java.util.logging.Logger;
5353
import org.netbeans.api.progress.ProgressHandle;
54-
import org.netbeans.api.progress.ProgressHandleFactory;
5554
import org.netbeans.modules.php.api.phpmodule.PhpModule;
5655
import org.netbeans.modules.php.spi.framework.actions.BaseAction;
5756
import org.netbeans.modules.php.wordpress.modules.WordPressModule;
@@ -61,6 +60,7 @@
6160
import org.netbeans.modules.php.wordpress.util.UnderscoresZipEntryFilter;
6261
import org.netbeans.modules.php.wordpress.util.WPFileUtils;
6362
import org.netbeans.modules.php.wordpress.util.WPUtils;
63+
import org.netbeans.modules.php.wordpress.util.WordPressUnzipException;
6464
import org.openide.filesystems.FileAlreadyLockedException;
6565
import org.openide.filesystems.FileObject;
6666
import org.openide.filesystems.FileUtil;
@@ -190,7 +190,7 @@ private boolean unzipAndReplace(FileObject themeFolder) {
190190
themeFolder.refresh();
191191
} catch (MalformedURLException ex) {
192192
LOGGER.log(Level.WARNING, null, ex);
193-
} catch (IOException ex) {
193+
} catch (IOException | WordPressUnzipException ex) {
194194
LOGGER.log(Level.WARNING, null, ex);
195195
}
196196
FileObject[] children = themeFolder.getChildren();

src/org/netbeans/modules/php/wordpress/ui/logicalview/MVCNode.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
import java.util.logging.Logger;
5151
import javax.swing.Action;
5252
import org.netbeans.modules.php.api.util.FileUtils;
53+
import org.netbeans.modules.php.wordpress.modules.WordPressModule;
54+
import org.netbeans.modules.php.wordpress.ui.actions.CreateChildThemeAction;
55+
import org.netbeans.modules.php.wordpress.ui.actions.CreatePluginAction;
56+
import org.netbeans.modules.php.wordpress.ui.actions.CreateThemeAction;
5357
import org.netbeans.spi.project.ui.support.CommonProjectActions;
5458
import org.netbeans.spi.project.ui.support.FileSensitiveActions;
5559
import org.netbeans.spi.project.ui.support.ProjectSensitiveActions;
@@ -79,20 +83,22 @@ public class MVCNode extends FilterNode {
7983

8084
private static final String ICON_PATH = "org/netbeans/modules/php/wordpress/resources/wordpress_icon_8.png"; //NOI18N
8185
private static final Image WP_ICON = ImageUtilities.loadImage(ICON_PATH);
86+
private final WordPressModule.DIR_TYPE type;
8287

8388
/**
8489
* creates source root node based on specified DataFolder. Uses specified
8590
* name.
8691
*/
87-
MVCNode(DataFolder folder, DataFilter filter, String name) {
88-
this(folder, new FilterNode(folder.getNodeDelegate(), folder.createNodeChildren(filter)), name);
92+
MVCNode(DataFolder folder, DataFilter filter, String name, WordPressModule.DIR_TYPE type) {
93+
this(folder, new FilterNode(folder.getNodeDelegate(), folder.createNodeChildren(filter)), name, type);
8994
}
9095

91-
private MVCNode(DataFolder folder, FilterNode node, String name) {
96+
private MVCNode(DataFolder folder, FilterNode node, String name, WordPressModule.DIR_TYPE type) {
9297
super(node, new MVCNode.FolderChildren(node, false), new ProxyLookup(folder.getNodeDelegate().getLookup()));
9398

9499
disableDelegation(DELEGATE_GET_DISPLAY_NAME | DELEGATE_SET_DISPLAY_NAME | DELEGATE_GET_SHORT_DESCRIPTION | DELEGATE_GET_ACTIONS);
95100
setDisplayName(name);
101+
this.type = type;
96102
}
97103

98104
@Override
@@ -134,6 +140,18 @@ public boolean canDestroy() {
134140
public Action[] getActions(boolean context) {
135141
List<Action> actions = new ArrayList<>();
136142
actions.add(CommonProjectActions.newFileAction());
143+
// WordPress Actions
144+
switch (type) {
145+
case PLUGINS:
146+
actions.add(CreatePluginAction.getInstance());
147+
break;
148+
case THEMES:
149+
actions.add(CreateThemeAction.getInstance());
150+
actions.add(CreateChildThemeAction.getInstance());
151+
break;
152+
default:
153+
break;
154+
}
137155
actions.add(null);
138156
actions.add(FileSensitiveActions.fileCommandAction("dowonload", Bundle.LBL_DownloadCommand(), null));
139157
actions.add(FileSensitiveActions.fileCommandAction("upload", Bundle.LBL_UploadCommand(), null));

src/org/netbeans/modules/php/wordpress/ui/logicalview/MVCNodeFactory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,23 @@ public List<Node> keys() {
9595
// plugins
9696
FileObject pluginsDirectory = module.getPluginsDirectory();
9797
if (pluginsDirectory != null) {
98-
addNode(list, pluginsDirectory);
98+
addNode(list, pluginsDirectory, WordPressModule.DIR_TYPE.PLUGINS);
9999
}
100100
// themes
101101
FileObject themesDirectory = module.getThemesDirectory();
102102
if (themesDirectory != null) {
103-
addNode(list, themesDirectory);
103+
addNode(list, themesDirectory, WordPressModule.DIR_TYPE.THEMES);
104104
}
105105
return list;
106106
}
107107
return Collections.emptyList();
108108
}
109109

110-
private void addNode(List<Node> list, FileObject fileObject) {
110+
private void addNode(List<Node> list, FileObject fileObject, WordPressModule.DIR_TYPE type) {
111111
if (fileObject != null) {
112112
DataFolder folder = getFolder(fileObject);
113113
if (folder != null) {
114-
list.add(new MVCNode(folder, null, fileObject.getName()));
114+
list.add(new MVCNode(folder, null, fileObject.getName(), type));
115115
}
116116
}
117117
}

src/org/netbeans/modules/php/wordpress/util/WPFileUtils.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,16 @@ private static void compress(File target, File[] files, ZipOutputStream zipOutpu
143143
* @throws MalformedURLException
144144
* @throws IOException
145145
*/
146-
public static void unzip(String url, File targetDirectory, ZipEntryFilter filter) throws MalformedURLException, IOException {
146+
public static void unzip(String url, File targetDirectory, ZipEntryFilter filter) throws MalformedURLException, IOException, WordPressUnzipException {
147147
if (targetDirectory == null) {
148148
return;
149149
}
150150
URL zipUrl = new URL(url);
151151
try (ZipInputStream zipInputStream = new ZipInputStream(new BufferedInputStream(zipUrl.openStream()))) {
152152
ZipEntry entry;
153+
boolean isEmpty = true;
153154
while ((entry = zipInputStream.getNextEntry()) != null) {
155+
isEmpty = false;
154156
if (!filter.accept(entry)) {
155157
zipInputStream.closeEntry();
156158
continue;
@@ -163,6 +165,9 @@ public static void unzip(String url, File targetDirectory, ZipEntryFilter filter
163165
createDirectories(outFile, entry);
164166
writeFile(outFile, zipInputStream, entry);
165167
}
168+
if (isEmpty) {
169+
throw new WordPressUnzipException("Cannot unzip:" + url);
170+
}
166171
}
167172
}
168173

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2018 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+
package org.netbeans.modules.php.wordpress.util;
41+
42+
/**
43+
*
44+
* @author junichi11
45+
*/
46+
public class WordPressUnzipException extends Exception {
47+
48+
private static final long serialVersionUID = 1607655567611796935L;
49+
50+
/**
51+
* Creates a new instance of <code>WordPressUnzipException</code> without
52+
* detail message.
53+
*/
54+
public WordPressUnzipException() {
55+
}
56+
57+
/**
58+
* Constructs an instance of <code>WordPressUnzipException</code> with the
59+
* specified detail message.
60+
*
61+
* @param msg the detail message.
62+
*/
63+
public WordPressUnzipException(String msg) {
64+
super(msg);
65+
}
66+
}

0 commit comments

Comments
 (0)