Add API to set load flags used by UnpackingJSBundleLoader

Reviewed By: tadeuzagallo

Differential Revision: D3557667

fbshipit-source-id: 5665667185cda10415210efce83685c3e3abee92
This commit is contained in:
Michał Gregorczyk 2016-08-04 15:42:52 -07:00 committed by Facebook Github Bot 6
parent 38979f9c68
commit f08f23f8cb
3 changed files with 24 additions and 3 deletions

View File

@ -104,6 +104,7 @@ public abstract class JSBundleLoader {
.setDestinationPath(new File(context.getFilesDir(), "optimized-bundle")) .setDestinationPath(new File(context.getFilesDir(), "optimized-bundle"))
.checkAndUnpackFile(bundleName + ".meta", "bundle.meta") .checkAndUnpackFile(bundleName + ".meta", "bundle.meta")
.unpackFile(bundleName, "bundle.js") .unpackFile(bundleName, "bundle.js")
.setLoadFlags(UnpackingJSBundleLoader.UNPACKED_JS_SOURCE)
.build(); .build();
} }

View File

@ -42,7 +42,7 @@ public class UnpackingJSBundleLoader extends JSBundleLoader {
* Flag passed to loadScriptFromOptimizedBundle to let the bridge know that * Flag passed to loadScriptFromOptimizedBundle to let the bridge know that
* the unpacked unpacked js source file. * the unpacked unpacked js source file.
*/ */
static final int UNPACKED_JS_SOURCE = (1 << 0); public static final int UNPACKED_JS_SOURCE = (1 << 0);
/** /**
* Name of the lock files. Multiple processes can be spawned off the same app * Name of the lock files. Multiple processes can be spawned off the same app
@ -71,6 +71,7 @@ public class UnpackingJSBundleLoader extends JSBundleLoader {
private final String mSourceURL; private final String mSourceURL;
private final Context mContext; private final Context mContext;
private final int mLoadFlags;
/** /**
* Description of what needs to be unpacked. * Description of what needs to be unpacked.
@ -82,6 +83,7 @@ public class UnpackingJSBundleLoader extends JSBundleLoader {
mDirectoryPath = Assertions.assertNotNull(builder.destinationPath); mDirectoryPath = Assertions.assertNotNull(builder.destinationPath);
mSourceURL = Assertions.assertNotNull(builder.sourceURL); mSourceURL = Assertions.assertNotNull(builder.sourceURL);
mUnpackers = builder.unpackers.toArray(new Unpacker[builder.unpackers.size()]); mUnpackers = builder.unpackers.toArray(new Unpacker[builder.unpackers.size()]);
mLoadFlags = builder.loadFlags;
} }
/** /**
@ -150,7 +152,7 @@ public class UnpackingJSBundleLoader extends JSBundleLoader {
instance.loadScriptFromOptimizedBundle( instance.loadScriptFromOptimizedBundle(
mDirectoryPath.getPath(), mDirectoryPath.getPath(),
mSourceURL, mSourceURL,
UNPACKED_JS_SOURCE); mLoadFlags);
} }
@Override @Override
@ -204,12 +206,14 @@ public class UnpackingJSBundleLoader extends JSBundleLoader {
private @Nullable File destinationPath; private @Nullable File destinationPath;
private @Nullable String sourceURL; private @Nullable String sourceURL;
private final ArrayList<Unpacker> unpackers; private final ArrayList<Unpacker> unpackers;
private int loadFlags;
public Builder() { public Builder() {
this.unpackers = new ArrayList<Unpacker>(); this.unpackers = new ArrayList<Unpacker>();
context = null; context = null;
destinationPath = null; destinationPath = null;
sourceURL = null; sourceURL = null;
loadFlags = 0;
} }
public Builder setContext(Context context) { public Builder setContext(Context context) {
@ -227,6 +231,11 @@ public class UnpackingJSBundleLoader extends JSBundleLoader {
return this; return this;
} }
public Builder setLoadFlags(int loadFlags) {
this.loadFlags = loadFlags;
return this;
}
/** /**
* Adds a file for unpacking. Content of extracted file is not checked on each * Adds a file for unpacking. Content of extracted file is not checked on each
* start against content of the file bundled in apk. * start against content of the file bundled in apk.

View File

@ -105,10 +105,21 @@ public class UnpackingJSBundleLoaderTest {
verify(mCatalystInstanceImpl).loadScriptFromOptimizedBundle( verify(mCatalystInstanceImpl).loadScriptFromOptimizedBundle(
eq(mDestinationPath.getPath()), eq(mDestinationPath.getPath()),
eq(URL), eq(URL),
eq(UnpackingJSBundleLoader.UNPACKED_JS_SOURCE)); eq(0));
verifyNoMoreInteractions(mCatalystInstanceImpl); verifyNoMoreInteractions(mCatalystInstanceImpl);
} }
@Test
public void testSetLoadFlags() throws IOException {
mBuilder.setLoadFlags(UnpackingJSBundleLoader.UNPACKED_JS_SOURCE)
.build()
.loadScript(mCatalystInstanceImpl);
verify(mCatalystInstanceImpl).loadScriptFromOptimizedBundle(
eq(mDestinationPath.getPath()),
eq(URL),
eq(UnpackingJSBundleLoader.UNPACKED_JS_SOURCE));
}
@Test @Test
public void testLoadScriptUnpacks() { public void testLoadScriptUnpacks() {
mBuilder.build().loadScript(mCatalystInstanceImpl); mBuilder.build().loadScript(mCatalystInstanceImpl);