Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.creative.studio.component.dependency.plugins;
  
  import java.io.File;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
 
 

Author(s):
Von Gosling
See also:
mojo-api-specification
 
 @Mojo(name = "check", threadSafe = true, requiresDependencyResolution = ., defaultPhase = .)
 public class DependencyMediatorMojo extends AbstractMojo {
    
The Maven project.
 
     @Component
     private MavenProject          project;
    
The dependency tree builder to use for verbose output.
 
     @Component
     private DependencyTreeBuilder dependencyTreeBuilder;
    
Local Repository.
 
     @Parameter(defaultValue = "${localRepository}", readonly = true, required = true)
     private ArtifactRepository    localRepository;
    
Skip plugin execution completely.
 
     @Parameter(property = "skip", defaultValue = "false")
     private boolean               skip;
    
Whether report class incompatible details
 
     @Parameter(property = "printIncompatibleDetails", defaultValue = "true")
     private boolean               printIncompatibleDetails;
    
The scope to filter by when resolving the dependency tree, or null to include dependencies from all scopes. Note that this feature does not currently work due to MNG-3236.

Since:
2.0-alpha-5
See also:
MNG-3236
 
     @Parameter(property = "scope")
     private String                scope;
    
A comma-separated list of artifacts to filter the serialized dependency tree by, or null not to filter the dependency tree. The filter syntax is:
 [groupId]:[artifactId]:[type]:[version]
 
where each pattern segment is optional and supports full and partial * wildcards. An empty pattern segment is treated as an implicit wildcard.

For example, org.apache.* will match all artifacts whose group id starts with org.apache., and :::*-SNAPSHOT will match all snapshot artifacts.

Since:
2.0-alpha-6
See also:
StrictPatternIncludesArtifactFilter
 
     @Parameter(property = "includes")
     private String                includes;

    
A comma-separated list of artifacts to filter from the serialized dependency tree, or null not to filter any artifacts from the dependency tree. The filter syntax is:
 [groupId]:[artifactId]:[type]:[version]
 
where each pattern segment is optional and supports full and partial * wildcards. An empty pattern segment is treated as an implicit wildcard.

For example, org.apache.* will match all artifacts whose group id starts with org.apache., and :::*-SNAPSHOT will match all snapshot artifacts.

Since:
2.0-alpha-6
See also:
StrictPatternExcludesArtifactFilter
    @Parameter(property = "excludes")
    private String                excludes;
    
Determines whether or not to abort the build when encountering an error dependency checking.
    @Parameter(defaultValue = "true")
    private boolean               failOnError;
    public boolean isSkip() {
        return ;
    }

    
Gets the artifact filter to use when resolving the dependency.

Returns:
the artifact filter
        // add filters in well known order, least specific to most specific
        ArtifactFilter filter = null;
        // filter scope
        if ( != null) {
            getLog().debug("+ Resolving dependency tree for scope '" +  + "'");
            filter = new ScopeArtifactFilter();
        } else {
            filter = null;
        }
        return filter;
    }
    public void execute() throws MojoExecutionExceptionMojoFailureException {
        if (isSkip()) {
            getLog().info(.getArtifactId() + " skipped compatible checking");
            return;
        }
        doExecute();
    }
    private void processPackage() throws MojoExecutionException {
        try {
            //Limit the transitivity of a dependency, and also to affect the classpath used for various build tasks.
            ArtifactFilter artifactFilter = createResolvingArtifactFilter();
            DependencyResolver dependencyResolver = new DefaultDependencyResolver();
                    artifactFilter);
            DependencyResolutionResult drr = dependencyResolver.resolve(rootNode);
            Map<StringList<Artifact>> conflictDependencyArtifact = drr
                    .getConflictDependencyArtifact();
            Map<StringArtifactresults = drr.getResolvedDependenciesByName();
            if (!conflictDependencyArtifact.isEmpty()) {
                Iterator<Entry<StringList<Artifact>>> iter = conflictDependencyArtifact
                        .entrySet().iterator();
                while (iter.hasNext()) {
                    Entry<StringList<Artifact>> conflictEntries = iter.next();
                    StringBuilder sb = new StringBuilder("Founded conflicting dependency component:");
                    List<ArtifactconflictArtifacts = conflictEntries.getValue();
                    sb.append(conflictEntries.getKey())
                            .append("\n Resolved version is "
                                    + results.get(conflictEntries.getKey()))
                            .append("\n But found conflicting artifact ");
                    for (Artifact at : conflictArtifacts) {
                        sb.append(String.format("%s:%s:%s,"at.getGroupId(), at.getArtifactId(),
                                at.getVersion()));
                    }
                    getLog().warn(sb.subSequence(0, sb.length() - 1));
                }
            }
        } catch (DependencyTreeBuilderException e) {
            throw new MojoExecutionException("Cannot build project dependency "e);
        }
    }
    private void doExecute() throws MojoExecutionException {
        Model model = .getModel();
        String packagingType = model.getPackaging();
        if (..getValue().equalsIgnoreCase(packagingType)) {
            processWarPackage();
            printResult();
        } else {
            processPackage();
        }
    }
    private void processWarPackage() throws MojoExecutionException {
        File dependencyFolder = new File(new File(new File(.getBuild().getDirectory()),
                .getBuild().getFinalName()), "WEB-INF/lib");
        if (!dependencyFolder.exists()) {
            throw new MojoExecutionException(dependencyFolder
                    + " not exits, please execute mvn install first");
        }
        File[] jarFiles = listFiles(dependencyFolder);
        if (jarFiles == null || jarFiles.length == 0) {
            getLog().info("No dependencies for " + .getArtifactId());
            System.exit(0);
        }
        try {
            processJarFiles(jarFiles);
        } catch (IOException e) {
            String message = "Failed to process  " + .getArtifactId();
            getLog().error(messagee);
            throw new MojoExecutionException(messagee);
        }
    }
    private void processJarFiles(File[] jarFilesthrows IOException {
        for (File file : jarFiles) {
            DependencyMediator.processJarFile(filetrue);
        }
    }
    private void printResult() {
        getLog().info("Output component reactor info......");
        int count = 0;
        for (Entry<StringTreeSet<ComponentEntry>> entry : ..entrySet()) {
            if (entry.getValue().size() > 1) {
                count++;
                getLog().warn(
                        String.format("Conflicting component  [%s] was founded in the  path : \n",
                                entry.getKey()));
                for (ComponentEntry jar : entry.getValue()) {
                    getLog().warn(String.format(" \t%s\n"jar.getPathName()));
                }
            }
        }
        if (count == 0) {
            getLog().info("Congratulations,no conflicting component  exist!");
        }
    }
    private File[] listFiles(File dependencyFolder) {
        return dependencyFolder.listFiles(new FilenameFilter() {
            public boolean accept(File dirString name) {
                return ..matcher(name).matches();
            }
        });
    }
New to GrepCode? Check out our FAQ X