use of org.codehaus.plexus.components.io.functions.InputStreamTransformer in project maven-plugins by apache.
the class ReaderFormatterTest method lineDosFeed_withoutFiltering.
@Test
public void lineDosFeed_withoutFiltering() throws IOException, AssemblyFormattingException {
final PojoConfigSource cfg = getPojoConfigSource();
InputStreamTransformer fileSetTransformers = ReaderFormatter.getFileSetTransformers(cfg, false, "dos");
InputStream fud = fileSetTransformers.transform(dummyResource(), payload("This is a\ntest."));
assertEquals("This is a\r\ntest.", readResultStream(fud));
}
use of org.codehaus.plexus.components.io.functions.InputStreamTransformer in project maven-plugins by apache.
the class FileItemAssemblyPhase method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute(final Assembly assembly, final Archiver archiver, final AssemblerConfigurationSource configSource) throws ArchiveCreationException, AssemblyFormattingException {
final List<FileItem> fileList = assembly.getFiles();
final File basedir = configSource.getBasedir();
for (final FileItem fileItem : fileList) {
final String sourcePath = fileItem.getSource();
// ensure source file is in absolute path for reactor build to work
File source = new File(sourcePath);
// save the original sourcefile's name, because filtration may
// create a temp file with a different name.
final String sourceName = source.getName();
if (!source.isAbsolute()) {
source = new File(basedir, sourcePath);
}
String destName = fileItem.getDestName();
if (destName == null) {
destName = sourceName;
}
final String outputDirectory1 = fileItem.getOutputDirectory();
AssemblyFormatUtils.warnForPlatformSpecifics(getLogger(), outputDirectory1);
final String outputDirectory = AssemblyFormatUtils.getOutputDirectory(outputDirectory1, configSource.getFinalName(), configSource, AssemblyFormatUtils.moduleProjectInterpolator(configSource.getProject()), AssemblyFormatUtils.artifactProjectInterpolator(null));
String target;
// omit the last char if ends with / or \\
if (outputDirectory.endsWith("/") || outputDirectory.endsWith("\\")) {
target = outputDirectory + destName;
} else if (outputDirectory.length() < 1) {
target = destName;
} else {
target = outputDirectory + "/" + destName;
}
try {
final InputStreamTransformer fileSetTransformers = ReaderFormatter.getFileSetTransformers(configSource, fileItem.isFiltered(), fileItem.getLineEnding());
final PlexusIoResource restoUse = createResource(source, fileSetTransformers);
int mode = TypeConversionUtils.modeToInt(fileItem.getFileMode(), getLogger());
archiver.addResource(restoUse, target, mode);
} catch (final ArchiverException e) {
throw new ArchiveCreationException("Error adding file to archive: " + e.getMessage(), e);
} catch (IOException e) {
throw new ArchiveCreationException("Error adding file to archive: " + e.getMessage(), e);
}
}
}
use of org.codehaus.plexus.components.io.functions.InputStreamTransformer in project maven-plugins by apache.
the class ReaderFormatterTest method lineUnixFeedWithInterpolation.
@Test
public void lineUnixFeedWithInterpolation() throws IOException, AssemblyFormattingException {
final PojoConfigSource cfg = getPojoConfigSource();
InputStreamTransformer fileSetTransformers = ReaderFormatter.getFileSetTransformers(cfg, true, "unix");
InputStream fud = fileSetTransformers.transform(dummyResource(), payload("This is a test for project: ${artifactId} @artifactId@."));
assertEquals("This is a test for project: anArtifact anArtifact.", readResultStream(fud));
}
use of org.codehaus.plexus.components.io.functions.InputStreamTransformer in project maven-plugins by apache.
the class ReaderFormatterTest method lineDosFeed.
@Test
public void lineDosFeed() throws IOException, AssemblyFormattingException {
final PojoConfigSource cfg = getPojoConfigSource();
InputStreamTransformer fileSetTransformers = ReaderFormatter.getFileSetTransformers(cfg, true, "dos");
InputStream fud = fileSetTransformers.transform(dummyResource(), payload("This is a\ntest."));
assertEquals("This is a\r\ntest.", readResultStream(fud));
}
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);
}
}
Aggregations