1 /* 2 * Copyright 2021 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 15 package com.google.googlejavaformat.java; 16 17 import com.google.auto.service.AutoService; 18 import java.io.PrintWriter; 19 import java.util.spi.ToolProvider; 20 21 /** Provide a way to be invoked without necessarily starting a new VM. */ 22 @AutoService(ToolProvider.class) 23 public class GoogleJavaFormatToolProvider implements ToolProvider { 24 @Override name()25 public String name() { 26 return "google-java-format"; 27 } 28 29 @Override run(PrintWriter out, PrintWriter err, String... args)30 public int run(PrintWriter out, PrintWriter err, String... args) { 31 try { 32 return Main.main(System.in, out, err, args); 33 } catch (RuntimeException e) { 34 err.print(e.getMessage()); 35 err.flush(); 36 return 1; // pass non-zero value back indicating an error has happened 37 } 38 } 39 } 40