All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.prezi.gradle.pride.internal.LoggedProgressAction Maven / Gradle / Ivy

package com.prezi.gradle.pride.internal;

import com.google.common.base.Strings;
import com.prezi.gradle.pride.Named;
import com.prezi.gradle.pride.Pride;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

public abstract class LoggedProgressAction implements ProgressAction {
	protected static final Logger logger = LoggerFactory.getLogger(LoggedProgressAction.class);

	private final String logPrefix;
	private final String logSuffix;
	private final Named.Namer namer;

	public LoggedProgressAction(String logPrefix, Named.Namer namer) {
		this(logPrefix, null, namer);
	}

	public LoggedProgressAction(String logPrefix, String logSuffix, Named.Namer namer) {
		this.namer = namer;
		this.logPrefix = Strings.isNullOrEmpty(logPrefix) ? "" : logPrefix + " ";
		this.logSuffix = Strings.isNullOrEmpty(logSuffix) ? "" : " " + logSuffix;
	}

	@Override
	public void execute(Pride pride, T item, int index, int count) throws IOException {
		logger.info("[{}/{}] {}{}{}", index + 1, count, logPrefix, namer.getName(item), logSuffix);
		execute(pride, item);
	}

	abstract protected void execute(Pride pride, T item) throws IOException;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy