RequireThis rule and fixThis Gradle task

* `gradlew clean check -x test --parallel --continue` - to collect reports
* `gradlew fixThis --parallel` - to fix all possible vulnerabilities. With `-Dfile.encoding=UTF-8` on Windows

Since the `RequireThisCheck` doesn't see parents for anonymous classes (e.g. `Runnable` callback), its report doesn't contains the outer class name with `this.`,
therefore we still have to fix those cases manually.
Thanks to the wrong `replacer` just with `this.` we have uncompilable code enough easy to find problems.
Not so easy to fix for good readability though...

* Upgrade to Grade 2.12
* Upgrade to SonarQube native plugin

The fix contains at about 300 files. So, will be done on merge.

Fix `fixThis.gradle` according PR comments

Apply `fixThis` and also `fixModifiers` for test classes.
 Fix some `this.` inner issues manually.
 Make code polishing for long lines after `fixThis`

Fix conflicts and vulnerabilities after the rebase
This commit is contained in:
Artem Bilan
2016-03-17 17:02:15 -04:00
parent e189307ab6
commit 2b0598291c
348 changed files with 1828 additions and 1781 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -169,7 +169,7 @@ public class FileReadingMessageSource extends IntegrationObjectSupport implement
* @since 4.2
*/
public DirectoryScanner getScanner() {
return scanner;
return this.scanner;
}
/**
@@ -243,12 +243,12 @@ public class FileReadingMessageSource extends IntegrationObjectSupport implement
@Override
protected void onInit() {
Assert.notNull(directory, "'directory' must not be null");
Assert.notNull(this.directory, "'directory' must not be null");
if (!this.directory.exists() && this.autoCreateDirectory) {
this.directory.mkdirs();
}
Assert.isTrue(this.directory.exists(),
"Source directory [" + directory + "] does not exist.");
"Source directory [" + this.directory + "] does not exist.");
Assert.isTrue(this.directory.isDirectory(),
"Source path [" + this.directory + "] does not point to a directory.");
Assert.isTrue(this.directory.canRead(),
@@ -268,16 +268,16 @@ public class FileReadingMessageSource extends IntegrationObjectSupport implement
Message<File> message = null;
// rescan only if needed or explicitly configured
if (scanEachPoll || toBeReceived.isEmpty()) {
if (this.scanEachPoll || this.toBeReceived.isEmpty()) {
scanInputDirectory();
}
File file = toBeReceived.poll();
File file = this.toBeReceived.poll();
// file == null means the queue was empty
// we can't rely on isEmpty for concurrency reasons
while ((file != null) && !scanner.tryClaim(file)) {
file = toBeReceived.poll();
while ((file != null) && !this.scanner.tryClaim(file)) {
file = this.toBeReceived.poll();
}
if (file != null) {
@@ -290,10 +290,10 @@ public class FileReadingMessageSource extends IntegrationObjectSupport implement
}
private void scanInputDirectory() {
List<File> filteredFiles = scanner.listFiles(directory);
List<File> filteredFiles = this.scanner.listFiles(this.directory);
Set<File> freshFiles = new LinkedHashSet<File>(filteredFiles);
if (!freshFiles.isEmpty()) {
toBeReceived.addAll(freshFiles);
this.toBeReceived.addAll(freshFiles);
if (logger.isDebugEnabled()) {
logger.debug("Added to queue: " + freshFiles);
}
@@ -310,7 +310,7 @@ public class FileReadingMessageSource extends IntegrationObjectSupport implement
if (logger.isWarnEnabled()) {
logger.warn("Failed to send: " + failedMessage);
}
toBeReceived.offer(failedMessage.getPayload());
this.toBeReceived.offer(failedMessage.getPayload());
}
/**

View File

@@ -251,7 +251,7 @@ public class FileWritingMessageHandler extends AbstractReplyProducingMessageHand
}
protected String getTemporaryFileSuffix() {
return temporaryFileSuffix;
return this.temporaryFileSuffix;
}
/**
@@ -473,8 +473,8 @@ public class FileWritingMessageHandler extends AbstractReplyProducingMessageHand
if (rename(sourceFile, resultFile)) {
return resultFile;
}
if (logger.isInfoEnabled()) {
logger.info(String.format("Failed to move file '%s'. Using copy and delete fallback.",
if (this.logger.isInfoEnabled()) {
this.logger.info(String.format("Failed to move file '%s'. Using copy and delete fallback.",
sourceFile.getAbsolutePath()));
}
}
@@ -835,7 +835,7 @@ public class FileWritingMessageHandler extends AbstractReplyProducingMessageHand
private synchronized void clearState(final File fileToWriteTo, final FileState state) {
if (state != null) {
fileStates.remove(fileToWriteTo.getAbsolutePath());
this.fileStates.remove(fileToWriteTo.getAbsolutePath());
}
}
@@ -896,8 +896,8 @@ public class FileWritingMessageHandler extends AbstractReplyProducingMessageHand
if (state.lastWrite < expired) {
iterator.remove();
state.close();
if (logger.isDebugEnabled()) {
logger.debug("Flushed: " + entry.getKey());
if (FileWritingMessageHandler.this.logger.isDebugEnabled()) {
FileWritingMessageHandler.this.logger.debug("Flushed: " + entry.getKey());
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -67,7 +67,7 @@ public class HeadDirectoryScanner extends DefaultDirectoryScanner {
@Override
public List<File> filterFiles(File[] files) {
return Arrays.asList(files).subList(0, Math.min(files.length, maxNumberOfFiles));
return Arrays.asList(files).subList(0, Math.min(files.length, this.maxNumberOfFiles));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -174,7 +174,7 @@ public class WatchServiceDirectoryScanner extends DefaultDirectoryScanner implem
}
private Set<File> filesFromEvents() {
WatchKey key = watcher.poll();
WatchKey key = this.watcher.poll();
Set<File> files = new LinkedHashSet<File>();
while (key != null) {
for (WatchEvent<?> event : key.pollEvents()) {
@@ -209,7 +209,7 @@ public class WatchServiceDirectoryScanner extends DefaultDirectoryScanner implem
}
}
key.reset();
key = watcher.poll();
key = this.watcher.poll();
}
return files;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -137,7 +137,7 @@ public class FileReadingMessageSourceFactoryBean implements FactoryBean<FileRead
this.source = new FileReadingMessageSource(this.comparator);
}
else if (queueSizeSet) {
this.source = new FileReadingMessageSource(queueSize);
this.source = new FileReadingMessageSource(this.queueSize);
}
else {
this.source = new FileReadingMessageSource();
@@ -155,7 +155,7 @@ public class FileReadingMessageSourceFactoryBean implements FactoryBean<FileRead
compositeFileListFilter.addFilter(this.filter);
compositeFileListFilter.addFilter(this.locker);
this.source.setFilter(compositeFileListFilter);
this.source.setLocker(locker);
this.source.setLocker(this.locker);
}
}
else if (this.locker != null) {
@@ -163,7 +163,7 @@ public class FileReadingMessageSourceFactoryBean implements FactoryBean<FileRead
compositeFileListFilter.addFilter(new FileListFilterFactoryBean().getObject());
compositeFileListFilter.addFilter(this.locker);
this.source.setFilter(compositeFileListFilter);
this.source.setLocker(locker);
this.source.setLocker(this.locker);
}
if (this.scanEachPoll != null) {
this.source.setScanEachPoll(this.scanEachPoll);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2015 the original author or authors.
* Copyright 2013-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -72,7 +72,7 @@ public abstract class AbstractPersistentAcceptOnceFileListFilter<F> extends Abst
@Override
protected boolean accept(F file) {
String key = buildKey(file);
synchronized(monitor) {
synchronized(this.monitor) {
String newValue = value(file);
String oldValue = this.store.putIfAbsent(key, newValue);
if (oldValue == null) { // not in store

View File

@@ -39,7 +39,7 @@ public class LastModifiedFileListFilter implements FileListFilter<File> {
private volatile long age = DEFAULT_AGE;
public long getAge() {
return age;
return this.age;
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,7 +45,7 @@ public class NioFileLocker extends AbstractFileLockerFilter {
* {@inheritDoc}
*/
public boolean lock(File fileToLock) {
FileLock lock = lockCache.get(fileToLock);
FileLock lock = this.lockCache.get(fileToLock);
if (lock == null) {
FileLock newLock = null;
try {
@@ -55,7 +55,7 @@ public class NioFileLocker extends AbstractFileLockerFilter {
+ fileToLock, e);
}
if (newLock != null) {
FileLock original = lockCache.putIfAbsent(fileToLock, newLock);
FileLock original = this.lockCache.putIfAbsent(fileToLock, newLock);
lock = original != null ? original : newLock;
}
}
@@ -63,11 +63,11 @@ public class NioFileLocker extends AbstractFileLockerFilter {
}
public boolean isLockable(File file) {
return lockCache.containsKey(file) || !FileChannelCache.isLocked(file);
return this.lockCache.containsKey(file) || !FileChannelCache.isLocked(file);
}
public void unlock(File fileToUnlock) {
FileLock fileLock = lockCache.get(fileToUnlock);
FileLock fileLock = this.lockCache.get(fileToUnlock);
try {
if (fileLock != null) {
fileLock.release();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,7 +37,7 @@ public abstract class AbstractFileInfo<F> implements FileInfo<F>, Comparable<Fil
}
public String getRemoteDirectory() {
return remoteDirectory;
return this.remoteDirectory;
}
public String toString() {

View File

@@ -104,7 +104,7 @@ public class RemoteFileTemplate<F> implements RemoteFileOperations<F>, Initializ
* @since 4.2
*/
public SessionFactory<F> getSessionFactory() {
return sessionFactory;
return this.sessionFactory;
}
/**
@@ -129,7 +129,7 @@ public class RemoteFileTemplate<F> implements RemoteFileOperations<F>, Initializ
* @return the remote file separator.
*/
public final String getRemoteFileSeparator() {
return remoteFileSeparator;
return this.remoteFileSeparator;
}
/**
@@ -176,7 +176,7 @@ public class RemoteFileTemplate<F> implements RemoteFileOperations<F>, Initializ
* system.
*/
public boolean isUseTemporaryFileName() {
return useTemporaryFileName;
return this.useTemporaryFileName;
}
/**
@@ -245,7 +245,7 @@ public class RemoteFileTemplate<F> implements RemoteFileOperations<F>, Initializ
if (this.autoCreateDirectory){
Assert.hasText(this.remoteFileSeparator, "'remoteFileSeparator' must not be empty when 'autoCreateDirectory' is set to 'true'");
}
if (hasExplicitlySetSuffix && !useTemporaryFileName){
if (this.hasExplicitlySetSuffix && !this.useTemporaryFileName){
this.logger.warn("Since 'use-temporary-file-name' is set to 'false' the value of 'temporary-file-suffix' has no effect");
}
}
@@ -333,8 +333,8 @@ public class RemoteFileTemplate<F> implements RemoteFileOperations<F>, Initializ
}
else {
// A null holder means a File payload that does not exist.
if (logger.isWarnEnabled()) {
logger.warn("File " + message.getPayload() + " does not exist");
if (this.logger.isWarnEnabled()) {
this.logger.warn("File " + message.getPayload() + " does not exist");
}
return null;
}
@@ -425,8 +425,8 @@ public class RemoteFileTemplate<F> implements RemoteFileOperations<F>, Initializ
session.close();
}
catch (Exception ignored) {
if (logger.isDebugEnabled()) {
logger.debug("failed to close Session", ignored);
if (this.logger.isDebugEnabled()) {
this.logger.debug("failed to close Session", ignored);
}
}
}
@@ -488,7 +488,7 @@ public class RemoteFileTemplate<F> implements RemoteFileOperations<F>, Initializ
String tempRemoteFilePath = temporaryRemoteDirectory + fileName;
// write remote file first with temporary file extension if enabled
String tempFilePath = tempRemoteFilePath + (useTemporaryFileName ? this.temporaryFileSuffix : "");
String tempFilePath = tempRemoteFilePath + (this.useTemporaryFileName ? this.temporaryFileSuffix : "");
if (this.autoCreateDirectory) {
try {
@@ -515,8 +515,8 @@ public class RemoteFileTemplate<F> implements RemoteFileOperations<F>, Initializ
"The destination file already exists at '" + remoteFilePath + "'.");
}
else {
if (logger.isDebugEnabled()) {
logger.debug("File not transferred to '" + remoteFilePath + "'; already exists.");
if (this.logger.isDebugEnabled()) {
this.logger.debug("File not transferred to '" + remoteFilePath + "'; already exists.");
}
}
rename = false;
@@ -560,11 +560,11 @@ public class RemoteFileTemplate<F> implements RemoteFileOperations<F>, Initializ
}
public InputStream getStream() {
return stream;
return this.stream;
}
public String getName() {
return name;
return this.name;
}
}

View File

@@ -438,7 +438,7 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
Command.GET.equals(this.command)) {
Assert.isNull(this.filter, "Filters are not supported with the rm and get commands");
}
if ((Command.GET.equals(this.command) && !options.contains(Option.STREAM))
if ((Command.GET.equals(this.command) && !this.options.contains(Option.STREAM))
|| Command.MGET.equals(this.command)) {
Assert.notNull(this.localDirectoryExpression, "localDirectory must not be null");
if (this.localDirectoryExpression instanceof LiteralExpression) {
@@ -503,7 +503,8 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
@Override
public Object doInSession(Session<F> session) throws IOException {
return messageSessionCallback.doInSession(session, requestMessage);
return AbstractRemoteFileOutboundGateway.this.messageSessionCallback.doInSession(session,
requestMessage);
}
});

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -177,18 +177,18 @@ public class CachingSessionFactory<F> implements SessionFactory<F>, DisposableBe
@Override
public synchronized void close() {
if (released) {
if (this.released) {
if (logger.isDebugEnabled()){
logger.debug("Session " + targetSession + " already released.");
logger.debug("Session " + this.targetSession + " already released.");
}
}
else {
if (logger.isDebugEnabled()){
logger.debug("Releasing Session " + targetSession + " back to the pool.");
logger.debug("Releasing Session " + this.targetSession + " back to the pool.");
}
if (this.sharedSessionEpoch != CachingSessionFactory.this.sharedSessionEpoch) {
if (logger.isDebugEnabled()){
logger.debug("Closing session " + targetSession + " after reset.");
logger.debug("Closing session " + this.targetSession + " after reset.");
}
this.targetSession.close();
}
@@ -203,8 +203,8 @@ public class CachingSessionFactory<F> implements SessionFactory<F>, DisposableBe
//No-op in this context
}
}
pool.releaseItem(this.targetSession);
released = true;
CachingSessionFactory.this.pool.releaseItem(this.targetSession);
this.released = true;
}
}

View File

@@ -59,7 +59,7 @@ public class DelegatingSessionFactory<F> implements SessionFactory<F> {
* @return the locator.
*/
public SessionFactoryLocator<F> getFactoryLocator() {
return factoryLocator;
return this.factoryLocator;
}
/**

View File

@@ -215,7 +215,7 @@ public abstract class AbstractInboundFileSynchronizer<F>
}
protected String getTemporaryFileSuffix() {
return temporaryFileSuffix;
return this.temporaryFileSuffix;
}
@Override
@@ -227,12 +227,12 @@ public abstract class AbstractInboundFileSynchronizer<F>
@Override
public void synchronizeToLocalDirectory(final File localDirectory) {
final String remoteDirectory = this.remoteDirectoryExpression.getValue(this.evaluationContext, String.class);
try {
int transferred = this.remoteFileTemplate.execute(new SessionCallback<F, Integer>() {
@Override
public Integer doInSession(Session<F> session) throws IOException {
String remoteDirectory = remoteDirectoryExpression.getValue(evaluationContext, String.class);
F[] files = session.list(remoteDirectory);
if (!ObjectUtils.isEmpty(files)) {
List<F> filteredFiles = filterFiles(files);
@@ -266,8 +266,8 @@ public abstract class AbstractInboundFileSynchronizer<F>
}
}
});
if (logger.isDebugEnabled()) {
logger.debug(transferred + " files transferred");
if (this.logger.isDebugEnabled()) {
this.logger.debug(transferred + " files transferred");
}
}
catch (Exception e) {
@@ -280,11 +280,11 @@ public abstract class AbstractInboundFileSynchronizer<F>
String remoteFileName = this.getFilename(remoteFile);
String localFileName = this.generateLocalFileName(remoteFileName);
String remoteFilePath = remoteDirectoryPath != null
? (remoteDirectoryPath + remoteFileSeparator + remoteFileName)
? (remoteDirectoryPath + this.remoteFileSeparator + remoteFileName)
: remoteFileName;
if (!this.isFile(remoteFile)) {
if (logger.isDebugEnabled()) {
logger.debug("cannot copy, not a file: " + remoteFilePath);
if (this.logger.isDebugEnabled()) {
this.logger.debug("cannot copy, not a file: " + remoteFilePath);
}
return;
}
@@ -316,8 +316,8 @@ public abstract class AbstractInboundFileSynchronizer<F>
if (tempFile.renameTo(localFile)) {
if (this.deleteRemoteFiles) {
session.remove(remoteFilePath);
if (logger.isDebugEnabled()) {
logger.debug("deleted " + remoteFilePath);
if (this.logger.isDebugEnabled()) {
this.logger.debug("deleted " + remoteFilePath);
}
}
}
@@ -329,7 +329,7 @@ public abstract class AbstractInboundFileSynchronizer<F>
private String generateLocalFileName(String remoteFileName){
if (this.localFilenameGeneratorExpression != null){
return this.localFilenameGeneratorExpression.getValue(evaluationContext, remoteFileName, String.class);
return this.localFilenameGeneratorExpression.getValue(this.evaluationContext, remoteFileName, String.class);
}
return remoteFileName;
}

View File

@@ -301,24 +301,24 @@ public class FileSplitter extends AbstractMessageSplitter {
}
public String getFilePath() {
return filePath;
return this.filePath;
}
public Mark getMark() {
return mark;
return this.mark;
}
public long getLineCount() {
return lineCount;
return this.lineCount;
}
@Override
public String toString() {
if (this.mark.equals(Mark.START)) {
return "FileMarker [filePath=" + filePath + ", mark=" + mark + "]";
return "FileMarker [filePath=" + this.filePath + ", mark=" + this.mark + "]";
}
else {
return "FileMarker [filePath=" + filePath + ", mark=" + mark + ", lineCount=" + lineCount + "]";
return "FileMarker [filePath=" + this.filePath + ", mark=" + this.mark + ", lineCount=" + this.lineCount + "]";
}
}

View File

@@ -87,7 +87,7 @@ public abstract class FileTailingMessageProducerSupport extends MessageProducerS
}
protected long getMissingFileDelay() {
return tailAttemptsDelay;
return this.tailAttemptsDelay;
}
protected TaskExecutor getTaskExecutor() {
@@ -131,11 +131,11 @@ public abstract class FileTailingMessageProducerSupport extends MessageProducerS
}
protected String getMessage() {
return message;
return this.message;
}
public File getFile() {
return file;
return this.file;
}
@Override