Search in sources :

Example 1 with InputStreamTransformer

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));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InputStreamTransformer(org.codehaus.plexus.components.io.functions.InputStreamTransformer) PojoConfigSource(org.apache.maven.plugins.assembly.testutils.PojoConfigSource) Test(org.junit.Test)

Example 2 with InputStreamTransformer

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);
        }
    }
}
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 3 with InputStreamTransformer

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));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InputStreamTransformer(org.codehaus.plexus.components.io.functions.InputStreamTransformer) PojoConfigSource(org.apache.maven.plugins.assembly.testutils.PojoConfigSource) Test(org.junit.Test)

Example 4 with InputStreamTransformer

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));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InputStreamTransformer(org.codehaus.plexus.components.io.functions.InputStreamTransformer) PojoConfigSource(org.apache.maven.plugins.assembly.testutils.PojoConfigSource) Test(org.junit.Test)

Example 5 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)

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