Search in sources :

Example 6 with InputStreamTransformer

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);
    }
}
Also used : AssemblyFormattingException(org.apache.maven.plugins.assembly.format.AssemblyFormattingException) InputStreamTransformer(org.codehaus.plexus.components.io.functions.InputStreamTransformer) File(java.io.File)

Example 7 with InputStreamTransformer

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;
}
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)7 InputStream (java.io.InputStream)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 PojoConfigSource (org.apache.maven.plugins.assembly.testutils.PojoConfigSource)3 Test (org.junit.Test)3 File (java.io.File)2 PlexusIoResource (org.codehaus.plexus.components.io.resources.PlexusIoResource)2 IOException (java.io.IOException)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 Artifact (org.apache.maven.artifact.Artifact)1 ArchiveCreationException (org.apache.maven.plugins.assembly.archive.ArchiveCreationException)1 AssemblyFormattingException (org.apache.maven.plugins.assembly.format.AssemblyFormattingException)1 FileItem (org.apache.maven.plugins.assembly.model.FileItem)1 LineEndings (org.apache.maven.plugins.assembly.utils.LineEndings)1 MavenProject (org.apache.maven.project.MavenProject)1 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)1