-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-22269][BUILD] Run Java linter via SBT for Jenkins #21399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
15e4cf8
b004047
81ed6da
558b1be
54d070d
0cf6de0
1df7285
6e4f6c3
7bb0eb3
294e189
6943ff8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # | ||
| # 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. | ||
| # | ||
|
|
||
| # NOTE: echo "q" is needed because SBT prompts the user for input on encountering a build file | ||
| # with failure (either resolution or compilation); the "q" makes SBT quit. | ||
| ERRORS=$(echo -e "q\n" \ | ||
| | build/sbt \ | ||
| -Pkinesis-asl \ | ||
| -Pmesos \ | ||
| -Pkafka-0-8 \ | ||
| -Pkubernetes \ | ||
| -Pyarn \ | ||
| -Pflume \ | ||
| -Phive \ | ||
| -Phive-thriftserver \ | ||
| checkstyle test:checkstyle \ | ||
| | awk '{if($1~/error/)print}' \ | ||
| ) | ||
|
|
||
| if test ! -z "$ERRORS"; then | ||
| echo -e "Checkstyle failed at following occurrences:\n$ERRORS" | ||
| exit 1 | ||
| else | ||
| echo -e "Checkstyle checks passed." | ||
| fi | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ import sbt._ | |
| import sbt.Classpaths.publishTask | ||
| import sbt.Keys._ | ||
| import sbtunidoc.Plugin.UnidocKeys.unidocGenjavadocVersion | ||
| import com.etsy.sbt.checkstyle.CheckstylePlugin.autoImport._ | ||
| import com.simplytyped.Antlr4Plugin._ | ||
| import com.typesafe.sbt.pom.{PomBuild, SbtPomKeys} | ||
| import com.typesafe.tools.mima.plugin.MimaKeys | ||
|
|
@@ -317,7 +318,7 @@ object SparkBuild extends PomBuild { | |
| /* Enable shared settings on all projects */ | ||
| (allProjects ++ optionallyEnabledProjects ++ assemblyProjects ++ copyJarsProjects ++ Seq(spark, tools)) | ||
| .foreach(enable(sharedSettings ++ DependencyOverrides.settings ++ | ||
| ExcludedDependencies.settings)) | ||
| ExcludedDependencies.settings ++ CheckStyle.settings)) | ||
|
|
||
| /* Enable tests settings for all projects except examples, assembly and tools */ | ||
| (allProjects ++ optionallyEnabledProjects).foreach(enable(TestSettings.settings)) | ||
|
|
@@ -740,6 +741,16 @@ object Unidoc { | |
| ) | ||
| } | ||
|
|
||
| object CheckStyle { | ||
|
||
| lazy val settings = Seq( | ||
| checkstyleSeverityLevel := Some(CheckstyleSeverityLevel.Error), | ||
| javaSource in (Compile, checkstyle) := baseDirectory.value / "src/main/java", | ||
| javaSource in (Test, checkstyle) := baseDirectory.value / "src/test/java", | ||
| checkstyleConfigLocation := CheckstyleConfigLocation.File("dev/checkstyle.xml"), | ||
| checkstyleOutputFile := baseDirectory.value / "target/checkstyle-output.xml" | ||
| ) | ||
| } | ||
|
|
||
| object CopyDependencies { | ||
|
|
||
| val copyDeps = TaskKey[Unit]("copyDeps", "Copies needed dependencies to the build directory.") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,11 @@ | ||
| addSbtPlugin("com.etsy" % "sbt-checkstyle-plugin" % "3.1.1") | ||
|
|
||
| // sbt-checkstyle-plugin uses an old version of checkstyle. Match it to Maven's. | ||
| libraryDependencies += "com.puppycrawl.tools" % "checkstyle" % "8.2" | ||
|
|
||
| // checkstyle uses guava 23.0. | ||
| libraryDependencies += "com.google.guava" % "guava" % "23.0" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a little surprised this is not causing other problems... when I was testing this, it was overriding Spark's own Guava import (which is version 14). But if it works, awesome.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea but it's plugin dependency here. I was a little surprised too because I was stuck here for a while. |
||
|
|
||
| // need to make changes to uptake sbt 1.0 support in "com.eed3si9n" % "sbt-assembly" % "1.14.5" | ||
| addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2") | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really minor, but now you'll be running this when building with maven too. That could be avoided by checking that the build is not using maven; and also changing the maven target from
packagetoverifyso that these checks run.You can add
[build-maven]to the PR title to try it out (or locally withAMPLAB_JENKINS_BUILD_TOOL=maven).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no problem.