Skip to content

Commit

Permalink
refactor: OpenRewrite best practices (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek and TeamModerne authored Jun 7, 2024
1 parent 90f9c9e commit 27bac59
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import lombok.AllArgsConstructor;
import org.openrewrite.Cursor;
import org.openrewrite.analysis.trait.Top;
import org.openrewrite.analysis.trait.util.TraitErrors;
import org.openrewrite.analysis.trait.TraitFactory;
import org.openrewrite.analysis.trait.util.TraitErrors;
import org.openrewrite.java.tree.J;

import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import lombok.AllArgsConstructor;
import lombok.experimental.Delegate;
import org.openrewrite.Cursor;
import org.openrewrite.analysis.trait.Top;
import org.openrewrite.analysis.trait.TraitFactory;
import org.openrewrite.analysis.trait.util.TraitErrors;
import org.openrewrite.analysis.trait.Top;

/**
* A use of the keyword `this`, which may be qualified.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,3 @@ static Field create(JavaType.Variable variable, Cursor anyCursor) {
return new FieldFromJavaTypeVariable(variable, anyCursor.dropParentUntil(JavaSourceFile.class::isInstance));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,3 @@ static <V extends InitializerMethodBase> Validation<TraitErrors, V> genericViewO
return TraitErrors.invalidTraitCreationType(clazz, cursor, J.Block.class);
}
}

26 changes: 8 additions & 18 deletions src/test/resources/dataflow-functional-tests/ArchiveAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,6 @@
*/
package org.owasp.dependencycheck.analyzer;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.concurrent.ThreadSafe;

import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.ArchiveInputStream;
import org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream;
Expand All @@ -49,7 +33,6 @@
import org.eclipse.packager.rpm.RpmTag;
import org.eclipse.packager.rpm.parse.RpmInputStream;
import org.owasp.dependencycheck.Engine;
import static org.owasp.dependencycheck.analyzer.AbstractNpmAnalyzer.shouldProcess;
import org.owasp.dependencycheck.analyzer.exception.AnalysisException;
import org.owasp.dependencycheck.analyzer.exception.ArchiveExtractionException;
import org.owasp.dependencycheck.analyzer.exception.UnexpectedAnalysisException;
Expand All @@ -58,10 +41,17 @@
import org.owasp.dependencycheck.utils.FileFilterBuilder;
import org.owasp.dependencycheck.utils.FileUtils;
import org.owasp.dependencycheck.utils.Settings;

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

import javax.annotation.concurrent.ThreadSafe;
import java.io.*;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;

import static org.owasp.dependencycheck.analyzer.AbstractNpmAnalyzer.shouldProcess;

/**
* <p>
* An analyzer that extracts files from archives and ensures any supported files
Expand Down
26 changes: 5 additions & 21 deletions src/test/resources/dataflow-functional-tests/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,20 @@
*/
package org.apache.commons.io;

import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.commons.io.filefilter.*;
import org.apache.commons.io.output.NullOutputStream;

import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.*;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;
import java.util.zip.Checksum;

import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.FalseFileFilter;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.io.filefilter.SuffixFileFilter;
import org.apache.commons.io.filefilter.TrueFileFilter;
import org.apache.commons.io.output.NullOutputStream;

/**
* General file manipulation utilities.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
*/

import org.apache.commons.io.FilenameUtils;

import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.provider.git.util.GitUtil;
import org.apache.maven.scm.providers.gitlib.settings.Settings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@

package org.jsonschema2pojo.maven;

import static java.lang.String.*;
import static java.util.Arrays.*;
import static java.util.regex.Pattern.*;
import org.apache.maven.shared.utils.io.DirectoryScanner;
import org.apache.maven.shared.utils.io.MatchPatterns;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.maven.shared.utils.io.DirectoryScanner;
import org.apache.maven.shared.utils.io.MatchPatterns;
import static java.lang.String.*;
import static java.util.Arrays.*;
import static java.util.regex.Pattern.*;

/**
* <p>A file filter that supports include and exclude patterns.</p>
Expand Down
21 changes: 10 additions & 11 deletions src/test/resources/dataflow-functional-tests/SimpleFileServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@
******************************************************************************/
package org.eclipse.californium.examples;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.SocketException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.californium.core.CoapResource;
import org.eclipse.californium.core.coap.CoAP;
import org.eclipse.californium.core.coap.MediaTypeRegistry;
Expand All @@ -37,23 +28,31 @@
import org.eclipse.californium.core.server.resources.MyIpResource;
import org.eclipse.californium.core.server.resources.Resource;
import org.eclipse.californium.elements.config.Configuration;
import org.eclipse.californium.elements.config.UdpConfig;
import org.eclipse.californium.elements.config.Configuration.DefinitionsProvider;
import org.eclipse.californium.elements.config.TcpConfig;
import org.eclipse.californium.elements.config.UdpConfig;
import org.eclipse.californium.elements.util.StringUtil;
import org.eclipse.californium.plugtests.AbstractTestServer;
import org.eclipse.californium.plugtests.PlugtestServer.BaseConfig;
import org.eclipse.californium.plugtests.resources.MyContext;
import org.eclipse.californium.scandium.config.DtlsConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.ParameterException;
import picocli.CommandLine.ParseResult;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.SocketException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class SimpleFileServer extends AbstractTestServer {

private static final Logger LOG = LoggerFactory.getLogger(SimpleFileServer.class);
Expand Down
3 changes: 2 additions & 1 deletion src/test/resources/dataflow-functional-tests/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.util.Collection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.function.Supplier;

@SuppressWarnings("RedundantSuppression")
Expand All @@ -32,6 +32,7 @@ public Collection get() {
}
};
}

Test() {
Collection c = new ArrayList();
c.add(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.util.List;
import java.util.ArrayList;
import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import java.util.List;

class TestAssignmentToNull {
void test2(File srcDir, File destDir, FileFilter filter) {
Expand Down

0 comments on commit 27bac59

Please sign in to comment.