@@ -38,6 +38,14 @@ public static void addMainMetadata(BuildScanApi buildScanApi) {
3838 buildScanApi .tag ( "hibernate-search" );
3939 }
4040
41+ public static void addCompilerMetadata (GoalMetadataProvider .Context context ) {
42+ var buildScanApi = context .buildScan ();
43+ String compilerId = context .configuration ().getString ( "compilerId" );
44+ if ( !Strings .isBlank ( compilerId ) ) {
45+ buildScanApi .tag ( "compiler-%s" .formatted ( compilerId ) );
46+ }
47+ }
48+
4149 public static void addJavaExecutableVersion (GoalMetadataProvider .Context context ,
4250 String javaExecutable , String javaVersion ,
4351 boolean canCacheExactVersion ) {
@@ -79,8 +87,8 @@ public static void addFailsafeMetadata(GoalMetadataProvider.Context context) {
7987 buildScanApi .tag ( "h2" );
8088 }
8189 else {
82- addDockerfileShortImageRef ( context ,
83- "database/%s.Dockerfile" .formatted ( dbKind ), null );
90+ addDockerfileMetadata ( context ,
91+ "database/%s.Dockerfile" .formatted ( dbKind ), dbKind , null , false );
8492 }
8593 }
8694 }
@@ -101,17 +109,22 @@ public static void addFailsafeMetadata(GoalMetadataProvider.Context context) {
101109 && ( explicitBackend == null || "elasticsearch" .equals ( explicitBackend ) )
102110 && !context .properties ().getBoolean ( "test.elasticsearch.skip" ) ) {
103111 var distribution = context .properties ().getString ( "test.elasticsearch.distribution" );
104- addDockerfileShortImageRef ( context ,
112+ addDockerfileMetadata ( context ,
105113 "search-backend/%s.Dockerfile" .formatted ( distribution ),
106- context .properties ().getString ( "test.elasticsearch.version" ) );
114+ "elastic" .equals ( distribution ) ? "elasticsearch" : distribution ,
115+ context .properties ().getString ( "test.elasticsearch.version" ), true );
107116 }
108117 }
109118
110- private static void addDockerfileShortImageRef (GoalMetadataProvider .Context context ,
111- String dockerfileRelativePath , String versionOverride ) {
119+ private static void addDockerfileMetadata (GoalMetadataProvider .Context context ,
120+ String dockerfileRelativePath , String tag , String versionOverride , boolean tagVersion ) {
112121 var buildScanApi = context .buildScan ();
113122 var path = Path .of ( context .metadata ().getSession ().getExecutionRootDirectory (),
114123 "build/container" , dockerfileRelativePath );
124+ if ( tag != null ) {
125+ // Tag without version
126+ buildScanApi .tag ( tag );
127+ }
115128 try {
116129 String ref ;
117130 try ( var stream = Files .lines ( path ) ) {
@@ -131,15 +144,19 @@ private static void addDockerfileShortImageRef(GoalMetadataProvider.Context cont
131144 if ( !Strings .isBlank ( versionOverride ) ) {
132145 ref = ref .substring ( 0 , ref .lastIndexOf ( ':' ) + 1 ) + versionOverride ;
133146 }
134- String shortImageRef = toShortImageRef ( ref );
135- buildScanApi .tag ( shortImageRef .replace ( ':' , '-' ) );
136- buildScanApi .value (
137- shortImageRef .substring ( 0 , shortImageRef .lastIndexOf ( ':' ) ),
138- ref .substring ( ref .lastIndexOf ( ':' ) + 1 )
139- );
147+ context .buildScanDeduplicatedValue ( "Container" , ref );
148+
149+ // Tag with version
150+ if ( tag != null && tagVersion ) {
151+ String shortImageRef = toShortImageRef ( ref );
152+ int colonIndex = shortImageRef .indexOf ( ':' );
153+ if ( colonIndex >= 0 ) {
154+ buildScanApi .tag ( tag + "-" + shortImageRef .substring ( colonIndex + 1 ) );
155+ }
156+ }
140157 }
141158 catch (RuntimeException | IOException e ) {
142- Log .warn ( "Unable to add tag from Dockerfile at %s: %s" .formatted ( path , e .getMessage () ) );
159+ Log .warn ( "Unable to add metadata from Dockerfile at %s: %s" .formatted ( path , e .getMessage () ) );
143160 }
144161 }
145162
0 commit comments