use of org.codehaus.plexus.components.io.functions.InputStreamTransformer in project maven-plugins by apache.
the class AddFileSetsTask method addFileSet.
void addFileSet(final FileSet fileSet, final Archiver archiver, final AssemblerConfigurationSource configSource, final File archiveBaseDir) throws AssemblyFormattingException, ArchiveCreationException {
// throw this check in just in case someone extends this class...
checkLogger();
if (project == null) {
project = configSource.getProject();
}
final File basedir = project.getBasedir();
String destDirectory = fileSet.getOutputDirectory();
if (destDirectory == null) {
destDirectory = fileSet.getDirectory();
}
AssemblyFormatUtils.warnForPlatformSpecifics(logger, destDirectory);
destDirectory = AssemblyFormatUtils.getOutputDirectory(destDirectory, configSource.getFinalName(), configSource, AssemblyFormatUtils.moduleProjectInterpolator(moduleProject), AssemblyFormatUtils.artifactProjectInterpolator(project));
if (logger.isDebugEnabled()) {
logger.debug("FileSet[" + destDirectory + "]" + " dir perms: " + Integer.toString(archiver.getOverrideDirectoryMode(), 8) + " file perms: " + Integer.toString(archiver.getOverrideFileMode(), 8) + (fileSet.getLineEnding() == null ? "" : " lineEndings: " + fileSet.getLineEnding()));
}
logger.debug("The archive base directory is '" + archiveBaseDir + "'");
File fileSetDir = getFileSetDirectory(fileSet, basedir, archiveBaseDir);
if (fileSetDir.exists()) {
InputStreamTransformer fileSetTransformers = ReaderFormatter.getFileSetTransformers(configSource, fileSet.isFiltered(), fileSet.getLineEnding());
if (fileSetTransformers == null) {
logger.debug("NOT reformatting any files in " + fileSetDir);
}
if (fileSetDir.getPath().equals(File.separator)) {
throw new AssemblyFormattingException("Your assembly descriptor specifies a directory of " + File.separator + ", which is your *entire* file system.\nThese are not the files you are looking for");
}
final AddDirectoryTask task = new AddDirectoryTask(fileSetDir, fileSetTransformers);
final int dirMode = TypeConversionUtils.modeToInt(fileSet.getDirectoryMode(), logger);
if (dirMode != -1) {
task.setDirectoryMode(dirMode);
}
final int fileMode = TypeConversionUtils.modeToInt(fileSet.getFileMode(), logger);
if (fileMode != -1) {
task.setFileMode(fileMode);
}
task.setUseDefaultExcludes(fileSet.isUseDefaultExcludes());
task.setExcludes(fileSet.getExcludes());
task.setIncludes(fileSet.getIncludes());
task.setOutputDirectory(destDirectory);
task.execute(archiver);
}
}
use of org.codehaus.plexus.components.io.functions.InputStreamTransformer in project maven-plugins by apache.
the class ReaderFormatter method getFileSetTransformers.
@Nullable
public static InputStreamTransformer getFileSetTransformers(final AssemblerConfigurationSource configSource, final boolean isFiltered, String fileSetLineEnding) throws AssemblyFormattingException {
final LineEndings lineEndingToUse = LineEndingsUtils.getLineEnding(fileSetLineEnding);
final boolean transformLineEndings = !LineEndings.keep.equals(lineEndingToUse);
if (transformLineEndings || isFiltered) {
return new InputStreamTransformer() {
@Override
@Nonnull
public InputStream transform(@Nonnull PlexusIoResource plexusIoResource, @Nonnull InputStream inputStream) throws IOException {
InputStream result = inputStream;
if (isFiltered) {
boolean isPropertyFile = AssemblyFileUtils.isPropertyFile(plexusIoResource.getName());
final String encoding = isPropertyFile ? "ISO-8859-1" : configSource.getEncoding();
Reader source = encoding != null ? new InputStreamReader(inputStream, encoding) : // wtf platform encoding ? TODO: Fix this
new InputStreamReader(inputStream);
Reader filtered = createReaderFilter(source, configSource.getEscapeString(), configSource.getDelimiters(), configSource, isPropertyFile);
result = encoding != null ? new ReaderInputStream(filtered, encoding) : new ReaderInputStream(filtered);
}
if (transformLineEndings) {
checkifFileTypeIsAppropriateForLineEndingTransformation(plexusIoResource);
result = LineEndingsUtils.lineEndingConverter(result, lineEndingToUse);
}
return result;
}
};
}
return null;
}
Aggregations