Skip to content

Commit

Permalink
Merge branch '0.4-release'
Browse files Browse the repository at this point in the history
  • Loading branch information
sherter committed Oct 13, 2016
2 parents 8e975ec + a2b43f8 commit 828014b
Show file tree
Hide file tree
Showing 36 changed files with 420 additions and 536 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env:
- secure: Oq15JlYDBG3Z0YoxKAsaQlvakzzi5O/MqndVsYBKiro1xgBKiiyTo9pAdOHsyIuVOlzZZhlTyNSdcKDpjzN05HbcRvMo3zd/BigwesO6Rm02lPY4JpR9oxYa3pRHR+hcNBYoErkMNzwr5glRHZISuT8MTTBBKKzt/ltaPNkbvDMlIkNWLLqjTH+csJechsZ+Q8LAZYlRsTkEWjKI8COAnyYBaJJE4dPTa7TYm4eDwNaDWSumoPy8Xh7SwhyKGMSWhDTIMiboGUuF+qSl6RGoSxmHoMmEDuOp4JlVfQ+XsSBHdKFrjkSfW07nTQw2wSiHj4Jv2+g7PhMh6vLbsHWER0oUxLX6SfgZmyzyds501s+WCM7lHjf+CrXbNTg4b7LnI+YQog+LVJW/7HJwmwCOWENriFOQSsKuWG59lTh2fa3AzC22c/RcvJ+Ed/aZ2DBVtj5XavjhTI5C2K0W48ljX9GcKuNgawvMAOBUpmWDHcg7zLviMTVh3fpdTjMJZmfRiwH5Rh+FmsyWPdSrquDrdWQZ25UcP8OBVmlDdFhoyoJhdsVsKXP4DEFs7JoQi+GEy/PBloZgukjGifrnEXbv5CFSs8NozPqMk7170ts7ra7/vN9EP/DSkR/7z6//RINdmhh3KscAU2Ib58jqltK58/KqFYV1/iabeLJKVpkpVjg=
- secure: DRVGtaHlV11hRFbfLVueXiQovFUmcBd92sI7Ot9HLVM8yZY1N7GzN4f9cr/OLm4a0ROUOaOa05j/dqL/7zkoG2rSPfOWcBNDvxEiIarVFh393zs3kbn+Qk8OLVF5jg7WHGV5PM/9gjJAdAnr3/IySweXHinhuoRP8/hZhIx56C3v9mq22xH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ju6mO5qWxYZxq0y28p93uE4QJvxZUV9gNZ8fvDrK6xDylB06SDXQqyTxf+GnOv2bRYTTap2PSBgcFScr/Q7jTB65h/e0KlFle8dOEwDMm9E62r4WfS2E6sY=
- ALL_GRADLE_VERSIONS=2.0,2.1,2.2.1,2.3,2.4,2.5,2.6,2.7,2.8,2.9,2.10,2.11,2.12,2.13,2.14.1,3.0
- ALL_GRADLE_VERSIONS=2.0,2.1,2.2.1,2.3,2.4,2.5,2.6,2.7,2.8,2.9,2.10,2.11,2.12,2.13,2.14.1,3.0,3.1
- PARALLEL_INTEG_TEST_COUNT=4
- GRADLE_OPTS="-Xms128m"
matrix:
Expand Down
8 changes: 4 additions & 4 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
= google-java-format-gradle-plugin
:release-version: 0.3.2
:default-google-java-format-version: 1.0
:snapshot-version: 0.4-SNAPSHOT
:release-version: 0.4
:default-google-java-format-version: 1.1
:snapshot-version: 0.5-SNAPSHOT


A https://github.com/gradle/gradle[Gradle] plugin that utilizes
Expand Down Expand Up @@ -59,7 +59,7 @@ googleJavaFormat {
}
----

* Choose betweeen `'GOOGLE'` (default) and `'AOSP'` style by setting the style option (not supported in conjunction with `toolVersion` `v0.1-alpha`):
* Choose betweeen `'GOOGLE'` (default) and `'AOSP'` style by setting the style option:
+
[source,groovy]
----
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Aug 24 14:40:09 CEST 2016
#Wed Oct 05 14:45:20 CEST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.1-bin.zip
5 changes: 5 additions & 0 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,9 @@ function splitJvmOpts() {
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
6 changes: 0 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ goto fail
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args

:win9xME_args
@rem Slurp the command line arguments.
Expand All @@ -60,11 +59,6 @@ set _SKIP=2
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*
goto execute

:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$

:execute
@rem Setup the command line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,62 +97,4 @@ class OptionsSpec extends AbstractIntegrationSpec {
"googleJavaFormat { options style: 'GOOGLE' }" | "class Foo {\n void bar() {}\n}\n"
"googleJavaFormat { options style: 'AOSP' }" | "class Foo {\n void bar() {}\n}\n"
}

def 'javadoc is formatted with expected javadoc formatter'() {
given:
project.createFile(['build.gradle'], """\
|$applyPlugin
|$defaultRepositories
|googleJavaFormat {
| toolVersion = '$toolVersion'
|}
|""".stripMargin())
def foo = project.createFile(['Foo.java'], '''\
|/**
| * foo
| * bar
| */
|class Foo {}
|'''.stripMargin())

when:
runner.withArguments('goJF').build()

then:
foo.read() == expected

where:
toolVersion | expected
'0.1-alpha' | '/**\n * foo\n * bar\n */\nclass Foo {}\n' // no javadoc formatting
'1.0' | '/**\n * foo bar\n */\nclass Foo {}\n' // EclipseJavadocFormatter
}

def 'imports are sorted if supported by tool version'() {
given:
project.createFile(['build.gradle'], """\
|$applyPlugin
|$defaultRepositories
|googleJavaFormat {
| toolVersion = '$toolVersion'
|}
|""".stripMargin())
def foo = project.createFile(['Foo.java'], '''\
|import second.Foo;
|import first.Bar;
|
|class Foo {}
|'''.stripMargin())

when:
runner.withArguments('goJF').build()

then:
foo.read() == expected

where:
// TODO(sherter): add another row as soon as a version is released that actually supports it
toolVersion | expected
'0.1-alpha' | 'import second.Foo;\nimport first.Bar;\n\nclass Foo {}\n' // no sorting
'1.0' | 'import second.Foo;\nimport first.Bar;\n\nclass Foo {}\n' // no sorting (google-java-format issue #42)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class UpToDateSpec extends AbstractIntegrationSpec {
|$applyPlugin
|$defaultRepositories
|googleJavaFormat {
| toolVersion = '0.1-alpha'
| toolVersion = '1.1'
|}
|""".stripMargin())
result = runner.withArguments(DEFAULT_FORMAT_TASK_NAME).build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.github.sherter.googlejavaformatgradleplugin
import com.github.sherter.googlejavaformatgradleplugin.format.Formatter
import com.github.sherter.googlejavaformatgradleplugin.format.FormatterOption
import com.github.sherter.googlejavaformatgradleplugin.format.Gjf
import com.google.common.collect.ImmutableList
import com.github.sherter.googlejavaformatgradleplugin.format.Style
import com.google.common.collect.ImmutableSet
import com.google.common.collect.ImmutableTable
import groovy.transform.CompileStatic
Expand Down Expand Up @@ -42,12 +42,13 @@ class FormatterFactory {
'google-java-format. This should not be a problem if the task is executed without failures.',
GoogleJavaFormatPlugin.PLUGIN_VERSION, toolVersion)
}
if (toolVersion.equals('0.1-alpha')) {
return Gjf.newFormatter(classLoader, toolVersion, options as FormatterOption[])

if (options.contains(FormatterOption.AOSP_STYLE)) {
return Gjf.newFormatter(classLoader, new com.github.sherter.googlejavaformatgradleplugin.format.Configuration(
toolVersion, Style.AOSP))
} else {
return Gjf.newFormatter(classLoader, toolVersion,
(options as FormatterOption[]) + [FormatterOption.ECLIPSE_JAVADOC_FORMATTER,
FormatterOption.SORT_IMPORTS])
return Gjf.newFormatter(classLoader, new com.github.sherter.googlejavaformatgradleplugin.format.Configuration(
toolVersion, Style.GOOGLE))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import groovy.transform.CompileStatic
@CompileStatic
class GoogleJavaFormatExtension {

static final String DEFAULT_TOOL_VERSION = '1.0'
static final String DEFAULT_TOOL_VERSION = '1.1'

private String toolVersion = null
private Map<String, Object> options = null
Expand Down Expand Up @@ -58,12 +58,6 @@ class GoogleJavaFormatExtension {
if (option == null) {
throw new ConfigurationException("Unsupported value '${entry.value}' for option '${entry.key}'")
}
// if toolVersion is officially supported we can do further validation and
// check if specific options are available for that version
if (getToolVersion() in Gjf.SUPPORTED_VERSIONS && !(getToolVersion() in option.supportedVersions)) {
throw new ConfigurationException("Option '${entry.key}: ${entry.value}' is not supported " +
"by version '${getToolVersion()}' of googel-java-format")
}
}
options.putAll(newOptions)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.github.sherter.googlejavaformatgradleplugin;

import com.google.auto.value.AutoValue;

import java.nio.file.Path;
import java.nio.file.attribute.FileTime;

Expand All @@ -15,8 +14,8 @@ abstract class FileInfo {
/**
* Constructs a new object of type {@link FileInfo} storing the given values.
*
* If {@code path} is not already absolute and normalized, an absolute and normalized path that is
* equivalent to {@code path} is stored instead.
* <p>If {@code path} is not already absolute and normalized, an absolute and normalized path that
* is equivalent to {@code path} is stored instead.
*
* @throws IllegalArgumentException if {@code state} == {@link FileState#UNKNOWN}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;

import javax.inject.Inject;
import javax.inject.Named;
import java.io.IOError;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
Expand All @@ -16,16 +13,16 @@
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.inject.Named;

/**
* Immutable and therefore thread safe.
*/
/** Immutable and therefore thread safe. */
class FileInfoDecoder {
private final Path basePath; // absolute and normalized

/**
* Constructs a new {@link FileInfoDecoder} that resolves serialized path strings against
* {@code basePath}.
* Constructs a new {@link FileInfoDecoder} that resolves serialized path strings against {@code
* basePath}.
*
* @throws IOError if {@code basePath} is not absolute and {@link Path#toAbsolutePath()} fails
*/
Expand All @@ -38,7 +35,7 @@ class FileInfoDecoder {
* Deserialize the given {@code serializedFileInfo}.
*
* @throws IllegalArgumentException if {@code serializedFileInfo} is not a valid serialization of
* a {@link FileInfo} object according to {@link FileInfoEncoder}
* a {@link FileInfo} object according to {@link FileInfoEncoder}
*/
FileInfo decode(CharSequence serializedFileInfo) {
String[] elements = Iterables.toArray(Splitter.on(',').split(serializedFileInfo), String.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.github.sherter.googlejavaformatgradleplugin;

import com.google.common.base.Joiner;

import javax.inject.Inject;
import javax.inject.Named;
import java.io.IOError;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
Expand All @@ -13,10 +10,10 @@
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.inject.Named;

/**
* Immutable and therefore thread safe.
*/
/** Immutable and therefore thread safe. */
class FileInfoEncoder {
private final Path basePath; // absolute and normalized

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
package com.github.sherter.googlejavaformatgradleplugin;

import com.google.common.collect.ImmutableSet;
import org.gradle.api.logging.Logger;

import javax.inject.Inject;
import javax.inject.Named;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import javax.inject.Inject;
import javax.inject.Named;
import org.gradle.api.logging.Logger;

/**
* Persistent fileInfoStore for {@link FileInfo} objects.
*
* It's not safe to use instances of this class concurrently in multiple threads.
* <p>It's not safe to use instances of this class concurrently in multiple threads.
*/
class FileInfoStore {

Expand All @@ -49,7 +47,7 @@ class FileInfoStore {
* Reads serialized {@link FileInfo} objects from this {@link FileInfoStore}'s backing file and
* returns deserialized {@link FileInfo} objects.
*
* The method succeeds if the backing file can be accessed as required and the file's general
* <p>The method succeeds if the backing file can be accessed as required and the file's general
* format is intact. Decoding errors for single elements are logged, but don't prevent the method
* from succeeding.
*
Expand Down Expand Up @@ -88,9 +86,10 @@ private void init() throws IOException {
/**
* Insert the given {@link FileInfo}'s into the persistent fileInfoStore.
*
* If the fileInfoStore already contains information about a path that is referenced in an element
* in {@code updates}, then this information is replaced. If {@code updates} contain multiple
* {@link FileInfo} objects for the same path, the last one in iteration order is inserted.
* <p>If the fileInfoStore already contains information about a path that is referenced in an
* element in {@code updates}, then this information is replaced. If {@code updates} contain
* multiple {@link FileInfo} objects for the same path, the last one in iteration order is
* inserted.
*
* @throws IOException if an I/O error occurs
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.Iterators;
import com.google.common.collect.Multimaps;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.FileTime;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;

/**
* Map files to their {@link FileState}. Designed for concurrent use in multiple threads.
*/
/** Map files to their {@link FileState}. Designed for concurrent use in multiple threads. */
class FileToStateMapper implements Iterable<FileInfo> {

private static final Logger log = Logging.getLogger(FileToStateMapper.class);
Expand All @@ -43,14 +40,13 @@ ImmutableListMultimap<FileState, Path> reverseMap(Iterable<Path> files) {
}

/**
* Checks if we have information about the given {@code file} and returns the associated
* {@link FileState} if this information is still valid. Otherwise returns
* {@link FileState#UNKNOWN}.
* Checks if we have information about the given {@code file} and returns the associated {@link
* FileState} if this information is still valid. Otherwise returns {@link FileState#UNKNOWN}.
*
* The information is valid if {@link FileInfo#lastModified()} and {@link FileInfo#size()} equals
* the {@code file}'s current size and last modified time. This method always tries to access the
* file system to verify this. Returns {@link FileState#UNKNOWN} if accessing the file system
* fails.
* <p>The information is valid if {@link FileInfo#lastModified()} and {@link FileInfo#size()}
* equals the {@code file}'s current size and last modified time. This method always tries to
* access the file system to verify this. Returns {@link FileState#UNKNOWN} if accessing the file
* system fails.
*/
FileState map(Path file) {
file = file.toAbsolutePath().normalize();
Expand Down Expand Up @@ -110,9 +106,9 @@ FileInfo putIfNewer(FileInfo fileInfo) {
}

/**
* Returns a "weakly consistent", unmodifiable iterator that will never throw
* {@link ConcurrentModificationException}, and guarantees to traverse elements as they existed
* upon construction of the iterator, and may (but is not guaranteed to) reflect any modifications
* Returns a "weakly consistent", unmodifiable iterator that will never throw {@link
* ConcurrentModificationException}, and guarantees to traverse elements as they existed upon
* construction of the iterator, and may (but is not guaranteed to) reflect any modifications
* subsequent to construction.
*/
@Override
Expand Down
Loading

0 comments on commit 828014b

Please sign in to comment.