com.google.javascript.jscomp.instrumentation.reporter.ProductionInstrumentationReporter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of closure-compiler Show documentation
Show all versions of closure-compiler Show documentation
Closure Compiler is a JavaScript optimizing compiler. It parses your
JavaScript, analyzes it, removes dead code and rewrites and minimizes
what's left. It also checks syntax, variable references, and types, and
warns about common JavaScript pitfalls. It is used in many of Google's
JavaScript apps, including Gmail, Google Web Search, Google Maps, and
Google Docs.
/*
* Copyright 2020 The Closure Compiler Authors.
*
* 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.
*/
package com.google.javascript.jscomp.instrumentation.reporter;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.collect.ImmutableList;
import com.google.common.io.CharStreams;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.google.javascript.jscomp.instrumentation.reporter.proto.InstrumentationPoint;
import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.lang.reflect.Type;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;
/**
* This class will read a file that contains the instrumentation mapping generated by the compiler
* production instrumentation pass, and also a list of other files which are the reports sent by the
* instrumented production code. It will then take these inputs and generate a single JSON which
* provides a detailed breakdown of each instrumentation point.
*/
@GwtIncompatible
final class ProductionInstrumentationReporter {
@Option(
name = "--mapping_file",
usage = "The file name of the mapping generated by the production instrumentation pass.",
required = true)
private String instrumentationMappingLocation = "";
@Option(
name = "--reports_directory",
usage =
"The folder/directory which contains all the reports created by the instrumented"
+ " production code.",
required = true)
private String instrumentationReportsDirectory = "";
@Option(
name = "--result_output",
usage =
"Use this flag to provide the name of the final report that will be generated by"
+ "this reporter.",
required = true)
private String finalResultOutput = "";
public static void main(String[] args) {
try {
new ProductionInstrumentationReporter().doMain(args);
} catch (IOException e) {
System.err.println(e.getMessage());
}
}
/** This function reads a file at the given filePath and converts the contents into a string. */
public static String readFile(String filePath) throws IOException {
return CharStreams.toString(Files.newBufferedReader(Paths.get(filePath), UTF_8));
}
/**
* Reads all files found in folder and converts the contents of each file to a Map data structure where it is a mapping of the unique param value to the encoded
* values. The folder contains all the reports sent by the instrumented production code.
*/
private ImmutableList