-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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 #6232: Load resources relative to resources root #6600
Conversation
@peterdemaeyer spellchecker in travis is failed and pitest is failing in circle ci. |
1779abe
to
6de5e93
Compare
@peterdemaeyer pitest is still failing. |
6de5e93
to
94e787b
Compare
The build timed out while downloading dependencies. Can someone please rebuild to see if it's maybe a transient issue? Apparently I don't have permission to trigger a rebuild myself. |
I restarted the CI. |
Thanks, all green now. |
src/test/java/com/puppycrawl/tools/checkstyle/utils/CommonUtilTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/utils/CommonUtilTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/utils/CommonUtilTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/utils/CommonUtilTest.java
Outdated
Show resolved
Hide resolved
@peterdemaeyer , thanks a lot for your updates. |
94e787b
to
734967c
Compare
Fixed the review comments, but now the wercker/build fails with an unclear "401". |
@rnveach , please continue/finish review. |
@peterdemaeyer failure is because your branch is based on an outdated master. Please rebase. |
@@ -0,0 +1 @@ | |||
good |
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.
Why does this file need to be in its own folder and not part of checkstyle's standard packaging?
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.
Because it most elegantly illustrates the initial issue I encountered and have now fixed - which is to reach for a file outside of the package you're currently in.
I could move everything inside the "standard packaging", but at the expense of adding an excessively deep directory tree.
The "good" file would be then in src/test/resources/com/puppycrawl/tools/checkstyle/utils/commonutil
, the "bad" file would be in src/test/resources/com/puppycrawl/tools/checkstyle/utils/commonutil/com/puppycrawl/tools/checkstyle/utils/commonutil
, which would be a lot less comprehensive and a less good representation of what I'm trying to illustrate.
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.
@romani What do you think of 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.
I could move everything inside the "standard packaging", but at the expense of adding an excessively deep directory tree.
please deep path. Nobody will look at it, till deal with certain test.
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.
This is not so easy to fix after all. A good test must first fail without the fix (illustrating the issue) and succeed with the fix. The easy part is to make the test succeed with the fix. The hard part is to make it fail without the fix. That's why I have the two files by the way, the "good" file and the "bad" file. Whatever I try, there is always a combination where one of these files causes the AllTestsTest
to fail. That is the reason it's taking me so long to fix 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.
I tried, but I couldn't move the resources while still keeping AllTestsTest
happy, and I certainly don't want to reduce the value of my test, so I left it the way it was because it's the only way I could preserve the value of the test while still satisfying AllTestsTest
.
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.
@peterdemaeyer what failure were you getting in AllTestsTest
and what path were you setting it to?
The only reason AllTestsTest
isn't flagging this now is because it is specifically looking in com/puppycrawl
sub-folder which your file is not in.
You can add suppression to test and we can review later.
checkstyle/src/test/java/com/puppycrawl/tools/checkstyle/internal/AllTestsTest.java
Line 153 in a73ff08
if (!path.contains(File.separatorChar + "grammar" + File.separatorChar) |
checkstyle/src/test/java/com/puppycrawl/tools/checkstyle/internal/AllTestsTest.java
Line 255 in a73ff08
private static boolean shouldSkipInputFileNameCheck(String path, String fileName) { |
src/test/java/com/puppycrawl/tools/checkstyle/utils/CommonUtilTest.java
Outdated
Show resolved
Hide resolved
eacd920
to
ff27f0d
Compare
The build fails because of what I believe to be an issue with the build system: it seems that openjdk 9/10/11/12 just fails to install on it. |
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.
Sorry, 1 final change.
...ources/com/puppycrawl/tools/checkstyle/utils/commonutil/InputCommonUtilTest_empty_checks.xml
Outdated
Show resolved
Hide resolved
@peterdemaeyer , ping. |
Yeah, sorry, I left this aside a bit after I ran into some trouble moving the resources around in an attempt to satisfy one of your remarks. I'll try picking it up again this weekend. |
If problem is heavy .... please share it, we can reconsider decisions. |
a73a6e8
to
d78e355
Compare
The remaining "problem" is the one about the test resources: the location of "good" and "bad" versions of Additionally, I now run into a build issue I didn't have before, I still need to investigate that. |
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.
item to improve:
} | ||
|
||
@Override | ||
protected String getPackageLocation() { |
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.
please move this method to the top of class, right after fields.
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.
It better to reply "done" when you finished review item.
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.
OK - I'll do that.
I expected the button "Resolve conversation" to do more or less the same, but apparently not (not sure what it actually does then).
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.
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 expected the button "Resolve conversation" to do more or less the same, but apparently not
We don't get notifications on clicking resolve and pushing commits, so it could go unnotice that you made changes. Also we ask that we be the ones to click resolve conversation so we can use it as a way to double verify the work.
Please share error message. |
9088073
to
8bc51a0
Compare
I finally managed to move the resource, and the |
The build is stuck waiting for a build slave. |
Jenkins can be ignored. |
Why the double package in the folder path? |
@peterdemaeyer , |
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.
items to improve:
@Test | ||
public void testGetUriByFilenameFindsResourceRelativeToRootClasspath() throws Exception { | ||
final String filename = | ||
"com/puppycrawl/tools/checkstyle/utils/commonutil/InputCommonUtilTest_resource.txt"; |
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.
getPackageLocation() + "/InputCommonUtilTest_resource.txt"
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.
Consider it done (commit pending).
final String uriRelativeToPackage = | ||
"com/puppycrawl/tools/checkstyle/utils/" | ||
+ "com/puppycrawl/tools/checkstyle/utils/" | ||
+ "commonutil/InputCommonUtilTest_resource.txt"; |
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.
getPackageLocation() + "/InputCommonUtilTest_resource.txt"
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.
Consider it done (commit pending).
+ "com/puppycrawl/tools/checkstyle/utils/" | ||
+ "commonutil/InputCommonUtilTest_resource.txt"; | ||
assertThat("URI is relative to package " + uriRelativeToPackage, | ||
uri.toString(), not(containsString(uriRelativeToPackage))); |
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.
please explain this assert , filename
and uriRelativeToPackage
are both relative . uriRelativeToPackage
is bigger than filename
so it will always have no assert. Do I miss something ?
We probably need some comments over code, as it is not obvious, or improve names of variables.
I think we need some summary from #6600 (comment)
with wording something like:
this test case is for "Issue #6232" without fix
if user define
"com/puppycrawl/tools/checkstyle/utils/commonutil/InputCommonUtilTest_resource.txt"
it is was converted to
"com/puppycrawl/tools/checkstyle/utils"
+ "/"
+ "com/puppycrawl/tools/checkstyle/utils/commonutil/InputCommonUtilTest_resource.txt"
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.
OK, I'll explain everything in a Javadoc comment on the test method.
The assertion asserts that the URL does not contain the excessively deep path "com/puppycrawl/tools/checkstyle/utils/com/puppycrawl/tools/checkstyle/utils/commonutil".
It does fail without the fix.
With the fix, the location is not excessively deep, and the assertion succeeds.
Note that replacing the relevant portions of the strings with getPackageLocation()
may make the test even less obvious, but I'll do it anyway.
Consider it done (commit pending).
IOUtils.copy(in, out); | ||
} | ||
assertThat("Content mismatches for: " + uri, | ||
new String(out.toByteArray(), StandardCharsets.UTF_8), startsWith("good")); |
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.
String fileContent = new String(out.toByteArray(), StandardCharsets.UTF_8)
the simpler assertThat the better.
can we use https://github.com/apache/commons-io/blob/master/src/main/java/org/apache/commons/io/IOUtils.java#L2680 ? to skip all details on how actually content of file is loaded to String.
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.
Good idea. Consider it done (commit pending).
Because I want to illustrate that the "good" file is not in an excessively deep directory. It's only the "bad" file which is in the excessively deep directory. I'll explain everything in a Javadoc comment on the test. |
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.
Ok to merge, thanks a lot for your efforts to finish implementation
Issue #6232
"mvn clean verify" succeeded.