Search in sources :

Example 11 with ConsoleLogger

use of org.codehaus.plexus.logging.console.ConsoleLogger in project maven-plugins by apache.

the class FileItemAssemblyPhaseTest method testExecute_WithOutputDirectory.

public void testExecute_WithOutputDirectory() throws Exception {
    final EasyMockSupport mm = new EasyMockSupport();
    final MockAndControlForConfigSource macCS = new MockAndControlForConfigSource(mm);
    final File basedir = fileManager.createTempDir();
    final File readmeFile = fileManager.createFile(basedir, "README.txt", "This is a test file for README.txt.");
    final File licenseFile = fileManager.createFile(basedir, "LICENSE.txt", "This is a test file for LICENSE.txt.");
    final File configFile = fileManager.createFile(basedir, "config/config.txt", "This is a test file for config/config.txt");
    macCS.expectGetBasedir(basedir);
    macCS.expectGetProject(new MavenProject(new Model()));
    macCS.expectGetFinalName("final-name");
    macCS.expectInterpolators();
    final MockAndControlForLogger macLogger = new MockAndControlForLogger(mm);
    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        macLogger.logger.error("OS=Windows and the assembly descriptor contains a *nix-specific " + "root-relative-reference (starting with slash) /");
    } else {
        macLogger.logger.warn((String) anyObject());
    }
    final MockAndControlForArchiver macArchiver = new MockAndControlForArchiver(mm);
    final Assembly assembly = new Assembly();
    assembly.setId("test");
    assembly.setIncludeBaseDirectory(true);
    final FileItem readmeFileItem = new FileItem();
    readmeFileItem.setSource("README.txt");
    readmeFileItem.setOutputDirectory("");
    readmeFileItem.setFiltered(false);
    readmeFileItem.setLineEnding("keep");
    readmeFileItem.setFileMode("777");
    final FileItem licenseFileItem = new FileItem();
    licenseFileItem.setSource("LICENSE.txt");
    licenseFileItem.setOutputDirectory("/");
    licenseFileItem.setFiltered(false);
    licenseFileItem.setLineEnding("keep");
    licenseFileItem.setFileMode("777");
    final FileItem configFileItem = new FileItem();
    configFileItem.setSource("config/config.txt");
    configFileItem.setOutputDirectory("config");
    configFileItem.setFiltered(false);
    configFileItem.setLineEnding("keep");
    configFileItem.setFileMode("777");
    macArchiver.expectAddFile(readmeFile, "README.txt", TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test")));
    macArchiver.expectAddFile(licenseFile, "LICENSE.txt", TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test")));
    macArchiver.expectAddFile(configFile, "config/config.txt", TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test")));
    assembly.addFile(readmeFileItem);
    assembly.addFile(licenseFileItem);
    assembly.addFile(configFileItem);
    mm.replayAll();
    createPhase(macLogger.logger).execute(assembly, macArchiver.archiver, macCS.configSource);
    mm.verifyAll();
}
Also used : FileItem(org.apache.maven.plugins.assembly.model.FileItem) EasyMockSupport(org.easymock.classextension.EasyMockSupport) MavenProject(org.apache.maven.project.MavenProject) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) Model(org.apache.maven.model.Model) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 12 with ConsoleLogger

use of org.codehaus.plexus.logging.console.ConsoleLogger in project maven-plugins by apache.

the class TypeConversionUtilsTest method checkFileModeSanity.

private void checkFileModeSanity(final String mode, final boolean isSane, final List<String> messagesToCheckIfInsane) {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final PrintStream ps = new PrintStream(baos);
    final PrintStream oldOut = System.out;
    final PrintStream oldErr = System.err;
    try {
        System.setOut(ps);
        System.setErr(ps);
        assertEquals("Mode sanity should be: " + isSane, isSane, TypeConversionUtils.verifyModeSanity(Integer.parseInt(mode, 8), new ConsoleLogger(Logger.LEVEL_WARN, "test")));
    } finally {
        System.setOut(oldOut);
        System.setErr(oldErr);
    }
    if (!isSane && messagesToCheckIfInsane != null && !messagesToCheckIfInsane.isEmpty()) {
        final String message = new String(baos.toByteArray());
        for (final String checkMessage : messagesToCheckIfInsane) {
            assertTrue("\'" + checkMessage + "\' is not present in output.", message.contains(checkMessage));
        }
    }
}
Also used : PrintStream(java.io.PrintStream) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 13 with ConsoleLogger

use of org.codehaus.plexus.logging.console.ConsoleLogger in project maven-plugins by apache.

the class TypeConversionUtilsTest method testModeToInt_FailOnInvalidOctalValue.

public void testModeToInt_FailOnInvalidOctalValue() {
    try {
        TypeConversionUtils.modeToInt("493", new ConsoleLogger(Logger.LEVEL_DEBUG, "test"));
        fail("'493' is an invalid mode and should trigger an exception.");
    } catch (final AssemblyFormattingException e) {
    // expected.
    }
}
Also used : AssemblyFormattingException(org.apache.maven.plugins.assembly.format.AssemblyFormattingException) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger)

Example 14 with ConsoleLogger

use of org.codehaus.plexus.logging.console.ConsoleLogger in project maven-plugins by apache.

the class TypeConversionUtilsTest method testModeToInt_InterpretAsOctalWithoutLeadingZero.

public void testModeToInt_InterpretAsOctalWithoutLeadingZero() throws AssemblyFormattingException {
    final int check = Integer.decode("0777");
    final int test = TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test"));
    assertEquals(check, test);
}
Also used : ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger)

Example 15 with ConsoleLogger

use of org.codehaus.plexus.logging.console.ConsoleLogger in project maven-plugins by apache.

the class TypeConversionUtilsTest method testModeToInt_InterpretValuesWithLeadingZeroAsOctal.

public void testModeToInt_InterpretValuesWithLeadingZeroAsOctal() throws AssemblyFormattingException {
    final int check = Integer.decode("0777");
    final int test = TypeConversionUtils.modeToInt("0777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test"));
    assertEquals(check, test);
}
Also used : ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger)

Aggregations

ConsoleLogger (org.codehaus.plexus.logging.console.ConsoleLogger)59 MavenProject (org.apache.maven.project.MavenProject)36 File (java.io.File)32 EasyMockSupport (org.easymock.classextension.EasyMockSupport)21 Model (org.apache.maven.model.Model)20 ArtifactMock (org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock)20 Logger (org.codehaus.plexus.logging.Logger)16 MockAndControlForAddArtifactTask (org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddArtifactTask)12 Assembly (org.apache.maven.plugins.assembly.model.Assembly)12 DependencySet (org.apache.maven.plugins.assembly.model.DependencySet)10 MockAndControlForAddDependencySetsTask (org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddDependencySetsTask)9 ModuleSources (org.apache.maven.plugins.assembly.model.ModuleSources)9 ArrayList (java.util.ArrayList)8 FileSet (org.apache.maven.plugins.assembly.model.FileSet)8 ModuleBinaries (org.apache.maven.plugins.assembly.model.ModuleBinaries)7 FileItem (org.apache.maven.plugins.assembly.model.FileItem)5 MockAndControlForAddFileSetsTask (org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddFileSetsTask)4 HashSet (java.util.HashSet)3 Artifact (org.apache.maven.artifact.Artifact)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2