use of org.apache.maven.project.MavenProject 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.project.MavenProject 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.project.MavenProject in project maven-plugins by apache.
the class DependencySetAssemblyPhaseTest method newMavenProject.
private MavenProject newMavenProject(final String groupId, final String artifactId, final String version) {
final Model model = new Model();
model.setGroupId(groupId);
model.setArtifactId(artifactId);
model.setVersion(version);
return new MavenProject(model);
}
use of org.apache.maven.project.MavenProject 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.project.MavenProject 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