public static Collection<String> findOccupiedPackagesIn(File dir) { if (dir.exists()) { DirectoryClassPathRoot root = new DirectoryClassPathRoot(dir); Set<String> occupiedPackages = new HashSet<>(); FCollection.mapTo(root.classNames(), classToPackageGlob(), occupiedPackages); return occupiedPackages; } return Collections.emptyList(); }
private static List<ClassPathRoot> createRoots(final Collection<File> files) { File lastFile = null; try { final List<ClassPathRoot> rs = new ArrayList<>(); for (final File f : files) { lastFile = f; if (f.isDirectory()) { rs.add(new DirectoryClassPathRoot(f)); } else { handleArchive(rs, f); } } return rs; } catch (final IOException ex) { throw new PitError("Error handling file " + lastFile, ex); } }
private Predicate<String> createClassPredicate() { final Collection<String> classes = new HashSet<>(); for (final File buildOutputDirectory : this.compiledCodeDirectories) { if (buildOutputDirectory.exists()) { final DirectoryClassPathRoot dcRoot = new DirectoryClassPathRoot(buildOutputDirectory); classes.addAll(FCollection.map(dcRoot.classNames(), toPredicate())); } } return Prelude.or(FCollection.map(classes, Glob.toGlobPredicate())); }
@Test public void shouldReturnClassNames() { final File root = new File("target/test-classes/"); // this is going to be // flakey as hell this.testee = new DirectoryClassPathRoot(root); assertTrue(this.testee.classNames().contains( DirectoryClassPathRootTest.class.getName())); }
@Test public void getDataShouldReturnNullForUnknownClass() throws Exception { this.testee = new DirectoryClassPathRoot(new File("foo")); assertNull(this.testee.getData("bar")); }
@Test public void shouldNotTreatDirectoriesEndingInTestClassesAsCode() { final ClassPathRoot archiveRoot = new DirectoryClassPathRoot(new File( "foo/bar/test-classes")); assertFalse(this.testee.test(archiveRoot)); }
@Test public void shouldTreatDirectoriesAsCode() { final ClassPathRoot archiveRoot = new DirectoryClassPathRoot(new File( "foo/bar/")); assertTrue(this.testee.test(archiveRoot)); } }
@Test public void shouldNotTreatDirectoriesAsDependencies() { final ClassPathRoot archiveRoot = new DirectoryClassPathRoot(new File( "foo/bar/")); assertFalse(this.testee.test(archiveRoot)); }
@Test public void shouldNotTreatDirectoriesEndingInBinTestAsCode() { final ClassPathRoot archiveRoot = new DirectoryClassPathRoot(new File( "foo/bar/bin-test")); assertFalse(this.testee.test(archiveRoot)); }
@Test public void shouldMatchRootsWithMatchingNames() { final File testFile = new File("/foo/bar"); final ClassPathRoot root = new DirectoryClassPathRoot(testFile); this.testee = new PathNamePredicate(Prelude.isEqualTo(testFile .getAbsolutePath())); assertThat(this.testee.test(root), is(true)); }
@Test public void shouldNotMatchRootsWithNonMatchingNames() { final ClassPathRoot root = new DirectoryClassPathRoot(new File("/foo/bar/")); this.testee = new PathNamePredicate(Prelude.isEqualTo("phoee")); assertFalse(this.testee.test(root)); }
private static List<ClassPathRoot> createRoots(final Collection<File> files) { File lastFile = null; try { final List<ClassPathRoot> rs = new ArrayList<>(); for (final File f : files) { lastFile = f; if (f.isDirectory()) { rs.add(new DirectoryClassPathRoot(f)); } else { handleArchive(rs, f); } } return rs; } catch (final IOException ex) { throw new PitError("Error handling file " + lastFile, ex); } }
public static Collection<String> findOccupiedPackagesIn(File dir) { if (dir.exists()) { DirectoryClassPathRoot root = new DirectoryClassPathRoot(dir); Set<String> occupiedPackages = new HashSet<>(); FCollection.mapTo(root.classNames(), classToPackageGlob(), occupiedPackages); return occupiedPackages; } return Collections.emptyList(); }