@@ -140,41 +140,54 @@ private List<String> run(final List<File> sources) {
140140 }
141141
142142 /**
143- * Build the {@code javac} command line.
143+ * Build the {@code javac} command line. To stay below the
144+ * Windows {@code CreateProcess} 32 KB command-line limit even on
145+ * projects with thousands of sources or long classpaths, every
146+ * argument other than the launcher itself and the {@code -J}
147+ * flags (which {@code javac} forbids inside argfiles) is written
148+ * to a temporary argfile and passed as {@code @argfile}.
144149 * @param sources Java source files to feed
145150 * @return Argv
146151 */
147152 private List <String > command (final List <File > sources ) {
148153 final List <String > command = new ArrayList <>(
149- sources . size () + ErrorProneValidator .JVM_FLAGS .size () + 11
154+ ErrorProneValidator .JVM_FLAGS .size () + 2
150155 );
151156 command .add (ErrorProneValidator .javac ());
152157 for (final String flag : ErrorProneValidator .JVM_FLAGS ) {
153158 command .add ("-J" .concat (flag ));
154159 }
155- command .add ("-XDcompilePolicy=simple" );
156- command .add ("-XDaddTypeAnnotationsToSymbol=true" );
157- command .add ("--should-stop=ifError=FLOW" );
158- command .add ("-proc:none" );
159- command .add ("-Xplugin:ErrorProne" );
160- command .add ("-processorpath" );
161- command .add (ErrorProneValidator .pluginClasspath ());
162160 final File outdir = new File (this .env .tempdir (), "errorprone-classes" );
163161 if (!outdir .exists () && !outdir .mkdirs ()) {
164162 throw new IllegalStateException (
165163 String .format ("Unable to create %s" , outdir )
166164 );
167165 }
168- command .add ("-d" );
169- command .add (outdir .getAbsolutePath ());
166+ final List <String > args = new ArrayList <>(sources .size () + 11 );
167+ args .add ("-XDcompilePolicy=simple" );
168+ args .add ("-XDaddTypeAnnotationsToSymbol=true" );
169+ args .add ("--should-stop=ifError=FLOW" );
170+ args .add ("-proc:none" );
171+ args .add ("-Xplugin:ErrorProne" );
172+ args .add ("-processorpath" );
173+ args .add (ErrorProneValidator .pluginClasspath ());
174+ args .add ("-d" );
175+ args .add (outdir .getAbsolutePath ());
170176 final Collection <String > classpath = this .env .classpath ();
171177 if (!classpath .isEmpty ()) {
172- command .add ("-classpath" );
173- command .add (String .join (File .pathSeparator , classpath ));
178+ args .add ("-classpath" );
179+ args .add (String .join (File .pathSeparator , classpath ));
174180 }
175181 for (final File source : sources ) {
176- command .add (source .getAbsolutePath ());
182+ args .add (source .getAbsolutePath ());
177183 }
184+ command .add (
185+ "@" .concat (
186+ new Argfile (
187+ new File (this .env .tempdir (), "errorprone-args.txt" ), args
188+ ).save ().getAbsolutePath ()
189+ )
190+ );
178191 return command ;
179192 }
180193
0 commit comments