[android] remove deprecated gradle plugin
This commit is contained in:
parent
ae5de54f00
commit
ce7de93275
|
@ -1,5 +0,0 @@
|
|||
.idea/*
|
||||
!.idea/codeStyleSettings.xml
|
||||
|
||||
.gradle
|
||||
*.iml
|
|
@ -1,110 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectCodeStyleSettingsManager">
|
||||
<option name="PER_PROJECT_SETTINGS">
|
||||
<value>
|
||||
<option name="OTHER_INDENT_OPTIONS">
|
||||
<value>
|
||||
<option name="INDENT_SIZE" value="2" />
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||
<option name="TAB_SIZE" value="2" />
|
||||
<option name="USE_TAB_CHARACTER" value="false" />
|
||||
<option name="SMART_TABS" value="false" />
|
||||
<option name="LABEL_INDENT_SIZE" value="0" />
|
||||
<option name="LABEL_INDENT_ABSOLUTE" value="false" />
|
||||
<option name="USE_RELATIVE_INDENTS" value="false" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="FIELD_NAME_PREFIX" value="m" />
|
||||
<option name="STATIC_FIELD_NAME_PREFIX" value="s" />
|
||||
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="10000" />
|
||||
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="10000" />
|
||||
<option name="IMPORT_LAYOUT_TABLE">
|
||||
<value>
|
||||
<package name="javax" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="java" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="android" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="com.facebook" withSubpackages="true" static="false" />
|
||||
<package name="com.instagram" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="" withSubpackages="true" static="true" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="RIGHT_MARGIN" value="100" />
|
||||
<option name="JD_ALIGN_PARAM_COMMENTS" value="false" />
|
||||
<option name="JD_ALIGN_EXCEPTION_COMMENTS" value="false" />
|
||||
<option name="FORMATTER_TAGS_ENABLED" value="true" />
|
||||
<option name="WRAP_COMMENTS" value="true" />
|
||||
<XML>
|
||||
<option name="XML_TEXT_WRAP" value="0" />
|
||||
<option name="XML_KEEP_BLANK_LINES" value="1" />
|
||||
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
|
||||
</XML>
|
||||
<codeStyleSettings language="JAVA">
|
||||
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
|
||||
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
|
||||
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1" />
|
||||
<option name="BLANK_LINES_AFTER_CLASS_HEADER" value="1" />
|
||||
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
|
||||
<option name="CALL_PARAMETERS_WRAP" value="5" />
|
||||
<option name="CALL_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="METHOD_PARAMETERS_WRAP" value="5" />
|
||||
<option name="METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="RESOURCE_LIST_WRAP" value="5" />
|
||||
<option name="RESOURCE_LIST_LPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="EXTENDS_LIST_WRAP" value="1" />
|
||||
<option name="THROWS_LIST_WRAP" value="1" />
|
||||
<option name="EXTENDS_KEYWORD_WRAP" value="1" />
|
||||
<option name="THROWS_KEYWORD_WRAP" value="1" />
|
||||
<option name="METHOD_CALL_CHAIN_WRAP" value="1" />
|
||||
<option name="BINARY_OPERATION_WRAP" value="1" />
|
||||
<option name="TERNARY_OPERATION_WRAP" value="1" />
|
||||
<option name="FOR_STATEMENT_WRAP" value="5" />
|
||||
<option name="FOR_STATEMENT_LPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="ARRAY_INITIALIZER_WRAP" value="1" />
|
||||
<option name="ASSIGNMENT_WRAP" value="1" />
|
||||
<option name="ASSERT_STATEMENT_WRAP" value="1" />
|
||||
<option name="FIELD_ANNOTATION_WRAP" value="1" />
|
||||
<option name="PARAMETER_ANNOTATION_WRAP" value="1" />
|
||||
<option name="VARIABLE_ANNOTATION_WRAP" value="1" />
|
||||
<option name="ENUM_CONSTANTS_WRAP" value="1" />
|
||||
<indentOptions>
|
||||
<option name="INDENT_SIZE" value="2" />
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||
<option name="TAB_SIZE" value="2" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="JavaScript">
|
||||
<option name="WRAP_COMMENTS" value="true" />
|
||||
<option name="PARENT_SETTINGS_INSTALLED" value="true" />
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="Python">
|
||||
<indentOptions>
|
||||
<option name="INDENT_SIZE" value="2" />
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||
<option name="TAB_SIZE" value="2" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="TypeScript">
|
||||
<option name="WRAP_COMMENTS" value="true" />
|
||||
<option name="PARENT_SETTINGS_INSTALLED" value="true" />
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="XML">
|
||||
<indentOptions>
|
||||
<option name="INDENT_SIZE" value="2" />
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||
<option name="TAB_SIZE" value="2" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
</value>
|
||||
</option>
|
||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default (1)" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
# React Native Gradle plugin
|
||||
|
||||
This is a plugin for the default build system for Android applications, [gradle][0]. It hooks into the default Android build lifecycle and copies the JS bundle from the packager server to the `assets/` folder.
|
||||
|
||||
## Usage
|
||||
|
||||
To add this plugin to an existing Android project, first add this to your top-level `build.gradle` file, under `buildscript / dependencies`:
|
||||
|
||||
classpath 'com.facebook.react:gradleplugin:1.0.+'
|
||||
|
||||
Then apply the plugin to your application module (usually `app/build.gradle`):
|
||||
|
||||
apply plugin: 'com.facebook.react'
|
||||
|
||||
That's it! The plugin will now download the bundle from the default packager location (http://localhost:8081/index.android.js) and place it in the assets folder at build time.
|
||||
|
||||
## Configuration
|
||||
|
||||
The following shows all of the values that can be customized and their defaults. Configuration goes into your application module (`app/build.gradle`).
|
||||
|
||||
react {
|
||||
bundleFileName "index.android.bundle"
|
||||
bundlePath "/index.android.bundle"
|
||||
jsRoot "../../"
|
||||
packagerHost "localhost:8082"
|
||||
packagerCommand "../node_modules/react-native/packager/launchAndroidPackager.command"
|
||||
|
||||
devParams {
|
||||
dev true
|
||||
inlineSourceMap false
|
||||
minify false
|
||||
runModule true
|
||||
skip true
|
||||
}
|
||||
releaseParams {
|
||||
dev false
|
||||
inlineSourceMap false
|
||||
minify true
|
||||
runModule true
|
||||
skip false
|
||||
}
|
||||
}
|
||||
|
||||
Here's a breakdown of the various configurations:
|
||||
|
||||
* `bundleFileName` specifies the name of the asset file that is generated and bundled in the `.apk`
|
||||
* `bundlePath` is the path to the bundle, as recognized by the packager server
|
||||
* `jsRoot` is the root of your entire app; this is scanned for `.js` files to determine when the bundle needs to be re-fetched
|
||||
* `packagerHost` is the packager server address
|
||||
* `packagerCommand` specifies how to start the packager server if it's not running
|
||||
* `devParams` and `releaseParams` specify what parameters to include in the request to the packager server when fetching the bundle; see below for more information
|
||||
* `skip` in `devParams` and `releaseParams` specifies whether to skip requesting and bundling the JS for that configuration
|
||||
|
||||
The default config makes it so that the following bundles are added to the respective builds, as `assets/index.android.bundle`. The dev bundle is normally skipped as it is loaded from the packager at runtime, but you can change this behavior by setting `skip` to `false` under `devParams`:
|
||||
|
||||
| Build | Packager URL |
|
||||
|---------|---------------------------------------------------------------------------------------------------|
|
||||
| dev | http://localhost:8082/index.android.js?dev=true&inlineSourceMap=false&minify=false&runModule=true |
|
||||
| release | http://localhost:8082/index.android.js?dev=false&inlineSourceMap=false&minify=true&runModule=true |
|
||||
|
||||
For more information regarding the URL parameters, check out the [packager documentation][1].
|
||||
|
||||
## Contributing
|
||||
|
||||
After you make changes to the plugin code, simply run `gradle build install` in this directory. Then, in your Android project, change the top-level buildscript classpath dependency to whatever version you just built, something like `1.2.3-SNAPSHOT`. This should be picked up and used from your local maven repository.
|
||||
|
||||
[0]: https://gradle.org/
|
||||
[1]: https://github.com/facebook/react-native/blob/master/packager/README.md
|
|
@ -1,18 +0,0 @@
|
|||
group = 'com.facebook.react'
|
||||
version = '1.0.0-SNAPSHOT'
|
||||
|
||||
apply plugin: 'groovy'
|
||||
apply plugin: 'maven'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile gradleApi()
|
||||
compile 'commons-io:commons-io:2.4'
|
||||
compile 'org.apache.commons:commons-lang3:3.4'
|
||||
|
||||
testCompile 'junit:junit:4.12'
|
||||
testCompile 'com.squareup.okhttp:mockwebserver:2.4.0'
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
rootProject.name = 'gradleplugin'
|
|
@ -1,232 +0,0 @@
|
|||
package com.facebook.react;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.PathMatcher;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.gradle.api.DefaultTask;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Base class for tasks that build JS packages. Handles requesting a bundle from the packager server
|
||||
* and putting it into the appropriate folder.
|
||||
*/
|
||||
public abstract class AbstractPackageJsTask extends DefaultTask {
|
||||
|
||||
/**
|
||||
* Describes the status of the JS packager server.
|
||||
*
|
||||
* @see #getPackagerStatus
|
||||
*/
|
||||
private enum PackagerStatus {
|
||||
/**
|
||||
* Packager is up and running
|
||||
*/
|
||||
RUNNING,
|
||||
|
||||
/**
|
||||
* Packager is not running, but could be started
|
||||
*/
|
||||
NOT_RUNNING,
|
||||
|
||||
/**
|
||||
* Packager is not running and can't be started, something else is listening on the configured
|
||||
* port
|
||||
*/
|
||||
UNKNOWN
|
||||
}
|
||||
|
||||
private final boolean mDebug;
|
||||
private final ReactGradleExtension mConfig;
|
||||
private final PackagerParams mPackagerParams;
|
||||
|
||||
private final Logger mLogger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
public AbstractPackageJsTask(boolean debug) throws IOException {
|
||||
mDebug = debug;
|
||||
|
||||
mConfig = ReactGradleExtension.getConfig(getProject());
|
||||
mPackagerParams = PackagerParams.getPackagerParams(mConfig, mDebug);
|
||||
|
||||
if (mPackagerParams.isSkip()) {
|
||||
setEnabled(false);
|
||||
} else {
|
||||
setupInputs(mConfig);
|
||||
setupOutputs(mConfig);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a bundle from packager and copy it to the appropriate folder.
|
||||
*/
|
||||
protected void copyBundle() throws Exception {
|
||||
File bundle = getOutputFile(mConfig);
|
||||
bundle.getParentFile().mkdirs();
|
||||
|
||||
PackagerStatus packagerStatus = getPackagerStatus(mConfig);
|
||||
if (packagerStatus == PackagerStatus.NOT_RUNNING) {
|
||||
boolean started = startPackager();
|
||||
if (started) {
|
||||
packagerStatus = getPackagerStatus(mConfig);
|
||||
}
|
||||
if (!started || packagerStatus != PackagerStatus.RUNNING) {
|
||||
throw new Exception(
|
||||
"Could not start packager server. Please start it manually and try again.");
|
||||
}
|
||||
}
|
||||
if (packagerStatus == PackagerStatus.RUNNING) {
|
||||
URL packageUrl = getPackageUrl(mConfig, mPackagerParams);
|
||||
|
||||
InputStream packageStream = packageUrl.openStream();
|
||||
OutputStream bundleStream = new FileOutputStream(bundle);
|
||||
IOUtils.copy(packageStream, bundleStream);
|
||||
IOUtils.closeQuietly(packageStream);
|
||||
IOUtils.closeQuietly(bundleStream);
|
||||
} else if (packagerStatus == PackagerStatus.UNKNOWN) {
|
||||
throw new Exception(
|
||||
"Did not recognize the server at " + mConfig.getPackagerHost() +
|
||||
". Please stop the service listening at this address and try again.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if there is an HTTP server running at the configured address and if it is our packager.
|
||||
* See {@link PackagerStatus} for the possible return values and their meaning.
|
||||
*
|
||||
* @param config the project config that contains packager address information
|
||||
*/
|
||||
private PackagerStatus getPackagerStatus(ReactGradleExtension config) throws URISyntaxException {
|
||||
try {
|
||||
URL statusUrl = new URI("http", config.getPackagerHost(), "/status", null, null).toURL();
|
||||
HttpURLConnection conn = (HttpURLConnection) statusUrl.openConnection();
|
||||
if (conn.getResponseCode() != 200) {
|
||||
// something else must be running on this port
|
||||
return PackagerStatus.UNKNOWN;
|
||||
}
|
||||
InputStream is = conn.getInputStream();
|
||||
String status = IOUtils.toString(is);
|
||||
IOUtils.closeQuietly(is);
|
||||
return status.contains("packager-status:running")
|
||||
? PackagerStatus.RUNNING
|
||||
: PackagerStatus.UNKNOWN;
|
||||
} catch (IOException e) {
|
||||
// connect must have failed
|
||||
return PackagerStatus.NOT_RUNNING;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to spawn a process to run the packager server. Currently support OSX and Linux by running
|
||||
* {@code open launchPackager.command} and {@code xterm -e bash launchPackager.command}
|
||||
* respectively. Always waits 5 seconds for the server to finish initializing.
|
||||
*
|
||||
* @return {@code true} if the server process was started successfully, {@code false} otherwise.
|
||||
*/
|
||||
private boolean startPackager() throws IOException, InterruptedException {
|
||||
if (SystemUtils.IS_OS_MAC_OSX || SystemUtils.IS_OS_LINUX) {
|
||||
String launchPackagerScript =
|
||||
Paths.get(getProject().getProjectDir().getAbsolutePath(), mConfig.getPackagerCommand())
|
||||
.normalize().toString();
|
||||
if (SystemUtils.IS_OS_MAC_OSX) {
|
||||
Runtime.getRuntime().exec(new String[]{"open", launchPackagerScript}, null, null);
|
||||
} else if (SystemUtils.IS_OS_LINUX) {
|
||||
Runtime.getRuntime()
|
||||
.exec(new String[]{"xterm", "-e", "bash", launchPackagerScript}, null, null);
|
||||
}
|
||||
// wait for server to be ready
|
||||
Thread.sleep(5000);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a packager URL for a specific configuration.
|
||||
*
|
||||
* @param config the top-level config of the plugin
|
||||
* @param params packager params to include in the URL
|
||||
*/
|
||||
private URL getPackageUrl(ReactGradleExtension config, PackagerParams params)
|
||||
throws URISyntaxException, MalformedURLException {
|
||||
String query = "dev=" + params.isDev() + "&" +
|
||||
"inlineSourceMap=" + params.isInlineSourceMap() + "&" +
|
||||
"minify=" + params.isMinify() + "&" +
|
||||
"runModule=" + params.isRunModule();
|
||||
return new URI(
|
||||
"http",
|
||||
config.getPackagerHost(),
|
||||
config.getBundlePath(),
|
||||
query,
|
||||
null).toURL();
|
||||
}
|
||||
|
||||
private void setupInputs(ReactGradleExtension config) throws IOException {
|
||||
final long startTime = System.currentTimeMillis();
|
||||
InputsScanner scanner = new InputsScanner();
|
||||
Files.walkFileTree(
|
||||
Paths.get(getProject().getProjectDir().getAbsolutePath(), config.getJsRoot()).normalize(),
|
||||
scanner);
|
||||
final long endTime = System.currentTimeMillis();
|
||||
mLogger.info("Added {} .js files in {}ms", scanner.getCount(), endTime - startTime);
|
||||
}
|
||||
|
||||
private void setupOutputs(ReactGradleExtension config) {
|
||||
getOutputs().file(getOutputFile(config));
|
||||
}
|
||||
|
||||
private File getOutputFile(ReactGradleExtension config) {
|
||||
File assets = new File(
|
||||
getProject().getProjectDir(),
|
||||
FilenameUtils
|
||||
.separatorsToSystem("build/intermediates/assets/" + (mDebug ? "debug" : "release")));
|
||||
return new File(assets, config.getBundleFileName());
|
||||
}
|
||||
|
||||
private class InputsScanner extends SimpleFileVisitor<Path> {
|
||||
|
||||
private final PathMatcher mMatcher = FileSystems.getDefault().getPathMatcher("glob:*.js");
|
||||
private int mCount = 0;
|
||||
|
||||
@Override
|
||||
public FileVisitResult preVisitDirectory(
|
||||
Path dir, BasicFileAttributes attrs) throws IOException {
|
||||
if ("build".equals(dir.getFileName().toString())) {
|
||||
return FileVisitResult.SKIP_SUBTREE;
|
||||
} else {
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
if (mMatcher.matches(file.getFileName())) {
|
||||
getInputs().file(file.toString());
|
||||
mCount++;
|
||||
}
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return mCount;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package com.facebook.react;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
|
||||
/**
|
||||
* Gradle task that copies the dev bundle to the debug build's assets.
|
||||
*/
|
||||
public class PackageDebugJsTask extends AbstractPackageJsTask {
|
||||
|
||||
public PackageDebugJsTask() throws IOException {
|
||||
super(true);
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
public void packageJS() throws Exception {
|
||||
copyBundle();
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package com.facebook.react;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
|
||||
/**
|
||||
* Gradle task that copies the prod bundle to the debug build's assets.
|
||||
*/
|
||||
public class PackageReleaseJsTask extends AbstractPackageJsTask {
|
||||
|
||||
public PackageReleaseJsTask() throws IOException {
|
||||
super(false);
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
public void packageJS() throws Exception {
|
||||
copyBundle();
|
||||
}
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
package com.facebook.react;
|
||||
|
||||
/**
|
||||
* POJO for packager parameters.
|
||||
*/
|
||||
public class PackagerParams {
|
||||
private boolean dev = true;
|
||||
private boolean inlineSourceMap = false;
|
||||
private boolean minify = false;
|
||||
private boolean runModule = true;
|
||||
private boolean skip = false;
|
||||
|
||||
/**
|
||||
* Returns default parameters for debug builds.
|
||||
*/
|
||||
public static PackagerParams devDefaults() {
|
||||
PackagerParams params = new PackagerParams();
|
||||
params.dev = true;
|
||||
params.inlineSourceMap = false;
|
||||
params.minify = false;
|
||||
params.runModule = true;
|
||||
params.skip = true;
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns default parameters for release builds.
|
||||
*/
|
||||
public static PackagerParams releaseDefaults() {
|
||||
PackagerParams params = new PackagerParams();
|
||||
params.dev = false;
|
||||
params.inlineSourceMap = false;
|
||||
params.minify = true;
|
||||
params.runModule = true;
|
||||
params.skip = false;
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract packager parameters from a configuration, or return default values.
|
||||
*
|
||||
* @param config the configuration to extract from
|
||||
* @param debug whether default values should be for debug or prod
|
||||
*/
|
||||
public static PackagerParams getPackagerParams(ReactGradleExtension config, boolean debug) {
|
||||
if (debug) {
|
||||
return config.getDevParams() != null
|
||||
? config.getDevParams()
|
||||
: PackagerParams.devDefaults();
|
||||
} else {
|
||||
return config.getReleaseParams() != null
|
||||
? config.getReleaseParams()
|
||||
: PackagerParams.releaseDefaults();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDev() {
|
||||
return dev;
|
||||
}
|
||||
|
||||
public void dev(boolean dev) {
|
||||
this.dev = dev;
|
||||
}
|
||||
|
||||
public boolean isInlineSourceMap() {
|
||||
return inlineSourceMap;
|
||||
}
|
||||
|
||||
public void inlineSourceMap(boolean inlineSourceMap) {
|
||||
this.inlineSourceMap = inlineSourceMap;
|
||||
}
|
||||
|
||||
public boolean isMinify() {
|
||||
return minify;
|
||||
}
|
||||
|
||||
public void minify(boolean minify) {
|
||||
this.minify = minify;
|
||||
}
|
||||
|
||||
public boolean isRunModule() {
|
||||
return runModule;
|
||||
}
|
||||
|
||||
public void runModule(boolean runModule) {
|
||||
this.runModule = runModule;
|
||||
}
|
||||
|
||||
public boolean isSkip() {
|
||||
return skip;
|
||||
}
|
||||
|
||||
public void skip(boolean skip) {
|
||||
this.skip = skip;
|
||||
}
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
package com.facebook.react;
|
||||
|
||||
import groovy.lang.Closure;
|
||||
import org.gradle.api.Project;
|
||||
|
||||
/**
|
||||
* POJO-ish class for configuring the plugin.
|
||||
*/
|
||||
public class ReactGradleExtension {
|
||||
private String bundleFileName = "index.android.bundle";
|
||||
private String bundlePath = "/index.android.bundle";
|
||||
private String jsRoot = "../../";
|
||||
private String packagerHost = "localhost:8082";
|
||||
private String packagerCommand =
|
||||
"../../node_modules/react-native/packager/launchAndroidPackager.command";
|
||||
|
||||
private PackagerParams devParams;
|
||||
private PackagerParams releaseParams;
|
||||
|
||||
private Project project;
|
||||
|
||||
public ReactGradleExtension(Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configuration for a project, or a blank config.
|
||||
*/
|
||||
public static ReactGradleExtension getConfig(Project project) {
|
||||
ReactGradleExtension config =
|
||||
project.getExtensions().findByType(ReactGradleExtension.class);
|
||||
if (config == null) {
|
||||
config = new ReactGradleExtension(project);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
public String getBundleFileName() {
|
||||
return bundleFileName;
|
||||
}
|
||||
|
||||
public void setBundleFileName(String bundleFileName) {
|
||||
this.bundleFileName = bundleFileName;
|
||||
}
|
||||
|
||||
public String getBundlePath() {
|
||||
return bundlePath;
|
||||
}
|
||||
|
||||
public void setBundlePath(String bundlePath) {
|
||||
this.bundlePath = bundlePath;
|
||||
}
|
||||
|
||||
public String getJsRoot() {
|
||||
return jsRoot;
|
||||
}
|
||||
|
||||
public void setJsRoot(String jsRoot) {
|
||||
this.jsRoot = jsRoot;
|
||||
}
|
||||
|
||||
public void setPackagerCommand(String packagerCommand) {
|
||||
this.packagerCommand = packagerCommand;
|
||||
}
|
||||
|
||||
public String getPackagerCommand() {
|
||||
return packagerCommand;
|
||||
}
|
||||
|
||||
public String getPackagerHost() {
|
||||
return packagerHost;
|
||||
}
|
||||
|
||||
public void setPackagerHost(String packagerHost) {
|
||||
this.packagerHost = packagerHost;
|
||||
}
|
||||
|
||||
public PackagerParams getDevParams() {
|
||||
return devParams;
|
||||
}
|
||||
|
||||
public void devParams(Closure closure) {
|
||||
devParams = new PackagerParams();
|
||||
project.configure(devParams, closure);
|
||||
}
|
||||
|
||||
public PackagerParams getReleaseParams() {
|
||||
return releaseParams;
|
||||
}
|
||||
|
||||
public void releaseParams(Closure closure) {
|
||||
releaseParams = new PackagerParams();
|
||||
project.configure(releaseParams, closure);
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
package com.facebook.react;
|
||||
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.Task;
|
||||
|
||||
/**
|
||||
* Main entry point for our plugin. When applied to a project, this registers the {@code react}
|
||||
* gradle extension used for configuration and the {@code packageDebugJS} and
|
||||
* {@code packageReleaseJS} tasks. These are set up to run after {@code mergeDebugAssets} and
|
||||
* {@code mergeReleaseAssets} and before {@code processDebugResources} and
|
||||
* {@code processReleaseResources} respectively. If any of these tasks are not found the plugin will
|
||||
* crash (UnknownTaskException), as it was probably applied to a non-standard Android project, or it
|
||||
* was applied incorrectly.
|
||||
*/
|
||||
public class ReactGradlePlugin implements Plugin<Project> {
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
project.getExtensions().create("react", ReactGradleExtension.class, project);
|
||||
|
||||
project.afterEvaluate(
|
||||
new Action<Project>() {
|
||||
@Override
|
||||
public void execute(Project project) {
|
||||
PackageDebugJsTask packageDebugJsTask =
|
||||
project.getTasks().create("packageDebugJS", PackageDebugJsTask.class);
|
||||
PackageReleaseJsTask packageReleaseJsTask =
|
||||
project.getTasks().create("packageReleaseJS", PackageReleaseJsTask.class);
|
||||
|
||||
packageDebugJsTask.dependsOn("mergeDebugAssets");
|
||||
project.getTasks().getByName("processDebugResources").dependsOn(packageDebugJsTask);
|
||||
|
||||
packageReleaseJsTask.dependsOn("mergeReleaseAssets");
|
||||
project.getTasks().getByName("processReleaseResources").dependsOn(packageReleaseJsTask);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
implementation-class=com.facebook.react.ReactGradlePlugin
|
|
@ -1,85 +0,0 @@
|
|||
package com.facebook.react;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import com.squareup.okhttp.mockwebserver.MockResponse;
|
||||
import com.squareup.okhttp.mockwebserver.MockWebServer;
|
||||
import com.squareup.okhttp.mockwebserver.RecordedRequest;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.Task;
|
||||
import org.gradle.testfixtures.ProjectBuilder;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class PackageJSTasksTest {
|
||||
|
||||
private MockWebServer server;
|
||||
private Project project;
|
||||
|
||||
@Before
|
||||
public void setupMocks() throws IOException {
|
||||
server = new MockWebServer();
|
||||
server.enqueue(new MockResponse().setBody("This is some javascript"));
|
||||
server.start();
|
||||
|
||||
project = ProjectBuilder.builder().build();
|
||||
project.getPlugins().apply("com.facebook.react");
|
||||
project.getExtensions().configure(
|
||||
ReactGradleExtension.class,
|
||||
new Action<ReactGradleExtension>() {
|
||||
@Override
|
||||
public void execute(ReactGradleExtension config) {
|
||||
config.setPackagerHost(server.getHostName() + ":" + server.getPort());
|
||||
config.setBundleFileName("test.js");
|
||||
config.setBundlePath("/test.bundle");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void packageDebugJS() throws IOException, URISyntaxException, InterruptedException {
|
||||
Task task = project.getTasks().findByName("packageDebugJS");
|
||||
assertTrue(task != null && task instanceof PackageDebugJsTask);
|
||||
|
||||
((PackageDebugJsTask) task).packageJS();
|
||||
|
||||
RecordedRequest request = server.takeRequest();
|
||||
assertEquals(
|
||||
"/test.bundle?dev=true&inlineSourceMap=false&minify=false&runModule=true",
|
||||
request.getPath());
|
||||
assertEquals(
|
||||
"This is some javascript",
|
||||
FileUtils.readFileToString(
|
||||
new File(
|
||||
project.getProjectDir(),
|
||||
FilenameUtils.separatorsToSystem("build/intermediates/assets/debug/test.js"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void packageReleaseJS() throws IOException, URISyntaxException, InterruptedException {
|
||||
Task task = project.getTasks().findByName("packageReleaseJS");
|
||||
assertTrue(task != null && task instanceof PackageReleaseJsTask);
|
||||
|
||||
((PackageReleaseJsTask) task).packageJS();
|
||||
|
||||
RecordedRequest request = server.takeRequest();
|
||||
assertEquals(
|
||||
"/test.bundle?dev=false&inlineSourceMap=false&minify=true&runModule=true",
|
||||
request.getPath());
|
||||
assertEquals(
|
||||
"This is some javascript",
|
||||
FileUtils.readFileToString(
|
||||
new File(
|
||||
project.getProjectDir(),
|
||||
FilenameUtils.separatorsToSystem("build/intermediates/assets/release/test.js"))));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package com.facebook.react;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.testfixtures.ProjectBuilder;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ReactGradlePluginTest {
|
||||
@Test
|
||||
public void addsTasksToProject() {
|
||||
Project project = ProjectBuilder.builder().build();
|
||||
project.getPlugins().apply("com.facebook.react");
|
||||
|
||||
assertTrue(project.getTasks().getByName("packageDebugJS") instanceof PackageDebugJsTask);
|
||||
assertTrue(project.getTasks().getByName("packageReleaseJS") instanceof PackageReleaseJsTask);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addsExtensionToProject() {
|
||||
Project project = ProjectBuilder.builder().build();
|
||||
project.getPlugins().apply("com.facebook.react");
|
||||
|
||||
assertTrue(project.getExtensions().getByName("react") instanceof ReactGradleExtension);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue