@@ -1430,7 +1430,7 @@ public static int exit(ApplicationContext context, ExitCodeGenerator... exitCode
1430
1430
*/
1431
1431
public static SpringApplication .Augmented from (ThrowingConsumer <String []> main ) {
1432
1432
Assert .notNull (main , "Main must not be null" );
1433
- return new Augmented (main , Collections .emptySet ());
1433
+ return new Augmented (main , Collections .emptySet (), Collections . emptySet () );
1434
1434
}
1435
1435
1436
1436
/**
@@ -1492,9 +1492,12 @@ public static class Augmented {
1492
1492
1493
1493
private final Set <Class <?>> sources ;
1494
1494
1495
- Augmented (ThrowingConsumer <String []> main , Set <Class <?>> sources ) {
1495
+ private final Set <String > additionalProfiles ;
1496
+
1497
+ Augmented (ThrowingConsumer <String []> main , Set <Class <?>> sources , Set <String > additionalProfiles ) {
1496
1498
this .main = main ;
1497
1499
this .sources = Set .copyOf (sources );
1500
+ this .additionalProfiles = additionalProfiles ;
1498
1501
}
1499
1502
1500
1503
/**
@@ -1506,7 +1509,20 @@ public static class Augmented {
1506
1509
public Augmented with (Class <?>... sources ) {
1507
1510
LinkedHashSet <Class <?>> merged = new LinkedHashSet <>(this .sources );
1508
1511
merged .addAll (Arrays .asList (sources ));
1509
- return new Augmented (this .main , merged );
1512
+ return new Augmented (this .main , merged , this .additionalProfiles );
1513
+ }
1514
+
1515
+ /**
1516
+ * Return a new {@link SpringApplication.Augmented} instance with additional
1517
+ * profiles that should be applied when the application runs.
1518
+ * @param profiles the profiles that should be applied
1519
+ * @return a new {@link SpringApplication.Augmented} instance
1520
+ * @since 3.4.0
1521
+ */
1522
+ public Augmented withAdditionalProfiles (String ... profiles ) {
1523
+ Set <String > merged = new LinkedHashSet <>(this .additionalProfiles );
1524
+ merged .addAll (Arrays .asList (profiles ));
1525
+ return new Augmented (this .main , this .sources , merged );
1510
1526
}
1511
1527
1512
1528
/**
@@ -1518,6 +1534,7 @@ public SpringApplication.Running run(String... args) {
1518
1534
RunListener runListener = new RunListener ();
1519
1535
SpringApplicationHook hook = new SingleUseSpringApplicationHook ((springApplication ) -> {
1520
1536
springApplication .addPrimarySources (this .sources );
1537
+ springApplication .setAdditionalProfiles (this .additionalProfiles .toArray (String []::new ));
1521
1538
return runListener ;
1522
1539
});
1523
1540
withHook (hook , () -> this .main .accept (args ));
0 commit comments