use of org.apache.maven.project.ProjectBuildingRequest in project maven-plugins by apache.
the class JavadocReportTest method testTagletArtifacts.
/**
* Method to test the <code><tagletArtifacts/></code> parameter.
*
* @throws Exception if any
*/
public void testTagletArtifacts() throws Exception {
File testPom = new File(unit, "tagletArtifacts-test/tagletArtifacts-test-plugin-config.xml");
JavadocReport mojo = lookupMojo(testPom);
MavenSession session = spy(newMavenSession(mojo.project));
ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
when(buildingRequest.getRemoteRepositories()).thenReturn(mojo.project.getRemoteArtifactRepositories());
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(localRepo));
when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
when(session.getRepositorySession()).thenReturn(repositorySession);
LegacySupport legacySupport = lookup(LegacySupport.class);
legacySupport.setSession(session);
setVariableValueToObject(mojo, "session", session);
mojo.execute();
File optionsFile = new File(mojo.getOutputDirectory(), "options");
assertTrue(optionsFile.exists());
String options = readFile(optionsFile);
// count -taglet
assertEquals(20, StringUtils.countMatches(options, LINE_SEPARATOR + "-taglet" + LINE_SEPARATOR));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoAggregatorTypeTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoComponentFieldTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoConfiguratorTypeTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoExecuteTypeTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoExecutionStrategyTypeTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoGoalTypeTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoInheritByDefaultTypeTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoInstantiationStrategyTypeTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoParameterFieldTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoPhaseTypeTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoReadOnlyFieldTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiredFieldTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresDependencyResolutionTypeTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresDirectInvocationTypeTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresOnLineTypeTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresProjectTypeTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresReportsTypeTaglet"));
assertTrue(options.contains("org.codehaus.plexus.javadoc.PlexusConfigurationTaglet"));
assertTrue(options.contains("org.codehaus.plexus.javadoc.PlexusRequirementTaglet"));
assertTrue(options.contains("org.codehaus.plexus.javadoc.PlexusComponentTaglet"));
}
use of org.apache.maven.project.ProjectBuildingRequest in project maven-plugins by apache.
the class ShadeMojo method rewriteDependencyReducedPomIfWeHaveReduction.
private void rewriteDependencyReducedPomIfWeHaveReduction(List<Dependency> dependencies, boolean modified, List<Dependency> transitiveDeps, Model model) throws IOException, ProjectBuildingException, DependencyGraphBuilderException {
if (modified) {
for (int loopCounter = 0; modified; loopCounter++) {
model.setDependencies(dependencies);
if (generateUniqueDependencyReducedPom) {
dependencyReducedPomLocation = File.createTempFile("dependency-reduced-pom-", ".xml", project.getBasedir());
project.getProperties().setProperty("maven.shade.dependency-reduced-pom", dependencyReducedPomLocation.getAbsolutePath());
} else {
if (dependencyReducedPomLocation == null) {
// MSHADE-123: We can't default to 'target' because it messes up uses of ${project.basedir}
dependencyReducedPomLocation = new File(project.getBasedir(), "dependency-reduced-pom.xml");
}
}
File f = dependencyReducedPomLocation;
// Works for now, maybe there's a better algorithm where no for-loop is required
if (loopCounter == 0) {
getLog().info("Dependency-reduced POM written at: " + f.getAbsolutePath());
}
if (f.exists()) {
// noinspection ResultOfMethodCallIgnored
f.delete();
}
Writer w = WriterFactory.newXmlWriter(f);
String replaceRelativePath = null;
if (model.getParent() != null) {
replaceRelativePath = model.getParent().getRelativePath();
}
if (model.getParent() != null) {
File parentFile = new File(project.getBasedir(), model.getParent().getRelativePath()).getCanonicalFile();
if (!parentFile.isFile()) {
parentFile = new File(parentFile, "pom.xml");
}
parentFile = parentFile.getCanonicalFile();
String relPath = RelativizePath.convertToRelativePath(parentFile, f);
model.getParent().setRelativePath(relPath);
}
try {
PomWriter.write(w, model, true);
} finally {
if (model.getParent() != null) {
model.getParent().setRelativePath(replaceRelativePath);
}
w.close();
}
ProjectBuildingRequest projectBuildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
projectBuildingRequest.setLocalRepository(localRepository);
projectBuildingRequest.setRemoteRepositories(remoteArtifactRepositories);
ProjectBuildingResult result = projectBuilder.build(f, projectBuildingRequest);
getLog().debug("updateExcludesInDeps()");
modified = updateExcludesInDeps(result.getProject(), dependencies, transitiveDeps);
}
project.setFile(dependencyReducedPomLocation);
}
}
use of org.apache.maven.project.ProjectBuildingRequest in project maven-plugins by apache.
the class DefaultRepositoryAssembler method buildRemoteRepository.
public void buildRemoteRepository(File repositoryDirectory, RepositoryInfo repository, RepositoryBuilderConfigSource configSource) throws RepositoryAssemblyException {
MavenProject project = configSource.getProject();
ProjectBuildingRequest buildingRequest = configSource.getProjectBuildingRequest();
Iterable<ArtifactResult> result = null;
Collection<Dependency> dependencies = project.getDependencies();
if (dependencies == null) {
Logger logger = getLogger();
if (logger.isDebugEnabled()) {
logger.debug("dependency-artifact set for project: " + project.getId() + " is null. Skipping repository processing.");
}
return;
}
Collection<Dependency> managedDependencies = null;
if (project.getDependencyManagement() != null) {
managedDependencies = project.getDependencyManagement().getDependencies();
}
// Older Aether versions use an cache which can't be cleared. So can't delete repoDir and use it again.
// Instead create a temporary repository, delete it at end (should be in a finally-block)
File tempRepo = new File(repositoryDirectory.getParentFile(), repositoryDirectory.getName() + "_tmp");
buildingRequest = repositoryManager.setLocalRepositoryBasedir(buildingRequest, tempRepo);
try {
result = dependencyResolver.resolveDependencies(buildingRequest, dependencies, managedDependencies, null);
} catch (DependencyResolverException e) {
throw new RepositoryAssemblyException("Error resolving artifacts: " + e.getMessage(), e);
}
ArtifactFilter filter = buildRepositoryFilter(repository, project);
buildingRequest = repositoryManager.setLocalRepositoryBasedir(buildingRequest, repositoryDirectory);
Map<String, GroupVersionAlignment> groupVersionAlignments = createGroupVersionAlignments(repository.getGroupVersionAlignments());
assembleRepositoryArtifacts(buildingRequest, result, filter, groupVersionAlignments);
if (repository.isIncludeMetadata()) {
// assembleRepositoryMetadata( result, filter, centralRepository, targetRepository );
}
try {
FileUtils.deleteDirectory(tempRepo);
} catch (IOException e) {
// noop
}
}
use of org.apache.maven.project.ProjectBuildingRequest in project maven-plugins by apache.
the class DefaultDependencyResolver method updateDependencySetResolutionRequirements.
void updateDependencySetResolutionRequirements(final DependencySet set, final ResolutionManagementInfo requirements, AssemblyId assemblyId, ProjectBuildingRequest buildingRequest, final MavenProject... projects) throws DependencyResolutionException {
requirements.setResolutionRequired(true);
requirements.setResolvedTransitively(set.isUseTransitiveDependencies());
ScopeFilter scopeFilter = FilterUtils.newScopeFilter(set.getScope());
requirements.setScopeFilter(scopeFilter);
for (final MavenProject project : projects) {
if (project == null) {
continue;
}
Set<Artifact> dependencyArtifacts = project.getDependencyArtifacts();
if (dependencyArtifacts == null) {
try {
ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(buildingRequest);
pbr.setRemoteRepositories(project.getRemoteArtifactRepositories());
Iterable<ArtifactResult> artifactResults = dependencyResolver.resolveDependencies(pbr, project.getModel(), scopeFilter);
dependencyArtifacts = new HashSet<Artifact>();
for (ArtifactResult artifactResult : artifactResults) {
dependencyArtifacts.add(artifactResult.getArtifact());
}
project.setDependencyArtifacts(dependencyArtifacts);
} catch (final DependencyResolverException e) {
throw new DependencyResolutionException("Failed to create dependency artifacts for resolution. Assembly: " + assemblyId, e);
}
}
requirements.addArtifacts(dependencyArtifacts);
getLogger().debug("Dependencies for project: " + project.getId() + " are:\n" + StringUtils.join(dependencyArtifacts.iterator(), "\n"));
}
}
use of org.apache.maven.project.ProjectBuildingRequest in project maven-plugins by apache.
the class AddDependencySetsTask method addDependencySet.
void addDependencySet(final DependencySet dependencySet, final Archiver archiver, final AssemblerConfigurationSource configSource) throws AssemblyFormattingException, ArchiveCreationException, InvalidAssemblerConfigurationException {
logger.debug("Processing DependencySet (output=" + dependencySet.getOutputDirectory() + ")");
if (!dependencySet.isUseTransitiveDependencies() && dependencySet.isUseTransitiveFiltering()) {
logger.warn("DependencySet has nonsensical configuration: useTransitiveDependencies == false " + "AND useTransitiveFiltering == true. Transitive filtering flag will be ignored.");
}
final Set<Artifact> dependencyArtifacts = resolveDependencyArtifacts(dependencySet);
if (!unpackTransformsContent(dependencySet) && dependencyArtifacts.size() > 1) {
checkMultiArtifactOutputConfig(dependencySet);
}
logger.debug("Adding " + dependencyArtifacts.size() + " dependency artifacts.");
InputStreamTransformer fileSetTransformers = isUnpackWithOptions(dependencySet) ? ReaderFormatter.getFileSetTransformers(configSource, dependencySet.getUnpackOptions().isFiltered(), dependencySet.getUnpackOptions().getLineEnding()) : null;
for (final Artifact depArtifact : dependencyArtifacts) {
ProjectBuildingRequest pbr = getProjectBuildingRequest(configSource);
MavenProject depProject;
try {
ProjectBuildingResult build = projectBuilder1.build(depArtifact, pbr);
depProject = build.getProject();
} catch (final ProjectBuildingException e) {
logger.debug("Error retrieving POM of module-dependency: " + depArtifact.getId() + "; Reason: " + e.getMessage() + "\n\nBuilding stub project instance.");
depProject = buildProjectStub(depArtifact);
}
if (NON_ARCHIVE_DEPENDENCY_TYPES.contains(depArtifact.getType())) {
addNonArchiveDependency(depArtifact, depProject, dependencySet, archiver, configSource);
} else {
addNormalArtifact(dependencySet, depArtifact, depProject, archiver, configSource, fileSetTransformers);
}
}
}
Aggregations