Merge pull request #92 from P0nk/project-improvements
Project improvements - bump deps, get rid of commons-io
This commit is contained in:
17
pom.xml
17
pom.xml
@@ -19,19 +19,18 @@
|
||||
<mainClass>net.server.Server</mainClass>
|
||||
|
||||
<!-- Maven plugins -->
|
||||
<maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version> <!-- For running unit tests -->
|
||||
<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version> <!-- Disabled. (for building thin jar) -->
|
||||
<maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version> <!-- For packaging the executable fat jar -->
|
||||
<maven-surefire-plugin.version>3.0.0-M7</maven-surefire-plugin.version> <!-- For running unit tests -->
|
||||
<maven-jar-plugin.version>3.2.2</maven-jar-plugin.version> <!-- Disabled. (for building thin jar) -->
|
||||
<maven-assembly-plugin.version>3.4.2</maven-assembly-plugin.version> <!-- For packaging the executable fat jar -->
|
||||
|
||||
<!-- Dependencies -->
|
||||
<slf4j-api.version>1.7.36</slf4j-api.version> <!-- Logging facade -->
|
||||
<log4j.version>2.18.0</log4j.version> <!-- Slf4j implementation -->
|
||||
<graalvm.version>22.2.0</graalvm.version> <!-- ScriptEngine implementation -->
|
||||
<netty.version>4.1.79.Final</netty.version> <!-- Networking -->
|
||||
<junit.version>5.8.2</junit.version> <!-- Unit test -->
|
||||
<junit.version>5.9.0</junit.version> <!-- Unit test -->
|
||||
<yamlbeans.version>1.15</yamlbeans.version> <!-- Config file -->
|
||||
<jcip-annotations.version>1.0</jcip-annotations.version> <!-- Annotations for concurrency documentation -->
|
||||
<commons-io.version>2.11.0</commons-io.version> <!-- Util library used by some of our tools -->
|
||||
<HikariCP.version>5.0.1</HikariCP.version> <!-- Database connection pool -->
|
||||
<mysql-connector-java.version>8.0.30</mysql-connector-java.version> <!-- MySQL JDBC driver -->
|
||||
</properties>
|
||||
@@ -47,11 +46,6 @@
|
||||
<artifactId>jcip-annotations</artifactId>
|
||||
<version>${jcip-annotations.version}</version>
|
||||
</dependency>
|
||||
<dependency> <!-- only used for some tools -->
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Database -->
|
||||
<dependency>
|
||||
@@ -169,6 +163,9 @@
|
||||
<manifest>
|
||||
<mainClass>${mainClass}</mainClass>
|
||||
</manifest>
|
||||
<manifestEntries>
|
||||
<Multi-Release>true</Multi-Release>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<appendAssemblyId>false</appendAssemblyId>
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package tools.mapletools;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -20,14 +19,28 @@ import java.util.regex.Pattern;
|
||||
* Estimated parse time: 10 seconds
|
||||
*/
|
||||
public class EventMethodFiller {
|
||||
private static final Collection<String> RELEVANT_FILE_EXTENSIONS = Set.of("sql", "js", "txt", "java");
|
||||
|
||||
private static boolean foundMatchingDataOnFile(String fileContent, Pattern pattern) {
|
||||
Matcher matcher = pattern.matcher(fileContent);
|
||||
return matcher.find();
|
||||
}
|
||||
|
||||
private static void fileSearchMatchingData(File file, Map<Pattern, String> functions) {
|
||||
private static void filterDirectorySearchMatchingData(String directoryPath, Map<Pattern, String> functions)
|
||||
throws IOException {
|
||||
Files.walk(Path.of(directoryPath))
|
||||
.filter(EventMethodFiller::isRelevantFile)
|
||||
.forEach(path -> fileSearchMatchingData(path, functions));
|
||||
}
|
||||
|
||||
private static boolean isRelevantFile(Path path) {
|
||||
String fileName = path.getFileName().toString();
|
||||
return RELEVANT_FILE_EXTENSIONS.stream().anyMatch(fileName::endsWith);
|
||||
}
|
||||
|
||||
private static void fileSearchMatchingData(Path file, Map<Pattern, String> functions) {
|
||||
try {
|
||||
String fileContent = FileUtils.readFileToString(file, "UTF-8");
|
||||
String fileContent = Files.readString(file);
|
||||
List<String> fillFunctions = new LinkedList<>();
|
||||
|
||||
for (Map.Entry<Pattern, String> f : functions.entrySet()) {
|
||||
@@ -37,37 +50,25 @@ public class EventMethodFiller {
|
||||
}
|
||||
|
||||
if (!fillFunctions.isEmpty()) {
|
||||
System.out.println("Filling out " + file.getName() + "...");
|
||||
System.out.println("Filling out " + file.getFileName().toString() + "...");
|
||||
|
||||
FileWriter fileWriter = new FileWriter(file, true);
|
||||
PrintWriter printWriter = new PrintWriter(fileWriter);
|
||||
|
||||
printWriter.println();
|
||||
printWriter.println();
|
||||
printWriter.println("// ---------- FILLER FUNCTIONS ----------");
|
||||
printWriter.println();
|
||||
|
||||
for (String s : fillFunctions) {
|
||||
printWriter.println(s);
|
||||
try (PrintWriter printWriter = new PrintWriter(Files.newBufferedWriter(file, StandardOpenOption.APPEND))) {
|
||||
printWriter.println();
|
||||
printWriter.println();
|
||||
printWriter.println("// ---------- FILLER FUNCTIONS ----------");
|
||||
printWriter.println();
|
||||
}
|
||||
|
||||
printWriter.close();
|
||||
for (String s : fillFunctions) {
|
||||
printWriter.println(s);
|
||||
printWriter.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void filterDirectorySearchMatchingData(String directoryPath, Map<Pattern, String> functions) {
|
||||
Iterator iter = FileUtils.iterateFiles(new File(directoryPath), new String[]{"sql", "js", "txt", "java"}, true);
|
||||
|
||||
while (iter.hasNext()) {
|
||||
File file = (File) iter.next();
|
||||
fileSearchMatchingData(file, functions);
|
||||
}
|
||||
}
|
||||
|
||||
private static Pattern compileJsFunctionPattern(String function) {
|
||||
String jsFunction = "function(\\s)+";
|
||||
return Pattern.compile(jsFunction + function);
|
||||
@@ -95,7 +96,7 @@ public class EventMethodFiller {
|
||||
return functions;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws IOException {
|
||||
filterDirectorySearchMatchingData(ToolConstants.SCRIPTS_PATH + "/event", getFunctions());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package tools.mapletools;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import provider.wz.WZFiles;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -21,7 +21,6 @@ public class MapInfoRetriever {
|
||||
private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("map_info_report.txt");
|
||||
private static final List<Integer> missingInfo = new ArrayList<>();
|
||||
|
||||
private static BufferedReader bufferedReader = null;
|
||||
private static byte status = 0;
|
||||
private static boolean hasInfo;
|
||||
|
||||
@@ -41,11 +40,11 @@ public class MapInfoRetriever {
|
||||
return (d.trim());
|
||||
}
|
||||
|
||||
private static void forwardCursor(int st) {
|
||||
private static void forwardCursor(BufferedReader reader, int st) {
|
||||
String line = null;
|
||||
|
||||
try {
|
||||
while (status >= st && (line = bufferedReader.readLine()) != null) {
|
||||
while (status >= st && (line = reader.readLine()) != null) {
|
||||
simpleToken(line);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -61,7 +60,7 @@ public class MapInfoRetriever {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean translateToken(String token) {
|
||||
private static boolean translateToken(BufferedReader reader, String token) {
|
||||
String d;
|
||||
int temp;
|
||||
|
||||
@@ -76,7 +75,7 @@ public class MapInfoRetriever {
|
||||
}
|
||||
|
||||
temp = status;
|
||||
forwardCursor(temp);
|
||||
forwardCursor(reader, temp);
|
||||
}
|
||||
|
||||
status += 1;
|
||||
@@ -86,45 +85,40 @@ public class MapInfoRetriever {
|
||||
}
|
||||
|
||||
private static void searchMapDirectory(int mapArea) {
|
||||
final File mapDirectory = new File(WZFiles.MAP.getFilePath() + "/Map/Map" + mapArea);
|
||||
final Path mapDirectory = Path.of(WZFiles.MAP.getFilePath() + "/Map/Map" + Integer.toString(mapArea));
|
||||
System.out.println("Parsing map area " + mapArea);
|
||||
try {
|
||||
Iterator<File> iter = FileUtils.iterateFiles(mapDirectory, new String[]{"xml"}, true);
|
||||
System.out.println("Parsing map area " + mapArea);
|
||||
|
||||
while (iter.hasNext()) {
|
||||
File file = iter.next();
|
||||
searchMapFile(file);
|
||||
}
|
||||
} catch (UncheckedIOException e) {
|
||||
System.err.println("Directory " + mapDirectory.getPath() + " does not exist");
|
||||
Files.walk(mapDirectory)
|
||||
.filter(MapInfoRetriever::isRelevantFile)
|
||||
.forEach(MapInfoRetriever::searchMapFile);
|
||||
} catch (UncheckedIOException | IOException e) {
|
||||
System.err.println("Directory " + mapDirectory.getFileName().toString() + " does not exist");
|
||||
}
|
||||
}
|
||||
|
||||
private static void searchMapFile(File file) {
|
||||
private static boolean isRelevantFile(Path file) {
|
||||
return file.getFileName().toString().endsWith(".xml");
|
||||
}
|
||||
|
||||
private static void searchMapFile(Path file) {
|
||||
// This will reference one line at a time
|
||||
String line = null;
|
||||
|
||||
try {
|
||||
InputStreamReader fileReader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
|
||||
bufferedReader = new BufferedReader(fileReader);
|
||||
|
||||
try (BufferedReader reader = Files.newBufferedReader(file)) {
|
||||
hasInfo = false;
|
||||
status = 0;
|
||||
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
if (translateToken(line)) {
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (translateToken(reader, line)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasInfo) {
|
||||
missingInfo.add(Integer.valueOf(file.getName().split(".img.xml")[0]));
|
||||
missingInfo.add(Integer.valueOf(file.getFileName().toString().split(".img.xml")[0]));
|
||||
}
|
||||
|
||||
bufferedReader.close();
|
||||
fileReader.close();
|
||||
} catch (IOException ex) {
|
||||
System.out.println("Error reading file '" + file.getName() + "'");
|
||||
System.out.println("Error reading file '" + file.getFileName().toString() + "'");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package tools.mapletools;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import provider.wz.WZFiles;
|
||||
import server.ItemInformationProvider;
|
||||
import tools.DatabaseConnection;
|
||||
import tools.Pair;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.sql.Connection;
|
||||
@@ -19,7 +20,7 @@ import java.util.*;
|
||||
/**
|
||||
* @author RonanLana
|
||||
* <p>
|
||||
* This application haves 2 objectives: fetch missing drop data relevant to quests,
|
||||
* This application has 2 objectives: fetch missing drop data relevant to quests,
|
||||
* and update the questid from items that are labeled as "Quest Item" on the DB.
|
||||
* <p>
|
||||
* Running it should generate a report file under "output" folder with the search results.
|
||||
@@ -28,6 +29,7 @@ import java.util.*;
|
||||
*/
|
||||
public class QuestItemFetcher {
|
||||
private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("quest_report.txt");
|
||||
private static final Collection<String> RELEVANT_FILE_EXTENSIONS = Set.of(".sql", ".js", ".txt", ".java");
|
||||
private static final int INITIAL_STRING_LENGTH = 50;
|
||||
private static final int INITIAL_LENGTH = 200;
|
||||
private static final boolean DISPLAY_EXTRA_INFO = true; // display items with zero quantity over the quest act WZ
|
||||
@@ -335,22 +337,28 @@ public class QuestItemFetcher {
|
||||
}
|
||||
}
|
||||
|
||||
private static void filterDirectorySearchMatchingData(String path, List<Pair<Integer, Integer>> itemsWithQuest) {
|
||||
Iterator<File> iter = FileUtils.iterateFiles(new File(path), new String[]{"sql", "js", "txt", "java"}, true);
|
||||
|
||||
while (iter.hasNext()) {
|
||||
File file = iter.next();
|
||||
fileSearchMatchingData(file, itemsWithQuest);
|
||||
private static void filterDirectorySearchMatchingData(String filePath, List<Pair<Integer, Integer>> itemsWithQuest) {
|
||||
try {
|
||||
Files.walk(Path.of(filePath))
|
||||
.filter(QuestItemFetcher::isRelevantFile)
|
||||
.forEach(path -> fileSearchMatchingData(path, itemsWithQuest));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Error during recursive file walk", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isRelevantFile(Path file) {
|
||||
String fileName = file.getFileName().toString();
|
||||
return RELEVANT_FILE_EXTENSIONS.stream().anyMatch(fileName::endsWith);
|
||||
}
|
||||
|
||||
private static boolean foundMatchingDataOnFile(String fileContent, String searchStr) {
|
||||
return fileContent.contains(searchStr);
|
||||
}
|
||||
|
||||
private static void fileSearchMatchingData(File file, List<Pair<Integer, Integer>> itemsWithQuest) {
|
||||
private static void fileSearchMatchingData(Path file, List<Pair<Integer, Integer>> itemsWithQuest) {
|
||||
try {
|
||||
String fileContent = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
|
||||
String fileContent = Files.readString(file);
|
||||
|
||||
List<Pair<Integer, Integer>> copyItemsWithQuest = new ArrayList<>(itemsWithQuest);
|
||||
for (Pair<Integer, Integer> iq : copyItemsWithQuest) {
|
||||
@@ -359,7 +367,7 @@ public class QuestItemFetcher {
|
||||
}
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
System.out.println("Failed to read file: " + file.getAbsolutePath());
|
||||
System.out.println("Failed to read file: " + file.getFileName().toAbsolutePath().toString());
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -374,7 +382,7 @@ public class QuestItemFetcher {
|
||||
List<Map.Entry<Integer, Integer>> list = new ArrayList<>(map.size());
|
||||
list.addAll(map.entrySet());
|
||||
|
||||
list.sort((o1, o2) -> o1.getKey() - o2.getKey());
|
||||
list.sort(Comparator.comparingInt(Map.Entry::getKey));
|
||||
|
||||
return list;
|
||||
}
|
||||
@@ -383,7 +391,7 @@ public class QuestItemFetcher {
|
||||
List<Map.Entry<Integer, int[]>> list = new ArrayList<>(map.size());
|
||||
list.addAll(map.entrySet());
|
||||
|
||||
list.sort((o1, o2) -> o1.getKey() - o2.getKey());
|
||||
list.sort(Comparator.comparingInt(Map.Entry::getKey));
|
||||
|
||||
return list;
|
||||
}
|
||||
@@ -394,12 +402,12 @@ public class QuestItemFetcher {
|
||||
List<Integer> il = new ArrayList<>(2);
|
||||
il.addAll(e.getValue());
|
||||
|
||||
il.sort((o1, o2) -> o1 - o2);
|
||||
il.sort(Comparator.comparingInt(o -> o));
|
||||
|
||||
list.add(new Pair<>(e.getKey(), il));
|
||||
}
|
||||
|
||||
list.sort((o1, o2) -> o1.getLeft() - o2.getLeft());
|
||||
list.sort(Comparator.comparingInt(Pair::getLeft));
|
||||
|
||||
return list;
|
||||
}
|
||||
@@ -446,7 +454,7 @@ public class QuestItemFetcher {
|
||||
System.out.println("Filtering drops on project files...");
|
||||
// finally, filter whether this item is mentioned on the source code or not.
|
||||
filterDirectorySearchMatchingData("scripts", itemsWithQuest);
|
||||
filterDirectorySearchMatchingData("sql", itemsWithQuest);
|
||||
filterDirectorySearchMatchingData("database/sql", itemsWithQuest);
|
||||
filterDirectorySearchMatchingData("src", itemsWithQuest);
|
||||
|
||||
System.out.println("Reporting results...");
|
||||
|
||||
Reference in New Issue
Block a user