Skip to content

Commit

Permalink
Remove Commons Lang/IO dependency
Browse files Browse the repository at this point in the history
Update Commons CSV dependency
  • Loading branch information
kwin committed Oct 10, 2024
1 parent c494ff5 commit a0f5bc7
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build Site for Maven Plugin
if: github.ref != 'refs/heads/master'
run: mvn -B clean site --file aem-classification-maven-plugin/pom.xml
run: ./mvnw -B clean site --file aem-classification-maven-plugin/pom.xml
- name: Build, Analyse and Deploy Reactor with Maven
if: github.ref == 'refs/heads/master'
run: ./mvnw -B clean deploy org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=Netcentric_aem-classification -Dsonar.organization=netcentric -Dsonar.host.url=https://sonarcloud.io -Pcoverage-report
Expand All @@ -51,6 +51,7 @@ jobs:
with:
path: aem-classification-maven-plugin/target/site/
deploy:
if: github.ref == 'refs/heads/master'
# Add a dependency to the build job
needs: build
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
Expand Down
12 changes: 1 addition & 11 deletions aem-classification-validator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.7</version>
<version>1.12.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
import org.apache.jackrabbit.vault.util.DocViewNode;
import org.apache.jackrabbit.vault.validation.spi.DocumentViewXmlValidator;
Expand Down Expand Up @@ -230,7 +229,7 @@ private static boolean isJspFile(Path file) {
}

static @NotNull String extendMessageWithRemark(@NotNull String message, String remark) {
if (StringUtils.isNotBlank(remark)) {
if (remark != null && !remark.isEmpty()) {
return message + " Remark: " + remark;
}
return message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.apache.jackrabbit.vault.validation.spi.ValidationContext;
import org.apache.jackrabbit.vault.validation.spi.ValidationMessageSeverity;
import org.apache.jackrabbit.vault.validation.spi.Validator;
Expand Down Expand Up @@ -61,7 +60,7 @@ public class AemClassificationValidatorFactory implements ValidatorFactory {
public Validator createValidator(@NotNull ValidationContext context, @NotNull ValidatorSettings settings) {
String mapUrls = settings.getOptions().get(OPTION_MAPS);
// either load map from classpath, from filesystem or from generic url
if (StringUtils.isBlank(mapUrls)) {
if (mapUrls == null || mapUrls.isEmpty()) {
throw new IllegalArgumentException("Mandatory option " + OPTION_MAPS + " missing!");
}
String optionWhitelistedResourcePaths = null;
Expand Down Expand Up @@ -125,7 +124,7 @@ static Map<ContentClassification, ValidationMessageSeverity> getSeverityPerClass
private static Map<ContentClassification, ValidationMessageSeverity> parseSeverityClassification(List<String> severities) {
Map<ContentClassification, ValidationMessageSeverity> result = severities.stream()
.map(severity -> severity.split("="))
.filter(arr -> arr.length == 2 && !StringUtils.isEmpty(arr[0]) && !StringUtils.isEmpty(arr[1]))
.filter(arr -> arr.length == 2 && !arr[0].isEmpty() && !arr[1].isEmpty())
.collect(Collectors.toMap(s -> ContentClassification.valueOf(s[0].trim()),
s -> ValidationMessageSeverity.valueOf(s[1].trim())));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface MutableContentClassificationMap extends ContentClassificationMa

/**
* Writes the map to a given output stream.
* Leaves the output stream open.
* Closes the stream upon completion.
*
* @param outputStream the stream to write to
* @throws IOException in case of any exception during writing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVRecord;
import org.apache.commons.lang.StringUtils;
import org.apache.jackrabbit.util.Text;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -59,7 +58,7 @@ public class ContentClassificationMapImpl implements ContentClassificationMap {
protected final Map<String, String> remarkMap; // key = absolute repository path
private String label;

private static final CSVFormat CSV_FORMAT = CSVFormat.RFC4180.withCommentMarker('#');
static final CSVFormat CSV_FORMAT = CSVFormat.Builder.create(CSVFormat.RFC4180).setCommentMarker('#').build();
private static final Logger LOGGER = LoggerFactory.getLogger(ContentClassificationMapImpl.class);

public ContentClassificationMapImpl(String label) {
Expand Down Expand Up @@ -101,7 +100,7 @@ protected void put(@NotNull String resourcePath, @NotNull ContentClassification
throw new IllegalArgumentException("Only absolute resource paths are supported, but resource path given is '" + resourcePath + "'.");
}
classificationMap.put(resourcePath, classification);
if (StringUtils.isNotEmpty(remark)) {
if (remark != null && !remark.isEmpty()) {
remarkMap.put(resourcePath, remark);
}
}
Expand All @@ -110,7 +109,7 @@ protected void put(@NotNull String resourcePath, @NotNull ContentClassification
@NotNull
public Entry<ContentClassification, String> getContentClassificationAndRemarkForResourcePath(@NotNull String resourcePath, @Nullable Collection<Pattern> whitelistedResourcePaths) {
// ignore empty resourceTypes
if (StringUtils.isBlank(resourcePath)) {
if (resourcePath.isEmpty()) {
return new SimpleEntry<>(ContentClassification.PUBLIC, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
import java.util.LinkedList;
import java.util.Map.Entry;

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;
import org.apache.commons.io.output.CloseShieldOutputStream;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -36,8 +33,6 @@
*/
public class MutableContentClassificationMapImpl extends ContentClassificationMapImpl implements MutableContentClassificationMap {

private static final CSVFormat CSV_FORMAT = CSVFormat.RFC4180.withCommentMarker('#');

public MutableContentClassificationMapImpl(@NotNull String label) {
super(label);
}
Expand All @@ -49,14 +44,14 @@ public void put(@NotNull String resourcePath, @NotNull ContentClassification cla

@Override
public void write(@NotNull OutputStream output) throws IOException {
try (CSVPrinter csvPrinter = new CSVPrinter(new OutputStreamWriter(new CloseShieldOutputStream(output), StandardCharsets.US_ASCII), CSV_FORMAT)) {
try (CSVPrinter csvPrinter = new CSVPrinter(new OutputStreamWriter(output, StandardCharsets.US_ASCII), CSV_FORMAT)) {
csvPrinter.printComment(getLabel());
for (Entry<String, ContentClassification> entry : classificationMap.entrySet()) {
Collection<String> values = new LinkedList<>();
values.add(entry.getKey()); // resource type
values.add(entry.getValue().toString());
String remark = remarkMap.get(entry.getKey());
if (StringUtils.isNotEmpty(remark)) {
if (remark != null && !remark.isEmpty()) {
values.add(remark);
}
csvPrinter.printRecord(values);
Expand Down

0 comments on commit a0f5bc7

Please sign in to comment.