/** * 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); } }
this.inputJarsDir = getFile(inJarsDir, "Input jars dir not existing or invalid.", true); System.out.println("Input jars dir: " + inputJarsDir.getAbsolutePath()); this.outputJarsDir = getFile(outJarsDir, "Output jars dir not existing or invalid.", true); System.out.println("Output jars dir: " + outputJarsDir.getAbsolutePath()); this.configFile = getFile(configFilePath, "Config file not existing or invalid.", false); System.out.println("Config file: " + configFile.getAbsolutePath()); } else {
@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<Transform> transformClass; String transformClassName = System.getProperty(PROPERTY_TRANSFORM_CLASS); if (transformClassName != null) { transformClass = (Class<Transform>) 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); } } });
/** * 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); }
@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(); } }