| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.codehaus.mojo.nbm; |
| 18 | |
|
| 19 | |
import java.util.ArrayList; |
| 20 | |
import java.util.HashMap; |
| 21 | |
import java.util.HashSet; |
| 22 | |
import java.util.List; |
| 23 | |
import java.util.Map; |
| 24 | |
import java.util.Set; |
| 25 | |
import org.apache.maven.artifact.Artifact; |
| 26 | |
import org.apache.maven.plugin.MojoExecutionException; |
| 27 | |
import org.apache.maven.plugin.logging.Log; |
| 28 | |
import org.apache.maven.shared.dependency.graph.DependencyNode; |
| 29 | |
import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor; |
| 30 | |
import org.codehaus.mojo.nbm.utils.ExamineManifest; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
public class CollectLibrariesNodeVisitor |
| 38 | |
implements DependencyNodeVisitor |
| 39 | |
{ |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
private final List<Artifact> nodes; |
| 45 | |
|
| 46 | |
private Map<String, Artifact> artifacts; |
| 47 | |
|
| 48 | |
private Map<Artifact, ExamineManifest> examinerCache; |
| 49 | |
|
| 50 | |
private List<String> explicitLibs; |
| 51 | |
|
| 52 | |
private final Log log; |
| 53 | |
|
| 54 | |
private MojoExecutionException throwable; |
| 55 | |
|
| 56 | |
private DependencyNode root; |
| 57 | |
|
| 58 | |
private Set<String> duplicates; |
| 59 | |
|
| 60 | |
private Set<String> conflicts; |
| 61 | |
|
| 62 | |
private Set<String> includes; |
| 63 | |
|
| 64 | |
private final boolean useOsgiDependencies; |
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
public CollectLibrariesNodeVisitor( List<String> explicitLibraries, |
| 70 | |
List<Artifact> runtimeArtifacts, Map<Artifact, ExamineManifest> examinerCache, |
| 71 | |
Log log, DependencyNode root, boolean useOsgiDependencies ) |
| 72 | 0 | { |
| 73 | 0 | nodes = new ArrayList<Artifact>(); |
| 74 | 0 | artifacts = new HashMap<String, Artifact>(); |
| 75 | 0 | for ( Artifact a : runtimeArtifacts ) |
| 76 | |
{ |
| 77 | 0 | artifacts.put( a.getDependencyConflictId(), a ); |
| 78 | 0 | } |
| 79 | 0 | this.examinerCache = examinerCache; |
| 80 | 0 | this.explicitLibs = explicitLibraries; |
| 81 | 0 | this.log = log; |
| 82 | 0 | this.root = root; |
| 83 | 0 | this.useOsgiDependencies = useOsgiDependencies; |
| 84 | 0 | duplicates = new HashSet<String>(); |
| 85 | 0 | conflicts = new HashSet<String>(); |
| 86 | 0 | includes = new HashSet<String>(); |
| 87 | 0 | } |
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
public boolean visit( DependencyNode node ) |
| 93 | |
{ |
| 94 | 0 | if ( throwable != null ) |
| 95 | |
{ |
| 96 | 0 | return false; |
| 97 | |
} |
| 98 | 0 | if ( root == node ) |
| 99 | |
{ |
| 100 | 0 | return true; |
| 101 | |
} |
| 102 | |
try |
| 103 | |
{ |
| 104 | 0 | Artifact artifact = node.getArtifact(); |
| 105 | 0 | if ( !artifacts.containsKey( artifact.getDependencyConflictId() ) ) |
| 106 | |
{ |
| 107 | |
|
| 108 | 0 | return false; |
| 109 | |
} |
| 110 | |
|
| 111 | 0 | artifact = artifacts.get( artifact.getDependencyConflictId() ); |
| 112 | |
|
| 113 | 0 | ExamineManifest depExaminator = examinerCache.get( artifact ); |
| 114 | 0 | if ( depExaminator == null ) |
| 115 | |
{ |
| 116 | 0 | depExaminator = new ExamineManifest( log ); |
| 117 | 0 | depExaminator.setArtifactFile( artifact.getFile() ); |
| 118 | 0 | depExaminator.checkFile(); |
| 119 | 0 | examinerCache.put( artifact, depExaminator ); |
| 120 | |
} |
| 121 | 0 | if ( AbstractNbmMojo.matchesLibrary( artifact, explicitLibs, depExaminator, log, useOsgiDependencies ) ) |
| 122 | |
{ |
| 123 | 0 | if ( depExaminator.isNetBeansModule() ) |
| 124 | |
{ |
| 125 | 0 | log.warn( |
| 126 | |
"You are using a NetBeans Module as a Library (classpath extension): " + artifact.getId() ); |
| 127 | |
} |
| 128 | |
|
| 129 | 0 | nodes.add( artifact ); |
| 130 | 0 | includes.add( artifact.getDependencyConflictId() ); |
| 131 | |
|
| 132 | 0 | return true; |
| 133 | |
} |
| 134 | |
} |
| 135 | 0 | catch ( MojoExecutionException mojoExecutionException ) |
| 136 | |
{ |
| 137 | 0 | throwable = mojoExecutionException; |
| 138 | 0 | } |
| 139 | |
|
| 140 | 0 | return false; |
| 141 | |
} |
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
public boolean endVisit( DependencyNode node ) |
| 147 | |
{ |
| 148 | 0 | if ( throwable != null ) |
| 149 | |
{ |
| 150 | 0 | return false; |
| 151 | |
} |
| 152 | 0 | if ( node == root ) |
| 153 | |
{ |
| 154 | 0 | if ( nodes.size() > 0 ) |
| 155 | |
{ |
| 156 | 0 | log.info( "Adding on module's Class-Path:" ); |
| 157 | 0 | for ( Artifact inc : nodes ) |
| 158 | |
{ |
| 159 | 0 | log.info( " " + inc.getId() ); |
| 160 | 0 | } |
| 161 | |
} |
| 162 | |
} |
| 163 | 0 | return true; |
| 164 | |
} |
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
public List<Artifact> getArtifacts() |
| 172 | |
throws MojoExecutionException |
| 173 | |
{ |
| 174 | 0 | if ( throwable != null ) |
| 175 | |
{ |
| 176 | 0 | throw throwable; |
| 177 | |
} |
| 178 | 0 | return nodes; |
| 179 | |
} |
| 180 | |
} |