Skip to content

Commit c25a6d2

Browse files
committed
Add the WordPressUnzipException
- Leave a log if a file is not unzipped
1 parent c7410d1 commit c25a6d2

3 files changed

Lines changed: 75 additions & 2 deletions

File tree

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

Lines changed: 3 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()) {

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)