Skip to content

Commit

Permalink
Restyled by clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits committed Apr 29, 2020
1 parent 8c55d52 commit 36b40b6
Show file tree
Hide file tree
Showing 29 changed files with 1,383 additions and 1,302 deletions.
136 changes: 71 additions & 65 deletions WikipediaCleaner/src/org/wikipediacleaner/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Locale;
import java.util.Properties;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wikipediacleaner.api.check.algorithm.CheckErrorAlgorithm;
Expand All @@ -49,7 +48,6 @@
import org.wikipediacleaner.utils.ConfigurationConstants;
import org.wikipediacleaner.utils.ConfigurationValueString;


/**
* Wikipedia Cleaner running as a bot.
*/
Expand Down Expand Up @@ -116,14 +114,16 @@ private Bot(String[] args) {
currentArg += 2;
} else if ("-credentials".equals(arg)) {
if (args.length <= currentArg + 1) {
log.warn("When using parameter '-credentials', you must specify the file containing the credentials");
log.warn(
"When using parameter '-credentials', you must specify the file containing the credentials");
return;
}
credentials = args[currentArg + 1];
currentArg += 2;
} else if ("-prefix".equals(arg)) {
if (args.length <= currentArg + 1) {
log.warn("When using parameter '-prefix', you must specify the prefix used for the comments");
log.warn(
"When using parameter '-prefix', you must specify the prefix used for the comments");
return;
}
prefix = args[currentArg + 1].replaceAll("_", " ");
Expand Down Expand Up @@ -153,7 +153,8 @@ private Bot(String[] args) {
String password = null;
if (credentials != null) {
Properties properties = new Properties();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(credentials), "UTF8"))) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(
new FileInputStream(credentials), "UTF8"))) {
properties.load(reader);
} catch (IOException e) {
log.warn("Unable to load credentials file " + credentials);
Expand All @@ -174,16 +175,14 @@ private Bot(String[] args) {
// Retrieve action
actions = new ArrayList<>();
if (args.length > currentArg) {
actions.add(new Action(Arrays.copyOfRange(args, currentArg, args.length), null));
actions.add(
new Action(Arrays.copyOfRange(args, currentArg, args.length), null));
}
currentArg++;

// Check arguments
if ((wiki == null) ||
(userName == null) ||
(password == null) ||
actions.isEmpty() ||
!actions.get(0).isOk()) {
if ((wiki == null) || (userName == null) || (password == null) ||
actions.isEmpty() || !actions.get(0).isOk()) {
log.warn("Some parameters are incorrect");
return;
}
Expand All @@ -195,16 +194,16 @@ private Bot(String[] args) {
// Login
loginDone = false;
LoginWorker loginWorker = new LoginWorker(
wiki, null, null, EnumLanguage.getDefaultLanguage(),
userName, password.toCharArray(),
wiki, null, null, EnumLanguage.getDefaultLanguage(), userName,
password.toCharArray(),
ConfigurationConstants.VALUE_SAVE_USER_NO_CHANGE, true, false);
loginWorker.setListener(this);
loginWorker.start();
}

/**
* Execute an action.
*
*
* @param actionConfig Action and its configuration.
*/
void executeAction(Action actionConfig) {
Expand All @@ -226,16 +225,18 @@ void executeAction(Action actionConfig) {
} else if ("DoTasks".equalsIgnoreCase(action)) {
actionDone = true;
if (args.length > currentArg) {
File tasks = (actionConfig.baseDir != null) ?
new File(actionConfig.baseDir, args[currentArg]) :
new File(args[currentArg]);
File tasks = (actionConfig.baseDir != null)
? new File(actionConfig.baseDir, args[currentArg])
: new File(args[currentArg]);
int actionNum = 0;
try (BufferedReader reader = new BufferedReader(new FileReader(tasks))) {
try (BufferedReader reader =
new BufferedReader(new FileReader(tasks))) {
String line = null;
while ((line = reader.readLine()) != null) {
String[] tmpArgs = line.split(" +");
if ((tmpArgs != null) && (tmpArgs.length > 0)) {
actions.add(actionNum, new Action(tmpArgs, tasks.getParentFile()));
actions.add(actionNum,
new Action(tmpArgs, tasks.getParentFile()));
actionNum++;
}
}
Expand All @@ -245,7 +246,8 @@ void executeAction(Action actionConfig) {
}
} else if ("UpdateDabWarnings".equalsIgnoreCase(action)) {
Configuration config = Configuration.getConfiguration();
String start = config.getString(null, ConfigurationValueString.LAST_DAB_WARNING);
String start =
config.getString(null, ConfigurationValueString.LAST_DAB_WARNING);
if (args.length > currentArg) {
if (args[currentArg].equals("*")) {
start = null;
Expand All @@ -265,36 +267,41 @@ void executeAction(Action actionConfig) {
} else if ("UpdateDuplicateArgsWarnings".equalsIgnoreCase(action)) {
worker = new UpdateDuplicateArgsWarningWorker(wiki, null, false);
} else if ("FixCheckWiki".equalsIgnoreCase(action)) {
List<CheckErrorAlgorithm> algorithms = new ArrayList<CheckErrorAlgorithm>();
List<CheckErrorAlgorithm> allAlgorithms = new ArrayList<CheckErrorAlgorithm>();
List<CheckErrorAlgorithm> algorithms =
new ArrayList<CheckErrorAlgorithm>();
List<CheckErrorAlgorithm> allAlgorithms =
new ArrayList<CheckErrorAlgorithm>();
if (args.length > currentArg) {
extractAlgorithms(algorithms, allAlgorithms, args, currentArg);
}
worker = new AutomaticCWWorker(
wiki, null, algorithms, 10000, true, allAlgorithms, null, true, false);
worker = new AutomaticCWWorker(wiki, null, algorithms, 10000, true,
allAlgorithms, null, true, false);
} else if ("FixListCheckWiki".equalsIgnoreCase(action)) {
Page page = null;
if (args.length > currentArg) {
page = DataManager.getPage(wiki, args[currentArg], null, null, null);
currentArg++;
}
List<CheckErrorAlgorithm> algorithms = new ArrayList<CheckErrorAlgorithm>();
List<CheckErrorAlgorithm> allAlgorithms = new ArrayList<CheckErrorAlgorithm>();
List<CheckErrorAlgorithm> algorithms =
new ArrayList<CheckErrorAlgorithm>();
List<CheckErrorAlgorithm> allAlgorithms =
new ArrayList<CheckErrorAlgorithm>();
if (args.length > currentArg) {
extractAlgorithms(algorithms, allAlgorithms, args, currentArg);
}
worker = new AutomaticListCWWorker(
wiki, null, page,
algorithms, allAlgorithms, namespaces,
null, true, false);
worker =
new AutomaticListCWWorker(wiki, null, page, algorithms, allAlgorithms,
namespaces, null, true, false);
} else if ("MarkCheckWiki".equalsIgnoreCase(action)) {
List<CheckErrorAlgorithm> algorithms = new ArrayList<CheckErrorAlgorithm>();
List<CheckErrorAlgorithm> allAlgorithms = new ArrayList<CheckErrorAlgorithm>();
List<CheckErrorAlgorithm> algorithms =
new ArrayList<CheckErrorAlgorithm>();
List<CheckErrorAlgorithm> allAlgorithms =
new ArrayList<CheckErrorAlgorithm>();
if (args.length > currentArg) {
extractAlgorithms(algorithms, allAlgorithms, args, currentArg);
}
worker = new AutomaticCWWorker(
wiki, null, algorithms, 10000, true, allAlgorithms, null, false, false);
worker = new AutomaticCWWorker(wiki, null, algorithms, 10000, true,
allAlgorithms, null, false, false);
} else if ("ListCheckWiki".equalsIgnoreCase(action)) {
boolean check = true;
boolean onlyRecheck = false;
Expand All @@ -312,18 +319,17 @@ void executeAction(Action actionConfig) {
}
if (args.length > currentArg + 2) {
File dumpFile = getDumpFile(args[currentArg]);
List<CheckErrorAlgorithm> algorithms = new ArrayList<CheckErrorAlgorithm>();
List<CheckErrorAlgorithm> algorithms =
new ArrayList<CheckErrorAlgorithm>();
extractAlgorithms(algorithms, null, args, currentArg + 2);
if (args[currentArg + 1].startsWith("wiki:")) {
String pageName = args[currentArg + 1].substring(5);
worker = new ListCWWorker(
wiki, null, dumpFile, pageName,
algorithms, namespaces, check, onlyRecheck);
worker = new ListCWWorker(wiki, null, dumpFile, pageName, algorithms,
namespaces, check, onlyRecheck);
} else {
File output = new File(args[currentArg + 1]);
worker = new ListCWWorker(
wiki, null, dumpFile, output,
algorithms, namespaces, check);
worker = new ListCWWorker(wiki, null, dumpFile, output, algorithms,
namespaces, check);
}
}
} else if ("Set".equalsIgnoreCase(action)) {
Expand All @@ -332,7 +338,8 @@ void executeAction(Action actionConfig) {
actionDone = true;
if ("Prefix".equalsIgnoreCase(parameter)) {
if (args.length > currentArg + 1) {
CommentManager.addExtraText(args[currentArg + 1].replaceAll("_", " "));
CommentManager.addExtraText(
args[currentArg + 1].replaceAll("_", " "));
}
} else if ("AdditionalAlgorithms".equalsIgnoreCase(parameter)) {
additionalAlgorithms.clear();
Expand Down Expand Up @@ -374,10 +381,9 @@ void executeAction(Action actionConfig) {
* @param args Arguments.
* @param startIndex Start index in the arguments.
*/
private void extractAlgorithms(
List<CheckErrorAlgorithm> algorithms,
List<CheckErrorAlgorithm> allAlgorithms,
String[] args, int startIndex) {
private void extractAlgorithms(List<CheckErrorAlgorithm> algorithms,
List<CheckErrorAlgorithm> allAlgorithms,
String[] args, int startIndex) {

// Create list based on arguments
for (int i = startIndex; i < args.length; i++) {
Expand All @@ -390,28 +396,26 @@ private void extractAlgorithms(
if (algorithmNumber.equals("*") || algorithmNumber.equals("!")) {
// NOTE: Allowing "!" because of Eclipse bug with "*"
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=212264
List<CheckErrorAlgorithm> possibleAlgorithms = CheckErrorAlgorithms.getAlgorithms(wiki);
List<CheckErrorAlgorithm> possibleAlgorithms =
CheckErrorAlgorithms.getAlgorithms(wiki);
for (CheckErrorAlgorithm algorithm : possibleAlgorithms) {
if ((algorithm != null) && algorithm.isAvailable()) {
if (!addition &&
!algorithms.contains(algorithm)) {
if (!addition && !algorithms.contains(algorithm)) {
algorithms.add(algorithm);
}
if ((allAlgorithms != null) &&
!allAlgorithms.contains(algorithm)) {
if ((allAlgorithms != null) && !allAlgorithms.contains(algorithm)) {
allAlgorithms.add(algorithm);
}
}
}
} else {
CheckErrorAlgorithm algorithm = CheckErrorAlgorithms.getAlgorithm(wiki, Integer.parseInt(algorithmNumber));
CheckErrorAlgorithm algorithm = CheckErrorAlgorithms.getAlgorithm(
wiki, Integer.parseInt(algorithmNumber));
if (algorithm != null) {
if (!addition &&
!algorithms.contains(algorithm)) {
if (!addition && !algorithms.contains(algorithm)) {
algorithms.add(algorithm);
}
if ((allAlgorithms != null) &&
!allAlgorithms.contains(algorithm)) {
if ((allAlgorithms != null) && !allAlgorithms.contains(algorithm)) {
allAlgorithms.add(algorithm);
}
}
Expand Down Expand Up @@ -447,7 +451,6 @@ private File getDumpFile(String path) {
return null;
}
String[] filenames = parent.list(new FilenameFilter() {

@Override
public boolean accept(@SuppressWarnings("unused") File dir, String name) {
if (name.startsWith(filename.substring(0, starIndex)) &&
Expand All @@ -466,7 +469,8 @@ public boolean accept(@SuppressWarnings("unused") File dir, String name) {

/**
* @param worker Worker.
* @see org.wikipediacleaner.gui.swing.basic.BasicWorkerListener#beforeStart(org.wikipediacleaner.gui.swing.basic.BasicWorker)
* @see
* org.wikipediacleaner.gui.swing.basic.BasicWorkerListener#beforeStart(org.wikipediacleaner.gui.swing.basic.BasicWorker)
*/
@Override
public void beforeStart(BasicWorker worker) {
Expand All @@ -475,7 +479,8 @@ public void beforeStart(BasicWorker worker) {

/**
* @param worker Worker.
* @see org.wikipediacleaner.gui.swing.basic.BasicWorkerListener#afterStart(org.wikipediacleaner.gui.swing.basic.BasicWorker)
* @see
* org.wikipediacleaner.gui.swing.basic.BasicWorkerListener#afterStart(org.wikipediacleaner.gui.swing.basic.BasicWorker)
*/
@Override
public void afterStart(BasicWorker worker) {
Expand All @@ -484,7 +489,8 @@ public void afterStart(BasicWorker worker) {

/**
* @param worker Worker.
* @see org.wikipediacleaner.gui.swing.basic.BasicWorkerListener#beforeFinished(org.wikipediacleaner.gui.swing.basic.BasicWorker)
* @see
* org.wikipediacleaner.gui.swing.basic.BasicWorkerListener#beforeFinished(org.wikipediacleaner.gui.swing.basic.BasicWorker)
*/
@Override
public void beforeFinished(BasicWorker worker) {
Expand All @@ -494,7 +500,9 @@ public void beforeFinished(BasicWorker worker) {
/**
* @param worker Worker.
* @param ok True if it finished OK.
* @see org.wikipediacleaner.gui.swing.basic.BasicWorkerListener#afterFinished(org.wikipediacleaner.gui.swing.basic.BasicWorker, boolean)
* @see
* org.wikipediacleaner.gui.swing.basic.BasicWorkerListener#afterFinished(org.wikipediacleaner.gui.swing.basic.BasicWorker,
* boolean)
*/
@Override
public void afterFinished(BasicWorker worker, boolean ok) {
Expand Down Expand Up @@ -524,7 +532,7 @@ private static class Action {

/**
* Constructor.
*
*
* @param args List of arguments for the action.
* @param baseDir Base directory.
*/
Expand All @@ -536,8 +544,6 @@ public Action(String[] args, File baseDir) {
/**
* @return True if the action is OK.
*/
public boolean isOk() {
return (args != null) && (args.length > 0);
}
public boolean isOk() { return (args != null) && (args.length > 0); }
}
}
Loading

0 comments on commit 36b40b6

Please sign in to comment.