Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame^] | 1 | // Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file |
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | package dx; |
| 5 | |
| 6 | import java.io.File; |
| 7 | import java.io.IOException; |
| 8 | import org.gradle.api.Action; |
| 9 | import org.gradle.api.DefaultTask; |
| 10 | import org.gradle.api.UncheckedIOException; |
| 11 | import org.gradle.api.file.FileTree; |
| 12 | import org.gradle.api.tasks.TaskAction; |
| 13 | import org.gradle.process.ExecSpec; |
| 14 | import utils.Utils; |
| 15 | |
| 16 | public class DexMerger extends DefaultTask { |
| 17 | |
| 18 | private FileTree source; |
| 19 | private File destination; |
| 20 | private File dexMergerExecutable; |
| 21 | private boolean debug; |
| 22 | |
| 23 | public FileTree getSource() { |
| 24 | return source; |
| 25 | } |
| 26 | |
| 27 | public void setSource(FileTree source) { |
| 28 | this.source = source; |
| 29 | getInputs().file(source); |
| 30 | } |
| 31 | |
| 32 | public File getDestination() { |
| 33 | return destination; |
| 34 | } |
| 35 | |
| 36 | public void setDestination(File destination) { |
| 37 | this.destination = destination; |
| 38 | getOutputs().file(destination); |
| 39 | } |
| 40 | |
| 41 | public File getDexMergerExecutable() { |
| 42 | return dexMergerExecutable; |
| 43 | } |
| 44 | |
| 45 | public void setDexMergerExecutable(File dexMergerExecutable) { |
| 46 | this.dexMergerExecutable = dexMergerExecutable; |
| 47 | } |
| 48 | |
| 49 | @TaskAction |
| 50 | void exec() { |
| 51 | getProject().exec(new Action<ExecSpec>() { |
| 52 | @Override |
| 53 | public void execute(ExecSpec execSpec) { |
| 54 | try { |
| 55 | if (dexMergerExecutable == null) { |
| 56 | dexMergerExecutable = new File("tools/" + Utils.toolsDir() + "/dx/bin/dexmerger"); |
| 57 | } |
| 58 | execSpec.setExecutable(dexMergerExecutable); |
| 59 | execSpec.args(destination.getCanonicalPath()); |
| 60 | execSpec.args(source.getFiles()); |
| 61 | } catch (IOException e) { |
| 62 | throw new UncheckedIOException(e); |
| 63 | } |
| 64 | } |
| 65 | }); |
| 66 | } |
| 67 | } |