Skip to content

Commit

Permalink
If there are a large number of target specs, pass them to pants via a…
Browse files Browse the repository at this point in the history
… file to avoid exceeding the OS command line length limit. (#404)

If there are a large number of target specs, pass them to pants via a file to avoid exceeding the OS command line length limit.

Specifically uses a threshold of 100 right now, which is directly in the code as opposed to being defined in a constants file. This seems to be consistent with the rest of the plugin code, which is littered with strings, although there is at least one shared constant `PantsCompileOptionsExecutor.PROJECT_NAME_LIMIT`. In practice, the threshold of 100 should not make a difference to the rest of the plugin code.

Does not currently include any unit tests. In principle it seems like it should be possible to unit test `PantsCompileOptionsExecutor.getPantsExportCommand()`.
  • Loading branch information
sundresh authored and wisechengyi committed Jun 7, 2019
1 parent b4ffe89 commit 713eb08
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.jetbrains.annotations.TestOnly;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -196,7 +197,7 @@ private ProcessOutput getProcessOutput(
}

@NotNull
private GeneralCommandLine getPantsExportCommand(final File outputFile, @NotNull Consumer<String> statusConsumer) {
private GeneralCommandLine getPantsExportCommand(final File outputFile, @NotNull Consumer<String> statusConsumer) throws IOException {
final GeneralCommandLine commandLine = PantsUtil.defaultCommandLine(getProjectPath());

// Grab the import stage pants rc file for IntelliJ.
Expand All @@ -210,7 +211,21 @@ private GeneralCommandLine getPantsExportCommand(final File outputFile, @NotNull
commandLine.addParameter("--export-libraries-sources");
commandLine.addParameter("--export-libraries-javadocs");
}
commandLine.addParameters(getTargetSpecs());
// If there are a large number of target specs, pass them to pants via a
// file to avoid exceeding the OS command line length limit.
final List<String> targetSpecs = getTargetSpecs();
if (targetSpecs.size() > 100) {
final File targetSpecsFile = FileUtil.createTempFile("pants_target_specs", ".in");
try (FileWriter targetSpecsFileWriter = new FileWriter(targetSpecsFile)) {
for (String targetSpec : targetSpecs) {
targetSpecsFileWriter.write(targetSpec);
targetSpecsFileWriter.write('\n');
}
}
commandLine.addParameter("--target-spec-file=" + targetSpecsFile.getPath());
} else {
commandLine.addParameters(targetSpecs);
}
commandLine.addParameter("--export-output-file=" + outputFile.getPath());
return commandLine;
}
Expand Down

0 comments on commit 713eb08

Please sign in to comment.