org.apache.maven.project.DependencyResolutionRequest Java Examples

The following examples show how to use org.apache.maven.project.DependencyResolutionRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LinkageCheckerRuleTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testExecute_shouldPassGoodProject_sessionProperties()
    throws EnforcerRuleException, RepositoryException, DependencyResolutionException {
  setupMockDependencyResolution("com.google.guava:guava:27.0.1-jre");

  rule.execute(mockRuleHelper);

  ArgumentCaptor<DependencyResolutionRequest> argumentCaptor =
      ArgumentCaptor.forClass(DependencyResolutionRequest.class);
  verify(mockProjectDependenciesResolver).resolve(argumentCaptor.capture());
  Map<String, String> propertiesUsedInSession =
      argumentCaptor.getValue().getRepositorySession().getSystemProperties();
  Truth.assertWithMessage(
          "RepositorySystemSession should have variables such as os.detected.classifier")
      .that(propertiesUsedInSession)
      .containsAtLeastEntriesIn(OsProperties.detectOsProperties());
  // There was a problem in resolving profiles because original properties were missing (#817)
  Truth.assertWithMessage("RepositorySystemSession should have original properties")
      .that(propertiesUsedInSession)
      .containsAtLeastEntriesIn(repositorySystemSession.getSystemProperties());
}
 
Example #2
Source File: AggregatingGraphFactoryTest.java    From depgraph-maven-plugin with Apache License 2.0 6 votes vote down vote up
@BeforeEach
void before() throws Exception {
  this.globalFilter = mock(ArtifactFilter.class);
  ArtifactFilter transitiveIncludeExcludeFilter = mock(ArtifactFilter.class);
  ArtifactFilter targetFilter = mock(ArtifactFilter.class);
  when(this.globalFilter.include(any())).thenReturn(true);
  when(transitiveIncludeExcludeFilter.include(any())).thenReturn(true);
  when(targetFilter.include(any())).thenReturn(true);

  DependencyResolutionResult dependencyResolutionResult = mock(DependencyResolutionResult.class);
  org.eclipse.aether.graph.DependencyNode dependencyNode = mock(org.eclipse.aether.graph.DependencyNode.class);
  when(dependencyResolutionResult.getDependencyGraph()).thenReturn(dependencyNode);

  this.dependenciesResolver = mock(ProjectDependenciesResolver.class);
  when(this.dependenciesResolver.resolve(any(DependencyResolutionRequest.class))).thenReturn(dependencyResolutionResult);

  this.adapter = new MavenGraphAdapter(this.dependenciesResolver, transitiveIncludeExcludeFilter, targetFilter, EnumSet.of(INCLUDED));
  this.graphBuilder = GraphBuilder.create(ToStringNodeIdRenderer.INSTANCE);
}
 
Example #3
Source File: MavenGraphAdapterTest.java    From depgraph-maven-plugin with Apache License 2.0 6 votes vote down vote up
@BeforeEach
void before() throws Exception {
  Artifact projectArtifact = mock(Artifact.class);

  this.mavenProject = new MavenProject();
  this.mavenProject.setArtifact(projectArtifact);
  ProjectBuildingRequest projectBuildingRequest = mock(ProjectBuildingRequest.class);
  when(projectBuildingRequest.getRepositorySession()).thenReturn(mock(RepositorySystemSession.class));
  //noinspection deprecation
  this.mavenProject.setProjectBuildingRequest(projectBuildingRequest);

  this.globalFilter = mock(ArtifactFilter.class);
  ArtifactFilter transitiveIncludeExcludeFilter = mock(ArtifactFilter.class);
  ArtifactFilter targetFilter = mock(ArtifactFilter.class);
  this.graphBuilder = GraphBuilder.create(ToStringNodeIdRenderer.INSTANCE);

  this.dependenciesResolver = mock(ProjectDependenciesResolver.class);
  DependencyResolutionResult dependencyResolutionResult = mock(DependencyResolutionResult.class);
  when(dependencyResolutionResult.getDependencyGraph()).thenReturn(mock(org.eclipse.aether.graph.DependencyNode.class));
  when(this.dependenciesResolver.resolve(any(DependencyResolutionRequest.class))).thenReturn(dependencyResolutionResult);

  this.graphAdapter = new MavenGraphAdapter(this.dependenciesResolver, transitiveIncludeExcludeFilter, targetFilter, EnumSet.of(INCLUDED));
}
 
Example #4
Source File: LinkageCheckerRuleTest.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
private void setupMock()
    throws ExpressionEvaluationException, ComponentLookupException,
    DependencyResolutionException {
  mockProject = mock(MavenProject.class);
  mockMavenSession = mock(MavenSession.class);
  when(mockMavenSession.getRepositorySession()).thenReturn(repositorySystemSession);
  mockRuleHelper = mock(EnforcerRuleHelper.class);
  mockProjectDependenciesResolver = mock(ProjectDependenciesResolver.class);
  mockDependencyResolutionResult = mock(DependencyResolutionResult.class);
  mockLog = mock(Log.class);
  when(mockRuleHelper.getLog()).thenReturn(mockLog);
  when(mockRuleHelper.getComponent(ProjectDependenciesResolver.class))
      .thenReturn(mockProjectDependenciesResolver);
  when(mockProjectDependenciesResolver.resolve(any(DependencyResolutionRequest.class)))
      .thenReturn(mockDependencyResolutionResult);
  when(mockRuleHelper.evaluate("${session}")).thenReturn(mockMavenSession);
  when(mockRuleHelper.evaluate("${project}")).thenReturn(mockProject);
  mockMojoExecution = mock(MojoExecution.class);
  when(mockMojoExecution.getLifecyclePhase()).thenReturn("verify");
  when(mockRuleHelper.evaluate("${mojoExecution}")).thenReturn(mockMojoExecution);
  org.apache.maven.artifact.DefaultArtifact rootArtifact =
      new org.apache.maven.artifact.DefaultArtifact(
          "com.google.cloud",
          "linkage-checker-rule-test",
          "0.0.1",
          "compile",
          "jar",
          null,
          new DefaultArtifactHandler());
  rootArtifact.setFile(new File("dummy.jar"));
  when(mockProject.getArtifact()).thenReturn(rootArtifact);
}
 
Example #5
Source File: DependencyResolutionRequestHandler.java    From pipeline-maven-plugin with MIT License 5 votes vote down vote up
@Override
protected boolean _handle(DependencyResolutionRequest request) {
    Xpp3Dom root = new Xpp3Dom("DependencyResolutionRequest");
    root.setAttribute("class", request.getClass().getName());
    root.addChild(newElement("project", request.getMavenProject()));

    reporter.print(root);
    return true;
}
 
Example #6
Source File: MavenGraphAdapterTest.java    From depgraph-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
void dependencyGraphWithException() throws Exception {
  DependencyResolutionException exception = new DependencyResolutionException(mock(DependencyResolutionResult.class), "boom", new Exception());
  when(this.dependenciesResolver.resolve(any(DependencyResolutionRequest.class))).thenThrow(exception);

  try {
    this.graphAdapter.buildDependencyGraph(this.mavenProject, this.globalFilter, this.graphBuilder);
    fail("Expect exception");
  } catch (DependencyGraphException e) {
    assertEquals(exception, e.getCause());
  }
}
 
Example #7
Source File: AggregatingGraphFactoryTest.java    From depgraph-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public boolean matches(DependencyResolutionRequest argument) {
  return argument.getMavenProject().getName().equals(this.expectedProjectName);
}
 
Example #8
Source File: MavenGraphAdapterTest.java    From depgraph-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Test
void dependencyGraph() throws Exception {
  this.graphAdapter.buildDependencyGraph(this.mavenProject, this.globalFilter, this.graphBuilder);

  verify(this.dependenciesResolver).resolve(any(DependencyResolutionRequest.class));
}