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

com.github.jasonmfehr.combiner.input.FileInputSourceReader Maven / Gradle / Ivy

package com.github.jasonmfehr.combiner.input;

import java.nio.charset.Charset;
import java.util.List;
import java.util.Map;

import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;

import com.github.jasonmfehr.combiner.file.FileLocator;
import com.github.jasonmfehr.combiner.file.MultiFileReader;
import com.github.jasonmfehr.combiner.logging.ParameterizedLogger;

@Component(role=FileInputSourceReader.class)
public class FileInputSourceReader implements InputSourceReader {

	@Requirement
	private FileLocator fileLocator;
	
	@Requirement
	private MultiFileReader multiFileReader;
	
	@Requirement
	private ParameterizedLogger logger;
	
	public Map read(final String encoding, final List includes, final List excludes, final Map settings, final MavenProject mavenProject) {
		final Map fileContents;
		final List files;
		final Charset encodingCharset;
		
		encodingCharset = this.buildCharset(encoding);
		this.logger.debugWithParams("using base directory {0}", mavenProject.getBasedir().getAbsolutePath());
		files = fileLocator.locateFiles(mavenProject.getBasedir().getAbsolutePath(), includes, excludes);
		fileContents = multiFileReader.readInputFiles(encodingCharset, files);
		this.logger.debugWithParams("FileInputSource read {0} files", fileContents.size());
		
		return fileContents;
	}
	
	private Charset buildCharset(final String fileEncoding) {
		final Charset cs;
		
		cs = Charset.forName(fileEncoding);
		this.logger.infoWithParams("{0} using charset {1} to read files", this.getClass().getSimpleName(), cs.displayName());
		
		return cs;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy