Skip to content

Commit

Permalink
Issue checkstyle#3177: Remove validation of rw access for output file…
Browse files Browse the repository at this point in the history
… in Main#validateCli

(cherry picked from commit d6d86ab)
  • Loading branch information
MEZk committed Jun 17, 2016
1 parent f3d9289 commit 8cecf32
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 47 deletions.
7 changes: 0 additions & 7 deletions src/main/java/com/puppycrawl/tools/checkstyle/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,6 @@ else if (cmdLine.hasOption(OPTION_C_NAME)) {
result.add(String.format("Could not find file '%s'.", propertiesLocation));
}
}
if (cmdLine.hasOption(OPTION_O_NAME)) {
final String outputLocation = cmdLine.getOptionValue(OPTION_O_NAME);
final File file = new File(outputLocation);
if (file.exists() && !file.canWrite()) {
result.add(String.format("Permission denied : '%s'.", outputLocation));
}
}
}
else {
result.add("Must specify a config XML file.");
Expand Down
46 changes: 6 additions & 40 deletions src/test/java/com/puppycrawl/tools/checkstyle/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import static com.puppycrawl.tools.checkstyle.internal.TestUtils.assertUtilsClassHasPrivateConstructor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
Expand Down Expand Up @@ -350,49 +351,14 @@ public void checkAssertion() {
}

@Test
public void testExistingTargetFilePlainOutputToFileWithoutRwPermissions()
throws Exception {
final File file = temporaryFolder.newFile("file.output");
assertTrue(file.setReadable(true, true));
assertTrue(file.setWritable(false, false));
exit.expectSystemExitWithStatus(-1);
exit.checkAssertionAfterwards(new Assertion() {
@Override
public void checkAssertion() throws IOException {
assertEquals("Permission denied : '" + file.getCanonicalPath() + "'."
+ System.lineSeparator(), systemOut.getLog());
assertEquals("", systemErr.getLog());
}
});
Main.main("-c", getPath("config-classname.xml"),
"-f", "plain",
"-o", file.getCanonicalPath(),
getPath("InputMain.java"));
}

@Test
public void testExistingFilePlainOutputToFileWithoutReadAndRwPermissions()
throws Exception {
final File file = temporaryFolder.newFile("file.output");
// That works fine on Linux/Unix, but ....
// It's not possible to make a file unreadable in Windows NTFS for owner.
// http://stackoverflow.com/a/4354686
// https://github.com/google/google-oauth-java-client/issues/55#issuecomment-69403681
//assertTrue(file.setReadable(false, false));
assertTrue(file.setWritable(false, false));
exit.expectSystemExitWithStatus(-1);
exit.checkAssertionAfterwards(new Assertion() {
@Override
public void checkAssertion() throws IOException {
assertEquals("Permission denied : '" + file.getCanonicalPath() + "'."
+ System.lineSeparator(), systemOut.getLog());
assertEquals("", systemErr.getLog());
}
});
public void testCreateNonExistingOutputFile() throws Exception {
final String outputFile = temporaryFolder.getRoot().getCanonicalPath() + "nonexisting.out";
assertFalse(new File(outputFile).exists());
Main.main("-c", getPath("config-classname.xml"),
"-f", "plain",
"-o", file.getCanonicalPath(),
"-o", outputFile,
getPath("InputMain.java"));
assertTrue(new File(outputFile).exists());
}

@Test
Expand Down

0 comments on commit 8cecf32

Please sign in to comment.