diff --git a/another-app/src/com/example/hellojni/HelloJni.java b/another-app/src/com/example/hellojni/HelloJni.java index 49888fb1e..3ad6be5c0 100644 --- a/another-app/src/com/example/hellojni/HelloJni.java +++ b/another-app/src/com/example/hellojni/HelloJni.java @@ -2,18 +2,18 @@ public class HelloJni { - /* this is used to load the 'hello-jni' library on application - * startup. The library has already been unpacked into - * /data/data/com.example.hellojni/lib/libhello-jni.so at - * installation time by the package manager. - */ - static { - System.loadLibrary("hello-jni"); - } + /* this is used to load the 'hello-jni' library on application + * startup. The library has already been unpacked into + * /data/data/com.example.hellojni/lib/libhello-jni.so at + * installation time by the package manager. + */ + static { + System.loadLibrary("hello-jni"); + } - /* A native method that is implemented by the - * 'hello-jni' native library, which is packaged - * with this application. - */ - public static native String stringFromJNI(); + /* A native method that is implemented by the + * 'hello-jni' native library, which is packaged + * with this application. + */ + public static native String stringFromJNI(); } diff --git a/another-app/src/com/uber/okbuck/example/anotherapp/CustomView.java b/another-app/src/com/uber/okbuck/example/anotherapp/CustomView.java index c3e91579e..65112a06a 100644 --- a/another-app/src/com/uber/okbuck/example/anotherapp/CustomView.java +++ b/another-app/src/com/uber/okbuck/example/anotherapp/CustomView.java @@ -5,15 +5,15 @@ import android.util.AttributeSet; public class CustomView extends AppCompatTextView { - public CustomView(Context context) { - super(context); - } + public CustomView(Context context) { + super(context); + } - public CustomView(Context context, AttributeSet attrs) { - super(context, attrs); - } + public CustomView(Context context, AttributeSet attrs) { + super(context, attrs); + } - public CustomView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } + public CustomView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } } diff --git a/another-app/src/com/uber/okbuck/example/anotherapp/MainActivity.java b/another-app/src/com/uber/okbuck/example/anotherapp/MainActivity.java index 848b4d536..46be165a8 100644 --- a/another-app/src/com/uber/okbuck/example/anotherapp/MainActivity.java +++ b/another-app/src/com/uber/okbuck/example/anotherapp/MainActivity.java @@ -6,59 +6,58 @@ import android.view.Menu; import android.view.MenuItem; import android.widget.TextView; - import com.example.hellojni.HelloJni; import com.uber.okbuck.example.common.Calc; import com.uber.okbuck.example.common.CalcMonitor; public class MainActivity extends AppCompatActivity { - private TextView mTvTest; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - - CalcMonitor calcMonitor = new CalcMonitor(this); - calcMonitor.addCalled("from another-app"); - - mTvTest = findViewById(R.id.mTvTest); - mTvTest.setOnClickListener(v -> mTvTest()); - } - - void mTvTest() { - Log.d("TEST", "" + android.support.v7.appcompat.R.color.button_material_light); - mTvTest.setText(new StringBuilder().append("1 + 2 = ") - .append(new Calc(new CalcMonitor(this)).add(1, 2)) - .append("\n\n") - .append(HelloJni - .stringFromJNI()) - .append("\n\n") - .append(getString( - com.uber.okbuck.example.empty.R.string.empty_release_string)) - .toString()); + private TextView mTvTest; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + CalcMonitor calcMonitor = new CalcMonitor(this); + calcMonitor.addCalled("from another-app"); + + mTvTest = findViewById(R.id.mTvTest); + mTvTest.setOnClickListener(v -> mTvTest()); + } + + void mTvTest() { + Log.d("TEST", "" + android.support.v7.appcompat.R.color.button_material_light); + mTvTest.setText( + new StringBuilder() + .append("1 + 2 = ") + .append(new Calc(new CalcMonitor(this)).add(1, 2)) + .append("\n\n") + .append(HelloJni.stringFromJNI()) + .append("\n\n") + .append(getString(com.uber.okbuck.example.empty.R.string.empty_release_string)) + .toString()); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.menu_main, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + + //noinspection SimplifiableIfStatement + if (id == R.id.action_settings) { + return true; } - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.menu_main, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - int id = item.getItemId(); - - //noinspection SimplifiableIfStatement - if (id == R.id.action_settings) { - return true; - } - - return super.onOptionsItemSelected(item); - } + return super.onOptionsItemSelected(item); + } } diff --git a/app/src/androidTest/java/com/uber/okbuck/example/test/MainActivityTest.java b/app/src/androidTest/java/com/uber/okbuck/example/test/MainActivityTest.java index 849add74f..882bd07f5 100644 --- a/app/src/androidTest/java/com/uber/okbuck/example/test/MainActivityTest.java +++ b/app/src/androidTest/java/com/uber/okbuck/example/test/MainActivityTest.java @@ -1,36 +1,33 @@ package com.uber.okbuck.example.test; +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.assertion.ViewAssertions.matches; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static android.support.test.espresso.matcher.ViewMatchers.withText; +import static junit.framework.Assert.assertEquals; + import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; - import com.uber.okbuck.example.MainActivity; import com.uber.okbuck.example.R; - import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import static android.support.test.espresso.Espresso.onView; -import static android.support.test.espresso.assertion.ViewAssertions.matches; -import static android.support.test.espresso.matcher.ViewMatchers.withId; -import static android.support.test.espresso.matcher.ViewMatchers.withText; -import static junit.framework.Assert.assertEquals; - @RunWith(AndroidJUnit4.class) public class MainActivityTest { - @Rule - public ActivityTestRule rule = - new ActivityTestRule(MainActivity.class, true, true); + @Rule + public ActivityTestRule rule = new ActivityTestRule(MainActivity.class, true, true); - @Test - public void checkTextDisplayed() { - onView(withId(R.id.mTextView2)).check(matches(withText("test in app"))); - } + @Test + public void checkTextDisplayed() { + onView(withId(R.id.mTextView2)).check(matches(withText("test in app"))); + } - @Test - public void java8LambdaCompilesAndWorksInInstrumentationApk() { - Runnable runnable = () -> assertEquals(3, 2 + 1); - runnable.run(); - } + @Test + public void java8LambdaCompilesAndWorksInInstrumentationApk() { + Runnable runnable = () -> assertEquals(3, 2 + 1); + runnable.run(); + } } diff --git a/app/src/demo/java/com/uber/okbuck/example/FlavorLogger.java b/app/src/demo/java/com/uber/okbuck/example/FlavorLogger.java index e8ddf427a..7ec20ed07 100644 --- a/app/src/demo/java/com/uber/okbuck/example/FlavorLogger.java +++ b/app/src/demo/java/com/uber/okbuck/example/FlavorLogger.java @@ -4,7 +4,7 @@ public class FlavorLogger { - public static String log(Context context) { - return "FlavorLogger, dev, " + context.getString(R.string.flavor_string); - } + public static String log(Context context) { + return "FlavorLogger, dev, " + context.getString(R.string.flavor_string); + } } diff --git a/app/src/dev/java/com/uber/okbuck/example/FlavorLogger.java b/app/src/dev/java/com/uber/okbuck/example/FlavorLogger.java index e8ddf427a..7ec20ed07 100644 --- a/app/src/dev/java/com/uber/okbuck/example/FlavorLogger.java +++ b/app/src/dev/java/com/uber/okbuck/example/FlavorLogger.java @@ -4,7 +4,7 @@ public class FlavorLogger { - public static String log(Context context) { - return "FlavorLogger, dev, " + context.getString(R.string.flavor_string); - } + public static String log(Context context) { + return "FlavorLogger, dev, " + context.getString(R.string.flavor_string); + } } diff --git a/app/src/main/java/com/uber/okbuck/example/AppShell.java b/app/src/main/java/com/uber/okbuck/example/AppShell.java index 980843d3a..cc85c6f82 100644 --- a/app/src/main/java/com/uber/okbuck/example/AppShell.java +++ b/app/src/main/java/com/uber/okbuck/example/AppShell.java @@ -2,27 +2,26 @@ import android.support.multidex.MultiDex; import android.widget.Toast; - import com.facebook.buck.android.support.exopackage.ExopackageApplication; import com.uber.okbuck.example.common.Calc; import com.uber.okbuck.example.common.CalcMonitor; public class AppShell extends ExopackageApplication { - private static final String APP_NAME = "com.uber.okbuck.example.MyApp"; - private final boolean mIsExopackageMode; + private static final String APP_NAME = "com.uber.okbuck.example.MyApp"; + private final boolean mIsExopackageMode; - public AppShell() { - super(APP_NAME, BuildConfig.EXOPACKAGE_FLAGS != 0); - mIsExopackageMode = BuildConfig.EXOPACKAGE_FLAGS != 0; - } + public AppShell() { + super(APP_NAME, BuildConfig.EXOPACKAGE_FLAGS != 0); + mIsExopackageMode = BuildConfig.EXOPACKAGE_FLAGS != 0; + } - @Override - protected void onBaseContextAttached() { - if (!mIsExopackageMode) { - MultiDex.install(this); - } - Calc calc = new Calc(new CalcMonitor(this)); - Toast.makeText(this, "calc: " + calc.add(1, 2), Toast.LENGTH_SHORT).show(); + @Override + protected void onBaseContextAttached() { + if (!mIsExopackageMode) { + MultiDex.install(this); } + Calc calc = new Calc(new CalcMonitor(this)); + Toast.makeText(this, "calc: " + calc.add(1, 2), Toast.LENGTH_SHORT).show(); + } } diff --git a/app/src/main/java/com/uber/okbuck/example/CollapsingAppBarActivity.java b/app/src/main/java/com/uber/okbuck/example/CollapsingAppBarActivity.java index 88f0404a7..3a0e93654 100644 --- a/app/src/main/java/com/uber/okbuck/example/CollapsingAppBarActivity.java +++ b/app/src/main/java/com/uber/okbuck/example/CollapsingAppBarActivity.java @@ -14,115 +14,120 @@ import android.widget.TextView; import android.widget.Toast; -import butterknife.ButterKnife; - public class CollapsingAppBarActivity extends AppCompatActivity { - private final float APP_BAR_AUTO_COLLAPSE_RATION = 0.3F; - RecyclerView mRecyclerView; - AppBarLayout mAppBarLayout; - CoordinatorLayout mCoordinatorLayout; - private int mAppBarHeight = -1; - private int mCurrentAppBarOffset; // -height ==> 0 - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_collapsing_app_bar); - bind(); - mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); - Adapter adapter = new Adapter(this, new Adapter.Action() { - @Override - public void onClick() { + private final float APP_BAR_AUTO_COLLAPSE_RATION = 0.3F; + RecyclerView mRecyclerView; + AppBarLayout mAppBarLayout; + CoordinatorLayout mCoordinatorLayout; + private int mAppBarHeight = -1; + private int mCurrentAppBarOffset; // -height ==> 0 + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_collapsing_app_bar); + bind(); + mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); + Adapter adapter = + new Adapter( + this, + new Adapter.Action() { + @Override + public void onClick() { mAppBarLayout.setExpanded(false); + } + }); + mRecyclerView.setAdapter(adapter); + adapter.setContentCount(40); + + mAppBarLayout.addOnOffsetChangedListener( + new AppBarLayout.OnOffsetChangedListener() { + @Override + public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { + if (mAppBarHeight == -1) { + mAppBarHeight = appBarLayout.getHeight(); } + mCurrentAppBarOffset = -verticalOffset; + } }); - mRecyclerView.setAdapter(adapter); - adapter.setContentCount(40); - - mAppBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { - @Override - public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { - if (mAppBarHeight == -1) { - mAppBarHeight = appBarLayout.getHeight(); - } - mCurrentAppBarOffset = -verticalOffset; - } - }); - mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { - @Override - public void onScrollStateChanged(RecyclerView recyclerView, int newState) { - super.onScrollStateChanged(recyclerView, newState); - if (newState == RecyclerView.SCROLL_STATE_IDLE) { - if ((float) mCurrentAppBarOffset / mAppBarHeight < - APP_BAR_AUTO_COLLAPSE_RATION) { - mAppBarLayout.setExpanded(true); - } else { - mAppBarLayout.setExpanded(false); - } - } + mRecyclerView.addOnScrollListener( + new RecyclerView.OnScrollListener() { + @Override + public void onScrollStateChanged(RecyclerView recyclerView, int newState) { + super.onScrollStateChanged(recyclerView, newState); + if (newState == RecyclerView.SCROLL_STATE_IDLE) { + if ((float) mCurrentAppBarOffset / mAppBarHeight < APP_BAR_AUTO_COLLAPSE_RATION) { + mAppBarLayout.setExpanded(true); + } else { + mAppBarLayout.setExpanded(false); + } } + } }); + } + + private void bind() { + mRecyclerView = findViewById(R.id.mRecyclerView); + mAppBarLayout = findViewById(R.id.mAppBarLayout); + mCoordinatorLayout = findViewById(R.id.mCoordinatorLayout); + } + + public static class Adapter extends RecyclerView.Adapter { + + private final Context mContext; + private final Action mAction; + private int mContentCount = 0; + + public Adapter(Context context, Action action) { + mContext = context; + mAction = action; } - private void bind() { - mRecyclerView = findViewById(R.id.mRecyclerView); - mAppBarLayout = findViewById(R.id.mAppBarLayout); - mCoordinatorLayout = findViewById(R.id.mCoordinatorLayout); + public void setContentCount(int contentCount) { + mContentCount = contentCount; + notifyDataSetChanged(); } - public static class Adapter extends RecyclerView.Adapter { - - private final Context mContext; - private final Action mAction; - private int mContentCount = 0; - - public Adapter(Context context, Action action) { - mContext = context; - mAction = action; - } - - public void setContentCount(int contentCount) { - mContentCount = contentCount; - notifyDataSetChanged(); - } - - @Override - public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - return new ViewHolder(LayoutInflater.from(parent.getContext()) - .inflate(R.layout.ui_recycler_view_horizontal_item, parent, false)); - } - - @Override - public void onBindViewHolder(ViewHolder holder, final int position) { - holder.mTextView.setText(String.valueOf(holder.getAdapterPosition())); - holder.mLlContainer.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Toast.makeText(mContext, "Click: " + holder.getAdapterPosition(), Toast.LENGTH_SHORT).show(); - mAction.onClick(); - } - }); - } + @Override + public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + return new ViewHolder( + LayoutInflater.from(parent.getContext()) + .inflate(R.layout.ui_recycler_view_horizontal_item, parent, false)); + } + + @Override + public void onBindViewHolder(ViewHolder holder, final int position) { + holder.mTextView.setText(String.valueOf(holder.getAdapterPosition())); + holder.mLlContainer.setOnClickListener( + new View.OnClickListener() { + @Override + public void onClick(View v) { + Toast.makeText(mContext, "Click: " + holder.getAdapterPosition(), Toast.LENGTH_SHORT) + .show(); + mAction.onClick(); + } + }); + } - @Override - public int getItemCount() { - return mContentCount; - } + @Override + public int getItemCount() { + return mContentCount; + } - public interface Action { - void onClick(); - } + public interface Action { + void onClick(); } + } - public static class ViewHolder extends RecyclerView.ViewHolder { + public static class ViewHolder extends RecyclerView.ViewHolder { - TextView mTextView; - LinearLayout mLlContainer; + TextView mTextView; + LinearLayout mLlContainer; - public ViewHolder(View itemView) { - super(itemView); - mTextView = (TextView) itemView.findViewById(R.id.mNumber); - mLlContainer = (LinearLayout) itemView.findViewById(R.id.mLlContainer); - } + public ViewHolder(View itemView) { + super(itemView); + mTextView = (TextView) itemView.findViewById(R.id.mNumber); + mLlContainer = (LinearLayout) itemView.findViewById(R.id.mLlContainer); } + } } diff --git a/app/src/main/java/com/uber/okbuck/example/CustomView.java b/app/src/main/java/com/uber/okbuck/example/CustomView.java index d59ff121f..01aec8917 100644 --- a/app/src/main/java/com/uber/okbuck/example/CustomView.java +++ b/app/src/main/java/com/uber/okbuck/example/CustomView.java @@ -5,15 +5,15 @@ import android.util.AttributeSet; public class CustomView extends AppCompatTextView { - public CustomView(Context context) { - super(context); - } + public CustomView(Context context) { + super(context); + } - public CustomView(Context context, AttributeSet attrs) { - super(context, attrs); - } + public CustomView(Context context, AttributeSet attrs) { + super(context, attrs); + } - public CustomView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } + public CustomView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } } diff --git a/app/src/main/java/com/uber/okbuck/example/DummyComponent.java b/app/src/main/java/com/uber/okbuck/example/DummyComponent.java index 3b4ff6b4e..033bdd2fd 100644 --- a/app/src/main/java/com/uber/okbuck/example/DummyComponent.java +++ b/app/src/main/java/com/uber/okbuck/example/DummyComponent.java @@ -2,10 +2,9 @@ import com.uber.okbuck.example.dummylibrary.AndroidModule; import com.uber.okbuck.example.javalib.JavaModule; - import dagger.Component; @Component(modules = {JavaModule.class, AndroidModule.class}) public interface DummyComponent { - void inject(MainActivity activity); + void inject(MainActivity activity); } diff --git a/app/src/main/java/com/uber/okbuck/example/MainActivity.java b/app/src/main/java/com/uber/okbuck/example/MainActivity.java index c210f12b0..de2370933 100644 --- a/app/src/main/java/com/uber/okbuck/example/MainActivity.java +++ b/app/src/main/java/com/uber/okbuck/example/MainActivity.java @@ -10,7 +10,9 @@ import android.view.View; import android.widget.TextView; import android.widget.Toast; - +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.Unbinder; import com.github.piasy.rxscreenshotdetector.RxScreenshotDetector; import com.promegu.xlog.base.XLog; import com.uber.okbuck.example.common.Calc; @@ -23,106 +25,100 @@ import com.uber.okbuck.example.sqldelightmodel.GithubUser; import com.uber.okbuck.java.Pojo; import com.uber.okbuck.kotlin.KotlinDataClass; - -import javax.inject.Inject; - -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; import io.reactivex.Observer; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; +import javax.inject.Inject; @XLog public class MainActivity extends AppCompatActivity { - @Inject - DummyJavaClass mDummyJavaClass; - @Inject - DummyAndroidClass mDummyAndroidClass; - IMyAidlInterface mIMyAidlInterface; + @Inject DummyJavaClass mDummyJavaClass; + @Inject DummyAndroidClass mDummyAndroidClass; + IMyAidlInterface mIMyAidlInterface; - private Unbinder mUnbinder; + private Unbinder mUnbinder; - @BindView(R2.id.mTextView) - TextView mTextView; + @BindView(R2.id.mTextView) + TextView mTextView; - @BindView(R2.id.mTextView2) - TextView mTextView2; + @BindView(R2.id.mTextView2) + TextView mTextView2; - private ServiceConnection mServiceConnection = new ServiceConnection() { + private ServiceConnection mServiceConnection = + new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { - mIMyAidlInterface = IMyAidlInterface.Stub.asInterface(service); + mIMyAidlInterface = IMyAidlInterface.Stub.asInterface(service); } @Override public void onServiceDisconnected(ComponentName name) { - mIMyAidlInterface = null; + mIMyAidlInterface = null; } - }; + }; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - mUnbinder = ButterKnife.bind(this); + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + mUnbinder = ButterKnife.bind(this); - View view = findViewById(android.R.id.content); - if (view != null) { - view.setOnClickListener(v -> Log.d("TAG", "Hello, lambda! My view is: " + v)); - } - - DummyComponent component = DaggerDummyComponent.builder().build(); - component.inject(this); - - mTextView.setText( - String.format("%s %s, --from %s.", getString(R.string.dummy_library_android_str), - mDummyAndroidClass.getAndroidWord(this), mDummyJavaClass.getJavaWord())); - - if (BuildConfig.CAN_JUMP) { - mTextView.setOnClickListener( - v -> startActivity(new Intent(MainActivity.this, DummyActivity.class))); - } - - Log.d("test", "1 + 2 = " + new Calc(new CalcMonitor(this)).add(1, 2)); - - RxScreenshotDetector.start(this) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onComplete() { - - } - - @Override - public void onError(Throwable e) { - e.printStackTrace(); - } - - @Override - public void onNext(String path) { - mTextView.setText(mTextView.getText() + "\nScreenshot: " + path); - } + View view = findViewById(android.R.id.content); + if (view != null) { + view.setOnClickListener(v -> Log.d("TAG", "Hello, lambda! My view is: " + v)); + } - @Override - public void onSubscribe(Disposable disposable) { + DummyComponent component = DaggerDummyComponent.builder().build(); + component.inject(this); - } - }); - GithubUser user = GithubUser.create(100, "OkBuck"); - Toast.makeText(this, user.login(), Toast.LENGTH_SHORT).show(); - GithubRepo repo = GithubRepo.create(100, "OkBuck", "auto buck"); - Toast.makeText(this, repo.name() + ": " + repo.description(), Toast.LENGTH_SHORT).show(); + mTextView.setText( + String.format( + "%s %s, --from %s.", + getString(R.string.dummy_library_android_str), + mDummyAndroidClass.getAndroidWord(this), + mDummyJavaClass.getJavaWord())); - KotlinDataClass data = new KotlinDataClass("foo", R.string.foo); - Pojo pojo = new Pojo(); + if (BuildConfig.CAN_JUMP) { + mTextView.setOnClickListener( + v -> startActivity(new Intent(MainActivity.this, DummyActivity.class))); } - @Override - protected void onDestroy() { - mUnbinder.unbind(); - super.onDestroy(); - } + Log.d("test", "1 + 2 = " + new Calc(new CalcMonitor(this)).add(1, 2)); + + RxScreenshotDetector.start(this) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe( + new Observer() { + @Override + public void onComplete() {} + + @Override + public void onError(Throwable e) { + e.printStackTrace(); + } + + @Override + public void onNext(String path) { + mTextView.setText(mTextView.getText() + "\nScreenshot: " + path); + } + + @Override + public void onSubscribe(Disposable disposable) {} + }); + GithubUser user = GithubUser.create(100, "OkBuck"); + Toast.makeText(this, user.login(), Toast.LENGTH_SHORT).show(); + GithubRepo repo = GithubRepo.create(100, "OkBuck", "auto buck"); + Toast.makeText(this, repo.name() + ": " + repo.description(), Toast.LENGTH_SHORT).show(); + + KotlinDataClass data = new KotlinDataClass("foo", R.string.foo); + Pojo pojo = new Pojo(); + } + + @Override + protected void onDestroy() { + mUnbinder.unbind(); + super.onDestroy(); + } } diff --git a/app/src/main/java/com/uber/okbuck/example/MyApp.java b/app/src/main/java/com/uber/okbuck/example/MyApp.java index cc3eace2c..cfe6d43b2 100644 --- a/app/src/main/java/com/uber/okbuck/example/MyApp.java +++ b/app/src/main/java/com/uber/okbuck/example/MyApp.java @@ -2,29 +2,28 @@ import android.app.Application; import android.support.v7.app.AppCompatDelegate; - import com.facebook.buck.android.support.exopackage.DefaultApplicationLike; import com.github.promeg.xlog_android.lib.XLogConfig; import com.squareup.leakcanary.LeakCanary; public class MyApp extends DefaultApplicationLike { - static { - AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); - } + static { + AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); + } - private final Application mApplication; + private final Application mApplication; - public MyApp(Application application) { - mApplication = application; - } + public MyApp(Application application) { + mApplication = application; + } - @Override - public void onCreate() { - super.onCreate(); - if (BuildConfig.XLOG_ENABLED) { - XLogConfig.config(XLogConfig.newConfigBuilder(mApplication).build()); - } - LeakCanary.install(mApplication); + @Override + public void onCreate() { + super.onCreate(); + if (BuildConfig.XLOG_ENABLED) { + XLogConfig.config(XLogConfig.newConfigBuilder(mApplication).build()); } + LeakCanary.install(mApplication); + } } diff --git a/app/src/main/java/com/uber/okbuck/example/sqldelightmodel/GithubRepo.java b/app/src/main/java/com/uber/okbuck/example/sqldelightmodel/GithubRepo.java index fdf1040f5..664fbad24 100644 --- a/app/src/main/java/com/uber/okbuck/example/sqldelightmodel/GithubRepo.java +++ b/app/src/main/java/com/uber/okbuck/example/sqldelightmodel/GithubRepo.java @@ -6,11 +6,11 @@ @AutoValue public abstract class GithubRepo implements GithubRepoModel { - public static TypeAdapter typeAdapter(final Gson gson) { - return new AutoValue_GithubRepo.GsonTypeAdapter(gson); - } + public static TypeAdapter typeAdapter(final Gson gson) { + return new AutoValue_GithubRepo.GsonTypeAdapter(gson); + } - public static GithubRepo create(long id, String name, String desc) { - return new AutoValue_GithubRepo(id, name, desc); - } + public static GithubRepo create(long id, String name, String desc) { + return new AutoValue_GithubRepo(id, name, desc); + } } diff --git a/app/src/main/java/com/uber/okbuck/example/sqldelightmodel/GithubUser.java b/app/src/main/java/com/uber/okbuck/example/sqldelightmodel/GithubUser.java index 67baba4a1..bbbe06392 100644 --- a/app/src/main/java/com/uber/okbuck/example/sqldelightmodel/GithubUser.java +++ b/app/src/main/java/com/uber/okbuck/example/sqldelightmodel/GithubUser.java @@ -6,11 +6,11 @@ @AutoValue public abstract class GithubUser implements GithubUserModel { - public static TypeAdapter typeAdapter(final Gson gson) { - return new AutoValue_GithubUser.GsonTypeAdapter(gson); - } + public static TypeAdapter typeAdapter(final Gson gson) { + return new AutoValue_GithubUser.GsonTypeAdapter(gson); + } - public static GithubUser create(long id, String login) { - return new AutoValue_GithubUser(id, login); - } + public static GithubUser create(long id, String login) { + return new AutoValue_GithubUser(id, login); + } } diff --git a/app/src/prod/java/com/uber/okbuck/example/FlavorLogger.java b/app/src/prod/java/com/uber/okbuck/example/FlavorLogger.java index 40920a585..8072d0685 100644 --- a/app/src/prod/java/com/uber/okbuck/example/FlavorLogger.java +++ b/app/src/prod/java/com/uber/okbuck/example/FlavorLogger.java @@ -4,7 +4,7 @@ public class FlavorLogger { - public static String log(Context context) { - return "FlavorLogger, prod, " + context.getString(R.string.flavor_string); - } + public static String log(Context context) { + return "FlavorLogger, prod, " + context.getString(R.string.flavor_string); + } } diff --git a/app/src/test/java/com/uber/okbuck/ExampleUnitTest.java b/app/src/test/java/com/uber/okbuck/ExampleUnitTest.java index ab0f7611b..ccfb98d08 100644 --- a/app/src/test/java/com/uber/okbuck/ExampleUnitTest.java +++ b/app/src/test/java/com/uber/okbuck/ExampleUnitTest.java @@ -1,27 +1,24 @@ package com.uber.okbuck; -import com.uber.okbuck.example.common.Calc; -import com.uber.okbuck.example.common.CalcMonitor; - -import org.junit.Test; - import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.only; import static org.mockito.Mockito.verify; -/** - * To work on unit tests, switch the Test Artifact in the Build Variants view. - */ +import com.uber.okbuck.example.common.Calc; +import com.uber.okbuck.example.common.CalcMonitor; +import org.junit.Test; + +/** To work on unit tests, switch the Test Artifact in the Build Variants view. */ public class ExampleUnitTest { - @Test - public void testAdd() throws Exception { - CalcMonitor monitor = mock(CalcMonitor.class); - Calc calc = new Calc(monitor); + @Test + public void testAdd() throws Exception { + CalcMonitor monitor = mock(CalcMonitor.class); + Calc calc = new Calc(monitor); - int ret = calc.add(1, 2); - verify(monitor, only()).addCalled(any(String.class)); - assertEquals(3, ret); - } + int ret = calc.add(1, 2); + verify(monitor, only()).addCalled(any(String.class)); + assertEquals(3, ret); + } } diff --git a/dummy-transform/src/main/java/com/uber/okbuck/transform/DummyTransform.java b/dummy-transform/src/main/java/com/uber/okbuck/transform/DummyTransform.java index a4ec2ea7f..fbe15be9c 100644 --- a/dummy-transform/src/main/java/com/uber/okbuck/transform/DummyTransform.java +++ b/dummy-transform/src/main/java/com/uber/okbuck/transform/DummyTransform.java @@ -12,7 +12,6 @@ import com.android.build.api.transform.TransformInvocation; import com.android.utils.FileUtils; import com.google.common.collect.ImmutableSet; - import java.io.File; import java.io.IOException; import java.util.Map; @@ -20,98 +19,103 @@ public class DummyTransform extends Transform { - private static final String TRANSFORM_NAME = "DummyTransform"; - private static final String TRANSFORM_OUTPUT = "dummy-transform-output"; - - @Override - public String getName() { - return TRANSFORM_NAME; - } - - @NonNull - @Override - public Set getInputTypes() { - return ImmutableSet.of(QualifiedContent.DefaultContentType.CLASSES); + private static final String TRANSFORM_NAME = "DummyTransform"; + private static final String TRANSFORM_OUTPUT = "dummy-transform-output"; + + @Override + public String getName() { + return TRANSFORM_NAME; + } + + @NonNull + @Override + public Set getInputTypes() { + return ImmutableSet.of( + QualifiedContent.DefaultContentType.CLASSES); + } + + @NonNull + @Override + public Set getScopes() { + return ImmutableSet.of(QualifiedContent.Scope.PROJECT, QualifiedContent.Scope.SUB_PROJECTS); + } + + @NonNull + @Override + public Set getReferencedScopes() { + return ImmutableSet.of( + QualifiedContent.Scope.SUB_PROJECTS, + QualifiedContent.Scope.PROJECT_LOCAL_DEPS, + QualifiedContent.Scope.SUB_PROJECTS_LOCAL_DEPS, + QualifiedContent.Scope.EXTERNAL_LIBRARIES); + } + + @Override + public boolean isIncremental() { + return true; + } + + @Override + public void transform(TransformInvocation transformInvocation) + throws TransformException, InterruptedException, IOException { + + if (transformInvocation.getOutputProvider() == null) { + throw new IllegalArgumentException("Transform invocation needs a valid output provider."); } - @NonNull - @Override - public Set getScopes() { - return ImmutableSet.of(QualifiedContent.Scope.PROJECT, QualifiedContent.Scope.SUB_PROJECTS); - } - - @NonNull - @Override - public Set getReferencedScopes() { - return ImmutableSet.of( - QualifiedContent.Scope.SUB_PROJECTS, - QualifiedContent.Scope.PROJECT_LOCAL_DEPS, - QualifiedContent.Scope.SUB_PROJECTS_LOCAL_DEPS, - QualifiedContent.Scope.EXTERNAL_LIBRARIES); - } + File outputDir = + transformInvocation + .getOutputProvider() + .getContentLocation(TRANSFORM_OUTPUT, getOutputTypes(), getScopes(), Format.DIRECTORY); - @Override - public boolean isIncremental() { - return true; - } + for (TransformInput input : transformInvocation.getInputs()) { - @Override - public void transform(TransformInvocation transformInvocation) - throws TransformException, InterruptedException, IOException { + for (JarInput inputJar : input.getJarInputs()) { + File outputJar = + transformInvocation + .getOutputProvider() + .getContentLocation(inputJar.getName(), getOutputTypes(), getScopes(), Format.JAR); + outputJar.getParentFile().mkdirs(); - if (transformInvocation.getOutputProvider() == null) { - throw new IllegalArgumentException("Transform invocation needs a valid output provider."); + if (!transformInvocation.isIncremental() || inputJar.getStatus() != Status.REMOVED) { + FileUtils.copyFile(inputJar.getFile(), outputJar); } + } - File outputDir = transformInvocation.getOutputProvider().getContentLocation( - TRANSFORM_OUTPUT, getOutputTypes(), getScopes(), Format.DIRECTORY); + for (DirectoryInput directoryInput : input.getDirectoryInputs()) { - for (TransformInput input : transformInvocation.getInputs()) { + File inputDir = directoryInput.getFile(); + if (transformInvocation.isIncremental()) { - for (JarInput inputJar : input.getJarInputs()) { - File outputJar = transformInvocation.getOutputProvider() - .getContentLocation(inputJar.getName(), getOutputTypes(), getScopes(), Format.JAR); - outputJar.getParentFile().mkdirs(); + for (Map.Entry changedInput : directoryInput.getChangedFiles().entrySet()) { - if (!transformInvocation.isIncremental() || inputJar.getStatus() != Status.REMOVED) { - FileUtils.copyFile(inputJar.getFile(), outputJar); - } - } - - for (DirectoryInput directoryInput : input.getDirectoryInputs()) { - - File inputDir = directoryInput.getFile(); - if (transformInvocation.isIncremental()) { - - for (Map.Entry changedInput : directoryInput.getChangedFiles().entrySet()) { + File inputFile = changedInput.getKey(); + File outputFile = + new File(outputDir, FileUtils.relativePossiblyNonExistingPath(inputFile, inputDir)); - File inputFile = changedInput.getKey(); - File outputFile = new File(outputDir, FileUtils.relativePossiblyNonExistingPath(inputFile, inputDir)); + switch (changedInput.getValue()) { + case REMOVED: + FileUtils.delete(outputFile); + break; - switch (changedInput.getValue()) { - - case REMOVED: - FileUtils.delete(outputFile); - break; - - case ADDED: - case CHANGED: - FileUtils.copyFile(inputFile, outputFile); - } - } - } else { + case ADDED: + case CHANGED: + FileUtils.copyFile(inputFile, outputFile); + } + } + } else { - FileUtils.deleteDirectoryContents(inputDir); - inputDir.mkdirs(); + FileUtils.deleteDirectoryContents(inputDir); + inputDir.mkdirs(); - Iterable files = FileUtils.getAllFiles(inputDir); - for (File inputFile : files) { + Iterable files = FileUtils.getAllFiles(inputDir); + for (File inputFile : files) { - File outputFile = new File(outputDir, FileUtils.relativePath(inputFile, inputDir)); - FileUtils.copyFile(inputFile, outputFile); - } - } - } + File outputFile = new File(outputDir, FileUtils.relativePath(inputFile, inputDir)); + FileUtils.copyFile(inputFile, outputFile); + } } + } } + } } diff --git a/dummylibrary/src/com/uber/okbuck/example/dummylibrary/AndroidModule.java b/dummylibrary/src/com/uber/okbuck/example/dummylibrary/AndroidModule.java index 53e5bdc67..71d099601 100644 --- a/dummylibrary/src/com/uber/okbuck/example/dummylibrary/AndroidModule.java +++ b/dummylibrary/src/com/uber/okbuck/example/dummylibrary/AndroidModule.java @@ -5,8 +5,8 @@ @Module public class AndroidModule { - @Provides - DummyAndroidClass provideDummyAndroidClass() { - return new DummyAndroidClass(); - } + @Provides + DummyAndroidClass provideDummyAndroidClass() { + return new DummyAndroidClass(); + } } diff --git a/dummylibrary/src/com/uber/okbuck/example/dummylibrary/DummyActivity.java b/dummylibrary/src/com/uber/okbuck/example/dummylibrary/DummyActivity.java index 4de8197bb..9a40e0ba1 100644 --- a/dummylibrary/src/com/uber/okbuck/example/dummylibrary/DummyActivity.java +++ b/dummylibrary/src/com/uber/okbuck/example/dummylibrary/DummyActivity.java @@ -2,24 +2,21 @@ import android.app.Activity; import android.os.Bundle; - import com.uber.okbuck.example.common.CalcMonitor; import com.uber.okbuck.example.javalib.DummyJavaClass; public class DummyActivity extends Activity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - String mock = "Mock string from DummyActivity"; - new Thread(() -> System.out.println(mock + " 1")).start(); - dummyCall(System.out::println, mock + " 2"); - CalcMonitor calcMonitor = new CalcMonitor(this); - } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); - private void dummyCall(DummyJavaClass.DummyInterface dummyInterface, String val) { - dummyInterface.call(val); - } + String mock = "Mock string from DummyActivity"; + new Thread(() -> System.out.println(mock + " 1")).start(); + dummyCall(System.out::println, mock + " 2"); + CalcMonitor calcMonitor = new CalcMonitor(this); + } + private void dummyCall(DummyJavaClass.DummyInterface dummyInterface, String val) { + dummyInterface.call(val); + } } - diff --git a/dummylibrary/src/com/uber/okbuck/example/dummylibrary/DummyAndroidClass.java b/dummylibrary/src/com/uber/okbuck/example/dummylibrary/DummyAndroidClass.java index 6cb315e39..465749fb8 100644 --- a/dummylibrary/src/com/uber/okbuck/example/dummylibrary/DummyAndroidClass.java +++ b/dummylibrary/src/com/uber/okbuck/example/dummylibrary/DummyAndroidClass.java @@ -2,17 +2,16 @@ import android.content.Context; import android.widget.Toast; - import com.google.gson.GsonBuilder; public class DummyAndroidClass { - public String getAndroidWord(Context context) { - Toast.makeText(context, "getAndroidWord: Dummy", Toast.LENGTH_SHORT).show(); - String mock = "{\"lang\":\"" + context.getString(R.string.dummy_library_android_str) + "\"}"; - return new GsonBuilder().create().fromJson(mock, DummyObject.class).lang; - } + public String getAndroidWord(Context context) { + Toast.makeText(context, "getAndroidWord: Dummy", Toast.LENGTH_SHORT).show(); + String mock = "{\"lang\":\"" + context.getString(R.string.dummy_library_android_str) + "\"}"; + return new GsonBuilder().create().fromJson(mock, DummyObject.class).lang; + } - private static class DummyObject { - private String lang; - } + private static class DummyObject { + private String lang; + } } diff --git a/dummylibrary/test/com/uber/okbuck/example/dummylibrary/ExampleUnitTest.java b/dummylibrary/test/com/uber/okbuck/example/dummylibrary/ExampleUnitTest.java index 68564755d..6803e6916 100644 --- a/dummylibrary/test/com/uber/okbuck/example/dummylibrary/ExampleUnitTest.java +++ b/dummylibrary/test/com/uber/okbuck/example/dummylibrary/ExampleUnitTest.java @@ -1,12 +1,12 @@ package com.uber.okbuck.example.dummylibrary; -import org.junit.Test; - import static org.junit.Assert.*; +import org.junit.Test; + public class ExampleUnitTest { - @Test - public void addition_isCorrect() throws Exception { - assertEquals(4, 2 + 2); - } + @Test + public void addition_isCorrect() throws Exception { + assertEquals(4, 2 + 2); + } } diff --git a/java-app/src/main/java/com/uber/okbuck/example/javabin/DummyJavaClass.java b/java-app/src/main/java/com/uber/okbuck/example/javabin/DummyJavaClass.java index 801a8b07a..a1570c329 100644 --- a/java-app/src/main/java/com/uber/okbuck/example/javabin/DummyJavaClass.java +++ b/java-app/src/main/java/com/uber/okbuck/example/javabin/DummyJavaClass.java @@ -1,31 +1,27 @@ package com.uber.okbuck.example.javalib; -import com.google.gson.GsonBuilder; - import org.apache.avro.TypeEnum; import org.apache.avro.ipc.HandshakeMatch; - public class DummyJavaClass { - public void dummyMethod() { - // Added to make sure classifiers work properly - // From avro-ipc jar - System.out.println(HandshakeMatch.BOTH); - - // From avro-ipc tests jar - System.out.println(TypeEnum.a); - } - - private void dummyCall(DummyInterface dummyInterface, String val) { - dummyInterface.call(val); - } - - public interface DummyInterface { - void call(String v); - } - - private static class DummyObject { - private String lang; - } + public void dummyMethod() { + // Added to make sure classifiers work properly + // From avro-ipc jar + System.out.println(HandshakeMatch.BOTH); + + // From avro-ipc tests jar + System.out.println(TypeEnum.a); + } + + private void dummyCall(DummyInterface dummyInterface, String val) { + dummyInterface.call(val); + } + + public interface DummyInterface { + void call(String v); + } + + private static class DummyObject { + private String lang; + } } - diff --git a/kotlin-app/src/test/java/com/uber/okbuck/example/ExampleUnitTest.java b/kotlin-app/src/test/java/com/uber/okbuck/example/ExampleUnitTest.java index 588ea7263..f39c9c9e9 100644 --- a/kotlin-app/src/test/java/com/uber/okbuck/example/ExampleUnitTest.java +++ b/kotlin-app/src/test/java/com/uber/okbuck/example/ExampleUnitTest.java @@ -1,17 +1,17 @@ package com.uber.okbuck.example; -import org.junit.Test; - import static org.junit.Assert.*; +import org.junit.Test; + /** * Example local unit test, which will execute on the development machine (host). * * @see Testing documentation */ public class ExampleUnitTest { - @Test - public void addition_isCorrect () throws Exception { - assertEquals(4, 2 + 2); - } + @Test + public void addition_isCorrect() throws Exception { + assertEquals(4, 2 + 2); + } } diff --git a/libraries/common/src/androidTest/java/com/uber/okbuck/example/common/ApplicationTest.java b/libraries/common/src/androidTest/java/com/uber/okbuck/example/common/ApplicationTest.java index 85908a2e2..9beb39bdd 100644 --- a/libraries/common/src/androidTest/java/com/uber/okbuck/example/common/ApplicationTest.java +++ b/libraries/common/src/androidTest/java/com/uber/okbuck/example/common/ApplicationTest.java @@ -4,7 +4,7 @@ import android.test.ApplicationTestCase; public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } + public ApplicationTest() { + super(Application.class); + } } diff --git a/libraries/common/src/freeDebug/java/com/uber/okbuck/example/common/CalcMonitor.java b/libraries/common/src/freeDebug/java/com/uber/okbuck/example/common/CalcMonitor.java index fc1548d94..f709f41a8 100644 --- a/libraries/common/src/freeDebug/java/com/uber/okbuck/example/common/CalcMonitor.java +++ b/libraries/common/src/freeDebug/java/com/uber/okbuck/example/common/CalcMonitor.java @@ -4,14 +4,20 @@ import android.widget.Toast; public class CalcMonitor { - private final Context mContext; + private final Context mContext; - public CalcMonitor(Context context) { - mContext = context; - } + public CalcMonitor(Context context) { + mContext = context; + } - public void addCalled(String config) { - Toast.makeText(mContext, "addCalled from freeDebug: " + config + ", " + mContext - .getString(R.string.common_string), Toast.LENGTH_SHORT).show(); - } + public void addCalled(String config) { + Toast.makeText( + mContext, + "addCalled from freeDebug: " + + config + + ", " + + mContext.getString(R.string.common_string), + Toast.LENGTH_SHORT) + .show(); + } } diff --git a/libraries/common/src/freeRelease/java/com/uber/okbuck/example/common/CalcMonitor.java b/libraries/common/src/freeRelease/java/com/uber/okbuck/example/common/CalcMonitor.java index 1a9413ddb..f195c857f 100644 --- a/libraries/common/src/freeRelease/java/com/uber/okbuck/example/common/CalcMonitor.java +++ b/libraries/common/src/freeRelease/java/com/uber/okbuck/example/common/CalcMonitor.java @@ -4,14 +4,20 @@ import android.widget.Toast; public class CalcMonitor { - private final Context mContext; + private final Context mContext; - public CalcMonitor(Context context) { - mContext = context; - } + public CalcMonitor(Context context) { + mContext = context; + } - public void addCalled(String config) { - Toast.makeText(mContext, "addCalled from freeRelease: " + config + ", " + mContext - .getString(R.string.common_string), Toast.LENGTH_SHORT).show(); - } + public void addCalled(String config) { + Toast.makeText( + mContext, + "addCalled from freeRelease: " + + config + + ", " + + mContext.getString(R.string.common_string), + Toast.LENGTH_SHORT) + .show(); + } } diff --git a/libraries/common/src/main/java/com/uber/okbuck/example/common/Calc.java b/libraries/common/src/main/java/com/uber/okbuck/example/common/Calc.java index f81222458..d80491f96 100644 --- a/libraries/common/src/main/java/com/uber/okbuck/example/common/Calc.java +++ b/libraries/common/src/main/java/com/uber/okbuck/example/common/Calc.java @@ -1,14 +1,14 @@ package com.uber.okbuck.example.common; public class Calc { - private final CalcMonitor mCalcMonitor; + private final CalcMonitor mCalcMonitor; - public Calc(CalcMonitor calcMonitor) { - mCalcMonitor = calcMonitor; - } + public Calc(CalcMonitor calcMonitor) { + mCalcMonitor = calcMonitor; + } - public int add(int a, int b) { - mCalcMonitor.addCalled("flavor"); - return a + b; - } + public int add(int a, int b) { + mCalcMonitor.addCalled("flavor"); + return a + b; + } } diff --git a/libraries/common/src/paidDebug/java/com/uber/okbuck/example/common/CalcMonitor.java b/libraries/common/src/paidDebug/java/com/uber/okbuck/example/common/CalcMonitor.java index dce68529e..fae8ec250 100644 --- a/libraries/common/src/paidDebug/java/com/uber/okbuck/example/common/CalcMonitor.java +++ b/libraries/common/src/paidDebug/java/com/uber/okbuck/example/common/CalcMonitor.java @@ -5,14 +5,20 @@ public class CalcMonitor { - private final Context mContext; + private final Context mContext; - public CalcMonitor(Context context) { - mContext = context; - } + public CalcMonitor(Context context) { + mContext = context; + } - public void addCalled(String config) { - Toast.makeText(mContext, "addCalled from paidDebug: " + config + ", " + mContext - .getString(R.string.common_string), Toast.LENGTH_SHORT).show(); - } + public void addCalled(String config) { + Toast.makeText( + mContext, + "addCalled from paidDebug: " + + config + + ", " + + mContext.getString(R.string.common_string), + Toast.LENGTH_SHORT) + .show(); + } } diff --git a/libraries/common/src/paidRelease/java/com/uber/okbuck/example/common/CalcMonitor.java b/libraries/common/src/paidRelease/java/com/uber/okbuck/example/common/CalcMonitor.java index b305f05b2..1b4491b52 100644 --- a/libraries/common/src/paidRelease/java/com/uber/okbuck/example/common/CalcMonitor.java +++ b/libraries/common/src/paidRelease/java/com/uber/okbuck/example/common/CalcMonitor.java @@ -5,14 +5,20 @@ public class CalcMonitor { - private final Context mContext; + private final Context mContext; - public CalcMonitor(Context context) { - mContext = context; - } + public CalcMonitor(Context context) { + mContext = context; + } - public void addCalled(String config) { - Toast.makeText(mContext, "addCalled from paidRelease: " + config + ", " + mContext - .getString(R.string.common_string), Toast.LENGTH_SHORT).show(); - } + public void addCalled(String config) { + Toast.makeText( + mContext, + "addCalled from paidRelease: " + + config + + ", " + + mContext.getString(R.string.common_string), + Toast.LENGTH_SHORT) + .show(); + } } diff --git a/libraries/customLintLibrary/src/main/java/com/uber/lint/LintRegistry.java b/libraries/customLintLibrary/src/main/java/com/uber/lint/LintRegistry.java index 84947e7e1..4e7dd5120 100644 --- a/libraries/customLintLibrary/src/main/java/com/uber/lint/LintRegistry.java +++ b/libraries/customLintLibrary/src/main/java/com/uber/lint/LintRegistry.java @@ -3,13 +3,12 @@ import com.android.tools.lint.client.api.IssueRegistry; import com.android.tools.lint.detector.api.Issue; import com.google.common.collect.ImmutableList; - import java.util.List; public class LintRegistry extends IssueRegistry { - @Override - public List getIssues() { - return ImmutableList.of(SystemCurrentTimeMillisDetector.ISSUE); - } + @Override + public List getIssues() { + return ImmutableList.of(SystemCurrentTimeMillisDetector.ISSUE); + } } diff --git a/libraries/customLintLibrary/src/main/java/com/uber/lint/SystemCurrentTimeMillisDetector.java b/libraries/customLintLibrary/src/main/java/com/uber/lint/SystemCurrentTimeMillisDetector.java index 816032545..e97daa39f 100644 --- a/libraries/customLintLibrary/src/main/java/com/uber/lint/SystemCurrentTimeMillisDetector.java +++ b/libraries/customLintLibrary/src/main/java/com/uber/lint/SystemCurrentTimeMillisDetector.java @@ -9,51 +9,49 @@ import com.android.tools.lint.detector.api.Scope; import com.android.tools.lint.detector.api.Severity; import com.intellij.psi.PsiMethod; -import org.jetbrains.uast.UCallExpression; - import java.util.Collections; import java.util.List; +import org.jetbrains.uast.UCallExpression; -/** - * Custom Lint Check to prevent useage of System.currentTimeMillis. - */ +/** Custom Lint Check to prevent useage of System.currentTimeMillis. */ public class SystemCurrentTimeMillisDetector extends Detector implements Detector.UastScanner { - public static final String CHECK_METHOD_TO_EXCLUDE = "currentTimeMillis"; - public static final String CHECK_PACKAGE_TO_EXCLUDE = "java.lang.System"; + public static final String CHECK_METHOD_TO_EXCLUDE = "currentTimeMillis"; + public static final String CHECK_PACKAGE_TO_EXCLUDE = "java.lang.System"; - public static final String ISSUE_ID = "DontUseSystemTime"; - public static final Issue ISSUE = Issue.create( - ISSUE_ID, - "Don't use System.currentTimeMillis()", - "This method is blocked from useage. This can't be easily mocked, injected, or tested.", - Category.CORRECTNESS, - 6, - Severity.ERROR, - new Implementation(SystemCurrentTimeMillisDetector.class, Scope.JAVA_FILE_SCOPE) - ); + public static final String ISSUE_ID = "DontUseSystemTime"; + public static final Issue ISSUE = + Issue.create( + ISSUE_ID, + "Don't use System.currentTimeMillis()", + "This method is blocked from useage. This can't be easily mocked, injected, or tested.", + Category.CORRECTNESS, + 6, + Severity.ERROR, + new Implementation(SystemCurrentTimeMillisDetector.class, Scope.JAVA_FILE_SCOPE)); - /** - * Determine the method names we are interested in for this check. - * - * @return a list representing the method names to check - */ - @Nullable - @Override - public List getApplicableMethodNames() { - return Collections.singletonList(CHECK_METHOD_TO_EXCLUDE); - } + /** + * Determine the method names we are interested in for this check. + * + * @return a list representing the method names to check + */ + @Nullable + @Override + public List getApplicableMethodNames() { + return Collections.singletonList(CHECK_METHOD_TO_EXCLUDE); + } - /** - * Check that the currentTimeMillis() came from the System package, if so raise an error. - * - * @param context - * @param node - * @param method - */ - @Override - public void visitMethod(JavaContext context, UCallExpression node, PsiMethod method) { - String message = "System.currentTimeMillis() should not be used as this can't be easily mocked and tested."; - context.report(ISSUE, node, context.getLocation(node), message); - } + /** + * Check that the currentTimeMillis() came from the System package, if so raise an error. + * + * @param context + * @param node + * @param method + */ + @Override + public void visitMethod(JavaContext context, UCallExpression node, PsiMethod method) { + String message = + "System.currentTimeMillis() should not be used as this can't be easily mocked and tested."; + context.report(ISSUE, node, context.getLocation(node), message); + } } diff --git a/libraries/emptylibrary/src/main/java/com/uber/okbuck/example/empty/MyClass.java b/libraries/emptylibrary/src/main/java/com/uber/okbuck/example/empty/MyClass.java index a6bdc2d32..3acddcc80 100644 --- a/libraries/emptylibrary/src/main/java/com/uber/okbuck/example/empty/MyClass.java +++ b/libraries/emptylibrary/src/main/java/com/uber/okbuck/example/empty/MyClass.java @@ -1,4 +1,3 @@ package com.uber.okbuck.example.empty; -public class MyClass { -} +public class MyClass {} diff --git a/libraries/emptylibrary/src/test/java/com/uber/okbuck/example/empty/EmptyLibraryUnitTest.java b/libraries/emptylibrary/src/test/java/com/uber/okbuck/example/empty/EmptyLibraryUnitTest.java index 86796ccaa..c25b258f3 100644 --- a/libraries/emptylibrary/src/test/java/com/uber/okbuck/example/empty/EmptyLibraryUnitTest.java +++ b/libraries/emptylibrary/src/test/java/com/uber/okbuck/example/empty/EmptyLibraryUnitTest.java @@ -1,24 +1,26 @@ package com.uber.okbuck.example.empty; +import static org.junit.Assert.assertEquals; + import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; -import static org.junit.Assert.assertEquals; - @RunWith(RobolectricTestRunner.class) @Config(sdk = 27, packageName = "com.uber.okbuck.example.empty") public class EmptyLibraryUnitTest { - @Test - public void addition_isCorrect() throws Exception { - assertEquals(4, 2 + 2); - } + @Test + public void addition_isCorrect() throws Exception { + assertEquals(4, 2 + 2); + } - @Test - public void resource_loading() { - assertEquals(RuntimeEnvironment.application.getResources().getString(R.string.empty_release_string), "empty_release_string"); - } + @Test + public void resource_loading() { + assertEquals( + RuntimeEnvironment.application.getResources().getString(R.string.empty_release_string), + "empty_release_string"); + } } diff --git a/libraries/groovylibrary/src/main/java/com/uber/okbuck/groovy/example/DummyJava.java b/libraries/groovylibrary/src/main/java/com/uber/okbuck/groovy/example/DummyJava.java index 27b238762..0d6d69d57 100644 --- a/libraries/groovylibrary/src/main/java/com/uber/okbuck/groovy/example/DummyJava.java +++ b/libraries/groovylibrary/src/main/java/com/uber/okbuck/groovy/example/DummyJava.java @@ -2,7 +2,7 @@ public class DummyJava { - static int add(int a, int b) { - return a + b; - } + static int add(int a, int b) { + return a + b; + } } diff --git a/libraries/javalibrary/src/main/java/com/uber/okbuck/example/javalib/DummyJavaClass.java b/libraries/javalibrary/src/main/java/com/uber/okbuck/example/javalib/DummyJavaClass.java index c5c93f13f..2e72f8027 100644 --- a/libraries/javalibrary/src/main/java/com/uber/okbuck/example/javalib/DummyJavaClass.java +++ b/libraries/javalibrary/src/main/java/com/uber/okbuck/example/javalib/DummyJavaClass.java @@ -3,24 +3,23 @@ import com.google.gson.GsonBuilder; public class DummyJavaClass { - public String getJavaWord() { - String mock = "{\"lang\":\"Java\"}"; - final String mock2 = "Mock string from DummyJavaClass"; - new Thread(() -> System.out.println(mock2 + " 1")).start(); - dummyCall(System.out::println, mock2 + " 2"); - return new GsonBuilder().create().fromJson(mock, DummyObject.class).lang; - } + public String getJavaWord() { + String mock = "{\"lang\":\"Java\"}"; + final String mock2 = "Mock string from DummyJavaClass"; + new Thread(() -> System.out.println(mock2 + " 1")).start(); + dummyCall(System.out::println, mock2 + " 2"); + return new GsonBuilder().create().fromJson(mock, DummyObject.class).lang; + } - private void dummyCall(DummyInterface dummyInterface, String val) { - dummyInterface.call(val); - } + private void dummyCall(DummyInterface dummyInterface, String val) { + dummyInterface.call(val); + } - public interface DummyInterface { - void call(String v); - } + public interface DummyInterface { + void call(String v); + } - private static class DummyObject { - private String lang; - } + private static class DummyObject { + private String lang; + } } - diff --git a/libraries/javalibrary/src/main/java/com/uber/okbuck/example/javalib/JavaModule.java b/libraries/javalibrary/src/main/java/com/uber/okbuck/example/javalib/JavaModule.java index f20a53867..7d052e8f4 100644 --- a/libraries/javalibrary/src/main/java/com/uber/okbuck/example/javalib/JavaModule.java +++ b/libraries/javalibrary/src/main/java/com/uber/okbuck/example/javalib/JavaModule.java @@ -5,8 +5,8 @@ @Module public class JavaModule { - @Provides - DummyJavaClass provideDummyJavaClass() { - return new DummyJavaClass(); - } + @Provides + DummyJavaClass provideDummyJavaClass() { + return new DummyJavaClass(); + } } diff --git a/libraries/javalibrary/src/test/java/com/uber/okbuck/example/javalib/DummyTestJavaClass.java b/libraries/javalibrary/src/test/java/com/uber/okbuck/example/javalib/DummyTestJavaClass.java index 366efe925..2f2b8d246 100644 --- a/libraries/javalibrary/src/test/java/com/uber/okbuck/example/javalib/DummyTestJavaClass.java +++ b/libraries/javalibrary/src/test/java/com/uber/okbuck/example/javalib/DummyTestJavaClass.java @@ -1,15 +1,13 @@ package com.uber.okbuck.example.javalib; -import org.junit.Test; - import static org.junit.Assert.assertFalse; -public class DummyTestJavaClass { +import org.junit.Test; - @Test - public void testAssertFalse() { - assertFalse("failure - should be false", false); - } +public class DummyTestJavaClass { + @Test + public void testAssertFalse() { + assertFalse("failure - should be false", false); + } } - diff --git a/libraries/kotlinandroidlibrary/src/test/java/com/uber/okbuck/java/PojoTest.java b/libraries/kotlinandroidlibrary/src/test/java/com/uber/okbuck/java/PojoTest.java index 4bdca35d5..f6dee6498 100644 --- a/libraries/kotlinandroidlibrary/src/test/java/com/uber/okbuck/java/PojoTest.java +++ b/libraries/kotlinandroidlibrary/src/test/java/com/uber/okbuck/java/PojoTest.java @@ -4,9 +4,8 @@ public class PojoTest { - @Test - public void shouldCreatePojo() { - Pojo pojo = new Pojo(); - } - + @Test + public void shouldCreatePojo() { + Pojo pojo = new Pojo(); + } } diff --git a/libraries/kotlinlibrary/src/test/java/demo/JavaClassTest.java b/libraries/kotlinlibrary/src/test/java/demo/JavaClassTest.java index 31229db97..a2a59a440 100644 --- a/libraries/kotlinlibrary/src/test/java/demo/JavaClassTest.java +++ b/libraries/kotlinlibrary/src/test/java/demo/JavaClassTest.java @@ -1,13 +1,16 @@ package demo; -import org.junit.Test; - import static kotlin.test.AssertionsKt.assertEquals; +import org.junit.Test; + public class JavaClassTest { - @Test public void testGetGreetingJava() { - assertEquals(HelloWorldKt.getGreeting(), new JavaClass().getKotlinGreeting(), - "Java and kotlin greeting should be the same"); + @Test + public void testGetGreetingJava() { + assertEquals( + HelloWorldKt.getGreeting(), + new JavaClass().getKotlinGreeting(), + "Java and kotlin greeting should be the same"); } } diff --git a/libraries/lintErrorLibrary/src/main/java/com/uber/okbuck/example/lintError/MyClass.java b/libraries/lintErrorLibrary/src/main/java/com/uber/okbuck/example/lintError/MyClass.java index 5828aa7fc..925949a8d 100644 --- a/libraries/lintErrorLibrary/src/main/java/com/uber/okbuck/example/lintError/MyClass.java +++ b/libraries/lintErrorLibrary/src/main/java/com/uber/okbuck/example/lintError/MyClass.java @@ -1,23 +1,24 @@ package com.uber.okbuck.example.lintError; import android.util.Log; - import java.util.Arrays; import java.util.function.Consumer; public class MyClass { - public void testCustomLint_usingSystemTime_shouldFail() { - System.currentTimeMillis(); - } + public void testCustomLint_usingSystemTime_shouldFail() { + System.currentTimeMillis(); + } - public void testNewApiSdkLint_usingStreamsApi_shouldFail() { - Arrays.asList(1, 2, 3).stream() - .forEach(new Consumer() { - @Override - public void accept(Integer num) { - Log.d("TAG", "number is: " + String.valueOf(num)); - } - }); - } + public void testNewApiSdkLint_usingStreamsApi_shouldFail() { + Arrays.asList(1, 2, 3) + .stream() + .forEach( + new Consumer() { + @Override + public void accept(Integer num) { + Log.d("TAG", "number is: " + String.valueOf(num)); + } + }); + } } diff --git a/libraries/parcelable/src/main/java/com/uber/okbuck/example/common/Person.java b/libraries/parcelable/src/main/java/com/uber/okbuck/example/common/Person.java index 4edea0a5a..61f56aec4 100644 --- a/libraries/parcelable/src/main/java/com/uber/okbuck/example/common/Person.java +++ b/libraries/parcelable/src/main/java/com/uber/okbuck/example/common/Person.java @@ -4,44 +4,45 @@ import android.os.Parcelable; public class Person implements Parcelable { - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { public Person createFromParcel(Parcel source) { - return new Person(source); + return new Person(source); } public Person[] newArray(int size) { - return new Person[size]; + return new Person[size]; } - }; - private final String mName; - private final int mAge; - - public Person(String name, int age) { - mName = name; - mAge = age; - } - - protected Person(Parcel in) { - this.mName = in.readString(); - this.mAge = in.readInt(); - } - - public int getAge() { - return mAge; - } - - public String getName() { - return mName; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeString(this.mName); - dest.writeInt(this.mAge); - } + }; + private final String mName; + private final int mAge; + + public Person(String name, int age) { + mName = name; + mAge = age; + } + + protected Person(Parcel in) { + this.mName = in.readString(); + this.mAge = in.readInt(); + } + + public int getAge() { + return mAge; + } + + public String getName() { + return mName; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(this.mName); + dest.writeInt(this.mAge); + } } diff --git a/libraries/robolectric-base/src/main/java/com/uber/okbuck/BuckRobolectricTestRunner.java b/libraries/robolectric-base/src/main/java/com/uber/okbuck/BuckRobolectricTestRunner.java index 66a8fb1bf..187d5ced6 100644 --- a/libraries/robolectric-base/src/main/java/com/uber/okbuck/BuckRobolectricTestRunner.java +++ b/libraries/robolectric-base/src/main/java/com/uber/okbuck/BuckRobolectricTestRunner.java @@ -1,13 +1,5 @@ package com.uber.okbuck; -import org.junit.runners.model.InitializationError; -import org.robolectric.RobolectricTestRunner; -import org.robolectric.annotation.Config; -import org.robolectric.manifest.AndroidManifest; -import org.robolectric.res.Fs; -import org.robolectric.res.FsFile; -import org.robolectric.res.ResourcePath; - import java.io.File; import java.util.ArrayList; import java.util.Arrays; @@ -15,54 +7,62 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.ListIterator; +import org.junit.runners.model.InitializationError; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; +import org.robolectric.manifest.AndroidManifest; +import org.robolectric.res.Fs; +import org.robolectric.res.FsFile; +import org.robolectric.res.ResourcePath; /** - * The example test runner only runs robolectric tests with buck. - * If you want to run unit tests with both gradle and buck, - * you can use the example test runner and create a hybrid - * with robolectric's {@link org.robolectric.RobolectricGradleTestRunner}. + * The example test runner only runs robolectric tests with buck. If you want to run unit tests with + * both gradle and buck, you can use the example test runner and create a hybrid with robolectric's + * {@link org.robolectric.RobolectricGradleTestRunner}. */ public class BuckRobolectricTestRunner extends RobolectricTestRunner { - private static final String ROBOLECTRIC_RESOURCE_DIRECTORIES = "buck.robolectric_res_directories"; - private static final String ROBOLECTRIC_MANIFEST = "buck.robolectric_manifest"; + private static final String ROBOLECTRIC_RESOURCE_DIRECTORIES = "buck.robolectric_res_directories"; + private static final String ROBOLECTRIC_MANIFEST = "buck.robolectric_manifest"; - public BuckRobolectricTestRunner(Class testClass) throws InitializationError { - super(testClass); - } + public BuckRobolectricTestRunner(Class testClass) throws InitializationError { + super(testClass); + } - @Override - protected AndroidManifest getAppManifest(Config config) { - String buckManifest = System.getProperty(ROBOLECTRIC_MANIFEST); - String buckResourcesProperty = System.getProperty(ROBOLECTRIC_RESOURCE_DIRECTORIES); + @Override + protected AndroidManifest getAppManifest(Config config) { + String buckManifest = System.getProperty(ROBOLECTRIC_MANIFEST); + String buckResourcesProperty = System.getProperty(ROBOLECTRIC_RESOURCE_DIRECTORIES); - if (buckManifest != null && buckResourcesProperty != null) { - final List buckResources = Arrays.asList(buckResourcesProperty.split(File.pathSeparator)); + if (buckManifest != null && buckResourcesProperty != null) { + final List buckResources = + Arrays.asList(buckResourcesProperty.split(File.pathSeparator)); - final FsFile res = Fs.fileFromPath(buckResources.get(buckResources.size() - 1)); - final FsFile assets = Fs.fileFromPath(buckResources.get(buckResources.size() - 1)); - final FsFile manifest = Fs.fileFromPath(buckManifest); + final FsFile res = Fs.fileFromPath(buckResources.get(buckResources.size() - 1)); + final FsFile assets = Fs.fileFromPath(buckResources.get(buckResources.size() - 1)); + final FsFile manifest = Fs.fileFromPath(buckManifest); - return new AndroidManifest(manifest, res, assets, config.packageName()) { + return new AndroidManifest(manifest, res, assets, config.packageName()) { - @Override - public List getIncludedResourcePaths() { - Collection resourcePaths = new LinkedHashSet<>(); - resourcePaths.add(super.getResourcePath()); + @Override + public List getIncludedResourcePaths() { + Collection resourcePaths = new LinkedHashSet<>(); + resourcePaths.add(super.getResourcePath()); - ListIterator it = buckResources.listIterator(buckResources.size()); - while (it.hasPrevious()) { - resourcePaths.add(new ResourcePath( - getRClass(), - getPackageName(), - Fs.fileFromPath(it.previous()), - getAssetsDirectory())); - } - return new ArrayList<>(resourcePaths); - } - }; - } else { - return null; + ListIterator it = buckResources.listIterator(buckResources.size()); + while (it.hasPrevious()) { + resourcePaths.add( + new ResourcePath( + getRClass(), + getPackageName(), + Fs.fileFromPath(it.previous()), + getAssetsDirectory())); + } + return new ArrayList<>(resourcePaths); } + }; + } else { + return null; } + } } diff --git a/libraries/scalalibrary/src/main/java/com/uber/okbuck/scala/example/DummyJava.java b/libraries/scalalibrary/src/main/java/com/uber/okbuck/scala/example/DummyJava.java index 909d3f61e..c4bd6b0b1 100644 --- a/libraries/scalalibrary/src/main/java/com/uber/okbuck/scala/example/DummyJava.java +++ b/libraries/scalalibrary/src/main/java/com/uber/okbuck/scala/example/DummyJava.java @@ -2,7 +2,7 @@ public class DummyJava { - static int add(int a, int b) { - return a + b; - } + static int add(int a, int b) { + return a + b; + } } diff --git a/transform-cli/src/main/java/com/uber/okbuck/transform/CliTransform.java b/transform-cli/src/main/java/com/uber/okbuck/transform/CliTransform.java index fd0e795dc..8c4af09f9 100644 --- a/transform-cli/src/main/java/com/uber/okbuck/transform/CliTransform.java +++ b/transform-cli/src/main/java/com/uber/okbuck/transform/CliTransform.java @@ -1,153 +1,155 @@ package com.uber.okbuck.transform; import com.android.build.api.transform.Transform; - import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; -/** - * Main entry point for the cli application to apply the transform. - */ +/** Main entry point for the cli application to apply the transform. */ public class CliTransform { - private static final String PROPERTY_IN_JARS_DIR = "okbuck.inJarsDir"; - private static final String PROPERTY_OUT_JARS_DIR = "okbuck.outJarsDir"; - private static final String PROPERTY_CONFIG_FILE = "okbuck.configFile"; - private static final String PROPERTY_ANDROID_BOOTCLASSPATH = "okbuck.androidBootClasspath"; - private static final String PROPERTY_TRANSFORM_DEPENDENCIES_FILE = "okbuck.transformJarsFile"; - private static final String PROPERTY_TRANSFORM_CLASS = "okbuck.transformClass"; - private static final String DEPENDENCIES_SEPARATOR = ":"; - - private CliTransform() { } - - /** - * Main. - * - * @param args arguments. - */ - public static void main(String[] args) { - if (args.length != 0) { - StringBuilder sb = new StringBuilder() - .append("No argument is expected. All parameters should be passed through java system properties.\n") - .append(PROPERTY_IN_JARS_DIR + " : jars input directory\n") - .append(PROPERTY_OUT_JARS_DIR + " : jars output directory\n") - .append(PROPERTY_CONFIG_FILE + " : configuration file\n") - .append(PROPERTY_ANDROID_BOOTCLASSPATH + " : android classpath\n") - .append(PROPERTY_TRANSFORM_DEPENDENCIES_FILE + " : transform dependencies [optional]\n") - .append(PROPERTY_TRANSFORM_CLASS + " : full qualified name for transform class\n"); - throw new IllegalArgumentException(sb.toString()); - } - - //Loading transform dependencies in this class loader to ensure this application to work properly - final String[] postProcessDependencies = - readDependenciesFileFromSystemPropertyVar(PROPERTY_TRANSFORM_DEPENDENCIES_FILE); - if (postProcessDependencies.length > 0) { - new SystemClassLoader().loadJarFiles(postProcessDependencies); - } - - //Passing the dependencies to the transform runner. - main(new TransformRunnerProvider() { - @Override - public TransformRunner provide() { - - //Reading config file. - String configFilePath = System.getProperty(PROPERTY_CONFIG_FILE); - - //Reading input jar dir - String inJarsDir = System.getProperty(PROPERTY_IN_JARS_DIR); - - //Reading output jar dir - String outJarsDir = System.getProperty(PROPERTY_OUT_JARS_DIR); - - //Reading android classpaths - String[] androidClasspaths = readDependenciesFromSystemPropertyVar(PROPERTY_ANDROID_BOOTCLASSPATH); - - //Creating TransformRunner class - try { - - Class transformClass; - String transformClassName = System.getProperty(PROPERTY_TRANSFORM_CLASS); - if (transformClassName != null) { - transformClass = (Class) Class.forName(transformClassName); - } else { - throw new IllegalArgumentException("No transform class defined."); - } - - TransformRunner runner = new TransformRunner( - configFilePath, inJarsDir, outJarsDir, androidClasspaths, transformClass); - - return runner; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - }); + private static final String PROPERTY_IN_JARS_DIR = "okbuck.inJarsDir"; + private static final String PROPERTY_OUT_JARS_DIR = "okbuck.outJarsDir"; + private static final String PROPERTY_CONFIG_FILE = "okbuck.configFile"; + private static final String PROPERTY_ANDROID_BOOTCLASSPATH = "okbuck.androidBootClasspath"; + private static final String PROPERTY_TRANSFORM_DEPENDENCIES_FILE = "okbuck.transformJarsFile"; + private static final String PROPERTY_TRANSFORM_CLASS = "okbuck.transformClass"; + private static final String DEPENDENCIES_SEPARATOR = ":"; + + private CliTransform() {} + + /** + * Main. + * + * @param args arguments. + */ + public static void main(String[] args) { + if (args.length != 0) { + StringBuilder sb = + new StringBuilder() + .append( + "No argument is expected. All parameters should be passed through java system properties.\n") + .append(PROPERTY_IN_JARS_DIR + " : jars input directory\n") + .append(PROPERTY_OUT_JARS_DIR + " : jars output directory\n") + .append(PROPERTY_CONFIG_FILE + " : configuration file\n") + .append(PROPERTY_ANDROID_BOOTCLASSPATH + " : android classpath\n") + .append( + PROPERTY_TRANSFORM_DEPENDENCIES_FILE + " : transform dependencies [optional]\n") + .append(PROPERTY_TRANSFORM_CLASS + " : full qualified name for transform class\n"); + throw new IllegalArgumentException(sb.toString()); } - /** - * Main method for testing. - * - * @param provider a provider for the transform runner. - */ - static void main(TransformRunnerProvider provider) { - try { - provider.provide().runTransform(); - } catch (Exception e) { - throw new RuntimeException(e); - } + // Loading transform dependencies in this class loader to ensure this application to work + // properly + final String[] postProcessDependencies = + readDependenciesFileFromSystemPropertyVar(PROPERTY_TRANSFORM_DEPENDENCIES_FILE); + if (postProcessDependencies.length > 0) { + new SystemClassLoader().loadJarFiles(postProcessDependencies); } - /** - * Reads a dependency file from the path contained in a java system property. - * Dependency file contains jar file paths all colon separated. - * - * @param property the property with the file path to read. - * @return an array with all the dependency jars. - */ - static String[] readDependenciesFileFromSystemPropertyVar(String property) { - String envVarFilePath = System.getProperty(property); - if (envVarFilePath != null && envVarFilePath.length() > 0) { + // Passing the dependencies to the transform runner. + main( + new TransformRunnerProvider() { + @Override + public TransformRunner provide() { + + // Reading config file. + String configFilePath = System.getProperty(PROPERTY_CONFIG_FILE); + + // Reading input jar dir + String inJarsDir = System.getProperty(PROPERTY_IN_JARS_DIR); + + // Reading output jar dir + String outJarsDir = System.getProperty(PROPERTY_OUT_JARS_DIR); + + // Reading android classpaths + String[] androidClasspaths = + readDependenciesFromSystemPropertyVar(PROPERTY_ANDROID_BOOTCLASSPATH); + + // Creating TransformRunner class try { - //This part needs to be written in vanilla java, since no dependency is available here. - BufferedReader reader = new BufferedReader(new FileReader(new File(envVarFilePath))); - String line = reader.readLine(); - reader.close(); - String[] dependencies = line.split(DEPENDENCIES_SEPARATOR); - return dependencies; - } catch (IOException e) { - throw new RuntimeException(e); + + Class transformClass; + String transformClassName = System.getProperty(PROPERTY_TRANSFORM_CLASS); + if (transformClassName != null) { + transformClass = (Class) Class.forName(transformClassName); + } else { + throw new IllegalArgumentException("No transform class defined."); + } + + TransformRunner runner = + new TransformRunner( + configFilePath, inJarsDir, outJarsDir, androidClasspaths, transformClass); + + return runner; + } catch (Exception e) { + throw new RuntimeException(e); } - } else { - return new String[0]; - } + } + }); + } + + /** + * Main method for testing. + * + * @param provider a provider for the transform runner. + */ + static void main(TransformRunnerProvider provider) { + try { + provider.provide().runTransform(); + } catch (Exception e) { + throw new RuntimeException(e); } - - /** - * Reads the dependencies from a java system property. - * Dependency file paths should all be colon separated. - * - * @param property the property with the dependencies. - * @return an array with all the dependency jars. - */ - static String[] readDependenciesFromSystemPropertyVar(String property) { - String depsEnvVar = System.getProperty(property); - return depsEnvVar != null && depsEnvVar.length() > 0 - ? depsEnvVar.split(DEPENDENCIES_SEPARATOR) - : new String[0]; + } + + /** + * Reads a dependency file from the path contained in a java system property. Dependency file + * contains jar file paths all colon separated. + * + * @param property the property with the file path to read. + * @return an array with all the dependency jars. + */ + static String[] readDependenciesFileFromSystemPropertyVar(String property) { + String envVarFilePath = System.getProperty(property); + if (envVarFilePath != null && envVarFilePath.length() > 0) { + try { + // This part needs to be written in vanilla java, since no dependency is available here. + BufferedReader reader = new BufferedReader(new FileReader(new File(envVarFilePath))); + String line = reader.readLine(); + reader.close(); + String[] dependencies = line.split(DEPENDENCIES_SEPARATOR); + return dependencies; + } catch (IOException e) { + throw new RuntimeException(e); + } + } else { + return new String[0]; } + } + + /** + * Reads the dependencies from a java system property. Dependency file paths should all be colon + * separated. + * + * @param property the property with the dependencies. + * @return an array with all the dependency jars. + */ + static String[] readDependenciesFromSystemPropertyVar(String property) { + String depsEnvVar = System.getProperty(property); + return depsEnvVar != null && depsEnvVar.length() > 0 + ? depsEnvVar.split(DEPENDENCIES_SEPARATOR) + : new String[0]; + } + + /** A provider for transforms, used for mainly for testing. */ + interface TransformRunnerProvider { /** - * A provider for transforms, used for mainly for testing. + * Returns the transform runner. + * + * @return the transform runner. */ - interface TransformRunnerProvider { - - /** - * Returns the transform runner. - * - * @return the transform runner. - */ - TransformRunner provide(); - } + TransformRunner provide(); + } } diff --git a/transform-cli/src/main/java/com/uber/okbuck/transform/FileUtil.java b/transform-cli/src/main/java/com/uber/okbuck/transform/FileUtil.java index 33cb6b507..8a8080f8f 100644 --- a/transform-cli/src/main/java/com/uber/okbuck/transform/FileUtil.java +++ b/transform-cli/src/main/java/com/uber/okbuck/transform/FileUtil.java @@ -9,14 +9,15 @@ final class FileUtil { - private FileUtil() { } + private FileUtil() {} - static void deleteDirectory(File path) { - try { - Files.walk(path.toPath(), FileVisitOption.FOLLOW_LINKS) - .sorted(Comparator.reverseOrder()) - .map(Path::toFile) - .forEach(File::delete); - } catch (IOException ignored) { } + static void deleteDirectory(File path) { + try { + Files.walk(path.toPath(), FileVisitOption.FOLLOW_LINKS) + .sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); + } catch (IOException ignored) { } + } } diff --git a/transform-cli/src/main/java/com/uber/okbuck/transform/JarsTransformOutputProvider.java b/transform-cli/src/main/java/com/uber/okbuck/transform/JarsTransformOutputProvider.java index 51f363f6d..8f9cdc25e 100644 --- a/transform-cli/src/main/java/com/uber/okbuck/transform/JarsTransformOutputProvider.java +++ b/transform-cli/src/main/java/com/uber/okbuck/transform/JarsTransformOutputProvider.java @@ -3,95 +3,86 @@ import com.android.build.api.transform.Format; import com.android.build.api.transform.QualifiedContent; import com.android.build.api.transform.TransformOutputProvider; - import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.LinkedList; import java.util.Set; -/** - * A {@link TransformOutputProvider} providing jar outputs based on a given output folder. - */ +/** A {@link TransformOutputProvider} providing jar outputs based on a given output folder. */ public class JarsTransformOutputProvider implements TransformOutputProvider { - private final File outputFolder; - private final File inputFolder; - private final String[] outputFolderParts; - - /** - * Constructor. - */ - JarsTransformOutputProvider(File outputFolder, File inputFolder) { - this.outputFolder = outputFolder; - this.inputFolder = inputFolder; - this.outputFolderParts = outputFolder.getAbsolutePath().split(File.separator); - } + private final File outputFolder; + private final File inputFolder; + private final String[] outputFolderParts; - @Override - public void deleteAll() throws IOException { - FileUtil.deleteDirectory(outputFolder); - outputFolder.mkdirs(); - } + /** Constructor. */ + JarsTransformOutputProvider(File outputFolder, File inputFolder) { + this.outputFolder = outputFolder; + this.inputFolder = inputFolder; + this.outputFolderParts = outputFolder.getAbsolutePath().split(File.separator); + } - @Override - public File getContentLocation( - String name, - Set types, - Set scopes, - Format format) { + @Override + public void deleteAll() throws IOException { + FileUtil.deleteDirectory(outputFolder); + outputFolder.mkdirs(); + } - // Just a temp directory not to be used, to make the transform happy. - if (format == Format.DIRECTORY) { - return new File(System.getProperty("java.io.tmpdir")); - } + @Override + public File getContentLocation( + String name, + Set types, + Set scopes, + Format format) { - /** - * For jars, the name is actually the absolute path. - * The goal here is to calculate the absolute output path starting from the input one. Since The output path - * will be different only in the last folder (replaced from the base output folder), it's possible to exclude - * from the input path the parts in common plus the last folder (i.e. all the parts of the output folder). - * - * Example of input path: - * ...mobile/okbuck/buck-out/bin/app - * /java_classes_preprocess_in_bin_prodDebug/buck-out/gen/.okbuck/cache/__app.rxscreenshotdetector-release - * .aar#aar_prebuilt_jar__/classes.jar - * - * Example of output base folder: - * ...mobile/okbuck/buck-out/bin/app/ - * java_classes_preprocess_out_bin_prodDebug/ - * - * Example of output path: - * ...mobile/okbuck/buck-out/bin/app - * /java_classes_preprocess_out_bin_prodDebug/buck-out/gen/.okbuck/cache/__app.rxscreenshotdetector-release - * .aar#aar_prebuilt_jar__/classes.jar - */ + // Just a temp directory not to be used, to make the transform happy. + if (format == Format.DIRECTORY) { + return new File(System.getProperty("java.io.tmpdir")); + } + /** + * For jars, the name is actually the absolute path. The goal here is to calculate the absolute + * output path starting from the input one. Since The output path will be different only in the + * last folder (replaced from the base output folder), it's possible to exclude from the input + * path the parts in common plus the last folder (i.e. all the parts of the output folder). + * + *

Example of input path: ...mobile/okbuck/buck-out/bin/app + * /java_classes_preprocess_in_bin_prodDebug/buck-out/gen/.okbuck/cache/__app.rxscreenshotdetector-release + * .aar#aar_prebuilt_jar__/classes.jar + * + *

Example of output base folder: ...mobile/okbuck/buck-out/bin/app/ + * java_classes_preprocess_out_bin_prodDebug/ + * + *

Example of output path: ...mobile/okbuck/buck-out/bin/app + * /java_classes_preprocess_out_bin_prodDebug/buck-out/gen/.okbuck/cache/__app.rxscreenshotdetector-release + * .aar#aar_prebuilt_jar__/classes.jar + */ - // If the full absolute path was in name. - final File file; - if (name.startsWith(inputFolder.getAbsolutePath())) { - String[] nameParts = name.split(File.separator); - LinkedList baseFolderParts = new LinkedList(Arrays.asList(nameParts)); - for (int i = 0; i < outputFolderParts.length; i++) { - baseFolderParts.removeFirst(); - } - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < baseFolderParts.size(); i++) { - sb.append(baseFolderParts.get(i)); - if (i != baseFolderParts.size() - 1) { - sb.append(File.separator); - } - } - file = new File(outputFolder, sb.toString()); - } - // If just the filename was passed. - else { - if (!name.endsWith(".jar")) { - name += ".jar"; - } - file = new File(outputFolder, name); + // If the full absolute path was in name. + final File file; + if (name.startsWith(inputFolder.getAbsolutePath())) { + String[] nameParts = name.split(File.separator); + LinkedList baseFolderParts = new LinkedList(Arrays.asList(nameParts)); + for (int i = 0; i < outputFolderParts.length; i++) { + baseFolderParts.removeFirst(); + } + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < baseFolderParts.size(); i++) { + sb.append(baseFolderParts.get(i)); + if (i != baseFolderParts.size() - 1) { + sb.append(File.separator); } - return file; + } + file = new File(outputFolder, sb.toString()); + } + // If just the filename was passed. + else { + if (!name.endsWith(".jar")) { + name += ".jar"; + } + file = new File(outputFolder, name); } + return file; + } } diff --git a/transform-cli/src/main/java/com/uber/okbuck/transform/SystemClassLoader.java b/transform-cli/src/main/java/com/uber/okbuck/transform/SystemClassLoader.java index 788c18de6..0ee0ad910 100644 --- a/transform-cli/src/main/java/com/uber/okbuck/transform/SystemClassLoader.java +++ b/transform-cli/src/main/java/com/uber/okbuck/transform/SystemClassLoader.java @@ -7,54 +7,53 @@ import java.net.URLClassLoader; /** - * Extend the support for the system class loader to load additional dependencies at runtime. Note that internally - * it works using {@link ClassLoader#getSystemClassLoader()}, making accessible the `addURL` method through reflection. + * Extend the support for the system class loader to load additional dependencies at runtime. Note + * that internally it works using {@link ClassLoader#getSystemClassLoader()}, making accessible the + * `addURL` method through reflection. */ class SystemClassLoader { - private final URLClassLoader systemClassLoader; - private final Method addUrlMethod; + private final URLClassLoader systemClassLoader; + private final Method addUrlMethod; - /** - * Constructor. - */ - SystemClassLoader() { - try { - this.systemClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader(); - this.addUrlMethod = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); - this.addUrlMethod.setAccessible(true); - } catch (NoSuchMethodException e) { - throw new RuntimeException(e); - } + /** Constructor. */ + SystemClassLoader() { + try { + this.systemClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader(); + this.addUrlMethod = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); + this.addUrlMethod.setAccessible(true); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); } + } - /** - * Loads a new jar in the system class loader using the given path. - * - * @param jarFilePath the path of a jar file. - */ - private void loadJarFile(String jarFilePath) { - try { - File file = new File(jarFilePath); - if (!file.exists()) { - throw new FileNotFoundException(file.getAbsolutePath()); - } - URL jarFileUrl = file.toURI().toURL(); - this.addUrlMethod.invoke(systemClassLoader, jarFileUrl); - System.out.println("Added dependency: " + jarFileUrl.toString()); - } catch (Exception e) { - throw new RuntimeException(e); - } + /** + * Loads a new jar in the system class loader using the given path. + * + * @param jarFilePath the path of a jar file. + */ + private void loadJarFile(String jarFilePath) { + try { + File file = new File(jarFilePath); + if (!file.exists()) { + throw new FileNotFoundException(file.getAbsolutePath()); + } + URL jarFileUrl = file.toURI().toURL(); + this.addUrlMethod.invoke(systemClassLoader, jarFileUrl); + System.out.println("Added dependency: " + jarFileUrl.toString()); + } catch (Exception e) { + throw new RuntimeException(e); } + } - /** - * Loads new jars in the system class loader using the given paths. - * - * @param jarFilePaths the paths of a jar file. - */ - void loadJarFiles(String[] jarFilePaths) { - for (String jarFilePath : jarFilePaths) { - this.loadJarFile(jarFilePath); - } + /** + * Loads new jars in the system class loader using the given paths. + * + * @param jarFilePaths the paths of a jar file. + */ + void loadJarFiles(String[] jarFilePaths) { + for (String jarFilePath : jarFilePaths) { + this.loadJarFile(jarFilePath); } + } } diff --git a/transform-cli/src/main/java/com/uber/okbuck/transform/TransformInputBuilder.java b/transform-cli/src/main/java/com/uber/okbuck/transform/TransformInputBuilder.java index d38eb39f0..488554b12 100644 --- a/transform-cli/src/main/java/com/uber/okbuck/transform/TransformInputBuilder.java +++ b/transform-cli/src/main/java/com/uber/okbuck/transform/TransformInputBuilder.java @@ -4,7 +4,6 @@ import com.android.build.api.transform.JarInput; import com.android.build.api.transform.Status; import com.android.build.api.transform.TransformInput; - import java.io.File; import java.util.Arrays; import java.util.Collection; @@ -13,191 +12,184 @@ import java.util.Map; import java.util.Set; -/** - * A builder for {@link TransformInput}. - */ +/** A builder for {@link TransformInput}. */ class TransformInputBuilder { - private static final String DOT_JAR = ".jar"; - - private final LinkedList jarInputs; - private final LinkedList directoryInputs; - - /** - * Constructor. - */ - TransformInputBuilder() { - this.jarInputs = new LinkedList<>(); - this.directoryInputs = new LinkedList<>(); - } - - /** - * Adds a jar input for this transform input. - * - * @param file the file of the jar input. - * @return this instance of the builder. - */ - TransformInputBuilder addJarInput(File file) { - if (file.exists()) { - this.jarInputs.add(new FileJarInput(file)); - System.out.println("Adding dependency jar: " + file.getAbsolutePath()); + private static final String DOT_JAR = ".jar"; + + private final LinkedList jarInputs; + private final LinkedList directoryInputs; + + /** Constructor. */ + TransformInputBuilder() { + this.jarInputs = new LinkedList<>(); + this.directoryInputs = new LinkedList<>(); + } + + /** + * Adds a jar input for this transform input. + * + * @param file the file of the jar input. + * @return this instance of the builder. + */ + TransformInputBuilder addJarInput(File file) { + if (file.exists()) { + this.jarInputs.add(new FileJarInput(file)); + System.out.println("Adding dependency jar: " + file.getAbsolutePath()); + } else { + System.out.println("Specified jar input doesn't exist: " + file.getAbsolutePath()); + } + return this; + } + + /** + * Adds a jar input folder for this transform input. All the jars found will be added to the class + * path. + * + * @param folder the folder of the jars input. + * @return this instance of the builder. + */ + TransformInputBuilder addJarInputFolder(File folder) { + File[] listFiles = folder.listFiles(); + if (listFiles != null) { + for (File file : listFiles) { + if (file.isDirectory()) { + addJarInputFolder(file); } else { - System.out.println("Specified jar input doesn't exist: " + file.getAbsolutePath()); - } - return this; - } - - /** - * Adds a jar input folder for this transform input. All the jars found will be added to the class path. - * - * @param folder the folder of the jars input. - * @return this instance of the builder. - */ - TransformInputBuilder addJarInputFolder(File folder) { - File[] listFiles = folder.listFiles(); - if (listFiles != null) { - for (File file : listFiles) { - if (file.isDirectory()) { - addJarInputFolder(file); - } else { - if (!file.getAbsolutePath().endsWith(DOT_JAR)) { - continue; - } - addJarInput(file); - } - } - } - return this; - } - - /** - * Adds multiple jar inputs for this transform input. - * - * @param filePaths the paths of the jars. - * @return this instance of the builder. - */ - TransformInputBuilder addJarInput(String... filePaths) { - return addJarInput(Arrays.asList(filePaths)); - } - - /** - * Adds multiple jar inputs for this transform input. - * - * @param filePaths the paths of the jars. - * @return this instance of the builder. - */ - TransformInputBuilder addJarInput(List filePaths) { - for (String filePath : filePaths) { - addJarInput(new File(filePath)); - } - return this; - } - - /** - * Adds a directory input for this transform input. - * - * @param file the file of the directory input. - * @return this instance of the builder. - */ - TransformInputBuilder addDirectoryInput(File file) { - if (!file.exists()) { - throw new IllegalArgumentException("Specified directory input doesn't exist: " + file.getAbsolutePath()); - } - this.directoryInputs.add(new FileDirectoryInput(file)); - return this; - } - - /** - * Builds the {@link TransformInput}. - * - * @return a new {@link TransformInput} with the specified jar and directories. - */ - TransformInput build() { - return new TransformInput() { - @Override - public Collection getJarInputs() { - return jarInputs; - } - - @Override - public Collection getDirectoryInputs() { - return directoryInputs; - } - }; - } - - /** - * A {@link JarInput} with specified file. - */ - private static class FileJarInput implements JarInput { - - private final File file; - - FileJarInput(File file) { - this.file = file; - } - - @Override - public File getFile() { - return file; + if (!file.getAbsolutePath().endsWith(DOT_JAR)) { + continue; + } + addJarInput(file); } + } + } + return this; + } + + /** + * Adds multiple jar inputs for this transform input. + * + * @param filePaths the paths of the jars. + * @return this instance of the builder. + */ + TransformInputBuilder addJarInput(String... filePaths) { + return addJarInput(Arrays.asList(filePaths)); + } + + /** + * Adds multiple jar inputs for this transform input. + * + * @param filePaths the paths of the jars. + * @return this instance of the builder. + */ + TransformInputBuilder addJarInput(List filePaths) { + for (String filePath : filePaths) { + addJarInput(new File(filePath)); + } + return this; + } + + /** + * Adds a directory input for this transform input. + * + * @param file the file of the directory input. + * @return this instance of the builder. + */ + TransformInputBuilder addDirectoryInput(File file) { + if (!file.exists()) { + throw new IllegalArgumentException( + "Specified directory input doesn't exist: " + file.getAbsolutePath()); + } + this.directoryInputs.add(new FileDirectoryInput(file)); + return this; + } + + /** + * Builds the {@link TransformInput}. + * + * @return a new {@link TransformInput} with the specified jar and directories. + */ + TransformInput build() { + return new TransformInput() { + @Override + public Collection getJarInputs() { + return jarInputs; + } + + @Override + public Collection getDirectoryInputs() { + return directoryInputs; + } + }; + } + + /** A {@link JarInput} with specified file. */ + private static class FileJarInput implements JarInput { + + private final File file; + + FileJarInput(File file) { + this.file = file; + } - @Override - public Status getStatus() { - throw new UnsupportedOperationException(); - } + @Override + public File getFile() { + return file; + } - @Override - public String getName() { - return file.getAbsolutePath(); - } + @Override + public Status getStatus() { + throw new UnsupportedOperationException(); + } - @Override - public Set getContentTypes() { - throw new UnsupportedOperationException(); - } + @Override + public String getName() { + return file.getAbsolutePath(); + } - @Override - public Set getScopes() { - throw new UnsupportedOperationException(); - } + @Override + public Set getContentTypes() { + throw new UnsupportedOperationException(); } - /** - * A {@link DirectoryInput} with specified file. - */ - private static class FileDirectoryInput implements DirectoryInput { + @Override + public Set getScopes() { + throw new UnsupportedOperationException(); + } + } - private final File file; + /** A {@link DirectoryInput} with specified file. */ + private static class FileDirectoryInput implements DirectoryInput { - FileDirectoryInput(File file) { - this.file = file; - } + private final File file; - @Override + FileDirectoryInput(File file) { + this.file = file; + } - public File getFile() { - return file; - } + @Override + public File getFile() { + return file; + } - @Override - public String getName() { - throw new UnsupportedOperationException(); - } + @Override + public String getName() { + throw new UnsupportedOperationException(); + } - @Override - public Set getContentTypes() { - throw new UnsupportedOperationException(); - } + @Override + public Set getContentTypes() { + throw new UnsupportedOperationException(); + } - @Override - public Set getScopes() { - throw new UnsupportedOperationException(); - } + @Override + public Set getScopes() { + throw new UnsupportedOperationException(); + } - @Override - public Map getChangedFiles() { - throw new UnsupportedOperationException(); - } + @Override + public Map getChangedFiles() { + throw new UnsupportedOperationException(); } + } } diff --git a/transform-cli/src/main/java/com/uber/okbuck/transform/TransformInvocationBuilder.java b/transform-cli/src/main/java/com/uber/okbuck/transform/TransformInvocationBuilder.java index f6ac4a7ce..095f283f1 100644 --- a/transform-cli/src/main/java/com/uber/okbuck/transform/TransformInvocationBuilder.java +++ b/transform-cli/src/main/java/com/uber/okbuck/transform/TransformInvocationBuilder.java @@ -5,157 +5,141 @@ import com.android.build.api.transform.TransformInput; import com.android.build.api.transform.TransformInvocation; import com.android.build.api.transform.TransformOutputProvider; - -import org.gradle.api.logging.LoggingManager; -import org.gradle.workers.WorkerExecutor; - import java.io.File; import java.util.Collection; import java.util.LinkedList; +import org.gradle.api.logging.LoggingManager; +import org.gradle.workers.WorkerExecutor; -/** - * A builder for {@link TransformInvocation}. - */ +/** A builder for {@link TransformInvocation}. */ class TransformInvocationBuilder { - private final LinkedList inputs; - private final LinkedList referencedInputs; - private TransformOutputProvider outputProvider; - - /** - * Constructor. - */ - TransformInvocationBuilder() { - this.inputs = new LinkedList<>(); - this.referencedInputs = new LinkedList<>(); + private final LinkedList inputs; + private final LinkedList referencedInputs; + private TransformOutputProvider outputProvider; + + /** Constructor. */ + TransformInvocationBuilder() { + this.inputs = new LinkedList<>(); + this.referencedInputs = new LinkedList<>(); + } + + /** + * Adds a new input. + * + * @param transformInput the input to add. + * @return this instance of the builder + */ + TransformInvocationBuilder addInput(TransformInput transformInput) { + this.inputs.add(transformInput); + return this; + } + + /** + * Adds a new input. + * + * @param transformInput the input to add. + * @return this instance of the builder + */ + TransformInvocationBuilder addReferencedInput(TransformInput transformInput) { + this.referencedInputs.add(transformInput); + return this; + } + + /** + * Sets the output provider. + * + * @param outputProvider the output provider. + * @return this instance of the builder + */ + TransformInvocationBuilder setOutputProvider(TransformOutputProvider outputProvider) { + this.outputProvider = outputProvider; + return this; + } + + /** + * Builds the {@link TransformInvocation}. + * + * @return a new {@link TransformInvocation} with the specified inputs. + */ + TransformInvocation build() { + if (outputProvider == null) { + throw new IllegalArgumentException("Output provider needs to be specified."); } + return new CustomTransformInvocation(inputs, referencedInputs, outputProvider); + } - /** - * Adds a new input. - * - * @param transformInput the input to add. - * @return this instance of the builder - */ + /** The {@link TransformInvocation} built by the builder. */ + private static class CustomTransformInvocation implements TransformInvocation, Context { - TransformInvocationBuilder addInput(TransformInput transformInput) { - this.inputs.add(transformInput); - return this; - } + private final Collection inputs; - /** - * Adds a new input. - * - * @param transformInput the input to add. - * @return this instance of the builder - */ + private final Collection referencedInputs; - TransformInvocationBuilder addReferencedInput(TransformInput transformInput) { - this.referencedInputs.add(transformInput); - return this; - } - - /** - * Sets the output provider. - * - * @param outputProvider the output provider. - * @return this instance of the builder - */ + private final TransformOutputProvider transformOutputProvider; - TransformInvocationBuilder setOutputProvider(TransformOutputProvider outputProvider) { - this.outputProvider = outputProvider; - return this; + CustomTransformInvocation( + Collection inputs, + Collection referencedInputs, + TransformOutputProvider transformOutputProvider) { + this.inputs = inputs; + this.referencedInputs = referencedInputs; + this.transformOutputProvider = transformOutputProvider; } - /** - * Builds the {@link TransformInvocation}. - * - * @return a new {@link TransformInvocation} with the specified inputs. - */ - - TransformInvocation build() { - if (outputProvider == null) { - throw new IllegalArgumentException("Output provider needs to be specified."); - } - return new CustomTransformInvocation(inputs, referencedInputs, outputProvider); + @Override + public Context getContext() { + return this; } - /** - * The {@link TransformInvocation} built by the builder. - */ - private static class CustomTransformInvocation implements TransformInvocation, Context { - - private final Collection inputs; - - private final Collection referencedInputs; - - private final TransformOutputProvider transformOutputProvider; - - CustomTransformInvocation( - Collection inputs, - Collection referencedInputs, - TransformOutputProvider transformOutputProvider) { - this.inputs = inputs; - this.referencedInputs = referencedInputs; - this.transformOutputProvider = transformOutputProvider; - } - - @Override - - public Context getContext() { - return this; - } - - @Override - - public Collection getInputs() { - return inputs; - } - - @Override - - public Collection getReferencedInputs() { - return referencedInputs; - } + @Override + public Collection getInputs() { + return inputs; + } - @Override - public boolean isIncremental() { - return false; - } + @Override + public Collection getReferencedInputs() { + return referencedInputs; + } - @Override + @Override + public boolean isIncremental() { + return false; + } - public TransformOutputProvider getOutputProvider() { - return transformOutputProvider; - } + @Override + public TransformOutputProvider getOutputProvider() { + return transformOutputProvider; + } - @Override - public Collection getSecondaryInputs() { - throw new UnsupportedOperationException(); - } + @Override + public Collection getSecondaryInputs() { + throw new UnsupportedOperationException(); + } - @Override - public LoggingManager getLogging() { - throw new UnsupportedOperationException(); - } + @Override + public LoggingManager getLogging() { + throw new UnsupportedOperationException(); + } - @Override - public File getTemporaryDir() { - throw new UnsupportedOperationException(); - } + @Override + public File getTemporaryDir() { + throw new UnsupportedOperationException(); + } - @Override - public String getPath() { - throw new UnsupportedOperationException(); - } + @Override + public String getPath() { + throw new UnsupportedOperationException(); + } - @Override - public String getVariantName() { - throw new UnsupportedOperationException(); - } + @Override + public String getVariantName() { + throw new UnsupportedOperationException(); + } - @Override - public WorkerExecutor getWorkerExecutor() { - throw new UnsupportedOperationException(); - } + @Override + public WorkerExecutor getWorkerExecutor() { + throw new UnsupportedOperationException(); } + } } diff --git a/transform-cli/src/main/java/com/uber/okbuck/transform/TransformRunner.java b/transform-cli/src/main/java/com/uber/okbuck/transform/TransformRunner.java index bbf25ec07..84d88e533 100644 --- a/transform-cli/src/main/java/com/uber/okbuck/transform/TransformRunner.java +++ b/transform-cli/src/main/java/com/uber/okbuck/transform/TransformRunner.java @@ -4,103 +4,99 @@ import com.android.build.api.transform.TransformInput; import com.android.build.api.transform.TransformInvocation; import com.android.build.api.transform.TransformOutputProvider; - import java.io.File; -/** - * Transform runner that instantiates the transform class and starts the transform invocation. - */ +/** Transform runner that instantiates the transform class and starts the transform invocation. */ class TransformRunner { - private final File inputJarsDir; - private final File outputJarsDir; - private final File configFile; - private final String[] androidClassPath; - private final Class transformClass; - - /** - * Constructor. - * - * @param configFilePath the path to the config file. - * @param inJarsDir input jars folder. - * @param outJarsDir output jars folder. - * @param androidClassPath android classpath. - * @param transformClass class for the transform. - */ - TransformRunner( - String configFilePath, - String inJarsDir, - String outJarsDir, - String[] androidClassPath, - Class transformClass) { - this.androidClassPath = androidClassPath; - this.transformClass = transformClass; - - //Check input class path. - this.inputJarsDir = getFile(inJarsDir, "Input jars dir not existing or invalid.", true); - System.out.println("Input jars dir: " + inputJarsDir.getAbsolutePath()); - - //Check output class path. - this.outputJarsDir = getFile(outJarsDir, "Output jars dir not existing or invalid.", true); - System.out.println("Output jars dir: " + outputJarsDir.getAbsolutePath()); - - //Reading config file. - if (configFilePath != null) { - this.configFile = getFile(configFilePath, "Config file not existing or invalid.", false); - System.out.println("Config file: " + configFile.getAbsolutePath()); - } else { - this.configFile = null; - } - } - - - private static File getFile(String path, String errorMsg, boolean isFolder) { - File file = new File(path); - if (!file.exists() || isFolder != file.isDirectory()) { - throw new IllegalArgumentException(errorMsg); - } - return file; - } - - /** - * Starts the transform. Here the transform is instantiated through reflection. - * If the config file is specified, a constructor with a single parameter accepting a - * {@link File} is used, otherwise an empty constructor. - * - * @throws Exception for any exception happened during the transform process. - */ - void runTransform() throws Exception { - Transform transform = configFile != null - ? transformClass.getConstructor(File.class).newInstance(configFile) - : transformClass.newInstance(); - - TransformOutputProvider transformOutputProvider = - new JarsTransformOutputProvider(outputJarsDir, inputJarsDir); - - runTransform(transform, transformOutputProvider); + private final File inputJarsDir; + private final File outputJarsDir; + private final File configFile; + private final String[] androidClassPath; + private final Class transformClass; + + /** + * Constructor. + * + * @param configFilePath the path to the config file. + * @param inJarsDir input jars folder. + * @param outJarsDir output jars folder. + * @param androidClassPath android classpath. + * @param transformClass class for the transform. + */ + TransformRunner( + String configFilePath, + String inJarsDir, + String outJarsDir, + String[] androidClassPath, + Class transformClass) { + this.androidClassPath = androidClassPath; + this.transformClass = transformClass; + + // Check input class path. + this.inputJarsDir = getFile(inJarsDir, "Input jars dir not existing or invalid.", true); + System.out.println("Input jars dir: " + inputJarsDir.getAbsolutePath()); + + // Check output class path. + this.outputJarsDir = getFile(outJarsDir, "Output jars dir not existing or invalid.", true); + System.out.println("Output jars dir: " + outputJarsDir.getAbsolutePath()); + + // Reading config file. + if (configFilePath != null) { + this.configFile = getFile(configFilePath, "Config file not existing or invalid.", false); + System.out.println("Config file: " + configFile.getAbsolutePath()); + } else { + this.configFile = null; } + } - private void runTransform( - Transform transform, - TransformOutputProvider outputProvider) throws Exception { - - //Cleaning output directory. - FileUtil.deleteDirectory(outputJarsDir); - outputJarsDir.mkdirs(); - - //Preparing Transform invocation. - TransformInput input = - new TransformInputBuilder().addJarInputFolder(inputJarsDir).build(); - TransformInput referencedInput = - new TransformInputBuilder().addJarInput(androidClassPath).build(); - - TransformInvocation invocation = new TransformInvocationBuilder() - .addInput(input) - .addReferencedInput(referencedInput) - .setOutputProvider(outputProvider) - .build(); - - //Running the transform invocation. - transform.transform(invocation); + private static File getFile(String path, String errorMsg, boolean isFolder) { + File file = new File(path); + if (!file.exists() || isFolder != file.isDirectory()) { + throw new IllegalArgumentException(errorMsg); } + return file; + } + + /** + * Starts the transform. Here the transform is instantiated through reflection. If the config file + * is specified, a constructor with a single parameter accepting a {@link File} is used, otherwise + * an empty constructor. + * + * @throws Exception for any exception happened during the transform process. + */ + void runTransform() throws Exception { + Transform transform = + configFile != null + ? transformClass.getConstructor(File.class).newInstance(configFile) + : transformClass.newInstance(); + + TransformOutputProvider transformOutputProvider = + new JarsTransformOutputProvider(outputJarsDir, inputJarsDir); + + runTransform(transform, transformOutputProvider); + } + + private void runTransform(Transform transform, TransformOutputProvider outputProvider) + throws Exception { + + // Cleaning output directory. + FileUtil.deleteDirectory(outputJarsDir); + outputJarsDir.mkdirs(); + + // Preparing Transform invocation. + TransformInput input = new TransformInputBuilder().addJarInputFolder(inputJarsDir).build(); + TransformInput referencedInput = + new TransformInputBuilder().addJarInput(androidClassPath).build(); + + TransformInvocation invocation = + new TransformInvocationBuilder() + .addInput(input) + .addReferencedInput(referencedInput) + .setOutputProvider(outputProvider) + .build(); + + // Running the transform invocation. + transform.transform(invocation); + } } diff --git a/transform-cli/src/test/java/com/uber/okbuck/transform/CliTransformTest.java b/transform-cli/src/test/java/com/uber/okbuck/transform/CliTransformTest.java index 6ae4683b8..415955da1 100644 --- a/transform-cli/src/test/java/com/uber/okbuck/transform/CliTransformTest.java +++ b/transform-cli/src/test/java/com/uber/okbuck/transform/CliTransformTest.java @@ -1,32 +1,31 @@ package com.uber.okbuck.transform; -import org.junit.Before; -import org.junit.Test; - import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -public class CliTransformTest { +import org.junit.Before; +import org.junit.Test; - @Before - public void setup() throws Exception { +public class CliTransformTest { - } + @Before + public void setup() throws Exception {} - @Test(expected = IllegalArgumentException.class) - public void whenStarting_withOneArgument_shouldThrowException() throws Exception { - CliTransform.main(new String[] {"any"}); - } + @Test(expected = IllegalArgumentException.class) + public void whenStarting_withOneArgument_shouldThrowException() throws Exception { + CliTransform.main(new String[] {"any"}); + } - @Test - public void whenStarting_shouldRunTransform() throws Exception { - final TransformRunner runner = mock(TransformRunner.class); - CliTransform.main(new CliTransform.TransformRunnerProvider() { - @Override - public TransformRunner provide() { - return runner; - } + @Test + public void whenStarting_shouldRunTransform() throws Exception { + final TransformRunner runner = mock(TransformRunner.class); + CliTransform.main( + new CliTransform.TransformRunnerProvider() { + @Override + public TransformRunner provide() { + return runner; + } }); - verify(runner).runTransform(); - } + verify(runner).runTransform(); + } } diff --git a/transform-cli/src/test/java/com/uber/okbuck/transform/JarsTransformOutputProviderTest.java b/transform-cli/src/test/java/com/uber/okbuck/transform/JarsTransformOutputProviderTest.java index efa6dd9ca..46709ecc2 100644 --- a/transform-cli/src/test/java/com/uber/okbuck/transform/JarsTransformOutputProviderTest.java +++ b/transform-cli/src/test/java/com/uber/okbuck/transform/JarsTransformOutputProviderTest.java @@ -1,50 +1,48 @@ package com.uber.okbuck.transform; -import com.android.build.api.transform.Format; +import static org.assertj.core.api.Assertions.assertThat; +import com.android.build.api.transform.Format; +import java.io.File; import org.assertj.core.util.Files; import org.junit.Before; import org.junit.Test; -import java.io.File; - -import static org.assertj.core.api.Assertions.assertThat; - public class JarsTransformOutputProviderTest { - private static final String NAME = - "buck-out/bin/app/java_classes_preprocess_in_bin_prodDebug/buck-out/gen/.okbuck/cache/" - + "__app.rxscreenshotdetector-release.aar#aar_prebuilt_jar__/classes.jar"; - - private static final String INPUT = - "buck-out/bin/app/java_classes_preprocess_in_bin_prodDebug/"; - - private static final String OUTPUT = - "buck-out/bin/app/java_classes_preprocess_out_bin_prodDebug/"; - - private static final String EXPECTED_OUTPUT_JAR = - "buck-out/bin/app/java_classes_preprocess_out_bin_prodDebug/buck-out/gen/.okbuck/cache/" - + "__app.rxscreenshotdetector-release.aar#aar_prebuilt_jar__/classes.jar"; - - private File inputJarFile; - private File outputJarFile; - private File inputFolder; - private File outputFolder; - private JarsTransformOutputProvider provider; - - @Before - public void setUp() throws Exception { - File baseFolder = Files.newTemporaryFolder(); - this.inputJarFile = new File(baseFolder, NAME); - this.outputJarFile = new File(baseFolder, EXPECTED_OUTPUT_JAR); - this.inputFolder = new File(baseFolder, INPUT); - this.outputFolder = new File(baseFolder, OUTPUT); - this.provider = new JarsTransformOutputProvider(outputFolder, inputFolder); - } - - @Test - public void getContentLocation() throws Exception { - File output = provider.getContentLocation(inputJarFile.getAbsolutePath(), null, null, Format.JAR); - assertThat(output.getAbsolutePath()).isEqualTo(outputJarFile.getAbsolutePath()); - } + private static final String NAME = + "buck-out/bin/app/java_classes_preprocess_in_bin_prodDebug/buck-out/gen/.okbuck/cache/" + + "__app.rxscreenshotdetector-release.aar#aar_prebuilt_jar__/classes.jar"; + + private static final String INPUT = "buck-out/bin/app/java_classes_preprocess_in_bin_prodDebug/"; + + private static final String OUTPUT = + "buck-out/bin/app/java_classes_preprocess_out_bin_prodDebug/"; + + private static final String EXPECTED_OUTPUT_JAR = + "buck-out/bin/app/java_classes_preprocess_out_bin_prodDebug/buck-out/gen/.okbuck/cache/" + + "__app.rxscreenshotdetector-release.aar#aar_prebuilt_jar__/classes.jar"; + + private File inputJarFile; + private File outputJarFile; + private File inputFolder; + private File outputFolder; + private JarsTransformOutputProvider provider; + + @Before + public void setUp() throws Exception { + File baseFolder = Files.newTemporaryFolder(); + this.inputJarFile = new File(baseFolder, NAME); + this.outputJarFile = new File(baseFolder, EXPECTED_OUTPUT_JAR); + this.inputFolder = new File(baseFolder, INPUT); + this.outputFolder = new File(baseFolder, OUTPUT); + this.provider = new JarsTransformOutputProvider(outputFolder, inputFolder); + } + + @Test + public void getContentLocation() throws Exception { + File output = + provider.getContentLocation(inputJarFile.getAbsolutePath(), null, null, Format.JAR); + assertThat(output.getAbsolutePath()).isEqualTo(outputJarFile.getAbsolutePath()); + } } diff --git a/transform-cli/src/test/java/com/uber/okbuck/transform/TransformInputBuilderTest.java b/transform-cli/src/test/java/com/uber/okbuck/transform/TransformInputBuilderTest.java index 538d3238b..9aca537be 100644 --- a/transform-cli/src/test/java/com/uber/okbuck/transform/TransformInputBuilderTest.java +++ b/transform-cli/src/test/java/com/uber/okbuck/transform/TransformInputBuilderTest.java @@ -1,61 +1,60 @@ package com.uber.okbuck.transform; +import static org.assertj.core.api.Assertions.assertThat; + import com.android.build.api.transform.DirectoryInput; import com.android.build.api.transform.JarInput; import com.android.build.api.transform.TransformInput; - -import org.junit.Before; -import org.junit.Test; - import java.io.File; import java.io.IOException; - -import static org.assertj.core.api.Assertions.assertThat; +import org.junit.Before; +import org.junit.Test; public class TransformInputBuilderTest { - private TransformInputBuilder builder; - - @Before - public void setup() throws Exception { - builder = new TransformInputBuilder(); - } - - @Test - public void addJarInput_whenAddFile_builtShouldReturnFile() throws Exception { - File file = getTmpFile("tmp"); - - TransformInput input = builder.addJarInput(file).build(); - assertThat(input.getJarInputs()).hasSize(1); - assertThat(input.getJarInputs().toArray(new JarInput[1])[0].getFile()).isEqualTo(file); - } - - @Test - public void addJarInput_whenAddPaths_builtShouldReturnCorrectPaths() throws Exception { - File file1 = getTmpFile("tmp1"); - File file2 = getTmpFile("tmp2"); - - TransformInput input = builder.addJarInput(file1.getAbsolutePath(), file2.getAbsolutePath()).build(); - assertThat(input.getJarInputs()).hasSize(2); - - JarInput[] jarInputs = input.getJarInputs().toArray(new JarInput[2]); - assertThat(jarInputs[0].getFile().getAbsolutePath()).isEqualTo(file1.getAbsolutePath()); - assertThat(jarInputs[1].getFile().getAbsolutePath()).isEqualTo(file2.getAbsolutePath()); - } - - @Test - public void addDirectoryInput_builtShouldReturnCorrectFile() throws Exception { - File file = getTmpFile("tmp"); - - TransformInput input = builder.addDirectoryInput(file).build(); - assertThat(input.getDirectoryInputs()).hasSize(1); - assertThat(input.getDirectoryInputs().toArray(new DirectoryInput[1])[0].getFile()).isEqualTo(file); - } - - private File getTmpFile(String prefix) throws IOException { - File file = File.createTempFile(prefix, null); - file.deleteOnExit(); - return file; - } - + private TransformInputBuilder builder; + + @Before + public void setup() throws Exception { + builder = new TransformInputBuilder(); + } + + @Test + public void addJarInput_whenAddFile_builtShouldReturnFile() throws Exception { + File file = getTmpFile("tmp"); + + TransformInput input = builder.addJarInput(file).build(); + assertThat(input.getJarInputs()).hasSize(1); + assertThat(input.getJarInputs().toArray(new JarInput[1])[0].getFile()).isEqualTo(file); + } + + @Test + public void addJarInput_whenAddPaths_builtShouldReturnCorrectPaths() throws Exception { + File file1 = getTmpFile("tmp1"); + File file2 = getTmpFile("tmp2"); + + TransformInput input = + builder.addJarInput(file1.getAbsolutePath(), file2.getAbsolutePath()).build(); + assertThat(input.getJarInputs()).hasSize(2); + + JarInput[] jarInputs = input.getJarInputs().toArray(new JarInput[2]); + assertThat(jarInputs[0].getFile().getAbsolutePath()).isEqualTo(file1.getAbsolutePath()); + assertThat(jarInputs[1].getFile().getAbsolutePath()).isEqualTo(file2.getAbsolutePath()); + } + + @Test + public void addDirectoryInput_builtShouldReturnCorrectFile() throws Exception { + File file = getTmpFile("tmp"); + + TransformInput input = builder.addDirectoryInput(file).build(); + assertThat(input.getDirectoryInputs()).hasSize(1); + assertThat(input.getDirectoryInputs().toArray(new DirectoryInput[1])[0].getFile()) + .isEqualTo(file); + } + + private File getTmpFile(String prefix) throws IOException { + File file = File.createTempFile(prefix, null); + file.deleteOnExit(); + return file; + } } diff --git a/transform-cli/src/test/java/com/uber/okbuck/transform/TransformInvocationBuilderTest.java b/transform-cli/src/test/java/com/uber/okbuck/transform/TransformInvocationBuilderTest.java index aa6ad7d57..1fe307c14 100644 --- a/transform-cli/src/test/java/com/uber/okbuck/transform/TransformInvocationBuilderTest.java +++ b/transform-cli/src/test/java/com/uber/okbuck/transform/TransformInvocationBuilderTest.java @@ -1,53 +1,48 @@ package com.uber.okbuck.transform; +import static org.assertj.core.api.Assertions.assertThat; + import com.android.build.api.transform.TransformInput; import com.android.build.api.transform.TransformInvocation; import com.android.build.api.transform.TransformOutputProvider; - import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import static org.assertj.core.api.Assertions.assertThat; - public class TransformInvocationBuilderTest { - @Mock private TransformInput transformInput; - @Mock private TransformOutputProvider outputProvider; - - private TransformInvocationBuilder builder; - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - builder = new TransformInvocationBuilder(); - } - - @Test - public void addInput_shouldAddAnInput() throws Exception { - TransformInvocation invocation = builder - .addInput(transformInput) - .setOutputProvider(outputProvider) - .build(); - assertThat(invocation.getInputs()).containsExactly(transformInput); - assertThat(invocation.getReferencedInputs()).isEmpty(); - assertThat(invocation.getOutputProvider()).isEqualTo(outputProvider); - } - - @Test - public void addReferencedInput_shouldAddReferencedInput() throws Exception { - TransformInvocation invocation = builder - .addReferencedInput(transformInput) - .setOutputProvider(outputProvider) - .build(); - assertThat(invocation.getInputs()).isEmpty(); - assertThat(invocation.getReferencedInputs()).containsExactly(transformInput); - assertThat(invocation.getOutputProvider()).isEqualTo(outputProvider); - } - - @Test(expected = IllegalArgumentException.class) - public void whenOutputProviderNotSet_shouldThrowException() throws Exception { - builder.build(); - } + @Mock private TransformInput transformInput; + @Mock private TransformOutputProvider outputProvider; + + private TransformInvocationBuilder builder; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + builder = new TransformInvocationBuilder(); + } + + @Test + public void addInput_shouldAddAnInput() throws Exception { + TransformInvocation invocation = + builder.addInput(transformInput).setOutputProvider(outputProvider).build(); + assertThat(invocation.getInputs()).containsExactly(transformInput); + assertThat(invocation.getReferencedInputs()).isEmpty(); + assertThat(invocation.getOutputProvider()).isEqualTo(outputProvider); + } + + @Test + public void addReferencedInput_shouldAddReferencedInput() throws Exception { + TransformInvocation invocation = + builder.addReferencedInput(transformInput).setOutputProvider(outputProvider).build(); + assertThat(invocation.getInputs()).isEmpty(); + assertThat(invocation.getReferencedInputs()).containsExactly(transformInput); + assertThat(invocation.getOutputProvider()).isEqualTo(outputProvider); + } + + @Test(expected = IllegalArgumentException.class) + public void whenOutputProviderNotSet_shouldThrowException() throws Exception { + builder.build(); + } }