Skip to content

Commit

Permalink
added PMD
Browse files Browse the repository at this point in the history
  • Loading branch information
sterlp committed Nov 2, 2023
1 parent 77d9c68 commit 9ffac13
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 24 deletions.
72 changes: 53 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.sterl.svg2png</groupId>
Expand All @@ -15,15 +15,16 @@
<name>SVG to PNG CLI util</name>

<description>
Manage your icons as SVG files and generate the needed PNG files into your projects as needed.
No "Web Service" needed, just an executable JAR file.
Manage your icons as SVG files and generate the needed PNG files into
your projects as needed.
No "Web Service" needed, just an executable JAR file.
</description>

<scm>
<url>https://github.com/sterlp/svg2png</url>
<connection>scm:git:[email protected]:sterlp/svg2png.git</connection>
<tag>v1.2.0</tag>
</scm>
</scm>

<licenses>
<license>
Expand Down Expand Up @@ -57,7 +58,7 @@
<java.version>1.8</java.version>
<batik.version>1.17</batik.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
Expand All @@ -69,7 +70,7 @@
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down Expand Up @@ -97,13 +98,13 @@
<artifactId>xmlgraphics-commons</artifactId>
<version>2.8</version>
</dependency>

<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.5.0</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand All @@ -121,14 +122,14 @@
<version>4.4.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<!--
https://junit.org/junit5/docs/current/user-guide/#writing-tests-parameterized-tests
https://junit.org/junit5/docs/current/user-guide/#writing-tests-parameterized-tests
-->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down Expand Up @@ -201,8 +202,37 @@
</profile>
</profiles>

<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.21.0</version>
</plugin>
</plugins>
</reporting>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.21.0</version>
<configuration>
<!-- failOnViolation is actually true by default, but can be
disabled -->
<failOnViolation>true</failOnViolation>
<!-- printFailingErrors is pretty useful -->
<printFailingErrors>true</printFailingErrors>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand All @@ -226,7 +256,8 @@
<minimizeJar>false</minimizeJar>
<createDependencyReducedPom>false</createDependencyReducedPom>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>org.sterl.svg2png.Main</Main-Class>
<X-Compile-Source-JDK>${java.version}</X-Compile-Source-JDK>
Expand Down Expand Up @@ -260,24 +291,27 @@
<artifactId>really-executable-jar-maven-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<!-- value of flags will be interpolated into the java invocation -->
<!-- value of flags will be interpolated into the java
invocation -->
<!-- as "java $flags -jar ..." -->
<flags>-Xmx1G</flags>

<!-- (optional) name for binary executable, if not set will just -->

<!-- (optional) name for binary executable, if not set will
just -->
<!-- make the regular jar artifact executable -->
<programFile>svg2png</programFile>

<!-- (optional) name for a file that will define what script
gets -->
<!-- embedded into the executable jar. This can be used to -->
<!-- override the default startup script which is -->
<!-- `#!/bin/sh -->
<!-- -->
<!-- exec java " + flags + " -jar "$0" "$@" -->
<!-- <scriptFile>src/packaging/someScript.extension</scriptFile> -->
<!--
<scriptFile>src/packaging/someScript.extension</scriptFile> -->
</configuration>

<executions>
<execution>
<phase>package</phase>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/sterl/svg2png/CliOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public enum CliOptions {
private final boolean hasArg;
private final String description;

private CliOptions(String shortName, String longName, boolean hasArg, String description) {
CliOptions(String shortName, String longName, boolean hasArg, String description) {
this.shortName = shortName;
this.longName = longName;
this.hasArg = hasArg;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/sterl/svg2png/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static List<File> run(String[] args) throws Svg2PngException {
}

// validation
if (!cfg.hasDirectoryOrFile() || (cfg.getInputDirectory() != null && cfg.getInputFile() != null)) {
if (!cfg.hasDirectoryOrFile()) {
throw new IllegalArgumentException("Please specify either a directory or a file to convert!");
} else if (cfg.getInputFile() != null) {
File f = FileUtil.newFile(cfg.getInputFile());
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/org/sterl/svg2png/Svg2Png.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ private static List<File> convertFile(File input, OutputConfig cfg) throws IOExc

generated.add(outputFile);
String outF = outputFile.getCanonicalPath();
if (inputPath != null && inputPath.length() > 0) outF.replace(inputPath, "");
if (inputPath != null && inputPath.length() > 0) {
outF = outF.replace(inputPath, "");
}
info.append("\t").append(outF);
}

Expand Down Expand Up @@ -138,7 +140,10 @@ private static File generateIOSContentJson(OutputConfig cfg) throws IOException,
return contents;
}

private static void replaceAlphaBackground(byte[] inputBytes, File outputFile, final Color newBackground) throws java.io.IOException {
private static void replaceAlphaBackground(byte[] inputBytes,
File outputFile,
final Color newBackground) throws IOException {

try (ByteArrayInputStream sourceStream = new ByteArrayInputStream(inputBytes)) {
BufferedImage sourceImage = ImageIO.read(sourceStream);

Expand All @@ -154,7 +159,7 @@ private static void replaceAlphaBackground(byte[] inputBytes, File outputFile, f

if (!ImageIO.write(destImage, "png", outputFile)) {
throw new RuntimeException("No image writer found in Graphics2D, cannot replace the background!");
};
}
}
}
}

0 comments on commit 9ffac13

Please sign in to comment.