use of org.apache.maven.plugins.assembly.model.Assembly in project maven-plugins by apache.
the class DefaultAssemblyReader method readAssembly.
public Assembly readAssembly(Reader reader, final String locationDescription, final File assemblyDir, final AssemblerConfigurationSource configSource) throws AssemblyReadException, InvalidAssemblerConfigurationException {
Assembly assembly;
final MavenProject project = configSource.getProject();
try {
InterpolationState is = new InterpolationState();
final RecursionInterceptor interceptor = new PrefixAwareRecursionInterceptor(InterpolationConstants.PROJECT_PREFIXES, true);
is.setRecursionInterceptor(interceptor);
FixedStringSearchInterpolator interpolator = AssemblyInterpolator.fullInterpolator(project, createProjectInterpolator(project), configSource);
AssemblyXpp3Reader.ContentTransformer transformer = AssemblyInterpolator.assemblyInterpolator(interpolator, is, getLogger());
final AssemblyXpp3Reader r = new AssemblyXpp3Reader(transformer);
assembly = r.read(reader);
ComponentXpp3Reader.ContentTransformer ctrans = AssemblyInterpolator.componentInterpolator(interpolator, is, getLogger());
mergeComponentsWithMainAssembly(assembly, assemblyDir, configSource, ctrans);
debugPrintAssembly("After assembly is interpolated:", assembly);
AssemblyInterpolator.checkErrors(AssemblyId.createAssemblyId(assembly), is, getLogger());
reader.close();
reader = null;
} catch (final IOException e) {
throw new AssemblyReadException("Error reading descriptor: " + locationDescription + ": " + e.getMessage(), e);
} catch (final XmlPullParserException e) {
throw new AssemblyReadException("Error reading descriptor: " + locationDescription + ": " + e.getMessage(), e);
} finally {
IOUtil.close(reader);
}
if (assembly.isIncludeSiteDirectory()) {
includeSiteInAssembly(assembly, configSource);
}
return assembly;
}
use of org.apache.maven.plugins.assembly.model.Assembly in project maven-plugins by apache.
the class DefaultAssemblyReader method readAssemblies.
@Override
public List<Assembly> readAssemblies(final AssemblerConfigurationSource configSource) throws AssemblyReadException, InvalidAssemblerConfigurationException {
final Locator locator = new Locator();
final List<LocatorStrategy> strategies = new ArrayList<LocatorStrategy>();
strategies.add(new RelativeFileLocatorStrategy(configSource.getBasedir()));
strategies.add(new FileLocatorStrategy());
final List<LocatorStrategy> refStrategies = new ArrayList<LocatorStrategy>();
refStrategies.add(new PrefixedClasspathLocatorStrategy("/assemblies/"));
final List<Assembly> assemblies = new ArrayList<Assembly>();
final String[] descriptors = configSource.getDescriptors();
final String[] descriptorRefs = configSource.getDescriptorReferences();
final File descriptorSourceDirectory = configSource.getDescriptorSourceDirectory();
if ((descriptors != null) && (descriptors.length > 0)) {
locator.setStrategies(strategies);
for (String descriptor1 : descriptors) {
getLogger().info("Reading assembly descriptor: " + descriptor1);
addAssemblyFromDescriptor(descriptor1, locator, configSource, assemblies);
}
}
if ((descriptorRefs != null) && (descriptorRefs.length > 0)) {
locator.setStrategies(refStrategies);
for (String descriptorRef : descriptorRefs) {
addAssemblyForDescriptorReference(descriptorRef, configSource, assemblies);
}
}
if ((descriptorSourceDirectory != null) && descriptorSourceDirectory.isDirectory()) {
// CHECKSTYLE_OFF: LineLength
locator.setStrategies(Collections.<LocatorStrategy>singletonList(new RelativeFileLocatorStrategy(descriptorSourceDirectory)));
// CHECKSTYLE_ON: LineLength
final DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(descriptorSourceDirectory);
scanner.setIncludes(new String[] { "**/*.xml" });
scanner.addDefaultExcludes();
scanner.scan();
final String[] paths = scanner.getIncludedFiles();
for (String path : paths) {
addAssemblyFromDescriptor(path, locator, configSource, assemblies);
}
}
if (assemblies.isEmpty()) {
if (configSource.isIgnoreMissingDescriptor()) {
getLogger().debug("Ignoring missing assembly descriptors per configuration. " + "See messages above for specifics.");
} else {
throw new AssemblyReadException("No assembly descriptors found.");
}
}
// check unique IDs
final Set<String> ids = new HashSet<String>();
for (final Assembly assembly : assemblies) {
if (!ids.add(assembly.getId())) {
getLogger().warn("The assembly id " + assembly.getId() + " is used more than once.");
}
}
return assemblies;
}
use of org.apache.maven.plugins.assembly.model.Assembly in project maven-plugins by apache.
the class DependencySetAssemblyPhaseTest method testExecute_ShouldAddOneDependencyFromProject.
public void testExecute_ShouldAddOneDependencyFromProject() throws AssemblyFormattingException, ArchiveCreationException, IOException, InvalidAssemblerConfigurationException, DependencyResolutionException {
final String outputLocation = "/out";
final MavenProject project = newMavenProject("group", "project", "0");
final ArtifactMock projectArtifactMock = new ArtifactMock(mm, "group", "project", "0", "jar", false);
project.setArtifact(projectArtifactMock.getArtifact());
final DependencySet ds = new DependencySet();
ds.setUseProjectArtifact(false);
ds.setOutputDirectory(outputLocation);
ds.setOutputFileNameMapping("${artifact.artifactId}");
ds.setUnpack(false);
ds.setScope(Artifact.SCOPE_COMPILE);
ds.setFileMode(Integer.toString(10, 8));
final Assembly assembly = new Assembly();
assembly.setId("test");
assembly.setIncludeBaseDirectory(false);
assembly.addDependencySet(ds);
final MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(mm, project);
final ArtifactMock artifactMock = new ArtifactMock(mm, "group", "dep", "1", "jar", false);
System.out.println("On test setup, hashcode for dependency artifact: " + artifactMock.getArtifact().hashCode());
macTask.expectCSGetRepositories(null, null);
macTask.expectGetDestFile(new File("junk"));
// macTask.expectAddFile( artifactFile, "out/dep", 10 );
project.setArtifacts(Collections.singleton(artifactMock.getArtifact()));
macTask.expectCSGetFinalName("final-name");
final Logger logger = new ConsoleLogger(Logger.LEVEL_DEBUG, "test");
final MavenProject depProject = newMavenProject("group", "dep", "1");
macTask.expectBuildFromRepository(depProject);
macTask.expectResolveDependencySets();
mm.replayAll();
createPhase(macTask, logger, macTask.dependencyResolver).execute(assembly, macTask.archiver, macTask.configSource);
mm.verifyAll();
}
use of org.apache.maven.plugins.assembly.model.Assembly in project maven-plugins by apache.
the class FileItemAssemblyPhaseTest method testExecute_ShouldAddRelativeFileNoFilterNoLineEndingConversion.
public void testExecute_ShouldAddRelativeFileNoFilterNoLineEndingConversion() throws ArchiveCreationException, AssemblyFormattingException, IOException {
final EasyMockSupport mm = new EasyMockSupport();
final MockAndControlForConfigSource macCS = new MockAndControlForConfigSource(mm);
final File basedir = fileManager.createTempDir();
final File file = fileManager.createFile(basedir, "file.txt", "This is a test file.");
macCS.expectGetBasedir(basedir);
macCS.expectGetProject(new MavenProject(new Model()));
macCS.expectGetFinalName("final-name");
macCS.expectInterpolators();
final MockAndControlForLogger macLogger = new MockAndControlForLogger(mm);
final MockAndControlForArchiver macArchiver = new MockAndControlForArchiver(mm);
final Assembly assembly = new Assembly();
assembly.setId("test");
final FileItem fi = new FileItem();
fi.setSource("file.txt");
fi.setFiltered(false);
fi.setLineEnding("keep");
fi.setFileMode("777");
macArchiver.expectAddFile(file, "file.txt", TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test")));
assembly.addFile(fi);
mm.replayAll();
createPhase(macLogger.logger).execute(assembly, macArchiver.archiver, macCS.configSource);
mm.verifyAll();
}
use of org.apache.maven.plugins.assembly.model.Assembly in project maven-plugins by apache.
the class FileItemAssemblyPhaseTest method testExecute_WithOutputDirectory.
public void testExecute_WithOutputDirectory() 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.setFiltered(false);
readmeFileItem.setLineEnding("keep");
readmeFileItem.setFileMode("777");
final FileItem licenseFileItem = new FileItem();
licenseFileItem.setSource("LICENSE.txt");
licenseFileItem.setOutputDirectory("/");
licenseFileItem.setFiltered(false);
licenseFileItem.setLineEnding("keep");
licenseFileItem.setFileMode("777");
final FileItem configFileItem = new FileItem();
configFileItem.setSource("config/config.txt");
configFileItem.setOutputDirectory("config");
configFileItem.setFiltered(false);
configFileItem.setLineEnding("keep");
configFileItem.setFileMode("777");
macArchiver.expectAddFile(readmeFile, "README.txt", TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test")));
macArchiver.expectAddFile(licenseFile, "LICENSE.txt", TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test")));
macArchiver.expectAddFile(configFile, "config/config.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();
}
Aggregations