private void runTransform(Transform transform, TransformOutputProvider outputProvider) throws Exception { // Cleaning output directory. FileUtil.deleteDirectory(outputJarsDir); outputJarsDir.mkdirs(); // Preparing Transform invocation. TransformInput input = new TransformInputBuilder().addJarInputFolder(inputJarsDir).build(); TransformInput referencedInput = new TransformInputBuilder().addJarInput(androidClassPath).build(); TransformInvocation invocation = new TransformInvocationBuilder() .addInput(input) .addReferencedInput(referencedInput) .setOutputProvider(outputProvider) .build(); // Running the transform invocation. transform.transform(invocation); } }
private boolean validateTransform(@NonNull Transform transform) { // check the content type are of the right Type. if (!checkContentTypes(transform.getInputTypes(), transform) || !checkContentTypes(transform.getOutputTypes(), transform)) { return false; } // check some scopes are not consumed. Set<? super Scope> scopes = transform.getScopes(); // Allow Jack transform to consume provided classes as the .jack files are needed. if (scopes.contains(Scope.PROVIDED_ONLY) && !isJackRuntimeLib(transform)) { errorReporter.handleSyncError(null, SyncIssue.TYPE_GENERIC, String.format("PROVIDED_ONLY scope cannot be consumed by Transform '%1$s'", transform.getName())); return false; } if (scopes.contains(Scope.TESTED_CODE)) { errorReporter.handleSyncError(null, SyncIssue.TYPE_GENERIC, String.format("TESTED_CODE scope cannot be consumed by Transform '%1$s'", transform.getName())); return false; } return true; }
String.format( "Unable to add Transform '%s' on variant '%s': requested streams not available: %s+%s / %s", transform.getName(), scope.getFullVariantName(), transform.getScopes(), transform.getReferencedScopes(), transform.getInputTypes())); return Optional.empty(); logger.debug("\tName: " + transform.getName()); logger.debug("\tTask: " + taskName); for (TransformStream sd : inputStreams) {
private synchronized Collection<SecondaryFile> getAllSecondaryInputs() { if (secondaryFiles == null) { ImmutableList.Builder<SecondaryFile> builder = ImmutableList.builder(); builder.addAll(transform.getSecondaryFiles()); builder.addAll( Iterables.transform( transform.getSecondaryFileInputs(), SecondaryFile::nonIncremental)); secondaryFiles = builder.build(); } return secondaryFiles; }
IncrementalTransformInput next = iterator.next(); if (next.checkRemovedJarFile( Sets.union(transform.getScopes(), transform.getReferencedScopes()), transform.getInputTypes(), removedFile, removedFileSegments) || next.checkRemovedFolderFile( Sets.union(transform.getScopes(), transform.getReferencedScopes()), transform.getInputTypes(), removedFile, removedFileSegments)) {
@OutputDirectories public Collection<File> getOtherFolderOutputs() { return transform.getSecondaryDirectoryOutputs(); }
@VisibleForTesting @NonNull static String getTaskNamePrefix(@NonNull Transform transform) { StringBuilder sb = new StringBuilder(100); sb.append("transform"); sb.append( transform.getInputTypes() .stream() .map(inputType -> CaseFormat.UPPER_UNDERSCORE.to( CaseFormat.UPPER_CAMEL, inputType.name())) .sorted() // Keep the order stable. .collect(Collectors.joining("And"))) .append("With") .append(capitalize(transform.getName())) .append("For"); return sb.toString(); }
@NonNull private List<TransformStream> grabReferencedStreams(@NonNull Transform transform) { Set<? super Scope> requestedScopes = transform.getReferencedScopes(); if (requestedScopes.isEmpty()) { return ImmutableList.of(); } List<TransformStream> streamMatches = Lists.newArrayListWithExpectedSize(streams.size()); Set<ContentType> requestedTypes = transform.getInputTypes(); for (TransformStream stream : streams) { // streams may contain more than we need. In this case, we'll provide the whole // stream as-is since it's not actually consumed. // It'll be up to the TransformTask to make sure that the content of the stream is // usable (for instance when a stream // may contain two scopes, these scopes could be combined or not, impacting consumption) Set<ContentType> availableTypes = stream.getContentTypes(); Set<? super Scope> availableScopes = stream.getScopes(); Set<ContentType> commonTypes = Sets.intersection(requestedTypes, availableTypes); Set<? super Scope> commonScopes = Sets.intersection(requestedScopes, availableScopes); if (!commonTypes.isEmpty() && !commonScopes.isEmpty()) { streamMatches.add(stream); } } return streamMatches; }
private boolean checkContentTypes( @NonNull Set<ContentType> contentTypes, @NonNull Transform transform) { for (ContentType contentType : contentTypes) { if (!(contentType instanceof QualifiedContent.DefaultContentType || contentType instanceof ExtendedContentType)) { errorReporter.handleSyncError(null, SyncIssue.TYPE_GENERIC, String.format("Custom content types (%1$s) are not supported in transforms (%2$s)", contentType.getClass().getName(), transform.getName())); return false; } } return true; }
@Input public Map<String, Object> getOtherInputs() { return transform.getParameterInputs(); }
/** * Returns the type(s) of data that is generated by the Transform. This may be more than * one type. * * <p>The default implementation returns {@link #getInputTypes()}. * * <p><strong>This must be of type {@link QualifiedContent.DefaultContentType}</strong> */ @NonNull public Set<ContentType> getOutputTypes() { return getInputTypes(); }
if (transform.getScopes().isEmpty()) { variantScope.getAssembleTask().dependsOn(tasks, t);
@NonNull File buildDir) { Set<? super Scope> requestedScopes = transform.getScopes(); if (requestedScopes.isEmpty()) { Set<ContentType> requestedTypes = transform.getInputTypes(); Set<ContentType> outputTypes = transform.getOutputTypes(); transform.getName(), scope.getDirectorySegments()));
@InputFiles public Collection<File> getOtherFileInputs() { //noinspection deprecation: Needed for backward compatibility. return Stream.concat( transform.getSecondaryFiles().stream().map(SecondaryFile::getFile), transform.getSecondaryFileInputs().stream()) .collect(Collectors.toList()); }
if (t.getTransform().getName().equals(NAME)) { t.dependsOn(getByVariant(t.getVariantName()));
@Override public void transform(TransformInvocation transformInvocation) throws TransformException, InterruptedException, IOException { super.transform(transformInvocation); Collection<TransformInput> inputs = transformInvocation.getInputs(); TransformOutputProvider outputProvider = transformInvocation.getOutputProvider();
transform(transformInvocation.getContext(), transformInvocation.getInputs(), transformInvocation.getReferencedInputs(), transformInvocation.getOutputProvider(),