com.commercehub.gradle.plugin.avro.ProcessingState Maven / Gradle / Ivy
package com.commercehub.gradle.plugin.avro;
import org.apache.avro.Schema;
import org.gradle.api.Project;
import java.io.File;
import java.util.*;
class ProcessingState {
private final Map typeStates = new HashMap();
private final Set delayedFiles = new LinkedHashSet();
private final Queue filesToProcess = new LinkedList();
private int processedTotal = 0;
ProcessingState(Set files, Project project) {
for (File file : files) {
filesToProcess.add(new FileState(file, project.relativePath(file)));
}
}
Map determineParserTypes(FileState fileState) {
Set duplicateTypeNames = fileState.getDuplicateTypeNames();
Map types = new HashMap();
for (TypeState typeState : typeStates.values()) {
String typeName = typeState.getName();
if (!duplicateTypeNames.contains(typeName)) {
types.put(typeState.getName(), typeState.getSchema());
}
}
return types;
}
void processTypeDefinitions(FileState fileState, Map newTypes) {
String path = fileState.getPath();
for (Map.Entry entry : newTypes.entrySet()) {
String typeName = entry.getKey();
Schema schema = entry.getValue();
getTypeState(typeName).processTypeDefinition(path, schema);
}
fileState.clearError();
processedTotal++;
queueDelayedFilesForProcessing();
}
Set getFailedFiles() {
return delayedFiles;
}
TypeState getTypeState(String typeName) {
TypeState typeState = typeStates.get(typeName);
if (typeState == null) {
typeState = new TypeState(typeName);
typeStates.put(typeName, typeState);
}
return typeState;
}
void queueForProcessing(FileState fileState) {
filesToProcess.add(fileState);
}
void queueForDelayedProcessing(FileState fileState) {
delayedFiles.add(fileState);
}
private void queueDelayedFilesForProcessing() {
filesToProcess.addAll(delayedFiles);
delayedFiles.clear();
}
FileState nextFileState() {
return filesToProcess.poll();
}
boolean isWorkRemaining() {
return !filesToProcess.isEmpty();
}
int getProcessedTotal() {
return processedTotal;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy