use of org.codehaus.plexus.components.io.resources.PlexusIoResource 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.resources.PlexusIoResource 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