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();
}
use of org.apache.maven.project.MavenProject in project maven-plugins by apache.
the class FileSetAssemblyPhaseTest method testShouldAddOneFileSet.
public void testShouldAddOneFileSet() throws ArchiveCreationException, AssemblyFormattingException {
final Assembly assembly = new Assembly();
assembly.setId("test");
assembly.setIncludeBaseDirectory(false);
final FileSet fs = new FileSet();
fs.setOutputDirectory("/out");
fs.setDirectory("/input");
fs.setFileMode("777");
fs.setDirectoryMode("777");
assembly.addFileSet(fs);
final MockAndControlForLogger macLogger = new MockAndControlForLogger();
final MockAndControlForAddFileSetsTask macTask = new MockAndControlForAddFileSetsTask(mm, fileManager);
macTask.expectGetArchiveBaseDirectory();
final MavenProject project = new MavenProject(new Model());
macLogger.expectError(true, true);
final int dirMode = Integer.parseInt("777", 8);
final int fileMode = Integer.parseInt("777", 8);
final int[] modes = { -1, -1, dirMode, fileMode };
macTask.expectAdditionOfSingleFileSet(project, "final-name", false, modes, 1, true);
DefaultAssemblyArchiverTest.setupInterpolators(macTask.configSource);
mm.replayAll();
createPhase(macLogger).execute(assembly, macTask.archiver, macTask.configSource);
mm.verifyAll();
}
use of org.apache.maven.project.MavenProject in project maven-plugins by apache.
the class ProjectUtils method getProjectModules.
@Nonnull
public static Set<MavenProject> getProjectModules(@Nonnull final MavenProject project, @Nonnull final List<MavenProject> reactorProjects, final boolean includeSubModules, @Nonnull final Logger logger) throws IOException {
final Set<MavenProject> singleParentSet = Collections.singleton(project);
final Set<MavenProject> moduleCandidates = new LinkedHashSet<MavenProject>(reactorProjects);
final Set<MavenProject> modules = new LinkedHashSet<MavenProject>();
// we temporarily add the master project to the modules set, since this
// set is pulling double duty as a set of
// potential module parents in the tree rooted at the master
// project...this allows us to use the same looping
// algorithm below to discover both direct modules of the master project
// AND modules of those direct modules.
modules.add(project);
int changed;
do {
changed = 0;
for (final Iterator<MavenProject> candidateIterator = moduleCandidates.iterator(); candidateIterator.hasNext(); ) {
final MavenProject moduleCandidate = candidateIterator.next();
if (moduleCandidate.getFile() == null) {
logger.warn("Cannot compute whether " + moduleCandidate.getId() + " is a module of: " + project.getId() + "; it does not have an associated POM file on the local filesystem.");
continue;
}
Set<MavenProject> currentPotentialParents;
if (includeSubModules) {
currentPotentialParents = new LinkedHashSet<MavenProject>(modules);
} else {
currentPotentialParents = singleParentSet;
}
for (final MavenProject potentialParent : currentPotentialParents) {
if (potentialParent.getFile() == null) {
logger.warn("Cannot use: " + moduleCandidate.getId() + " as a potential module-parent while computing the module set for: " + project.getId() + "; it does not have an associated POM file on the local filesystem.");
continue;
}
// module of that parent.
if (projectContainsModule(potentialParent, moduleCandidate)) {
// add the candidate to the list of modules (and
// potential parents)
modules.add(moduleCandidate);
// remove the candidate from the candidate pool, because
// it's been verified.
candidateIterator.remove();
// increment the change counter, to show that we
// verified a new module on this pass.
changed++;
// We need to move on to the next candidate since this one was just verified
break;
}
}
}
} while (changed != 0);
// remove the master project from the modules set, now that we're done
// using it as a set of potential module
// parents...
modules.remove(project);
return modules;
}
use of org.apache.maven.project.MavenProject in project maven-plugins by apache.
the class DefaultAssemblyArchiverTest method testCreateArchiver_ShouldConfigureArchiver.
@Test
public void testCreateArchiver_ShouldConfigureArchiver() throws NoSuchArchiverException, ArchiverException {
final EasyMockSupport mm = new EasyMockSupport();
final MockAndControlForAssemblyArchiver macArchiverManager = new MockAndControlForAssemblyArchiver(mm);
final TestArchiverWithConfig archiver = new TestArchiverWithConfig();
macArchiverManager.expectGetArchiver("dummy", archiver);
final AssemblerConfigurationSource configSource = mm.createMock(AssemblerConfigurationSource.class);
final String simpleConfig = "value";
expect(configSource.getArchiverConfig()).andReturn("<configuration><simpleConfig>" + simpleConfig + "</simpleConfig></configuration>").anyTimes();
final MavenProject project = new MavenProject(new Model());
expect(configSource.getProject()).andReturn(project).anyTimes();
expect(configSource.getMavenSession()).andReturn(null).anyTimes();
expect(configSource.isDryRun()).andReturn(false).anyTimes();
expect(configSource.getWorkingDirectory()).andReturn(new File(".")).anyTimes();
expect(configSource.isUpdateOnly()).andReturn(false).anyTimes();
final ArtifactRepository lr = mm.createMock(ArtifactRepository.class);
expect(lr.getBasedir()).andReturn("/path/to/local/repo").anyTimes();
expect(configSource.getLocalRepository()).andReturn(lr).anyTimes();
expect(configSource.isIgnorePermissions()).andReturn(true);
setupInterpolators(configSource, project);
mm.replayAll();
final DefaultAssemblyArchiver subject = createSubject(macArchiverManager, new ArrayList<AssemblyArchiverPhase>(), null);
subject.createArchiver("dummy", false, "finalName", configSource, null, false, null);
assertEquals(simpleConfig, archiver.getSimpleConfig());
mm.verifyAll();
}
Aggregations