@Test public void testCopyLibs() throws Exception { AbstractWisdomMojo mojo = new AbstractWisdomMojo() { @Override public void execute() throws MojoExecutionException, MojoFailureException { } }; mojo.basedir = new File("target/junk/project1"); mojo.basedir.mkdirs(); mojo.project = new MavenProject(); mojo.project.setArtifacts(resolved); mojo.buildDirectory = new File(mojo.basedir, "target"); final Artifact asmArtifact = artifact("asm"); final Artifact parboiledCoreArtifact = artifact("parboiledCore"); final Artifact parboiledArtifact = artifact("parboiled"); final Artifact pegdownArtifact = artifact("pegdown"); final Artifact projectArtifact = artifact("project"); setTrail(projectArtifact, projectArtifact); setTrail(pegdownArtifact, projectArtifact, pegdownArtifact); setTrail(parboiledArtifact, projectArtifact, pegdownArtifact, parboiledArtifact); setTrail(parboiledCoreArtifact, projectArtifact, pegdownArtifact, parboiledArtifact, parboiledCoreArtifact); setTrail(asmArtifact, projectArtifact, pegdownArtifact, asmArtifact); DefaultDependencyNode root = new DefaultDependencyNode(null, projectArtifact, null, null, null); DefaultDependencyNode pegdown = new DefaultDependencyNode(root, pegdownArtifact, null, null, null); DefaultDependencyNode parboiled = new DefaultDependencyNode(pegdown, parboiledArtifact, null, null, null); DefaultDependencyNode parboiledCore = new DefaultDependencyNode(parboiled, parboiledCoreArtifact, null, null, null); DefaultDependencyNode asm = new DefaultDependencyNode(parboiled, asmArtifact, null, null, null); root.setChildren(ImmutableList.<DependencyNode>of(pegdown)); pegdown.setChildren(ImmutableList.<DependencyNode>of(parboiled)); parboiled.setChildren(ImmutableList.<DependencyNode>of(parboiledCore, asm)); parboiledCore.setChildren(Collections.<DependencyNode>emptyList()); asm.setChildren(Collections.<DependencyNode>emptyList()); DependencyGraphBuilder builder = mock(DependencyGraphBuilder.class); when(builder.buildDependencyGraph(mojo.project, null)).thenReturn(root); Libraries libraries = new Libraries(); libraries.setResolveTransitive(true); libraries.setIncludes(ImmutableList.of(":pegdown")); Set<Artifact> copied = DependencyCopy.copyLibs(mojo, builder, libraries); assertThat(copied).hasSize(4); libraries.setResolveTransitive(false); libraries.setIncludes(ImmutableList.of(":pegdown")); copied = DependencyCopy.copyLibs(mojo, builder, libraries); assertThat(copied).hasSize(1); libraries.setResolveTransitive(true); libraries.setIncludes(ImmutableList.of(":pegdown")); libraries.setExcludes(ImmutableList.of(":asm")); copied = DependencyCopy.copyLibs(mojo, builder, libraries); assertThat(copied).hasSize(3); Artifact annotation = artifact("org.apache.felix.ipojo.annotations"); when(annotation.getGroupId()).thenReturn("org.apache.felix"); setTrail(annotation, projectArtifact, pegdownArtifact); DefaultDependencyNode ann = new DefaultDependencyNode(parboiled, annotation, null, null, null); ann.setChildren(Collections.<DependencyNode>emptyList()); pegdown.setChildren(ImmutableList.<DependencyNode>of(parboiled, ann)); libraries.setResolveTransitive(true); libraries.setIncludes(ImmutableList.of(":pegdown")); libraries.setExcludes(ImmutableList.of(":asm")); copied = DependencyCopy.copyLibs(mojo, builder, libraries); assertThat(copied).hasSize(3); }
public static Set<Artifact> copyLibs(AbstractWisdomMojo mojo, DependencyGraphBuilder graph, Libraries libraries) throws IOException { if (libraries == null || !libraries.hasLibraries()) { return Collections.emptySet(); } File libsDirectory = new File(mojo.getWisdomRootDirectory(), "libs"); ArtifactFilter filter = libraries.getFilter(); Set<Artifact> artifacts = getArtifactsToConsider(mojo, graph, true, null); for (final Iterator<Artifact> it = artifacts.iterator(); it.hasNext(); ) { final Artifact artifact = it.next(); if (!filter.include(artifact)) { it.remove(); if (mojo.getLog().isDebugEnabled()) { mojo.getLog().debug(artifact.getId() + " was removed by filters."); } continue; } if (BundleExclusions.isExcluded(artifact)) { it.remove(); mojo.getLog().info("Dependency " + artifact + " not copied - the artifact is on the exclusion list"); continue; } if (SCOPE_COMPILE.equalsIgnoreCase(artifact.getScope())) { File file = artifact.getFile(); if (file != null && file.isFile()) { mojo.getLog().warn("Copying " + file.getName() + " to the libs directory"); FileUtils.copyFileToDirectory(file, libsDirectory); } else { mojo.getLog().warn("Cannot copy the file associated with " + artifact.getArtifactId() + " - the " + "file is missing"); } } else { it.remove(); } } return artifacts; }
DependencyCopy { public static Set<Artifact> copyLibs(AbstractWisdomMojo mojo, DependencyGraphBuilder graph, Libraries libraries) throws IOException { if (libraries == null || !libraries.hasLibraries()) { return Collections.emptySet(); } File libsDirectory = new File(mojo.getWisdomRootDirectory(), "libs"); ArtifactFilter filter = libraries.getFilter(); Set<Artifact> artifacts = getArtifactsToConsider(mojo, graph, true, null); for (final Iterator<Artifact> it = artifacts.iterator(); it.hasNext(); ) { final Artifact artifact = it.next(); if (!filter.include(artifact)) { it.remove(); if (mojo.getLog().isDebugEnabled()) { mojo.getLog().debug(artifact.getId() + " was removed by filters."); } continue; } if (BundleExclusions.isExcluded(artifact)) { it.remove(); mojo.getLog().info("Dependency " + artifact + " not copied - the artifact is on the exclusion list"); continue; } if (SCOPE_COMPILE.equalsIgnoreCase(artifact.getScope())) { File file = artifact.getFile(); if (file != null && file.isFile()) { mojo.getLog().warn("Copying " + file.getName() + " to the libs directory"); FileUtils.copyFileToDirectory(file, libsDirectory); } else { mojo.getLog().warn("Cannot copy the file associated with " + artifact.getArtifactId() + " - the " + "file is missing"); } } else { it.remove(); } } return artifacts; } }
DependencyCopy { public static Set<Artifact> copyLibs(AbstractWisdomMojo mojo, DependencyGraphBuilder graph, Libraries libraries) throws IOException { if (libraries == null || !libraries.hasLibraries()) { return Collections.emptySet(); } File libsDirectory = new File(mojo.getWisdomRootDirectory(), "libs"); ArtifactFilter filter = libraries.getFilter(); Set<Artifact> artifacts = getArtifactsToConsider(mojo, graph, true, null); for (final Iterator<Artifact> it = artifacts.iterator(); it.hasNext(); ) { final Artifact artifact = it.next(); if (!filter.include(artifact)) { it.remove(); if (mojo.getLog().isDebugEnabled()) { mojo.getLog().debug(artifact.getId() + " was removed by filters."); } continue; } if (BundleExclusions.isExcluded(artifact)) { it.remove(); mojo.getLog().info("Dependency " + artifact + " not copied - the artifact is on the exclusion list"); continue; } if (SCOPE_COMPILE.equalsIgnoreCase(artifact.getScope())) { File file = artifact.getFile(); if (file != null && file.isFile()) { mojo.getLog().warn("Copying " + file.getName() + " to the libs directory"); FileUtils.copyFileToDirectory(file, libsDirectory); } else { mojo.getLog().warn("Cannot copy the file associated with " + artifact.getArtifactId() + " - the " + "file is missing"); } } else { it.remove(); } } return artifacts; }  }
DependencyCopy { public static Set<Artifact> copyLibs(AbstractWisdomMojo mojo, DependencyGraphBuilder graph, Libraries libraries) throws IOException { if (libraries == null || !libraries.hasLibraries()) { return Collections.emptySet(); } File libsDirectory = new File(mojo.getWisdomRootDirectory(), "libs"); ArtifactFilter filter = libraries.getFilter(); Set<Artifact> artifacts = getArtifactsToConsider(mojo, graph, true, null); for (final Iterator<Artifact> it = artifacts.iterator(); it.hasNext(); ) { final Artifact artifact = it.next(); if (!filter.include(artifact)) { it.remove(); if (mojo.getLog().isDebugEnabled()) { mojo.getLog().debug(artifact.getId() + " was removed by filters."); } continue; } if (BundleExclusions.isExcluded(artifact)) { it.remove(); mojo.getLog().info("Dependency " + artifact + " not copied - the artifact is on the exclusion list"); continue; } if (SCOPE_COMPILE.equalsIgnoreCase(artifact.getScope())) { File file = artifact.getFile(); if (file != null && file.isFile()) { mojo.getLog().warn("Copying " + file.getName() + " to the libs directory"); FileUtils.copyFileToDirectory(file, libsDirectory); } else { mojo.getLog().warn("Cannot copy the file associated with " + artifact.getArtifactId() + " - the " + "file is missing"); } } else { it.remove(); } } return artifacts; }  static void copyBundles(AbstractWisdomMojo mojo, DependencyGraphBuilder graph, boolean transitive,
                                   boolean deployTestDependencies, boolean disableDefaultExclusions, Libraries libraries); static Set<Artifact> copyLibs(AbstractWisdomMojo mojo, DependencyGraphBuilder graph, Libraries libraries); static Set<Artifact> getArtifactsToConsider(AbstractWisdomMojo mojo, DependencyGraphBuilder graph,
                                                       boolean transitive, ArtifactFilter filter); }
DependencyCopy { public static Set<Artifact> copyLibs(AbstractWisdomMojo mojo, DependencyGraphBuilder graph, Libraries libraries) throws IOException { if (libraries == null || !libraries.hasLibraries()) { return Collections.emptySet(); } File libsDirectory = new File(mojo.getWisdomRootDirectory(), "libs"); ArtifactFilter filter = libraries.getFilter(); Set<Artifact> artifacts = getArtifactsToConsider(mojo, graph, true, null); for (final Iterator<Artifact> it = artifacts.iterator(); it.hasNext(); ) { final Artifact artifact = it.next(); if (!filter.include(artifact)) { it.remove(); if (mojo.getLog().isDebugEnabled()) { mojo.getLog().debug(artifact.getId() + " was removed by filters."); } continue; } if (BundleExclusions.isExcluded(artifact)) { it.remove(); mojo.getLog().info("Dependency " + artifact + " not copied - the artifact is on the exclusion list"); continue; } if (SCOPE_COMPILE.equalsIgnoreCase(artifact.getScope())) { File file = artifact.getFile(); if (file != null && file.isFile()) { mojo.getLog().warn("Copying " + file.getName() + " to the libs directory"); FileUtils.copyFileToDirectory(file, libsDirectory); } else { mojo.getLog().warn("Cannot copy the file associated with " + artifact.getArtifactId() + " - the " + "file is missing"); } } else { it.remove(); } } return artifacts; }  static void copyBundles(AbstractWisdomMojo mojo, DependencyGraphBuilder graph, boolean transitive,
                                   boolean deployTestDependencies, boolean disableDefaultExclusions, Libraries libraries); static Set<Artifact> copyLibs(AbstractWisdomMojo mojo, DependencyGraphBuilder graph, Libraries libraries); static Set<Artifact> getArtifactsToConsider(AbstractWisdomMojo mojo, DependencyGraphBuilder graph,
                                                       boolean transitive, ArtifactFilter filter); static final String SCOPE_PROVIDED; static final String SCOPE_COMPILE; static final String SCOPE_TEST; }