Search in sources :

Example 41 with ConsoleLogger

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

the class AddArtifactTaskTest method testShouldAddArchiveFileWithDefaultOutputLocation.

public void testShouldAddArchiveFileWithDefaultOutputLocation() throws ArchiveCreationException, AssemblyFormattingException, IOException {
    String artifactId = "myArtifact";
    String version = "1";
    String ext = "jar";
    String outputDir = "tmp/";
    ArtifactMock mock = new ArtifactMock(mockManager, "group", artifactId, version, ext, false);
    File file = mock.setNewFile();
    mock.setExtension(ext);
    mac.expectGetMode(0222, 0222);
    mac.expectGetDestFile(new File("junk"));
    mac.expectAddFile(file, outputDir + artifactId + "-" + version + "." + ext);
    mac.expectInterpolators();
    mockManager.replayAll();
    AddArtifactTask task = new AddArtifactTask(mock.getArtifact(), new ConsoleLogger(Logger.LEVEL_DEBUG, "test"), null);
    task.setOutputDirectory(outputDir);
    task.setFileNameMapping(new DependencySet().getOutputFileNameMapping());
    Model model = new Model();
    model.setArtifactId(artifactId);
    model.setVersion(version);
    MavenProject project = new MavenProject(model);
    task.setProject(project);
    task.execute(mac.archiver, mac.configSource);
    mockManager.verifyAll();
}
Also used : MavenProject(org.apache.maven.project.MavenProject) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) Model(org.apache.maven.model.Model) MockAndControlForAddArtifactTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddArtifactTask) DependencySet(org.apache.maven.plugins.assembly.model.DependencySet) ArtifactMock(org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock) File(java.io.File)

Example 42 with ConsoleLogger

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

the class DefaultDependencyResolverTest method test_getModuleSetResolutionRequirements.

public void test_getModuleSetResolutionRequirements() throws DependencyResolutionException {
    final EasyMockSupport mm = new EasyMockSupport();
    final AssemblerConfigurationSource cs = mm.createMock(AssemblerConfigurationSource.class);
    final File rootDir = new File("root");
    final MavenProject project = createMavenProject("main-group", "main-artifact", "1", rootDir);
    final File module1Dir = new File(rootDir, "module-1");
    final MavenProject module1 = createMavenProject("main-group", "module-1", "1", module1Dir);
    final MavenProject module1a = createMavenProject("group1", "module-1a", "1", new File(module1Dir, "module-1a"));
    final MavenProject module1b = createMavenProject("group1.b", "module-1b", "1", new File(module1Dir, "module-1b"));
    module1.getModel().addModule(module1a.getArtifactId());
    module1.getModel().addModule(module1b.getArtifactId());
    final File module2Dir = new File(rootDir, "module-2");
    final MavenProject module2 = createMavenProject("main-group", "module-2", "1", module2Dir);
    final MavenProject module2a = createMavenProject("main-group", "module-2a", "1", new File(module2Dir, "module-2a"));
    module2.getModel().addModule(module2a.getArtifactId());
    project.getModel().addModule(module1.getArtifactId());
    project.getModel().addModule(module2.getArtifactId());
    final List<MavenProject> allProjects = new ArrayList<MavenProject>();
    allProjects.add(project);
    allProjects.add(module1);
    allProjects.add(module1a);
    allProjects.add(module1b);
    allProjects.add(module2);
    allProjects.add(module2a);
    expect(cs.getReactorProjects()).andReturn(allProjects).anyTimes();
    expect(cs.getProject()).andReturn(project).anyTimes();
    expect(cs.getMavenSession()).andReturn(newMavenSession(project)).anyTimes();
    final ResolutionManagementInfo info = new ResolutionManagementInfo(project);
    final List<ModuleSet> moduleSets = new ArrayList<ModuleSet>();
    final ModuleSet ms1 = new ModuleSet();
    final DependencySet ds1 = new DependencySet();
    {
        ms1.addInclude("*module1*");
        ms1.setIncludeSubModules(false);
        final ModuleBinaries mb = new ModuleBinaries();
        ds1.setScope(Artifact.SCOPE_COMPILE);
        mb.addDependencySet(ds1);
        ms1.setBinaries(mb);
        moduleSets.add(ms1);
    }
    final ModuleSet ms2 = new ModuleSet();
    final DependencySet ds2 = new DependencySet();
    {
        ms2.addInclude("main-group:*");
        ms2.setIncludeSubModules(true);
        final ModuleBinaries mb = new ModuleBinaries();
        ds2.setScope(Artifact.SCOPE_TEST);
        mb.addDependencySet(ds2);
        ms2.setBinaries(mb);
        moduleSets.add(ms2);
    }
    mm.replayAll();
    resolver.enableLogging(new ConsoleLogger(Logger.LEVEL_DEBUG, "test"));
    final Assembly assembly = new Assembly();
    assembly.setModuleSets(moduleSets);
    resolver.updateModuleSetResolutionRequirements(AssemblyId.createAssemblyId(assembly), ms1, ds1, info, cs);
    resolver.updateModuleSetResolutionRequirements(AssemblyId.createAssemblyId(assembly), ms2, ds2, info, cs);
    assertTrue(info.isResolutionRequired());
    final Set<MavenProject> enabledProjects = info.getEnabledProjects();
    assertTrue(enabledProjects.contains(project));
    assertTrue(enabledProjects.contains(module1));
    // these should be excluded since sub-modules are not traversable
    assertFalse(enabledProjects.contains(module1a));
    assertFalse(enabledProjects.contains(module1b));
    assertTrue(enabledProjects.contains(module2));
    assertTrue(enabledProjects.contains(module2a));
    // these are the two we directly set above.
    assertTrue(info.getScopeFilter().getIncluded().contains(Artifact.SCOPE_TEST));
    assertTrue(info.getScopeFilter().getIncluded().contains(Artifact.SCOPE_COMPILE));
    // this combination should be implied by the two direct scopes set above.
    assertTrue(info.getScopeFilter().getIncluded().contains(Artifact.SCOPE_RUNTIME));
    assertTrue(info.getScopeFilter().getIncluded().contains(Artifact.SCOPE_PROVIDED));
    assertTrue(info.getScopeFilter().getIncluded().contains(Artifact.SCOPE_SYSTEM));
    mm.verifyAll();
}
Also used : EasyMockSupport(org.easymock.classextension.EasyMockSupport) ModuleBinaries(org.apache.maven.plugins.assembly.model.ModuleBinaries) ArrayList(java.util.ArrayList) DependencySet(org.apache.maven.plugins.assembly.model.DependencySet) AssemblerConfigurationSource(org.apache.maven.plugins.assembly.AssemblerConfigurationSource) MavenProject(org.apache.maven.project.MavenProject) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) ModuleSet(org.apache.maven.plugins.assembly.model.ModuleSet) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 43 with ConsoleLogger

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

the class DefaultAssemblyReaderTest method testMergeComponentsWithMainAssembly_ShouldAddOneFileSetToAssembly.

public void testMergeComponentsWithMainAssembly_ShouldAddOneFileSetToAssembly() throws IOException, AssemblyReadException {
    final Component component = new Component();
    final FileSet fileSet = new FileSet();
    fileSet.setDirectory("/dir");
    component.addFileSet(fileSet);
    final File componentFile = fileManager.createTempFile();
    Writer writer = null;
    try {
        writer = new OutputStreamWriter(new FileOutputStream(componentFile), "UTF-8");
        final ComponentXpp3Writer componentWriter = new ComponentXpp3Writer();
        componentWriter.write(writer, component);
        writer.close();
        writer = null;
    } finally {
        IOUtil.close(writer);
    }
    final String filename = componentFile.getName();
    final Assembly assembly = new Assembly();
    assembly.addComponentDescriptor(filename);
    final File basedir = componentFile.getParentFile();
    final MavenProject project = new MavenProject();
    expect(configSource.getProject()).andReturn(project).anyTimes();
    expect(configSource.getBasedir()).andReturn(basedir).anyTimes();
    DefaultAssemblyArchiverTest.setupInterpolators(configSource);
    InterpolationState is = new InterpolationState();
    ComponentXpp3Reader.ContentTransformer componentIp = AssemblyInterpolator.componentInterpolator(FixedStringSearchInterpolator.create(), is, new ConsoleLogger(Logger.LEVEL_DEBUG, "console"));
    mockManager.replayAll();
    new DefaultAssemblyReader().mergeComponentsWithMainAssembly(assembly, null, configSource, componentIp);
    final List<FileSet> fileSets = assembly.getFileSets();
    assertNotNull(fileSets);
    assertEquals(1, fileSets.size());
    final FileSet fs = fileSets.get(0);
    assertEquals("/dir", fs.getDirectory());
    mockManager.verifyAll();
}
Also used : FileSet(org.apache.maven.plugins.assembly.model.FileSet) MavenProject(org.apache.maven.project.MavenProject) ComponentXpp3Reader(org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Reader) InterpolationState(org.codehaus.plexus.interpolation.fixed.InterpolationState) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) FileOutputStream(java.io.FileOutputStream) ComponentXpp3Writer(org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Writer) OutputStreamWriter(java.io.OutputStreamWriter) Component(org.apache.maven.plugins.assembly.model.Component) File(java.io.File) OutputStreamWriter(java.io.OutputStreamWriter) StringWriter(java.io.StringWriter) AssemblyXpp3Writer(org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Writer) Writer(java.io.Writer) ComponentXpp3Writer(org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Writer) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 44 with ConsoleLogger

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

the class FileItemAssemblyPhaseTest method testExecute_ShouldAddAbsoluteFileNoFilterNoLineEndingConversion.

public void testExecute_ShouldAddAbsoluteFileNoFilterNoLineEndingConversion() throws ArchiveCreationException, AssemblyFormattingException, IOException {
    final EasyMockSupport mm = new EasyMockSupport();
    final MockAndControlForConfigSource macCS = new MockAndControlForConfigSource(mm);
    final File basedir = fileManager.createTempDir();
    final File file = fileManager.createFile(basedir, "file.txt", "This is a test file.");
    macCS.expectGetBasedir(basedir);
    macCS.expectGetProject(new MavenProject(new Model()));
    macCS.expectGetFinalName("final-name");
    macCS.expectInterpolators();
    final MockAndControlForLogger macLogger = new MockAndControlForLogger(mm);
    final MockAndControlForArchiver macArchiver = new MockAndControlForArchiver(mm);
    final Assembly assembly = new Assembly();
    assembly.setId("test");
    final FileItem fi = new FileItem();
    fi.setSource(file.getAbsolutePath());
    fi.setFiltered(false);
    fi.setLineEnding("keep");
    fi.setFileMode("777");
    macArchiver.expectAddFile(file, "file.txt", TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test")));
    assembly.addFile(fi);
    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 45 with ConsoleLogger

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

the class FileItemAssemblyPhaseTest method testExecute_WithOutputDirectoryAndDestNameAndIncludeBaseDirectoryFalse.

public void testExecute_WithOutputDirectoryAndDestNameAndIncludeBaseDirectoryFalse() 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);
    final MockAndControlForArchiver macArchiver = new MockAndControlForArchiver(mm);
    final Assembly assembly = new Assembly();
    assembly.setId("test");
    assembly.setIncludeBaseDirectory(false);
    final FileItem readmeFileItem = new FileItem();
    readmeFileItem.setSource("README.txt");
    readmeFileItem.setDestName("README_renamed.txt");
    readmeFileItem.setFiltered(false);
    readmeFileItem.setLineEnding("keep");
    readmeFileItem.setFileMode("777");
    final FileItem licenseFileItem = new FileItem();
    licenseFileItem.setSource("LICENSE.txt");
    licenseFileItem.setDestName("LICENSE_renamed.txt");
    licenseFileItem.setFiltered(false);
    licenseFileItem.setLineEnding("keep");
    licenseFileItem.setFileMode("777");
    final FileItem configFileItem = new FileItem();
    configFileItem.setSource("config/config.txt");
    configFileItem.setDestName("config_renamed.txt");
    configFileItem.setOutputDirectory("config");
    configFileItem.setFiltered(false);
    configFileItem.setLineEnding("keep");
    configFileItem.setFileMode("777");
    macArchiver.expectAddFile(readmeFile, "README_renamed.txt", TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test")));
    macArchiver.expectAddFile(licenseFile, "LICENSE_renamed.txt", TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test")));
    macArchiver.expectAddFile(configFile, "config/config_renamed.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)

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