Search in sources :

Example 41 with Assembly

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

the class DefaultAssemblyReaderTest method writeAssembliesToFile.

private List<String> writeAssembliesToFile(final List<Assembly> assemblies, final File dir) throws IOException {
    final List<String> files = new ArrayList<String>();
    for (final Assembly assembly : assemblies) {
        final File assemblyFile = new File(dir, assembly.getId() + ".xml");
        Writer writer = null;
        try {
            writer = new OutputStreamWriter(new FileOutputStream(assemblyFile), "UTF-8");
            new AssemblyXpp3Writer().write(writer, assembly);
            writer.close();
            writer = null;
        } finally {
            IOUtil.close(writer);
        }
        files.add(assemblyFile.getAbsolutePath());
    }
    return files;
}
Also used : AssemblyXpp3Writer(org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Writer) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly) 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)

Example 42 with Assembly

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

the class AssemblyInterpolatorTest method testShouldResolveModelGroupIdInAssemblyId.

public void testShouldResolveModelGroupIdInAssemblyId() throws AssemblyInterpolationException, InvalidAssemblerConfigurationException, AssemblyReadException, IOException {
    final Model model = new Model();
    model.setArtifactId("artifact-id");
    model.setGroupId("group.id");
    model.setVersion("1");
    model.setPackaging("jar");
    final Assembly assembly = new Assembly();
    assembly.setId("assembly.${groupId}");
    final MavenProject project = new MavenProject(model);
    final PojoConfigSource configSourceStub = new PojoConfigSource();
    configSourceStub.setRootInterpolator(FixedStringSearchInterpolator.create());
    configSourceStub.setEnvironmentInterpolator(FixedStringSearchInterpolator.create());
    configSourceStub.setMavenProject(project);
    final Assembly outputAssembly = roundTripInterpolation(assembly, configSourceStub);
    assertEquals("assembly.group.id", outputAssembly.getId());
}
Also used : MavenProject(org.apache.maven.project.MavenProject) Model(org.apache.maven.model.Model) PojoConfigSource(org.apache.maven.plugins.assembly.testutils.PojoConfigSource) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 43 with Assembly

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

the class AssemblyInterpolatorTest method testDependencySetOutputFileNameMappingsAreNotInterpolated.

public void testDependencySetOutputFileNameMappingsAreNotInterpolated() throws IOException, AssemblyInterpolationException, AssemblyReadException, InvalidAssemblerConfigurationException {
    final Model model = new Model();
    model.setArtifactId("artifact-id");
    model.setGroupId("group.id");
    model.setVersion("1");
    model.setPackaging("jar");
    final MavenProject project = new MavenProject(model);
    final Assembly assembly = new Assembly();
    // artifactId is blacklisted, but packaging is not.
    final String outputFileNameMapping = "${artifactId}.${packaging}";
    final DependencySet set = new DependencySet();
    set.setOutputFileNameMapping(outputFileNameMapping);
    assembly.addDependencySet(set);
    final PojoConfigSource configSourceStub = new PojoConfigSource();
    configSourceStub.setRootInterpolator(FixedStringSearchInterpolator.create());
    configSourceStub.setEnvironmentInterpolator(FixedStringSearchInterpolator.create());
    configSourceStub.setMavenProject(project);
    final Assembly outputAssembly = roundTripInterpolation(assembly, configSourceStub);
    final List<DependencySet> outputDependencySets = outputAssembly.getDependencySets();
    assertEquals(1, outputDependencySets.size());
    final DependencySet outputSet = outputDependencySets.get(0);
    assertEquals("${artifactId}.${packaging}", outputSet.getOutputFileNameMapping());
}
Also used : MavenProject(org.apache.maven.project.MavenProject) Model(org.apache.maven.model.Model) DependencySet(org.apache.maven.plugins.assembly.model.DependencySet) PojoConfigSource(org.apache.maven.plugins.assembly.testutils.PojoConfigSource) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 44 with Assembly

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

the class ModuleSetAssemblyPhaseTest method testExecute_ShouldSkipIfNoModuleSetsFound.

public void testExecute_ShouldSkipIfNoModuleSetsFound() throws ArchiveCreationException, AssemblyFormattingException, InvalidAssemblerConfigurationException, DependencyResolutionException {
    final Assembly assembly = new Assembly();
    assembly.setIncludeBaseDirectory(false);
    createPhase(null, null).execute(assembly, null, null);
}
Also used : Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 45 with Assembly

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

the class ModuleSetAssemblyPhaseTest method testExecute_ShouldAddOneModuleSetWithOneModuleInIt.

public void testExecute_ShouldAddOneModuleSetWithOneModuleInIt() throws ArchiveCreationException, AssemblyFormattingException, IOException, InvalidAssemblerConfigurationException, DependencyResolutionException {
    final EasyMockSupport mm = new EasyMockSupport();
    final MavenProject project = createProject("group", "artifact", "version", null);
    final MockAndControlForAddArtifactTask macTask = new MockAndControlForAddArtifactTask(mm, project);
    final MavenProject module = createProject("group", "module", "version", project);
    final ArtifactMock moduleArtifactMock = new ArtifactMock(mm, "group", "module", "version", "jar", false);
    final File moduleArtifactFile = moduleArtifactMock.setNewFile();
    module.setArtifact(moduleArtifactMock.getArtifact());
    final List<MavenProject> projects = new ArrayList<MavenProject>();
    projects.add(module);
    macTask.expectGetReactorProjects(projects);
    macTask.expectGetFinalName("final-name");
    macTask.expectGetDestFile(new File("junk"));
    macTask.expectGetMode(0777, 0777);
    final int mode = TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test"));
    macTask.expectAddFile(moduleArtifactFile, "out/artifact", mode);
    final Assembly assembly = new Assembly();
    assembly.setIncludeBaseDirectory(false);
    final ModuleSet ms = new ModuleSet();
    final ModuleBinaries bin = new ModuleBinaries();
    bin.setOutputFileNameMapping("artifact");
    bin.setOutputDirectory("out");
    bin.setFileMode("777");
    bin.setUnpack(false);
    bin.setIncludeDependencies(false);
    ms.setBinaries(bin);
    assembly.addModuleSet(ms);
    final Logger logger = new ConsoleLogger(Logger.LEVEL_DEBUG, "test");
    macTask.expectResolveDependencySets();
    DefaultAssemblyArchiverTest.setupInterpolators(macTask.configSource);
    mm.replayAll();
    final ModuleSetAssemblyPhase phase = createPhase(logger, macTask.dependencyResolver, null);
    phase.execute(assembly, macTask.archiver, macTask.configSource);
    mm.verifyAll();
}
Also used : EasyMockSupport(org.easymock.classextension.EasyMockSupport) ModuleBinaries(org.apache.maven.plugins.assembly.model.ModuleBinaries) ArrayList(java.util.ArrayList) ArtifactMock(org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) Logger(org.codehaus.plexus.logging.Logger) MockAndControlForAddArtifactTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddArtifactTask) 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)

Aggregations

Assembly (org.apache.maven.plugins.assembly.model.Assembly)56 File (java.io.File)29 MavenProject (org.apache.maven.project.MavenProject)28 Model (org.apache.maven.model.Model)21 EasyMockSupport (org.easymock.classextension.EasyMockSupport)13 ConsoleLogger (org.codehaus.plexus.logging.console.ConsoleLogger)12 FileSet (org.apache.maven.plugins.assembly.model.FileSet)9 ArrayList (java.util.ArrayList)8 Component (org.apache.maven.plugins.assembly.model.Component)8 DependencySet (org.apache.maven.plugins.assembly.model.DependencySet)7 PojoConfigSource (org.apache.maven.plugins.assembly.testutils.PojoConfigSource)7 FileItem (org.apache.maven.plugins.assembly.model.FileItem)6 FileOutputStream (java.io.FileOutputStream)5 IOException (java.io.IOException)5 OutputStreamWriter (java.io.OutputStreamWriter)5 StringWriter (java.io.StringWriter)5 Writer (java.io.Writer)5 AssemblyXpp3Writer (org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Writer)5 ComponentXpp3Reader (org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Reader)5 ComponentXpp3Writer (org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Writer)5