
package info.freelibrary.maven;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.attribute.PosixFilePermission;
import java.util.Set;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import info.freelibrary.util.FileUtils;

@Mojo(name = "set-file-perms")
public class FilePermissionsMojo extends AbstractMojo {

    private static final Logger LOGGER = LoggerFactory.getLogger(FilePermissionsMojo.class);

    /**
     * The Maven project directory.
     */
    @Parameter(defaultValue = "${project}")
    protected MavenProject myProject;

    /**
     * The permissions to set.
     */
    @Parameter(alias = "perms")
    private int myPerms;

    /**
     * The file or directory to set permissions.
     */
    @Parameter(alias = "file")
    private File myFile;

    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {
        final Set<PosixFilePermission> perms = FileUtils.convertToPermissionsSet(myPerms);

        try {
            Files.setPosixFilePermissions(myFile.toPath(), perms);
        } catch (final IOException details) {
            throw new MojoExecutionException(details.getMessage(), details);
        }
    }

}

@@ -152,24 +152,74 @@
 Permission;%0A
+import java.util.Iterator;%0Aimport java.util.List;%0A
 import java.
@@ -228,16 +228,16 @@
 il.Set;%0A
-
 %0Aimport 
@@ -536,65 +536,8 @@
 ect;
-%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Aim
@@ -667,102 +667,8 @@
  %7B%0A%0A
-    private static final Logger LOGGER = LoggerFactory.getLogger(FilePermissionsMojo.class);%0A%0A
     
@@ -940,16 +940,25 @@
 rectory 
+on which 
 to set p
@@ -1034,16 +1034,166 @@
 yFile;%0A%0A
+    /**%0A     * A list of files or directories on which to set permissions.%0A     */%0A    @Parameter(alias = %22files%22)%0A    private List%3CString%3E myFiles;%0A%0A
     @Ove
@@ -1384,16 +1384,54 @@
   try %7B%0A
+            if (myFile != null) %7B%0A    
         
@@ -1485,24 +1485,308 @@
 (), perms);%0A
+            %7D else if (myFiles != null) %7B%0A                final Iterator%3CString%3E iterator = myFiles.iterator();%0A%0A                while (iterator.hasNext()) %7B%0A                    Files.setPosixFilePermissions(new File(iterator.next()).toPath(), perms);%0A                %7D%0A            %7D%0A
         %7D ca

Add option to process more than one file/dir with FilePermissionsMojo