From 02fc2b573c00dfdd8f2b877940e221eade4a42fc Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Tue, 17 Oct 2023 23:30:08 +0200 Subject: [PATCH] Tidy up --- .../transport/jdk/JdkHttpTransporter.java | 17 ++++++++++++++++- .../transport/jdk/JdkTransporterFactory.java | 2 +- .../transport/jdk/JdkTransporterFactory.java | 2 +- .../aether/transport/jdk/package-info.java | 4 ++-- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporter.java b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporter.java index cd9c33eef..529226a28 100644 --- a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporter.java +++ b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporter.java @@ -34,6 +34,7 @@ import java.net.http.HttpResponse; import java.nio.file.Files; import java.nio.file.StandardCopyOption; +import java.nio.file.attribute.FileTime; import java.security.NoSuchAlgorithmException; import java.text.SimpleDateFormat; import java.time.Duration; @@ -60,7 +61,9 @@ import org.eclipse.aether.util.FileUtils; /** - * A transporter for HTTP/HTTPS. + * JDK Transport using {@link java.net.http.HttpClient}. + * + * @since TBD */ final class JdkHttpTransporter extends AbstractTransporter { private static final int MULTIPLE_CHOICES = 300; @@ -85,6 +88,8 @@ final class JdkHttpTransporter extends AbstractTransporter { private static final String USER_AGENT = "User-Agent"; + private static final String LAST_MODIFIED = "Last-Modified"; + private static final Pattern CONTENT_RANGE_PATTERN = Pattern.compile("\\s*bytes\\s+([0-9]+)\\s*-\\s*([0-9]+)\\s*/.*"); @@ -244,6 +249,16 @@ protected void implGet(GetTask task) throws Exception { task.setDataFile(dataFile); } } + if (task.getDataFile() != null) { + String lastModifiedHeader = + response.headers().firstValue(LAST_MODIFIED).orElse(null); // note: Wagon also does first not last + if (lastModifiedHeader != null) { + Date lastModified = createRFC7231().parse(lastModifiedHeader); + if (lastModified != null) { + Files.setLastModifiedTime(task.getDataFile().toPath(), FileTime.fromMillis(lastModified.getTime())); + } + } + } Map checksums = extractXChecksums(response); if (checksums != null) { checksums.forEach(task::setChecksum); diff --git a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkTransporterFactory.java b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkTransporterFactory.java index 4fdcdb270..ef076f038 100644 --- a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkTransporterFactory.java +++ b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkTransporterFactory.java @@ -29,7 +29,7 @@ import static java.util.Objects.requireNonNull; /** - * JDK11 Transport factory. + * JDK Transport factory. * * @since TBD */ diff --git a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-8/src/main/java/org/eclipse/aether/transport/jdk/JdkTransporterFactory.java b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-8/src/main/java/org/eclipse/aether/transport/jdk/JdkTransporterFactory.java index b061977ba..aa015d2b2 100644 --- a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-8/src/main/java/org/eclipse/aether/transport/jdk/JdkTransporterFactory.java +++ b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-8/src/main/java/org/eclipse/aether/transport/jdk/JdkTransporterFactory.java @@ -29,7 +29,7 @@ import static java.util.Objects.requireNonNull; /** - * JDK8 Transport factory: is no-op. + * JDK Transport factory: on Java 8 is no-op. * * @since TBD */ diff --git a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-8/src/main/java/org/eclipse/aether/transport/jdk/package-info.java b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-8/src/main/java/org/eclipse/aether/transport/jdk/package-info.java index df4f0a3b4..bff601e02 100644 --- a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-8/src/main/java/org/eclipse/aether/transport/jdk/package-info.java +++ b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-8/src/main/java/org/eclipse/aether/transport/jdk/package-info.java @@ -18,8 +18,8 @@ * under the License. */ /** - * Support for downloads/uploads via the HTTP and HTTPS protocols. Below Java 11 this implementation - * is no-op. + * Support for downloads/uploads via the HTTP and HTTPS protocols. This implementation is no-op on Java versions + * below 11. * * @since TBD */