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 #15 WarFile.java:134-135: Implement validation of YAML inside. #28

Merged
merged 15 commits into from Oct 5, 2015
Merged

Issue #15 WarFile.java:134-135: Implement validation of YAML inside. #28

merged 15 commits into from Oct 5, 2015

Conversation

tmjee
Copy link

@tmjee tmjee commented Sep 25, 2015

Issue #15

  • Use snakeyaml to validate yaml
  • validationdone in AbstractBeanstalkMojo
  • added test cases

@dmarkov
Copy link

dmarkov commented Sep 28, 2015

@tmjee Thanks for your pull request, let me find someone who can review it

@dmarkov
Copy link

dmarkov commented Sep 28, 2015

@dmzaytsev please review, thanks

try {
new Yaml().load(text);
} catch (final YAMLException exception) {
valid = false;

Choose a reason for hiding this comment

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

@tmjee does YAMLException provide extended information about issues in the yaml file?
if so it would better inform the user about details instead just say the file is valid or not.
what do you think?

Copy link
Author

Choose a reason for hiding this comment

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

@dmzaytsev throw YAMLException up so message can be sticked into MojoExecution exception

@dmzaytsev
Copy link

@tmjee AbstractBeanstalkMojo.execute() not tested, let's test it

@dmzaytsev
Copy link

@tmjee please see 7 comments above

@tmjee
Copy link
Author

tmjee commented Sep 29, 2015

@dmzaytsev Test for AbstractBeanstalkMojo.execute() added.

@Test(expected = YAMLException.class)
public void testInvalidYaml() throws Exception {
// @checkstyle StringLiteralsConcatenationCheck (6 lines)
final String invalid = "Some illegal Prefix\n"

Choose a reason for hiding this comment

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

@tmjee String.format() or StringBuilder can be used here instead checkstyle suppression.

@dmzaytsev
Copy link

@tmjee thank you
just 5 minor comments above

try {
this.validYaml(text);
} catch (final YAMLException yamlException) {
final String msg =
Copy link
Member

Choose a reason for hiding this comment

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

@yegor256
Copy link
Member

@tmjee a few comments from me

@tmjee
Copy link
Author

tmjee commented Oct 1, 2015

@yegor256 Done.

try {
this.validYaml(text);
} catch (final YAMLException exception) {
final String msg =
Copy link
Member

Choose a reason for hiding this comment

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

@yegor256
Copy link
Member

yegor256 commented Oct 3, 2015

@tmjee a few more comments from me

@tmjee
Copy link
Author

tmjee commented Oct 4, 2015

@yegor256 done.

*/
private String readFile(final ZipFile warf, final ZipEntry entry)
throws MojoFailureException {
InputStreamReader reader = null;
Copy link
Member

Choose a reason for hiding this comment

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

@tmjee the use of null tells us that the design is wrong, see http://www.yegor256.com/2014/05/13/why-null-is-bad.html After taking a closer look at this code I understood what is wrong. Your try/catch block is too big. This is how this code should look:

final Reader reader;
try {
  reader = new InputStreamReader(warf.getInputStream(entry));
} catch () {
  throw ...
}
try {
  return CharStreams.toString(reader);
} finally {
  reader.close();
}

This is how it should be. Keep in mind that every time you see null - it's a bad design.

@yegor256
Copy link
Member

yegor256 commented Oct 4, 2015

@tmjee one more comment from me. Keep in mind, NULL is a very bad thing, in most cases. Well, in all cases.

@tmjee
Copy link
Author

tmjee commented Oct 5, 2015

@yegor256 done

@yegor256
Copy link
Member

yegor256 commented Oct 5, 2015

@rultor try to merge

@rultor
Copy link
Contributor

rultor commented Oct 5, 2015

@rultor try to merge

@yegor256 OK, I'll try to merge now. You can check the progress of the merge here

@rultor rultor merged commit b9977f3 into jcabi:master Oct 5, 2015
@rultor
Copy link
Contributor

rultor commented Oct 5, 2015

@rultor try to merge

@yegor256 Done! FYI, the full log is here (took me 4min)

@dmarkov dmarkov added the CR label Oct 6, 2015
@dmarkov
Copy link

dmarkov commented Oct 7, 2015

@dmzaytsev Much obliged! I have added 22 mins to your account in payment "66848066", 190 hours and 58 mins spent... review comments (c=7) added as a bonus... +22 added to your rating, current score is: +1340

@dmarkov
Copy link

dmarkov commented Oct 7, 2015

@rultor deploy now pls

@rultor
Copy link
Contributor

rultor commented Oct 7, 2015

@rultor deploy now pls

@dmarkov OK, I'll try to deploy now. You can check the progress here

@rultor
Copy link
Contributor

rultor commented Oct 7, 2015

@rultor deploy now pls

@dmarkov Done! FYI, the full log is here (took me 5min)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants