mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-13 20:15:09 +00:00
Close ZipOutputStream in eclipse dependency downloader
This commit is contained in:
1 parent
c8d6152097
commit
d21d551a4d
1 file changed
+31
-22
@@ -23,6 +23,7 @@ package lombok.eclipse.dependencies;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FilenameFilter;
|
||||
@@ -66,17 +67,12 @@ public class DownloadEclipseDependencies {
|
||||
String pluginSource = updateSite.getResolvedUrl() + "/plugins/";
|
||||
|
||||
for (String artifact : artifacts) {
|
||||
try {
|
||||
downloadFile(artifact, pluginSource, pluginTarget);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
// Download artifact
|
||||
downloadFile(artifact, pluginSource, pluginTarget);
|
||||
// Download artifact source
|
||||
int index = artifact.lastIndexOf("_");
|
||||
String source = artifact.substring(0, index) + ".source" + artifact.substring(index);
|
||||
try {
|
||||
downloadFile(source, pluginSource, pluginTarget);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
downloadFile(source, pluginSource, pluginTarget);
|
||||
}
|
||||
|
||||
writeEclipseLibrary(target, eclipseVersion);
|
||||
@@ -102,23 +98,27 @@ public class DownloadEclipseDependencies {
|
||||
} catch (IOException e) {
|
||||
System.out.println("[error]");
|
||||
} finally {
|
||||
if (in != null) try {
|
||||
in.close();
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
if (out != null) out.close();
|
||||
closeQuietly(in);
|
||||
closeQuietly(out);
|
||||
}
|
||||
}
|
||||
|
||||
private static void copyZipButStripSignatures(InputStream rawIn, OutputStream rawOut) throws IOException {
|
||||
ZipInputStream in = new ZipInputStream(rawIn);
|
||||
ZipOutputStream out = new ZipOutputStream(rawOut);
|
||||
|
||||
ZipEntry zipEntry;
|
||||
while ((zipEntry = in.getNextEntry()) != null) {
|
||||
if (zipEntry.getName().matches("META-INF/.*\\.(SF|RSA)")) continue;
|
||||
out.putNextEntry(zipEntry);
|
||||
copy(in, out);
|
||||
ZipInputStream in = null;
|
||||
ZipOutputStream out = null;
|
||||
try {
|
||||
in = new ZipInputStream(rawIn);
|
||||
out = new ZipOutputStream(rawOut);
|
||||
|
||||
ZipEntry zipEntry;
|
||||
while ((zipEntry = in.getNextEntry()) != null) {
|
||||
if (zipEntry.getName().matches("META-INF/.*\\.(SF|RSA)")) continue;
|
||||
out.putNextEntry(zipEntry);
|
||||
copy(in, out);
|
||||
}
|
||||
} finally {
|
||||
closeQuietly(in);
|
||||
closeQuietly(out);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,6 +131,15 @@ public class DownloadEclipseDependencies {
|
||||
}
|
||||
}
|
||||
|
||||
private static void closeQuietly(Closeable closeable) {
|
||||
if (closeable != null) {
|
||||
try {
|
||||
closeable.close();
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static InputStream getStreamForUrl(String url) throws IOException, MalformedURLException {
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
connection.setRequestProperty("User-Agent", "lombok");
|
||||
|
||||
Reference in new issue
Block a user