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: extract program #52

Merged
merged 1 commit into from
Jul 11, 2017
Merged

Issue #37: extract program #52

merged 1 commit into from
Jul 11, 2017

Conversation

Luolc
Copy link
Contributor

@Luolc Luolc commented Jul 6, 2017

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

  • name
  • packageName
  • parent
  • interfaces
  • hierarchies
  • properties
  • tokens

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.

@rnveach
Copy link
Member

rnveach commented Jul 6, 2017

pom.xml in checkstyle should be added a Gson dependency.

Checkstyle doesn't want any changes in their repository for our process, so this won't be possible.

See my comment at #37 (comment) :

So we don't have to inject gson dependency into Checkstyle too, I think we should just write out file by hand.

Otherwise, we have to inject test dependency into their POM, which may not be pretty and require us undoing the change after our process.

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.

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

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

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

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.

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.

@Luolc
Copy link
Contributor Author

Luolc commented Jul 7, 2017

@rnveach

Checkstyle doesn't want any changes in their repository for our process, so this won't be possible.
Otherwise, we have to inject test dependency into their POM, which may not be pretty and require us undoing the change after our process.

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 pom.xml changes one day, the maven process would fail quickly and then we would fix it. And I think this way is much better than we generate the file by our hand.

All the clear up operation can be done with a simple git checkout ., whatever JGit or just running command line Git. So we don't need to be worried about clearing.

@rnveach
Copy link
Member

rnveach commented Jul 7, 2017

If pom.xml changes one day, the maven process would fail quickly and then we would fix it.

Whereas if we write file by hand, it will never fail.
What are we gaining by adding this dependency besides easier to make/maintain code?
Adding dependency will make it harder to test in a travis build as travis was going to be a separate process from our production code.

@Luolc Luolc force-pushed the issue37-2 branch 2 times, most recently from c711cf3 to e083a53 Compare July 10, 2017 10:40
@Luolc
Copy link
Contributor Author

Luolc commented Jul 10, 2017

@rnveach Updated with our own json generation codes.

@rnveach
Copy link
Member

rnveach commented Jul 10, 2017

We need a way to ensure this file is compilable, especially in checkstyle process.

@Luolc Can you update travis to make sure this code compiles and executes without exception?

@Luolc
Copy link
Contributor Author

Luolc commented Jul 10, 2017

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

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better in #50 ? The test on generated file needs a lot of process of read/convert/... And many logic are included in #50 . Should we combine the changes of these two PR and close one of them?

Copy link
Member

@rnveach rnveach Jul 10, 2017

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.

Copy link
Contributor Author

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:

  1. check it is a valid json
  2. 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?

Copy link
Member

@rnveach rnveach Jul 11, 2017

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.

Copy link
Contributor Author

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JsonUtil

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.

import java.util.stream.Collectors;

/**
* Our own Json processing classes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

processing classes => processing utility.

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.

@rnveach
Copy link
Member

rnveach commented Jul 10, 2017

@Luolc One final thing, can you upload the result of this process somewhere for us to look at during GSoC?
Please name it after commit hash from CS project you use it on.

@Luolc
Copy link
Contributor Author

Luolc commented Jul 11, 2017

@rnveach Do you mean upload it every time sending a PR? I may try to add a deploy operation in Travis.

@rnveach
Copy link
Member

rnveach commented Jul 11, 2017

@Luolc I meant a one time upload in a place where we can look back on it in the future.
Every PR is not needed.

http://textuploader.com/ or something similar maybe?

@Luolc
Copy link
Contributor Author

Luolc commented Jul 11, 2017

@rnveach
Copy link
Member

rnveach commented Jul 11, 2017

Don't exactly understand the way actually...

If you mena the way to execute the test to make sure it passes with no errors, see #37 (comment)

Execute extract program as a one time junit. See https://github.com/sevntu-checkstyle/sevntu.checkstyle/blob/64d616821b2d2265fb8291fd6950b4eef83c4547/.travis.yml#L68 on how to do this execution.

It should literally just be && mvn test -Dtest=ExtractInfoGeneratorTest#generateExtractInfoFile

@Luolc
Copy link
Contributor Author

Luolc commented Jul 11, 2017

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

@rnveach
Copy link
Member

rnveach commented Jul 11, 2017

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.
What is in gist can also be tested by itself.

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.

missed this before.

if (ModuleReflectionUtils.isCheckstyleCheck(clazz)) {
parent = "TreeWalker";
}
else if (RootModule.class.isAssignableFrom(clazz)) {
Copy link
Member

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

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.

@rnveach rnveach merged commit 000ef03 into checkstyle:master Jul 11, 2017
@Luolc Luolc deleted the issue37-2 branch July 11, 2017 09:52
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