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: inject, invoke maven command, read file and clean up #50

Merged
merged 1 commit into from
Jul 19, 2017

Conversation

Luolc
Copy link
Contributor

@Luolc Luolc commented Jul 6, 2017

#37

This PR is just showing the abstract design thinking as mentioned at #37 (comment)

We need do the following things:

  1. run Git command to checkout to the PR branch.
  2. move the extract program to checkstyle repo
  3. invoke maven command
  4. read the file to memory
  5. clear

Problems:

  1. Where to put step 1? According to our design of package, there would be no JGit dependency outside git. So should we create a util class in git and use it in extract? If yes, we already have a GitUtils in test scope, we might need to rename it to smth like GitTestUtils and create a GitUtils for production code. If confirmed, we should make split issue for it and discuss there.
  2. CheckstyleInjector is a temporary name. I haven't thought out a proper name currently. Please share your suggestion if you have good ideas of the name.
  3. I would like to keep getModuleExtractInfosFromReader in ExtractInfoProcessor public, for we need this middleware method to create fake infos in ModuleInfoCollectorTest and ModuleUtilsTest.

@rnveach
Copy link
Member

rnveach commented Jul 6, 2017

  1. Where to put step 1?
    there would be no JGit dependency outside git.

truthfully I was thinking we would run a command line git execution instead of using JGit.
I like the idea of using JGit to make it truly system independent and not relying on something being installed.
If we are doing this for JGit, it is possible to do this for Maven too. See maven-embedder.

So should we create a util class in git and use it in extract?

I didn't want to allow jgit everywhere as then someone will import it in the wrong place and think it is acceptable when it isn't. Import control is to restrict bad designs, not to limit our design possibilities.
I don't think one component should be calling another, which is what a utility class in git will look like.
We can either allow jgit inside extract component (I think I prefer this right now), or make a util package and name class something like GitUtil.

  1. CheckstyleInjector

Edit: I didn't look at source changes first.
Name sounds fine to me for now.

  1. I would like to keep getModuleExtractInfosFromReader in ExtractInfoProcessor public, for we need this middleware method to create fake infos in ModuleInfoCollectorTest and ModuleUtilsTest.

No. If something is needed for testing, we should use reflection and break class that way than leave internal structure open for someone to mis-use. Production code should not be defined by tests except for maybe splitting things into smaller pieces.
In my work, if I need a method like this, I use reflection and store it as a class field for use everywhere in test.

@Luolc
Copy link
Contributor Author

Luolc commented Jul 6, 2017

No. If something is needed for testing, we should use reflection and break class that way than leave internal structure open for someone to mis-use.

OK.

We can either allow jgit inside extract component (I think I prefer this right now)

I agree with this.

it is possible to do this for Maven too. See maven-embedder

Ya, I was thinking to use it. Already been investigating on it.

@Luolc Luolc mentioned this pull request Jul 6, 2017
7 tasks
@Luolc
Copy link
Contributor Author

Luolc commented Jul 10, 2017

@rnveach Updated.
missing implementation of invokeMavenCommand currently.

I don't use static method in CheckstyleInjector this time, for every method in it needs repoPath and branch, and we need close repository, I think an instance is better.

Maybe we need to combine the another part of this issue then we could make test for all this updates.

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.

Are we going to finish this PR?

checkoutToPrBranch();
copyInjectFilesToCheckstyleRepo();
invokeMavenCommand();
return null;
Copy link
Member

Choose a reason for hiding this comment

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

Needs a result.

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.

* Invokes Maven command to generate the extract info file in checkstyle repository.
*/
private static void invokeMavenCommand() {
// invoke maven command to generate the extract info file
Copy link
Member

Choose a reason for hiding this comment

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

needs to do something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated. But have some problems. See my comments below.

pom.xml Outdated
<regex>
<pattern>com.github.checkstyle.regression.extract.CheckstyleInjector</pattern>
<branchRate>0</branchRate>
<lineRate>0</lineRate>
Copy link
Member

Choose a reason for hiding this comment

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

Please create issue to create some tests and coverage for this class at a later time.

@Luolc
Copy link
Contributor Author

Luolc commented Jul 11, 2017

@rnveach I encountered some strange problems:

  1. cobertura failed. I add/update the regex pattern according to the html report, but it still failed.
  2. If I uncomment the UT added in ExtractInfoProcessorTest: https://github.com/Luolc/regression-tool/blob/689f22c5d44223c268fe23227b8311bdae039e26/src/test/java/com/github/checkstyle/regression/extract/ExtractInfoProcessorTest.java#L105, mvn clean test is fine but mvn clean compile cobertura:cobertura would run with a lot of test error.
    If comment/remove this UT, then there would be no error with compile cobertura. I guess it is caused by System.setProperty(PROPERTY_KEY_DIRECTORY, repoPath);, and this is because the problem described in https://stackoverflow.com/questions/33400574/unable-to-run-maven-tasks-through-mavencli-maven-embedder. Can't fix this after a long time of investigation. :(

@rnveach
Copy link
Member

rnveach commented Jul 11, 2017

cobertura failed

remove quiet from POM for cobertura and you get this error:

[ERROR] com.github.checkstyle.regression.extract.CheckstyleInjector$1 failed coverage check. Line coverage rate of 0.0% is below 100.0%

Cobertura sees main class and inner classes differently.
There was a reason this is enabled in CS, feel free to make another PR to remove it if you wish.

Change line to something like: <pattern>com.github.checkstyle.regression.extract.CheckstyleInjector.*</pattern>

@rnveach
Copy link
Member

rnveach commented Jul 11, 2017

If I uncomment the UT added in ExtractInfoProcessorTest

This is why I have said repeatedly, lets not worry about code coverage on cloning, maven, etc...
Isolate it as best as you can and mock its true run away. We will eventually use travis to make sure it functions properly in a full run.
I don't want junits doing actual cloning or running maven/git commands except on our own sources or repositories we can quickly create.

guess it is caused by System.setProperty(PROPERTY_KEY_DIRECTORY, repoPath);

Why not set this as arguments to doMain as specified in https://stackoverflow.com/questions/33400574/unable-to-run-maven-tasks-through-mavencli-maven-embedder
Ex: int result = cli.doMain(new String[] { "-Dmaven.multiModuleProjectDirectory=" + projectRoot, "install" }, "/path/to/project", System.out, System.err);

@Luolc
Copy link
Contributor Author

Luolc commented Jul 12, 2017

We will eventually use travis to make sure it functions properly in a full run.

I add this in UT just for quick test and debug, I would remove it when I confirm the code function is acceptable.

Why not set this as arguments to doMain as specified in

I tried this but it doesn't work. Still has error -Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variable and mvn script match.

@Luolc
Copy link
Contributor Author

Luolc commented Jul 12, 2017

Change line to something like: com.github.checkstyle.regression.extract.CheckstyleInjector.*

It works. Thanks. :)

}
}

//@Test
Copy link
Member

Choose a reason for hiding this comment

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

Do not leave commented code in.

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.

returnValue = getModuleExtractInfosFromReader(reader);
}
catch (IOException ex) {
throw new InjectException("unable to read to info file", ex);
Copy link
Member

Choose a reason for hiding this comment

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

This message is not very informative of issue.
Expand on what we were trying to do. Since it is the extract file, it should be in message somewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.


try {
try {
final File file = injector.generateExtractInfoFile();
Copy link
Member

Choose a reason for hiding this comment

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

if generateExtractInfoFile doesn't throw an IOException it should be outside the 2nd level try.

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.

<regex>
<pattern>com.github.checkstyle.regression.extract.InjectException</pattern>
<branchRate>0</branchRate>
<lineRate>0</lineRate>
Copy link
Member

Choose a reason for hiding this comment

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

Needs issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#54

<regex>
<pattern>com.github.checkstyle.regression.extract.CheckstyleInjector.*</pattern>
<branchRate>0</branchRate>
<lineRate>0</lineRate>
Copy link
Member

Choose a reason for hiding this comment

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

Needs issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#54

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.

I am not seeing anything.

@rnveach rnveach merged commit f1f6c45 into checkstyle:master Jul 19, 2017
@Luolc Luolc deleted the issue37-1 branch July 19, 2017 09:43
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