Skip to content

Commit

Permalink
fix: fixed temporary file deletion after non-retryable download excep…
Browse files Browse the repository at this point in the history
…tion (#255)

Fixes #254
  • Loading branch information
v1nc3n4 authored Oct 28, 2024
1 parent 35a9179 commit 34fc07e
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Actual results: ...
- OS: [e.g. Ubuntu 24.04, Windows 11 Pro, Mac OS X]
- JDK: [e.g. Adoptium Temurin JDK 21 64 bits]
- Gradle: [e.g. Gradle 8.10.2]
- Frontend Gradle plugin: [e.g. 9.0.0 JDK 21]
- Frontend Gradle plugin: [e.g. 9.0.1 JDK 21]

Settings in `build.gradle[.kts]` file:
```groovy
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Explain what you would like the plugin do: ...
- OS: [e.g. Ubuntu 24.04, Windows 11 Pro, Mac OS X]
- JDK: [e.g. Adoptium Temurin JDK 21 64 bits]
- Gradle: [e.g. Gradle 8.10.2]
- Frontend Gradle plugin: [e.g. 9.0.0 JDK 21]
- Frontend Gradle plugin: [e.g. 9.0.1 JDK 21]

Settings in `build.gradle[.kts]` file:
```groovy
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<a href="https://www.npmjs.com/" title="npm">npm</a>, <a href="https://pnpm.io/" title="pnpm">pnpm</a>,
<a href="https://yarnpkg.com/" title="Yarn">Yarn</a> builds</h2>
<p align="center">
<a href="https://github.com/siouan/frontend-gradle-plugin/releases/tag/v9.0.0"><img src="https://img.shields.io/badge/Latest%20release-9.0.0-blue.svg" alt="Latest release 9.0.0"/></a>
<a href="https://github.com/siouan/frontend-gradle-plugin/releases/tag/v9.0.1"><img src="https://img.shields.io/badge/Latest%20release-9.0.1-blue.svg" alt="Latest release 9.0.1"/></a>
<br/>
<a href="https://github.com/siouan/frontend-gradle-plugin/actions/workflows/build.yml"><img src="https://github.com/siouan/frontend-gradle-plugin/actions/workflows/build.yml/badge.svg?branch=9.0-jdk21" alt="Build status"/></a>
<a href="https://sonarcloud.io/project/overview?id=siouan_frontend-gradle-plugin"><img src="https://sonarcloud.io/api/project_badges/measure?project=siouan_frontend-gradle-plugin&metric=alert_status" alt="Quality gate status"/></a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pluginManagement {
plugins {
id("org.siouan.frontend-jdk21") version "9.0.0"
id("org.siouan.frontend-jdk21") version "9.0.1"
}
}
2 changes: 1 addition & 1 deletion examples/fullstack-war-application/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pluginManagement {
id("war")
id("org.springframework.boot") version "3.3.4"
id("io.spring.dependency-management") version "1.1.6"
id("org.siouan.frontend-jdk21") version "9.0.0"
id("org.siouan.frontend-jdk21") version "9.0.1"
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pluginManagement {
plugins {
id("org.siouan.frontend-jdk21") version "9.0.0"
id("org.siouan.frontend-jdk21") version "9.0.1"
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/npm-application/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pluginManagement {
plugins {
id("org.siouan.frontend-jdk21") version "9.0.0"
id("org.siouan.frontend-jdk21") version "9.0.1"
}
}
2 changes: 1 addition & 1 deletion examples/pnpm-application/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pluginManagement {
plugins {
id("org.siouan.frontend-jdk21") version "9.0.0"
id("org.siouan.frontend-jdk21") version "9.0.1"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pluginManagement {
plugins {
id("org.siouan.frontend-jdk21") version "9.0.0"
id("org.siouan.frontend-jdk21") version "9.0.1"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pluginManagement {
plugins {
id("org.siouan.frontend-jdk21") version "9.0.0"
id("org.siouan.frontend-jdk21") version "9.0.1"
}
}
2 changes: 1 addition & 1 deletion plugin/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fgpArtifactId=frontend-jdk21
fgpGroup=org.siouan
fgpVersion=9.0.0
fgpVersion=9.0.1
fgpDisplayName=Frontend Gradle plugin
fgpDescription=Build Javascript applications with Node, NPM, PNPM, Yarn: distribution management and package manager activation (Corepack), built-in tasks, additional task types.
fgpImplementationClass=org.siouan.frontendgradleplugin.FrontendGradlePlugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.net.Proxy;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;

Expand Down Expand Up @@ -107,13 +108,11 @@ private void attemptDownload(final DownloadResourceCommand command) throws Resou
throw new ResourceDownloadException(errorMessage);
}
}
} catch (final ResourceDownloadException e) {
deleteTemporaryFileOrWarn(command.getTemporaryFilePath());
throw e;
} catch (final IOException e) {
try {
fileManager.deleteIfExists(command.getTemporaryFilePath());
} catch (IOException ex) {
// Ignore this second exception as it would hide the first exception.
logger.warn("Unexpected error while deleting file after error: {}", command.getTemporaryFilePath());
}
deleteTemporaryFileOrWarn(command.getTemporaryFilePath());
throw new RetryableResourceDownloadException(e);
}
}
Expand All @@ -126,4 +125,13 @@ private void logAttemptFailure(final RetrySettings retrySettings, final RetryEve
retryEvent.getLastThrowable().getMessage());
}
}

public void deleteTemporaryFileOrWarn(final Path temporaryFilePath) {
try {
fileManager.deleteIfExists(temporaryFilePath);
} catch (IOException e) {
// Ignore this second exception as it would hide the first exception.
logger.warn("Unexpected error while deleting file after error: {}", temporaryFilePath);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ void should_retry_and_fail_when_http_response_status_code_is_not_ok_and_retryabl

verify(resourceInputChannel, times(2)).close();
verify(httpResponse, times(2)).close();
verify(fileManager, times(2)).deleteIfExists(downloadResourceCommand.getTemporaryFilePath());
verifyNoMoreInteractions(fileManager, channelProvider, httpClientProvider, httpClient);
}

Expand All @@ -175,6 +176,7 @@ void should_not_retry_and_fail_when_http_response_status_code_is_not_ok_and_not_

verify(resourceInputChannel).close();
verify(httpResponse).close();
verify(fileManager).deleteIfExists(downloadResourceCommand.getTemporaryFilePath());
verifyNoMoreInteractions(fileManager, channelProvider, httpClientProvider, httpClient);
}

Expand Down Expand Up @@ -265,7 +267,7 @@ void should_download_resource_after_retries() throws IOException, ResourceDownlo

verify(resourceInputChannel, times(4)).close();
verify(httpResponse, times(5)).close();
verify(fileManager, times(4)).deleteIfExists(downloadResourceCommand.getTemporaryFilePath());
verify(fileManager, times(5)).deleteIfExists(downloadResourceCommand.getTemporaryFilePath());
verifyNoMoreInteractions(fileManager, channelProvider, httpClientProvider, httpClient);
}

Expand Down
2 changes: 1 addition & 1 deletion site/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
}

dependencies {
classpath("org.siouan", "frontend-jdk21", "9.0.0")
classpath("org.siouan", "frontend-jdk21", "9.0.1")
}
}

Expand Down
2 changes: 1 addition & 1 deletion site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "frontend-gradle-plugin-site",
"description": "Frontend Gradle plugin's official site",
"license": "Apache-2.0",
"version": "9.0.0",
"version": "9.0.1",
"engines": {
"node": "~20.18.0"
},
Expand Down
24 changes: 12 additions & 12 deletions site/src/pages/getting-started.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@
<template #groovy>
<pre><FgpCode>plugins {
<FgpCodeComment>// For JDK 21+</FgpCodeComment>
id 'org.siouan.frontend-jdk21' version '9.0.0'
id 'org.siouan.frontend-jdk21' version '9.0.1'
<FgpCodeComment>// For JDK 17+</FgpCodeComment>
id 'org.siouan.frontend-jdk17' version '9.0.0'
id 'org.siouan.frontend-jdk17' version '9.0.1'
<FgpCodeComment>// For JDK 11+</FgpCodeComment>
id 'org.siouan.frontend-jdk11' version '9.0.0'
id 'org.siouan.frontend-jdk11' version '9.0.1'
}</FgpCode></pre>
</template>
<template #kotlin>
<pre><FgpCode>plugins {
<FgpCodeComment>// For JDK 21+</FgpCodeComment>
id("org.siouan.frontend-jdk21") version "9.0.0"
id("org.siouan.frontend-jdk21") version "9.0.1"
<FgpCodeComment>// For JDK 17+</FgpCodeComment>
id("org.siouan.frontend-jdk17") version "9.0.0"
id("org.siouan.frontend-jdk17") version "9.0.1"
<FgpCodeComment>// For JDK 11+</FgpCodeComment>
id("org.siouan.frontend-jdk11") version "9.0.0"
id("org.siouan.frontend-jdk11") version "9.0.1"
}</FgpCode></pre>
</template>
</FgpGradleScripts>
Expand All @@ -82,11 +82,11 @@
}
dependencies {
<FgpCodeComment>// For JDK 21+</FgpCodeComment>
classpath 'org.siouan:frontend-gradle-plugin-jdk21:9.0.0'
classpath 'org.siouan:frontend-gradle-plugin-jdk21:9.0.1'
<FgpCodeComment>// For JDK 17+</FgpCodeComment>
classpath 'org.siouan:frontend-gradle-plugin-jdk17:9.0.0'
classpath 'org.siouan:frontend-gradle-plugin-jdk17:9.0.1'
<FgpCodeComment>// For JDK 11+</FgpCodeComment>
classpath 'org.siouan:frontend-gradle-plugin-jdk11:9.0.0'
classpath 'org.siouan:frontend-gradle-plugin-jdk11:9.0.1'
}
}

Expand All @@ -104,11 +104,11 @@ apply plugin: 'org.siouan.frontend-jdk11'</FgpCode></pre>
}
dependencies {
<FgpCodeComment>// For JDK 21+</FgpCodeComment>
classpath("org.siouan:frontend-gradle-plugin-jdk21:9.0.0")
classpath("org.siouan:frontend-gradle-plugin-jdk21:9.0.1")
<FgpCodeComment>// For JDK 17+</FgpCodeComment>
classpath("org.siouan:frontend-gradle-plugin-jdk17:9.0.0")
classpath("org.siouan:frontend-gradle-plugin-jdk17:9.0.1")
<FgpCodeComment>// For JDK 11+</FgpCodeComment>
classpath("org.siouan:frontend-gradle-plugin-jdk11:9.0.0")
classpath("org.siouan:frontend-gradle-plugin-jdk11:9.0.1")
}
}

Expand Down
6 changes: 3 additions & 3 deletions site/src/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<FgpMainTitle class="text-center">
Frontend Gradle plugin
<FgpImageLink
href="https://github.com/siouan/frontend-gradle-plugin/releases/tag/v9.0.0"
src="https://img.shields.io/badge/Latest%20release-9.0.0-blue.svg"
alt="Latest release 9.0.0"
href="https://github.com/siouan/frontend-gradle-plugin/releases/tag/v9.0.1"
src="https://img.shields.io/badge/Latest%20release-9.0.1-blue.svg"
alt="Latest release 9.0.1"
/> <FgpImageLink
href="https://github.com/siouan/frontend-gradle-plugin/stargazers"
src="https://img.shields.io/github/stars/siouan/frontend-gradle-plugin?style=badge&label=%E2%9C%AE&color=gold&cacheSeconds=86400"
Expand Down

0 comments on commit 34fc07e

Please sign in to comment.