-
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: extract program #52
Conversation
Checkstyle doesn't want any changes in their repository for our process, so this won't be possible. See my comment at #37 (comment) :
Otherwise, we have to inject test dependency into their POM, which may not be pretty and require us undoing the change after our process. |
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 need a way to ensure this file is compilable, especially in checkstyle process.
I suggest we use a new travis item where we clone checkstyle, move our file there, and just test for success on mvn compile
.
We can go further and test execution of file to make sure it doesn't atleast throw exception or fail.
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonObject; |
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.
See my comments.
@Test | ||
public void generateExtractInfoFile() throws IOException { | ||
final Gson gson = new GsonBuilder().setPrettyPrinting().create(); | ||
final List<JsonObject> objects = CheckUtil.getCheckstyleModules().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.
One issue with CheckUtil.getCheckstyleModules
is we can't test on old commits.
I think we should find someway to be more backward compatible. This can be a new issue.
if (ModuleReflectionUtils.isCheckstyleCheck(clazz)) { | ||
parent = "TreeWalker"; | ||
} | ||
else if ("Checker".equals(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.
Check if it is a root module instead of Checker
.
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.
I don't mean that we need change in checkstyle main repo. At the meantime we do the injection, we just need to find this line, https://github.com/checkstyle/checkstyle/blob/master/pom.xml#L267, and add the dependency below the line. If All the clear up operation can be done with a simple |
Whereas if we write file by hand, it will never fail. |
c711cf3
to
e083a53
Compare
@rnveach Updated with our own json generation codes. |
@Luolc Can you update travis to make sure this code compiles and executes without exception? |
@rnveach Done. |
.travis.yml
Outdated
- CMD5="checkstyle/src/test/java/com/puppycrawl/tools/checkstyle/Json.java &&" | ||
- CMD6="cd checkstyle &&" | ||
- CMD7="mvn clean compile" | ||
- CMD="$CMD1$CMD2$CMD3$CMD4$CMD5$CMD6$CMD7" |
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 can go further and test execution of file to make sure it doesn't atleast throw exception or fail.
What about this statement?
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.
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 am fine with this being separated.
I don't expect this to be done in #50 in the junits (if that was what your thinking), as junits won't be cloning the external repository as part of their tests. They should be pretty quick tests, which is why missing code coverage for this one script is fine. That is why travis makes better sense for doing all these long complicated tasks.
Once you add this to travis I will merge this PR as it will be confirmed working.
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.
What level of the test should be? The ones I could think out now:
- check it is a valid json
- check whether it is in correct format(a list, each item contains "name", "packageName" etc)
Do you have anything to add?
And, to test a json format is much hard to do with only shell script, if we won't do it in UT, then could we use other script lang like Groovy?
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 no exception test is fine for now in travis.
Travis won't be verifying output for now. We can manually confirm this.
Later since this extract program should work on all checkstyle versions, we could try to use release version for code coverage and expected output in another issue.
I don't want to put something like this with full cloning in JUnits.
We may have to import Checkstyle release's test JAR dependency to accomplish this.
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.
@rnveach Don't exactly understand the way actually...
But let's do the further discussion in the issue for this, if you think current test is fine for now. :) Should I create that issue now?
* Our own Json processing classes. | ||
* @author LuoLiangchen | ||
*/ | ||
class Json { |
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.
JsonUtil
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.
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Our own Json processing classes. |
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.
processing classes
=> processing utility
.
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.
@Luolc One final thing, can you upload the result of this process somewhere for us to look at during GSoC? |
@rnveach Do you mean upload it every time sending a PR? I may try to add a deploy operation in Travis. |
@Luolc I meant a one time upload in a place where we can look back on it in the future. http://textuploader.com/ or something similar maybe? |
@rnveach I upload a gist: https://gist.github.com/Luolc/f3898dc507d66d21b48d85c1c09e5001 |
If you mena the way to execute the test to make sure it passes with no errors, see #37 (comment)
It should literally just be |
@rnveach Oh I think I misunderstood this. I was thinking to test the json format. If you mean run this UT, I am clear of the way. |
I assume you already tested the json format since you had it originally in our repo with the full thing but than trimmed it down for just what we used in tests. |
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.
missed this before.
if (ModuleReflectionUtils.isCheckstyleCheck(clazz)) { | ||
parent = "TreeWalker"; | ||
} | ||
else if (RootModule.class.isAssignableFrom(clazz)) { |
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.
RootModule.class.isAssignableFrom
=> ModuleReflectionUtils.isRootModule
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.
#37
This is the file that would be injected into checkstyle project.
Also we should update
pom.xml
in checkstyle to add a Gson dependency.As mentioned at https://github.com/checkstyle/regression-tool/pulls#issuecomment-310935967, we ignored the last two for now.
Edit: If necessary, I am fine with combining this PR with #50 into one PR together.