Skip to content

Commit

Permalink
[Improve] resolve maven artifacts improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
benjobs committed Nov 10, 2023
1 parent a69dc84 commit 8f3fc72
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
Expand Down Expand Up @@ -424,7 +425,17 @@ private void prepareJars(Application app) throws IOException {

// 3). pom dependency
if (!app.getDependencyInfo().mavenArts().isEmpty()) {
jars.addAll(MavenTool.resolveArtifactsAsJava(app.getDependencyInfo().mavenArts()));
Set<File> mavenArts =
MavenTool.resolveArtifactsAsJava(
app.getDependencyInfo()
.mavenArts()
.filter(
x -> {
File jarFile = new File(localUploadDIR, x.jarName());
return !jarFile.exists();
})
.toSet());
jars.addAll(mavenArts);
}

// 4). local uploadDIR to hdfs uploadsDIR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ case class Artifact(
}
}

lazy val jarName = s"$artifactId-$version.jar"

}

object Artifact {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import javax.annotation.{Nonnull, Nullable}

import java.io.File
import java.util
import java.util.{HashSet, Set => JavaSet}

import scala.collection.JavaConversions._
import scala.collection.JavaConverters._
Expand All @@ -56,8 +55,10 @@ object MavenTool extends Logger {

private[this] val excludeArtifact = List(
Artifact.of("org.apache.flink:force-shading:*"),
Artifact.of("org.apache.flink:flink-shaded-force-shading:*"),
Artifact.of("com.google.code.findbugs:jsr305:*"),
Artifact.of("org.apache.logging.log4j:*:*"))
Artifact.of("org.apache.logging.log4j:*:*")
)

private[this] def getRemoteRepos(): List[RemoteRepository] = {
val builder =
Expand Down Expand Up @@ -145,7 +146,7 @@ object MavenTool extends Logger {
}
req.setResourceTransformers(transformer.toList)
// issue: https://github.com/apache/incubator-streampark/issues/2350
req.setFilters(List(new ShadeFilter))
req.setFilters(List(new ShadedFilter))
req.setRelocators(Lists.newArrayList())
req
}
Expand Down Expand Up @@ -178,7 +179,7 @@ object MavenTool extends Logger {
buildFatJar(mainClass, jarLibs ++ artFilePaths, outFatJarPath)
}

def resolveArtifactsAsJava(mavenArtifacts: Set[Artifact]): JavaSet[File] = resolveArtifacts(
def resolveArtifactsAsJava(mavenArtifacts: Set[Artifact]): util.Set[File] = resolveArtifacts(
mavenArtifacts).asJava

/**
Expand Down Expand Up @@ -256,13 +257,13 @@ object MavenTool extends Logger {
(repoSystem, session)
}

class ShadeFilter extends Filter {
private class ShadedFilter extends Filter {
override def canFilter(jar: File): Boolean = true

override def isFiltered(name: String): Boolean = {
if (name.startsWith("META-INF/")) {
if (name.endsWith(".SF") || name.endsWith(".DSA") || name.endsWith(".RSA")) {
logInfo(s"shade ignore file: $name")
logInfo(s"shaded ignore file: $name")
return true
}
}
Expand Down

0 comments on commit 8f3fc72

Please sign in to comment.