From 1fafcb47bc66e277f7faf69b380b1ae0a80f9680 Mon Sep 17 00:00:00 2001 From: "Valeriy.Vyrva" Date: Wed, 5 Dec 2018 18:23:37 +0300 Subject: [PATCH] Cleanup project --- .../valery1707/kaitai/KaitaiException.java | 2 + .../valery1707/kaitai/KaitaiGenerator.java | 3 +- .../name/valery1707/kaitai/KaitaiMojo.java | 4 +- .../name/valery1707/kaitai/LogWriter.java | 2 +- .../name/valery1707/kaitai/MojoUtils.java | 3 + .../java/name/valery1707/kaitai/MyMojo.java | 72 ------------------- .../name/valery1707/kaitai/MojoUtilsTest.java | 6 +- 7 files changed, 12 insertions(+), 80 deletions(-) delete mode 100644 src/main/java/name/valery1707/kaitai/MyMojo.java diff --git a/src/main/java/name/valery1707/kaitai/KaitaiException.java b/src/main/java/name/valery1707/kaitai/KaitaiException.java index 8db9e14..d449cfb 100644 --- a/src/main/java/name/valery1707/kaitai/KaitaiException.java +++ b/src/main/java/name/valery1707/kaitai/KaitaiException.java @@ -1,6 +1,8 @@ package name.valery1707.kaitai; +@SuppressWarnings("WeakerAccess") public class KaitaiException extends Exception { + @SuppressWarnings("unused") public KaitaiException(String message) { super(message); } diff --git a/src/main/java/name/valery1707/kaitai/KaitaiGenerator.java b/src/main/java/name/valery1707/kaitai/KaitaiGenerator.java index cb2cd48..729c090 100644 --- a/src/main/java/name/valery1707/kaitai/KaitaiGenerator.java +++ b/src/main/java/name/valery1707/kaitai/KaitaiGenerator.java @@ -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; @@ -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) diff --git a/src/main/java/name/valery1707/kaitai/KaitaiMojo.java b/src/main/java/name/valery1707/kaitai/KaitaiMojo.java index 4cded43..36a680a 100644 --- a/src/main/java/name/valery1707/kaitai/KaitaiMojo.java +++ b/src/main/java/name/valery1707/kaitai/KaitaiMojo.java @@ -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; @@ -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.*; @@ -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; diff --git a/src/main/java/name/valery1707/kaitai/LogWriter.java b/src/main/java/name/valery1707/kaitai/LogWriter.java index 40543fc..ef4ed9e 100644 --- a/src/main/java/name/valery1707/kaitai/LogWriter.java +++ b/src/main/java/name/valery1707/kaitai/LogWriter.java @@ -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, diff --git a/src/main/java/name/valery1707/kaitai/MojoUtils.java b/src/main/java/name/valery1707/kaitai/MojoUtils.java index 691642d..6527091 100644 --- a/src/main/java/name/valery1707/kaitai/MojoUtils.java +++ b/src/main/java/name/valery1707/kaitai/MojoUtils.java @@ -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() { } @@ -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; @@ -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); diff --git a/src/main/java/name/valery1707/kaitai/MyMojo.java b/src/main/java/name/valery1707/kaitai/MyMojo.java deleted file mode 100644 index fcd7316..0000000 --- a/src/main/java/name/valery1707/kaitai/MyMojo.java +++ /dev/null @@ -1,72 +0,0 @@ -package name.valery1707.kaitai; - -/* - * Copyright 2001-2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; - -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.plugins.annotations.ResolutionScope; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; - -/** - * Goal which touches a timestamp file. - * - * @deprecated Don't use! - */ -@Mojo(name = "touch", defaultPhase = LifecyclePhase.PROCESS_SOURCES) -public class MyMojo extends AbstractMojo { - - /** - * Location of the file. - */ - @Parameter(defaultValue = "${project.build.directory}", property = "outputDir", required = true) - private File outputDirectory; - - public void execute() - throws MojoExecutionException { - File f = outputDirectory; - - if (!f.exists()) { - f.mkdirs(); - } - - File touch = new File(f, "touch.txt"); - - FileWriter w = null; - try { - w = new FileWriter(touch); - - w.write("touch.txt"); - } catch (IOException e) { - throw new MojoExecutionException("Error creating file " + touch, e); - } finally { - if (w != null) { - try { - w.close(); - } catch (IOException e) { - // ignore - } - } - } - } -} diff --git a/src/test/java/name/valery1707/kaitai/MojoUtilsTest.java b/src/test/java/name/valery1707/kaitai/MojoUtilsTest.java index 6a177f3..6c99404 100644 --- a/src/test/java/name/valery1707/kaitai/MojoUtilsTest.java +++ b/src/test/java/name/valery1707/kaitai/MojoUtilsTest.java @@ -72,7 +72,7 @@ public void testExecutable_windows() throws MojoExecutionException, IOException @Test public void testScanFiles() throws MojoExecutionException { - List files = MojoUtils.scanFiles(new File(".").toPath(), new String[]{"*.java"}, new String[]{"My*.java", "*Test.java"}); + List files = MojoUtils.scanFiles(new File(".").toPath(), new String[]{"*.java"}, new String[]{"Log*.java", "*Test.java"}); assertThat(files) .isNotEmpty() .contains( @@ -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") ) ; @@ -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); @@ -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(); ) {