Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
LanguageFileCompare
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Jira
Jira
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
測試專案
LanguageFileCompare
Commits
75f97ae2
Commit
75f97ae2
authored
Nov 27, 2018
by
王品堯
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add properties files check
parent
4be171ae
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
1 deletion
+63
-1
src/main/java/JsonFileCompare.java
src/main/java/JsonFileCompare.java
+63
-1
No files found.
src/main/java/JsonFileCompare.java
View file @
75f97ae2
...
...
@@ -4,6 +4,8 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
...
...
@@ -23,11 +25,11 @@ public class JsonFileCompare {
addKeys
(
""
,
twJson
,
originSet
,
new
ArrayList
<>());
IntStream
.
range
(
1
,
args
.
length
).
forEach
(
i
->
findMissingKeys
(
Paths
.
get
(
args
[
i
]),
originSet
));
}
catch
(
Exception
e
)
{
log
.
error
(
"{} is not exists or not json files."
,
args
[
0
],
e
);
System
.
exit
(
1
);
}
checkProperties
();
}
private
static
void
addKeys
(
...
...
@@ -78,4 +80,64 @@ public class JsonFileCompare {
System
.
exit
(
1
);
}
}
private
static
void
checkProperties
()
{
String
path
=
"./src/main/resources/i18n/"
;
String
extension
=
".properties"
;
Map
<
String
,
List
<
String
>>
map
=
Arrays
.
stream
(
Optional
.
ofNullable
(
Paths
.
get
(
path
).
toFile
().
list
((
dir
,
name
)
->
name
.
endsWith
(
extension
)))
.
orElse
(
new
String
[
0
]))
.
map
(
s
->
s
.
split
(
extension
)[
0
])
.
collect
(
Collectors
.
groupingBy
(
filename
->
filename
.
split
(
"_"
)[
0
],
Collectors
.
mapping
(
l
->
path
+
l
+
extension
,
Collectors
.
toList
())));
for
(
Map
.
Entry
<
String
,
List
<
String
>>
entry
:
map
.
entrySet
())
{
List
<
String
>
twList
=
entry
.
getValue
()
.
stream
()
.
filter
(
fileName
->
fileName
.
contains
(
"zh_TW"
))
.
collect
(
Collectors
.
toList
());
List
<
String
>
otherList
=
entry
.
getValue
()
.
stream
()
.
filter
(
fileName
->
!
fileName
.
contains
(
"zh_TW"
))
.
collect
(
Collectors
.
toList
());
if
(
twList
.
isEmpty
()
||
otherList
.
isEmpty
())
continue
;
try
{
Set
<
String
>
originKeySet
=
getKeys
(
twList
.
get
(
0
));
for
(
String
target
:
otherList
)
{
Set
<
String
>
targetKeySet
=
getKeys
(
target
);
Set
<
String
>
missingSet
=
originKeySet
.
parallelStream
()
.
filter
(
k
->
!
targetKeySet
.
contains
(
k
))
.
collect
(
Collectors
.
toSet
());
if
(!
missingSet
.
isEmpty
())
{
log
.
error
(
"Missing Key on {} \nMissing Keys: {}"
,
Paths
.
get
(
target
).
getFileName
(),
missingSet
);
System
.
exit
(
1
);
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"check i18n properties error."
,
e
);
System
.
exit
(
1
);
}
}
}
private
static
Set
<
String
>
getKeys
(
String
fileName
)
throws
IOException
{
Properties
properties
=
new
Properties
();
properties
.
load
(
new
FileInputStream
(
fileName
));
return
new
HashSet
(
Collections
.
list
(
properties
.
propertyNames
()));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment