use of org.eclipse.aether.graph.DependencyNode in project cloud-opensource-java by GoogleCloudPlatform.
the class LinkageCheckerRuleTest method testArtifactTransferError.
@Test
public void testArtifactTransferError() throws RepositoryException, DependencyResolutionException {
DependencyNode graph = createResolvedDependencyGraph("org.apache.maven:maven-core:jar:3.5.2");
DependencyResolutionResult resolutionResult = mock(DependencyResolutionResult.class);
when(resolutionResult.getDependencyGraph()).thenReturn(graph);
DependencyResolutionException exception = createDummyResolutionException(new DefaultArtifact("aopalliance:aopalliance:1.0"), resolutionResult);
when(mockProjectDependenciesResolver.resolve(any())).thenThrow(exception);
try {
rule.execute(mockRuleHelper);
fail("The rule should throw EnforcerRuleException upon dependency resolution exception");
} catch (EnforcerRuleException expected) {
verify(mockLog).warn("aopalliance:aopalliance:jar:1.0 was not resolved. " + "Dependency path: a:b:jar:0.1 > " + "org.apache.maven:maven-core:jar:3.5.2 (compile) > " + "com.google.inject:guice:jar:no_aop:4.0 (compile) > " + "aopalliance:aopalliance:jar:1.0 (compile)");
}
}
use of org.eclipse.aether.graph.DependencyNode in project m2e-core by eclipse-m2e.
the class MavenPropertyTester method test.
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (WORKSPACE_RESULUTION_ENABLE.equals(property)) {
boolean enableWorkspaceResolution = true;
IAdaptable adaptable = (IAdaptable) receiver;
IProject projectAdapter = adaptable.getAdapter(IProject.class);
if (projectAdapter != null) {
IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry();
IMavenProjectFacade projectFacade = projectManager.create(projectAdapter, new NullProgressMonitor());
if (projectFacade != null) {
ResolverConfiguration configuration = projectFacade.getResolverConfiguration();
return !configuration.shouldResolveWorkspaceProjects();
}
}
return enableWorkspaceResolution;
}
if (HAS_ARTIFACT_KEY.equals(property)) {
ArtifactKey ak = SelectionUtil.getType(receiver, ArtifactKey.class);
return ak != null;
}
if (HAS_PROJECT_ARTIFACT_KEY.equals(property)) {
ArtifactKey key = SelectionUtil.getType(receiver, ArtifactKey.class);
if (key != null) {
IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry();
IMavenProjectFacade mavenProject = null;
mavenProject = //
projectManager.getMavenProject(key.getGroupId(), key.getArtifactId(), key.getVersion());
return mavenProject != null;
}
}
if (IS_TRANSITIVE_DEPENDENCY_TREE_NODE.equals(property)) {
if (receiver instanceof DependencyNode) {
DependencyNode nd = (DependencyNode) receiver;
return nd.getData().get("LEVEL") == null;
}
}
if (IS_DIRECT_DEPENDENCY_TREE_NODE.equals(property)) {
if (receiver instanceof DependencyNode) {
DependencyNode nd = (DependencyNode) receiver;
return "DIRECT".equals(nd.getData().get("LEVEL"));
}
}
if (IS_BUILD_DIRECTORY.equals(property)) {
if (receiver instanceof IFolder) {
IFolder folder = (IFolder) receiver;
IProject project = folder.getProject();
if (project != null) {
IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry();
// Lookup project facade in the cache registry to minimize UI locking
IMavenProjectFacade projectFacade = projectManager.create(project, new NullProgressMonitor());
IPath outputLocation;
if (projectFacade == null || projectFacade.getMavenProject() == null) {
// If the project facade has not been cached yet (ex. during workspace startup),
// fall back on the default value
outputLocation = new Path(DEFAULT_BUILD_DIR);
} else {
String buildDir = projectFacade.getMavenProject().getBuild().getDirectory();
outputLocation = MavenProjectUtils.getProjectRelativePath(project, buildDir);
}
if (outputLocation != null) {
return folder.equals(project.getFolder(outputLocation));
}
}
}
}
if (HAS_MAVEN_NATURE.equals(property)) {
if (receiver instanceof IFileEditorInput) {
var editor = (IFileEditorInput) receiver;
return checkProjectNature(editor.getFile().getProject(), expectedValue);
}
if (receiver instanceof IResource) {
IProject project = ((IResource) receiver).getProject();
return checkProjectNature(project, expectedValue);
}
}
return false;
}
use of org.eclipse.aether.graph.DependencyNode in project m2e-core by eclipse-m2e.
the class DependencyTreePage method createHierarchySection.
private void createHierarchySection(Composite sashForm, FormToolkit formToolkit) {
Composite hierarchyComposite = formToolkit.createComposite(sashForm, SWT.NONE);
hierarchyComposite.setLayout(new GridLayout());
Section hierarchySection = formToolkit.createSection(hierarchyComposite, ExpandableComposite.TITLE_BAR);
hierarchySection.marginHeight = 1;
GridData gd_hierarchySection = new GridData(SWT.FILL, SWT.FILL, true, true);
gd_hierarchySection.widthHint = 100;
gd_hierarchySection.minimumWidth = 100;
hierarchySection.setLayoutData(gd_hierarchySection);
hierarchySection.setText(Messages.DependencyTreePage_section_hierarchy);
formToolkit.paintBordersFor(hierarchySection);
Tree tree = formToolkit.createTree(hierarchySection, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI);
hierarchySection.setClient(tree);
treeViewer = new TreeViewer(tree);
treeViewer.setData(FormToolkit.KEY_DRAW_BORDER, Boolean.TRUE);
DependencyTreeLabelProvider treeLabelProvider = new DependencyTreeLabelProvider();
treeViewer.setContentProvider(new DependencyTreeContentProvider());
treeViewer.setLabelProvider(treeLabelProvider);
treeViewer.addSelectionChangedListener(event -> {
if (!isSettingSelection) {
isSettingSelection = true;
IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
selectListElements(new DependencyNodeMatcher(selection));
isSettingSelection = false;
}
});
treeViewer.addOpenListener(event -> {
IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
for (Object o : selection) {
if (o instanceof DependencyNode) {
org.eclipse.aether.artifact.Artifact a = ((DependencyNode) o).getDependency().getArtifact();
OpenPomAction.openEditor(a.getGroupId(), a.getArtifactId(), a.getVersion(), mavenProject, null);
}
}
});
createHierarchyToolbar(hierarchySection, treeLabelProvider, formToolkit);
}
use of org.eclipse.aether.graph.DependencyNode in project m2e-core by eclipse-m2e.
the class ExcludeArtifactRefactoring method getDependencyExcludes.
/**
* Map key is one of <dependency> element of specified (workspace) model. Map value is set of <excludes> element keys
* to be added to the <dependency>.
*/
private Map<Dependency, Set<ArtifactKey>> getDependencyExcludes(ParentHierarchyEntry model, IProgressMonitor monitor) throws CoreException {
IMavenProjectFacade facade = model.getFacade();
MavenProject project = model.getProject();
DependencyNode root = MavenPlugin.getMavenModelManager().readDependencyTree(facade, project, JavaScopes.TEST, monitor);
Visitor visitor = new Visitor(model);
root.accept(visitor);
return visitor.getSourceMap();
}
use of org.eclipse.aether.graph.DependencyNode in project m2e-core by eclipse-m2e.
the class MavenModelManager method readDependencyTree.
DependencyNode readDependencyTree(RepositorySystemSession repositorySession, MavenProject mavenProject, String scope) throws CoreException {
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySession);
//
// Taken from MavenRepositorySystemSession.newSession()
//
ConflictResolver transformer = new ConflictResolver(new NearestVersionSelector(), new JavaScopeSelector(), new SimpleOptionalitySelector(), new JavaScopeDeriver());
session.setDependencyGraphTransformer(transformer);
session.setConfigProperty(ConflictResolver.CONFIG_PROP_VERBOSE, Boolean.toString(true));
session.setConfigProperty(DependencyManagerUtils.CONFIG_PROP_VERBOSE, true);
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(maven.getProjectRealm(mavenProject));
ArtifactTypeRegistry stereotypes = session.getArtifactTypeRegistry();
CollectRequest request = new CollectRequest();
// $NON-NLS-1$
request.setRequestContext("project");
request.setRepositories(mavenProject.getRemoteProjectRepositories());
for (org.apache.maven.model.Dependency dependency : mavenProject.getDependencies()) {
request.addDependency(RepositoryUtils.toDependency(dependency, stereotypes));
}
DependencyManagement depMngt = mavenProject.getDependencyManagement();
if (depMngt != null) {
for (org.apache.maven.model.Dependency dependency : depMngt.getDependencies()) {
request.addManagedDependency(RepositoryUtils.toDependency(dependency, stereotypes));
}
}
DependencyNode node;
try {
node = MavenPluginActivator.getDefault().getRepositorySystem().collectDependencies(session, request).getRoot();
} catch (DependencyCollectionException ex) {
String msg = Messages.MavenModelManager_error_read;
log.error(msg, ex);
throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, msg, ex));
}
Collection<String> scopes = new HashSet<>();
Collections.addAll(scopes, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_COMPILE, Artifact.SCOPE_PROVIDED, Artifact.SCOPE_RUNTIME, Artifact.SCOPE_TEST);
if (Artifact.SCOPE_COMPILE.equals(scope)) {
scopes.remove(Artifact.SCOPE_COMPILE);
scopes.remove(Artifact.SCOPE_SYSTEM);
scopes.remove(Artifact.SCOPE_PROVIDED);
} else if (Artifact.SCOPE_RUNTIME.equals(scope)) {
scopes.remove(Artifact.SCOPE_COMPILE);
scopes.remove(Artifact.SCOPE_RUNTIME);
} else if (Artifact.SCOPE_COMPILE_PLUS_RUNTIME.equals(scope)) {
scopes.remove(Artifact.SCOPE_COMPILE);
scopes.remove(Artifact.SCOPE_SYSTEM);
scopes.remove(Artifact.SCOPE_PROVIDED);
scopes.remove(Artifact.SCOPE_RUNTIME);
} else {
scopes.clear();
}
CloningDependencyVisitor cloner = new CloningDependencyVisitor();
node.accept(new FilteringDependencyVisitor(cloner, new ScopeDependencyFilter(null, scopes)));
node = cloner.getRootNode();
return node;
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
}
Aggregations