From 3c4a3845618db44c46d2fde9f50de2180390f8d0 Mon Sep 17 00:00:00 2001 From: Evgeni Gordeev Date: Thu, 4 Aug 2016 10:37:50 -0500 Subject: [PATCH 1/2] closes #20. --- .gitignore | 4 ++ .../github/release/plugin/UploadMojo.java | 54 +++++++++++++++---- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index d060983..5bdfbeb 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,7 @@ # Maven # /target/ + +# Intellij IDEA # +.idea/ +*.iml \ No newline at end of file diff --git a/src/main/java/de/jutzig/github/release/plugin/UploadMojo.java b/src/main/java/de/jutzig/github/release/plugin/UploadMojo.java index 270b0be..cb28998 100644 --- a/src/main/java/de/jutzig/github/release/plugin/UploadMojo.java +++ b/src/main/java/de/jutzig/github/release/plugin/UploadMojo.java @@ -16,13 +16,7 @@ * limitations under the License. */ -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.text.MessageFormat; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import static java.lang.Thread.sleep; import org.apache.commons.lang.StringUtils; import org.apache.maven.execution.MavenSession; @@ -48,6 +42,14 @@ import org.kohsuke.github.GHRepository; import org.kohsuke.github.GitHub; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.text.MessageFormat; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** * Goal which attaches a file to a GitHub release * @@ -145,6 +147,20 @@ public class UploadMojo extends AbstractMojo implements Contextualizable{ */ private Boolean prerelease; + /** + * Number of attempts to upload, defaults to 5. + * + * @parameter default-value=5 + */ + private int retryUploadCount = 5; + + /** + * Retry timeout between failing uploads, defaults to 10 seconds. + * + * @parameter default-value=10000 + */ + private int retryUploadTimeout = 10000; + public void execute() throws MojoExecutionException { if(releaseName==null) releaseName = tag; @@ -214,8 +230,28 @@ private void uploadAsset(GHRelease release, File asset) throws IOException { } getLog().info(" Upload asset"); - // for some reason this doesn't work currently - release.uploadAsset(asset, "application/zip"); + int attempt = 0; + do { + try { + release.uploadAsset(asset, "application/zip"); + break; + } catch (IOException e) { + if (attempt < retryUploadCount) { + getLog().warn(String.format("Asset %s failed to upload, retrying in %d seconds (%d/%d)." + , asset.getName() + , retryUploadTimeout / 1000 + , attempt + 1 + , retryUploadCount)); + try { + sleep(retryUploadTimeout); + } catch (InterruptedException e1) { + throw new IOException(e1); + } + } else { + throw e; + } + } + } while (attempt++ <= retryUploadTimeout); } private void uploadAssets(GHRelease release, FileSet fileset) throws IOException { From e23c17188c37ad1eada70becb4f6a51524cb21e8 Mon Sep 17 00:00:00 2001 From: Evgeni Gordeev Date: Thu, 4 Aug 2016 10:44:37 -0500 Subject: [PATCH 2/2] fixing formatting. --- .../github/release/plugin/UploadMojo.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/jutzig/github/release/plugin/UploadMojo.java b/src/main/java/de/jutzig/github/release/plugin/UploadMojo.java index cb28998..737809b 100644 --- a/src/main/java/de/jutzig/github/release/plugin/UploadMojo.java +++ b/src/main/java/de/jutzig/github/release/plugin/UploadMojo.java @@ -16,7 +16,13 @@ * limitations under the License. */ -import static java.lang.Thread.sleep; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.text.MessageFormat; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.apache.commons.lang.StringUtils; import org.apache.maven.execution.MavenSession; @@ -42,14 +48,6 @@ import org.kohsuke.github.GHRepository; import org.kohsuke.github.GitHub; -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.text.MessageFormat; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - /** * Goal which attaches a file to a GitHub release * @@ -243,7 +241,7 @@ private void uploadAsset(GHRelease release, File asset) throws IOException { , attempt + 1 , retryUploadCount)); try { - sleep(retryUploadTimeout); + Thread.sleep(retryUploadTimeout); } catch (InterruptedException e1) { throw new IOException(e1); }