@Test public void ninePatchPngsAreNotProcessedIfNotEnabledBeforeV22() throws Exception { Aapt aapt = makeAapt( AaptV1.PngProcessMode.NONE, new Revision(AaptV1.VERSION_FOR_SERVER_AAPT.getMajor() - 1, 0, 0)); File originalFile = AaptTestUtils.getNinePatchTestPng(); Future<File> compiledFuture = aapt.compile(originalFile, AaptTestUtils.getOutputDir(mTemporaryFolder)); File compiled = compiledFuture.get(); assertNull(compiled); }
@NonNull @Override public ListenableFuture<File> compile(@NonNull File file, @NonNull File output) throws AaptException { ListenableFuture<File> compilationFuture; if (ResourceFolderType.getFolderType(file.getParentFile().getName()) == ResourceFolderType.RAW) { return Futures.immediateFuture(null); } if (mCruncher == null) { compilationFuture = super.compile(file, output); } else { Preconditions.checkArgument(file.isFile(), "!file.isFile()"); Preconditions.checkArgument(output.isDirectory(), "!output.isDirectory()"); SettableFuture<File> future = SettableFuture.create(); compilationFuture = future; if (!mProcessMode.shouldProcess(file)) { future.set(null); } else { File outputFile = compileOutputFor(file, output); try { Files.createParentDirs(outputFile); } catch (IOException e) { throw new AaptException(e, String.format( "Failed to create parent directories for file '%s'", output.getAbsolutePath())); } int key = mCruncher.start(); try { mCruncher.crunchPng(key, file, outputFile); } catch (PngException e) { throw new AaptException(e, String.format( "Failed to crunch file '%s' into '%s'", file.getAbsolutePath(), outputFile.getAbsolutePath())); } mWaitExecutor.execute(() -> { try { mCruncher.end(key); future.set(outputFile); } catch (Exception e) { future.setException(e); } }); } } if (file.getName().endsWith(SdkConstants.DOT_9PNG)) { return compilationFuture; } return Futures.transform(compilationFuture, (File result) -> { SettableFuture<File> returnFuture = SettableFuture.create(); try { if (result != null && file.length() < result.length()) { Files.copy(file, result); } returnFuture.set(result); } catch (Exception e) { returnFuture.setException(e); } return returnFuture; }); }
AaptV1 extends AbstractProcessExecutionAapt { @NonNull @Override public ListenableFuture<File> compile(@NonNull File file, @NonNull File output) throws AaptException { ListenableFuture<File> compilationFuture; if (ResourceFolderType.getFolderType(file.getParentFile().getName()) == ResourceFolderType.RAW) { return Futures.immediateFuture(null); } if (mCruncher == null) { compilationFuture = super.compile(file, output); } else { Preconditions.checkArgument(file.isFile(), "!file.isFile()"); Preconditions.checkArgument(output.isDirectory(), "!output.isDirectory()"); SettableFuture<File> future = SettableFuture.create(); compilationFuture = future; if (!mProcessMode.shouldProcess(file)) { future.set(null); } else { File outputFile = compileOutputFor(file, output); try { Files.createParentDirs(outputFile); } catch (IOException e) { throw new AaptException(e, String.format( "Failed to create parent directories for file '%s'", output.getAbsolutePath())); } int key = mCruncher.start(); try { mCruncher.crunchPng(key, file, outputFile); } catch (PngException e) { throw new AaptException(e, String.format( "Failed to crunch file '%s' into '%s'", file.getAbsolutePath(), outputFile.getAbsolutePath())); } mWaitExecutor.execute(() -> { try { mCruncher.end(key); future.set(outputFile); } catch (Exception e) { future.setException(e); } }); } } if (file.getName().endsWith(SdkConstants.DOT_9PNG)) { return compilationFuture; } return Futures.transform(compilationFuture, (File result) -> { SettableFuture<File> returnFuture = SettableFuture.create(); try { if (result != null && file.length() < result.length()) { Files.copy(file, result); } returnFuture.set(result); } catch (Exception e) { returnFuture.setException(e); } return returnFuture; }); } }
AaptV1 extends AbstractProcessExecutionAapt { @NonNull @Override public ListenableFuture<File> compile(@NonNull File file, @NonNull File output) throws AaptException { ListenableFuture<File> compilationFuture; if (ResourceFolderType.getFolderType(file.getParentFile().getName()) == ResourceFolderType.RAW) { return Futures.immediateFuture(null); } if (mCruncher == null) { compilationFuture = super.compile(file, output); } else { Preconditions.checkArgument(file.isFile(), "!file.isFile()"); Preconditions.checkArgument(output.isDirectory(), "!output.isDirectory()"); SettableFuture<File> future = SettableFuture.create(); compilationFuture = future; if (!mProcessMode.shouldProcess(file)) { future.set(null); } else { File outputFile = compileOutputFor(file, output); try { Files.createParentDirs(outputFile); } catch (IOException e) { throw new AaptException(e, String.format( "Failed to create parent directories for file '%s'", output.getAbsolutePath())); } int key = mCruncher.start(); try { mCruncher.crunchPng(key, file, outputFile); } catch (PngException e) { throw new AaptException(e, String.format( "Failed to crunch file '%s' into '%s'", file.getAbsolutePath(), outputFile.getAbsolutePath())); } mWaitExecutor.execute(() -> { try { mCruncher.end(key); future.set(outputFile); } catch (Exception e) { future.setException(e); } }); } } if (file.getName().endsWith(SdkConstants.DOT_9PNG)) { return compilationFuture; } return Futures.transform(compilationFuture, (File result) -> { SettableFuture<File> returnFuture = SettableFuture.create(); try { if (result != null && file.length() < result.length()) { Files.copy(file, result); } returnFuture.set(result); } catch (Exception e) { returnFuture.setException(e); } return returnFuture; }); } AaptV1(
            @NonNull ProcessExecutor processExecutor,
            @NonNull ProcessOutputHandler processOutputHandler,
            @NonNull BuildToolInfo buildToolInfo,
            @NonNull ILogger logger,
            @NonNull PngProcessMode processMode,
            int cruncherProcesses); }
AaptV1 extends AbstractProcessExecutionAapt { @NonNull @Override public ListenableFuture<File> compile(@NonNull File file, @NonNull File output) throws AaptException { ListenableFuture<File> compilationFuture; if (ResourceFolderType.getFolderType(file.getParentFile().getName()) == ResourceFolderType.RAW) { return Futures.immediateFuture(null); } if (mCruncher == null) { compilationFuture = super.compile(file, output); } else { Preconditions.checkArgument(file.isFile(), "!file.isFile()"); Preconditions.checkArgument(output.isDirectory(), "!output.isDirectory()"); SettableFuture<File> future = SettableFuture.create(); compilationFuture = future; if (!mProcessMode.shouldProcess(file)) { future.set(null); } else { File outputFile = compileOutputFor(file, output); try { Files.createParentDirs(outputFile); } catch (IOException e) { throw new AaptException(e, String.format( "Failed to create parent directories for file '%s'", output.getAbsolutePath())); } int key = mCruncher.start(); try { mCruncher.crunchPng(key, file, outputFile); } catch (PngException e) { throw new AaptException(e, String.format( "Failed to crunch file '%s' into '%s'", file.getAbsolutePath(), outputFile.getAbsolutePath())); } mWaitExecutor.execute(() -> { try { mCruncher.end(key); future.set(outputFile); } catch (Exception e) { future.setException(e); } }); } } if (file.getName().endsWith(SdkConstants.DOT_9PNG)) { return compilationFuture; } return Futures.transform(compilationFuture, (File result) -> { SettableFuture<File> returnFuture = SettableFuture.create(); try { if (result != null && file.length() < result.length()) { Files.copy(file, result); } returnFuture.set(result); } catch (Exception e) { returnFuture.setException(e); } return returnFuture; }); } AaptV1(
            @NonNull ProcessExecutor processExecutor,
            @NonNull ProcessOutputHandler processOutputHandler,
            @NonNull BuildToolInfo buildToolInfo,
            @NonNull ILogger logger,
            @NonNull PngProcessMode processMode,
            int cruncherProcesses); @NonNull @Override ListenableFuture<File> compile(@NonNull File file, @NonNull File output); }
AaptV1 extends AbstractProcessExecutionAapt { @NonNull @Override public ListenableFuture<File> compile(@NonNull File file, @NonNull File output) throws AaptException { ListenableFuture<File> compilationFuture; if (ResourceFolderType.getFolderType(file.getParentFile().getName()) == ResourceFolderType.RAW) { return Futures.immediateFuture(null); } if (mCruncher == null) { compilationFuture = super.compile(file, output); } else { Preconditions.checkArgument(file.isFile(), "!file.isFile()"); Preconditions.checkArgument(output.isDirectory(), "!output.isDirectory()"); SettableFuture<File> future = SettableFuture.create(); compilationFuture = future; if (!mProcessMode.shouldProcess(file)) { future.set(null); } else { File outputFile = compileOutputFor(file, output); try { Files.createParentDirs(outputFile); } catch (IOException e) { throw new AaptException(e, String.format( "Failed to create parent directories for file '%s'", output.getAbsolutePath())); } int key = mCruncher.start(); try { mCruncher.crunchPng(key, file, outputFile); } catch (PngException e) { throw new AaptException(e, String.format( "Failed to crunch file '%s' into '%s'", file.getAbsolutePath(), outputFile.getAbsolutePath())); } mWaitExecutor.execute(() -> { try { mCruncher.end(key); future.set(outputFile); } catch (Exception e) { future.setException(e); } }); } } if (file.getName().endsWith(SdkConstants.DOT_9PNG)) { return compilationFuture; } return Futures.transform(compilationFuture, (File result) -> { SettableFuture<File> returnFuture = SettableFuture.create(); try { if (result != null && file.length() < result.length()) { Files.copy(file, result); } returnFuture.set(result); } catch (Exception e) { returnFuture.setException(e); } return returnFuture; }); } AaptV1(
            @NonNull ProcessExecutor processExecutor,
            @NonNull ProcessOutputHandler processOutputHandler,
            @NonNull BuildToolInfo buildToolInfo,
            @NonNull ILogger logger,
            @NonNull PngProcessMode processMode,
            int cruncherProcesses); @NonNull @Override ListenableFuture<File> compile(@NonNull File file, @NonNull File output);  }