List of usage examples for org.apache.maven.artifact.resolver ResolutionNode setArtifact
public void setArtifact(Artifact artifact)
From source file:org.universAAL.maven.treebuilder.DependencyTreeBuilder.java
License:Apache License
/** * Method checks if passed child artifact has one of groupIds specified in * separatedGroupIds Set. If so its artifactId is checked, if the ending * suffix is ".core". It this is true then there are two cases: * <ul>/*from w ww. j av a 2 s . c o m*/ * <li>the parent and the child have the same groupId and they artifactIds * are different only in suffix (.core != .osgi). In such case method does * not change anything, however it checks if versions of the parent and the * child are the same. If not an exception is thrown. * <li>if the previous does not apply then the suffix of child's artifactId * is changed from ".core" to ".osgi. * </ul> * * @param parentNode * Parent node. * @param childNode * Child node. * @param separatedGroupIds * List of groupIds which artifacts are separated to .core and * .osgi branches. * @param listener * Listener to be notified about events related to resolution * process. */ private void changeArtifactCoreToOsgi(final ResolutionNode parentNode, final ResolutionNode childNode, final Set<String> separatedGroupIds, final DependencyTreeResolutionListener listener) { Artifact parent = parentNode.getArtifact(); Artifact child = childNode.getArtifact(); if (separatedGroupIds.contains(child.getGroupId())) { String childArtifactId = child.getArtifactId(); if (childArtifactId.endsWith(".core")) { if (child.getGroupId().equals(parent.getGroupId())) { if (parent.getArtifactId().endsWith(".osgi")) { if (changeCoreSuffixToOsgi(childArtifactId).equals(parent.getArtifactId())) { /* * rotgier: In this case artifact cannot be changed * because cyclic dependency will be created and * TreeBuilder will miss the actual dependencies of * the .core artifact. * * However the version check is performed. */ if (child.getVersion() != null) { if (!parent.getVersion().equals(child.getVersion())) { throw new IllegalStateException("Versions of parent and child are different"); } } else { throw new IllegalStateException("Child version is not present"); } if (this.stringifiedRoot.equals(FilteringVisitorSupport.stringify(parent))) { this.separatedArtifactDepsOfRoot.add(childNode); } listener.addExcludedCoreArtifact(childNode); return; } } } /* * rotgier: Otherwise the artifactId suffix has to be changed * from .core to .osgi to follow the actual dependencies of the * .osgi branch. */ Artifact osgiArtifact = null; String osgiArtifactId = changeCoreSuffixToOsgi(childArtifactId); if (child.getVersion() != null) { osgiArtifact = artifactFactory.createArtifact(child.getGroupId(), osgiArtifactId, child.getVersion(), child.getScope(), child.getType()); } else { throw new IllegalArgumentException(); } childNode.setArtifact(osgiArtifact); } } }