Skip to content

Add support for javac-style @params files - #77

Closed
sormuras wants to merge 1 commit into
google:masterfrom
sormuras:sourcesFile
Closed

sormuras wants to merge 1 commit into
google:masterfrom
sormuras:sourcesFile

Conversation

@sormuras

@sormuras sormuras commented Sep 29, 2016 •

Copy link
Copy Markdown
Contributor

This PR adds support for javac-style @params files.

Example: @params.txt:

--dry-run
--set-exit-if-changed
@@-escaped-option-starting-with-a-single-@-character

α.java
β.java
Ω.java

@nested-params-file

This solves two problems with current command line program:

@lowasser

Copy link
Copy Markdown
Contributor

If I were doing this on a Linux box I'd just write cat file | xargs run-formatter. Is there not something equivalent in your environment?

@sormuras

sormuras commented Sep 30, 2016 •

Copy link
Copy Markdown
Contributor Author

Maybe. I think, not.

The main problem is the command line / shell environment on Windows. If those programs you mention exists on Windows, they'll still use the non-Unicode ... shell thing. If I'm not missing something, it would still not work.

See the MainTest#testMainWithUnicodeArgumentFailsOnWindows included in this PR:

    String expected = "ℕ.java";
    String actual = "N.java"

And this is a good (human-readable) guess -- almost all other Unicode characters are translated to ?s.

Path path = Paths.get(value);
try {
for (String line : Files.readAllLines(path, StandardCharsets.UTF_8)) {
line = line.trim();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if this line would be less bug-prone if it were replaced with CharMatcher.whitespace().trimFrom(line).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Replaced.

@cushon

cushon commented Oct 12, 2017

Copy link
Copy Markdown
Collaborator

What do you think about supporting javac-style @params files, instead of doing this specifically for the sources argument?

@sormuras

Copy link
Copy Markdown
Contributor Author

In progress...

@cushon

cushon commented Oct 12, 2017

Copy link
Copy Markdown
Collaborator

@sormuras

Copy link
Copy Markdown
Contributor Author

Ah, with escaping. Check.

@sormuras

Copy link
Copy Markdown
Contributor Author

Expand the "args" in Main#processArgs(String...) or CommandLineOptionsParser#parse(Iterable<String>)?

I go with the second option for an initial PR.

@sormuras sormuras changed the title Command line option sourcesFile added Add support for javac-style @params files Oct 12, 2017
@sormuras

sormuras commented Oct 12, 2017 •

Copy link
Copy Markdown
Contributor Author

Ready for review. Not. Missed the now out-dated UsageException implementation...

@cushon cushon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM aside from a couple of minor questions.


@Test
// https://stackoverflow.com/questions/7660651/passing-command-line-unicode-argument-to-java-code
public void testMainWithUnicodeArgumentFailsOnWindows() throws Exception {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Did you want to include this test, or was it more to document the problem? I guess it would provide some notice if this changed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It only demonstrates the underlying issue why I needed that --sourceFile feature.

I think, it's superseded by now and I'll remove it from this PR.

CommandLineOptions options =
CommandLineOptionsParser.parse(Arrays.asList("@" + path.toString()));
assertThat(options.files()).containsExactly("Hello.java", "ℕ.java", "Goodbye.java");
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you also test non-params file arguments before/after the params file, the @@-escape syntax, and maybe a nested params file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure.

@sormuras

sormuras commented Oct 12, 2017 •

Copy link
Copy Markdown
Contributor Author

Should we also support comment lines? Meaning ignore lines that start with //.

@sormuras

Copy link
Copy Markdown
Contributor Author

Almost down to a single feature branch. :)

@cushon cushon closed this in 598f248 Oct 14, 2017
@sormuras
sormuras deleted the sourcesFile branch October 14, 2017 03:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants