Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ bin/
.settings

.classpath
android-runtime.iml
android-runtime.iml
test-app/build-tools/*.log
16 changes: 12 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,20 @@ task copyFilesToProjectTemeplate {
into "$DIST_FRAMEWORK_PATH"
}
copy {
from "$TEST_APP_PATH/paths.gradle"
into "$DIST_FRAMEWORK_PATH"
from "$TEST_APP_PATH/gradle-helpers/paths.gradle"
into "$DIST_FRAMEWORK_PATH/gradle-helpers"
}
copy {
from "$TEST_APP_PATH/user_properties_reader.gradle"
into "$DIST_FRAMEWORK_PATH"
from "$TEST_APP_PATH/gradle-helpers/user_properties_reader.gradle"
into "$DIST_FRAMEWORK_PATH/gradle-helpers"
}
copy {
from "$TEST_APP_PATH/app/gradle-helpers/CustomExecutionLogger.gradle"
into "$DIST_FRAMEWORK_PATH/app/gradle-helpers"
}
copy {
from "$TEST_APP_PATH/app/gradle-helpers/BuildToolTask.gradle"
into "$DIST_FRAMEWORK_PATH/app/gradle-helpers"
}
copy {
from "$TEST_APP_PATH/gradle"
Expand Down
50 changes: 31 additions & 19 deletions test-app/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.StandardCopyOption
import java.security.MessageDigest
import org.gradle.internal.logging.text.StyledTextOutputFactory
import static org.gradle.internal.logging.text.StyledTextOutput.Style

apply plugin: "com.android.application"
apply from: "gradle-helpers/BuildToolTask.gradle"
apply from: "gradle-helpers/CustomExecutionLogger.gradle"
def outLogger = services.get(StyledTextOutputFactory).create("colouredOutputLogger")

def enableKotlin = (project.hasProperty("useKotlin") && project.useKotlin == "true")

Expand All @@ -39,7 +44,7 @@ if (enableKotlin) {

def onlyX86 = project.hasProperty("onlyX86")
if (onlyX86) {
println "OnlyX86 build triggered."
outLogger.withStyle(Style.Info).println "OnlyX86 build triggered."
}

//common
Expand Down Expand Up @@ -146,15 +151,15 @@ version of the {N} CLI install a previous version of the runtime package - 'tns
def pathToBuildScriptGradle = "$absolutePathToAppResources/Android/buildscript.gradle"
def buildScriptGradle = file(pathToBuildScriptGradle)
if (buildScriptGradle.exists()) {
println "\t + applying user-defined buildscript from ${buildScriptGradle}"
outLogger.withStyle(Style.SuccessHeader).println "\t + applying user-defined buildscript from ${buildScriptGradle}"
apply from: pathToBuildScriptGradle, to: buildscript
}

nativescriptDependencies.each { dep ->
def pathToPluginBuildScriptGradle = "$rootDir/${dep.directory}/$PLATFORMS_ANDROID/buildscript.gradle"
def pluginBuildScriptGradle = file(pathToPluginBuildScriptGradle)
if (pluginBuildScriptGradle.exists()) {
println "\t + applying user-defined buildscript from dependency ${pluginBuildScriptGradle}"
outLogger.withStyle(Style.SuccessHeader).println "\t + applying user-defined buildscript from dependency ${pluginBuildScriptGradle}"
apply from: pathToPluginBuildScriptGradle, to: buildscript
}
}
Expand All @@ -172,7 +177,7 @@ def applyBeforePluginGradleConfiguration = { ->
def pathToBeforePluginGradle = "$appResourcesPath/Android/before-plugins.gradle"
def beforePluginGradle = file(pathToBeforePluginGradle)
if (beforePluginGradle.exists()) {
println "\t + applying user-defined configuration from ${beforePluginGradle}"
outLogger.withStyle(Style.SuccessHeader).println "\t + applying user-defined configuration from ${beforePluginGradle}"
apply from: pathToBeforePluginGradle
}
}
Expand All @@ -182,10 +187,10 @@ def applyAppGradleConfiguration = { ->
def pathToAppGradle = "$appResourcesPath/Android/app.gradle"
def appGradle = file(pathToAppGradle)
if (appGradle.exists()) {
println "\t + applying user-defined configuration from ${appGradle}"
outLogger.withStyle(Style.SuccessHeader).println "\t + applying user-defined configuration from ${appGradle}"
apply from: pathToAppGradle
} else {
println "\t + couldn't load user-defined configuration from ${appGradle}. File doesn't exist."
outLogger.withStyle(Style.Info).println "\t + couldn't load user-defined configuration from ${appGradle}. File doesn't exist."
}
}

Expand All @@ -211,7 +216,7 @@ def getAppIdentifier = { packageJsonMap ->
}

def setAppIdentifier = { ->
println "\t + setting applicationId"
outLogger.withStyle(Style.SuccessHeader).println "\t + setting applicationId"
File packageJsonFile = new File("$USER_PROJECT_ROOT/$PACKAGE_JSON")

if (packageJsonFile.exists()) {
Expand Down Expand Up @@ -339,7 +344,7 @@ dependencies {
androidXMaterialVersion = androidXMaterial
}

println "\t + using android X library androidx.legacy:legacy-support-v4:$androidXLegacyVersion"
outLogger.withStyle(Style.SuccessHeader).println "\t + using android X library androidx.legacy:legacy-support-v4:$androidXLegacyVersion"

implementation "androidx.multidex:multidex:2.0.1"
implementation "androidx.legacy:legacy-support-v4:$androidXLegacyVersion"
Expand Down Expand Up @@ -374,7 +379,7 @@ dependencies {
runtime = "nativescript-regular"
}

println "\t + adding nativescript runtime package dependency: $runtime"
outLogger.withStyle(Style.SuccessHeader).println "\t + adding nativescript runtime package dependency: $runtime"
project.dependencies.add("implementation", [name: runtime, ext: "aar"])
} else {
implementation project(':runtime')
Expand All @@ -397,14 +402,14 @@ task addDependenciesFromNativeScriptPlugins {
aarFiles.each { aarFile ->
def length = aarFile.name.length() - 4
def fileName = aarFile.name[0..<length]
println "\t + adding aar plugin dependency: " + aarFile.getAbsolutePath()
outLogger.withStyle(Style.SuccessHeader).println "\t + adding aar plugin dependency: " + aarFile.getAbsolutePath()
project.dependencies.add("implementation", [name: fileName, ext: "aar"])
}

def jarFiles = fileTree(dir: file("$rootDir/${dep.directory}/$PLATFORMS_ANDROID"), include: ["**/*.jar"])
jarFiles.each { jarFile ->
def jarFileAbsolutePath = jarFile.getAbsolutePath()
println "\t + adding jar plugin dependency: $jarFileAbsolutePath"
outLogger.withStyle(Style.SuccessHeader).println "\t + adding jar plugin dependency: $jarFileAbsolutePath"
pluginsJarLibraries.add(jarFile.getAbsolutePath())
}

Expand All @@ -420,14 +425,14 @@ task addDependenciesFromAppResourcesLibraries {
aarFiles.each { aarFile ->
def length = aarFile.name.length() - 4
def fileName = aarFile.name[0..<length]
println "\t + adding aar library dependency: " + aarFile.getAbsolutePath()
outLogger.withStyle(Style.SuccessHeader).println "\t + adding aar library dependency: " + aarFile.getAbsolutePath()
project.dependencies.add("implementation", [name: fileName, ext: "aar"])
}

def jarFiles = fileTree(dir: appResourcesLibraries, include: ["**/*.jar"])
jarFiles.each { jarFile ->
def jarFileAbsolutePath = jarFile.getAbsolutePath()
println "\t + adding jar plugin dependency: $jarFileAbsolutePath"
outLogger.withStyle(Style.SuccessHeader).println "\t + adding jar plugin dependency: $jarFileAbsolutePath"
pluginsJarLibraries.add(jarFile.getAbsolutePath())
}

Expand Down Expand Up @@ -464,7 +469,7 @@ tasks.whenTaskAdded({ org.gradle.api.DefaultTask currentTask ->
///////////////////////////// EXECUTUION PHASE /////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////

task runSbg(type: JavaExec) {
task runSbg(type: BuildToolTask) {
dependsOn "collectAllJars"
if (!findProject(':static-binding-generator').is(null)) {
dependsOn ':static-binding-generator:jar'
Expand All @@ -484,6 +489,8 @@ task runSbg(type: JavaExec) {
paramz.add("-show-deprecation-warnings")
}

setOutputs outLogger

args paramz

doFirst {
Expand Down Expand Up @@ -576,7 +583,7 @@ afterEvaluate { project ->
}
}
} else {
println "WARNING: Folder ${jarDir.path} does not exists, the dependent project's classes won't be included in the metadata"
outLogger.withStyle(Style.Info).println "WARNING: Folder ${jarDir.path} does not exists, the dependent project's classes won't be included in the metadata"
}
}
}
Expand Down Expand Up @@ -695,7 +702,7 @@ task collectAllJars {
}
}

task buildMetadata(type: JavaExec) {
task buildMetadata(type: BuildToolTask) {
if (!findProject(':android-metadata-generator').is(null)) {
dependsOn ':android-metadata-generator:jar'
}
Expand Down Expand Up @@ -749,11 +756,13 @@ task buildMetadata(type: JavaExec) {
workingDir "$BUILD_TOOLS_PATH"
main "-jar"

setOutputs outLogger

args "android-metadata-generator.jar"
}
}

task generateTypescriptDefinitions(type: JavaExec) {
task generateTypescriptDefinitions(type: BuildToolTask) {
if (!findProject(':dts-generator').is(null)) {
dependsOn ':dts-generator:jar'
}
Expand Down Expand Up @@ -784,7 +793,10 @@ task generateTypescriptDefinitions(type: JavaExec) {
new File("$TYPINGS_PATH").mkdirs()

logger.info("Task generateTypescriptDefinitions: Call dts-generator.jar with arguments: " + paramz.toString().replaceAll(',', ''))
println "Task generateTypescriptDefinitions: Call dts-generator.jar with arguments: " + paramz.toString().replaceAll(',', '')
outLogger.withStyle(Style.SuccessHeader).println "Task generateTypescriptDefinitions: Call dts-generator.jar with arguments: " + paramz.toString().replaceAll(',', '')

setOutputs outLogger

args paramz.toArray()
}
}
Expand All @@ -807,7 +819,7 @@ static def shouldIncludeDirForTypings(path, includeDirs) {

task copyTypings {
doLast {
println "Copied generated typings to application root level. Make sure to import android.d.ts in reference.d.ts"
outLogger.withStyle(Style.Info).println "Copied generated typings to application root level. Make sure to import android.d.ts in reference.d.ts"

copy {
from "$TYPINGS_PATH"
Expand Down
50 changes: 50 additions & 0 deletions test-app/app/gradle-helpers/BuildToolTask.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import static org.gradle.internal.logging.text.StyledTextOutput.Style

class BuildToolTask extends JavaExec {
void setOutputs(def logger) {
def logFile = new File("$workingDir/${name}.log")
if(logFile.exists()) {
logFile.delete()
}
standardOutput new FileOutputStream(logFile)
errorOutput new FailureOutputStream(logger, logFile)
}
}

class FailureOutputStream extends OutputStream {
private logger
private File logFile
private currentLine = ""
private firstWrite = true
FailureOutputStream(inLogger, inLogFile) {
logger = inLogger
logFile = inLogFile
}

@Override
void write(int i) throws IOException {
if(firstWrite) {
println ""
firstWrite = false
}
currentLine += String.valueOf((char) i)
}

@Override
void flush() {
if(currentLine?.trim()) {
logger.withStyle(Style.Failure).println currentLine.trim()
currentLine = ""
}
}

@Override
void close() {
if(!firstWrite && logFile.exists()) {
logger.withStyle(Style.Info).println "Detailed log here: ${logFile.getAbsolutePath()}\n"
}
super.close()
}
}

ext.BuildToolTask = BuildToolTask
52 changes: 52 additions & 0 deletions test-app/app/gradle-helpers/CustomExecutionLogger.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import org.gradle.internal.logging.text.StyledTextOutputFactory

import static org.gradle.internal.logging.text.StyledTextOutput.Style
def outLogger = services.get(StyledTextOutputFactory).create("colouredOutputLogger")

class CustomExecutionLogger extends BuildAdapter implements TaskExecutionListener {
private logger
private failedTask

CustomExecutionLogger(passedLogger) {
logger = passedLogger
}

void buildStarted(Gradle gradle) {
failedTask = null
}

void beforeExecute(Task task) {
}

void afterExecute(Task task, TaskState state) {
def failure = state.getFailure()
if(failure) {
failedTask = task
}
}

void buildFinished(BuildResult result) {
def failure = result.getFailure()
if(failure) {
if(failedTask && (failedTask.getClass().getName().contains("BuildToolTask"))) {
// the error from this task is already logged
return
}

println ""
logger.withStyle(Style.FailureHeader).println failure.getMessage()

def causeException = failure.getCause()
while (causeException != null) {
failure = causeException
causeException = failure.getCause()
}
if(failure != causeException) {
logger.withStyle(Style.Failure).println failure.getMessage()
}
println ""
}
}
}

gradle.useLogger(new CustomExecutionLogger(outLogger))
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,39 @@ public class Generator {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
String metadataOutputDir = "bin";
List<String> params = null;

public static void main(String[] args) {
try {
metadataOutputDir = getFileRows(MDG_OUTPUT_DIR).get(0);
} catch (Exception e) {
throw new InvalidParameterException(String.format("You need to pass a file containing a single line: the output dir for the metadata generator1\n", e.getMessage()));
}
try {
params = getFileRows(MDG_JAVA_DEPENDENCIES);
} catch (Exception e) {
throw new InvalidParameterException(String.format("You need to pass a file containing a list of jar/class paths, so metadata can be generated for them!\n", e.getMessage()));
}
String metadataOutputDir;
List<String> params;

TreeNode root = Builder.build(params);
try {
metadataOutputDir = getFileRows(MDG_OUTPUT_DIR).get(0);
} catch (Exception e) {
throw new InvalidParameterException(String.format("You need to pass a file containing a single line: the output dir for the metadata generator1\n", e.getMessage()));
}
try {
params = getFileRows(MDG_JAVA_DEPENDENCIES);
} catch (Exception e) {
throw new InvalidParameterException(String.format("You need to pass a file containing a list of jar/class paths, so metadata can be generated for them!\n", e.getMessage()));
}

FileOutputStream ovs = new FileOutputStream(new File(metadataOutputDir, "treeValueStream.dat"));
FileStreamWriter outValueStream = new FileStreamWriter(ovs);
TreeNode root = Builder.build(params);

FileOutputStream ons = new FileOutputStream(new File(metadataOutputDir, "treeNodeStream.dat"));
FileStreamWriter outNodeStream = new FileStreamWriter(ons);
FileOutputStream ovs = new FileOutputStream(new File(metadataOutputDir, "treeValueStream.dat"));
FileStreamWriter outValueStream = new FileStreamWriter(ovs);

FileOutputStream oss = new FileOutputStream(new File(metadataOutputDir, "treeStringsStream.dat"));
FileStreamWriter outStringsStream = new FileStreamWriter(oss);
FileOutputStream ons = new FileOutputStream(new File(metadataOutputDir, "treeNodeStream.dat"));
FileStreamWriter outNodeStream = new FileStreamWriter(ons);

new Writer(outNodeStream, outValueStream, outStringsStream).writeTree(root);
FileOutputStream oss = new FileOutputStream(new File(metadataOutputDir, "treeStringsStream.dat"));
FileStreamWriter outStringsStream = new FileStreamWriter(oss);

new Writer(outNodeStream, outValueStream, outStringsStream).writeTree(root);
} catch (Throwable ex) {
System.err.println(String.format("Error executing Metadata Generator: %s", ex.getMessage()));
ex.printStackTrace(System.out);
System.exit(1);
}
}

public static List<String> getFileRows(String filename) throws IOException {
Expand Down
Loading