Skip to content

Commit

Permalink
Cleanup project
Browse files Browse the repository at this point in the history
  • Loading branch information
valery1707 committed Dec 5, 2018
1 parent 2a68350 commit 1fafcb4
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 80 deletions.
2 changes: 2 additions & 0 deletions src/main/java/name/valery1707/kaitai/KaitaiException.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package name.valery1707.kaitai;

@SuppressWarnings("WeakerAccess")
public class KaitaiException extends Exception {
@SuppressWarnings("unused")
public KaitaiException(String message) {
super(message);
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/name/valery1707/kaitai/KaitaiGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static java.util.Collections.unmodifiableSet;
import static name.valery1707.kaitai.MojoUtils.*;

@SuppressWarnings("WeakerAccess")
public class KaitaiGenerator {
private final Path kaitai;
private final Path output;
Expand Down Expand Up @@ -77,8 +78,6 @@ public KaitaiGenerator overwrite(boolean overwrite) {

private ProcBuilder process(Log log) {
return new ProcBuilder(getKaitai().normalize().toAbsolutePath().toString())
// return new ProcBuilder(getKaitai().getFileName().toString())
// .withWorkingDirectory(getKaitai().getParent().toFile())
.withErrorStream(LogWriter.logError(log))
.withOutputStream(LogWriter.logInfo(log))
.withExpectedExitStatuses(0)
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/name/valery1707/kaitai/KaitaiMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
Expand All @@ -16,7 +15,6 @@
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;

Expand Down Expand Up @@ -128,7 +126,7 @@ public class KaitaiMojo extends AbstractMojo {
/**
* Executes the plugin, to read the given source and behavioural properties and generate POJOs.
*/
public void execute() throws MojoExecutionException, MojoFailureException {
public void execute() throws MojoExecutionException {
if (skip) {
getLog().info("Skip KaiTai generation: skip=true");
return;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/name/valery1707/kaitai/LogWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import java.io.OutputStream;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@SuppressWarnings("WeakerAccess")
public class LogWriter extends Writer {
public enum Mode {
INFO,
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/name/valery1707/kaitai/MojoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static java.lang.String.format;
import static org.apache.commons.lang3.StringUtils.removeStart;

@SuppressWarnings("WeakerAccess")
public final class MojoUtils {
private MojoUtils() {
}
Expand Down Expand Up @@ -151,6 +152,7 @@ private static void move(Path source, Path target) throws MojoExecutionException
}
}

@SuppressWarnings("UnnecessarySemicolon")
public static void download(URL source, Path target, Log log) throws MojoExecutionException {
if (Files.exists(target)) {
return;
Expand Down Expand Up @@ -178,6 +180,7 @@ public static void download(URL source, Path target, Log log) throws MojoExecuti
move(temp, target);
}

@SuppressWarnings("UnnecessarySemicolon")
public static Path unpack(Path zip, Log log) throws MojoExecutionException {
String filename = zip.getFileName().toString();
String extension = FilenameUtils.getExtension(filename);
Expand Down
72 changes: 0 additions & 72 deletions src/main/java/name/valery1707/kaitai/MyMojo.java

This file was deleted.

6 changes: 4 additions & 2 deletions src/test/java/name/valery1707/kaitai/MojoUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,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[]{"My*.java", "*Test.java"});
List<Path> files = MojoUtils.scanFiles(new File(".").toPath(), new String[]{"*.java"}, new String[]{"Log*.java", "*Test.java"});
assertThat(files)
.isNotEmpty()
.contains(
Expand All @@ -82,7 +82,7 @@ public void testScanFiles() throws MojoExecutionException {
new File(".").toPath().resolve("src/main/java/name/valery1707/kaitai/KaitaiMojo.java"),
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/MyMojo.java"),
new File(".").toPath().resolve("src/main/java/name/valery1707/kaitai/LogWriter.java"),
new File(".").toPath().resolve("src/test/java/name/valery1707/kaitai/MojoUtilsTest.java")
)
;
Expand Down Expand Up @@ -110,6 +110,7 @@ public void testUnpack_exists() throws IOException, MojoExecutionException {
@Test
public void testUnpack_zipEntry_withPathStartingWithSlash() throws IOException, MojoExecutionException {
Path zip = temporaryFolder.newFile("malicious.zip").toPath();
//noinspection UnnecessarySemicolon
try (
OutputStream out = Files.newOutputStream(zip, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
ZipOutputStream zos = new ZipOutputStream(out);
Expand Down Expand Up @@ -146,6 +147,7 @@ public void testDownload_success() throws IOException, MojoExecutionException, N
Files.copy(target, new DigestOutputStream(new NullOutputStream(), digest));
String hashActual = Hex.encodeHexString(digest.digest());

//noinspection UnnecessarySemicolon
try (
InputStream shaExpected = new URL(source.toExternalForm() + ".sha1").openStream();
) {
Expand Down

0 comments on commit 1fafcb4

Please sign in to comment.