Search in sources :

Example 1 with AntlrWorkerManager

use of org.gradle.api.plugins.antlr.internal.AntlrWorkerManager in project gradle by gradle.

the class AntlrTask method execute.

/**
 * Generate the parsers.
 *
 * @since 6.0
 */
@TaskAction
public void execute(InputChanges inputChanges) {
    Set<File> grammarFiles = new HashSet<>();
    FileCollection stableSources = getStableSources();
    if (inputChanges.isIncremental()) {
        boolean rebuildRequired = false;
        for (FileChange fileChange : inputChanges.getFileChanges(stableSources)) {
            if (fileChange.getFileType() == FileType.FILE) {
                if (fileChange.getChangeType() == ChangeType.REMOVED) {
                    rebuildRequired = true;
                    break;
                }
                grammarFiles.add(fileChange.getFile());
            }
        }
        if (rebuildRequired) {
            try {
                getDeleter().ensureEmptyDirectory(outputDirectory);
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
            grammarFiles.addAll(stableSources.getFiles());
        }
    } else {
        grammarFiles.addAll(stableSources.getFiles());
    }
    AntlrWorkerManager manager = new AntlrWorkerManager();
    AntlrSpec spec = new AntlrSpecFactory().create(this, grammarFiles, sourceSetDirectories);
    AntlrResult result = manager.runWorker(projectDir(), getWorkerProcessBuilderFactory(), getAntlrClasspath(), spec);
    evaluate(result);
}
Also used : AntlrSpecFactory(org.gradle.api.plugins.antlr.internal.AntlrSpecFactory) AntlrResult(org.gradle.api.plugins.antlr.internal.AntlrResult) AntlrSpec(org.gradle.api.plugins.antlr.internal.AntlrSpec) AntlrWorkerManager(org.gradle.api.plugins.antlr.internal.AntlrWorkerManager) FileChange(org.gradle.work.FileChange) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File) HashSet(java.util.HashSet) TaskAction(org.gradle.api.tasks.TaskAction)

Example 2 with AntlrWorkerManager

use of org.gradle.api.plugins.antlr.internal.AntlrWorkerManager in project gradle by gradle.

the class AntlrTask method execute.

@TaskAction
public void execute(IncrementalTaskInputs inputs) {
    final Set<File> grammarFiles = new HashSet<File>();
    final Set<File> sourceFiles = getSource().getFiles();
    final AtomicBoolean cleanRebuild = new AtomicBoolean();
    inputs.outOfDate(new Action<InputFileDetails>() {

        public void execute(InputFileDetails details) {
            File input = details.getFile();
            if (sourceFiles.contains(input)) {
                grammarFiles.add(input);
            } else {
                // classpath change?
                cleanRebuild.set(true);
            }
        }
    });
    inputs.removed(new Action<InputFileDetails>() {

        @Override
        public void execute(InputFileDetails details) {
            if (details.isRemoved()) {
                cleanRebuild.set(true);
            }
        }
    });
    if (cleanRebuild.get()) {
        GFileUtils.cleanDirectory(outputDirectory);
        grammarFiles.addAll(sourceFiles);
    }
    AntlrWorkerManager manager = new AntlrWorkerManager();
    AntlrSpec spec = new AntlrSpecFactory().create(this, grammarFiles, sourceDirectorySet);
    AntlrResult result = manager.runWorker(getProject().getProjectDir(), getWorkerProcessBuilderFactory(), getAntlrClasspath(), spec);
    evaluate(result);
}
Also used : AntlrSpecFactory(org.gradle.api.plugins.antlr.internal.AntlrSpecFactory) AntlrResult(org.gradle.api.plugins.antlr.internal.AntlrResult) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) InputFileDetails(org.gradle.api.tasks.incremental.InputFileDetails) AntlrSpec(org.gradle.api.plugins.antlr.internal.AntlrSpec) AntlrWorkerManager(org.gradle.api.plugins.antlr.internal.AntlrWorkerManager) File(java.io.File) HashSet(java.util.HashSet) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

File (java.io.File)2 HashSet (java.util.HashSet)2 AntlrResult (org.gradle.api.plugins.antlr.internal.AntlrResult)2 AntlrSpec (org.gradle.api.plugins.antlr.internal.AntlrSpec)2 AntlrSpecFactory (org.gradle.api.plugins.antlr.internal.AntlrSpecFactory)2 AntlrWorkerManager (org.gradle.api.plugins.antlr.internal.AntlrWorkerManager)2 TaskAction (org.gradle.api.tasks.TaskAction)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 FileCollection (org.gradle.api.file.FileCollection)1 InputFileDetails (org.gradle.api.tasks.incremental.InputFileDetails)1 FileChange (org.gradle.work.FileChange)1