Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DC0E517ADF for ; Tue, 20 Jan 2015 20:04:59 +0000 (UTC) Received: (qmail 28481 invoked by uid 500); 20 Jan 2015 20:04:59 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 28446 invoked by uid 500); 20 Jan 2015 20:04:59 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 28436 invoked by uid 99); 20 Jan 2015 20:04:59 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Jan 2015 20:04:59 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 720C1E03E3; Tue, 20 Jan 2015 20:04:59 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: agrieve@apache.org To: commits@cordova.apache.org Date: Tue, 20 Jan 2015 20:04:59 -0000 Message-Id: <8e38f29fed6848abbf2cbaf46d5f9c22@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] android commit: Move cordova.gradle from project template to CordovaLib Repository: cordova-android Updated Branches: refs/heads/3.7.x 050dd088c -> c3bdebdb8 Move cordova.gradle from project template to CordovaLib Make it easier to share with tests project. Also, one less file in the project template is a good thing. Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/9514a3ed Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/9514a3ed Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/9514a3ed Branch: refs/heads/3.7.x Commit: 9514a3ed94a36d9a313857ae6efe77312040dad2 Parents: 050dd08 Author: Andrew Grieve Authored: Tue Jan 20 11:03:26 2015 -0500 Committer: Andrew Grieve Committed: Tue Jan 20 15:04:46 2015 -0500 ---------------------------------------------------------------------- bin/lib/create.js | 2 +- bin/templates/project/build.gradle | 2 +- bin/templates/project/cordova.gradle | 161 ------------------------------ framework/cordova.gradle | 161 ++++++++++++++++++++++++++++++ 4 files changed, 163 insertions(+), 163 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-android/blob/9514a3ed/bin/lib/create.js ---------------------------------------------------------------------- diff --git a/bin/lib/create.js b/bin/lib/create.js index c0d0c50..5471bb4 100755 --- a/bin/lib/create.js +++ b/bin/lib/create.js @@ -72,6 +72,7 @@ function copyJsAndLibrary(projectPath, shared, projectName) { shell.cp('-f', path.join(ROOT, 'framework', 'AndroidManifest.xml'), nestedCordovaLibPath); shell.cp('-f', path.join(ROOT, 'framework', 'project.properties'), nestedCordovaLibPath); shell.cp('-f', path.join(ROOT, 'framework', 'build.gradle'), nestedCordovaLibPath); + shell.cp('-f', path.join(ROOT, 'framework', 'cordova.gradle'), nestedCordovaLibPath); shell.cp('-r', path.join(ROOT, 'framework', 'src'), nestedCordovaLibPath); // Create an eclipse project file and set the name of it to something unique. // Without this, you can't import multiple CordovaLib projects into the same workspace. @@ -122,7 +123,6 @@ function copyBuildRules(projectPath) { shell.cp('-f', path.join(srcDir, 'custom_rules.xml'), projectPath); shell.cp('-f', path.join(srcDir, 'build.gradle'), projectPath); - shell.cp('-f', path.join(srcDir, 'cordova.gradle'), projectPath); } function copyScripts(projectPath) { http://git-wip-us.apache.org/repos/asf/cordova-android/blob/9514a3ed/bin/templates/project/build.gradle ---------------------------------------------------------------------- diff --git a/bin/templates/project/build.gradle b/bin/templates/project/build.gradle index 52bb3fd..911ffb6 100644 --- a/bin/templates/project/build.gradle +++ b/bin/templates/project/build.gradle @@ -57,7 +57,7 @@ task wrapper(type: Wrapper) { // Configuration properties. Set these via environment variables, build-extras.gradle, or gradle.properties. // Refer to: http://www.gradle.org/docs/current/userguide/tutorial_this_and_that.html ext { - apply from: 'cordova.gradle' + apply from: 'CordovaLib/cordova.gradle' // The value for android.compileSdkVersion. if (!project.hasProperty('cdvCompileSdkVersion')) { cdvCompileSdkVersion = privateHelpers.getProjectTarget('android-19') http://git-wip-us.apache.org/repos/asf/cordova-android/blob/9514a3ed/bin/templates/project/cordova.gradle ---------------------------------------------------------------------- diff --git a/bin/templates/project/cordova.gradle b/bin/templates/project/cordova.gradle deleted file mode 100644 index 8b371bf..0000000 --- a/bin/templates/project/cordova.gradle +++ /dev/null @@ -1,161 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you 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. -*/ - -import java.util.regex.Pattern -import groovy.swing.SwingBuilder - - -String getProjectTarget(String defaultTarget) { - def manifestFile = file("project.properties") - def pattern = Pattern.compile("target\\s*=\\s*(.*)") - def matcher = pattern.matcher(manifestFile.getText()) - if (matcher.find()) { - matcher.group(1) - } else { - defaultTarget - } -} - -String[] getAvailableBuildTools() { - def buildToolsDir = new File(getAndroidSdkDir(), "build-tools") - buildToolsDir.list() - .findAll { it ==~ /[0-9.]+/ } - .sort { a, b -> compareVersions(b, a) } -} - -String findLatestInstalledBuildTools(String minBuildToolsVersion) { - def availableBuildToolsVersions - try { - availableBuildToolsVersions = getAvailableBuildTools() - } catch (e) { - println "An exception occurred while trying to find the Android build tools." - throw e - } - if (availableBuildToolsVersions.length > 0) { - def highestBuildToolsVersion = availableBuildToolsVersions[0] - if (compareVersions(highestBuildToolsVersion, minBuildToolsVersion) < 0) { - throw new RuntimeException( - "No usable Android build tools found. Highest installed version is " + - highestBuildToolsVersion + "; minimum version required is " + - minBuildToolsVersion + ".") - } - highestBuildToolsVersion - } else { - throw new RuntimeException( - "No installed build tools found. Please install the Android build tools version " + - minBuildToolsVersion + " or higher.") - } -} - -// Return the first non-zero result of subtracting version list elements -// pairwise. If they are all identical, return the difference in length of -// the two lists. -int compareVersionList(Collection aParts, Collection bParts) { - def pairs = ([aParts, bParts]).transpose() - pairs.findResult(aParts.size()-bParts.size()) {it[0] - it[1] != 0 ? it[0] - it[1] : null} -} - -// Compare two version strings, such as "19.0.0" and "18.1.1.0". If all matched -// elements are identical, the longer version is the largest by this method. -// Examples: -// "19.0.0" > "19" -// "19.0.1" > "19.0.0" -// "19.1.0" > "19.0.1" -// "19" > "18.999.999" -int compareVersions(String a, String b) { - def aParts = a.tokenize('.').collect {it.toInteger()} - def bParts = b.tokenize('.').collect {it.toInteger()} - compareVersionList(aParts, bParts) -} - -String getAndroidSdkDir() { - def rootDir = project.rootDir - def androidSdkDir = null - String envVar = System.getenv("ANDROID_HOME") - def localProperties = new File(rootDir, 'local.properties') - String systemProperty = System.getProperty("android.home") - if (envVar != null) { - androidSdkDir = envVar - } else if (localProperties.exists()) { - Properties properties = new Properties() - localProperties.withInputStream { instr -> - properties.load(instr) - } - def sdkDirProp = properties.getProperty('sdk.dir') - if (sdkDirProp != null) { - androidSdkDir = sdkDirProp - } else { - sdkDirProp = properties.getProperty('android.dir') - if (sdkDirProp != null) { - androidSdkDir = (new File(rootDir, sdkDirProp)).getAbsolutePath() - } - } - } - if (androidSdkDir == null && systemProperty != null) { - androidSdkDir = systemProperty - } - if (androidSdkDir == null) { - throw new RuntimeException( - "Unable to determine Android SDK directory.") - } - androidSdkDir -} - -def extractIntFromManifest(name) { - def manifestFile = file(android.sourceSets.main.manifest.srcFile) - def pattern = Pattern.compile(name + "=\"(\\d+)\"") - def matcher = pattern.matcher(manifestFile.getText()) - matcher.find() - return Integer.parseInt(matcher.group(1)) -} - -def promptForPassword(msg) { - if (System.console() == null) { - def ret = null - new SwingBuilder().edt { - dialog(modal: true, title: 'Enter password', alwaysOnTop: true, resizable: false, locationRelativeTo: null, pack: true, show: true) { - vbox { - label(text: msg) - def input = passwordField() - button(defaultButton: true, text: 'OK', actionPerformed: { - ret = input.password; - dispose(); - }) - } - } - } - if (!ret) { - throw new GradleException('User canceled build') - } - return new String(ret) - } else { - return System.console().readPassword('\n' + msg); - } -} - -// Properties exported here are visible to all plugins. -ext { - // These helpers are shared, but are not guaranteed to be stable / unchanged. - privateHelpers = {} - privateHelpers.getProjectTarget = { defaultValue -> getProjectTarget(defaultValue) } - privateHelpers.findLatestInstalledBuildTools = { defaultValue -> findLatestInstalledBuildTools(defaultValue) } - privateHelpers.extractIntFromManifest = { name -> extractIntFromManifest(name) } - privateHelpers.promptForPassword = { msg -> promptForPassword(msg) } -} - http://git-wip-us.apache.org/repos/asf/cordova-android/blob/9514a3ed/framework/cordova.gradle ---------------------------------------------------------------------- diff --git a/framework/cordova.gradle b/framework/cordova.gradle new file mode 100644 index 0000000..8b371bf --- /dev/null +++ b/framework/cordova.gradle @@ -0,0 +1,161 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you 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. +*/ + +import java.util.regex.Pattern +import groovy.swing.SwingBuilder + + +String getProjectTarget(String defaultTarget) { + def manifestFile = file("project.properties") + def pattern = Pattern.compile("target\\s*=\\s*(.*)") + def matcher = pattern.matcher(manifestFile.getText()) + if (matcher.find()) { + matcher.group(1) + } else { + defaultTarget + } +} + +String[] getAvailableBuildTools() { + def buildToolsDir = new File(getAndroidSdkDir(), "build-tools") + buildToolsDir.list() + .findAll { it ==~ /[0-9.]+/ } + .sort { a, b -> compareVersions(b, a) } +} + +String findLatestInstalledBuildTools(String minBuildToolsVersion) { + def availableBuildToolsVersions + try { + availableBuildToolsVersions = getAvailableBuildTools() + } catch (e) { + println "An exception occurred while trying to find the Android build tools." + throw e + } + if (availableBuildToolsVersions.length > 0) { + def highestBuildToolsVersion = availableBuildToolsVersions[0] + if (compareVersions(highestBuildToolsVersion, minBuildToolsVersion) < 0) { + throw new RuntimeException( + "No usable Android build tools found. Highest installed version is " + + highestBuildToolsVersion + "; minimum version required is " + + minBuildToolsVersion + ".") + } + highestBuildToolsVersion + } else { + throw new RuntimeException( + "No installed build tools found. Please install the Android build tools version " + + minBuildToolsVersion + " or higher.") + } +} + +// Return the first non-zero result of subtracting version list elements +// pairwise. If they are all identical, return the difference in length of +// the two lists. +int compareVersionList(Collection aParts, Collection bParts) { + def pairs = ([aParts, bParts]).transpose() + pairs.findResult(aParts.size()-bParts.size()) {it[0] - it[1] != 0 ? it[0] - it[1] : null} +} + +// Compare two version strings, such as "19.0.0" and "18.1.1.0". If all matched +// elements are identical, the longer version is the largest by this method. +// Examples: +// "19.0.0" > "19" +// "19.0.1" > "19.0.0" +// "19.1.0" > "19.0.1" +// "19" > "18.999.999" +int compareVersions(String a, String b) { + def aParts = a.tokenize('.').collect {it.toInteger()} + def bParts = b.tokenize('.').collect {it.toInteger()} + compareVersionList(aParts, bParts) +} + +String getAndroidSdkDir() { + def rootDir = project.rootDir + def androidSdkDir = null + String envVar = System.getenv("ANDROID_HOME") + def localProperties = new File(rootDir, 'local.properties') + String systemProperty = System.getProperty("android.home") + if (envVar != null) { + androidSdkDir = envVar + } else if (localProperties.exists()) { + Properties properties = new Properties() + localProperties.withInputStream { instr -> + properties.load(instr) + } + def sdkDirProp = properties.getProperty('sdk.dir') + if (sdkDirProp != null) { + androidSdkDir = sdkDirProp + } else { + sdkDirProp = properties.getProperty('android.dir') + if (sdkDirProp != null) { + androidSdkDir = (new File(rootDir, sdkDirProp)).getAbsolutePath() + } + } + } + if (androidSdkDir == null && systemProperty != null) { + androidSdkDir = systemProperty + } + if (androidSdkDir == null) { + throw new RuntimeException( + "Unable to determine Android SDK directory.") + } + androidSdkDir +} + +def extractIntFromManifest(name) { + def manifestFile = file(android.sourceSets.main.manifest.srcFile) + def pattern = Pattern.compile(name + "=\"(\\d+)\"") + def matcher = pattern.matcher(manifestFile.getText()) + matcher.find() + return Integer.parseInt(matcher.group(1)) +} + +def promptForPassword(msg) { + if (System.console() == null) { + def ret = null + new SwingBuilder().edt { + dialog(modal: true, title: 'Enter password', alwaysOnTop: true, resizable: false, locationRelativeTo: null, pack: true, show: true) { + vbox { + label(text: msg) + def input = passwordField() + button(defaultButton: true, text: 'OK', actionPerformed: { + ret = input.password; + dispose(); + }) + } + } + } + if (!ret) { + throw new GradleException('User canceled build') + } + return new String(ret) + } else { + return System.console().readPassword('\n' + msg); + } +} + +// Properties exported here are visible to all plugins. +ext { + // These helpers are shared, but are not guaranteed to be stable / unchanged. + privateHelpers = {} + privateHelpers.getProjectTarget = { defaultValue -> getProjectTarget(defaultValue) } + privateHelpers.findLatestInstalledBuildTools = { defaultValue -> findLatestInstalledBuildTools(defaultValue) } + privateHelpers.extractIntFromManifest = { name -> extractIntFromManifest(name) } + privateHelpers.promptForPassword = { msg -> promptForPassword(msg) } +} + --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org For additional commands, e-mail: commits-help@cordova.apache.org