Search in sources :

Example 1 with PlexusIoResource

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);
        }
    }
}
Also used : FileItem(org.apache.maven.plugins.assembly.model.FileItem) PlexusIoResource(org.codehaus.plexus.components.io.resources.PlexusIoResource) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException) InputStreamTransformer(org.codehaus.plexus.components.io.functions.InputStreamTransformer) IOException(java.io.IOException) File(java.io.File)

Example 2 with PlexusIoResource

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;
}
Also used : LineEndings(org.apache.maven.plugins.assembly.utils.LineEndings) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) PlexusIoResource(org.codehaus.plexus.components.io.resources.PlexusIoResource) InputStreamReader(java.io.InputStreamReader) Nonnull(javax.annotation.Nonnull) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) InputStream(java.io.InputStream) InputStreamTransformer(org.codehaus.plexus.components.io.functions.InputStreamTransformer) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Nullable(javax.annotation.Nullable)

Aggregations

InputStreamTransformer (org.codehaus.plexus.components.io.functions.InputStreamTransformer)2 PlexusIoResource (org.codehaus.plexus.components.io.resources.PlexusIoResource)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 ReaderInputStream (org.apache.commons.io.input.ReaderInputStream)1 ArchiveCreationException (org.apache.maven.plugins.assembly.archive.ArchiveCreationException)1 FileItem (org.apache.maven.plugins.assembly.model.FileItem)1 LineEndings (org.apache.maven.plugins.assembly.utils.LineEndings)1 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)1