Skip to content

Commit

Permalink
Add back dependency management
Browse files Browse the repository at this point in the history
  • Loading branch information
machaval committed Nov 25, 2021
1 parent 2bb2476 commit dda436f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
2 changes: 1 addition & 1 deletion native-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies {
compile group: 'org.graalvm.sdk', name: 'graal-sdk', version: '1.0.0-rc12'
compile group: 'org.mule.weave', name: 'core-modules', version: weaveVersion
compile group: 'org.mule.weave', name: 'yaml-module', version: weaveVersion
// compile group: 'org.mule.weave', name: 'dependency-manager', version: weaveVersion
compile group: 'org.mule.weave', name: 'dependency-manager', version: weaveVersion
// compile(group: 'org.mule.weave', name: 'raml-module', version: ioVersion){
// exclude group: 'org.slf4j'
// exclude group: 'org.topbraid.shacl'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package org.mule.weave.dwnative
import io.netty.util.internal.PlatformDependent
import org.mule.weave.dwnative.cli.Console
import org.mule.weave.dwnative.initializer.NativeSystemModuleComponents
import org.mule.weave.v2.deps.Artifact
import org.mule.weave.v2.deps.ResourceDependencyAnnotationProcessor
import org.mule.weave.v2.exception.InvalidLocationException
import org.mule.weave.v2.interpreted.CustomRuntimeModuleNodeCompiler
import org.mule.weave.v2.interpreted.RuntimeModuleNodeCompiler
Expand Down Expand Up @@ -45,14 +47,34 @@ import java.io.OutputStream
import java.io.PrintWriter
import java.io.StringWriter
import java.nio.charset.StandardCharsets
import java.util.concurrent.ExecutorService
import scala.concurrent.Await
import scala.concurrent.Future
import scala.concurrent.duration.Duration

class NativeRuntime(libDir: File, path: Array[File], console: Console) {
class NativeRuntime(resourcesCacheDir: File, executor: ExecutorService, libDir: File, path: Array[File], console: Console) {

private val pathBasedResourceResolver: PathBasedResourceResolver = PathBasedResourceResolver(path ++ Option(libDir.listFiles()).getOrElse(new Array[File](0)))


private val resourceDependencyAnnotationProcessor = ResourceDependencyAnnotationProcessor(
new File(resourcesCacheDir, "resources"),
(id: String, kind: String, artifact: Future[Seq[Artifact]]) => {
pathBasedResourceResolver.addContent(new LazyContentResolver(() => {
new CompositeContentResolver(Await.result(artifact, Duration.Inf)
.map((artifact) => {
ContentResolver(artifact.file)
}))
})
)
}, executor
)

private val annotationProcessors: Seq[(String, AnnotationProcessor)] = Seq(
(ResourceDependencyAnnotationProcessor.ANNOTATION_NAME.name, resourceDependencyAnnotationProcessor)
)
private val weaveScriptingEngine: DataWeaveScriptingEngine = {
setupEnv()
val annotationProcessors: Seq[(String, AnnotationProcessor)] = Seq()
DataWeaveScriptingEngine(new NativeModuleComponentFactory(() => pathBasedResourceResolver, systemFirst = true), ParserConfiguration(parsingAnnotationProcessors = annotationProcessors))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.mule.weave.dwnative.cli.Console
import org.mule.weave.dwnative.cli.FileWatcher
import org.mule.weave.dwnative.utils.DataWeaveUtils
import org.mule.weave.dwnative.utils.DataWeaveUtils._
import org.mule.weave.v2.io.FileHelper.deleteDirectory
import org.mule.weave.v2.model.EvaluationContext
import org.mule.weave.v2.model.values.StringValue
import org.mule.weave.v2.module.DataFormatManager
Expand All @@ -19,6 +20,7 @@ import java.io.FileOutputStream
import java.io.OutputStream
import java.io.PrintWriter
import java.io.StringWriter
import java.util.concurrent.Executors
import scala.util.Try

class RunWeaveCommand(config: WeaveRunnerConfig, console: Console) extends WeaveCommand {
Expand All @@ -32,8 +34,12 @@ class RunWeaveCommand(config: WeaveRunnerConfig, console: Console) extends Weave

def exec(): Int = {
val path: Array[File] = config.path.map(new File(_))
val nativeRuntime: NativeRuntime = new NativeRuntime(weaveUtils.getLibPathHome(), path, console)

val cacheDirectory: File = weaveUtils.getCacheHome()
if (config.cleanCache) {
deleteDirectory(cacheDirectory)
cacheDirectory.mkdirs()
}
val nativeRuntime: NativeRuntime = new NativeRuntime(cacheDirectory, Executors.newCachedThreadPool(), weaveUtils.getLibPathHome(), path, console)
if (config.watch) {
console.clear()
val fileWatcher = FileWatcher(config.filesToWatch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ object DataWeaveUtils {
class DataWeaveUtils(console: Console) {


def getCacheHome(): File = {
val weavehome = console.envVar("DW_CACHE_PATH")
if (weavehome.nonEmpty) {
val home = new File(weavehome.get)
if (!home.exists()) {
console.error(s" Weave Cache Home Directory `${weavehome}` declared on environment variable `DW_CACHE_PATH` does not exists.")
}
home
} else {
new File(getDWHome(), "cache")
}
}

/**
* Returns the DW home directory if exists it can be overwritten with env variable DW_HOME
*
Expand Down

0 comments on commit dda436f

Please sign in to comment.