Search in sources :

Example 21 with FileSet

use of org.apache.maven.plugins.assembly.model.FileSet in project maven-plugins by apache.

the class DefaultAssemblyReader method mergeComponentWithAssembly.

/**
     * Add the content of a single Component to main assembly
     *
     * @param component The component
     * @param assembly The assembly
     */
protected void mergeComponentWithAssembly(final Component component, final Assembly assembly) {
    final List<ContainerDescriptorHandlerConfig> containerHandlerDescriptors = component.getContainerDescriptorHandlers();
    for (final ContainerDescriptorHandlerConfig cfg : containerHandlerDescriptors) {
        assembly.addContainerDescriptorHandler(cfg);
    }
    final List<DependencySet> dependencySetList = component.getDependencySets();
    for (final DependencySet dependencySet : dependencySetList) {
        assembly.addDependencySet(dependencySet);
    }
    final List<FileSet> fileSetList = component.getFileSets();
    for (final FileSet fileSet : fileSetList) {
        assembly.addFileSet(fileSet);
    }
    final List<FileItem> fileList = component.getFiles();
    for (final FileItem fileItem : fileList) {
        assembly.addFile(fileItem);
    }
    final List<Repository> repositoriesList = component.getRepositories();
    for (final Repository repository : repositoriesList) {
        assembly.addRepository(repository);
    }
    final List<ModuleSet> moduleSets = component.getModuleSets();
    for (final ModuleSet moduleSet : moduleSets) {
        assembly.addModuleSet(moduleSet);
    }
}
Also used : FileItem(org.apache.maven.plugins.assembly.model.FileItem) Repository(org.apache.maven.plugins.assembly.model.Repository) FileSet(org.apache.maven.plugins.assembly.model.FileSet) ContainerDescriptorHandlerConfig(org.apache.maven.plugins.assembly.model.ContainerDescriptorHandlerConfig) DependencySet(org.apache.maven.plugins.assembly.model.DependencySet) ModuleSet(org.apache.maven.plugins.assembly.model.ModuleSet)

Example 22 with FileSet

use of org.apache.maven.plugins.assembly.model.FileSet in project maven-plugins by apache.

the class FileSetAssemblyPhase method execute.

/**
     * {@inheritDoc}
     */
@Override
public void execute(@Nonnull final Assembly assembly, final Archiver archiver, final AssemblerConfigurationSource configSource) throws ArchiveCreationException, AssemblyFormattingException {
    final List<FileSet> fileSets = assembly.getFileSets();
    if ((fileSets != null) && !fileSets.isEmpty()) {
        final AddFileSetsTask task = new AddFileSetsTask(fileSets);
        task.setLogger(getLogger());
        task.execute(archiver, configSource);
    }
}
Also used : FileSet(org.apache.maven.plugins.assembly.model.FileSet) AddFileSetsTask(org.apache.maven.plugins.assembly.archive.task.AddFileSetsTask)

Example 23 with FileSet

use of org.apache.maven.plugins.assembly.model.FileSet in project maven-plugins by apache.

the class ModuleSetAssemblyPhase method addModuleSourceFileSets.

void addModuleSourceFileSets(final ModuleSources sources, final Set<MavenProject> moduleProjects, final Archiver archiver, final AssemblerConfigurationSource configSource) throws ArchiveCreationException, AssemblyFormattingException {
    if (sources == null) {
        return;
    }
    final List<FileSet> fileSets = new ArrayList<FileSet>();
    if (isDeprecatedModuleSourcesConfigPresent(sources)) {
        final FileSet fs = new FileSet();
        fs.setOutputDirectory(sources.getOutputDirectory());
        fs.setIncludes(sources.getIncludes());
        fs.setExcludes(sources.getExcludes());
        fs.setUseDefaultExcludes(sources.isUseDefaultExcludes());
        fileSets.add(fs);
    }
    List<FileSet> subFileSets = sources.getFileSets();
    if ((subFileSets == null) || subFileSets.isEmpty()) {
        final FileSet fs = new FileSet();
        fs.setDirectory("src");
        subFileSets = Collections.singletonList(fs);
    }
    fileSets.addAll(subFileSets);
    for (final MavenProject moduleProject : moduleProjects) {
        getLogger().info("Processing sources for module project: " + moduleProject.getId());
        final List<FileSet> moduleFileSets = new ArrayList<FileSet>();
        for (final FileSet fileSet : fileSets) {
            moduleFileSets.add(createFileSet(fileSet, sources, moduleProject, configSource));
        }
        final AddFileSetsTask task = new AddFileSetsTask(moduleFileSets);
        task.setProject(moduleProject);
        task.setModuleProject(moduleProject);
        task.setLogger(getLogger());
        task.execute(archiver, configSource);
    }
}
Also used : FileSet(org.apache.maven.plugins.assembly.model.FileSet) MavenProject(org.apache.maven.project.MavenProject) ArrayList(java.util.ArrayList) AddFileSetsTask(org.apache.maven.plugins.assembly.archive.task.AddFileSetsTask)

Example 24 with FileSet

use of org.apache.maven.plugins.assembly.model.FileSet in project maven-plugins by apache.

the class DefaultAssemblyReaderTest method testMergeComponentWithAssembly_ShouldAddOneFileSetToExistingListOfTwo.

public void testMergeComponentWithAssembly_ShouldAddOneFileSetToExistingListOfTwo() {
    final Assembly assembly = new Assembly();
    FileSet fs = new FileSet();
    fs.setDirectory("/dir");
    assembly.addFileSet(fs);
    fs = new FileSet();
    fs.setDirectory("/other-dir");
    assembly.addFileSet(fs);
    fs = new FileSet();
    fs.setDirectory("/third-dir");
    final Component component = new Component();
    component.addFileSet(fs);
    new DefaultAssemblyReader().mergeComponentWithAssembly(component, assembly);
    final List<FileSet> fileSets = assembly.getFileSets();
    assertNotNull(fileSets);
    assertEquals(3, fileSets.size());
    final FileSet rfs1 = fileSets.get(0);
    assertEquals("/dir", rfs1.getDirectory());
    final FileSet rfs2 = fileSets.get(1);
    assertEquals("/other-dir", rfs2.getDirectory());
    final FileSet rfs3 = fileSets.get(2);
    assertEquals("/third-dir", rfs3.getDirectory());
}
Also used : FileSet(org.apache.maven.plugins.assembly.model.FileSet) Component(org.apache.maven.plugins.assembly.model.Component) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 25 with FileSet

use of org.apache.maven.plugins.assembly.model.FileSet 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)

Aggregations

FileSet (org.apache.maven.plugins.assembly.model.FileSet)27 File (java.io.File)19 MavenProject (org.apache.maven.project.MavenProject)14 Model (org.apache.maven.model.Model)11 MockAndControlForAddFileSetsTask (org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddFileSetsTask)11 Assembly (org.apache.maven.plugins.assembly.model.Assembly)9 ConsoleLogger (org.codehaus.plexus.logging.console.ConsoleLogger)8 ArrayList (java.util.ArrayList)6 FileOutputStream (java.io.FileOutputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4 StringWriter (java.io.StringWriter)4 Writer (java.io.Writer)4 ArtifactMock (org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock)4 Component (org.apache.maven.plugins.assembly.model.Component)4 ModuleSources (org.apache.maven.plugins.assembly.model.ModuleSources)4 AssemblyXpp3Writer (org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Writer)4 ComponentXpp3Writer (org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Writer)4 EasyMockSupport (org.easymock.classextension.EasyMockSupport)4 StringReader (java.io.StringReader)3 MockAndControlForAddArtifactTask (org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddArtifactTask)3