2828import java .nio .file .Path ;
2929import java .nio .file .StandardCopyOption ;
3030import java .util .ArrayList ;
31+ import java .util .LinkedHashMap ;
3132import java .util .LinkedList ;
3233import java .util .List ;
3334import java .util .Map ;
@@ -156,7 +157,7 @@ protected List<Layer> collectLayers(T ref, String contentType, boolean includeAl
156157 * @param paths The paths to the files
157158 * @return The layers
158159 */
159- protected final List <Layer > pushLayers (T ref , boolean withDigest , LocalPath ... paths ) {
160+ protected final List <Layer > pushLayers (T ref , Annotations annotations , boolean withDigest , LocalPath ... paths ) {
160161 List <Layer > layers = new ArrayList <>();
161162 for (LocalPath path : paths ) {
162163 try {
@@ -172,15 +173,20 @@ protected final List<Layer> pushLayers(T ref, boolean withDigest, LocalPath... p
172173 ? path .getPath ().getFileName ().toString ()
173174 : path .getPath ().toString ();
174175 LOG .debug ("Uploading directory as archive with title: {}" , title );
176+
177+ Map <String , String > layerAnnotations = annotations .hasFileAnnotations (title )
178+ ? annotations .getFileAnnotations (title )
179+ : new LinkedHashMap <>(Map .of (Const .ANNOTATION_TITLE , title ));
180+
181+ // Add oras digest/unpack
182+ layerAnnotations .put (
183+ Const .ANNOTATION_ORAS_CONTENT_DIGEST ,
184+ ref .getAlgorithm ().digest (tempTar .getPath ()));
185+ layerAnnotations .put (Const .ANNOTATION_ORAS_UNPACK , "true" );
186+
175187 Layer layer = pushBlob (ref , is )
176188 .withMediaType (path .getMediaType ())
177- .withAnnotations (Map .of (
178- Const .ANNOTATION_TITLE ,
179- title ,
180- Const .ANNOTATION_ORAS_CONTENT_DIGEST ,
181- ref .getAlgorithm ().digest (tempTar .getPath ()),
182- Const .ANNOTATION_ORAS_UNPACK ,
183- "true" ));
189+ .withAnnotations (layerAnnotations );
184190 layers .add (layer );
185191 LOG .info ("Uploaded directory: {}" , layer .getDigest ());
186192 }
@@ -190,11 +196,14 @@ protected final List<Layer> pushLayers(T ref, boolean withDigest, LocalPath... p
190196 if (withDigest ) {
191197 ref = ref .withDigest (ref .getAlgorithm ().digest (path .getPath ()));
192198 }
199+ String title = path .getPath ().getFileName ().toString ();
200+ Map <String , String > layerAnnotations = annotations .hasFileAnnotations (title )
201+ ? annotations .getFileAnnotations (title )
202+ : Map .of (Const .ANNOTATION_TITLE , title );
203+
193204 Layer layer = pushBlob (ref , is )
194205 .withMediaType (path .getMediaType ())
195- .withAnnotations (Map .of (
196- Const .ANNOTATION_TITLE ,
197- path .getPath ().getFileName ().toString ()));
206+ .withAnnotations (layerAnnotations );
198207 layers .add (layer );
199208 LOG .info ("Uploaded: {}" , layer .getDigest ());
200209 }
@@ -413,7 +422,7 @@ public abstract Manifest pushArtifact(
413422 public Manifest attachArtifact (T ref , ArtifactType artifactType , Annotations annotations , LocalPath ... paths ) {
414423
415424 // Push layers
416- List <Layer > layers = pushLayers (ref , true , paths );
425+ List <Layer > layers = pushLayers (ref , annotations , true , paths );
417426
418427 // Get the subject from the descriptor
419428 Descriptor descriptor = getDescriptor (ref );
0 commit comments