001/* 002 * Copyright (C) 2015-2021 KeepSafe Software 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.getkeepsafe.dexcount; 017 018import com.google.auto.value.AutoValue; 019 020import javax.annotation.Nullable; 021import java.io.Serializable; 022 023@AutoValue 024public abstract class PrintOptions implements Serializable { 025 private static final long serialVersionUID = -1L; 026 027 public abstract boolean getIncludeClasses(); 028 public abstract boolean getIncludeClassCount(); 029 public abstract boolean getIncludeMethodCount(); 030 public abstract boolean getIncludeFieldCount(); 031 public abstract boolean getIncludeTotalMethodCount(); 032 public abstract boolean getTeamCityIntegration(); 033 @Nullable 034 public abstract String getTeamCitySlug(); 035 public abstract boolean getPrintHeader(); 036 public abstract boolean getOrderByMethodCount(); 037 public abstract int getMaxTreeDepth(); 038 public abstract int getMaxMethodCount(); 039 public abstract boolean getPrintDeclarations(); 040 public abstract boolean isAndroidProject(); 041 public abstract boolean isVerbose(); 042 public abstract OutputFormat getOutputFormat(); 043 044 public abstract Builder toBuilder(); 045 046 public PrintOptions withIsAndroidProject(boolean isAndroidProject) { 047 return toBuilder() 048 .setAndroidProject(isAndroidProject) 049 .build(); 050 } 051 052 @AutoValue.Builder 053 public abstract static class Builder { 054 public abstract Builder setIncludeClasses(boolean includeClasses); 055 public abstract Builder setIncludeClassCount(boolean includeClassCount); 056 public abstract Builder setIncludeMethodCount(boolean includeMethodCount); 057 public abstract Builder setIncludeFieldCount(boolean includeFieldCount); 058 public abstract Builder setIncludeTotalMethodCount(boolean includeTotalMethodCount); 059 public abstract Builder setTeamCityIntegration(boolean teamCityIntegration); 060 public abstract Builder setTeamCitySlug(@Nullable String teamCitySlug); 061 public abstract Builder setPrintHeader(boolean printHeader); 062 public abstract Builder setOrderByMethodCount(boolean orderByMethodCount); 063 public abstract Builder setMaxTreeDepth(int maxTreeDepth); 064 public abstract Builder setMaxMethodCount(int maxMethodCount); 065 public abstract Builder setPrintDeclarations(boolean printDeclarations); 066 public abstract Builder setAndroidProject(boolean androidProject); 067 public abstract Builder setVerbose(boolean verbose); 068 public abstract Builder setOutputFormat(OutputFormat outputFormat); 069 070 public abstract PrintOptions build(); 071 } 072 073 public static Builder builder() { 074 return new AutoValue_PrintOptions.Builder() 075 .setIncludeClasses(false) 076 .setIncludeClassCount(false) 077 .setIncludeMethodCount(true) 078 .setIncludeFieldCount(false) 079 .setIncludeTotalMethodCount(false) 080 .setTeamCityIntegration(false) 081 .setTeamCitySlug(null) 082 .setPrintHeader(false) 083 .setOrderByMethodCount(false) 084 .setMaxTreeDepth(Integer.MAX_VALUE) 085 .setMaxMethodCount(-1) 086 .setPrintDeclarations(false) 087 .setAndroidProject(true) 088 .setVerbose(false) 089 .setOutputFormat(OutputFormat.LIST); 090 } 091 092 public static PrintOptions fromDexCountExtension(DexCountExtension ext) { 093 return builder() 094 .setIncludeClasses(ext.getIncludeClasses().get()) 095 .setIncludeClassCount(ext.getIncludeClassCount().get()) 096 .setIncludeMethodCount(true) 097 .setIncludeFieldCount(ext.getIncludeFieldCount().get()) 098 .setIncludeTotalMethodCount(ext.getIncludeTotalMethodCount().get()) 099 .setTeamCityIntegration(ext.getTeamCityIntegration().get()) 100 .setTeamCitySlug(ext.getTeamCitySlug().getOrNull()) 101 .setPrintHeader(ext.getPrintVersion().get()) 102 .setPrintDeclarations(ext.getPrintDeclarations().get()) 103 .setMaxTreeDepth(ext.getMaxTreeDepth().get()) 104 .setMaxMethodCount(ext.getMaxMethodCount().get()) 105 .setOrderByMethodCount(ext.getOrderByMethodCount().get()) 106 .setVerbose(ext.getVerbose().get()) 107 .setOutputFormat(ext.getFormat().get()) 108 .build(); 109 } 110}