[
https://issues.apache.org/jira/browse/MNG-7622?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17645972#comment-17645972
]
ASF GitHub Bot commented on MNG-7622:
-------------------------------------
gnodet commented on code in PR #907:
URL: https://github.com/apache/maven/pull/907#discussion_r1045541829
##########
maven-core/src/main/java/org/apache/maven/internal/transformation/TransformedArtifact.java:
##########
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.internal.transformation;
+
+import static java.util.Objects.requireNonNull;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.security.MessageDigest;
+import java.util.function.BiConsumer;
+import java.util.function.Supplier;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+
+/**
+ * Transformed artifact is derived with some transformation from source
artifact.
+ *
+ * @since TBD
+ */
+public abstract class TransformedArtifact extends DefaultArtifact {
+
+ private final OnChangeTransformer onChangeTransformer;
+
+ public TransformedArtifact(
+ Artifact source,
+ Supplier<Path> sourcePathProvider,
+ String classifier,
+ String extension,
+ Path targetPath,
+ BiConsumer<Path, Path> transformerConsumer) {
+ super(
+ source.getGroupId(),
+ source.getArtifactId(),
+ source.getVersionRange(),
+ source.getScope(),
+ extension,
+ classifier,
+ new TransformedArtifactHandler(
+ classifier, extension,
source.getArtifactHandler().getPackaging()));
+ this.onChangeTransformer =
+ new OnChangeTransformer(sourcePathProvider, targetPath,
TransformedArtifact::sha1, transformerConsumer);
+ }
+
+ @Override
+ public boolean isResolved() {
+ return getFile() != null;
+ }
+
+ @Override
+ public void setFile(File file) {
+ throw new IllegalStateException("transformed artifact file cannot be
set");
+ }
+
+ @Override
+ public File getFile() {
+ Path result = onChangeTransformer.get();
+ if (result == null) {
+ return null;
+ }
+ return result.toFile();
+ }
+
+ private static final int BUFFER_SIZE = 8192;
+
+ private static String sha1(Path path) {
+ try {
+ MessageDigest md = MessageDigest.getInstance("SHA-1");
+ try (InputStream fis = new
BufferedInputStream(Files.newInputStream(path), BUFFER_SIZE)) {
Review Comment:
Yes, but the stream is read using a `read(buffer)` which achieves the same
effect than the `BufferedInputStream. So we end up reading into a buffer, then
transferring into another buffer.
> Reimplement Consumer POM feature
> --------------------------------
>
> Key: MNG-7622
> URL: https://issues.apache.org/jira/browse/MNG-7622
> Project: Maven
> Issue Type: Task
> Components: build/consumer
> Reporter: Tamas Cservenak
> Priority: Major
> Fix For: 4.0.x-candidate
>
>
> Current implementation relies on deprecated resolver API (is deprecated as it
> is OOM prone), and also renders use cases like m-gpg-p but also checksum-m-p
> broken.
> Reimplement consumer POM feature that:
> * does not use FileTransformer API
> * allows use cases like m-gpg-p
--
This message was sent by Atlassian Jira
(v8.20.10#820010)