summaryrefslogtreecommitdiffstats
path: root/bundle-plugin/src/main/scala/com/yahoo/container/plugin/mojo/Artifacts.scala
blob: 8e9f06cdde6574825f21dabb14c05a3fc5cb7d4d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright 2017 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 scala.collection.JavaConversions._
import org.apache.maven.project.MavenProject
import org.apache.maven.artifact.Artifact


/**
 * @author tonytv
 */
object Artifacts {
  def getArtifacts(project : MavenProject) = {
    type artifactSet = java.util.Set[Artifact]
    val artifacts = project.getArtifacts.asInstanceOf[artifactSet].groupBy(_.getScope)

    def isTypeJar(artifact : Artifact) = artifact.getType == "jar"
    def getByScope(scope: String) =
      artifacts.getOrElse(scope, Iterable.empty).partition(isTypeJar)


    val (jarArtifactsToInclude, nonJarArtifactsToInclude) = getByScope(Artifact.SCOPE_COMPILE)
    val (jarArtifactsProvided,   nonJarArtifactsProvided)  = getByScope(Artifact.SCOPE_PROVIDED)

    (jarArtifactsToInclude, jarArtifactsProvided, nonJarArtifactsToInclude ++ nonJarArtifactsProvided)
  }

  def getArtifactsToInclude(project: MavenProject) = getArtifacts(project)._1
}