6
6
import com .typesafe .config .Config ;
7
7
import com .typesafe .config .ConfigFactory ;
8
8
import com .typesafe .config .ConfigParseOptions ;
9
+ import java .util .Collections ;
9
10
import org .gradle .profiler .mutations .ApplyAbiChangeToSourceFileMutator ;
10
11
import org .gradle .profiler .mutations .ApplyChangeToAndroidLayoutFileMutator ;
11
12
import org .gradle .profiler .mutations .ApplyChangeToAndroidManifestFileMutator ;
@@ -220,72 +221,19 @@ static List<ScenarioDefinition> loadScenarios(File scenarioFile, InvocationSetti
220
221
int buildCount = getBuildCount (settings , scenario );
221
222
File scenarioBaseDir = new File (settings .getOutputDir (), GradleScenarioDefinition .safeFileName (scenarioName ));
222
223
223
- if (scenario .hasPath (BAZEL ) && settings .isBazel ()) {
224
- Config executionInstructions = getConfig (scenarioFile , settings , scenarioName , scenario , BAZEL , BAZEL_KEYS );
225
-
226
- List <String > targets = ConfigUtil .strings (executionInstructions , TARGETS );
227
- File bazelHome = getToolHome (executionInstructions );
228
- File outputDir = new File (scenarioBaseDir , "bazel" );
229
- int warmUpCount = getWarmUpCount (settings , scenario );
230
- definitions .add (new BazelScenarioDefinition (scenarioName , title , targets , mutators , warmUpCount , buildCount , outputDir , bazelHome ));
231
- } else if (scenario .hasPath (BUCK ) && settings .isBuck ()) {
232
- Config executionInstructions = getConfig (scenarioFile , settings , scenarioName , scenario , BUCK , BUCK_KEYS );
233
- List <String > targets = ConfigUtil .strings (executionInstructions , TARGETS );
234
- String type = ConfigUtil .string (executionInstructions , TYPE , null );
235
- File buckHome = getToolHome (executionInstructions );
236
- File outputDir = new File (scenarioBaseDir , "buck" );
237
- int warmUpCount = getWarmUpCount (settings , scenario );
238
- definitions .add (new BuckScenarioDefinition (scenarioName , title , targets , type , mutators , warmUpCount , buildCount , outputDir , buckHome ));
239
- } else if (scenario .hasPath (MAVEN ) && settings .isMaven ()) {
240
- Config executionInstructions = getConfig (scenarioFile , settings , scenarioName , scenario , MAVEN , MAVEN_KEYS );
241
- List <String > targets = ConfigUtil .strings (executionInstructions , TARGETS );
242
- File mavenHome = getToolHome (executionInstructions );
243
- File outputDir = new File (scenarioBaseDir , "maven" );
244
- int warmUpCount = getWarmUpCount (settings , scenario );
245
- definitions .add (new MavenScenarioDefinition (scenarioName , title , targets , mutators , warmUpCount , buildCount , outputDir , mavenHome ));
246
- } else if (!settings .isBazel () && !settings .isBuck () && !settings .isMaven ()) {
247
- List <GradleBuildConfiguration > versions = ConfigUtil .strings (scenario , VERSIONS , settings .getVersions ()).stream ().map (inspector ::readConfiguration ).collect (
248
- Collectors .toList ());
249
- if (versions .isEmpty ()) {
250
- versions .add (inspector .readConfiguration ());
251
- }
252
-
253
- List <String > gradleArgs = ConfigUtil .strings (scenario , GRADLE_ARGS );
254
- BuildAction buildAction = getBuildAction (scenario , scenarioFile , settings );
255
- GradleBuildInvoker invoker = invoker (scenario , (GradleBuildInvoker ) settings .getInvoker (), buildAction );
256
- int warmUpCount = getWarmUpCount (settings , invoker , scenario );
257
- List <String > measuredBuildOperations = getMeasuredBuildOperations (settings , scenario );
258
- BuildAction cleanupAction = getCleanupAction (scenario );
259
- Map <String , String > systemProperties = ConfigUtil .map (scenario , SYSTEM_PROPERTIES , settings .getSystemProperties ());
260
- List <String > jvmArgs = ConfigUtil .strings (scenario , JVM_ARGS );
261
- for (GradleBuildConfiguration version : versions ) {
262
- File outputDir = versions .size () == 1 ? scenarioBaseDir : new File (scenarioBaseDir , version .getGradleVersion ().getVersion ());
263
- definitions .add (new GradleScenarioDefinition (
264
- scenarioName ,
265
- title ,
266
- invoker ,
267
- version ,
268
- buildAction ,
269
- cleanupAction ,
270
- gradleArgs ,
271
- systemProperties ,
272
- mutators ,
273
- warmUpCount ,
274
- buildCount ,
275
- outputDir ,
276
- jvmArgs ,
277
- measuredBuildOperations
278
- ));
279
- }
280
- }
224
+ definitions .addAll (
225
+ getScenarioDefinitions (
226
+ scenarioFile , settings , scenarioName , scenario , title , mutators , buildCount ,
227
+ scenarioBaseDir , inspector )
228
+ );
281
229
}
282
230
283
231
definitions .forEach (ScenarioDefinition ::validate );
284
232
285
233
return definitions ;
286
234
}
287
235
288
- private static Config getConfig (File scenarioFile , InvocationSettings settings , String scenarioName , Config scenario , String toolName , List <String > toolKeys ) {
236
+ private static Config getExecutionInstructions (File scenarioFile , InvocationSettings settings , String scenarioName , Config scenario , String toolName , List <String > toolKeys ) {
289
237
if (settings .isProfile ()) {
290
238
throw new IllegalArgumentException ("Can only profile scenario '" + scenarioName + "' when building using Gradle." );
291
239
}
@@ -298,6 +246,129 @@ private static Config getConfig(File scenarioFile, InvocationSettings settings,
298
246
return executionInstructions ;
299
247
}
300
248
249
+ private static List <ScenarioDefinition > getScenarioDefinitions (File scenarioFile ,
250
+ InvocationSettings settings , String scenarioName , Config scenario , String title ,
251
+ List <BuildMutator > mutators , int buildCount , File scenarioBaseDir ,
252
+ GradleBuildConfigurationReader inspector ) {
253
+ if (scenario .hasPath (BAZEL ) && settings .isBazel ()) {
254
+ return ImmutableList .copyOf (
255
+ getBazelScenarioDefinitions (scenarioFile , settings , scenarioName , scenario , title , mutators , buildCount ,
256
+ scenarioBaseDir )
257
+ );
258
+ } else if (scenario .hasPath (BUCK ) && settings .isBuck ()) {
259
+ return ImmutableList .copyOf (
260
+ getBuckScenarioDefinitions (scenarioFile , settings , scenarioName , scenario , title , mutators , buildCount ,
261
+ scenarioBaseDir )
262
+ );
263
+ } else if (scenario .hasPath (MAVEN ) && settings .isMaven ()) {
264
+ return ImmutableList .copyOf (
265
+ getMavenScenarioDefinitions (scenarioFile , settings , scenarioName , scenario , title , mutators , buildCount ,
266
+ scenarioBaseDir )
267
+ );
268
+ } else if (!settings .isBazel () && !settings .isBuck () && !settings .isMaven ()) {
269
+ return ImmutableList .copyOf (
270
+ getGradleScenarioDefinitions (scenarioFile , settings , scenarioName , scenario , title , mutators , buildCount ,
271
+ scenarioBaseDir , inspector
272
+ )
273
+ );
274
+ } else {
275
+ return Collections .emptyList ();
276
+ }
277
+ }
278
+
279
+ private static List <GradleScenarioDefinition > getGradleScenarioDefinitions (
280
+ File scenarioFile ,
281
+ InvocationSettings settings , String scenarioName , Config scenario , String title ,
282
+ List <BuildMutator > mutators , int buildCount , File scenarioBaseDir ,
283
+ GradleBuildConfigurationReader inspector
284
+ ) {
285
+ List <GradleScenarioDefinition > scenarioDefinitions = new ArrayList <>();
286
+ List <GradleBuildConfiguration > versions = ConfigUtil
287
+ .strings (scenario , VERSIONS , settings .getVersions ()).stream ()
288
+ .map (inspector ::readConfiguration ).collect (
289
+ Collectors .toList ());
290
+ if (versions .isEmpty ()) {
291
+ versions .add (inspector .readConfiguration ());
292
+ }
293
+
294
+ List <String > gradleArgs = ConfigUtil .strings (scenario , GRADLE_ARGS );
295
+ BuildAction buildAction = getBuildAction (scenario , scenarioFile , settings );
296
+ GradleBuildInvoker invoker = invoker (scenario ,
297
+ (GradleBuildInvoker ) settings .getInvoker (), buildAction );
298
+ int warmUpCount = getWarmUpCount (settings , invoker , scenario );
299
+ List <String > measuredBuildOperations = getMeasuredBuildOperations (settings ,
300
+ scenario );
301
+ BuildAction cleanupAction = getCleanupAction (scenario );
302
+ Map <String , String > systemProperties = ConfigUtil
303
+ .map (scenario , SYSTEM_PROPERTIES , settings .getSystemProperties ());
304
+ List <String > jvmArgs = ConfigUtil .strings (scenario , JVM_ARGS );
305
+ for (GradleBuildConfiguration version : versions ) {
306
+ File outputDir = versions .size () == 1 ? scenarioBaseDir
307
+ : new File (scenarioBaseDir , version .getGradleVersion ().getVersion ());
308
+ scenarioDefinitions .add (new GradleScenarioDefinition (
309
+ scenarioName ,
310
+ title ,
311
+ invoker ,
312
+ version ,
313
+ buildAction ,
314
+ cleanupAction ,
315
+ gradleArgs ,
316
+ systemProperties ,
317
+ mutators ,
318
+ warmUpCount ,
319
+ buildCount ,
320
+ outputDir ,
321
+ jvmArgs ,
322
+ measuredBuildOperations
323
+ ));
324
+ }
325
+ return scenarioDefinitions ;
326
+ }
327
+
328
+ private static List <MavenScenarioDefinition > getMavenScenarioDefinitions (File scenarioFile ,
329
+ InvocationSettings settings , String scenarioName , Config scenario , String title ,
330
+ List <BuildMutator > mutators , int buildCount , File scenarioBaseDir ) {
331
+
332
+ Config executionInstructions = getExecutionInstructions (scenarioFile , settings , scenarioName ,
333
+ scenario , MAVEN , MAVEN_KEYS );
334
+ List <String > targets = ConfigUtil .strings (executionInstructions , TARGETS );
335
+ File mavenHome = getToolHome (executionInstructions );
336
+ File outputDir = new File (scenarioBaseDir , "maven" );
337
+ int warmUpCount = getWarmUpCount (settings , scenario );
338
+ return ImmutableList .of (new MavenScenarioDefinition (scenarioName ,
339
+ title , targets , mutators , warmUpCount ,
340
+ buildCount , outputDir , mavenHome ));
341
+ }
342
+
343
+ private static List <BuckScenarioDefinition > getBuckScenarioDefinitions (File scenarioFile ,
344
+ InvocationSettings settings , String scenarioName , Config scenario , String title ,
345
+ List <BuildMutator > mutators , int buildCount , File scenarioBaseDir ) {
346
+ Config executionInstructions = getExecutionInstructions (scenarioFile , settings , scenarioName ,
347
+ scenario , BUCK , BUCK_KEYS );
348
+ List <String > targets = ConfigUtil .strings (executionInstructions , TARGETS );
349
+ String type = ConfigUtil .string (executionInstructions , TYPE , null );
350
+ File buckHome = getToolHome (executionInstructions );
351
+ File outputDir = new File (scenarioBaseDir , "buck" );
352
+ int warmUpCount = getWarmUpCount (settings , scenario );
353
+ return ImmutableList .of (new BuckScenarioDefinition (scenarioName , title , targets , type , mutators ,
354
+ warmUpCount , buildCount , outputDir , buckHome ));
355
+ }
356
+
357
+ private static List <BazelScenarioDefinition > getBazelScenarioDefinitions (File scenarioFile ,
358
+ InvocationSettings settings , String scenarioName , Config scenario , String title ,
359
+ List <BuildMutator > mutators , int buildCount , File scenarioBaseDir ) {
360
+ Config executionInstructions = getExecutionInstructions (scenarioFile , settings , scenarioName , scenario ,
361
+ BAZEL , BAZEL_KEYS );
362
+
363
+ List <String > targets = ConfigUtil .strings (executionInstructions , TARGETS );
364
+ File bazelHome = getToolHome (executionInstructions );
365
+ File outputDir = new File (scenarioBaseDir , "bazel" );
366
+ int warmUpCount = getWarmUpCount (settings , scenario );
367
+ return ImmutableList .of (new BazelScenarioDefinition (
368
+ scenarioName , title , targets , mutators , warmUpCount , buildCount , outputDir ,
369
+ bazelHome ));
370
+ }
371
+
301
372
private static ImmutableList <String > getMeasuredBuildOperations (InvocationSettings settings , Config scenario ) {
302
373
return ImmutableSet .<String >builder ()
303
374
.addAll (settings .getMeasuredBuildOperations ())
0 commit comments