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 #4714: Make SuppressionCommentFilter and SuppressWithNearbyCommentFilter children of TreeWalker #4755

Merged
merged 2 commits into from Jul 24, 2017

Conversation

timurt
Copy link
Contributor

@timurt timurt commented Jul 18, 2017

@codecov-io
Copy link

codecov-io commented Jul 18, 2017

Codecov Report

Merging #4755 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #4755   +/-   ##
======================================
  Coverage     100%    100%           
======================================
  Files         287     288    +1     
  Lines       15396   15432   +36     
  Branches     3499    3504    +5     
======================================
+ Hits        15396   15432   +36
Impacted Files Coverage Δ
...s/checkstyle/filters/SuppressionCommentFilter.java 100% <100%> (ø) ⬆️
...pycrawl/tools/checkstyle/TreeWalkerAuditEvent.java 100% <100%> (ø)
...va/com/puppycrawl/tools/checkstyle/TreeWalker.java 100% <100%> (ø) ⬆️
...style/filters/SuppressWithNearbyCommentFilter.java 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4c10bc5...d365551. Read the comment docs.

@rnveach
Copy link
Member

rnveach commented Jul 18, 2017

@MEZk @timurt @romani

From wercker.

project postgresql: Failed during checkstyle configuration: SuppressionCommentFilter is not allowed as a child in Checker -> [Help 1]

Doing this in one change is going to be hard, and probably impossible thanks to wercker and all the regression we do. This change can't be made to other projects until we release this newest code.

@MEZk I recommend we split this PR into 2.
1st PR: The introduction of AstFilter and TreeWalkerAuditEvent.
2nd PR: The rewrite of SuppressionCommentFilter and SuppressWithNearbyCommentFilter to use the new filtering and events.
The delay of the second PR will atleast allow us to validate the rest of the changes in wercker.
This sound good?

@romani To keep this class backwards compatible should we have them implement Filter too, or just duplicate the entire class with different Filters? Duplication might not be possibly because of other breaking changing that this change probably wants.

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.

ModuleReflectionUtils needs to be updated to recognize the new filters.

@MEZk
Copy link
Contributor

MEZk commented Jul 18, 2017

@rnveach

This change can't be made to other projects until we release this newest code.

Yes, this PR will completely break compatibility with previous versions. @romani This is what we intend to do.

To keep this class backwards compatible should we have them implement Filter too

No, we decided to break compatibility.

Doing this in one change is going to be hard, and probably impossible thanks to wercker and all the regression we do.

Yes, but we should do this. @romani As far as I remember we decided not to split this PR.

The delay of the second PR will atleast allow us to validate the rest of the changes in wercker.
This sound good?

Why do we need to introduce just interface and a wrapper (TreeWalkerAuditEvent) ? What for? They do not contain logic.

@rnveach
Copy link
Member

rnveach commented Jul 18, 2017

Why do we need to introduce just interface and a wrapper

I meant all logic too except for backward breaking stuff.

we decided to break compatibility.

I will make a suggestion in gitter on this. If we are breaking, we might as well disable all of wercker.

@romani
Copy link
Member

romani commented Jul 18, 2017

We could make transition without braking compatibility:

  • introduce new interfaces, classes
  • copy existing filters to new filters. So there will be 4 filters , 2 for Checker and 2 for TreeWalker
  • release filters for TreeWalker
  • migrate project that we use in CI
  • update our CI to use latest commit for projects
  • remove old filters.
  • introduce braking compatibility for all community.

Disadvantage: but we will end up with new Filter names and there still CI related changes but smooth.


Braking compatibility:

  • we keep names and brake compatibility on a commit, CI will react on it.
  • we can disable wercker for 1-2 weeks OR we can make forks+fix for all project in Wercker OR we do file substitution by wget in clones sources for they checkstyle config (this could be done in the same PR so CI will always be green).
  • CI come back to green if required
  • after release, help to upgrade project from CI to new chekstyle and new config.
  • after upgrade is done, switch to most recent commit and remove hack(fork/wget) from CI

Good: names are the same,CI is always green.
Bad: we will rely on some personal gist/hosting to keep updated files.

I do prefer to follow "Braking compatibility" as it will speedup acceptance of fixes and will keep names and will be the same efforts on CI update.

@romani
Copy link
Member

romani commented Jul 18, 2017

@timurt , while we try to persuade @rnveach , please prepare separate commit in this PR to substitute all configs in affected projects with file from your gist.
You can use "patch approach", keep in gist only patch(not whole file content) if you are good with patch shell tool.
All wercker commands you can run on your local, they are just shell commands.

@rnveach
Copy link
Member

rnveach commented Jul 18, 2017

while we try to persuade @rnveach

@romani If you are referring to breaking compatibility I am fine with that. I assumed we would want to try to avoid breaking compatibility like we have in other PRs.
If you are referring to any other chats in gitter, I have made my case and you can proceed with how you wish to keep wercker working.

@MEZk
Copy link
Contributor

MEZk commented Jul 19, 2017

@timurt
Please, rebase your branch and make changes suggested by @romani to fix wercker build.

@rnveach
Copy link
Member

rnveach commented Jul 20, 2017

@romani

with file from your gist.

Why aren't we doing it from a location all of us can access? If we restrict access to one person, it will cause a conflict if they happen to go away when an emergency fix is needed.

@MEZk
Copy link
Contributor

MEZk commented Jul 20, 2017

@timurt
Ping

@romani
Copy link
Member

romani commented Jul 20, 2017

Why aren't we doing it from a location all of us can access?

just try to economize time, as release is planned to this weekend, so that location is very temporal.
We could have shared gist at https://gist.github.com/checkstyle
@timurt , can fork our contribution repo and make PR it with patch files, we will not merge this PR, it will allow him to use that files for wget.

@MEZk
Copy link
Contributor

MEZk commented Jul 20, 2017

@timurt
Do you still have problems with Wercker CI? Do you understand what you should do after my private message?

@timurt
Copy link
Contributor Author

timurt commented Jul 21, 2017

@MEZk @romani @rnveach
I changed checkstyle_sevntu_checks.xml

I made separate commit for wecker.yml containing gist patches
I've tested locally using bash commands, it worked fine
Can you check, is it ok?

@rnveach
Copy link
Member

rnveach commented Jul 21, 2017

in wercker: Postgresql JDBC Driver failed with run.sh: line 9: patch: command not found.

@@ -155,6 +141,20 @@
value="The warning ''{0}'' cannot be suppressed at this location. Only few javac warnings are allowed to suppress. If try to suppress checkstyle/pmd/..... violation please do this in their config file. If you try to suppress IntelliJ IDEA inspection, please use javadoc block tag @noinspection"
/>
</module>
<module name="SuppressionCommentFilter">
Copy link
Member

Choose a reason for hiding this comment

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

These are filters not annotations as the header on line 122 suggest.
Make a new header for filters inside TreeWalker and move these lines right under it.

Copy link
Member

Choose a reason for hiding this comment

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

Please also make sure all headers are in alphabetical order.

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

final DetailAST rootAST = parse(contents);

if (!ordinaryChecks.isEmpty()) {
walk(rootAST, contents, AstState.ORDINARY);
}
if (!commentChecks.isEmpty()) {
final DetailAST astWithComments = appendHiddenCommentNodes(rootAST);

Copy link
Member

Choose a reason for hiding this comment

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

restore empty line.

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

@timurt
Copy link
Contributor Author

timurt commented Jul 21, 2017

@rnveach
run.sh: line 9: patch: command not found - how patches should be applied without patch command? Or should I insert apt install inside wecker.yml?

@rnveach
Copy link
Member

rnveach commented Jul 21, 2017

how patches should be applied without patch command?

We should have access to the git command since it is pulling in our work from it.
My original plan was to use git to apply the patch.

@romani
Copy link
Member

romani commented Jul 21, 2017

@timurt ,
please use git to apply - https://www.devroom.io/2009/10/26/how-to-create-and-apply-a-patch-with-git/
if any problem again .... please use whole file override.
We have few days only before release day (this Sunday), we need to merge you as soon as possible.

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

item to improve:

wercker.yml Outdated
@@ -46,7 +46,10 @@ build:
CS_POM_VERSION=$(mvn -q -Dexec.executable='echo' -Dexec.args='${project.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec)
echo CS_version: ${CS_POM_VERSION}
for i in 1 2 3 4 5; do git clone https://github.com/pgjdbc/pgjdbc.git && break || sleep 15; done
cd pgjdbc/pgjdbc
cd pgjdbc/pgjdbc/src/main/checkstyle
Copy link
Member

Choose a reason for hiding this comment

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

please avoid change of this line cd ...., HACK lines(wget+patch) should not affect other lines to be easily removed.

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

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

more items to change

*
* @author Timur Tibeyev.
*/
public interface AstFilter {
Copy link
Member

Choose a reason for hiding this comment

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

@timurt , @MEZk
I do not remember that I allowed new classes in API.
We discussed to keep then out of API till we finish implementation, to make sure that tested that contract and we could keep it.
One more point is names of interfaces: AstFilter vs TreeWalkerAuditEvent .
it is better to name filter as TreeWalkerFilter.

Copy link
Contributor

Choose a reason for hiding this comment

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

@romani

  1. AstFilter should be outside API package.
  2. If somebody implements the check which is able to work with AST like TreeWalker, the filter will be available to use in that check. Why should we name it TreeWalker* ?

Copy link
Member

Choose a reason for hiding this comment

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

both names should consistent as they can not be used without each other.
both interfaces should be out of API
two ways:

AstFilter
AstAuditEvent

or

TreeWalkerFilter
TreeWalkerAuditEvent

@timurt , @soon , @Vladlis , @rnveach , please share your vote.

Copy link
Member

@rnveach rnveach Jul 21, 2017

Choose a reason for hiding this comment

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

If I have to choose between the 2, I currently like TreeWalker* better since it is connected with that module and Java compiling.
I dislike Ast slightly as Javadoc is a form of AST even though we call it Node. If Java upgrades to ANTLR4, will we rename these classes accordingly too and break previous compatibility? And how will we name them differently so not to confuse with Javadoc as both will be nodes?

Copy link
Member

Choose a reason for hiding this comment

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

agree with rnveach.
additional point is that TreeWalkerAuditEvent will contain not only Ast , but some other context from TreeWalker.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AstFilter
AstAuditEvent

Maybe we should call them

CheckerFilter
CheckerAuditEvent

because they are children of module Checker, similarly to TreeWalkerFilter

Copy link
Member

Choose a reason for hiding this comment

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

because they are children of module Checker, similarly to TreeWalkerFilter

it is already too late, with such a change you will brake whole word of Checkstyle.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would also vote for TreeWalkerAuditEvent since it is produced by TreeWalker and, therefore, for TreeWalkerFilter

Copy link
Contributor

Choose a reason for hiding this comment

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

I dislike Ast slightly as Javadoc is a form of AST even though we call it Node. If Java upgrades to ANTLR4, will we rename these classes accordingly too and break previous compatibility? And how will we name them differently so not to confuse with Javadoc as both will be nodes?

Ok, lets name them as TreeWalkerFilter and TreeWalkerAuditEvent.

@timurt
Please, do.

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

@timurt timurt force-pushed the 4714 branch 2 times, most recently from 9082055 to 6ff7c2c Compare July 21, 2017 17:29
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 removed FileContentsHolder from filters but documentation in xdoc still makes reference to FileContentsHolder.

See http://checkstyle.sourceforge.net/config_filters.html#SuppressWithNearbyCommentFilter and http://checkstyle.sourceforge.net/config_filters.html#SuppressionCommentFilter in Description and Examples.

XDoc needs to be updated for all affected filters.

mvn -s settings-example.xml clean install -DskipTests=true -Dtest.elasticsearch.host.provided=true
wget https://gist.githubusercontent.com/timurt/f8e6c08b681337dfee76fdf8cc4ebb37/raw/c95333027111d055de8c943d3bc0b757ad638605/hibernate.patch
git apply hibernate.patch
mvn -s settings-example.xml clean install -DskipTests=true -Dtest.elasticsearch.host.provided=true -Dpuppycrawl.checkstyle.version=${CS_POM_VERSION}
Copy link
Member

Choose a reason for hiding this comment

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

@romani Looks like we had a bug with hibernate

Copy link
Member

Choose a reason for hiding this comment

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

@rnveach , what do you mean by this ?

@Override
public void setupChild(Configuration childConf)
throws CheckstyleException {
final String name = childConf.getName();
final Object module = moduleFactory.createModule(name);
if (!(module instanceof AbstractCheck)) {
if (module instanceof AbstractCheck) {
final AutomaticBean bean = (AutomaticBean) module;
Copy link
Contributor

Choose a reason for hiding this comment

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

@timurt
Why do we need to treat AbstractCheck as AutomaticBean directly? Please, restore original actions:

        final AbstractCheck check = (AbstractCheck) module;
        check.contextualize(childContext);
        check.configure(childConf);
        check.init();

        registerCheck(check);

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, but again this TC violation

175: setupChild() Cast (AutomaticBean) module conflicts with surrounding 'instanceof' check

Should I suppress 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.

resolved, TeamCity passed

"TreeWalker is not allowed as a parent of " + name
+ " Please review 'Parent Module' section for this Check in web"
+ " documentation if Check is standard.");
"TreeWalker is not allowed as a parent of " + name
Copy link
Contributor

Choose a reason for hiding this comment

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

@timurt
Do not ignore this point

@@ -169,10 +188,11 @@ protected void processFiltered(File file, FileText fileText) throws CheckstyleEx
if (CommonUtils.matchesFileExtension(file, getFileExtensions())) {
final String msg = "%s occurred during the analysis of file %s.";
final String fileName = file.getPath();
final FileContents contents = new FileContents(fileText);

try {
if (!ordinaryChecks.isEmpty()
Copy link
Contributor

Choose a reason for hiding this comment

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

@timurt
So, FileContext holder position should be restored. It should be closer to its first usage.

}

final String[] expected = {
"2:16: Name 'I' must match pattern '^[a-z][a-zA-Z0-9]*$'.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Use getCheckMessage, do not hardcode violation message in the test.

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

@MEZk
Copy link
Contributor

MEZk commented Jul 22, 2017

@timurt
CIs should be fixed. Please, use mvn clean verify before sending your changes.

@timurt timurt force-pushed the 4714 branch 2 times, most recently from 9735983 to ea45b23 Compare July 22, 2017 21:50
*
* @author Timur Tibeyev.
*/
@FunctionalInterface
Copy link
Contributor

Choose a reason for hiding this comment

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

You declare functional interface. but do not use lambdas. Please, remove. It is not necessary. Future contributor will not understand your intention.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MEZk
Done
Added noinspection javadoc because TeamCity was failing with violation:

27: TreeWalkerFilter Interface TreeWalkerFilter may be annotated with @FunctionalInterface

Copy link
Contributor

Choose a reason for hiding this comment

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

@rnveach
Please explain why do we need the annotation ?

Copy link
Member

Choose a reason for hiding this comment

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

annotation is allowed here: #3435 (comment)

@timurt timurt force-pushed the 4714 branch 4 times, most recently from a469677 to 4fad17a Compare July 23, 2017 07:28
* An interface for filtering {@code TreeWalkerAuditEvent}.
*
* @author Timur Tibeyev.
* @noinspection InterfaceMayBeAnnotatedFunctional
Copy link
Member

Choose a reason for hiding this comment

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

Taken from #4755 (comment) ,
remove suppression and add annotation.

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Please explain why do we need the annotation ?

Copy link
Member

Choose a reason for hiding this comment

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

@MEZk See issue #3435 .
We added annotation to all interfaces and did no suppressions.

@@ -144,23 +155,35 @@ public void finishLocalSetup() {
childContext = checkContext;
}

/**
* {@inheritDoc} Creates child module.
* @noinspection ChainOfInstanceofChecks
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this suppression here when Checker, which has similar code doesn't need it?
https://github.com/rnveach/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/Checker.java#L436

Copy link
Contributor Author

@timurt timurt Jul 23, 2017

Choose a reason for hiding this comment

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

@rnveach
Your example from your forked repo, inside main repo this suppression exists
https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/Checker.java#L442

Otherwise TeamCity fails

Copy link
Member

@rnveach rnveach Jul 23, 2017

Choose a reason for hiding this comment

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

Sorry, I used the wrong link to my own fork.
You are correct and can ignore this.

@Override
public void setupChild(Configuration childConf)
throws CheckstyleException {
final String name = childConf.getName();
final Object module = moduleFactory.createModule(name);
if (!(module instanceof AbstractCheck)) {
if (module instanceof AutomaticBean) {
Copy link
Member

@rnveach rnveach Jul 23, 2017

Choose a reason for hiding this comment

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

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
I think moduleFactory.createModule(name); is where exception probably could happen, but i was not surrounded by try/catch before. Should I do it now?

Copy link
Member

Choose a reason for hiding this comment

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

It was a question to more to the others. It may be helpful to let the user know their module cant initialize versus some other exception that can happen around there.
@MEZk @romani

Copy link
Member

@romani romani Jul 23, 2017

Choose a reason for hiding this comment

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

createModule already put in exception all required context for user - https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/PackageObjectFactory.java#L183

but other methods contextualize and configure will not provide context of which module was in reflection initialization process.
@timurt , please add try-catch.

UPDATE: moved to #4814

Copy link
Contributor Author

@timurt timurt Jul 23, 2017

Choose a reason for hiding this comment

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

@romani @rnveach @MEZk
As I understood, TreeWalker is the child of the Checker. So if any exception occurs inside TreeWalker.setupChild it will be caught inside Checker.setupChild, right?
Is this try-catch necessary?
It will require some tests to be changed, because new thrown exception differs from old one.

Previous exception message

cannot initialize module com.puppycrawl.tools.checkstyle.TreeWalker - Cannot set property 'excludedPackages' to 'com.puppycrawl.tools.checkstyle.checks.metrics.inputs.a.' in module com.puppycrawl.tools.checkstyle.checks.metrics.ClassFanOutComplexityCheck

Exception with try/catch inside TreeWalker.setupChild

cannot initialize module com.puppycrawl.tools.checkstyle.checks.metrics.ClassFanOutComplexityCheck - Cannot set property 'excludedPackages' to 'com.puppycrawl.tools.checkstyle.checks.metrics.inputs.a.' in module com.puppycrawl.tools.checkstyle.checks.metrics.ClassFanOutComplexityCheck

Other moment, if for example TreeWalker.setupChild catches exception and throws CheckstyleException. This thrown exception will be caught by Checker.setupChild and message becomes little bit weird:

cannot initialize module com.puppycrawl.tools.checkstyle.TreeWalker - cannot initialize module com.puppycrawl.tools.checkstyle.checks.blocks.EmptyBlockCheck - Cannot set property 'option' to 'invalid_option' in module com.puppycrawl.tools.checkstyle.checks.blocks.EmptyBlockCheck

original message

cannot initialize module com.puppycrawl.tools.checkstyle.TreeWalker - Cannot set property 'option' to 'invalid_option' in module com.puppycrawl.tools.checkstyle.checks.blocks.EmptyBlockCheck

Copy link
Member

Choose a reason for hiding this comment

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

lets move this nuance to #4814 .
It could be done later.

@rnveach , @MEZk , please approve PR.

@@ -59,6 +63,7 @@
*
* @author Oliver Burn
*/
// -@cs[ClassFanOutComplexity] Number of classes current class relies on exceeds 25.
Copy link
Member

Choose a reason for hiding this comment

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

Suppression comment should be on why you can't comply with check, not what violation was.
Example: https://github.com/checkstyle/checkstyle/blob/master/config/suppressions.xml#L74-L75

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

Copy link
Contributor

Choose a reason for hiding this comment

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

@rnveach
Please explain why do we need the annotation ?

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

@rnveach , @MEZk if you are agree with changes please do not forget to click "Approve changes" in review. I will do merge as soon as all of us approve changes.

one point from me (moved to #4814 ):

@Override
public void setupChild(Configuration childConf)
throws CheckstyleException {
final String name = childConf.getName();
final Object module = moduleFactory.createModule(name);
if (!(module instanceof AbstractCheck)) {
if (module instanceof AutomaticBean) {
Copy link
Member

@romani romani Jul 23, 2017

Choose a reason for hiding this comment

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

createModule already put in exception all required context for user - https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/PackageObjectFactory.java#L183

but other methods contextualize and configure will not provide context of which module was in reflection initialization process.
@timurt , please add try-catch.

UPDATE: moved to #4814

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 don't see anything else.

final File file = temporaryFolder.newFile("file.java");
try (Writer writer = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8))) {
final String content = "public class Main {\n"
Copy link
Member

@rnveach rnveach Jul 24, 2017

Choose a reason for hiding this comment

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

Why isn't this in an input file? Why do we have to create it at runtime?

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 thought source is too small to be stored inside separate file

Copy link
Member

@rnveach rnveach Jul 24, 2017

Choose a reason for hiding this comment

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

Size doesn't matter for inputs. Please move this to input file.
Code and inputs should be separated. Inputs are in files so they can be verified that they compile fine. We don't deal with non-compilable files.

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 24, 2017

@romani Looks like we had a bug with hibernate

@rnveach , what do you mean by this ?

Look at change in command.
Previous ended with -Dtest.elasticsearch.host.provided=true.
New command ends with -Dtest.elasticsearch.host.provided=true -Dpuppycrawl.checkstyle.version=${CS_POM_VERSION}.
It looks like it was missing the forcing of the snapshot checkstyle version, so we were probably never really testing regression.
Right?

Edit: I see we have snapshot in the next command, which actually runs regression. The line commented on was building their custom modules, I assume? so we were missing regression with that.

@timurt
Copy link
Contributor Author

timurt commented Jul 24, 2017

@rnveach

It looks like it was missing the forcing of the snapshot checkstyle version, so we were probably never really testing regression.

I think no, inside NoErrorTest - Hibernate Search we have two maven commands. I am not sure what they do

mvn -s settings-example.xml clean install -DskipTests=true -Dtest.elasticsearch.host.provided=true

Probably runs hibernate-search/build-config/src/main/resources/checkstyle.xml for build-config directory and copies this checkstyle.xml to subprojects.

mvn -s settings-example.xml checkstyle:check -Dpuppycrawl.checkstyle.version=${CS_POM_VERSION}

Probably runs checkstyle for all subprojects. So it would definitely fail, if compatibility error occurred.

I added -Dpuppycrawl.checkstyle.version=${CS_POM_VERSION} to the first command, because otherwise it was failing with error like:

SuppressionCommentFilter cannot be child of the TreeWalker

@timurt
Copy link
Contributor Author

timurt commented Jul 24, 2017

@rnveach @romani
Also Hibernate Search have two source file which are not compatible with last versions of checkstyle. Inside DoubleSpacesCheckTest.java and StringSuppressorTest source files FileText.fromLines is used, which was replaced by constructor FileText(File file, List<String> lines).
I had this error on my local machine and I wonder why wercker/build was not failing before this PR

@MEZk
Copy link
Contributor

MEZk commented Jul 24, 2017

@romani
Are we ready to merge?

@romani romani merged commit 1695cab into checkstyle:master Jul 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

6 participants