Skip to content

Commit

Permalink
Initial upgrade to primogenitor 3.0.0-beta0004
Browse files Browse the repository at this point in the history
  • Loading branch information
io7m committed May 20, 2018
1 parent 9623694 commit d291103
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 123 deletions.
29 changes: 19 additions & 10 deletions com.io7m.jdownload.api/pom.xml
Expand Up @@ -13,7 +13,7 @@
</parent>

<artifactId>com.io7m.jdownload.api</artifactId>
<packaging>bundle</packaging>
<packaging>jar</packaging>

<name>com.io7m.jdownload.api</name>
<description>Simple HTTP downloads (API)</description>
Expand All @@ -35,17 +35,26 @@
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>

<!-- Produce OSGi bundle -->
<!-- Analyze semantic versioning -->
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-baseline-maven-plugin</artifactId>
</plugin>

<!-- Spot bugs -->
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
</plugin>

<!-- Produce OSGi manifest -->
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<configuration>
<instructions>
<Export-Package>
com.io7m.jdownload.api
</Export-Package>
</instructions>
<bnd><![CDATA[
Export-Package: com.io7m.jdownload.api
]]></bnd>
</configuration>
</plugin>
</plugins>
Expand Down
Expand Up @@ -37,6 +37,7 @@
typeModifiable = "*Mutable",
builder = "builder",
build = "build",
allowedClasspathAnnotations = Override.class,
visibility = Value.Style.ImplementationVisibility.PUBLIC,
defaults = @Value.Immutable(copy = false))
public @interface DownloadImmutableStyleType
Expand Down
Expand Up @@ -53,7 +53,7 @@ static int writeBufferSizeDefault()

static String userAgentDefault()
{
final Package pack = DownloadRequest.class.getPackage();
final Package pack = DownloadRequestType.class.getPackage();
final String version = pack.getImplementationVersion();
return new StringBuilder(32)
.append("com.io7m.jdownload ")
Expand Down
18 changes: 17 additions & 1 deletion com.io7m.jdownload.cmdline/pom.xml
Expand Up @@ -15,7 +15,7 @@
<artifactId>com.io7m.jdownload.cmdline</artifactId>
<packaging>jar</packaging>

<name>com.io7m.jdownload.api</name>
<name>com.io7m.jdownload.cmdline</name>
<description>Simple HTTP downloads (Command line tool)</description>
<url>http://io7m.github.io/jdownload/</url>

Expand All @@ -34,6 +34,10 @@
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand All @@ -47,6 +51,18 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>

<!-- Ignore dependencies that bytecode analysis gets wrong. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<failOnWarning>true</failOnWarning>
<ignoredUnusedDeclaredDependencies>
<ignoredUnusedDeclaredDependency>ch.qos.logback:logback-classic:*</ignoredUnusedDeclaredDependency>
</ignoredUnusedDeclaredDependencies>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
61 changes: 15 additions & 46 deletions com.io7m.jdownload.tests/pom.xml
Expand Up @@ -34,69 +34,23 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<scope>test</scope>
</dependency>

<!-- To avoid compiler warnings about @API annotations in JUnit code -->
<dependency>
<groupId>org.apiguardian</groupId>
<artifactId>apiguardian-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${com.io7m.junit-platform-surefire-provider.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${com.io7m.junit.version}</version>
</dependency>
</dependencies>
<configuration>
<includes>
<include>**/Test*.java</include>
<include>**/*Test.java</include>
<include>**/*Tests.java</include>
<include>**/*TestCase.java</include>
</includes>
</configuration>
</plugin>

<!-- Check style -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -108,6 +62,21 @@
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>

<!-- Ignore dependencies that bytecode analysis gets wrong. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<failOnWarning>true</failOnWarning>
<ignoredUnusedDeclaredDependencies>
<ignoredUnusedDeclaredDependency>org.junit.jupiter:*:*</ignoredUnusedDeclaredDependency>
<ignoredUnusedDeclaredDependency>${project.groupId}:*:*</ignoredUnusedDeclaredDependency>
<ignoredUnusedDeclaredDependency>org.jmockit:jmockit:*</ignoredUnusedDeclaredDependency>
<ignoredUnusedDeclaredDependency>ch.qos.logback:logback-classic:*</ignoredUnusedDeclaredDependency>
</ignoredUnusedDeclaredDependencies>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Expand Up @@ -22,7 +22,6 @@
import com.io7m.jdownload.vanilla.DownloaderVanilla;
import mockit.Expectations;
import mockit.Mocked;
import org.junit.Assert;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -41,17 +40,14 @@
import java.time.Instant;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalUnit;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

public final class DownloaderVanillaTest
{
Expand Down
29 changes: 19 additions & 10 deletions com.io7m.jdownload.vanilla/pom.xml
Expand Up @@ -13,7 +13,7 @@
</parent>

<artifactId>com.io7m.jdownload.vanilla</artifactId>
<packaging>bundle</packaging>
<packaging>jar</packaging>

<name>com.io7m.jdownload.vanilla</name>
<description>Simple HTTP downloads (Vanilla implementation)</description>
Expand All @@ -40,17 +40,26 @@
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>

<!-- Produce OSGi bundle -->
<!-- Analyze semantic versioning -->
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-baseline-maven-plugin</artifactId>
</plugin>

<!-- Spot bugs -->
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
</plugin>

<!-- Produce OSGi manifest -->
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<configuration>
<instructions>
<Export-Package>
com.io7m.jdownload.vanilla
</Export-Package>
</instructions>
<bnd><![CDATA[
Export-Package: com.io7m.jdownload.vanilla
]]></bnd>
</configuration>
</plugin>
</plugins>
Expand Down
Expand Up @@ -129,6 +129,7 @@ public DownloadType download(
this.connections,
request,
new CompletableFuture<>());

executor.submit(download);
return download;
}
Expand Down Expand Up @@ -235,31 +236,33 @@ public Path call()
private Path download()
throws Exception
{
final URI source_uri = this.request.source();
final HttpURLConnection head_connection =
this.connections.connectionFor(this.request.source());
this.connections.connectionFor(source_uri);

final String agent = this.request.userAgent();
LOG.debug("HEAD {}", this.request.source());
LOG.debug("HEAD {}", source_uri);
head_connection.setRequestMethod("HEAD");
head_connection.setRequestProperty("User-Agent", agent);
head_connection.connect();

final int head_code = head_connection.getResponseCode();
LOG.debug(
"HEAD {}: {}",
this.request.source(),
source_uri,
Integer.valueOf(head_code));

final String separator = System.lineSeparator();
if (head_code >= 400) {
throw new IOException(
new StringBuilder(128)
.append("Download failed.")
.append(System.lineSeparator())
.append(separator)
.append(" Status: ")
.append(head_code)
.append(" - ")
.append(head_connection.getResponseMessage())
.append(System.lineSeparator())
.append(separator)
.toString());
}

Expand All @@ -269,9 +272,10 @@ private Path download()
Instant.ofEpochMilli(head_connection.getLastModified());

final Instant local_modified;
if (Files.isRegularFile(this.request.temporaryFile())) {
final Path temporary_file = this.request.temporaryFile();
if (Files.isRegularFile(temporary_file)) {
local_modified = Files.getLastModifiedTime(
this.request.temporaryFile(),
temporary_file,
NOFOLLOW_LINKS).toInstant();
} else {
local_modified = this.clock.instant();
Expand All @@ -285,13 +289,13 @@ private Path download()
local_modified);

if (!resume_supported || local_data_is_stale) {
Files.deleteIfExists(this.request.temporaryFile());
Files.deleteIfExists(temporary_file);
}

final HttpURLConnection data_connection =
this.connections.connectionFor(this.request.source());
this.connections.connectionFor(source_uri);

LOG.debug("GET {}", this.request.source());
LOG.debug("GET {}", source_uri);
data_connection.setRequestMethod("GET");
data_connection.setRequestProperty("User-Agent", agent);
this.configureRangeRequest(resume_supported, data_connection);
Expand All @@ -300,27 +304,27 @@ private Path download()
final int data_code = data_connection.getResponseCode();
LOG.debug(
"GET {}: {}",
this.request.source(),
source_uri,
Integer.valueOf(data_code));

if (data_code >= 400) {
throw new IOException(
new StringBuilder(128)
.append("Download failed.")
.append(System.lineSeparator())
.append(separator)
.append(" Status: ")
.append(data_code)
.append(" - ")
.append(data_connection.getResponseMessage())
.append(System.lineSeparator())
.append(separator)
.toString());
}

try (InputStream input = data_connection.getInputStream()) {
try (OutputStream output =
new BufferedOutputStream(
Files.newOutputStream(
this.request.temporaryFile(), CREATE, APPEND, WRITE),
temporary_file, CREATE, APPEND, WRITE),
this.request.writeBufferSize())) {
this.bytes_expected = server_size;
return this.downloadData(input, output, server_size);
Expand Down Expand Up @@ -392,19 +396,20 @@ private Path downloadData(

final long received_size = Files.size(file_tmp);
if (received_size != expected_size) {
final String separator = System.lineSeparator();
throw new IOException(
new StringBuilder(128)
.append(
"Resulting file size did not match the expected size.")
.append(System.lineSeparator())
.append(separator)
.append(" Expected: ")
.append(Long.toUnsignedString(expected_size))
.append(" octets")
.append(System.lineSeparator())
.append(separator)
.append(" Received: ")
.append(Long.toUnsignedString(received_size))
.append(" octets")
.append(System.lineSeparator())
.append(separator)
.toString());
}

Expand Down

0 comments on commit d291103

Please sign in to comment.