-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #37: json file processor #40
Conversation
new InputStreamReader(stream, Charset.forName("UTF-8")); | ||
|
||
try { | ||
modules = GSON.fromJson(reader, new TypeToken<List<ModuleExtractInfo>>() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move new TypeToken
to a static final field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
* @return the full qualified name to module extract info map | ||
*/ | ||
public static Map<String, ModuleExtractInfo> getNameToModuleExtractInfoFromInputStream( | ||
InputStream stream) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InputStream
is fine, but you take that and than wrap it around InputStreamReader
for UTF 8 support.
Shouldn't class that creates the stream define what charset the file should support and not this method?
I think we should either remove InputStreamReader
and stick with InputStream
or change this parameter to InputStreamReader
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change this parameter to InputStreamReader
Done.
.getResourceAsStream("checkstyle_modules.json"); | ||
final Map<String, ModuleExtractInfo> map = | ||
ExtractInfoProcessor.getNameToModuleExtractInfoFromInputStream(is); | ||
assertEquals(165, map.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trim test json
file to only include items needed for specific testing.
We don't need full copy of checkstyle repo for basic testing.
If we find something we need later in it, we will expand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. And, IMO, it is better to create another json file only for ExtractInfoProcessorTest
, with a name like checkstyle_modules_sample.json
(and maybe in resources/.../extract
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rebase on latest master. Than I can more closely review what is only for this PR.
config/import-control.xml
Outdated
@@ -7,6 +7,15 @@ | |||
<allow pkg="java.io"/> | |||
<allow pkg="java.util"/> | |||
<allow pkg="com.github.checkstyle.regression.data"/> | |||
<allow pkg="org.immutables"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and other similar items should go away with rebase.
final InputStreamReader reader = new InputStreamReader(is, Charset.forName("UTF-8")); | ||
final Map<String, ModuleExtractInfo> map = | ||
ExtractInfoProcessor.getNameToModuleExtractInfoFromInputStream(reader); | ||
assertEquals(165, map.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was listed as outdated but is still not done.
it is better to create another json file only for ExtractInfoProcessorTest, with a name like checkstyle_modules_sample.json
I am fine with 1 or multiple json files. If we do multiple, they should be trimmed down to bare bones for test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Emm... now I decide to keep this json file name currently. And if we find it is necessary to split the json file when we are doing main code of module component, we do the split then.
Done.
222ebb4
to
fcf0f9c
Compare
Done: Rebased and json trimmed. |
config/import-control.xml
Outdated
<allow pkg="com.google.gson"/> | ||
<allow class="com.sun.tools.javac.util.ServiceLoader"/> | ||
<allow class="java.lang.reflect.Type"/> | ||
<allow class="java.nio.charset.Charset"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be needed since it is not imported in main code.
Please remove and confirm the others are needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
/** | ||
* Contains checkstyle maven command executing codes and extract file processor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
executing codes
?
Change to Contains execution of checkstyle maven extract process and...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
.packageName(BASE_PACKAGE + ".checks.coding") | ||
.parent("TreeWalker") | ||
.build(); | ||
assertEquals(2, map.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We started requiring assertion messages in main repo by PMD.
This project doesn't have the newly updated PMD, but I may add it soon.
Please make sure all new assertions in PRs have message. It can be very simple phrase.
Check out main project for any examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
* @param reader the given reader | ||
* @return the full qualified name to module extract info map | ||
*/ | ||
public static Map<String, ModuleExtractInfo> getNameToModuleExtractInfoFromReader( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getNameToModuleExtractInfo
This makes it sound like we are passing to the method name
as a parameter and it is giving us ModuleExtractInfo
. We aren't giving it any parameters.
Please rename to something like getModuleExtractInfoFromReader
or such.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
} | ||
} | ||
catch (IOException ex) { | ||
throw new IllegalStateException( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throwing as a runtime exception is fine, but we will never be able to catch it in Main
if we wish to add any more information to it. Please confirm this is your intent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only way to go into catch block is reader.close()
throwing an exception. I think it is rare. Instead of this, GSON.fromJson
is more likely to throwing exception sometimes (wrong format, etc.). Json exception is not caught here so we could use them in main if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Json exception is not caught here so we could use them in main
Method has no throws Exception
declaration so then all throwable exceptions, if any, are runtime.
We can't do anything about GSON
but if we know an error is possible, we should not use runtime exceptions.
We can ignore this for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything else looks fine and I will merge when done.
} | ||
|
||
/** | ||
* Gets the full qualified name to module extract info map from the given reader. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remember to update Javadoc if you change method. This is the 3rd time now.
Gets the full qualified name to module extract info map
=> Gets the module extract info map
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did check this javadoc and I thought a "key to value map" description is clearer and kept it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My building is on a unexpected power cut god...
I can only use GitHub on my phone and there is no edit function on it...
Maybe map of full qualified name to module extract info
is better? It refers the javadoc of the hardcode map in PackageObjectFactory. I am not able to write the link to it on my phone...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really think a key to value description is necessary. If no description of the key in neither javadoc nor method name, it's confused what the key is when we use the method elsewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Luolc The issue is name to module extract info
which is what method was named and we did away with it at #40 (comment) . This is specifically the text I want removed. Anything else is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a "key to value map" description is clearer
How about this: Gets the module extract info map from the given reader. Map key is the fully qualified module name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good. :D Updated.
Merged. @Luolc As you do only pieces of issue, please keep main issue updated with what is left to do in new post. |
Issue #37
Taken from #33 , this is blocked by #38 and #39