Skip to content
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

Merged
merged 1 commit into from
Jun 28, 2017
Merged

Conversation

Luolc
Copy link
Contributor

@Luolc Luolc commented Jun 26, 2017

Issue #37

Taken from #33 , this is blocked by #38 and #39

@Luolc Luolc mentioned this pull request Jun 26, 2017
new InputStreamReader(stream, Charset.forName("UTF-8"));

try {
modules = GSON.fromJson(reader, new TypeToken<List<ModuleExtractInfo>>() {
Copy link
Member

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.

Copy link
Contributor Author

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) {
Copy link
Member

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.

Copy link
Contributor Author

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());
Copy link
Member

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.

Copy link
Contributor Author

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).

Copy link
Member

@rnveach rnveach left a 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.

@@ -7,6 +7,15 @@
<allow pkg="java.io"/>
<allow pkg="java.util"/>
<allow pkg="com.github.checkstyle.regression.data"/>
<allow pkg="org.immutables"/>
Copy link
Member

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());
Copy link
Member

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.

Copy link
Contributor Author

@Luolc Luolc Jun 27, 2017

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.

@Luolc Luolc force-pushed the issue37-part1 branch 3 times, most recently from 222ebb4 to fcf0f9c Compare June 27, 2017 17:36
@Luolc
Copy link
Contributor Author

Luolc commented Jun 27, 2017

Done: Rebased and json trimmed.

<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"/>
Copy link
Member

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.

Copy link
Contributor Author

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.
Copy link
Member

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...

Copy link
Contributor Author

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());
Copy link
Member

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.

Copy link
Contributor Author

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(
Copy link
Member

@rnveach rnveach Jun 27, 2017

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.

Copy link
Contributor Author

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(
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

@rnveach rnveach left a 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.
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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...

Copy link
Contributor Author

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

Copy link
Member

@rnveach rnveach Jun 28, 2017

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

@rnveach rnveach merged commit 567d5b7 into checkstyle:master Jun 28, 2017
@Luolc Luolc deleted the issue37-part1 branch June 28, 2017 17:12
@rnveach
Copy link
Member

rnveach commented Jun 28, 2017

Merged.

@Luolc As you do only pieces of issue, please keep main issue updated with what is left to do in new post.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants