Skip to content

Commit

Permalink
Automatically generate the version of the components
Browse files Browse the repository at this point in the history
  • Loading branch information
machaval committed Nov 7, 2019
1 parent 1835c07 commit 8ab8cff
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.mule.weave.v2.parser.ast.variables.NameIdentifier
import org.mule.weave.v2.parser.phase.ModuleLoaderManager
import org.mule.weave.v2.runtime.ScriptingBindings
import org.mule.weave.v2.runtime.utils.AnsiColor.red
import org.mule.weave.v2.version.ComponentVersion

import scala.collection.mutable
import scala.io.Source
Expand All @@ -33,9 +34,9 @@ class DataWeaveCLIRunner {

val DW_DEFAULT_OUTPUT_MIMETYPE_VAR = "DW_DEFAULT_OUTPUT_MIMETYPE"

val DW_CLI_VERSION = "1.0.1"
val DW_CLI_VERSION = ComponentVersion.nativeVersion

val DW_RUNTIME_VERSION = "2.3.0"
val DW_RUNTIME_VERSION = ComponentVersion.weaveVersion

def run(args: Array[String]): Int = {
val scriptToRun = parse(args)
Expand Down
35 changes: 30 additions & 5 deletions native-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sourceSets {
}
}

repositories{
repositories {
mavenLocal()
}

Expand All @@ -44,14 +44,37 @@ task downloadWlang(type: Copy) {
into "$buildDir/wlang"
}

def genDirectory = new File("$project.buildDir/genresource")

task genWlangSource {
def wlangResources = new File("$buildDir/wlang")
def genDirectory = new File("$project.buildDir/genresource")
def outputFile = new File(genDirectory, "org/mule/weave/v2/resources/WeaveResourceLoader.scala")
new ResourceBuilder().run(outputFile, wlangResources);
}

task genVersions {
def componentVersion = new File(genDirectory, "org/mule/weave/v2/version/ComponentVersion.scala")
def parentFile = componentVersion.getParentFile()
if (!parentFile.exists()) {
parentFile.mkdirs()
}
final PrintWriter outputPrinter = new PrintWriter(new FileWriter(componentVersion))
def properties = new Properties()
def gradleProperties = new File(project.projectDir, "../gradle.properties")
println(gradleProperties)
properties.load(new FileInputStream(gradleProperties))
outputPrinter.println("package org.mule.weave.v2.version")
outputPrinter.println()
outputPrinter.println("object ComponentVersion {")
def entrySet = properties.entrySet()
for (Map.Entry entry : entrySet) {
outputPrinter.println("\tvar " + entry.getKey() + " = \"" + entry.getValue() + "\"")
}
outputPrinter.println("}")
outputPrinter.close()
}

genWlangSource.dependsOn(genVersions)
genWlangSource.mustRunAfter(downloadWlang)
genWlangSource.dependsOn(downloadWlang)
compileScala.dependsOn(genWlangSource)
Expand All @@ -63,7 +86,7 @@ import org.apache.commons.io.IOUtils

public class ResourceBuilder {

public void run(File outputScalaFile, File... resourceDir ) throws Exception {
public void run(File outputScalaFile, File... resourceDir) throws Exception {
def parentFile = outputScalaFile.getParentFile()
if (!parentFile.exists()) {
parentFile.mkdirs()
Expand Down Expand Up @@ -105,21 +128,23 @@ public class ResourceBuilder {
boolean accept(File pathname) {
return pathname.isDirectory() || pathname.getName().endsWith(".dwl")
}
} );
});
for (File file : files) {
final String resourcePath = basePath.isEmpty() ? file.getName().replace("/", "::") : basePath + "::" + file.getName().replace(".dwl", "");
if (file.isDirectory()) {
generate(resourcePath, file, outputPrinter, resources);
} else {
final String variableName = FilenameUtils.getBaseName(file.getName());
resources.put(resourcePath, variableName);
final List<String> lines = IOUtils.readLines(new FileInputStream(file), "UTF-8");
def stream = new FileInputStream(file)
final List<String> lines = IOUtils.readLines(stream, "UTF-8");
outputPrinter.println(" def " + variableName + " =");
outputPrinter.println(" Array(");
for (String line : lines) {
outputPrinter.println("\"\"\"" + line + "\"\"\", ");
}
outputPrinter.println("\"\").mkString(\"\\n\").stripMargin");
stream.close()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,6 @@ package org.mule.weave.dwnative.utils

import java.io.File

import org.mule.weave.dwnative.CustomWeaveDataFormat
import org.mule.weave.v2.env.StaticServiceProvider
import org.mule.weave.v2.env.WeaveRuntime
import org.mule.weave.v2.model.ServiceRegistration
import org.mule.weave.v2.module.DataFormat
import org.mule.weave.v2.module.csv.CSVDataFormat
import org.mule.weave.v2.module.json.JsonDataFormat
import org.mule.weave.v2.module.multipart.MultiPartDataFormat
import org.mule.weave.v2.module.native.NativeValueProvider
import org.mule.weave.v2.module.octetstream.OctetStreamDataFormat
import org.mule.weave.v2.module.properties.PropertiesDataFormat
import org.mule.weave.v2.module.textplain.TextPlainDataFormat
import org.mule.weave.v2.module.xml.XmlDataFormat
import org.mule.weave.v2.parser.phase.ModuleLoaderManager
import org.mule.weave.v2.runtime.core.SystemNativeValueProvider
import org.mule.weave.v2.runtime.core.functions.ReadFunctionProtocolHandler
import org.mule.weave.v2.runtime.core.functions.UrlProtocolHandler

object DataWeaveUtils {

def getDWHome(): File = {
Expand Down Expand Up @@ -68,25 +50,6 @@ object DataWeaveUtils {
new File(getDWHome(), "libs")
}
}

def setupServices(moduleLoaderManager: ModuleLoaderManager): Unit = {
val services: Map[Class[_], Seq[_]] = Map(
classOf[NativeValueProvider] -> Seq(new SystemNativeValueProvider()), //Native Functions
classOf[DataFormat[_, _]] -> Seq(
new CSVDataFormat,
new JsonDataFormat,
new XmlDataFormat,
new CustomWeaveDataFormat(moduleLoaderManager),
new TextPlainDataFormat,
new OctetStreamDataFormat,
new PropertiesDataFormat,
new MultiPartDataFormat),
classOf[ServiceRegistration[_]] -> Seq(),
classOf[ReadFunctionProtocolHandler] -> Seq(new UrlProtocolHandler())
)
//Configure static provider
WeaveRuntime.setServiceProvider(new StaticServiceProvider(services))
}
}

object WeaveProperties {
Expand Down

0 comments on commit 8ab8cff

Please sign in to comment.