Skip to content

Commit

Permalink
Merge pull request #24 from 2m/wip-auto-release-2m
Browse files Browse the repository at this point in the history
Update readme and prepare for release by Travis
  • Loading branch information
2m authored Jun 21, 2018
2 parents 9a9b464 + bda7454 commit aeec738
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 232 deletions.
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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="
56 changes: 16 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
-------
Expand Down
42 changes: 24 additions & 18 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
/*
* 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 ++
Seq("-Xmx1024M", "-Dplugin.version=" + version.value)
},
scriptedBufferLog := false
)
.enablePlugins(AutomateHeaderPlugin)
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -79,12 +79,10 @@ object JavaFormatterPlugin extends AutoPlugin {
tPR,
c,
streamz)
}
)
})

def notToBeScopedSettings: Seq[Setting[_]] =
List(
includeFilter in format := "*.java"
)
includeFilter in format := "*.java")

}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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()

Expand Down Expand Up @@ -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]) = {
Expand Down
49 changes: 0 additions & 49 deletions project/Common.scala

This file was deleted.

52 changes: 0 additions & 52 deletions project/Publish.scala

This file was deleted.

20 changes: 0 additions & 20 deletions project/headers.sbt

This file was deleted.

26 changes: 5 additions & 21 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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
libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value
Binary file removed project/project/.DS_Store
Binary file not shown.
1 change: 0 additions & 1 deletion project/project/build.properties

This file was deleted.

Loading

0 comments on commit aeec738

Please sign in to comment.