You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "hboutemy (via GitHub)" <gi...@apache.org> on 2023/04/18 23:31:40 UTC

[GitHub] [maven-gpg-plugin] hboutemy opened a new pull request, #45: extract FilesCollector

hboutemy opened a new pull request, #45:
URL: https://github.com/apache/maven-gpg-plugin/pull/45

   this will ease writing another signing plugin using for example sigstore as a signing tool #43 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-gpg-plugin] hboutemy commented on a diff in pull request #45: extract FilesCollector

Posted by "hboutemy (via GitHub)" <gi...@apache.org>.
hboutemy commented on code in PR #45:
URL: https://github.com/apache/maven-gpg-plugin/pull/45#discussion_r1173390628


##########
src/main/java/org/apache/maven/plugins/gpg/FilesCollector.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * 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.plugins.gpg;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.SelectorUtils;
+
+/**
+ * Collects project artifact, the POM, and attached artifacts to be signed.
+ *
+ * @since 3.1.0
+ */
+public class FilesCollector {
+    private final MavenProject project;
+
+    private static final String DEFAULT_EXCLUDES[] =
+            new String[] {"**/*.md5", "**/*.sha1", "**/*.sha256", "**/*.sha512", "**/*.asc"};
+
+    private final String[] excludes;
+
+    private final Log log;
+
+    public FilesCollector(MavenProject project, String[] excludes, Log log) {
+        this.project = project;
+        this.log = log;
+        if (excludes == null || excludes.length == 0) {
+            this.excludes = DEFAULT_EXCLUDES;
+            return;
+        }
+        String newExcludes[] = new String[excludes.length];
+        for (int i = 0; i < excludes.length; i++) {
+            String pattern;
+            pattern = excludes[i].trim().replace('/', File.separatorChar).replace('\\', File.separatorChar);
+            if (pattern.endsWith(File.separator)) {
+                pattern += "**";
+            }
+            newExcludes[i] = pattern;
+        }
+        this.excludes = newExcludes;
+    }
+
+    public List<Item> collect() throws MojoExecutionException, MojoFailureException {
+        List<Item> items = new ArrayList<>();
+
+        if (!"pom".equals(project.getPackaging())) {
+            // ----------------------------------------------------------------------------
+            // Project artifact
+            // ----------------------------------------------------------------------------
+
+            Artifact artifact = project.getArtifact();
+
+            File file = artifact.getFile();
+
+            if (file != null && file.isFile()) {
+                items.add(new Item(file, artifact.getArtifactHandler().getExtension()));
+            } else if (project.getAttachedArtifacts().isEmpty()) {
+                throw new MojoFailureException("The project artifact has not been assembled yet. "
+                        + "Please do not invoke this goal before the lifecycle phase \"package\".");
+            } else {
+                log.debug("Main artifact not assembled, skipping signature generation");
+            }
+        }
+
+        // ----------------------------------------------------------------------------
+        // POM
+        // ----------------------------------------------------------------------------
+
+        File pomToSign =
+                new File(project.getBuild().getDirectory(), project.getBuild().getFinalName() + ".pom");
+
+        try {
+            FileUtils.copyFile(project.getFile(), pomToSign);

Review Comment:
   no idea, this is not the purpose of this refactoring :)
   what i know is that anything that will have to change in the future for producer/consumer will be shared and easier to see with the shared files collector implementation



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-gpg-plugin] hboutemy merged pull request #45: extract FilesCollector

Posted by "hboutemy (via GitHub)" <gi...@apache.org>.
hboutemy merged PR #45:
URL: https://github.com/apache/maven-gpg-plugin/pull/45


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-gpg-plugin] hboutemy commented on a diff in pull request #45: extract FilesCollector

Posted by "hboutemy (via GitHub)" <gi...@apache.org>.
hboutemy commented on code in PR #45:
URL: https://github.com/apache/maven-gpg-plugin/pull/45#discussion_r1173386541


##########
src/main/java/org/apache/maven/plugins/gpg/FilesCollector.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * 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.plugins.gpg;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.SelectorUtils;
+
+/**
+ * Collects project artifact, the POM, and attached artifacts to be signed.
+ *
+ * @since 3.1.0
+ */
+public class FilesCollector {
+    private final MavenProject project;
+
+    private static final String DEFAULT_EXCLUDES[] =
+            new String[] {"**/*.md5", "**/*.sha1", "**/*.sha256", "**/*.sha512", "**/*.asc"};

Review Comment:
   this PR is about refactoring: adding other extension will be next, yes, it's planned :)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-gpg-plugin] michael-o commented on a diff in pull request #45: extract FilesCollector

Posted by "michael-o (via GitHub)" <gi...@apache.org>.
michael-o commented on code in PR #45:
URL: https://github.com/apache/maven-gpg-plugin/pull/45#discussion_r1172426963


##########
src/main/java/org/apache/maven/plugins/gpg/FilesCollector.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * 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.plugins.gpg;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.SelectorUtils;
+
+/**
+ * Collects project artifact, the POM, and attached artifacts to be signed.
+ *
+ * @since 3.1.0
+ */
+public class FilesCollector {
+    private final MavenProject project;
+
+    private static final String DEFAULT_EXCLUDES[] =
+            new String[] {"**/*.md5", "**/*.sha1", "**/*.sha256", "**/*.sha512", "**/*.asc"};

Review Comment:
   Since this is generic, maybe one needs to add `.sig` and `.crt` as well?



##########
src/main/java/org/apache/maven/plugins/gpg/FilesCollector.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * 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.plugins.gpg;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.SelectorUtils;
+
+/**
+ * Collects project artifact, the POM, and attached artifacts to be signed.
+ *
+ * @since 3.1.0
+ */
+public class FilesCollector {
+    private final MavenProject project;
+
+    private static final String DEFAULT_EXCLUDES[] =
+            new String[] {"**/*.md5", "**/*.sha1", "**/*.sha256", "**/*.sha512", "**/*.asc"};
+
+    private final String[] excludes;
+
+    private final Log log;
+
+    public FilesCollector(MavenProject project, String[] excludes, Log log) {
+        this.project = project;
+        this.log = log;
+        if (excludes == null || excludes.length == 0) {
+            this.excludes = DEFAULT_EXCLUDES;
+            return;
+        }
+        String newExcludes[] = new String[excludes.length];
+        for (int i = 0; i < excludes.length; i++) {
+            String pattern;
+            pattern = excludes[i].trim().replace('/', File.separatorChar).replace('\\', File.separatorChar);
+            if (pattern.endsWith(File.separator)) {
+                pattern += "**";
+            }
+            newExcludes[i] = pattern;
+        }
+        this.excludes = newExcludes;
+    }
+
+    public List<Item> collect() throws MojoExecutionException, MojoFailureException {
+        List<Item> items = new ArrayList<>();
+
+        if (!"pom".equals(project.getPackaging())) {
+            // ----------------------------------------------------------------------------
+            // Project artifact
+            // ----------------------------------------------------------------------------
+
+            Artifact artifact = project.getArtifact();
+
+            File file = artifact.getFile();
+
+            if (file != null && file.isFile()) {
+                items.add(new Item(file, artifact.getArtifactHandler().getExtension()));
+            } else if (project.getAttachedArtifacts().isEmpty()) {
+                throw new MojoFailureException("The project artifact has not been assembled yet. "

Review Comment:
   This also applies to the main artifact I guess?



##########
src/main/java/org/apache/maven/plugins/gpg/FilesCollector.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * 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.plugins.gpg;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.SelectorUtils;
+
+/**
+ * Collects project artifact, the POM, and attached artifacts to be signed.
+ *
+ * @since 3.1.0
+ */
+public class FilesCollector {
+    private final MavenProject project;
+
+    private static final String DEFAULT_EXCLUDES[] =
+            new String[] {"**/*.md5", "**/*.sha1", "**/*.sha256", "**/*.sha512", "**/*.asc"};
+
+    private final String[] excludes;
+
+    private final Log log;
+
+    public FilesCollector(MavenProject project, String[] excludes, Log log) {
+        this.project = project;
+        this.log = log;
+        if (excludes == null || excludes.length == 0) {
+            this.excludes = DEFAULT_EXCLUDES;
+            return;
+        }
+        String newExcludes[] = new String[excludes.length];
+        for (int i = 0; i < excludes.length; i++) {
+            String pattern;
+            pattern = excludes[i].trim().replace('/', File.separatorChar).replace('\\', File.separatorChar);
+            if (pattern.endsWith(File.separator)) {
+                pattern += "**";
+            }
+            newExcludes[i] = pattern;
+        }
+        this.excludes = newExcludes;
+    }
+
+    public List<Item> collect() throws MojoExecutionException, MojoFailureException {
+        List<Item> items = new ArrayList<>();
+
+        if (!"pom".equals(project.getPackaging())) {
+            // ----------------------------------------------------------------------------
+            // Project artifact
+            // ----------------------------------------------------------------------------
+
+            Artifact artifact = project.getArtifact();
+
+            File file = artifact.getFile();
+
+            if (file != null && file.isFile()) {
+                items.add(new Item(file, artifact.getArtifactHandler().getExtension()));
+            } else if (project.getAttachedArtifacts().isEmpty()) {
+                throw new MojoFailureException("The project artifact has not been assembled yet. "
+                        + "Please do not invoke this goal before the lifecycle phase \"package\".");
+            } else {
+                log.debug("Main artifact not assembled, skipping signature generation");
+            }
+        }
+
+        // ----------------------------------------------------------------------------
+        // POM
+        // ----------------------------------------------------------------------------
+
+        File pomToSign =
+                new File(project.getBuild().getDirectory(), project.getBuild().getFinalName() + ".pom");
+
+        try {
+            FileUtils.copyFile(project.getFile(), pomToSign);

Review Comment:
   How will this work with producer/consumer?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-gpg-plugin] hboutemy commented on a diff in pull request #45: extract FilesCollector

Posted by "hboutemy (via GitHub)" <gi...@apache.org>.
hboutemy commented on code in PR #45:
URL: https://github.com/apache/maven-gpg-plugin/pull/45#discussion_r1173389857


##########
src/main/java/org/apache/maven/plugins/gpg/FilesCollector.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * 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.plugins.gpg;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.SelectorUtils;
+
+/**
+ * Collects project artifact, the POM, and attached artifacts to be signed.
+ *
+ * @since 3.1.0
+ */
+public class FilesCollector {
+    private final MavenProject project;
+
+    private static final String DEFAULT_EXCLUDES[] =
+            new String[] {"**/*.md5", "**/*.sha1", "**/*.sha256", "**/*.sha512", "**/*.asc"};
+
+    private final String[] excludes;
+
+    private final Log log;
+
+    public FilesCollector(MavenProject project, String[] excludes, Log log) {
+        this.project = project;
+        this.log = log;
+        if (excludes == null || excludes.length == 0) {
+            this.excludes = DEFAULT_EXCLUDES;
+            return;
+        }
+        String newExcludes[] = new String[excludes.length];
+        for (int i = 0; i < excludes.length; i++) {
+            String pattern;
+            pattern = excludes[i].trim().replace('/', File.separatorChar).replace('\\', File.separatorChar);
+            if (pattern.endsWith(File.separator)) {
+                pattern += "**";
+            }
+            newExcludes[i] = pattern;
+        }
+        this.excludes = newExcludes;
+    }
+
+    public List<Item> collect() throws MojoExecutionException, MojoFailureException {
+        List<Item> items = new ArrayList<>();
+
+        if (!"pom".equals(project.getPackaging())) {
+            // ----------------------------------------------------------------------------
+            // Project artifact
+            // ----------------------------------------------------------------------------
+
+            Artifact artifact = project.getArtifact();
+
+            File file = artifact.getFile();
+
+            if (file != null && file.isFile()) {
+                items.add(new Item(file, artifact.getArtifactHandler().getExtension()));
+            } else if (project.getAttachedArtifacts().isEmpty()) {
+                throw new MojoFailureException("The project artifact has not been assembled yet. "

Review Comment:
   1. AFAIK it is the main artifact: I don't get what you mean by "also applies"
   2. this is purely an extract of existing algorithm from `gpg:sign`: the initial code just signs when collecting, when I differentiate the collection as a first step to let different signature algorithms after
   
   see https://github.com/apache/maven-gpg-plugin/blob/525508093293cd1bb78d439cb28f2c48d7d79d9b/src/main/java/org/apache/maven/plugins/gpg/GpgSignAttachedMojo.java#L129



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-gpg-plugin] hboutemy commented on a diff in pull request #45: extract FilesCollector

Posted by "hboutemy (via GitHub)" <gi...@apache.org>.
hboutemy commented on code in PR #45:
URL: https://github.com/apache/maven-gpg-plugin/pull/45#discussion_r1173390628


##########
src/main/java/org/apache/maven/plugins/gpg/FilesCollector.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * 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.plugins.gpg;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.SelectorUtils;
+
+/**
+ * Collects project artifact, the POM, and attached artifacts to be signed.
+ *
+ * @since 3.1.0
+ */
+public class FilesCollector {
+    private final MavenProject project;
+
+    private static final String DEFAULT_EXCLUDES[] =
+            new String[] {"**/*.md5", "**/*.sha1", "**/*.sha256", "**/*.sha512", "**/*.asc"};
+
+    private final String[] excludes;
+
+    private final Log log;
+
+    public FilesCollector(MavenProject project, String[] excludes, Log log) {
+        this.project = project;
+        this.log = log;
+        if (excludes == null || excludes.length == 0) {
+            this.excludes = DEFAULT_EXCLUDES;
+            return;
+        }
+        String newExcludes[] = new String[excludes.length];
+        for (int i = 0; i < excludes.length; i++) {
+            String pattern;
+            pattern = excludes[i].trim().replace('/', File.separatorChar).replace('\\', File.separatorChar);
+            if (pattern.endsWith(File.separator)) {
+                pattern += "**";
+            }
+            newExcludes[i] = pattern;
+        }
+        this.excludes = newExcludes;
+    }
+
+    public List<Item> collect() throws MojoExecutionException, MojoFailureException {
+        List<Item> items = new ArrayList<>();
+
+        if (!"pom".equals(project.getPackaging())) {
+            // ----------------------------------------------------------------------------
+            // Project artifact
+            // ----------------------------------------------------------------------------
+
+            Artifact artifact = project.getArtifact();
+
+            File file = artifact.getFile();
+
+            if (file != null && file.isFile()) {
+                items.add(new Item(file, artifact.getArtifactHandler().getExtension()));
+            } else if (project.getAttachedArtifacts().isEmpty()) {
+                throw new MojoFailureException("The project artifact has not been assembled yet. "
+                        + "Please do not invoke this goal before the lifecycle phase \"package\".");
+            } else {
+                log.debug("Main artifact not assembled, skipping signature generation");
+            }
+        }
+
+        // ----------------------------------------------------------------------------
+        // POM
+        // ----------------------------------------------------------------------------
+
+        File pomToSign =
+                new File(project.getBuild().getDirectory(), project.getBuild().getFinalName() + ".pom");
+
+        try {
+            FileUtils.copyFile(project.getFile(), pomToSign);

Review Comment:
   no idea, this is not the purpose of this refactoring :)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-gpg-plugin] michael-o commented on a diff in pull request #45: extract FilesCollector

Posted by "michael-o (via GitHub)" <gi...@apache.org>.
michael-o commented on code in PR #45:
URL: https://github.com/apache/maven-gpg-plugin/pull/45#discussion_r1173410839


##########
src/main/java/org/apache/maven/plugins/gpg/FilesCollector.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * 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.plugins.gpg;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.SelectorUtils;
+
+/**
+ * Collects project artifact, the POM, and attached artifacts to be signed.
+ *
+ * @since 3.1.0
+ */
+public class FilesCollector {
+    private final MavenProject project;
+
+    private static final String DEFAULT_EXCLUDES[] =
+            new String[] {"**/*.md5", "**/*.sha1", "**/*.sha256", "**/*.sha512", "**/*.asc"};
+
+    private final String[] excludes;
+
+    private final Log log;
+
+    public FilesCollector(MavenProject project, String[] excludes, Log log) {
+        this.project = project;
+        this.log = log;
+        if (excludes == null || excludes.length == 0) {
+            this.excludes = DEFAULT_EXCLUDES;
+            return;
+        }
+        String newExcludes[] = new String[excludes.length];
+        for (int i = 0; i < excludes.length; i++) {
+            String pattern;
+            pattern = excludes[i].trim().replace('/', File.separatorChar).replace('\\', File.separatorChar);
+            if (pattern.endsWith(File.separator)) {
+                pattern += "**";
+            }
+            newExcludes[i] = pattern;
+        }
+        this.excludes = newExcludes;
+    }
+
+    public List<Item> collect() throws MojoExecutionException, MojoFailureException {
+        List<Item> items = new ArrayList<>();
+
+        if (!"pom".equals(project.getPackaging())) {
+            // ----------------------------------------------------------------------------
+            // Project artifact
+            // ----------------------------------------------------------------------------
+
+            Artifact artifact = project.getArtifact();
+
+            File file = artifact.getFile();
+
+            if (file != null && file.isFile()) {
+                items.add(new Item(file, artifact.getArtifactHandler().getExtension()));
+            } else if (project.getAttachedArtifacts().isEmpty()) {
+                throw new MojoFailureException("The project artifact has not been assembled yet. "

Review Comment:
   Yes, correct. My bad.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-gpg-plugin] michael-o commented on a diff in pull request #45: extract FilesCollector

Posted by "michael-o (via GitHub)" <gi...@apache.org>.
michael-o commented on code in PR #45:
URL: https://github.com/apache/maven-gpg-plugin/pull/45#discussion_r1173410245


##########
src/main/java/org/apache/maven/plugins/gpg/FilesCollector.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * 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.plugins.gpg;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.SelectorUtils;
+
+/**
+ * Collects project artifact, the POM, and attached artifacts to be signed.
+ *
+ * @since 3.1.0
+ */
+public class FilesCollector {
+    private final MavenProject project;
+
+    private static final String DEFAULT_EXCLUDES[] =
+            new String[] {"**/*.md5", "**/*.sha1", "**/*.sha256", "**/*.sha512", "**/*.asc"};

Review Comment:
   Agreed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org