use of org.apache.maven.plugins.assembly.model.Component in project maven-plugins by apache.
the class DefaultAssemblyReaderTest method testMergeComponentWithAssembly_ShouldAddOneFileItemToExistingListOfTwo.
public void testMergeComponentWithAssembly_ShouldAddOneFileItemToExistingListOfTwo() {
final Assembly assembly = new Assembly();
FileItem fi = new FileItem();
fi.setSource("file");
assembly.addFile(fi);
fi = new FileItem();
fi.setSource("file2");
assembly.addFile(fi);
fi = new FileItem();
fi.setSource("file3");
final Component component = new Component();
component.addFile(fi);
new DefaultAssemblyReader().mergeComponentWithAssembly(component, assembly);
final List<FileItem> fileItems = assembly.getFiles();
assertNotNull(fileItems);
assertEquals(3, fileItems.size());
final FileItem rf1 = fileItems.get(0);
assertEquals("file", rf1.getSource());
final FileItem rf2 = fileItems.get(1);
assertEquals("file2", rf2.getSource());
final FileItem rf3 = fileItems.get(2);
assertEquals("file3", rf3.getSource());
}
use of org.apache.maven.plugins.assembly.model.Component in project maven-plugins by apache.
the class DefaultAssemblyReaderTest method testReadAssembly_ShouldReadAssemblyWithComponentWithoutSiteDirInclusionOrInterpolation.
public void testReadAssembly_ShouldReadAssemblyWithComponentWithoutSiteDirInclusionOrInterpolation() throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException {
final File componentsFile = fileManager.createTempFile();
final File basedir = componentsFile.getParentFile();
final String componentsFilename = componentsFile.getName();
final Component component = new Component();
final FileSet fs = new FileSet();
fs.setDirectory("/dir");
component.addFileSet(fs);
Writer fw = null;
try {
fw = new OutputStreamWriter(new FileOutputStream(componentsFile), "UTF-8");
new ComponentXpp3Writer().write(fw, component);
fw.close();
fw = null;
} finally {
IOUtil.close(fw);
}
final Assembly assembly = new Assembly();
assembly.setId("test");
assembly.addComponentDescriptor(componentsFilename);
final StringReader sr = writeToStringReader(assembly);
expect(configSource.getBasedir()).andReturn(basedir).anyTimes();
final Model model = new Model();
model.setGroupId("group");
model.setArtifactId("artifact");
model.setVersion("version");
final MavenProject project = new MavenProject(model);
expect(configSource.getProject()).andReturn(project).anyTimes();
DefaultAssemblyArchiverTest.setupInterpolators(configSource);
mockManager.replayAll();
final Assembly result = new DefaultAssemblyReader().readAssembly(sr, "testLocation", null, configSource);
assertEquals(assembly.getId(), result.getId());
final List<FileSet> fileSets = result.getFileSets();
assertEquals(1, fileSets.size());
assertEquals("/dir", fileSets.get(0).getDirectory());
mockManager.verifyAll();
}
use of org.apache.maven.plugins.assembly.model.Component in project maven-plugins by apache.
the class DefaultAssemblyReaderTest method testMergeComponentWithAssembly_ShouldAddOneContainerDescriptorHandlerToExistingListOfTwo.
// FIXME: Deep merging should take place...
// public void
// testMergeComponentWithAssembly_ShouldMergeOneFileSetToOneOfExistingTwo()
// {
// Assembly assembly = new Assembly();
//
// FileSet fs = new FileSet();
// fs.setDirectory( "/dir" );
// fs.addInclude( "**/test.txt" );
//
// assembly.addFileSet( fs );
//
// fs = new FileSet();
// fs.setDirectory( "/other-dir" );
// assembly.addFileSet( fs );
//
// fs = new FileSet();
// fs.setDirectory( "/dir" );
// fs.addInclude( "**/components.txt" );
//
// Component component = new Component();
//
// component.addFileSet( fs );
//
// new DefaultAssemblyReader().mergeComponentWithAssembly( component,
// assembly );
//
// List<FileSet> fileSets = assembly.getFileSets();
//
// assertNotNull( fileSets );
// assertEquals( 2, fileSets.size() );
//
// FileSet rfs1 = (FileSet) fileSets.get( 0 );
// assertEquals( "/dir", rfs1.getDirectory() );
//
// List includes = rfs1.getIncludes();
//
// assertNotNull( includes );
// assertEquals( 2, includes.size() );
// assertTrue( includes.contains( "**/test.txt" ) );
// assertTrue( includes.contains( "**/components.txt" ) );
//
// FileSet rfs2 = (FileSet) fileSets.get( 1 );
// assertEquals( "/other-dir", rfs2.getDirectory() );
//
// }
public void testMergeComponentWithAssembly_ShouldAddOneContainerDescriptorHandlerToExistingListOfTwo() {
final Assembly assembly = new Assembly();
ContainerDescriptorHandlerConfig cfg = new ContainerDescriptorHandlerConfig();
cfg.setHandlerName("one");
assembly.addContainerDescriptorHandler(cfg);
cfg = new ContainerDescriptorHandlerConfig();
cfg.setHandlerName("two");
assembly.addContainerDescriptorHandler(cfg);
final Component component = new Component();
cfg = new ContainerDescriptorHandlerConfig();
cfg.setHandlerName("three");
component.addContainerDescriptorHandler(cfg);
new DefaultAssemblyReader().mergeComponentWithAssembly(component, assembly);
final List<ContainerDescriptorHandlerConfig> result = assembly.getContainerDescriptorHandlers();
assertNotNull(result);
assertEquals(3, result.size());
final Iterator<ContainerDescriptorHandlerConfig> it = result.iterator();
assertEquals("one", it.next().getHandlerName());
assertEquals("two", it.next().getHandlerName());
assertEquals("three", it.next().getHandlerName());
}
use of org.apache.maven.plugins.assembly.model.Component in project maven-plugins by apache.
the class DefaultAssemblyReader method mergeComponentsWithMainAssembly.
/**
* Add the contents of all included components to main assembly
*
* @param assembly The assembly
* @param assemblyDir The assembly directory
* @param transformer The component interpolator
* @throws AssemblyReadException .
*/
protected void mergeComponentsWithMainAssembly(final Assembly assembly, final File assemblyDir, final AssemblerConfigurationSource configSource, ComponentXpp3Reader.ContentTransformer transformer) throws AssemblyReadException {
final Locator locator = new Locator();
if (assemblyDir != null && assemblyDir.exists() && assemblyDir.isDirectory()) {
locator.addStrategy(new RelativeFileLocatorStrategy(assemblyDir));
}
// allow absolute paths in componentDescriptor... MASSEMBLY-486
locator.addStrategy(new RelativeFileLocatorStrategy(configSource.getBasedir()));
locator.addStrategy(new FileLocatorStrategy());
locator.addStrategy(new ClasspathResourceLocatorStrategy());
final AssemblyExpressionEvaluator aee = new AssemblyExpressionEvaluator(configSource);
final List<String> componentLocations = assembly.getComponentDescriptors();
for (String location : componentLocations) {
// allow expressions in path to component descriptor... MASSEMBLY-486
try {
location = aee.evaluate(location).toString();
} catch (final Exception eee) {
getLogger().error("Error interpolating componentDescriptor: " + location, eee);
}
final Location resolvedLocation = locator.resolve(location);
if (resolvedLocation == null) {
throw new AssemblyReadException("Failed to locate component descriptor: " + location);
}
Component component = null;
Reader reader = null;
try {
reader = new InputStreamReader(resolvedLocation.getInputStream());
component = new ComponentXpp3Reader(transformer).read(reader);
} catch (final IOException e) {
throw new AssemblyReadException("Error reading component descriptor: " + location + " (resolved to: " + resolvedLocation.getSpecification() + ")", e);
} catch (final XmlPullParserException e) {
throw new AssemblyReadException("Error reading component descriptor: " + location + " (resolved to: " + resolvedLocation.getSpecification() + ")", e);
} finally {
IOUtil.close(reader);
}
mergeComponentWithAssembly(component, assembly);
}
}
use of org.apache.maven.plugins.assembly.model.Component 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());
}
Aggregations