Skip to content

Commit

Permalink
Correct lock cleanup error message, add error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-mcnamara committed Oct 27, 2023
1 parent f47ba03 commit 048a7f8
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGES.MD
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change log

## 1.3.4
### Changed
- Updated lock cleanup error message to indicate correct file
- Updated error logging for repository operations
## 1.3.3
### Fixed
- Fixed `UpdatePluginsXml` incorrectly specifying @Input for an output file.
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group 'dev.bmac.intellij.plugins'
version '1.3.3'
version '1.3.4'

repositories {
mavenCentral()
Expand All @@ -24,7 +24,7 @@ dependencies {
implementation 'com.sun.xml.bind:jaxb-impl:2.3.3-b02'
implementation 'com.google.guava:guava:31.1-jre'
implementation "com.github.rholder:guava-retrying:2.0.0"
implementation "com.amazonaws:aws-java-sdk-s3:1.12.220"
implementation 'com.amazonaws:aws-java-sdk-s3:1.12.232'
implementation('org.jetbrains.intellij:blockmap') {
version {
strictly '[1.0.5, 1.0.6]'
Expand Down
24 changes: 16 additions & 8 deletions src/main/java/dev/bmac/gradle/intellij/PluginUploader.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package dev.bmac.gradle.intellij;

import com.github.rholder.retry.*;
import com.github.rholder.retry.Attempt;
import com.github.rholder.retry.RetryException;
import com.github.rholder.retry.RetryListener;
import com.github.rholder.retry.Retryer;
import com.github.rholder.retry.RetryerBuilder;
import com.github.rholder.retry.StopStrategies;
import com.github.rholder.retry.WaitStrategies;
import com.google.common.io.ByteSource;
import com.google.common.io.CharStreams;
import com.sun.istack.Nullable;
Expand All @@ -13,11 +19,13 @@
import org.gradle.api.logging.Logger;
import org.jetbrains.annotations.NotNull;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import java.io.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.text.DateFormat;
Expand Down Expand Up @@ -181,7 +189,7 @@ void postPluginAndUpdateXml() throws RetryableException, FatalException {
return null;
});
} catch (ExecutionException | RetryException e) {
throw new FatalException("Failed to cleanup " + file + LOCK_FILE_EXTENSION + ". File must be cleaned up manually", e);
throw new FatalException("Failed to delete " + updateFile + LOCK_FILE_EXTENSION + ". File must be cleaned up manually on repository", e);
}
} else {
throw new FatalException("The lock value changed during execution. This is bad! The release may be invalid");
Expand Down Expand Up @@ -366,9 +374,9 @@ protected Repo getRepoType() {
switch (repoType) {
case REST_POST:
case REST_PUT:
return new RestRepo(url, authentication, repoType);
return new RestRepo(url, authentication, repoType, logger);
case S3:
return new S3Repo(url, authentication);
return new S3Repo(url, authentication, logger);
default:
throw new IllegalStateException("Upload method not implemented for " + repoType.name());
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/dev/bmac/gradle/intellij/repos/Repo.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.bmac.gradle.intellij.repos;

import org.gradle.api.logging.Logger;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -12,10 +14,12 @@ public abstract class Repo {

final String baseRepoPath;
final String authentication;
final Logger logger;

public Repo(String baseRepoPath, String authentication) {
public Repo(String baseRepoPath, String authentication, Logger logger) {
this.baseRepoPath = baseRepoPath;
this.authentication = authentication;
this.logger = logger;
}

/**
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/dev/bmac/gradle/intellij/repos/RestRepo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package dev.bmac.gradle.intellij.repos;

import dev.bmac.gradle.intellij.PluginUploader;
import okhttp3.*;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import org.gradle.api.logging.Logger;

import java.io.File;
import java.io.IOException;
Expand All @@ -13,8 +19,8 @@
public class RestRepo extends Repo {
private static final OkHttpClient CLIENT = new OkHttpClient.Builder().build();
private final String method;
public RestRepo(String baseRepoPath, String authentication, PluginUploader.RepoType repoType) {
super(baseRepoPath, authentication);
public RestRepo(String baseRepoPath, String authentication, PluginUploader.RepoType repoType, Logger logger) {
super(baseRepoPath, authentication, logger);
switch (repoType) {
case REST_POST:
method = "POST";
Expand Down Expand Up @@ -48,6 +54,7 @@ public <T> T get(String relativePath, Function<RepoObject, T> converter) throws
}
object = RepoObject.of(body.byteStream());
} else {
logger.error("While getting '" + relativePath + "' the server returned status code: " + response.code());
throw new RuntimeException("Received an unknown status code while retrieving " + relativePath);
}
return converter.apply(object);
Expand All @@ -67,6 +74,7 @@ public void upload(String relativePath, File file, String mediaType) throws IOEx

try (Response response = CLIENT.newCall(request).execute()) {
if (!response.isSuccessful()) {
logger.error("Failed to upload '" + relativePath + "', server returned status code: " + response.code());
throw new IOException("Failed to upload plugin with status: " + response.code());
}
}
Expand All @@ -86,6 +94,7 @@ public void delete(String relativePath) throws IOException {

try (Response response = CLIENT.newCall(request).execute()) {
if (!response.isSuccessful()) {
logger.error("Failed to delete '" + relativePath + "', Server returned status code: " + response.code());
throw new IOException("Failed to delete lock with status: " + response.code());
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/dev/bmac/gradle/intellij/repos/S3Repo.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.AmazonS3Exception;
import com.amazonaws.services.s3.model.S3Object;
import org.gradle.api.logging.Logger;

import java.io.File;
import java.io.IOException;
Expand All @@ -24,8 +25,8 @@ public class S3Repo extends Repo {
final String region;
final AmazonS3 client;

public S3Repo(String baseRepoPath, String authentication) {
super(getBaseKeyPath(baseRepoPath), authentication);
public S3Repo(String baseRepoPath, String authentication, Logger logger) {
super(getBaseKeyPath(baseRepoPath), authentication, logger);

AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard();

Expand Down Expand Up @@ -74,6 +75,8 @@ public <T> T get(String relativePath, Function<RepoObject, T> converter) throws
if (e.getStatusCode() == 404) {
return converter.apply(RepoObject.empty());
}
logger.error("Failed to get object '" + relativePath + "', response code from s3: " + e.getStatusCode() +
" message: " + e.getMessage());
throw new IOException("Failed to get object from s3", e);
}
}
Expand Down

0 comments on commit 048a7f8

Please sign in to comment.