From 6bf8e36fad017818aa7285579b976615baaf959e Mon Sep 17 00:00:00 2001
From: Jumper Chen
Date: Tue, 14 Feb 2017 09:53:21 +0800
Subject: [PATCH] Fix #19 Exception on Intellij IU-163.12024.16
---
META-INF/plugin.xml | 7 ++++++-
src/org/zkoss/zkidea/project/ZKProjectsManager.java | 12 ++++++++++--
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/META-INF/plugin.xml b/META-INF/plugin.xml
index 1c8e924..96076d6 100644
--- a/META-INF/plugin.xml
+++ b/META-INF/plugin.xml
@@ -1,7 +1,7 @@
org.zkoss.zkidea
ZK
- 0.1.8
+ 0.1.9
ZK Framework
org.jetbrains.idea.maven
@@ -12,6 +12,11 @@
]]>
0.1.9
+
+ - [bug] #19 - Exception on Intellij IU-163.12024.16
+
+
0.1.8
- [bug] #14 - Worker exited due to exception
diff --git a/src/org/zkoss/zkidea/project/ZKProjectsManager.java b/src/org/zkoss/zkidea/project/ZKProjectsManager.java
index 3b3647d..cec6494 100644
--- a/src/org/zkoss/zkidea/project/ZKProjectsManager.java
+++ b/src/org/zkoss/zkidea/project/ZKProjectsManager.java
@@ -139,7 +139,11 @@ public void run() {
LOG.info("Downloading latest zul file: " + ZulSchemaProvider.ZUL_PROJECT_SCHEMA_URL);
File fileTmp = new File(fileSrc.getAbsolutePath() + ".tmp");
- FileUtil.writeToFile(fileTmp, download(new URL(ZulSchemaProvider.ZUL_PROJECT_SCHEMA_URL)));
+ byte[] download = download(
+ new URL(ZulSchemaProvider.ZUL_PROJECT_SCHEMA_URL));
+ if (download != null && download.length == 0)
+ return; // try next time.
+ FileUtil.writeToFile(fileTmp, download);
// HttpRequests.request(ZulSchemaProvider.ZUL_PROJECT_SCHEMA_URL).saveToFile(fileTmp, ProgressManager.getGlobalProgressIndicator());
double origin = getSchemaVersion(fileSrc);
double newone = getSchemaVersion(fileTmp);
@@ -154,6 +158,7 @@ public void run() {
private byte[] download(URL url) throws IOException {
URLConnection uc = url.openConnection();
int len = uc.getContentLength();
+ if (len < 0) return new byte[0];
InputStream is = new BufferedInputStream(uc.getInputStream());
try {
byte[] data = new byte[len];
@@ -189,7 +194,10 @@ private void updateMavenArchetype() {
File fileTmp = new File(fileSrc.getAbsolutePath() + ".tmp");
- FileUtil.writeToFile(fileTmp, download(new URL(ZKMavenArchetypesProvider.MAVEN_ARCHETYPE_URL)));
+ byte[] download = download(new URL(ZKMavenArchetypesProvider.MAVEN_ARCHETYPE_URL));
+ if (download != null && download.length == 0)
+ return; // try next time.
+ FileUtil.writeToFile(fileTmp, download);
// HttpRequests.request(ZKMavenArchetypesProvider.MAVEN_ARCHETYPE_URL).saveToFile(fileTmp, ProgressManager.getGlobalProgressIndicator());
if (fileTmp.length() > fileSrc.length()) {