diff --git a/README.md b/README.md index b49b456..0ea0acc 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ buildscript { } dependencies { - classpath 'io.michaelrocks:paranoid-gradle-plugin:0.1.3' + classpath 'io.michaelrocks:paranoid-gradle-plugin:0.1.4' } } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index ca78035..9d44b9a 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0155852..34a8c08 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sat Jan 21 21:16:53 MSK 2017 +#Mon Apr 24 20:52:24 MSK 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip diff --git a/gradlew b/gradlew index 27309d9..4453cce 100755 --- a/gradlew +++ b/gradlew @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh ############################################################################## ## @@ -154,11 +154,19 @@ if $cygwin ; then esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save ( ) { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=$(save "$@") -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 832fdb6..f955316 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -49,7 +49,6 @@ goto fail @rem Get command-line arguments, handling Windows variants if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. @@ -60,11 +59,6 @@ set _SKIP=2 if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ :execute @rem Setup the command line diff --git a/processor/src/main/kotlin/io/michaelrocks/paranoid/processor/Generator.kt b/processor/src/main/kotlin/io/michaelrocks/paranoid/processor/Generator.kt index 428d258..753d8d5 100644 --- a/processor/src/main/kotlin/io/michaelrocks/paranoid/processor/Generator.kt +++ b/processor/src/main/kotlin/io/michaelrocks/paranoid/processor/Generator.kt @@ -58,9 +58,15 @@ class Generator(private val stringRegistry: StringRegistry) { logger.error( "Compilation error: {}:{}:{}: {}", it.source.name, it.lineNumber, it.columnNumber, it.getMessage(null)) } + + val message = diagnostics.diagnostics.joinToString(separator = "\n", prefix = "Compilation error:\n") { + "%s:%d:%d: %s".format(it.source.name, it.lineNumber, it.columnNumber, it.getMessage(null)) + } + throw ParanoidException(message) } } catch (exception: Exception) { logger.error("Compilation error", exception) + throw ParanoidException("Compilation error", exception) } } @@ -87,7 +93,7 @@ class Generator(private val stringRegistry: StringRegistry) { appendln() appendln("public class $className {") appendln(" private static final char[] chars = new char[] {") - indexesByChar.keys.joinTo(this, prefix = " ", postfix = "\n") { "'\\u%04x'".format(it.toShort()) } + indexesByChar.keys.joinTo(this, prefix = " ", postfix = "\n") { it.toLiteral() } appendln(" };") appendln(" private static final short[][] indexes = new short[][] {") strings @@ -109,4 +115,13 @@ class Generator(private val stringRegistry: StringRegistry) { appendln("}") } } + + // https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.10.4 + private fun Char.toLiteral(): String { + return when (this) { + '\n' -> "'\\n'" + '\r' -> "'\\r'" + else -> "'\\u%04x'".format(toShort()) + } + } } diff --git a/processor/src/main/kotlin/io/michaelrocks/paranoid/processor/ParanoidException.kt b/processor/src/main/kotlin/io/michaelrocks/paranoid/processor/ParanoidException.kt new file mode 100644 index 0000000..e5b7f0e --- /dev/null +++ b/processor/src/main/kotlin/io/michaelrocks/paranoid/processor/ParanoidException.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2017 Michael Rozumyanskiy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.michaelrocks.paranoid.processor + +class ParanoidException : Exception { + constructor() : super() + constructor(message: String?) : super(message) + constructor(message: String?, cause: Throwable?) : super(message, cause) + constructor(cause: Throwable?) : super(cause) +} diff --git a/sample/src/main/java/io/michaelrocks/paranoid/sample/MainActivity.java b/sample/src/main/java/io/michaelrocks/paranoid/sample/MainActivity.java index c41b09a..30424b1 100644 --- a/sample/src/main/java/io/michaelrocks/paranoid/sample/MainActivity.java +++ b/sample/src/main/java/io/michaelrocks/paranoid/sample/MainActivity.java @@ -23,8 +23,8 @@ @Obfuscate public class MainActivity extends AppCompatActivity { - private static final String QUESTION = "Q: %s"; - private static final String ANSWER = "A: %s"; + private static final String QUESTION = "Q:\r\n%s"; + private static final String ANSWER = "A:\r\n%s"; @Override protected void onCreate(final Bundle savedInstanceState) { diff --git a/version.properties b/version.properties index e043263..1ffd5d1 100644 --- a/version.properties +++ b/version.properties @@ -1,6 +1,6 @@ version.major=0 version.minor=1 -version.patch=3 +version.patch=4 version.snapshot=false version.dryRun=false