// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.plugin.mojo;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.project.MavenProject;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author Tony Vaagenes
 * @author ollivir
 */
public class Artifacts {
    public static class ArtifactSet {
        private final List<Artifact> jarArtifactsToInclude;
        private final List<Artifact> jarArtifactsProvided;
        private final List<Artifact> nonJarArtifacts;

        private ArtifactSet(List<Artifact> jarArtifactsToInclude, List<Artifact> jarArtifactsProvided, List<Artifact> nonJarArtifacts) {
            this.jarArtifactsToInclude = jarArtifactsToInclude;
            this.jarArtifactsProvided = jarArtifactsProvided;
            this.nonJarArtifacts = nonJarArtifacts;
        }

        public List<Artifact> getJarArtifactsToInclude() {
            return jarArtifactsToInclude;
        }

        public List<Artifact> getJarArtifactsProvided() {
            return jarArtifactsProvided;
        }

        public List<Artifact> getNonJarArtifacts() {
            return nonJarArtifacts;
        }
    }

    public static ArtifactSet getArtifacts(MavenProject project) {

        List<Artifact> jarArtifactsToInclude = new ArrayList<>();
        List<Artifact> jarArtifactsProvided = new ArrayList<>();
        List<Artifact> nonJarArtifactsToInclude = new ArrayList<>();
        List<Artifact> nonJarArtifactsProvided = new ArrayList<>();

        for (Artifact artifact : project.getArtifacts()) {
            if ("jar".equals(artifact.getType())) {
                if (Artifact.SCOPE_COMPILE.equals(artifact.getScope())) {
                    jarArtifactsToInclude.add(artifact);
                } else if (Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) {
                    jarArtifactsProvided.add(artifact);
                }
            } else {
                if (Artifact.SCOPE_COMPILE.equals(artifact.getScope())) {
                    nonJarArtifactsToInclude.add(artifact);
                } else if (Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) {
                    nonJarArtifactsProvided.add(artifact);
                }
            }
        }
        nonJarArtifactsToInclude.addAll(nonJarArtifactsProvided);
        return new ArtifactSet(jarArtifactsToInclude, jarArtifactsProvided, nonJarArtifactsToInclude);
    }

    public static Collection<Artifact> getArtifactsToInclude(MavenProject project) {
        return getArtifacts(project).getJarArtifactsToInclude();
    }
}

@@ -377,23 +377,16 @@
 vir%0A */%0A
-public 
 class Ar
@@ -395,31 +395,24 @@
 facts %7B%0A    
-public 
 static class
@@ -926,39 +926,32 @@
      %7D%0A%0A        
-public 
 List%3CArtifact%3E g
@@ -1031,39 +1031,32 @@
      %7D%0A%0A        
-public 
 List%3CArtifact%3E g
@@ -1142,23 +1142,16 @@
         
-public 
 List%3CArt
@@ -1233,31 +1233,24 @@
 %0A    %7D%0A%0A    
-public 
 static Artif
@@ -2483,15 +2483,8 @@
     
-public 
 stat

remove unnecessary public modifiers