Skip to content

Commit

Permalink
Merge branch 'master' into pr/4967
Browse files Browse the repository at this point in the history
  • Loading branch information
oowekyala committed Apr 23, 2024
2 parents b42108d + f308115 commit 3765e45
Show file tree
Hide file tree
Showing 38 changed files with 1,122 additions and 131 deletions.
76 changes: 76 additions & 0 deletions docs/images/logo/PMD_small.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/logo/favicon.ico
Binary file not shown.
Binary file added docs/images/logo/pmd-logo-small-300px.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/logo/pmd-logo-small-64px.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/logo/pmd-logo-small-white-300px.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/logo/pmd-logo-small-white-64px.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion docs/pages/pmd/projectdocs/logo.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ The following PMD Logos and Icons are licensed under [CC BY 4.0](https://creativ
* [Logo (600px, white)](images/logo/pmd-logo-white-600px.png)
* [Logo (600px, white, suqare shape)](images/logo/pmd-logo-white-600px-squared.png)

* [Favicon (16x16)](images/logo/favicon.ico)
Small variants, square shaped:
* [PMD_small.svg](images/logo/PMD_small.svg)
* [Small Logo (64px, transparent)](images/logo/pmd-logo-small-64px.png)
* [Small Logo (64px, white)](images/logo/pmd-logo-small-white-64px.png)
* [Small Logo (300px, transparent)](images/logo/pmd-logo-small-300px.png)
* [Small Logo (300px, white)](images/logo/pmd-logo-small-white-300px.png)
* [Favicon (32x32)](images/logo/favicon.ico)

This new greenish logo was introduced with PMD 7.

Expand Down
15 changes: 15 additions & 0 deletions docs/pages/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ This is a {{ site.pmd.release_type }} release.

### 🚀 New and noteworthy

### ✨ New rules

- The new Java rule {%rule java/bestpractices/UnnecessaryVarargsArrayCreation %} reports explicit array creation
when a varargs is expected. This is more heavy to read and could be simplified.

- The new Java rule {% rule "java/codestyle/LambdaCanBeMethodReference" %} reports lambda expressions that can be replaced
with a method reference. Please read the documentation of the rule for more info. This rule is now part of the Quickstart
ruleset.

### 🌟 Rule Changes

* {%rule java/bestpractices/JUnitTestsShouldIncludeAssert %} and {% rule java/bestpractices/JUnitTestContainsTooManyAsserts %}
Expand All @@ -23,6 +32,8 @@ This is a {{ site.pmd.release_type }} release.
### 🐛 Fixed Issues
* core
* [#494](https://github.com/pmd/pmd/issues/494): \[core] Adopt JApiCmp to enforce control over API changes
* [#4942](https://github.com/pmd/pmd/issues/4942): \[core] CPD: `--skip-duplicate-files` has no effect (7.0.0 regression)
* [#4959](https://github.com/pmd/pmd/pull/4959): \[core] Upgrade saxon to 12.4
* cli
* [#4791](https://github.com/pmd/pmd/issues/4791): \[cli] Could not find or load main class
* [#4913](https://github.com/pmd/pmd/issues/4913): \[cli] cpd-gui closes immediately
Expand All @@ -38,6 +49,7 @@ This is a {{ site.pmd.release_type }} release.
* [#4947](https://github.com/pmd/pmd/issues/4947): \[java] Broken TextBlock parser
* java-bestpractices
* [#1084](https://github.com/pmd/pmd/issues/1084): \[java] Allow JUnitTestsShouldIncludeAssert to configure verification methods
* [#3216](https://github.com/pmd/pmd/issues/3216): \[java] New rule: UnnecessaryVarargsArrayCreation
* [#4435](https://github.com/pmd/pmd/issues/4435): \[java] \[7.0-rc1] UnusedAssignment for used field
* [#4569](https://github.com/pmd/pmd/issues/4569): \[java] ForLoopCanBeForeach reports on loop `for (int i = 0; i < list.size(); i += 2)`
* [#4618](https://github.com/pmd/pmd/issues/4618): \[java] UnusedAssignment false positive with conditional assignments of fields
Expand All @@ -47,10 +59,12 @@ This is a {{ site.pmd.release_type }} release.
* [#4779](https://github.com/pmd/pmd/issues/4779): \[java] Examples in documentation of MethodArgumentCanBeFinal do not trigger the rule
* [#4881](https://github.com/pmd/pmd/issues/4881): \[java] ClassNamingConventions: interfaces are identified as abstract classes (regression in 7.0.0)
* java-design
* [#2440](https://github.com/pmd/pmd/issues/2440): \[java] FinalFieldCouldBeStatic FN when the right side of the assignment is a constant expression
* [#3694](https://github.com/pmd/pmd/issues/3694): \[java] SingularField ignores static variables
* [#4873](https://github.com/pmd/pmd/issues/4873): \[java] AvoidCatchingGenericException: Can no longer suppress on the exception itself
* java-errorprone
* [#2056](https://github.com/pmd/pmd/issues/2056): \[java] CloseResource false-positive with URLClassLoader in cast expression
* [#4751](https://github.com/pmd/pmd/issues/4751): \[java] PMD crashes when analyzing CloseResource Rule
* [#4928](https://github.com/pmd/pmd/issues/4928): \[java] EmptyCatchBlock false negative when allowCommentedBlocks=true
* java-performance
* [#3845](https://github.com/pmd/pmd/issues/3845): \[java] InsufficientStringBufferDeclaration should consider literal expression
Expand All @@ -65,6 +79,7 @@ This is a {{ site.pmd.release_type }} release.

#### Deprecated methods

* {% jdoc java::lang.java.ast.ASTLambdaExpression#getBlock() %} and {% jdoc java::lang.java.ast.ASTLambdaExpression#getExpression() %}
* {%jdoc java::lang.java.rule.design.SingularFieldRule#mayBeSingular(java::lang.java.ast.ModifierOwner) %} has been deprecated for
removal. The method is only useful for the rule itself and shouldn't be used otherwise.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@

import java.io.IOException;
import java.io.Reader;
import java.io.UncheckedIOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.sourceforge.pmd.AbstractConfiguration;
import net.sourceforge.pmd.cpd.CPDConfiguration;
import net.sourceforge.pmd.lang.document.FileCollector;
import net.sourceforge.pmd.lang.document.FileId;
import net.sourceforge.pmd.lang.document.InternalApiBridge;
Expand All @@ -36,6 +41,35 @@ private FileCollectionUtil() {

}

public static void collectFiles(CPDConfiguration cpdConfiguration, FileCollector collector) {
if (cpdConfiguration.isSkipDuplicates()) {
final Set<String> alreadyAddedFileNamesWithSize = new HashSet<>();
collector.setFileFilter(fileId -> {
Path path = Paths.get(fileId.getAbsolutePath());
if (!Files.isRegularFile(path)) {
// file is not a simple file, maybe inside a ZIP archive
// don't filter these out
LOG.debug("Path {} is not a regular file, skipping in fileFilter", path);
return true;
}

try {
String signature = path.getFileName() + "_" + Files.size(path);
if (!alreadyAddedFileNamesWithSize.add(signature)) {
LOG.info("Skipping {} since it appears to be a duplicate file and --skip-duplicate-files is set",
path);
return false;
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return true;
});
}

collectFiles((AbstractConfiguration) cpdConfiguration, collector);
}

public static void collectFiles(AbstractConfiguration configuration, FileCollector collector) {
if (configuration.getSourceEncoding() != null) {
collector.setCharset(configuration.getSourceEncoding());
Expand Down Expand Up @@ -77,23 +111,23 @@ public static void collectFiles(FileCollector collector, List<Path> filePaths) {
try {
addRoot(collector, rootLocation);
} catch (IOException e) {
collector.getReporter().errorEx("Error collecting " + rootLocation, e);
collector.getReporter().errorEx("Error collecting {0}", new Object[]{ rootLocation }, e);
}
}
}

public static void collectFileList(FileCollector collector, Path fileList) {
LOG.debug("Reading file list {}.", fileList);
if (!Files.exists(fileList)) {
collector.getReporter().error("No such file {}", fileList);
collector.getReporter().error("No such file {0}", fileList);
return;
}

List<Path> filePaths;
try {
filePaths = FileUtil.readFilelistEntries(fileList);
} catch (IOException e) {
collector.getReporter().errorEx("Error reading {}", new Object[] { fileList }, e);
collector.getReporter().errorEx("Error reading {0}", new Object[] { fileList }, e);
return;
}
collectFiles(collector, filePaths);
Expand Down Expand Up @@ -135,15 +169,15 @@ public static void collectDB(FileCollector collector, URI uri) {
String source = IOUtil.readToString(sourceCode);
collector.addSourceFile(FileId.fromPathLikeString(falseFilePath), source);
} catch (SQLException ex) {
collector.getReporter().warnEx("Cannot get SourceCode for {} - skipping ...",
collector.getReporter().warnEx("Cannot get SourceCode for {0} - skipping ...",
new Object[] { falseFilePath },
ex);
}
}
} catch (ClassNotFoundException e) {
collector.getReporter().errorEx("Cannot get files from DB - probably missing database JDBC driver", e);
} catch (Exception e) {
collector.getReporter().errorEx("Cannot get files from DB - ''{}''", new Object[] { uri }, e);
collector.getReporter().errorEx("Cannot get files from DB - ''{0}''", new Object[] { uri }, e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -60,6 +61,7 @@ public final class FileCollector implements AutoCloseable {
private final FileId outerFsPath;
private boolean closed;
private boolean recursive = true;
private Predicate<FileId> fileFilter = file -> true;

// construction

Expand Down Expand Up @@ -206,6 +208,12 @@ && addFileImpl(TextFile.builderForCharSeq(sourceContents, fileId, version)

private boolean addFileImpl(TextFile textFile) {
LOG.trace("Adding file {} (lang: {}) ", textFile.getFileId().getAbsolutePath(), textFile.getLanguageVersion().getTerseName());

if (!fileFilter.test(textFile.getFileId())) {
LOG.trace("File was skipped due to fileFilter...");
return false;
}

if (allFilesToProcess.add(textFile)) {
return true;
}
Expand Down Expand Up @@ -377,6 +385,17 @@ public void setCharset(Charset charset) {
this.charset = Objects.requireNonNull(charset);
}

/**
* Sets an additional filter that is being called before adding the
* file to the list.
*
* @param fileFilter the filter should return {@code true} if the file
* should be collected and analyzed.
* @throws NullPointerException if {@code fileFilter} is {@code null}.
*/
public void setFileFilter(Predicate<FileId> fileFilter) {
this.fileFilter = Objects.requireNonNull(fileFilter);
}

// filtering

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@

import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;

import net.sourceforge.pmd.lang.rule.xpath.Attribute;

import net.sf.saxon.om.AtomicSequence;
import net.sf.saxon.om.NodeInfo;
import net.sf.saxon.pattern.NodeTest;
import net.sf.saxon.tree.iter.AxisIterator;
import net.sf.saxon.tree.iter.EmptyIterator;
import net.sf.saxon.tree.util.FastStringBuffer;
import net.sf.saxon.tree.util.Navigator;
import net.sf.saxon.tree.wrapper.SiblingCountingNode;
import net.sf.saxon.type.SchemaType;
Expand Down Expand Up @@ -53,17 +52,17 @@ public int getSiblingPosition() {


@Override
protected AxisIterator iterateAttributes(Predicate<? super NodeInfo> nodeTest) {
protected AxisIterator iterateAttributes(NodeTest nodeTest) {
return EmptyIterator.ofNodes();
}

@Override
protected AxisIterator iterateChildren(Predicate<? super NodeInfo> nodeTest) {
protected AxisIterator iterateChildren(NodeTest nodeTest) {
return EmptyIterator.ofNodes();
}

@Override
protected AxisIterator iterateSiblings(Predicate<? super NodeInfo> nodeTest, boolean forwards) {
protected AxisIterator iterateSiblings(NodeTest nodeTest, boolean forwards) {
return EmptyIterator.ofNodes();
}

Expand Down Expand Up @@ -102,13 +101,13 @@ public String getLocalPart() {


@Override
public void generateId(FastStringBuffer buffer) {
buffer.append(Integer.toString(hashCode()));
public void generateId(StringBuilder buffer) {
buffer.append(hashCode());
}


@Override
public CharSequence getStringValueCS() {
public String getStringValue() {
getTreeInfo().getLogger().recordUsageOf(attribute);
return attribute.getStringValue();
}
Expand Down

0 comments on commit 3765e45

Please sign in to comment.