Java Code Examples for org.gradle.api.tasks.incremental.InputFileDetails

The following examples show how to use org.gradle.api.tasks.incremental.InputFileDetails. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public void execute(InputFileDetails inputFileDetails) {
    if (fullRebuildNeeded != null) {
        return;
    }
    File inputFile = inputFileDetails.getFile();
    String name = inputFile.getName();
    if (name.endsWith(".java")) {
        JavaSourceClass source = mapper.toJavaSourceClass(inputFile);
        compiler.addStaleClass(source);
        changedSourceOnly.include(source.getRelativePath());
        Set<String> actualDependents = dependencyInfo.getActualDependents(source.getClassName());
        if (actualDependents == null) {
            fullRebuildNeeded = "change to " + source.getClassName() + " requires full rebuild";
            return;
        }
        for (String d : actualDependents) {
            JavaSourceClass dSource = mapper.toJavaSourceClass(d);
            compiler.addStaleClass(dSource);
            changedSourceOnly.include(dSource.getRelativePath());
        }
    }
    if (name.endsWith(".jar")) {
        fullRebuildNeeded = "change to " + inputFile + " requires full rebuild";
        return;
    }
}
 
Example 2
public RebuildInfo processJarChange(InputFileDetails jarChangeDetails, JarArchive jarArchive) {
    JarSnapshot existing = jarSnapshotFeeder.changedJar(jarChangeDetails.getFile());
    if (jarChangeDetails.isAdded()) {
        return DefaultRebuildInfo.NOTHING_TO_REBUILD;
    }

    if (jarChangeDetails.isRemoved()) {
        if (existing != null) {
            return new AllFromJarRebuildInfo(jarArchive);
        } else {
            return DefaultRebuildInfo.FULL_REBUILD;
        }
    }

    if (jarChangeDetails.isModified()) {
        if (existing != null) {
            JarSnapshot newSnapshot = jarSnapshotFeeder.createSnapshot(jarArchive);
            JarDelta jarDelta = existing.compareToSnapshot(newSnapshot);
            return new SpecificClassesRebuildInfo(jarDelta);
        } else {
            return new AllFromJarRebuildInfo(jarArchive);
        }
    }

    throw new IllegalArgumentException("Unknown input file details provided: " + jarChangeDetails);
}
 
Example 3
public void execute(InputFileDetails inputFileDetails) {
    if (fullRebuildNeeded != null) {
        return;
    }
    File inputFile = inputFileDetails.getFile();
    String name = inputFile.getName();
    if (name.endsWith(".java")) {
        JavaSourceClass source = mapper.toJavaSourceClass(inputFile);
        compiler.addStaleClass(source);
        changedSourceOnly.include(source.getRelativePath());
        Set<String> actualDependents = dependencyInfo.getActualDependents(source.getClassName());
        if (actualDependents == null) {
            fullRebuildNeeded = "change to " + source.getClassName() + " requires full rebuild";
            return;
        }
        for (String d : actualDependents) {
            JavaSourceClass dSource = mapper.toJavaSourceClass(d);
            compiler.addStaleClass(dSource);
            changedSourceOnly.include(dSource.getRelativePath());
        }
    }
    if (name.endsWith(".jar")) {
        fullRebuildNeeded = "change to " + inputFile + " requires full rebuild";
        return;
    }
}
 
Example 4
public RebuildInfo processJarChange(InputFileDetails jarChangeDetails, JarArchive jarArchive) {
    JarSnapshot existing = jarSnapshotFeeder.changedJar(jarChangeDetails.getFile());
    if (jarChangeDetails.isAdded()) {
        return DefaultRebuildInfo.NOTHING_TO_REBUILD;
    }

    if (jarChangeDetails.isRemoved()) {
        if (existing != null) {
            return new AllFromJarRebuildInfo(jarArchive);
        } else {
            return DefaultRebuildInfo.FULL_REBUILD;
        }
    }

    if (jarChangeDetails.isModified()) {
        if (existing != null) {
            JarSnapshot newSnapshot = jarSnapshotFeeder.createSnapshot(jarArchive);
            JarDelta jarDelta = existing.compareToSnapshot(newSnapshot);
            return new SpecificClassesRebuildInfo(jarDelta);
        } else {
            return new AllFromJarRebuildInfo(jarArchive);
        }
    }

    throw new IllegalArgumentException("Unknown input file details provided: " + jarChangeDetails);
}
 
Example 5
public void processChange(InputFileDetails input, RecompilationSpec spec) {
    JarArchive jarArchive = new JarArchive(input.getFile(), fileOperations.zipTree(input.getFile()));
    JarChangeDependentsFinder dependentsFinder = new JarChangeDependentsFinder(jarClasspathSnapshot, previousCompilation);
    DependentsSet actualDependents = dependentsFinder.getActualDependents(input, jarArchive);
    if (actualDependents.isDependencyToAll()) {
        spec.setFullRebuildCause(actualDependents.getDescription(), input.getFile());
        return;
    }
    spec.getClassNames().addAll(actualDependents.getDependentClasses());
}
 
Example 6
public void execute(InputFileDetails input) {
    if (spec.getFullRebuildCause() != null) {
        return;
    }
    if (input.getFile().getName().endsWith(".java")) {
        javaChangeProcessor.processChange(input, spec);
    }
    if (input.getFile().getName().endsWith(".jar")) {
        jarChangeProcessor.processChange(input, spec);
    }
}
 
Example 7
public void processChange(InputFileDetails input, RecompilationSpec spec) {
    String className = sourceToNameConverter.getClassName(input.getFile());
    spec.getClassNames().add(className);
    DependentsSet actualDependents = previousCompilation.getDependents(className);
    if (actualDependents.isDependencyToAll()) {
        spec.setFullRebuildCause(actualDependents.getDescription(), input.getFile());
        return;
    }
    spec.getClassNames().addAll(actualDependents.getDependentClasses());
}
 
Example 8
public void outOfDate(final Action<? super InputFileDetails> outOfDateAction) {
    if (outOfDateProcessed) {
        throw new IllegalStateException("Cannot process outOfDate files multiple times");
    }
    doOutOfDate(outOfDateAction);
    outOfDateProcessed = true;
}
 
Example 9
public void removed(Action<? super InputFileDetails> removedAction) {
    if (!outOfDateProcessed) {
        throw new IllegalStateException("Must first process outOfDate files before processing removed files");
    }
    if (removedProcessed) {
        throw new IllegalStateException("Cannot process removed files multiple times");
    }
    doRemoved(removedAction);
    removedProcessed = true;
}
 
Example 10
@Override
protected void doOutOfDate(final Action<? super InputFileDetails> outOfDateAction) {
    for (TaskStateChange change : inputFilesState) {
        InputFileDetails fileChange = (InputFileDetails) change;
        if (fileChange.isRemoved()) {
            removedFiles.add(fileChange);
        } else {
            outOfDateAction.execute(fileChange);
        }
    }
}
 
Example 11
public void outOfDate(final Action<? super InputFileDetails> outOfDateAction) {
    if (outOfDateProcessed) {
        throw new IllegalStateException("Cannot process outOfDate files multiple times");
    }
    doOutOfDate(outOfDateAction);
    outOfDateProcessed = true;
}
 
Example 12
public void removed(Action<? super InputFileDetails> removedAction) {
    if (!outOfDateProcessed) {
        throw new IllegalStateException("Must first process outOfDate files before processing removed files");
    }
    if (removedProcessed) {
        throw new IllegalStateException("Cannot process removed files multiple times");
    }
    doRemoved(removedAction);
    removedProcessed = true;
}
 
Example 13
@Override
protected void doOutOfDate(final Action<? super InputFileDetails> outOfDateAction) {
    for (TaskStateChange change : inputFilesState) {
        InputFileDetails fileChange = (InputFileDetails) change;
        if (fileChange.isRemoved()) {
            removedFiles.add(fileChange);
        } else {
            outOfDateAction.execute(fileChange);
        }
    }
}
 
Example 14
public void processChange(InputFileDetails input, RecompilationSpec spec) {
    JarArchive jarArchive = new JarArchive(input.getFile(), fileOperations.zipTree(input.getFile()));
    JarChangeDependentsFinder dependentsFinder = new JarChangeDependentsFinder(jarClasspathSnapshot, previousCompilation);
    DependentsSet actualDependents = dependentsFinder.getActualDependents(input, jarArchive);
    if (actualDependents.isDependencyToAll()) {
        spec.setFullRebuildCause(actualDependents.getDescription(), input.getFile());
        return;
    }
    spec.getClassNames().addAll(actualDependents.getDependentClasses());
}
 
Example 15
public void execute(InputFileDetails input) {
    if (spec.getFullRebuildCause() != null) {
        return;
    }
    if (input.getFile().getName().endsWith(".java")) {
        javaChangeProcessor.processChange(input, spec);
    }
    if (input.getFile().getName().endsWith(".jar")) {
        jarChangeProcessor.processChange(input, spec);
    }
}
 
Example 16
public void processChange(InputFileDetails input, RecompilationSpec spec) {
    String className = sourceToNameConverter.getClassName(input.getFile());
    spec.getClassNames().add(className);
    DependentsSet actualDependents = previousCompilation.getDependents(className);
    if (actualDependents.isDependencyToAll()) {
        spec.setFullRebuildCause(actualDependents.getDescription(), input.getFile());
        return;
    }
    spec.getClassNames().addAll(actualDependents.getDependentClasses());
}
 
Example 17
public void outOfDate(final Action<? super InputFileDetails> outOfDateAction) {
    if (outOfDateProcessed) {
        throw new IllegalStateException("Cannot process outOfDate files multiple times");
    }
    doOutOfDate(outOfDateAction);
    outOfDateProcessed = true;
}
 
Example 18
public void removed(Action<? super InputFileDetails> removedAction) {
    if (!outOfDateProcessed) {
        throw new IllegalStateException("Must first process outOfDate files before processing removed files");
    }
    if (removedProcessed) {
        throw new IllegalStateException("Cannot process removed files multiple times");
    }
    doRemoved(removedAction);
    removedProcessed = true;
}
 
Example 19
@Override
protected void doOutOfDate(final Action<? super InputFileDetails> outOfDateAction) {
    for (TaskStateChange change : inputFilesState) {
        InputFileDetails fileChange = (InputFileDetails) change;
        if (fileChange.isRemoved()) {
            removedFiles.add(fileChange);
        } else {
            outOfDateAction.execute(fileChange);
        }
    }
}
 
Example 20
public void outOfDate(final Action<? super InputFileDetails> outOfDateAction) {
    if (outOfDateProcessed) {
        throw new IllegalStateException("Cannot process outOfDate files multiple times");
    }
    doOutOfDate(outOfDateAction);
    outOfDateProcessed = true;
}
 
Example 21
public void removed(Action<? super InputFileDetails> removedAction) {
    if (!outOfDateProcessed) {
        throw new IllegalStateException("Must first process outOfDate files before processing removed files");
    }
    if (removedProcessed) {
        throw new IllegalStateException("Cannot process removed files multiple times");
    }
    doRemoved(removedAction);
    removedProcessed = true;
}
 
Example 22
@Override
protected void doOutOfDate(final Action<? super InputFileDetails> outOfDateAction) {
    for (TaskStateChange change : inputFilesState) {
        InputFileDetails fileChange = (InputFileDetails) change;
        if (fileChange.isRemoved()) {
            removedFiles.add(fileChange);
        } else {
            outOfDateAction.execute(fileChange);
        }
    }
}
 
Example 23
public DependentsSet getActualDependents(InputFileDetails jarChangeDetails, JarArchive jarArchive) {
    if (jarChangeDetails.isAdded()) {
        if (jarClasspathSnapshot.isAnyClassDuplicated(jarArchive)) {
            //at least one of the classes from the new jar is already present in jar classpath
            //to avoid calculation which class gets on the classpath first, rebuild all
            return new DependencyToAll("at least one of the classes of '" + jarArchive.file.getName() + "' is already present in classpath");
        } else {
            //none of the new classes in the jar are duplicated on classpath, don't rebuild
            return new DefaultDependentsSet();
        }
    }
    JarSnapshot previous = previousCompilation.getJarSnapshot(jarChangeDetails.getFile());

    if (previous == null) {
        //we don't know what classes were dependents of the jar in the previous build
        //for example, a class (in jar) with a constant might have changed into a class without a constant - we need to rebuild everything
        return new DependencyToAll("missing jar snapshot of '" + jarArchive.file.getName()  + "' from previous build");
    }

    if (jarChangeDetails.isRemoved()) {
        DependentsSet allClasses = previous.getAllClasses();
        if (allClasses.isDependencyToAll()) {
            return new DependencyToAll("at least one of the classes of removed jar '" + jarArchive.file.getName() + "' requires it");
        }
        //recompile all dependents of all the classes from jar
        return previousCompilation.getDependents(allClasses.getDependentClasses());
    }

    if (jarChangeDetails.isModified()) {
        JarSnapshot currentSnapshot = jarClasspathSnapshot.getSnapshot(jarArchive);
        AffectedClasses affected = currentSnapshot.getAffectedClassesSince(previous);
        if (affected.getAltered().isDependencyToAll()) {
            //at least one of the classes changed in the jar is a 'dependency-to-all'
            return affected.getAltered();
        }

        if (jarClasspathSnapshot.isAnyClassDuplicated(affected.getAdded())) {
            //A new duplicate class on classpath. As we don't fancy-handle classpath order right now, we don't know which class is on classpath first.
            //For safe measure rebuild everything
            return new DependencyToAll("at least one of the classes of modified jar '" + jarArchive.file.getName() + "' is already present in the classpath");
        }

        //recompile all dependents of the classes changed in the jar
        return previousCompilation.getDependents(affected.getAltered().getDependentClasses());
    }

    throw new IllegalArgumentException("Unknown input file details provided: " + jarChangeDetails);
}
 
Example 24
public void doOutOfDate(Action<? super InputFileDetails> outOfDateAction) {
    for (File file : task.getInputs().getFiles()) {
        outOfDateAction.execute(new RebuildInputFile(file));
    }
}
 
Example 25
public void doRemoved(Action<? super InputFileDetails> removedAction) {
}
 
Example 26
@Override
protected void doRemoved(Action<? super InputFileDetails> removedAction) {
    for (InputFileDetails removedFile : removedFiles) {
        removedAction.execute(removedFile);
    }
}
 
Example 27
public void doOutOfDate(Action<? super InputFileDetails> outOfDateAction) {
    for (File file : task.getInputs().getFiles()) {
        outOfDateAction.execute(new RebuildInputFile(file));
    }
}
 
Example 28
public void doRemoved(Action<? super InputFileDetails> removedAction) {
}
 
Example 29
@Override
protected void doRemoved(Action<? super InputFileDetails> removedAction) {
    for (InputFileDetails removedFile : removedFiles) {
        removedAction.execute(removedFile);
    }
}
 
Example 30
Source Project: atlas   Source File: Dex.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Actual entry point for the action.
 * Calls out to the doTaskAction as needed.
 */
@TaskAction
public void taskAction(IncrementalTaskInputs inputs) throws IOException, InterruptedException, ProcessException {
    Collection<File> _inputFiles = getInputFiles();
    File _inputDir = getInputDir();
    if (_inputFiles == null && _inputDir == null) {
        throw new RuntimeException("Dex task \'" + getName() + ": inputDir and inputFiles cannot both be null");
    }

    if (!dexOptions.getIncremental() || !enableIncremental) {
        doTaskAction(_inputFiles, _inputDir, false);
        return;

    }

    if (!inputs.isIncremental()) {
        getProject().getLogger().info("Unable to do incremental execution: full task run.");
        doTaskAction(_inputFiles, _inputDir, false);
        return;

    }

    final AtomicBoolean forceFullRun = new AtomicBoolean();

    //noinspection GroovyAssignabilityCheck
    inputs.outOfDate(new Action<InputFileDetails>() {
        @Override
        public void execute(InputFileDetails change) {
            // force full dx run if existing jar file is modified
            // New jar files are fine.
            if (((InputFileDetails)change).isModified() && ((InputFileDetails)change).getFile().getPath().endsWith(
                SdkConstants.DOT_JAR)) {
                getProject().getLogger().info(
                    "Force full dx run: Found updated " + String.valueOf(((InputFileDetails)change).getFile()));
                forceFullRun.set(true);
            }

        }

    });

    //noinspection GroovyAssignabilityCheck
    inputs.removed(change -> {
        // force full dx run if existing jar file is removed
        if (((InputFileDetails)change).getFile().getPath().endsWith(SdkConstants.DOT_JAR)) {
            getProject().getLogger().info(
                "Force full dx run: Found removed " + String.valueOf(((InputFileDetails)change).getFile()));
            forceFullRun.set(true);
        }

    });

    doTaskAction(_inputFiles, _inputDir, !forceFullRun.get());
}