1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.assembly.io;
20
21 import java.io.File;
22 import java.io.IOException;
23 import java.io.OutputStreamWriter;
24 import java.io.StringReader;
25 import java.io.StringWriter;
26 import java.io.Writer;
27 import java.nio.charset.StandardCharsets;
28 import java.nio.file.Files;
29 import java.util.ArrayList;
30 import java.util.Collections;
31 import java.util.Iterator;
32 import java.util.List;
33
34 import org.apache.maven.artifact.Artifact;
35 import org.apache.maven.model.Model;
36 import org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
37 import org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException;
38 import org.apache.maven.plugins.assembly.archive.DefaultAssemblyArchiverTest;
39 import org.apache.maven.plugins.assembly.interpolation.AssemblyInterpolator;
40 import org.apache.maven.plugins.assembly.model.Assembly;
41 import org.apache.maven.plugins.assembly.model.Component;
42 import org.apache.maven.plugins.assembly.model.ContainerDescriptorHandlerConfig;
43 import org.apache.maven.plugins.assembly.model.DependencySet;
44 import org.apache.maven.plugins.assembly.model.FileItem;
45 import org.apache.maven.plugins.assembly.model.FileSet;
46 import org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Writer;
47 import org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Reader;
48 import org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Writer;
49 import org.apache.maven.project.MavenProject;
50 import org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator;
51 import org.codehaus.plexus.interpolation.fixed.InterpolationState;
52 import org.junit.Rule;
53 import org.junit.Test;
54 import org.junit.rules.TemporaryFolder;
55 import org.junit.runner.RunWith;
56 import org.mockito.Mock;
57 import org.mockito.junit.MockitoJUnitRunner;
58 import org.slf4j.LoggerFactory;
59
60 import static org.junit.Assert.assertEquals;
61 import static org.junit.Assert.assertNotNull;
62 import static org.junit.Assert.assertSame;
63 import static org.junit.Assert.fail;
64 import static org.mockito.Mockito.when;
65
66 @RunWith(MockitoJUnitRunner.class)
67 public class DefaultAssemblyReaderTest {
68
69 @Rule
70 public TemporaryFolder temporaryFolder = new TemporaryFolder();
71
72 @Mock
73 private AssemblerConfigurationSource configSource;
74
75 public static StringReader writeToStringReader(Assembly assembly) throws IOException {
76 final StringWriter sw = new StringWriter();
77 final AssemblyXpp3Writer assemblyWriter = new AssemblyXpp3Writer();
78
79 assemblyWriter.write(sw, assembly);
80
81 return new StringReader(sw.toString());
82 }
83
84 @Test
85 public void testIncludeSiteInAssembly_ShouldFailIfSiteDirectoryNonExistent() throws Exception {
86 final File siteDir = Files.createTempFile("assembly-reader.", ".test").toFile();
87 siteDir.delete();
88
89 when(configSource.getSiteDirectory()).thenReturn(siteDir);
90
91 final Assembly assembly = new Assembly();
92
93 try {
94 new DefaultAssemblyReader().includeSiteInAssembly(assembly, configSource);
95
96 fail("Should fail when site directory is non-existent.");
97 } catch (final InvalidAssemblerConfigurationException e) {
98
99 }
100 }
101
102 @Test
103 public void testIncludeSiteInAssembly_ShouldAddSiteDirFileSetWhenDirExists() throws Exception {
104 final File siteDir = temporaryFolder.getRoot();
105
106 when(configSource.getSiteDirectory()).thenReturn(siteDir);
107
108 final Assembly assembly = new Assembly();
109
110 new DefaultAssemblyReader().includeSiteInAssembly(assembly, configSource);
111
112 final List<FileSet> fileSets = assembly.getFileSets();
113
114 assertNotNull(fileSets);
115 assertEquals(1, fileSets.size());
116
117 final FileSet fs = fileSets.get(0);
118
119 assertEquals(siteDir.getPath(), fs.getDirectory());
120 }
121
122 @Test
123 public void testMergeComponentWithAssembly_ShouldAddOneFileSetToExistingListOfTwo() {
124 final Assembly assembly = new Assembly();
125
126 FileSet fs = new FileSet();
127 fs.setDirectory("/dir");
128
129 assembly.addFileSet(fs);
130
131 fs = new FileSet();
132 fs.setDirectory("/other-dir");
133 assembly.addFileSet(fs);
134
135 fs = new FileSet();
136 fs.setDirectory("/third-dir");
137
138 final Component component = new Component();
139
140 component.addFileSet(fs);
141
142 new DefaultAssemblyReader().mergeComponentWithAssembly(component, assembly);
143
144 final List<FileSet> fileSets = assembly.getFileSets();
145
146 assertNotNull(fileSets);
147 assertEquals(3, fileSets.size());
148
149 final FileSet rfs1 = fileSets.get(0);
150 assertEquals("/dir", rfs1.getDirectory());
151
152 final FileSet rfs2 = fileSets.get(1);
153 assertEquals("/other-dir", rfs2.getDirectory());
154
155 final FileSet rfs3 = fileSets.get(2);
156 assertEquals("/third-dir", rfs3.getDirectory());
157 }
158
159 @Test
160 public void testMergeComponentWithAssembly_ShouldAddOneFileItemToExistingListOfTwo() {
161 final Assembly assembly = new Assembly();
162
163 FileItem fi = new FileItem();
164 fi.setSource("file");
165
166 assembly.addFile(fi);
167
168 fi = new FileItem();
169 fi.setSource("file2");
170
171 assembly.addFile(fi);
172
173 fi = new FileItem();
174 fi.setSource("file3");
175
176 final Component component = new Component();
177
178 component.addFile(fi);
179
180 new DefaultAssemblyReader().mergeComponentWithAssembly(component, assembly);
181
182 final List<FileItem> fileItems = assembly.getFiles();
183
184 assertNotNull(fileItems);
185 assertEquals(3, fileItems.size());
186
187 final FileItem rf1 = fileItems.get(0);
188 assertEquals("file", rf1.getSource());
189
190 final FileItem rf2 = fileItems.get(1);
191 assertEquals("file2", rf2.getSource());
192
193 final FileItem rf3 = fileItems.get(2);
194 assertEquals("file3", rf3.getSource());
195 }
196
197 @Test
198 public void testMergeComponentWithAssembly_ShouldAddOneDependencySetToExistingListOfTwo() {
199 final Assembly assembly = new Assembly();
200
201 DependencySet ds = new DependencySet();
202 ds.setScope(Artifact.SCOPE_RUNTIME);
203
204 assembly.addDependencySet(ds);
205
206 ds = new DependencySet();
207 ds.setScope(Artifact.SCOPE_COMPILE);
208
209 assembly.addDependencySet(ds);
210
211 final Component component = new Component();
212
213 ds = new DependencySet();
214 ds.setScope(Artifact.SCOPE_SYSTEM);
215
216 component.addDependencySet(ds);
217
218 new DefaultAssemblyReader().mergeComponentWithAssembly(component, assembly);
219
220 final List<DependencySet> depSets = assembly.getDependencySets();
221
222 assertNotNull(depSets);
223 assertEquals(3, depSets.size());
224
225 assertEquals(Artifact.SCOPE_RUNTIME, depSets.get(0).getScope());
226 assertEquals(Artifact.SCOPE_COMPILE, depSets.get(1).getScope());
227 assertEquals(Artifact.SCOPE_SYSTEM, depSets.get(2).getScope());
228 }
229
230 @Test
231 public void testMergeComponentWithAssembly_ShouldAddOneContainerDescriptorHandlerToExistingListOfTwo() {
232 final Assembly assembly = new Assembly();
233
234 ContainerDescriptorHandlerConfig cfg = new ContainerDescriptorHandlerConfig();
235 cfg.setHandlerName("one");
236
237 assembly.addContainerDescriptorHandler(cfg);
238
239 cfg = new ContainerDescriptorHandlerConfig();
240 cfg.setHandlerName("two");
241
242 assembly.addContainerDescriptorHandler(cfg);
243
244 final Component component = new Component();
245
246 cfg = new ContainerDescriptorHandlerConfig();
247 cfg.setHandlerName("three");
248
249 component.addContainerDescriptorHandler(cfg);
250
251 new DefaultAssemblyReader().mergeComponentWithAssembly(component, assembly);
252
253 final List<ContainerDescriptorHandlerConfig> result = assembly.getContainerDescriptorHandlers();
254
255 assertNotNull(result);
256 assertEquals(3, result.size());
257
258 final Iterator<ContainerDescriptorHandlerConfig> it = result.iterator();
259 assertEquals("one", it.next().getHandlerName());
260 assertEquals("two", it.next().getHandlerName());
261 assertEquals("three", it.next().getHandlerName());
262 }
263
264 @Test
265 public void testMergeComponentsWithMainAssembly_ShouldAddOneFileSetToAssembly() throws Exception {
266 final Component component = new Component();
267
268 final FileSet fileSet = new FileSet();
269 fileSet.setDirectory("/dir");
270
271 component.addFileSet(fileSet);
272
273 final File componentFile = temporaryFolder.newFile();
274
275 try (Writer writer =
276 new OutputStreamWriter(Files.newOutputStream(componentFile.toPath()), StandardCharsets.UTF_8)) {
277 final ComponentXpp3Writer componentWriter = new ComponentXpp3Writer();
278
279 componentWriter.write(writer, component);
280 }
281
282 final String filename = componentFile.getName();
283
284 final Assembly assembly = new Assembly();
285 assembly.addComponentDescriptor(filename);
286
287 final File basedir = componentFile.getParentFile();
288
289 final MavenProject project = new MavenProject();
290
291 when(configSource.getProject()).thenReturn(project);
292 when(configSource.getBasedir()).thenReturn(basedir);
293 DefaultAssemblyArchiverTest.setupInterpolators(configSource);
294 InterpolationState is = new InterpolationState();
295 ComponentXpp3Reader.ContentTransformer componentIp = AssemblyInterpolator.componentInterpolator(
296 FixedStringSearchInterpolator.create(), is, LoggerFactory.getLogger(getClass()));
297
298 new DefaultAssemblyReader().mergeComponentsWithMainAssembly(assembly, null, configSource, componentIp);
299
300 final List<FileSet> fileSets = assembly.getFileSets();
301
302 assertNotNull(fileSets);
303 assertEquals(1, fileSets.size());
304
305 final FileSet fs = fileSets.get(0);
306
307 assertEquals("/dir", fs.getDirectory());
308 }
309
310 @Test
311 public void testReadAssembly_ShouldReadAssemblyWithoutComponentsInterpolationOrSiteDirInclusion() throws Exception {
312 final Assembly assembly = new Assembly();
313 assembly.setId("test");
314
315 final Assembly result = doReadAssembly(assembly);
316
317 assertEquals(assembly.getId(), result.getId());
318 }
319
320 @Test
321 public void testReadAssembly_ShouldReadAssemblyWithSiteDirInclusionFromAssemblyWithoutComponentsOrInterpolation()
322 throws Exception {
323 final Assembly assembly = new Assembly();
324 assembly.setId("test");
325
326 assembly.setIncludeSiteDirectory(true);
327
328 final StringReader sr = writeToStringReader(assembly);
329
330 final File siteDir = temporaryFolder.newFolder("site");
331
332 when(configSource.getSiteDirectory()).thenReturn(siteDir);
333
334 final File basedir = temporaryFolder.getRoot();
335
336 when(configSource.getBasedir()).thenReturn(basedir);
337
338 final Model model = new Model();
339 model.setGroupId("group");
340 model.setArtifactId("artifact");
341 model.setVersion("version");
342
343 final MavenProject project = new MavenProject(model);
344
345 when(configSource.getProject()).thenReturn(project);
346
347 DefaultAssemblyArchiverTest.setupInterpolators(configSource);
348
349 final Assembly result = new DefaultAssemblyReader().readAssembly(sr, "testLocation", null, configSource);
350
351 assertEquals(assembly.getId(), result.getId());
352
353 final List<FileSet> fileSets = result.getFileSets();
354
355 assertEquals(1, fileSets.size());
356
357 assertEquals("/site", fileSets.get(0).getOutputDirectory());
358 }
359
360 @Test
361 public void testReadAssembly_ShouldReadAssemblyWithComponentWithoutSiteDirInclusionOrInterpolation()
362 throws Exception {
363 final File componentsFile = temporaryFolder.newFile();
364
365 final File basedir = componentsFile.getParentFile();
366 final String componentsFilename = componentsFile.getName();
367
368 final Component component = new Component();
369
370 final FileSet fs = new FileSet();
371 fs.setDirectory("/dir");
372
373 component.addFileSet(fs);
374
375 try (Writer fw =
376 new OutputStreamWriter(Files.newOutputStream(componentsFile.toPath()), StandardCharsets.UTF_8)) {
377 new ComponentXpp3Writer().write(fw, component);
378 }
379
380 final Assembly assembly = new Assembly();
381 assembly.setId("test");
382
383 assembly.addComponentDescriptor(componentsFilename);
384
385 final StringReader sr = writeToStringReader(assembly);
386
387 when(configSource.getBasedir()).thenReturn(basedir);
388
389 final Model model = new Model();
390 model.setGroupId("group");
391 model.setArtifactId("artifact");
392 model.setVersion("version");
393
394 final MavenProject project = new MavenProject(model);
395 when(configSource.getProject()).thenReturn(project);
396
397 DefaultAssemblyArchiverTest.setupInterpolators(configSource);
398
399 final Assembly result = new DefaultAssemblyReader().readAssembly(sr, "testLocation", null, configSource);
400
401 assertEquals(assembly.getId(), result.getId());
402
403 final List<FileSet> fileSets = result.getFileSets();
404
405 assertEquals(1, fileSets.size());
406
407 assertEquals("/dir", fileSets.get(0).getDirectory());
408 }
409
410 @Test
411 public void
412 testReadAssembly_ShouldReadAssemblyWithComponentInterpolationWithoutSiteDirInclusionOrAssemblyInterpolation()
413 throws Exception {
414 final File componentsFile = temporaryFolder.newFile();
415
416 final File basedir = componentsFile.getParentFile();
417 final String componentsFilename = componentsFile.getName();
418
419 final Component component = new Component();
420
421 final FileSet fs = new FileSet();
422 fs.setDirectory("${groupId}-dir");
423
424 component.addFileSet(fs);
425
426 try (Writer fw =
427 new OutputStreamWriter(Files.newOutputStream(componentsFile.toPath()), StandardCharsets.UTF_8)) {
428 new ComponentXpp3Writer().write(fw, component);
429 }
430
431 final Assembly assembly = new Assembly();
432 assembly.setId("test");
433
434 assembly.addComponentDescriptor(componentsFilename);
435
436 final StringReader sr = writeToStringReader(assembly);
437
438 when(configSource.getBasedir()).thenReturn(basedir);
439
440 final Model model = new Model();
441 model.setGroupId("group");
442 model.setArtifactId("artifact");
443 model.setVersion("version");
444
445 final MavenProject project = new MavenProject(model);
446
447 when(configSource.getProject()).thenReturn(project);
448
449 DefaultAssemblyArchiverTest.setupInterpolators(configSource);
450
451 final Assembly result = new DefaultAssemblyReader().readAssembly(sr, "testLocation", null, configSource);
452
453 assertEquals(assembly.getId(), result.getId());
454
455 final List<FileSet> fileSets = result.getFileSets();
456
457 assertEquals(1, fileSets.size());
458
459 assertEquals("group-dir", fileSets.get(0).getDirectory());
460 }
461
462 @Test
463 public void testReadAssembly_ShouldReadAssemblyWithInterpolationWithoutComponentsOrSiteDirInclusion()
464 throws Exception {
465 final Assembly assembly = new Assembly();
466 assembly.setId("${groupId}-assembly");
467
468 final Assembly result = doReadAssembly(assembly);
469
470 assertEquals("group-assembly", result.getId());
471 }
472
473 private Assembly doReadAssembly(Assembly assembly)
474 throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException {
475 final StringReader sr = writeToStringReader(assembly);
476
477 final File basedir = temporaryFolder.getRoot();
478
479 when(configSource.getBasedir()).thenReturn(basedir);
480
481 final Model model = new Model();
482 model.setGroupId("group");
483 model.setArtifactId("artifact");
484 model.setVersion("version");
485
486 final MavenProject project = new MavenProject(model);
487
488 when(configSource.getProject()).thenReturn(project);
489
490 DefaultAssemblyArchiverTest.setupInterpolators(configSource);
491
492 return new DefaultAssemblyReader().readAssembly(sr, "testLocation", null, configSource);
493 }
494
495 @Test
496 public void testGetAssemblyFromDescriptorFile_ShouldReadAssembly() throws Exception {
497 final Assembly assembly = new Assembly();
498 assembly.setId("test");
499
500 final FileSet fs = new FileSet();
501 fs.setDirectory("/dir");
502
503 assembly.addFileSet(fs);
504
505 final File assemblyFile = temporaryFolder.newFile();
506
507 final File basedir = assemblyFile.getParentFile();
508
509 when(configSource.getBasedir()).thenReturn(basedir);
510
511 when(configSource.getProject()).thenReturn(new MavenProject(new Model()));
512
513 DefaultAssemblyArchiverTest.setupInterpolators(configSource);
514
515 try (Writer writer =
516 new OutputStreamWriter(Files.newOutputStream(assemblyFile.toPath()), StandardCharsets.UTF_8)) {
517 new AssemblyXpp3Writer().write(writer, assembly);
518 }
519
520 final Assembly result = new DefaultAssemblyReader().getAssemblyFromDescriptorFile(assemblyFile, configSource);
521
522 assertEquals(assembly.getId(), result.getId());
523 }
524
525 @Test
526 public void testGetAssemblyForDescriptorReference_ShouldReadBinaryAssemblyRef() throws Exception {
527 final File basedir = temporaryFolder.getRoot();
528
529 when(configSource.getBasedir()).thenReturn(basedir);
530
531 when(configSource.getProject()).thenReturn(new MavenProject(new Model()));
532
533 DefaultAssemblyArchiverTest.setupInterpolators(configSource);
534
535 final Assembly result = new DefaultAssemblyReader().getAssemblyForDescriptorReference("bin", configSource);
536
537 assertEquals("bin", result.getId());
538 }
539
540 @Test
541 public void testReadAssemblies_ShouldGetAssemblyDescriptorFromSingleFile() throws Exception {
542 final Assembly assembly = new Assembly();
543 assembly.setId("test");
544
545 final FileSet fs = new FileSet();
546 fs.setDirectory("/dir");
547
548 assembly.addFileSet(fs);
549
550 final File basedir = temporaryFolder.getRoot();
551
552 final List<String> files = writeAssembliesToFile(Collections.singletonList(assembly), basedir);
553
554 final String assemblyFile = files.get(0);
555
556 final List<Assembly> assemblies = performReadAssemblies(basedir, new String[] {assemblyFile}, null, null);
557
558 assertNotNull(assemblies);
559 assertEquals(1, assemblies.size());
560
561 final Assembly result = assemblies.get(0);
562
563 assertEquals(assembly.getId(), result.getId());
564 }
565
566 @Test
567 public void testReadAssemblies_ShouldFailWhenSingleDescriptorFileMissing() throws Exception {
568 final File basedir = temporaryFolder.getRoot();
569
570 try {
571 performReadAssemblies(basedir, null, null, null, false);
572
573 fail("Should fail when descriptor file is missing and ignoreDescriptors == false");
574 } catch (final AssemblyReadException e) {
575
576 }
577 }
578
579 @Test
580 public void testReadAssemblies_ShouldIgnoreMissingSingleDescriptorFileWhenIgnoreIsConfigured() throws Exception {
581 final File basedir = temporaryFolder.getRoot();
582
583 try {
584 performReadAssemblies(basedir, null, null, null, true);
585 } catch (final AssemblyReadException e) {
586 fail("Setting ignoreMissingDescriptor == true (true flag in performReadAssemblies, above) should NOT "
587 + "produce an exception.");
588 }
589 }
590
591 @Test
592 public void testReadAssemblies_ShouldGetAssemblyDescriptorFromFileArray() throws Exception {
593 final Assembly assembly1 = new Assembly();
594 assembly1.setId("test");
595
596 final Assembly assembly2 = new Assembly();
597 assembly2.setId("test2");
598
599 final List<Assembly> assemblies = new ArrayList<>();
600 assemblies.add(assembly1);
601 assemblies.add(assembly2);
602
603 final File basedir = temporaryFolder.getRoot();
604
605 final List<String> files = writeAssembliesToFile(assemblies, basedir);
606
607 final List<Assembly> results = performReadAssemblies(basedir, files.toArray(new String[0]), null, null);
608
609 assertNotNull(results);
610 assertEquals(2, results.size());
611
612 final Assembly result1 = assemblies.get(0);
613
614 assertEquals(assembly1.getId(), result1.getId());
615
616 final Assembly result2 = assemblies.get(1);
617
618 assertEquals(assembly2.getId(), result2.getId());
619 }
620
621 @Test
622 public void testReadAssemblies_ShouldGetAssemblyDescriptorFromMultipleRefs() throws Exception {
623 final File basedir = temporaryFolder.getRoot();
624
625 final List<Assembly> assemblies = performReadAssemblies(basedir, null, new String[] {"bin", "src"}, null);
626
627 assertNotNull(assemblies);
628 assertEquals(2, assemblies.size());
629
630 final Assembly result = assemblies.get(0);
631
632 assertEquals("bin", result.getId());
633
634 final Assembly result2 = assemblies.get(1);
635
636 assertEquals("src", result2.getId());
637 }
638
639 @Test
640 public void testReadAssemblies_ShouldGetAssemblyDescriptorFromDirectory() throws Exception {
641 final Assembly assembly1 = new Assembly();
642 assembly1.setId("test");
643
644 final Assembly assembly2 = new Assembly();
645 assembly2.setId("test2");
646
647 final List<Assembly> assemblies = new ArrayList<>();
648 assemblies.add(assembly1);
649 assemblies.add(assembly2);
650
651 final File basedir = temporaryFolder.getRoot();
652
653 writeAssembliesToFile(assemblies, basedir);
654
655 final List<Assembly> results = performReadAssemblies(basedir, null, null, basedir);
656
657 assertNotNull(results);
658 assertEquals(2, results.size());
659
660 final Assembly result1 = assemblies.get(0);
661
662 assertEquals(assembly1.getId(), result1.getId());
663
664 final Assembly result2 = assemblies.get(1);
665
666 assertEquals(assembly2.getId(), result2.getId());
667 }
668
669 @Test
670 public void testReadAssemblies_ShouldGetTwoAssemblyDescriptorsFromDirectoryWithThreeFiles() throws Exception {
671 final Assembly assembly1 = new Assembly();
672 assembly1.setId("test");
673
674 final Assembly assembly2 = new Assembly();
675 assembly2.setId("test2");
676
677 final List<Assembly> assemblies = new ArrayList<>();
678 assemblies.add(assembly1);
679 assemblies.add(assembly2);
680
681 final File basedir = temporaryFolder.getRoot();
682
683 writeAssembliesToFile(assemblies, basedir);
684
685 Files.write(
686 basedir.toPath().resolve("readme.txt"),
687 Collections.singletonList("This is just a readme file, not a descriptor."),
688 StandardCharsets.UTF_8);
689
690 final List<Assembly> results = performReadAssemblies(basedir, null, null, basedir);
691
692 assertNotNull(results);
693 assertEquals(2, results.size());
694
695 final Assembly result1 = assemblies.get(0);
696
697 assertEquals(assembly1.getId(), result1.getId());
698
699 final Assembly result2 = assemblies.get(1);
700
701 assertEquals(assembly2.getId(), result2.getId());
702 }
703
704 @Test
705 public void inlineAssemblyShouldBeReturned() throws Exception {
706
707 Assembly assemby = new Assembly();
708 assemby.setId("test-id");
709 when(configSource.getInlineDescriptors()).thenReturn(Collections.singletonList(assemby));
710
711
712 List<Assembly> assemblies = new DefaultAssemblyReader().readAssemblies(configSource);
713
714
715 assertEquals(1, assemblies.size());
716 assertSame(assemby, assemblies.get(0));
717 }
718
719 private List<String> writeAssembliesToFile(final List<Assembly> assemblies, final File dir) throws IOException {
720 final List<String> files = new ArrayList<>();
721
722 for (final Assembly assembly : assemblies) {
723 final File assemblyFile = new File(dir, assembly.getId() + ".xml");
724
725 try (Writer writer =
726 new OutputStreamWriter(Files.newOutputStream(assemblyFile.toPath()), StandardCharsets.UTF_8)) {
727 new AssemblyXpp3Writer().write(writer, assembly);
728 }
729
730 files.add(assemblyFile.getAbsolutePath());
731 }
732
733 return files;
734 }
735
736 private List<Assembly> performReadAssemblies(
737 final File basedir, final String[] descriptors, final String[] descriptorRefs, final File descriptorDir)
738 throws AssemblyReadException, InvalidAssemblerConfigurationException {
739 return performReadAssemblies(basedir, descriptors, descriptorRefs, descriptorDir, false);
740 }
741
742 private List<Assembly> performReadAssemblies(
743 final File basedir,
744 final String[] descriptors,
745 final String[] descriptorRefs,
746 final File descriptorDir,
747 final boolean ignoreMissing)
748 throws AssemblyReadException, InvalidAssemblerConfigurationException {
749 when(configSource.getDescriptorReferences()).thenReturn(descriptorRefs);
750
751 when(configSource.getDescriptors()).thenReturn(descriptors);
752
753 when(configSource.getDescriptorSourceDirectory()).thenReturn(descriptorDir);
754
755 when(configSource.getBasedir()).thenReturn(basedir);
756
757 if (descriptors == null && descriptorRefs == null && descriptorDir == null) {
758 when(configSource.isIgnoreMissingDescriptor()).thenReturn(ignoreMissing);
759 }
760
761 if (!ignoreMissing) {
762 when(configSource.getProject()).thenReturn(new MavenProject(new Model()));
763
764 DefaultAssemblyArchiverTest.setupInterpolators(configSource);
765 }
766
767 return new DefaultAssemblyReader().readAssemblies(configSource);
768 }
769 }