Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Commit

Permalink
Merge branch 'develop' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-archano authored Oct 24, 2019
2 parents 4d92311 + db201b7 commit 26d042c
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 35 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ subprojects {
}

wrapper {
gradleVersion = '4.10.2'
gradleVersion = '5.6.3'
distributionType = Wrapper.DistributionType.ALL
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.gradle.jvmargs=-Xmx3g -XX:MaxMetaspaceSize=512m
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
22 changes: 19 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/usr/bin/env sh

#
# Copyright 2015 the original author or authors.
#
# 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
#
# https://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.
#

##############################################################################
##
## Gradle start up script for UN*X
Expand Down Expand Up @@ -28,7 +44,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
Expand Down Expand Up @@ -109,8 +125,8 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
Expand Down
18 changes: 17 additions & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
Expand All @@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.gradle.api.GradleException
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.file.RegularFileProperty

import static com.novoda.staticanalysis.internal.Exceptions.handleException
import static com.novoda.staticanalysis.internal.TasksCompat.createTask
Expand All @@ -18,6 +19,7 @@ class KtlintConfigurator implements Configurator {
private static final String KTLINT_PLUGIN = 'org.jlleitschuh.gradle.ktlint'
private static final String KTLINT_NOT_APPLIED = 'The Ktlint plugin is configured but not applied. Please apply the plugin in your build script.\nFor more information see https://github.com/JLLeitschuh/ktlint-gradle/#how-to-use'
private static final String XML_REPORT_NOT_ENABLED = 'XML report must be enabled. Please make sure to add "CHECKSTYLE" into reports in your Ktlint configuration'
private static final String KTLINT_OUTPUT_FILES_NOT_DEFINED = 'No property for KtLint output files. Please check if the KtLint plugin has changed.'

private static final String LAST_COMPATIBLE_KTLINT_VERSION = '8.0.0'
private static final String MIN_COMPATIBLE_KTLINT_VERSION = '6.2.1' // Do not forget to update ktlint.md
Expand Down Expand Up @@ -134,7 +136,9 @@ Last tested compatible version: $LAST_COMPATIBLE_KTLINT_VERSION
File xmlReportFile = null
File txtReportFile = null
try {
ktlintTask.reportOutputFiles.each { key, fileProp ->
Map<String, RegularFileProperty> outputFiles = getOutputFilesMap(ktlintTask)

outputFiles.each { key, fileProp ->
def file = fileProp.get().asFile
if (file.name.endsWith('.xml')) {
xmlReportFile = file
Expand All @@ -156,4 +160,21 @@ Last tested compatible version: $LAST_COMPATIBLE_KTLINT_VERSION
task.dependsOn ktlintTask
}
}

/**
* This change was made to support version 9.0.0 of the JLLeitschuh/ktlint-gradle plugin which renamed
* `reportOutputFiles` to `allReportsOutputFiles`
*
* https://github.com/JLLeitschuh/ktlint-gradle/blob/master/CHANGELOG.md#900---2019-09-30
*/
private static Map<String, RegularFileProperty> getOutputFilesMap(Task ktlintTask) {

if (ktlintTask.hasProperty("allReportsOutputFiles")) {
return ktlintTask.allReportsOutputFiles
} else if(ktlintTask.hasProperty("reportOutputFiles")) {
return ktlintTask.reportOutputFiles
} else {
throw new GradleException(KTLINT_OUTPUT_FILES_NOT_DEFINED)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,49 @@ class KtlintIntegrationTest {
}
'''

public static final String DEFAULT_CONFIG_V9 = '''
ktlint {
reporters {
reporter "plain"
reporter "checkstyle"
}
includeVariants { it.name == "debug" }
}
'''

@Parameterized.Parameters(name = '{0} with ktlint {1}')
static def rules() {
return [
[TestProjectRule.forKotlinProject(), '6.2.1', 'ktlintMainCheck.txt'],
[TestProjectRule.forAndroidKotlinProject(), '6.2.1', 'ktlintMainCheck.txt'],
[TestProjectRule.forKotlinProject(), '6.3.1', 'ktlintMainCheck.txt'],
[TestProjectRule.forAndroidKotlinProject(), '6.3.1', 'ktlintMainCheck.txt'],
[TestProjectRule.forKotlinProject(), '6.2.1', 'ktlintMainCheck.txt', DEFAULT_CONFIG],
[TestProjectRule.forAndroidKotlinProject(), '6.2.1', 'ktlintMainCheck.txt', DEFAULT_CONFIG],
[TestProjectRule.forKotlinProject(), '6.3.1', 'ktlintMainCheck.txt', DEFAULT_CONFIG],
[TestProjectRule.forAndroidKotlinProject(), '6.3.1', 'ktlintMainCheck.txt', DEFAULT_CONFIG],
// Fails because of Android dependency problem in non-Android project.
// > Could not generate a decorated class for class org.jlleitschuh.gradle.ktlint.KtlintPlugin.
// > com/android/build/gradle/BaseExtension
// [TestProjectRule.forKotlinProject(), '7.0.0', 'ktlintMainSourceSetCheck.txt'],
[TestProjectRule.forAndroidKotlinProject(), '7.0.0', 'ktlintMainSourceSetCheck.txt'],
[TestProjectRule.forKotlinProject(), '7.3.0', 'ktlintMainSourceSetCheck.txt'],
[TestProjectRule.forAndroidKotlinProject(), '7.3.0', 'ktlintMainSourceSetCheck.txt'],
[TestProjectRule.forKotlinProject(), '8.0.0', 'ktlintMainSourceSetCheck.txt'],
[TestProjectRule.forAndroidKotlinProject(), '8.0.0', 'ktlintMainSourceSetCheck.txt'],
// [TestProjectRule.forKotlinProject(), '7.0.0', 'ktlintMainSourceSetCheck.txt', DEFAULT_CONFIG],
[TestProjectRule.forAndroidKotlinProject(), '7.0.0', 'ktlintMainSourceSetCheck.txt', DEFAULT_CONFIG],
[TestProjectRule.forKotlinProject(), '7.3.0', 'ktlintMainSourceSetCheck.txt', DEFAULT_CONFIG],
[TestProjectRule.forAndroidKotlinProject(), '7.3.0', 'ktlintMainSourceSetCheck.txt', DEFAULT_CONFIG],
[TestProjectRule.forKotlinProject(), '8.0.0', 'ktlintMainSourceSetCheck.txt', DEFAULT_CONFIG],
[TestProjectRule.forAndroidKotlinProject(), '8.0.0', 'ktlintMainSourceSetCheck.txt', DEFAULT_CONFIG],
[TestProjectRule.forKotlinProject(), '9.0.0', 'ktlintMainSourceSetCheck.txt', DEFAULT_CONFIG_V9],
[TestProjectRule.forAndroidKotlinProject(), '9.0.0', 'ktlintMainSourceSetCheck.txt', DEFAULT_CONFIG_V9],
]*.toArray()
}

@Rule
public final TestProjectRule projectRule
private final String ktlintVersion
private final String expectedOutputFileName
private final String defaultConfig

KtlintIntegrationTest(TestProjectRule projectRule, String ktlintVersion, String expectedOutputFileName) {
KtlintIntegrationTest(TestProjectRule projectRule, String ktlintVersion, String expectedOutputFileName, String defaultConfig) {
this.projectRule = projectRule
this.ktlintVersion = ktlintVersion
this.expectedOutputFileName = expectedOutputFileName
this.defaultConfig = defaultConfig
}

@Test
Expand All @@ -78,7 +93,7 @@ class KtlintIntegrationTest {
@Test
void shouldFailBuildOnConfigurationWhenKtlintConfiguredButNotApplied() {
def result = projectRule.newProject()
.withToolsConfig(DEFAULT_CONFIG)
.withToolsConfig(defaultConfig)
.buildAndFail('evaluateViolations')

assertThat(result.logs).contains(KTLINT_NOT_APPLIED)
Expand All @@ -87,7 +102,7 @@ class KtlintIntegrationTest {
@Test
void shouldFailBuildWhenKtlintErrorsOverTheThreshold() {
def result = createProjectWith(Fixtures.Ktlint.SOURCES_WITH_ERROR)
.withToolsConfig(DEFAULT_CONFIG)
.withToolsConfig(defaultConfig)
.buildAndFail('evaluateViolations')

assertThat(result.logs).containsLimitExceeded(1, 0)
Expand All @@ -98,7 +113,7 @@ class KtlintIntegrationTest {
@Test
void shouldNotFailWhenErrorsAreWithinThreshold() {
def result = createProjectWith(Fixtures.Ktlint.SOURCES_WITH_ERROR, 1)
.withToolsConfig(DEFAULT_CONFIG)
.withToolsConfig(defaultConfig)
.build('evaluateViolations')

assertThat(result.logs).containsKtlintViolations(1,
Expand All @@ -108,7 +123,7 @@ class KtlintIntegrationTest {
@Test
void shouldNotFailBuildWhenNoErrorsEncounteredAndNoThresholdTrespassed() {
def result = createProjectWith(Fixtures.Ktlint.SOURCES_NO_ERROR, 0)
.withToolsConfig(DEFAULT_CONFIG)
.withToolsConfig(defaultConfig)
.build('evaluateViolations')

assertThat(result.logs).doesNotContainLimitExceeded()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import static com.novoda.test.LogsSubject.assertThat
class LintAndroidVariantIntegrationTest {

@Rule
public final TestProjectRule<TestAndroidProject> projectRule = TestProjectRule.forAndroidProject()
public final TestProjectRule<TestAndroidProject> projectRule = TestProjectRule.forAndroidLintProject()

@Test
void shouldFailBuildWhenLintViolationsOverThreshold() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,13 @@ class LintIntegrationTest {
}

private static TestProject createAndroidProjectWith(File sources, int maxWarnings = 0, int maxErrors = 0) {
def testProject = new TestAndroidProject()
return new TestAndroidProject(false)
.withSourceSet('main', sources)
.withPenalty("""{
maxWarnings = ${maxWarnings}
maxErrors = ${maxErrors}
}""")

testProject.withToolsConfig(LINT_CONFIGURATION)
.withToolsConfig(LINT_CONFIGURATION)
}

}
14 changes: 13 additions & 1 deletion plugin/src/test/groovy/com/novoda/test/TestAndroidProject.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ ${formatExtension(project)}
"""
}

private final boolean shouldDisableAndroidLint

private String additionalAndroidConfig = ''

TestAndroidProject() {
TestAndroidProject(boolean shouldDisableAndroidLint) {
super(TEMPLATE)
File localProperties = Fixtures.LOCAL_PROPERTIES
if (localProperties.exists()) {
withFile(localProperties, 'local.properties')
}
this.shouldDisableAndroidLint = shouldDisableAndroidLint
}

private static String formatSourceSets(TestProject project) {
Expand All @@ -67,6 +70,15 @@ ${formatExtension(project)}
.join('\n\t\t')
}

@Override
List<String> defaultArguments() {
defaultAndroidArguments() + super.defaultArguments()
}

private List<String> defaultAndroidArguments() {
shouldDisableAndroidLint ? ['-x', 'lint'] : []
}

TestAndroidProject withAdditionalAndroidConfig(String additionalAndroidConfig) {
this.additionalAndroidConfig = additionalAndroidConfig
return this
Expand Down
2 changes: 2 additions & 0 deletions plugin/src/test/groovy/com/novoda/test/TestProject.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ abstract class TestProject<T extends TestProject> {
}
"""
}
private static final String GRADLE_MEMORY_SETTINGS = 'org.gradle.jvmargs=-Xmx3g -XX:MaxMetaspaceSize=512m'

private final File projectDir
private final Closure<String> template
Expand Down Expand Up @@ -108,6 +109,7 @@ abstract class TestProject<T extends TestProject> {
private GradleRunner newRunner(String... arguments) {
new File(projectDir, 'build.gradle').text = template.call(this)
new File(projectDir, 'settings.gradle').text = SETTINGS_GRADLE_TEMPLATE.call(projectDir.name)
new File(projectDir, 'gradle.properties').text = GRADLE_MEMORY_SETTINGS
List<String> defaultArgs = defaultArguments()
List<String> args = new ArrayList<>(arguments.size() + defaultArgs.size())
args.addAll(defaultArgs)
Expand Down
10 changes: 9 additions & 1 deletion plugin/src/test/groovy/com/novoda/test/TestProjectRule.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ final class TestProjectRule<T extends TestProject> implements TestRule {
}

static TestProjectRule<TestAndroidProject> forAndroidProject() {
new TestProjectRule({ new TestAndroidProject() }, { String name -> "project.android.sourceSets.$name" }, 'Android project')
new TestProjectRule({ new TestAndroidProject(true) }, { String name -> "project.android.sourceSets.$name" }, 'Android project')
}

static TestProjectRule<TestAndroidProject> forAndroidLintProject() {
new TestProjectRule(
{ new TestAndroidProject(false) },
{ String name -> "project.android.sourceSets.$name" },
'Android Lint project'
)
}

static TestProjectRule<TestAndroidKotlinProject> forAndroidKotlinProject() {
Expand Down
3 changes: 1 addition & 2 deletions sample-multi-module/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ buildscript {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.novoda:gradle-static-analysis-plugin:local'
classpath 'io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.0.0-RC14'
classpath 'org.jlleitschuh.gradle:ktlint-gradle:8.0.0'
classpath 'org.jlleitschuh.gradle:ktlint-gradle:9.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
ext.ReporterType = org.jlleitschuh.gradle.ktlint.reporter.ReporterType

apply from: rootProject.file('team-props/tasks.gradle')

Expand Down
4 changes: 3 additions & 1 deletion sample-multi-module/team-props/static-analysis.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ staticAnalysis {
}

ktlint {
reporters = [ReporterType.CHECKSTYLE]
reporters {
reporter "checkstyle"
}

includeVariants { variant -> variant.name.contains('debug') }
}
Expand Down
6 changes: 3 additions & 3 deletions sample/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType

plugins {
id 'io.gitlab.arturbosch.detekt'
id "org.jlleitschuh.gradle.ktlint"
Expand Down Expand Up @@ -66,7 +64,9 @@ staticAnalysis {

ktlint {
android.set(true)
reporters = [ReporterType.CHECKSTYLE]
reporters {
reporter "checkstyle"
}

includeVariants { variant -> variant.name.contains('debug') }
}
Expand Down
2 changes: 1 addition & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.novoda:gradle-static-analysis-plugin:local'
classpath 'io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.0.0-RC14'
classpath 'org.jlleitschuh.gradle:ktlint-gradle:8.0.0'
classpath 'org.jlleitschuh.gradle:ktlint-gradle:9.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down

0 comments on commit 26d042c

Please sign in to comment.