@@ -626,6 +626,93 @@ String replaceCiFriendlyVersion(Map<String, String> properties, String version)
626
626
return version != null ? interpolator .interpolate (version , properties ::get ) : null ;
627
627
}
628
628
629
+ /**
630
+ * Get enhanced properties that include profile-aware property resolution.
631
+ * This method activates profiles to ensure that properties defined in profiles
632
+ * are available for CI-friendly version processing and repository URL interpolation.
633
+ * It also includes directory-related properties that may be needed during profile activation.
634
+ */
635
+ private Map <String , String > getEnhancedProperties (Model model , Path rootDirectory ) {
636
+ Map <String , String > properties = new HashMap <>();
637
+
638
+ // Add directory-specific properties first, as they may be needed for profile activation
639
+ if (model .getProjectDirectory () != null ) {
640
+ String basedir = model .getProjectDirectory ().toString ();
641
+ String basedirUri = model .getProjectDirectory ().toUri ().toString ();
642
+ properties .put ("basedir" , basedir );
643
+ properties .put ("project.basedir" , basedir );
644
+ properties .put ("project.basedir.uri" , basedirUri );
645
+ }
646
+ try {
647
+ String root = rootDirectory .toString ();
648
+ String rootUri = rootDirectory .toUri ().toString ();
649
+ properties .put ("project.rootDirectory" , root );
650
+ properties .put ("project.rootDirectory.uri" , rootUri );
651
+ } catch (IllegalStateException e ) {
652
+ // Root directory not available, continue without it
653
+ }
654
+
655
+ // Handle root vs non-root project properties with profile activation
656
+ if (!Objects .equals (rootDirectory , model .getProjectDirectory ())) {
657
+ Path rootModelPath = modelProcessor .locateExistingPom (rootDirectory );
658
+ if (rootModelPath != null ) {
659
+ Model rootModel = derive (Sources .buildSource (rootModelPath )).readFileModel ();
660
+ properties .putAll (getPropertiesWithProfiles (rootModel , properties ));
661
+ }
662
+ } else {
663
+ properties .putAll (getPropertiesWithProfiles (model , properties ));
664
+ }
665
+
666
+ return properties ;
667
+ }
668
+
669
+ /**
670
+ * Get properties from a model including properties from activated profiles.
671
+ * This performs lightweight profile activation to merge profile properties.
672
+ *
673
+ * @param model the model to get properties from
674
+ * @param baseProperties base properties (including directory properties) to include in profile activation context
675
+ */
676
+ private Map <String , String > getPropertiesWithProfiles (Model model , Map <String , String > baseProperties ) {
677
+ Map <String , String > properties = new HashMap <>();
678
+
679
+ // Start with base properties (including directory properties)
680
+ properties .putAll (baseProperties );
681
+
682
+ // Add model properties
683
+ properties .putAll (model .getProperties ());
684
+
685
+ try {
686
+ // Create a profile activation context for this model with base properties available
687
+ DefaultProfileActivationContext profileContext = getProfileActivationContext (request , model );
688
+
689
+ // Activate profiles and merge their properties
690
+ List <Profile > activeProfiles = getActiveProfiles (model .getProfiles (), profileContext );
691
+
692
+ for (Profile profile : activeProfiles ) {
693
+ properties .putAll (profile .getProperties ());
694
+ }
695
+ } catch (Exception e ) {
696
+ // If profile activation fails, log a warning but continue with base properties
697
+ // This ensures that CI-friendly versions still work even if profile activation has issues
698
+ logger .warn ("Failed to activate profiles for CI-friendly version processing: {}" , e .getMessage ());
699
+ logger .debug ("Profile activation failure details" , e );
700
+ }
701
+
702
+ // User properties override everything
703
+ properties .putAll (session .getEffectiveProperties ());
704
+
705
+ return properties ;
706
+ }
707
+
708
+ /**
709
+ * Convenience method for getting properties with profiles without additional base properties.
710
+ * This is a backward compatibility method that provides an empty base properties map.
711
+ */
712
+ private Map <String , String > getPropertiesWithProfiles (Model model ) {
713
+ return getPropertiesWithProfiles (model , new HashMap <>());
714
+ }
715
+
629
716
private void buildBuildPom () throws ModelBuilderException {
630
717
// Retrieve and normalize the source path, ensuring it's non-null and in absolute form
631
718
Path top = request .getSource ().getPath ();
@@ -1501,21 +1588,11 @@ Model doReadFileModel() throws ModelBuilderException {
1501
1588
}
1502
1589
}
1503
1590
1504
- // CI friendly version
1505
- // All expressions are interpolated using user properties and properties
1506
- // defined on the root project.
1507
- Map <String , String > properties = new HashMap <>();
1508
- if (!Objects .equals (rootDirectory , model .getProjectDirectory ())) {
1509
- Path rootModelPath = modelProcessor .locateExistingPom (rootDirectory );
1510
- if (rootModelPath != null ) {
1511
- Model rootModel =
1512
- derive (Sources .buildSource (rootModelPath )).readFileModel ();
1513
- properties .putAll (rootModel .getProperties ());
1514
- }
1515
- } else {
1516
- properties .putAll (model .getProperties ());
1517
- }
1518
- properties .putAll (session .getEffectiveProperties ());
1591
+ // Enhanced property resolution with profile activation for CI-friendly versions and repository URLs
1592
+ // This includes directory properties, profile properties, and user properties
1593
+ Map <String , String > properties = getEnhancedProperties (model , rootDirectory );
1594
+
1595
+ // CI friendly version processing with profile-aware properties
1519
1596
model = model .with ()
1520
1597
.version (replaceCiFriendlyVersion (properties , model .getVersion ()))
1521
1598
.parent (
@@ -1526,22 +1603,8 @@ Model doReadFileModel() throws ModelBuilderException {
1526
1603
model .getParent ().getVersion ()))
1527
1604
: null )
1528
1605
.build ();
1529
- // Interpolate repository URLs
1530
- if (model .getProjectDirectory () != null ) {
1531
- String basedir = model .getProjectDirectory ().toString ();
1532
- String basedirUri = model .getProjectDirectory ().toUri ().toString ();
1533
- properties .put ("basedir" , basedir );
1534
- properties .put ("project.basedir" , basedir );
1535
- properties .put ("project.basedir.uri" , basedirUri );
1536
- }
1537
- try {
1538
- String root = request .getSession ().getRootDirectory ().toString ();
1539
- String rootUri =
1540
- request .getSession ().getRootDirectory ().toUri ().toString ();
1541
- properties .put ("project.rootDirectory" , root );
1542
- properties .put ("project.rootDirectory.uri" , rootUri );
1543
- } catch (IllegalStateException e ) {
1544
- }
1606
+
1607
+ // Repository URL interpolation with the same profile-aware properties
1545
1608
UnaryOperator <String > callback = properties ::get ;
1546
1609
model = model .with ()
1547
1610
.repositories (interpolateRepository (model .getRepositories (), callback ))
0 commit comments