Skip to content

Commit

Permalink
Use more general version for internal classes
Browse files Browse the repository at this point in the history
  • Loading branch information
valery1707 committed Dec 6, 2018
1 parent 1fafcb4 commit bf4c412
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import static org.apache.commons.lang3.StringUtils.removeStart;

@SuppressWarnings("WeakerAccess")
public final class MojoUtils {
private MojoUtils() {
public final class IoUtils {
private IoUtils() {
}

public static void checkFileIsReadable(Path target) throws MojoExecutionException {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/name/valery1707/kaitai/KaitaiGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.Set;

import static java.util.Collections.unmodifiableSet;
import static name.valery1707.kaitai.MojoUtils.*;
import static name.valery1707.kaitai.IoUtils.*;

@SuppressWarnings("WeakerAccess")
public class KaitaiGenerator {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/name/valery1707/kaitai/KaitaiMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.*;

import static java.lang.String.format;
import static name.valery1707.kaitai.MojoUtils.*;
import static name.valery1707.kaitai.IoUtils.*;

/**
* @see <a href="http://maven.apache.org/developers/mojo-api-specification.html">Mojo API Specification</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@
import java.util.zip.ZipOutputStream;

import static java.nio.charset.StandardCharsets.UTF_8;
import static name.valery1707.kaitai.MojoUtils.checkFileIsExecutable;
import static name.valery1707.kaitai.MojoUtils.mkdirs;
import static name.valery1707.kaitai.IoUtils.*;
import static org.apache.commons.io.FilenameUtils.getName;
import static org.assertj.core.api.Assertions.assertThat;

public class MojoUtilsTest {
public class IoUtilsTest {
private static final SystemStreamLog LOG = new SystemStreamLog();

@Rule
Expand Down Expand Up @@ -72,7 +71,7 @@ public void testExecutable_windows() throws MojoExecutionException, IOException

@Test
public void testScanFiles() throws MojoExecutionException {
List<Path> files = MojoUtils.scanFiles(new File(".").toPath(), new String[]{"*.java"}, new String[]{"Log*.java", "*Test.java"});
List<Path> files = scanFiles(new File(".").toPath(), new String[]{"*.java"}, new String[]{"Log*.java", "*Test.java"});
assertThat(files)
.isNotEmpty()
.contains(
Expand All @@ -83,15 +82,15 @@ public void testScanFiles() throws MojoExecutionException {
new File(".").toPath().resolve("src/main/java/name/valery1707/kaitai/KaitaiMojo.java").toAbsolutePath(),
new File(".").toPath().resolve("src/main/java/name/valery1707/kaitai/KaitaiMojo.java").normalize(),
new File(".").toPath().resolve("src/main/java/name/valery1707/kaitai/LogWriter.java"),
new File(".").toPath().resolve("src/test/java/name/valery1707/kaitai/MojoUtilsTest.java")
new File(".").toPath().resolve("src/test/java/name/valery1707/kaitai/IoUtilsTest.java")
)
;
}

@Test
public void testUnpack() throws IOException, MojoExecutionException {
Path zip = copy("/demo-vertx.zip");
Path target = MojoUtils.unpack(zip, LOG);
Path target = unpack(zip, LOG);
assertThat(target).exists().isDirectory();
assertThat(target.resolve("demo-vertx")).exists().isDirectory();
assertThat(target.resolve("demo-vertx/pom.xml")).exists().isRegularFile();
Expand All @@ -101,7 +100,7 @@ public void testUnpack() throws IOException, MojoExecutionException {
public void testUnpack_exists() throws IOException, MojoExecutionException {
Path zip = copy("/demo-vertx.zip");
Files.createDirectories(zip.resolveSibling("demo-vertx"));
Path target = MojoUtils.unpack(zip, LOG);
Path target = unpack(zip, LOG);
assertThat(target).exists().isDirectory();
assertThat(target.resolve("demo-vertx")).doesNotExist();
assertThat(target.resolve("demo-vertx/pom.xml")).doesNotExist();
Expand All @@ -124,7 +123,7 @@ public void testUnpack_zipEntry_withPathStartingWithSlash() throws IOException,
).getBytes(UTF_8)
);
}
Path target = MojoUtils.unpack(zip, LOG);
Path target = unpack(zip, LOG);
assertThat(target).exists().isDirectory();

//malicious directory at root path
Expand All @@ -140,7 +139,7 @@ public void testDownload_success() throws IOException, MojoExecutionException, N
Path target = temporaryFolder.newFile("assertj-core-2.9.0.jar").toPath();
Files.delete(target);
URL source = new URL("https://search.maven.org/remotecontent?filepath=org/assertj/assertj-core/2.9.0/assertj-core-2.9.0.jar");
MojoUtils.download(source, target, LOG);
download(source, target, LOG);
assertThat(target).exists().isRegularFile().isReadable();

MessageDigest digest = MessageDigest.getInstance("SHA1");
Expand All @@ -161,7 +160,7 @@ public void testDownload_success() throws IOException, MojoExecutionException, N
public void testDownload_noDownloadIfExists() throws IOException, MojoExecutionException {
Path target = temporaryFolder.newFile("assertj-core-2.9.0.jar").toPath();
URL source = new URL("https://search.maven.org/remotecontent?filepath=org/assertj/assertj-core/2.9.0/assertj-core-2.9.0.jar");
MojoUtils.download(source, target, LOG);
download(source, target, LOG);
assertThat(target)
.exists()
.isRegularFile()
Expand All @@ -174,7 +173,7 @@ public void testDownload_404() throws IOException, MojoExecutionException {
Path target = temporaryFolder.newFile("assertj-core-2.9.0.jar").toPath();
Files.delete(target);
URL source = new URL("https://search.maven.org/remotecontent?filepath=org/assertj/assertj-core/2.7.0/assertj-core-2.9.0.jar");
MojoUtils.download(source, target, LOG);
download(source, target, LOG);
throw new IllegalStateException("Unreachable statement");
}
}

0 comments on commit bf4c412

Please sign in to comment.