Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use frontend-maven-plugin configuration of parent POM #222

Merged
merged 3 commits into from
Sep 16, 2023
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
Empty file added .mvn_exec_node
Empty file.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"remark-preset-lint-recommended": "6.1.3"
},
"scripts": {
"lint-md": "remark ."
"lint-md": "remark .",
"mvnbuild": "",
"mvntest": ""
},
"remarkConfig": {
"plugins": [
Expand Down
29 changes: 1 addition & 28 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jvnet.hudson.plugins</groupId>
<artifactId>analysis-pom</artifactId>
<version>6.10.0</version>
<version>6.12.0</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -119,33 +119,6 @@
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.13.4</version>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<nodeVersion>v18.12.0</nodeVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

git pull
git push
mvn -B clean release:prepare release:perform
72 changes: 49 additions & 23 deletions src/main/java/io/jenkins/plugins/fontawesome/FontAwesomeIcons.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
package io.jenkins.plugins.fontawesome;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.*;
import java.util.*;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream;

import org.apache.commons.lang3.StringUtils;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import io.jenkins.plugins.fontawesome.SvgTag.FontAwesomeStyle;

/**
* Utility to work with icons provided by the font-awesome-api-plugin.
*
* @author strangelookingnerd
*/
public final class FontAwesomeIcons {

private static final Logger LOGGER = Logger.getLogger(FontAwesomeIcons.class.getName());
private static final String SVG_FILE_ENDING = ".svg";
private static final String IMAGES_SYMBOLS_PATH = "images/symbols/";
Expand All @@ -29,7 +40,9 @@
/**
* Takes an icon name and generates an icon class name from it.
*
* @param icon the icon name
* @param icon
* the icon name
*
* @return the icon class name
*/
public static String getIconClassName(final String icon) {
Expand All @@ -39,8 +52,7 @@
/**
* Get all available icons provided by the font-awesome-api-plugin.
*
* @return a sorted map of available icons with icon name as key and the icon
* class name as value.
* @return a sorted map of available icons with icon name as key and the icon class name as value.
*/
public static Map<String, String> getAvailableIcons() {
return getAvailableIcons(null);
Expand All @@ -49,15 +61,17 @@
/**
* Get all available icons provided by the font-awesome-api-plugin filtered by their style.
*
* @param filter the style to filter
* @return a sorted map of available icons with icon name as key and the icon
* class name as value filtered by the given style.
* @param filter
* the style to filter
*
* @return a sorted map of available icons with icon name as key and the icon class name as value filtered by the
* given style.
*/
public static Map<String, String> getAvailableIcons(final SvgTag.FontAwesomeStyle filter) {
public static Map<String, String> getAvailableIcons(@CheckForNull final FontAwesomeStyle filter) {
return getIconsFromClasspath(filter);
}

private static Map<String, String> getIconsFromClasspath(final SvgTag.FontAwesomeStyle filter) {
private static Map<String, String> getIconsFromClasspath(@CheckForNull final FontAwesomeStyle filter) {
try {
Enumeration<URL> urls = FontAwesomeIcons.class.getClassLoader().getResources(IMAGES_SYMBOLS_PATH);

Expand Down Expand Up @@ -85,27 +99,39 @@
return new LinkedHashMap<>();
}

private static Map<String, String> collectIcons(final Path path, @CheckForNull final SvgTag.FontAwesomeStyle filter) throws IOException {
@SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE")
private static Map<String, String> collectIcons(
@CheckForNull final Path path, @CheckForNull final FontAwesomeStyle filter) throws IOException {
Map<String, String> icons = new LinkedHashMap<>();

if (path != null) {
try (Stream<Path> stream = filter == null ? Files.walk(path, 2) : Files.walk(path.resolve(filter.name().toLowerCase(Locale.ENGLISH)), 1)) {
stream.filter(icon -> icon != null && icon.getFileName() != null && StringUtils.endsWith(icon.getFileName().toString(), SVG_FILE_ENDING))
try (Stream<Path> stream = findIcons(path, filter)) {
stream.filter(icon -> icon != null && icon.getFileName() != null && StringUtils.endsWith(

Check warning on line 109 in src/main/java/io/jenkins/plugins/fontawesome/FontAwesomeIcons.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 109 is only partially covered, 2 branches are missing
icon.getFileName().toString(), SVG_FILE_ENDING))

Check warning on line 110 in src/main/java/io/jenkins/plugins/fontawesome/FontAwesomeIcons.java

View check run for this annotation

ci.jenkins.io / SpotBugs

NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

LOW: Possible null pointer dereference in io.jenkins.plugins.fontawesome.FontAwesomeIcons.lambda$collectIcons$0(Path) due to return value of called method
Raw output
<p> The return value from a method is dereferenced without a null check, and the return value of that method is one that should generally be checked for null. This may lead to a <code>NullPointerException</code> when the code is executed. </p>
.sorted().forEach(icon -> {
if (icon.getParent() != null && icon.getParent().getFileName() != null && icon.getFileName() != null) {
String iconName = icon.getParent().getFileName() + "/" + StringUtils.removeEnd(icon.getFileName().toString(), SVG_FILE_ENDING);
icons.put(iconName, getIconClassName(iconName));
}
}
if (icon.getParent() != null && icon.getParent().getFileName() != null

Check warning on line 112 in src/main/java/io/jenkins/plugins/fontawesome/FontAwesomeIcons.java

View check run for this annotation

ci.jenkins.io / SpotBugs

NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

LOW: Possible null pointer dereference in io.jenkins.plugins.fontawesome.FontAwesomeIcons.lambda$collectIcons$1(Map, Path) due to return value of called method
Raw output
<p> The return value from a method is dereferenced without a null check, and the return value of that method is one that should generally be checked for null. This may lead to a <code>NullPointerException</code> when the code is executed. </p>

Check warning on line 112 in src/main/java/io/jenkins/plugins/fontawesome/FontAwesomeIcons.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 112 is only partially covered, 2 branches are missing
&& icon.getFileName() != null) {

Check warning on line 113 in src/main/java/io/jenkins/plugins/fontawesome/FontAwesomeIcons.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 113 is only partially covered, one branch is missing
String iconName = icon.getParent().getFileName() + "/" + StringUtils.removeEnd(
icon.getFileName().toString(), SVG_FILE_ENDING);

Check warning on line 115 in src/main/java/io/jenkins/plugins/fontawesome/FontAwesomeIcons.java

View check run for this annotation

ci.jenkins.io / SpotBugs

NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

LOW: Possible null pointer dereference in io.jenkins.plugins.fontawesome.FontAwesomeIcons.lambda$collectIcons$1(Map, Path) due to return value of called method
Raw output
<p> The return value from a method is dereferenced without a null check, and the return value of that method is one that should generally be checked for null. This may lead to a <code>NullPointerException</code> when the code is executed. </p>
icons.put(iconName, getIconClassName(iconName));
}
}
);
}
}

return icons;
}

private static Stream<Path> findIcons(final Path path, @CheckForNull final FontAwesomeStyle filter) throws IOException {
if (filter == null) {
return Files.walk(path, 2);
}

return Files.walk(path.resolve(filter.name().toLowerCase(Locale.ENGLISH)), 1);
}

private FontAwesomeIcons() {
// hidden
}

}