Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,37 @@
import java.nio.file.Paths;
import java.nio.file.attribute.PosixFilePermission;
import java.util.EnumSet;
import java.util.List;
import java.util.stream.Collectors;

import com.g2forge.alexandria.java.close.ICloseableSupplier;
import com.g2forge.alexandria.java.core.helpers.HCollection;
import com.g2forge.alexandria.java.io.HBinaryIO;
import com.g2forge.alexandria.java.io.RuntimeIOException;
import com.g2forge.alexandria.java.platform.HPlatform;

public class HCLIReport {
public static final String CLIREPORT_VERSION = "v0.0.1";
public static final String CLIREPORT_VERSION = "v0.0.2";

public static final String CLIREPORT_FILENAME = "clireport";

public static final String CLIREPORT_DOWNLOADFORMAT = "https://github.com/g2forge/clireport/releases/download/%1$s/%2$s";

public static List<String> computeExpectedOutput(final List<String> arguments) {
return HCollection.concatenate(HCollection.asList(String.format("CLIReport: %1$d arguments", arguments.size())), arguments.stream().map(argument -> String.format("%1$04d: %2$s", argument.length(), argument)).collect(Collectors.toList()));
}

public static List<String> computeExpectedOutput(String executable, String... arguments) {
return computeExpectedOutput(HCollection.concatenate(HCollection.asList(executable), HCollection.asList(arguments)));
}

public static ICloseableSupplier<Path> download(Path directory) {
final String filename = HPlatform.getPlatform().getExeSpecs()[0].fromBase(CLIREPORT_FILENAME);
final Path path = directory == null ? Paths.get(filename) : directory.resolve(filename);
if (!Files.exists(path)) {
final String url = String.format(CLIREPORT_DOWNLOADFORMAT, CLIREPORT_VERSION, path.getFileName().toString());
try (final InputStream input = new URL(url).openStream(); final OutputStream output = Files.newOutputStream(path)) {
try (final InputStream input = new URL(url).openStream();
final OutputStream output = Files.newOutputStream(path)) {
HBinaryIO.copy(input, output);
} catch (IOException e) {
throw new RuntimeIOException("Failed to download clireport", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.junit.Assume;
import org.junit.Before;
Expand Down Expand Up @@ -105,7 +104,7 @@ protected void test(String... arguments) throws IOException, InterruptedExceptio
}
HAssert.assertEquals(0, exitCode);

final List<String> expected = HCollection.concatenate(HCollection.asList(String.format("CLIReport: %1$d arguments", invocation.getArguments().size())), invocation.getArguments().stream().map(argument -> String.format("%1$04d: %2$s", argument.length(), argument)).collect(Collectors.toList()));
final List<String> expected = HCLIReport.computeExpectedOutput(invocation.getArguments());
HAssert.assertEquals(expected, output);
}
}