Search in sources :

Example 81 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class FileSetAssemblyPhaseTest method testShouldAddOneFileSet.

public void testShouldAddOneFileSet() throws ArchiveCreationException, AssemblyFormattingException {
    final Assembly assembly = new Assembly();
    assembly.setId("test");
    assembly.setIncludeBaseDirectory(false);
    final FileSet fs = new FileSet();
    fs.setOutputDirectory("/out");
    fs.setDirectory("/input");
    fs.setFileMode("777");
    fs.setDirectoryMode("777");
    assembly.addFileSet(fs);
    final MockAndControlForLogger macLogger = new MockAndControlForLogger();
    final MockAndControlForAddFileSetsTask macTask = new MockAndControlForAddFileSetsTask(mm, fileManager);
    macTask.expectGetArchiveBaseDirectory();
    final MavenProject project = new MavenProject(new Model());
    macLogger.expectError(true, true);
    final int dirMode = Integer.parseInt("777", 8);
    final int fileMode = Integer.parseInt("777", 8);
    final int[] modes = { -1, -1, dirMode, fileMode };
    macTask.expectAdditionOfSingleFileSet(project, "final-name", false, modes, 1, true);
    DefaultAssemblyArchiverTest.setupInterpolators(macTask.configSource);
    mm.replayAll();
    createPhase(macLogger).execute(assembly, macTask.archiver, macTask.configSource);
    mm.verifyAll();
}
Also used : FileSet(org.apache.maven.plugins.assembly.model.FileSet) MavenProject(org.apache.maven.project.MavenProject) Model(org.apache.maven.model.Model) MockAndControlForAddFileSetsTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddFileSetsTask) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 82 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class ProjectUtils method getProjectModules.

@Nonnull
public static Set<MavenProject> getProjectModules(@Nonnull final MavenProject project, @Nonnull final List<MavenProject> reactorProjects, final boolean includeSubModules, @Nonnull final Logger logger) throws IOException {
    final Set<MavenProject> singleParentSet = Collections.singleton(project);
    final Set<MavenProject> moduleCandidates = new LinkedHashSet<MavenProject>(reactorProjects);
    final Set<MavenProject> modules = new LinkedHashSet<MavenProject>();
    // we temporarily add the master project to the modules set, since this
    // set is pulling double duty as a set of
    // potential module parents in the tree rooted at the master
    // project...this allows us to use the same looping
    // algorithm below to discover both direct modules of the master project
    // AND modules of those direct modules.
    modules.add(project);
    int changed;
    do {
        changed = 0;
        for (final Iterator<MavenProject> candidateIterator = moduleCandidates.iterator(); candidateIterator.hasNext(); ) {
            final MavenProject moduleCandidate = candidateIterator.next();
            if (moduleCandidate.getFile() == null) {
                logger.warn("Cannot compute whether " + moduleCandidate.getId() + " is a module of: " + project.getId() + "; it does not have an associated POM file on the local filesystem.");
                continue;
            }
            Set<MavenProject> currentPotentialParents;
            if (includeSubModules) {
                currentPotentialParents = new LinkedHashSet<MavenProject>(modules);
            } else {
                currentPotentialParents = singleParentSet;
            }
            for (final MavenProject potentialParent : currentPotentialParents) {
                if (potentialParent.getFile() == null) {
                    logger.warn("Cannot use: " + moduleCandidate.getId() + " as a potential module-parent while computing the module set for: " + project.getId() + "; it does not have an associated POM file on the local filesystem.");
                    continue;
                }
                // module of that parent.
                if (projectContainsModule(potentialParent, moduleCandidate)) {
                    // add the candidate to the list of modules (and
                    // potential parents)
                    modules.add(moduleCandidate);
                    // remove the candidate from the candidate pool, because
                    // it's been verified.
                    candidateIterator.remove();
                    // increment the change counter, to show that we
                    // verified a new module on this pass.
                    changed++;
                    // We need to move on to the next candidate since this one was just verified
                    break;
                }
            }
        }
    } while (changed != 0);
    // remove the master project from the modules set, now that we're done
    // using it as a set of potential module
    // parents...
    modules.remove(project);
    return modules;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MavenProject(org.apache.maven.project.MavenProject) Nonnull(javax.annotation.Nonnull)

Example 83 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class DefaultAssemblyArchiverTest method testCreateArchiver_ShouldConfigureArchiver.

@Test
public void testCreateArchiver_ShouldConfigureArchiver() throws NoSuchArchiverException, ArchiverException {
    final EasyMockSupport mm = new EasyMockSupport();
    final MockAndControlForAssemblyArchiver macArchiverManager = new MockAndControlForAssemblyArchiver(mm);
    final TestArchiverWithConfig archiver = new TestArchiverWithConfig();
    macArchiverManager.expectGetArchiver("dummy", archiver);
    final AssemblerConfigurationSource configSource = mm.createMock(AssemblerConfigurationSource.class);
    final String simpleConfig = "value";
    expect(configSource.getArchiverConfig()).andReturn("<configuration><simpleConfig>" + simpleConfig + "</simpleConfig></configuration>").anyTimes();
    final MavenProject project = new MavenProject(new Model());
    expect(configSource.getProject()).andReturn(project).anyTimes();
    expect(configSource.getMavenSession()).andReturn(null).anyTimes();
    expect(configSource.isDryRun()).andReturn(false).anyTimes();
    expect(configSource.getWorkingDirectory()).andReturn(new File(".")).anyTimes();
    expect(configSource.isUpdateOnly()).andReturn(false).anyTimes();
    final ArtifactRepository lr = mm.createMock(ArtifactRepository.class);
    expect(lr.getBasedir()).andReturn("/path/to/local/repo").anyTimes();
    expect(configSource.getLocalRepository()).andReturn(lr).anyTimes();
    expect(configSource.isIgnorePermissions()).andReturn(true);
    setupInterpolators(configSource, project);
    mm.replayAll();
    final DefaultAssemblyArchiver subject = createSubject(macArchiverManager, new ArrayList<AssemblyArchiverPhase>(), null);
    subject.createArchiver("dummy", false, "finalName", configSource, null, false, null);
    assertEquals(simpleConfig, archiver.getSimpleConfig());
    mm.verifyAll();
}
Also used : EasyMockSupport(org.easymock.classextension.EasyMockSupport) MavenProject(org.apache.maven.project.MavenProject) Model(org.apache.maven.model.Model) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) AssemblerConfigurationSource(org.apache.maven.plugins.assembly.AssemblerConfigurationSource) File(java.io.File) AssemblyArchiverPhase(org.apache.maven.plugins.assembly.archive.phase.AssemblyArchiverPhase) Test(org.junit.Test)

Example 84 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class FileItemAssemblyPhaseTest method testExecute_WithOutputDirectoryAndDestName.

public void testExecute_WithOutputDirectoryAndDestName() 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.setDestName("README_renamed.txt");
    readmeFileItem.setFiltered(false);
    readmeFileItem.setLineEnding("keep");
    readmeFileItem.setFileMode("777");
    final FileItem licenseFileItem = new FileItem();
    licenseFileItem.setSource("LICENSE.txt");
    licenseFileItem.setOutputDirectory("/");
    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)

Example 85 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class ModuleSetAssemblyPhaseTest method testGetModuleProjects_ShouldExcludeModuleAndDescendentsTransitively.

public void testGetModuleProjects_ShouldExcludeModuleAndDescendentsTransitively() throws ArchiveCreationException {
    final EasyMockSupport mm = new EasyMockSupport();
    final MavenProject project = createProject("group", "artifact", "version", null);
    final MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(mm, project);
    addArtifact(project, mm, false);
    final MavenProject project2 = createProject("group", "artifact2", "version", project);
    addArtifact(project2, mm, false);
    final MavenProject project3 = createProject("group", "artifact3", "version", project2);
    addArtifact(project3, mm, true);
    final List<MavenProject> projects = new ArrayList<MavenProject>();
    projects.add(project);
    projects.add(project2);
    projects.add(project3);
    macTask.expectGetReactorProjects(projects);
    final ModuleSet moduleSet = new ModuleSet();
    moduleSet.setIncludeSubModules(true);
    moduleSet.addExclude("group:artifact2");
    mm.replayAll();
    final Set<MavenProject> moduleProjects = ModuleSetAssemblyPhase.getModuleProjects(moduleSet, macTask.configSource, logger);
    assertTrue(moduleProjects.isEmpty());
    mm.verifyAll();
}
Also used : MockAndControlForAddDependencySetsTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddDependencySetsTask) EasyMockSupport(org.easymock.classextension.EasyMockSupport) MavenProject(org.apache.maven.project.MavenProject) ArrayList(java.util.ArrayList) ModuleSet(org.apache.maven.plugins.assembly.model.ModuleSet)

Aggregations

MavenProject (org.apache.maven.project.MavenProject)297 File (java.io.File)138 Artifact (org.apache.maven.artifact.Artifact)66 ArrayList (java.util.ArrayList)64 Model (org.apache.maven.model.Model)57 ConsoleLogger (org.codehaus.plexus.logging.console.ConsoleLogger)36 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)33 IOException (java.io.IOException)29 Assembly (org.apache.maven.plugins.assembly.model.Assembly)28 EasyMockSupport (org.easymock.classextension.EasyMockSupport)27 ArtifactMock (org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock)20 Test (org.junit.Test)17 HashMap (java.util.HashMap)16 HashSet (java.util.HashSet)16 MavenSession (org.apache.maven.execution.MavenSession)16 DependencySet (org.apache.maven.plugins.assembly.model.DependencySet)16 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)16 LinkedHashSet (java.util.LinkedHashSet)15 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)15 FileSet (org.apache.maven.plugins.assembly.model.FileSet)15