Skip to content

Commit b27b767

Browse files
committed
Release ZomboidDoc v3.0.0
Resolves: #56
2 parents 8b3346f + 2203345 commit b27b767

File tree

105 files changed

+526
-468
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+526
-468
lines changed

.idea/runConfigurations/Annotate_Lua.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/Compile_Lua.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Read [Commands](#commands) and [Examples](#examples) section for more informatio
6969
Here is an overview list of available commands:
7070

7171
- `help` - print command usage info for all available commands.
72-
- `version` - print Project Zomboid game installation version.
72+
- `version` - print application and game version information.
7373
- `annotate` - annotate vanilla Lua files with EmmyLua.
7474
- `compile` - compile Lua library from modding API.
7575

build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ apply from: 'setup.gradle'
2424
apply from: 'spotless.gradle'
2525
apply from: 'distribution.gradle'
2626

27-
group 'io.yooksi'
28-
version '2.2.0'
27+
group 'io.cocolabs'
28+
version file('version.txt').readLines().get(0)
2929

3030
wrapper {
3131
distributionType = Wrapper.DistributionType.ALL
3232
}
3333

3434
application {
35-
mainClassName = 'io.yooksi.pz.zdoc.Main'
35+
mainClassName = 'io.cocolabs.pz.zdoc.Main'
3636
}
3737

3838
java {

buildSrc/src/main/java/ZUnixStartScriptGenerator.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.InputStream;
2020
import java.io.Writer;
2121
import java.nio.charset.Charset;
22+
import java.nio.charset.StandardCharsets;
2223
import java.util.Map;
2324
import java.util.Objects;
2425
import java.util.regex.Matcher;
@@ -36,7 +37,7 @@
3637
@NonNullApi
3738
public class ZUnixStartScriptGenerator implements ScriptGenerator {
3839

39-
private static final Charset CHARSET = Charset.defaultCharset();
40+
private static final Charset CHARSET = StandardCharsets.UTF_8;
4041
private static final ClassLoader CL = ZUnixStartScriptGenerator.class.getClassLoader();
4142

4243
private static final String[] CLASSPATH_ADDENDUM = new String[]{

buildSrc/src/main/java/ZWindowsStartScriptGenerator.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.InputStream;
2020
import java.io.Writer;
2121
import java.nio.charset.Charset;
22+
import java.nio.charset.StandardCharsets;
2223
import java.util.Map;
2324
import java.util.Objects;
2425
import java.util.regex.Matcher;
@@ -36,7 +37,7 @@
3637
@NonNullApi
3738
public class ZWindowsStartScriptGenerator implements ScriptGenerator {
3839

39-
private static final Charset CHARSET = Charset.defaultCharset();
40+
private static final Charset CHARSET = StandardCharsets.UTF_8;
4041
private static final ClassLoader CL = ZWindowsStartScriptGenerator.class.getClassLoader();
4142

4243
private static final String[] CLASSPATH_ADDENDUM = new String[]{

distribution.gradle

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ tasks.register("generateChangelog", Exec.class) {
5858

5959
distributions.main.contents {
6060
it.from ('README.md', 'LICENSE.txt', 'CHANGELOG.md')
61+
// version.txt is used by version command
62+
it.from(projectDir) {
63+
it.include 'version.txt'
64+
}
6165
it.exclude {
6266
File file = it.file
6367
String filename = file.getName()

src/intTest/java/io/yooksi/pz/zdoc/IntegrationTest.java src/intTest/java/io/cocolabs/pz/zdoc/IntegrationTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ZomboidDoc - Lua library compiler for Project Zomboid
3-
* Copyright (C) 2021 Matthew Cain
3+
* Copyright (C) 2020-2021 Matthew Cain
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
1515
* You should have received a copy of the GNU General Public License
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
package io.yooksi.pz.zdoc;
18+
package io.cocolabs.pz.zdoc;
1919

2020
import java.io.File;
2121
import java.io.IOException;

src/intTest/java/io/yooksi/pz/zdoc/MainTest.java src/intTest/java/io/cocolabs/pz/zdoc/MainTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ZomboidDoc - Lua library compiler for Project Zomboid
3-
* Copyright (C) 2021 Matthew Cain
3+
* Copyright (C) 2020-2021 Matthew Cain
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -15,13 +15,13 @@
1515
* You should have received a copy of the GNU General Public License
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
package io.yooksi.pz.zdoc;
18+
package io.cocolabs.pz.zdoc;
1919

2020
import java.util.List;
2121

2222
import org.jetbrains.annotations.TestOnly;
2323

24-
import io.yooksi.pz.zdoc.cmd.Command;
24+
import io.cocolabs.pz.zdoc.cmd.Command;
2525

2626
class MainTest extends TestWorkspace implements IntegrationTest {
2727

src/intTest/java/io/yooksi/pz/zdoc/compile/JavaCompilerIntTest.java src/intTest/java/io/cocolabs/pz/zdoc/compile/JavaCompilerIntTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ZomboidDoc - Lua library compiler for Project Zomboid
3-
* Copyright (C) 2021 Matthew Cain
3+
* Copyright (C) 2020-2021 Matthew Cain
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
1515
* You should have received a copy of the GNU General Public License
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
package io.yooksi.pz.zdoc.compile;
18+
package io.cocolabs.pz.zdoc.compile;
1919

2020
import java.io.File;
2121
import java.io.IOException;
@@ -30,7 +30,7 @@
3030
import org.junit.jupiter.api.Test;
3131
import org.opentest4j.AssertionFailedError;
3232

33-
import io.yooksi.pz.zdoc.IntegrationTest;
33+
import io.cocolabs.pz.zdoc.IntegrationTest;
3434

3535
class JavaCompilerIntTest implements IntegrationTest {
3636

src/main/java/io/yooksi/pz/zdoc/Main.java src/main/java/io/cocolabs/pz/zdoc/Main.java

+41-22
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,40 @@
1515
* You should have received a copy of the GNU General Public License
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
package io.yooksi.pz.zdoc;
18+
package io.cocolabs.pz.zdoc;
1919

2020
import java.io.File;
2121
import java.io.FileNotFoundException;
2222
import java.io.IOException;
23-
import java.nio.charset.Charset;
23+
import java.io.InputStream;
24+
import java.nio.charset.StandardCharsets;
2425
import java.nio.file.Files;
2526
import java.nio.file.Path;
2627
import java.nio.file.Paths;
2728
import java.util.*;
2829
import java.util.stream.Collectors;
30+
import java.util.stream.Stream;
2931

3032
import org.apache.commons.cli.ParseException;
3133
import org.apache.commons.io.FileUtils;
3234
import org.apache.commons.lang3.StringUtils;
3335
import org.apache.commons.lang3.reflect.MethodUtils;
3436

35-
import io.yooksi.pz.zdoc.cmd.Command;
36-
import io.yooksi.pz.zdoc.cmd.CommandLine;
37-
import io.yooksi.pz.zdoc.compile.CompilerException;
38-
import io.yooksi.pz.zdoc.compile.JavaCompiler;
39-
import io.yooksi.pz.zdoc.compile.LuaAnnotator;
40-
import io.yooksi.pz.zdoc.compile.LuaCompiler;
41-
import io.yooksi.pz.zdoc.doc.ZomboidJavaDoc;
42-
import io.yooksi.pz.zdoc.doc.ZomboidLuaDoc;
43-
import io.yooksi.pz.zdoc.element.lua.LuaClass;
44-
import io.yooksi.pz.zdoc.logger.Logger;
45-
import io.yooksi.pz.zdoc.util.Utils;
46-
47-
import static io.yooksi.pz.zdoc.compile.LuaAnnotator.AnnotateResult;
48-
import static io.yooksi.pz.zdoc.compile.LuaAnnotator.AnnotateRules;
37+
import io.cocolabs.pz.zdoc.cmd.Command;
38+
import io.cocolabs.pz.zdoc.cmd.CommandLine;
39+
import io.cocolabs.pz.zdoc.compile.CompilerException;
40+
import io.cocolabs.pz.zdoc.compile.JavaCompiler;
41+
import io.cocolabs.pz.zdoc.compile.LuaAnnotator;
42+
import io.cocolabs.pz.zdoc.compile.LuaCompiler;
43+
import io.cocolabs.pz.zdoc.doc.ZomboidJavaDoc;
44+
import io.cocolabs.pz.zdoc.doc.ZomboidLuaDoc;
45+
import io.cocolabs.pz.zdoc.element.lua.LuaClass;
46+
import io.cocolabs.pz.zdoc.logger.Logger;
47+
import io.cocolabs.pz.zdoc.util.Utils;
4948

5049
public class Main {
5150

52-
public static final String CHARSET = Charset.defaultCharset().name();
51+
public static final String CHARSET = StandardCharsets.UTF_8.name();
5352
public static final ClassLoader CLASS_LOADER = Main.class.getClassLoader();
5453

5554
/**
@@ -79,13 +78,32 @@ else if (command == Command.HELP)
7978
else if (command == Command.VERSION)
8079
{
8180
try {
81+
/* first try to find version file project root directory,
82+
* available when we are not running from a jar
83+
*/
84+
String zdocVersion;
85+
File versionFile = new File("version.txt");
86+
if (!versionFile.exists())
87+
{
88+
try (InputStream iStream = CLASS_LOADER.getResourceAsStream("version.txt"))
89+
{
90+
if (iStream == null) {
91+
throw new FileNotFoundException("Unable to read version, missing version.txt");
92+
}
93+
zdocVersion = iStream.toString();
94+
}
95+
}
96+
else zdocVersion = FileUtils.readFileToString(versionFile, CHARSET);
97+
Logger.info("zdoc version " + zdocVersion);
98+
8299
Class<?> coreClass = Utils.getClassForName("zombie.core.Core");
83100
Object core = MethodUtils.invokeStaticMethod(coreClass, "getInstance");
84101

85102
Object gameVersion = MethodUtils.invokeExactMethod(core, "getGameVersion");
86103
Object sGameVersion = MethodUtils.invokeExactMethod(gameVersion, "toString");
87104

88105
Logger.info("game version " + sGameVersion);
106+
return;
89107
}
90108
catch (ReflectiveOperationException e) {
91109
throw new RuntimeException(e);
@@ -98,10 +116,11 @@ else if (command == Command.VERSION)
98116
Logger.debug("Preparing to parse and document lua files...");
99117

100118
Path root = cmdLine.getInputPath();
119+
List<Path> paths;
101120
Path dir = cmdLine.getOutputPath();
102-
List<Path> paths = Files.walk(Paths.get(root.toString()))
103-
.filter(Files::isRegularFile).collect(Collectors.toCollection(ArrayList::new));
104-
121+
try (Stream<Path> stream = Files.walk(Paths.get(root.toString()))) {
122+
paths = stream.filter(Files::isRegularFile).collect(Collectors.toCollection(ArrayList::new));
123+
}
105124
if (paths.size() > 1) {
106125
Logger.info("Parsing and documenting lua files found in " + root);
107126
}
@@ -145,8 +164,8 @@ else if (dir != null)
145164
String fileName = path.getFileName().toString();
146165
List<String> content = new ArrayList<>();
147166

148-
AnnotateRules rules = new AnnotateRules(properties, exclude);
149-
AnnotateResult result = LuaAnnotator.annotate(path.toFile(), content, rules);
167+
LuaAnnotator.AnnotateRules rules = new LuaAnnotator.AnnotateRules(properties, exclude);
168+
LuaAnnotator.AnnotateResult result = LuaAnnotator.annotate(path.toFile(), content, rules);
150169

151170
String addendum = outputFile.exists() ? " and overwriting" : "";
152171
Logger.debug(String.format("Annotating%s file %s...", addendum, fileName));

src/main/java/io/yooksi/pz/zdoc/cmd/Command.java src/main/java/io/cocolabs/pz/zdoc/cmd/Command.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* You should have received a copy of the GNU General Public License
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
package io.yooksi.pz.zdoc.cmd;
18+
package io.cocolabs.pz.zdoc.cmd;
1919

2020
import java.util.Arrays;
2121
import java.util.stream.Collectors;
@@ -28,6 +28,7 @@
2828
/**
2929
* All available application commands.
3030
*/
31+
@SuppressWarnings("ImmutableEnumChecker")
3132
public enum Command {
3233

3334
HELP("help", "", new Options(), "print command usage info"),
@@ -68,7 +69,7 @@ public enum Command {
6869
this(name, HelpFormatter.DEFAULT_OPT_PREFIX, options, help);
6970
}
7071

71-
/** @return {@code Command} that matches the given name. */
72+
/** Returns command that matches the given name. */
7273
public static @Nullable Command get(String name) {
7374

7475
for (Command value : Command.values())
@@ -81,8 +82,9 @@ public enum Command {
8182
}
8283

8384
/**
84-
* @return {@code Command} that matches first element in the given
85-
* array of arguments or {@code null} if no matching command was found.
85+
* Returns command that matches first array element.
86+
*
87+
* @return first array element or {@code null} if no matching command was found.
8688
*
8789
* @throws IllegalArgumentException if argument array is empty.
8890
*/
@@ -95,10 +97,13 @@ public enum Command {
9597
}
9698

9799
/**
98-
* @return {@code Command} that matches first element in the given
99-
* array of arguments or {@code null} if no matching command was found.
100+
* Returns command that matches first array element.
101+
*
102+
* @param fromIndex index to reference the first element from.
103+
* @return first array element or {@code null} if no matching command was found.
100104
*
101105
* @throws IllegalArgumentException if argument array is empty.
106+
* @see #parse(String[])
102107
*/
103108
public static @Nullable Command parse(String[] args, int fromIndex) {
104109

0 commit comments

Comments
 (0)