From 4806cc2ecc05f27bf1c4e595d2910f4382b35391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martynas=20Mickevi=C4=8Dius?= Date: Sun, 17 Jun 2018 19:13:08 +0300 Subject: [PATCH 1/3] Update build definition --- build.sbt | 42 ++++++++------ .../lightbend/sbt/JavaFormatterPlugin.scala | 8 +-- .../sbt/javaformatter/JavaFormatter.scala | 18 +++--- project/Common.scala | 49 ----------------- project/Publish.scala | 52 ------------------ project/headers.sbt | 20 ------- project/plugins.sbt | 26 ++------- project/project/.DS_Store | Bin 6148 -> 0 bytes project/project/build.properties | 1 - project/project/plugins.sbt | 17 ------ project/project/project/.DS_Store | Bin 6148 -> 0 bytes 11 files changed, 41 insertions(+), 192 deletions(-) delete mode 100644 project/Common.scala delete mode 100644 project/Publish.scala delete mode 100644 project/headers.sbt delete mode 100644 project/project/.DS_Store delete mode 100644 project/project/build.properties delete mode 100644 project/project/plugins.sbt delete mode 100644 project/project/project/.DS_Store diff --git a/build.sbt b/build.sbt index 76d0386..4ff66f3 100644 --- a/build.sbt +++ b/build.sbt @@ -1,34 +1,39 @@ -/* - * Copyright 2016 Lightbend Inc. - * - * 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. - */ +import com.typesafe.sbt.SbtScalariform.ScalariformKeys +import scalariform.formatter.preferences._ lazy val sbtJavaFormatter = project .in(file(".")) .aggregate(plugin) - .enablePlugins(NoPublish) + .settings(skip in publish := true) lazy val plugin = project .in(file("plugin")) .settings( + organization := "com.lightbend.sbt", name := "sbt-java-formatter", sbtPlugin := true, libraryDependencies ++= Seq( "com.google.googlejavaformat" % "google-java-format" % "1.6" - ) + ), + + organizationName := "Lightbend Inc.", + startYear := Some(2015), + description := "Formats Java code in your project.", + licenses += ("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0.html")), + + bintrayRepository := "sbt-plugins", + bintrayOrganization := None, + + scalacOptions ++= Seq("-encoding", "UTF-8", "-target:jvm-1.6", "-unchecked", "-deprecation", "-feature"), + javacOptions ++= Seq("-encoding", "UTF-8", "-source", "1.6", "-target", "1.6"), + + ScalariformKeys.preferences := ScalariformKeys.preferences.value + .setPreference(AlignSingleLineCaseStatements, true) + .setPreference(AlignSingleLineCaseStatements.MaxArrowIndent, 100) + .setPreference(DoubleIndentClassDeclaration, true) + .setPreference(DanglingCloseParenthesis, Preserve) + .setPreference(AlignParameters, true), ) - .settings(BintrayPlugin.bintrayPublishSettings: _*) .settings( ScriptedPlugin.projectSettings, scriptedLaunchOpts := { scriptedLaunchOpts.value ++ @@ -36,3 +41,4 @@ lazy val plugin = project }, scriptedBufferLog := false ) + .enablePlugins(AutomateHeaderPlugin) diff --git a/plugin/src/main/scala/com/lightbend/sbt/JavaFormatterPlugin.scala b/plugin/src/main/scala/com/lightbend/sbt/JavaFormatterPlugin.scala index 8e2c0c1..6ec2c8d 100644 --- a/plugin/src/main/scala/com/lightbend/sbt/JavaFormatterPlugin.scala +++ b/plugin/src/main/scala/com/lightbend/sbt/JavaFormatterPlugin.scala @@ -1,5 +1,5 @@ /* - * Copyright 2016 Lightbend Inc. + * Copyright 2015 Lightbend Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -79,12 +79,10 @@ object JavaFormatterPlugin extends AutoPlugin { tPR, c, streamz) - } - ) + }) def notToBeScopedSettings: Seq[Setting[_]] = List( - includeFilter in format := "*.java" - ) + includeFilter in format := "*.java") } diff --git a/plugin/src/main/scala/com/lightbend/sbt/javaformatter/JavaFormatter.scala b/plugin/src/main/scala/com/lightbend/sbt/javaformatter/JavaFormatter.scala index 9d8a82e..de80339 100644 --- a/plugin/src/main/scala/com/lightbend/sbt/javaformatter/JavaFormatter.scala +++ b/plugin/src/main/scala/com/lightbend/sbt/javaformatter/JavaFormatter.scala @@ -1,5 +1,5 @@ /* - * Copyright 2016 Lightbend Inc. + * Copyright 2015 Lightbend Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,11 +26,11 @@ object JavaFormatter { def apply( sourceDirectories: Seq[File], - includeFilter: FileFilter, - excludeFilter: FileFilter, - ref: ProjectRef, - configuration: Configuration, - streams: TaskStreams): Seq[File] = { + includeFilter: FileFilter, + excludeFilter: FileFilter, + ref: ProjectRef, + configuration: Configuration, + streams: TaskStreams): Seq[File] = { val formatter = new Formatter() @@ -62,9 +62,9 @@ object JavaFormatter { } def handleFiles( - files: Set[File], - cache: File, - logFun: String => Unit, + files: Set[File], + cache: File, + logFun: String => Unit, updateFun: Set[File] => Unit): Set[File] = { def handleUpdate(in: ChangeReport[File], out: ChangeReport[File]) = { diff --git a/project/Common.scala b/project/Common.scala deleted file mode 100644 index f9073d0..0000000 --- a/project/Common.scala +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2016 Lightbend Inc. - * - * 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. - */ - -import sbt._ -import sbt.Keys._ -import de.heikoseeberger.sbtheader.{ HeaderPlugin, AutomateHeaderPlugin } -import com.typesafe.sbt.SbtScalariform.{ scalariformSettings, ScalariformKeys } -import scalariform.formatter.preferences._ - -/** - * Common sbt settings — automatically added to all projects. - */ -object Common extends AutoPlugin { - - override def trigger = allRequirements - - override def requires = plugins.JvmPlugin && HeaderPlugin - - // AutomateHeaderPlugin is not an allRequirements-AutoPlugin, so explicitly add settings here: - override def projectSettings = scalariformSettings ++ AutomateHeaderPlugin.projectSettings ++ Seq( - organization := "com.lightbend.sbt", - scalacOptions ++= Seq("-encoding", "UTF-8", "-target:jvm-1.6", "-unchecked", "-deprecation", "-feature"), - javacOptions ++= Seq("-encoding", "UTF-8", "-source", "1.6", "-target", "1.6"), - - // Scalariform settings - ScalariformKeys.preferences := ScalariformKeys.preferences.value - .setPreference(AlignSingleLineCaseStatements, true) - .setPreference(AlignSingleLineCaseStatements.MaxArrowIndent, 100) - .setPreference(DoubleIndentClassDeclaration, true) - .setPreference(DanglingCloseParenthesis, Preserve) - .setPreference(AlignParameters, true), - - // Header settings - HeaderPlugin.autoImport.headerLicense := Some(HeaderPlugin.autoImport.HeaderLicense.ALv2("2016", "Lightbend Inc.")) - ) -} diff --git a/project/Publish.scala b/project/Publish.scala deleted file mode 100644 index 12f14c1..0000000 --- a/project/Publish.scala +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2016 Lightbend Inc. - * - * 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. - */ - -import sbt._ -import sbt.Keys._ -import bintray.BintrayKeys._ - -/** - * Publish to private bintray repository. - */ -object Publish extends AutoPlugin { - - override def trigger = allRequirements - - override def requires = plugins.JvmPlugin - - override def projectSettings = Seq( - description := "Formats Java code in your project using the Eclipse formatter.", - licenses += ("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0.html")), - publishMavenStyle := false, - bintrayRepository := "sbt-plugins", - bintrayOrganization := None - ) - -} - -/** - * For projects that are not published. - */ -object NoPublish extends AutoPlugin { - - override def requires = plugins.JvmPlugin && Publish - - override def projectSettings = Seq( - publish := (), - publishLocal := () - ) - -} diff --git a/project/headers.sbt b/project/headers.sbt deleted file mode 100644 index 5dce8c4..0000000 --- a/project/headers.sbt +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2016 Lightbend Inc. - * - * 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. - */ - -// This is to add copyright headers to the build files -inConfig(Compile)(compileInputs.in(compile) := compileInputs.in(compile).dependsOn(headerCreate.in(compile)).value) - -headerLicense := Some(HeaderLicense.ALv2("2016", "Lightbend Inc.")) diff --git a/project/plugins.sbt b/project/plugins.sbt index 1c818a6..ebc1135 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,23 +1,7 @@ -/* - * Copyright 2016 Lightbend Inc. - * - * 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. - */ - addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0-M1") -addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.6") -addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.0") -addSbtPlugin("de.heikoseeberger" % "sbt-header" % "3.0.1") -addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.1") +addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.0") +addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.0.0") +addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.4") +addSbtPlugin("com.dwijnand" % "sbt-dynver" % "3.0.0") -libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value \ No newline at end of file +libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value diff --git a/project/project/.DS_Store b/project/project/.DS_Store deleted file mode 100644 index 4f161a655e2ecc0ecebdf6969d9128322ec7cc70..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKJ5EC}5S)cbL`svA(pTUHR+O9|7eFLwP^5?W^snMv94)h-g6NSh6rfpYJ@$IX zmZy087J#ij_7A`kz?|-gPame{`|cCFsfZEjJmY{J-uG|2JG|f(1D?P0 zhof)Fq<|EV0#ZNEIA80CC1}80XPT z5Ss^xy>Luqgl0)4Ce^CNu%t8IDz6ugiAjf5^I>(fRfl46JI`;C4(o{;rGOMTSKv06 zORxVM`i1`goTQZ$kOKco0h_J2>lL3=wRQ41ueFW-NcWsCx*O*~;SlAR80DA?FUR+h blzGkP-0y{BV$c~6I#E9Zu8T|x{I&uoNJtfu diff --git a/project/project/build.properties b/project/project/build.properties deleted file mode 100644 index 94005e5..0000000 --- a/project/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=1.0.0 diff --git a/project/project/plugins.sbt b/project/project/plugins.sbt deleted file mode 100644 index 921f15d..0000000 --- a/project/project/plugins.sbt +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright 2016 Lightbend Inc. - * - * 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. - */ - -addSbtPlugin("de.heikoseeberger" % "sbt-header" % "3.0.1") diff --git a/project/project/project/.DS_Store b/project/project/project/.DS_Store deleted file mode 100644 index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Sun, 17 Jun 2018 19:18:00 +0300 Subject: [PATCH 2/3] Add publish on tag travis configuration --- .travis.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.travis.yml b/.travis.yml index 499a7b4..d44fbc3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,11 +7,19 @@ jobs: - stage: test script: sbt scripted + - stage: publish + script: sbt publish + stages: # runs on master commits and PRs - name: test if: NOT tag =~ ^v + # runs on main repo master commits or version-tagged commits + - name: publish + if: repo = sbt/sbt-java-formatter AND ( ( branch = master AND type = push ) OR tag =~ ^v ) + + before_cache: - find $HOME/.ivy2/ -name "ivydata-*.properties" -print -delete - find $HOME/.sbt -name "*.lock" -print -delete @@ -20,3 +28,10 @@ cache: directories: - $HOME/.ivy2/cache - $HOME/.sbt/boot + +env: + global: + # encrypt with: travis encrypt BINTRAY_USER=... + - secure: "mToe3N5fQj06rPdsgQxRUASQtZLlEHKKB45g+E+9vseJBTqXcoSM9C2KmQB4Xw2G2Nu7aBJrua36Cz+WF7J4SXUlh6IoY4RwjDjvLFzpLM0j4GCZlZAy0g3f5cOQpp87J03ujhleyEcuPNU1eqZUwSgyJyAiRfnG6wylGbgjPA9gy6HivSCBeVTrcAzQnT4iJbUHJQfWv2vrEwoqm+hqy/fEVAaoG+Pe7yBiA33gcg6ovt2mB5nycpkfPVvU2V/aTUv+bNlLVc1GqVkTVgq4t5qPL0J7rduaK6tp6gopGxdDapbxoUdMv7J+jrbg4jWsSSx6UlR6JclQKCCbatKi+nnXcKQnC33PN6dFWjyKTXB7nRUGlPJ16RyJA2NUi9Ip7rgZeVbAKNnShy5aG6XcnKrGRCkdATB1A+whQZ5sCpQ4kQ48swQZSA0QUIhknITKwC91ONsYiXGEkSjXRtz98aXSqcGG6nP4IjgNsHiBmr5i//xDFnYqNxKBV48Vvyv+QdrhBprrmgfe9vTQWdpalu1HZuAnax9JaUfTx8ujJ3sOZAQ+uQplK/kXo5NnyptcVdOoPu2ddFN5gtWbg7jGC/Iza6vGszFtOw2xoPT/BMetgTp5Ncv+ZNYY6jfRIlRX2BMYtH9HZU2fSSxs7YQs5TI5C/yMb/wXKDEcMPwet+Y=" + # encrypt with: travis encrypt BINTRAY_PASS=... + - secure: "dLRZeB2nBuy7b6a6qXjiTeznGyKmH6Mbgi4OoAZMJAEt0WBQTcibjzC/5IBDpqzUVNMovUsfqypJzRhbTvPI70V/XjEUT987mOewK92hKISbSGkZ3wGgrMoskrVHvtro5QPoWqawy5sAGiI0qyyBj0d1m4hRB7pWpSwCLUbJIGcJRTBMGK6XzuKcqfuRwihr0dZFLQJnWc961+UykKvBF98MyMyaVvohRdundHik32J7gTGkPl3WINKk+LnUHjCXYEeZikphrxWbrS4M6PJmOkOpO7K/nariPzWYIifTDmxmF5YWa6DMzFsADlujObWotMwsDBTXh96b9Z+nYW+sG9GSYJIvW9i4dUPlPDDiDhXRdnYqo3adydwHwmmc/W6W6T2MCXXFQDYmFdE3Y4N9PrdrZGloLT0ZhPgLZ1lzEY6VoxuoEuj2uk6K3N/Z2aCUwls/lQhepvbEuWBZhtUP/fB+lBs85DGHl5uTFo2Mx9GDrwtoUA/Hgc3pIF3MSfd5dbulDYl4wKGDOXWhFn+LcTR6B2myZIxbuzvlJ65ABkiFLSv1JadsMp/tPb3xXYs4VdKijsZzOWYboDa0XM8Jp1yRnV3rQ42b0HTcDtyVkuenZ0MWVdi63tgZhN2F2/piWceYlpUQsTAAak4LC/9YJUPMjuaxMJY1yMX/IguBFp4=" From bda7454569eb1446c7789ce3c016798c5ae95a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martynas=20Mickevi=C4=8Dius?= Date: Sun, 17 Jun 2018 19:26:49 +0300 Subject: [PATCH 3/3] Update readme --- README.md | 56 ++++++++++++++++--------------------------------------- 1 file changed, 16 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 8ac85bf..eb66507 100644 --- a/README.md +++ b/README.md @@ -1,59 +1,35 @@ -# sbt-java-formatter +# [sbt-java-formatter][] [![scaladex-badge][]][scaladex] [![travis-badge][]][travis] -[ ![Download](https://api.bintray.com/packages/ktosopl/sbt-plugins/sbt-java-formatter/images/download.svg) ](https://bintray.com/ktosopl/sbt-plugins/sbt-java-formatter/_latestVersion) [![Build Status](https://travis-ci.org/sbt/sbt-java-formatter.svg?branch=master)](https://travis-ci.org/sbt/sbt-java-formatter) +[sbt-java-formatter]: https://github.com/sbt/sbt-java-formatter +[scaladex]: https://index.scala-lang.org/sbt/sbt-java-formatter +[scaladex-badge]: https://index.scala-lang.org/sbt/sbt-java-formatter/latest.svg +[travis]: https://travis-ci.org/sbt/sbt-java-formatter +[travis-badge]: https://travis-ci.org/sbt/sbt-java-formatter.svg?branch=master -An sbt plugin for formating Java code. Ideas from this [blog post](https://ssscripting.wordpress.com/2009/06/10/how-to-use-the-eclipse-code-formatter-from-your-code/) and this [maven plugin](https://github.com/revelc/formatter-maven-plugin). +An sbt plugin for formatting Java code. This plugin began as a combination of ideas from this +[blog post](https://ssscripting.wordpress.com/2009/06/10/how-to-use-the-eclipse-code-formatter-from-your-code/) +and this [maven plugin](https://github.com/revelc/formatter-maven-plugin). + +However now this plugin uses [Google Java Format](https://github.com/google/google-java-format) library. Use `0.3.0`+ for sbt 1.0.0, and `0.2.0` for previous versions of sbt. Usage ----- -1. Add the plugin to `project/plugins.sbt`: - -```scala -addSbtPlugin("com.lightbend.sbt" % "sbt-java-formatter" % JavaFormatterVersion) -``` - -2. Prepare a `formatting-java.xml` using Eclipse or steal someone's settings. - -3. Profit! - -There is one optional step, in case you want to name the file differently, -in which case you can do so via: +Add the plugin to `project/plugins.sbt`: ```scala - javaFormattingSettingsFilename := "my-little-formatting-settings.xml" +addSbtPlugin("com.lightbend.sbt" % "sbt-java-formatter" % "0.3.0") ``` -File search order in multi-module projects ------------------------------------------- -The plugin runs under the assumption that in multi-module projects, the "deeper" projects -may want to specialize their formatting. In other words, the plugin looks up the config -file using the folowing order: - -``` -1. my-example/project/formatting-java.xml -2. my-example/formatting-java.xml -3. project/formatting-java.xml -4. formatting-java.xml -``` - -Always defaulting at the "root" project's `project/formatting-java.xml` (and lastly to `formatting-java.xml`). - Contributing ------------ -Yes, we'll happily accept PRs to improve the plugin. -Please note that your changes should not accidentally cause reformatting of entire codebases (i.e. by changing defaults etc). - -Please note that the plugin is very rough around the edges. It, in its current form was good enough for its initial use case, -and we decided to share it instead of keeping it to ourselfes. - -Maintained by -------------- +Yes, we'll happily accept PRs to improve the plugin, but please note that the plugin is very rough around the edges. -@bantonsson and/or @ktoso, at @lightbend +Take a look at the [contributors graph](https://github.com/sbt/sbt-java-formatter/graphs/contributors) if you want to contact +any of the contributors directly. License -------