Skip to content
This repository has been archived by the owner on Jan 18, 2021. It is now read-only.

minor cleanup #568

Merged
merged 3 commits into from Nov 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,7 +1,6 @@
package org.shipkit.gradle.java;

import org.gradle.api.DefaultTask;
import org.gradle.api.publish.maven.tasks.GenerateMavenPom;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.Optional;
Expand Down
Expand Up @@ -5,8 +5,6 @@
import org.gradle.api.tasks.bundling.Jar;
import org.shipkit.internal.gradle.util.JavaPluginUtil;

import java.io.File;

/**
* Makes a java library that has not only the main jar but also sources and javadoc jars.
* Intended to be applied in individual Java submodule.
Expand Down
@@ -1,7 +1,6 @@
package org.shipkit.internal.gradle.java.tasks;

import org.gradle.api.DefaultTask;
import org.gradle.api.Project;
import org.gradle.api.artifacts.*;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFiles;
Expand Down
Expand Up @@ -52,15 +52,30 @@ public static String readFully(InputStream stream) {
* @param closeable the target, may be null
*/
public static void close(Closeable closeable) {
close(closeable, false);
}

private static void close(Closeable closeable, boolean quietly) {
if (closeable != null) {
try {
closeable.close();
} catch (IOException e) {
throw new RuntimeException("Problems closing stream", e);
if (!quietly) {
throw new RuntimeException("Problems closing closeable", e);
}
}
}
}

/**
* Closes the target. Does nothing when target is null. Is silent.
*
* @param closeable the target, may be null
*/
public static void closeQuietly(Closeable closeable) {
close(closeable, true);
}

public static void createParentDirectory(File file) {
createDirectory(file.getParentFile());
}
Expand All @@ -80,31 +95,26 @@ public static void createDirectory(File file) {
*/
public static void downloadToFile(String url, File file) {
InputStream input = null;
FileOutputStream output = null;
try {
input = new BufferedInputStream(new URL(url).openStream());

IOUtil.createParentDirectory(file);

FileOutputStream fos = new FileOutputStream(file);
byte[] buf = new byte[1024];
int n;
while ((n = input.read(buf)) != -1) {
fos.write(buf, 0, n);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
byte[] buf = new byte[1024];
int n;
while ((n = input.read(buf)) != -1) {
fos.write(buf, 0, n);
}
} finally {
closeQuietly(fos);
}
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
try {
if (input != null) {
input.close();
}
if (output != null) {
output.close();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
closeQuietly(input);
}
}

Expand Down