Format all Java files with google-java-format
Having a standard tool for formatting saves reviewers' valuable time. google-java-format is Google's standard formatter and is somewhat inspired by gofmt[1]. This commit formats everything using google-java-format version 1.2. The downside of this one-off formatting is breaking blame. This can be somewhat hacked around with a tool like git-hyper-blame[2], but it's definitely not optimal until/unless this kind of feature makes its way to git core. Not in this change: * Tool support, e.g. Eclipse. The command must be run manually [3]. * Documentation of best practice, e.g. new 100-column default. [1] https://talks.golang.org/2015/gofmt-en.slide#3 [2] https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/git-hyper-blame.html [3] git ls-files | grep java$ | xargs google-java-format -i Change-Id: Id5f3c6de95ce0b68b41f0a478b5c99a93675aaa3 Signed-off-by: David Pursehouse <dpursehouse@collab.net>
This commit is contained in:
committed by
David Pursehouse
parent
6723b6d0fa
commit
292fa154c1
@@ -13,18 +13,6 @@
|
||||
// limitations under the License.
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
import org.asciidoctor.Asciidoctor;
|
||||
import org.asciidoctor.AttributesBuilder;
|
||||
import org.asciidoctor.Options;
|
||||
import org.asciidoctor.OptionsBuilder;
|
||||
import org.asciidoctor.SafeMode;
|
||||
import org.asciidoctor.internal.JRubyAsciidoctor;
|
||||
import org.kohsuke.args4j.Argument;
|
||||
import org.kohsuke.args4j.CmdLineException;
|
||||
import org.kohsuke.args4j.CmdLineParser;
|
||||
import org.kohsuke.args4j.Option;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@@ -39,6 +27,16 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
import org.asciidoctor.Asciidoctor;
|
||||
import org.asciidoctor.AttributesBuilder;
|
||||
import org.asciidoctor.Options;
|
||||
import org.asciidoctor.OptionsBuilder;
|
||||
import org.asciidoctor.SafeMode;
|
||||
import org.asciidoctor.internal.JRubyAsciidoctor;
|
||||
import org.kohsuke.args4j.Argument;
|
||||
import org.kohsuke.args4j.CmdLineException;
|
||||
import org.kohsuke.args4j.CmdLineParser;
|
||||
import org.kohsuke.args4j.Option;
|
||||
|
||||
public class AsciiDoctor {
|
||||
|
||||
@@ -67,16 +65,16 @@ public class AsciiDoctor {
|
||||
@Option(name = "--mktmp", usage = "create a temporary output path")
|
||||
private boolean mktmp;
|
||||
|
||||
@Option(name = "-a", usage =
|
||||
"a list of attributes, in the form key or key=value pair")
|
||||
@Option(name = "-a", usage = "a list of attributes, in the form key or key=value pair")
|
||||
private List<String> attributes = new ArrayList<>();
|
||||
|
||||
@Option(name = "--bazel", usage =
|
||||
"bazel mode: generate multiple output files instead of a single zip file")
|
||||
@Option(
|
||||
name = "--bazel",
|
||||
usage = "bazel mode: generate multiple output files instead of a single zip file"
|
||||
)
|
||||
private boolean bazel;
|
||||
|
||||
@Option(name = "--revnumber-file", usage =
|
||||
"the file contains revnumber string")
|
||||
@Option(name = "--revnumber-file", usage = "the file contains revnumber string")
|
||||
private File revnumberFile;
|
||||
|
||||
@Argument(usage = "input files")
|
||||
@@ -84,8 +82,7 @@ public class AsciiDoctor {
|
||||
|
||||
private String revnumber;
|
||||
|
||||
public static String mapInFileToOutFile(
|
||||
String inFile, String inExt, String outExt) {
|
||||
public static String mapInFileToOutFile(String inFile, String inExt, String outExt) {
|
||||
String basename = new File(inFile).getName();
|
||||
if (basename.endsWith(inExt)) {
|
||||
basename = basename.substring(0, basename.length() - inExt.length());
|
||||
@@ -147,8 +144,7 @@ public class AsciiDoctor {
|
||||
try {
|
||||
parser.parseArgument(parameters);
|
||||
if (inputFiles.isEmpty()) {
|
||||
throw new CmdLineException(parser,
|
||||
"asciidoctor: FAILED: input file missing");
|
||||
throw new CmdLineException(parser, "asciidoctor: FAILED: input file missing");
|
||||
}
|
||||
} catch (CmdLineException e) {
|
||||
System.err.println(e.getMessage());
|
||||
@@ -158,8 +154,7 @@ public class AsciiDoctor {
|
||||
}
|
||||
|
||||
if (revnumberFile != null) {
|
||||
try (BufferedReader reader =
|
||||
new BufferedReader(new FileReader(revnumberFile))) {
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(revnumberFile))) {
|
||||
revnumber = reader.readLine();
|
||||
}
|
||||
}
|
||||
@@ -171,16 +166,17 @@ public class AsciiDoctor {
|
||||
if (bazel) {
|
||||
renderFiles(inputFiles, null);
|
||||
} else {
|
||||
try (ZipOutputStream zip =
|
||||
new ZipOutputStream(new FileOutputStream(zipFile))) {
|
||||
try (ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(zipFile))) {
|
||||
renderFiles(inputFiles, zip);
|
||||
|
||||
File[] cssFiles = tmpdir.listFiles(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(".css");
|
||||
}
|
||||
});
|
||||
File[] cssFiles =
|
||||
tmpdir.listFiles(
|
||||
new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(".css");
|
||||
}
|
||||
});
|
||||
for (File css : cssFiles) {
|
||||
zipFile(css, css.getName(), zip);
|
||||
}
|
||||
@@ -188,8 +184,7 @@ public class AsciiDoctor {
|
||||
}
|
||||
}
|
||||
|
||||
private void renderFiles(List<String> inputFiles, ZipOutputStream zip)
|
||||
throws IOException {
|
||||
private void renderFiles(List<String> inputFiles, ZipOutputStream zip) throws IOException {
|
||||
Asciidoctor asciidoctor = JRubyAsciidoctor.create();
|
||||
for (String inputFile : inputFiles) {
|
||||
String outName = mapInFileToOutFile(inputFile, inExt, outExt);
|
||||
@@ -198,8 +193,7 @@ public class AsciiDoctor {
|
||||
out.getParentFile().mkdirs();
|
||||
}
|
||||
File input = new File(inputFile);
|
||||
Options options =
|
||||
createOptions(basedir != null ? basedir : input.getParentFile(), out);
|
||||
Options options = createOptions(basedir != null ? basedir : input.getParentFile(), out);
|
||||
asciidoctor.renderFile(input, options);
|
||||
if (zip != null) {
|
||||
zipFile(out, outName, zip);
|
||||
@@ -207,8 +201,7 @@ public class AsciiDoctor {
|
||||
}
|
||||
}
|
||||
|
||||
public static void zipFile(File file, String name, ZipOutputStream zip)
|
||||
throws IOException {
|
||||
public static void zipFile(File file, String name, ZipOutputStream zip) throws IOException {
|
||||
zip.putNextEntry(new ZipEntry(name));
|
||||
try (FileInputStream input = new FileInputStream(file)) {
|
||||
ByteStreams.copy(input, zip);
|
||||
|
||||
@@ -15,23 +15,6 @@
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.gerrit.server.documentation.Constants;
|
||||
|
||||
import org.apache.lucene.analysis.standard.StandardAnalyzer;
|
||||
import org.apache.lucene.analysis.util.CharArraySet;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.StringField;
|
||||
import org.apache.lucene.document.TextField;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.IndexWriterConfig;
|
||||
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
|
||||
import org.apache.lucene.store.IndexInput;
|
||||
import org.apache.lucene.store.RAMDirectory;
|
||||
import org.kohsuke.args4j.Argument;
|
||||
import org.kohsuke.args4j.CmdLineException;
|
||||
import org.kohsuke.args4j.CmdLineParser;
|
||||
import org.kohsuke.args4j.Option;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
@@ -50,6 +33,21 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
import org.apache.lucene.analysis.standard.StandardAnalyzer;
|
||||
import org.apache.lucene.analysis.util.CharArraySet;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.StringField;
|
||||
import org.apache.lucene.document.TextField;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.IndexWriterConfig;
|
||||
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
|
||||
import org.apache.lucene.store.IndexInput;
|
||||
import org.apache.lucene.store.RAMDirectory;
|
||||
import org.kohsuke.args4j.Argument;
|
||||
import org.kohsuke.args4j.CmdLineException;
|
||||
import org.kohsuke.args4j.CmdLineParser;
|
||||
import org.kohsuke.args4j.Option;
|
||||
|
||||
public class DocIndexer {
|
||||
private static final Pattern SECTION_HEADER = Pattern.compile("^=+ (.*)");
|
||||
@@ -85,8 +83,7 @@ public class DocIndexer {
|
||||
|
||||
try (JarOutputStream jar = new JarOutputStream(new FileOutputStream(outFile))) {
|
||||
byte[] compressedIndex = zip(index());
|
||||
JarEntry entry = new JarEntry(
|
||||
String.format("%s/%s", Constants.PACKAGE, Constants.INDEX_ZIP));
|
||||
JarEntry entry = new JarEntry(String.format("%s/%s", Constants.PACKAGE, Constants.INDEX_ZIP));
|
||||
entry.setSize(compressedIndex.length);
|
||||
jar.putNextEntry(entry);
|
||||
jar.write(compressedIndex);
|
||||
@@ -94,11 +91,10 @@ public class DocIndexer {
|
||||
}
|
||||
}
|
||||
|
||||
private RAMDirectory index() throws IOException,
|
||||
UnsupportedEncodingException, FileNotFoundException {
|
||||
private RAMDirectory index()
|
||||
throws IOException, UnsupportedEncodingException, FileNotFoundException {
|
||||
RAMDirectory directory = new RAMDirectory();
|
||||
IndexWriterConfig config = new IndexWriterConfig(
|
||||
new StandardAnalyzer(CharArraySet.EMPTY_SET));
|
||||
IndexWriterConfig config = new IndexWriterConfig(new StandardAnalyzer(CharArraySet.EMPTY_SET));
|
||||
config.setOpenMode(OpenMode.CREATE);
|
||||
config.setCommitOnClose(true);
|
||||
try (IndexWriter iwriter = new IndexWriter(directory, config)) {
|
||||
@@ -109,8 +105,8 @@ public class DocIndexer {
|
||||
}
|
||||
|
||||
String title;
|
||||
try (BufferedReader titleReader = new BufferedReader(
|
||||
new InputStreamReader(new FileInputStream(file), UTF_8))) {
|
||||
try (BufferedReader titleReader =
|
||||
new BufferedReader(new InputStreamReader(new FileInputStream(file), UTF_8))) {
|
||||
title = titleReader.readLine();
|
||||
if (title != null && title.startsWith("[[")) {
|
||||
// Generally the first line of the txt is the title. In a few cases the
|
||||
@@ -123,13 +119,11 @@ public class DocIndexer {
|
||||
title = matcher.group(1);
|
||||
}
|
||||
|
||||
String outputFile = AsciiDoctor.mapInFileToOutFile(
|
||||
inputFile, inExt, outExt);
|
||||
String outputFile = AsciiDoctor.mapInFileToOutFile(inputFile, inExt, outExt);
|
||||
try (FileReader reader = new FileReader(file)) {
|
||||
Document doc = new Document();
|
||||
doc.add(new TextField(Constants.DOC_FIELD, reader));
|
||||
doc.add(new StringField(
|
||||
Constants.URL_FIELD, prefix + outputFile, Field.Store.YES));
|
||||
doc.add(new StringField(Constants.URL_FIELD, prefix + outputFile, Field.Store.YES));
|
||||
doc.add(new TextField(Constants.TITLE_FIELD, title, Field.Store.YES));
|
||||
iwriter.addDocument(doc);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user