Skip to content

Commit

Permalink
Run GJF on all java files (#780)
Browse files Browse the repository at this point in the history
  • Loading branch information
raviagarwal7 authored Jan 2, 2019
1 parent 96faa47 commit 8f3ab4d
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 80 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.uber.okbuck.example.anotherapp;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.example.hellojni.HelloJni;
import com.uber.okbuck.example.common.Calc;
import com.uber.okbuck.example.common.CalcMonitor;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/uber/okbuck/example/AppShell.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.uber.okbuck.example;

import androidx.multidex.MultiDex;
import android.widget.Toast;
import androidx.multidex.MultiDex;
import com.facebook.buck.android.support.exopackage.ExopackageApplication;
import com.uber.okbuck.example.common.Calc;
import com.uber.okbuck.example.common.CalcMonitor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@

import android.content.Context;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.appbar.AppBarLayout;

public class CollapsingAppBarActivity extends AppCompatActivity {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/uber/okbuck/example/CustomView.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.uber.okbuck.example;

import android.content.Context;
import androidx.appcompat.widget.AppCompatTextView;
import android.util.AttributeSet;
import androidx.appcompat.widget.AppCompatTextView;

public class CustomView extends AppCompatTextView {
public CustomView(Context context) {
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/com/uber/okbuck/example/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,9 +597,9 @@ public String getPackage() {
}

public String getResPackage() {
if(resourceUnionPackageName != null){
if (resourceUnionPackageName != null) {
return resourceUnionPackageName;
}else{
} else {
return getOriginalPackage();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public JvmTarget(
this.aptConfigurationName = aptConfigurationName;
this.testAptConfigurationName = testAptConfigurationName;
sourceSets = getProject().getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
isKotlin = project.getPlugins().stream()
.anyMatch(plugin -> plugin instanceof KotlinBasePluginWrapper);
isKotlin =
project.getPlugins().stream().anyMatch(plugin -> plugin instanceof KotlinBasePluginWrapper);

Optional<Task> compileTask =
project.getTasks().stream().filter(it -> it instanceof AbstractCompile).findFirst();
Expand Down Expand Up @@ -289,15 +289,16 @@ protected List<String> getKotlinCompilerOptions(boolean isTest) {
List<SubpluginOption> options =
subplugin.apply(getProject(), fakeCompile, fakeCompile, null, null, null);

optionBuilder.add(
"-Xplugin="
+ KotlinManager.KOTLIN_LIBRARIES_LOCATION
+ File.separator
+ KotlinManager.KOTLIN_ALLOPEN_JAR);

for (SubpluginOption option : options) {
optionBuilder.add("-P");
optionBuilder.add("plugin:org.jetbrains.kotlin.allopen:" + option.getKey() + "=" + option.getValue());
optionBuilder.add(
"-Xplugin="
+ KotlinManager.KOTLIN_LIBRARIES_LOCATION
+ File.separator
+ KotlinManager.KOTLIN_ALLOPEN_JAR);

for (SubpluginOption option : options) {
optionBuilder.add("-P");
optionBuilder.add(
"plugin:org.jetbrains.kotlin.allopen:" + option.getKey() + "=" + option.getValue());
}
}
}
Expand All @@ -308,7 +309,8 @@ protected List<String> getKotlinCompilerOptions(boolean isTest) {

// Note that we hardcode the path for now as location macros can only be used in genrules
// at the time of writing. When location macros are supported, can simply just write
// optionBuilder.add("-Xfriend-paths=$(location :" + JvmBuckRuleComposer.src(this) + "[output])");
// optionBuilder.add("-Xfriend-paths=$(location :" + JvmBuckRuleComposer.src(this) +
// "[output])");
String composedTargetName = JvmBuckRuleComposer.src(this);
optionBuilder.add(
"-Xfriend-paths="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,31 @@
import com.android.tools.lint.detector.api.Scope;
import com.android.tools.lint.detector.api.Severity;
import com.android.tools.lint.detector.api.XmlContext;
import org.w3c.dom.Attr;

import java.util.Collection;
import org.w3c.dom.Attr;

public class ColorDetector extends ResourceXmlDetector {

@SuppressWarnings("unchecked")
private static final Implementation IMPLEMENTATION = new Implementation(
ColorDetector.class,
Scope.MANIFEST_AND_RESOURCE_SCOPE,
Scope.MANIFEST_SCOPE, Scope.RESOURCE_FILE_SCOPE);

public static final Issue ISSUE = Issue.create(
"AndroidColorDetector",
"Using Android color resources",
"Android color resources like android:color/white should not be used." +
" Manufacturers tend to overwrite them.",
Category.CORRECTNESS,
7,
Severity.ERROR,
IMPLEMENTATION);

public ColorDetector() {
}
private static final Implementation IMPLEMENTATION =
new Implementation(
ColorDetector.class,
Scope.MANIFEST_AND_RESOURCE_SCOPE,
Scope.MANIFEST_SCOPE,
Scope.RESOURCE_FILE_SCOPE);

public static final Issue ISSUE =
Issue.create(
"AndroidColorDetector",
"Using Android color resources",
"Android color resources like android:color/white should not be used."
+ " Manufacturers tend to overwrite them.",
Category.CORRECTNESS,
7,
Severity.ERROR,
IMPLEMENTATION);

public ColorDetector() {}

@Override
public Collection<String> getApplicableAttributes() {
Expand All @@ -41,8 +42,11 @@ public Collection<String> getApplicableAttributes() {
@Override
public void visitAttribute(XmlContext context, Attr attribute) {
if (attribute.getValue().contains(SdkConstants.ANDROID_COLOR_RESOURCE_PREFIX)) {
context.report(ISSUE, attribute, context.getLocation(attribute),
context.report(
ISSUE,
attribute,
context.getLocation(attribute),
"Using Android color resources are not recommended. Manufacturers are overriding them with other colors.");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public List<Issue> getIssues() {
return ImmutableList.of(SystemCurrentTimeMillisDetector.ISSUE, ColorDetector.ISSUE);
}

@Override public int getApi() {
@Override
public int getApi() {
return ApiKt.CURRENT_API;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.google.common.base.Joiner;
import com.google.common.base.Strings;
import com.google.common.io.Files;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
Expand All @@ -19,12 +18,10 @@
import java.util.Locale;
import java.util.StringTokenizer;

/**
* Command line interface to the {@link ManifestMerger2}
*/
/** Command line interface to the {@link ManifestMerger2} */
public final class ManifestMergerCli {

private ManifestMergerCli() { }
private ManifestMergerCli() {}

public static void main(String[] args) {
try {
Expand All @@ -44,17 +41,17 @@ private static int process(String[] args) throws FileNotFoundException {
while (arguments.hasNext()) {
String selector = arguments.next();
if (!selector.startsWith("--")) {
logger.error(null /* throwable */,
"Invalid parameter " + selector + ", expected a command switch");
logger.error(
null /* throwable */, "Invalid parameter " + selector + ", expected a command switch");
return 1;
}
if ("--usage".equals(selector)) {
usage();
return 0;
}
if (!arguments.hasNext()) {
logger.error(null /* throwable */,
"Command switch " + selector + " has no value associated");
logger.error(
null /* throwable */, "Command switch " + selector + " has no value associated");
return 1;
}
String value = arguments.next();
Expand All @@ -75,11 +72,11 @@ private static int process(String[] args) throws FileNotFoundException {
// recreate the logger with the provided log level for the rest of the processing.
logger = createLogger(logLevel);
File mainManifestFile = checkPath(mainManifest);
ManifestMerger2.Invoker invoker = createInvoker(
mainManifestFile, logger);
ManifestMerger2.Invoker invoker = createInvoker(mainManifestFile, logger);

// set some features
invoker.withFeatures(ManifestMerger2.Invoker.Feature.NO_PLACEHOLDER_REPLACEMENT); // handled by buck
invoker.withFeatures(
ManifestMerger2.Invoker.Feature.NO_PLACEHOLDER_REPLACEMENT); // handled by buck

// second pass, get optional parameters and store them in the invoker.
arguments = Arrays.asList(args).iterator();
Expand All @@ -89,8 +86,7 @@ private static int process(String[] args) throws FileNotFoundException {
String selector = arguments.next();
String value = arguments.next();
if (Strings.isNullOrEmpty(value)) {
logger.error(null /* throwable */,
"Empty value for switch " + selector);
logger.error(null /* throwable */, "Empty value for switch " + selector);
return 1;
}
if ("--libs".equals(selector)) {
Expand All @@ -109,30 +105,33 @@ private static int process(String[] args) throws FileNotFoundException {
}
if ("--property".equals(selector)) {
if (!value.contains("=")) {
logger.error(null /* throwable */,
"Invalid property setting, should be NAME=VALUE format");
logger.error(
null /* throwable */, "Invalid property setting, should be NAME=VALUE format");
return 1;
}
try {
ManifestSystemProperty manifestSystemProperty = ManifestSystemProperty
.valueOf(value.substring(0, value.indexOf('='))
.toUpperCase(Locale.ENGLISH));
ManifestSystemProperty manifestSystemProperty =
ManifestSystemProperty.valueOf(
value.substring(0, value.indexOf('=')).toUpperCase(Locale.ENGLISH));
invoker.setOverride(manifestSystemProperty, value.substring(value.indexOf('=') + 1));
} catch (IllegalArgumentException e) {
logger.error(e, "Invalid property name " + value.substring(0, value.indexOf('='))
+ ", allowed properties are : " + Joiner
.on(',').join(ManifestSystemProperty.values()));
logger.error(
e,
"Invalid property name "
+ value.substring(0, value.indexOf('='))
+ ", allowed properties are : "
+ Joiner.on(',').join(ManifestSystemProperty.values()));
return 1;
}
}
if ("--placeholder".equals(selector)) {
if (!value.contains("=")) {
logger.error(null /* throwable */,
"Invalid placeholder setting, should be NAME=VALUE format");
logger.error(
null /* throwable */, "Invalid placeholder setting, should be NAME=VALUE format");
return 1;
}
invoker.setPlaceHolderValue(value.substring(0, value.indexOf('=')),
value.substring(value.indexOf('=') + 1));
invoker.setPlaceHolderValue(
value.substring(0, value.indexOf('=')), value.substring(value.indexOf('=') + 1));
}
if ("--debuggable".equals(selector)) {
if (value.equals("true")) {
Expand Down Expand Up @@ -172,8 +171,8 @@ private static int process(String[] args) throws FileNotFoundException {
}

private static ManifestMerger2.Invoker createInvoker(File mainManifestFile, ILogger logger) {
return ManifestMerger2
.newMerger(mainManifestFile, logger, ManifestMerger2.MergeType.APPLICATION);
return ManifestMerger2.newMerger(
mainManifestFile, logger, ManifestMerger2.MergeType.APPLICATION);
}

private static void usage() {
Expand All @@ -184,14 +183,12 @@ private static void usage() {
System.out.println("\t--debuggable [true, false]");
System.out.println("\t--libs [path separated list of lib's manifests]");
System.out.println("\t--overlays [path separated list of overlay's manifests]");
System.out.println("\t--property ["
+ Joiner.on(" | ").join(ManifestSystemProperty.values())
+ "=value]");
System.out.println(
"\t--property [" + Joiner.on(" | ").join(ManifestSystemProperty.values()) + "=value]");
System.out.println("\t--placeholder [name=value]");
System.out.println("\t--out [path of the output file]");
}


private static File checkPath(@NonNull String path) throws FileNotFoundException {
File file = new File(path);
if (!file.exists()) {
Expand Down

0 comments on commit 8f3ab4d

Please sign in to comment.