15
15
* You should have received a copy of the GNU General Public License
16
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
*/
18
- package io .yooksi .pz .zdoc ;
18
+ package io .cocolabs .pz .zdoc ;
19
19
20
20
import java .io .File ;
21
21
import java .io .FileNotFoundException ;
22
22
import java .io .IOException ;
23
- import java .nio .charset .Charset ;
23
+ import java .io .InputStream ;
24
+ import java .nio .charset .StandardCharsets ;
24
25
import java .nio .file .Files ;
25
26
import java .nio .file .Path ;
26
27
import java .nio .file .Paths ;
27
28
import java .util .*;
28
29
import java .util .stream .Collectors ;
30
+ import java .util .stream .Stream ;
29
31
30
32
import org .apache .commons .cli .ParseException ;
31
33
import org .apache .commons .io .FileUtils ;
32
34
import org .apache .commons .lang3 .StringUtils ;
33
35
import org .apache .commons .lang3 .reflect .MethodUtils ;
34
36
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 ;
49
48
50
49
public class Main {
51
50
52
- public static final String CHARSET = Charset . defaultCharset () .name ();
51
+ public static final String CHARSET = StandardCharsets . UTF_8 .name ();
53
52
public static final ClassLoader CLASS_LOADER = Main .class .getClassLoader ();
54
53
55
54
/**
@@ -79,13 +78,32 @@ else if (command == Command.HELP)
79
78
else if (command == Command .VERSION )
80
79
{
81
80
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
+
82
99
Class <?> coreClass = Utils .getClassForName ("zombie.core.Core" );
83
100
Object core = MethodUtils .invokeStaticMethod (coreClass , "getInstance" );
84
101
85
102
Object gameVersion = MethodUtils .invokeExactMethod (core , "getGameVersion" );
86
103
Object sGameVersion = MethodUtils .invokeExactMethod (gameVersion , "toString" );
87
104
88
105
Logger .info ("game version " + sGameVersion );
106
+ return ;
89
107
}
90
108
catch (ReflectiveOperationException e ) {
91
109
throw new RuntimeException (e );
@@ -98,10 +116,11 @@ else if (command == Command.VERSION)
98
116
Logger .debug ("Preparing to parse and document lua files..." );
99
117
100
118
Path root = cmdLine .getInputPath ();
119
+ List <Path > paths ;
101
120
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
+ }
105
124
if (paths .size () > 1 ) {
106
125
Logger .info ("Parsing and documenting lua files found in " + root );
107
126
}
@@ -145,8 +164,8 @@ else if (dir != null)
145
164
String fileName = path .getFileName ().toString ();
146
165
List <String > content = new ArrayList <>();
147
166
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 );
150
169
151
170
String addendum = outputFile .exists () ? " and overwriting" : "" ;
152
171
Logger .debug (String .format ("Annotating%s file %s..." , addendum , fileName ));
0 commit comments