Search in sources :

Example 71 with FileFilter

use of java.io.FileFilter in project maven-plugins by apache.

the class WarOverlaysTest method testCacheWithRemovedOverlay.

public void testCacheWithRemovedOverlay() throws Exception {
    // setup test data
    final String testId = "cache-removed-overlay";
    // Add an overlay
    final ArtifactStub overlay = buildWarOverlayStub("overlay-one");
    final ArtifactStub overlay2 = buildWarOverlayStub("overlay-two");
    final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] { overlay, overlay2 });
    final List<File> assertedFiles = new ArrayList<File>();
    try {
        // Use the cache
        setVariableValueToObject(mojo, "useCache", Boolean.TRUE);
        setVariableValueToObject(mojo, "cacheFile", new File(mojo.getWorkDirectory(), "cache.xml"));
        final LinkedList<Overlay> overlays = new LinkedList<Overlay>();
        overlays.add(new DefaultOverlay(overlay));
        overlays.add(new DefaultOverlay(overlay2));
        mojo.setOverlays(overlays);
        mojo.execute();
        // Now remove overlay one the right file is overwritten
        final LinkedList<Overlay> updatedOverlays = new LinkedList<Overlay>();
        updatedOverlays.add(new DefaultOverlay(overlay2));
        mojo.setOverlays(updatedOverlays);
        // Remove overlay one as a dep
        mojo.getProject().getArtifacts().remove(overlay);
        mojo.execute();
        assertedFiles.addAll(assertDefaultContent(webAppDirectory));
        assertedFiles.addAll(assertWebXml(webAppDirectory));
        assertedFiles.addAll(assertCustomContent(webAppDirectory, new String[] { "index.jsp", "login.jsp", "admin.jsp" }, "overlay file not found"));
        // index and login come from overlay2 now
        assertOverlayedFile(webAppDirectory, "overlay-two", "index.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-one", "login.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-two", "admin.jsp");
        // Ok now check that there is no more files/directories
        final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] { MANIFEST_PATH });
        assertWebAppContent(webAppDirectory, assertedFiles, filter);
    } finally {
        cleanDirectory(webAppDirectory);
    }
}
Also used : DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) ArrayList(java.util.ArrayList) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) Overlay(org.apache.maven.plugins.war.Overlay) DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) FileFilter(java.io.FileFilter) File(java.io.File) LinkedList(java.util.LinkedList)

Example 72 with FileFilter

use of java.io.FileFilter in project maven-plugins by apache.

the class WarOverlaysTest method testDefaultOverlay.

public void testDefaultOverlay() throws Exception {
    // setup test data
    final String testId = "default-overlay";
    // Add an overlay
    final ArtifactStub overlay = buildWarOverlayStub("overlay-one");
    final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] { overlay });
    final List<File> assertedFiles = new ArrayList<File>();
    try {
        mojo.execute();
        assertedFiles.addAll(assertDefaultContent(webAppDirectory));
        assertedFiles.addAll(assertWebXml(webAppDirectory));
        assertedFiles.addAll(assertCustomContent(webAppDirectory, new String[] { "index.jsp", "login.jsp" }, "overlay file not found"));
        // index and login come from overlay1
        assertOverlayedFile(webAppDirectory, "overlay-one", "index.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-one", "login.jsp");
        // Ok now check that there is no more files/directories
        final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] { MANIFEST_PATH });
        assertWebAppContent(webAppDirectory, assertedFiles, filter);
    } finally {
        cleanDirectory(webAppDirectory);
    }
}
Also used : ArrayList(java.util.ArrayList) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) FileFilter(java.io.FileFilter) File(java.io.File)

Example 73 with FileFilter

use of java.io.FileFilter in project maven-plugins by apache.

the class WarOverlaysTest method testOverlaysIncludesExcludesWithMultipleDefinitions2.

public void testOverlaysIncludesExcludesWithMultipleDefinitions2() throws Exception {
    // setup test data
    final String testId = "overlays-includes-excludes-multiple-defs2";
    // Add an overlay
    final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1");
    final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2");
    final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3");
    final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] { overlay1, overlay2, overlay3 }, new String[] { "org/sample/company/test.jsp", "jsp/b.jsp" });
    Overlay over1 = new DefaultOverlay(overlay3);
    over1.setExcludes("**/a.*,**/c.*,**/*.xml,jsp/b.jsp");
    Overlay over2 = new DefaultOverlay(overlay1);
    over2.setIncludes("jsp/d/*");
    over2.setExcludes("jsp/d/a.jsp");
    Overlay over3 = new DefaultOverlay(overlay3);
    over3.setIncludes("**/*.jsp");
    over3.setExcludes("jsp/b.jsp");
    Overlay over4 = new DefaultOverlay(overlay2);
    mojo.setOverlays(new LinkedList<Overlay>());
    mojo.addOverlay(over1);
    mojo.addOverlay(over2);
    mojo.addOverlay(over3);
    mojo.addOverlay(mojo.getCurrentProjectOverlay());
    mojo.addOverlay(over4);
    final List<File> assertedFiles = new ArrayList<File>();
    try {
        mojo.execute();
        assertedFiles.addAll(assertWebXml(webAppDirectory));
        assertedFiles.addAll(assertCustomContent(webAppDirectory, new String[] { "jsp/a.jsp", "jsp/b.jsp", "jsp/c.jsp", "jsp/d/a.jsp", "jsp/d/b.jsp", "jsp/d/c.jsp", "org/sample/company/test.jsp", "WEB-INF/classes/a.class", "WEB-INF/classes/b.class", "WEB-INF/classes/c.class", "WEB-INF/lib/a.jar", "WEB-INF/lib/b.jar", "WEB-INF/lib/c.jar" }, "overlay file not found"));
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/a.jsp");
        assertDefaultFileContent(testId, webAppDirectory, "jsp/b.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/c.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/a.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/b.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/c.jsp");
        assertDefaultFileContent(testId, webAppDirectory, "org/sample/company/test.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/web.xml");
        assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.class");
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.class");
        assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/c.class");
        assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/a.jar");
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/lib/b.jar");
        assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/c.jar");
        // Ok now check that there is no more files/directories
        final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] { MANIFEST_PATH });
        assertWebAppContent(webAppDirectory, assertedFiles, filter);
    } finally {
        cleanDirectory(webAppDirectory);
    }
}
Also used : DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) ArrayList(java.util.ArrayList) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) Overlay(org.apache.maven.plugins.war.Overlay) DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) FileFilter(java.io.FileFilter) File(java.io.File)

Example 74 with FileFilter

use of java.io.FileFilter in project maven-plugins by apache.

the class WarDependenciesAnalysisTest method doTestTwiceWithUpdatedDependency.

protected void doTestTwiceWithUpdatedDependency(String testId, ArtifactStub[] firstStubs, ArtifactStub[] secondStubs, String[] firstCustomContent, String[] secondCustomContent) throws Exception {
    // setup test data
    final File xmlSource = createXMLConfigDir(testId, new String[] { "web.xml" });
    final File webAppDirectory = setUpMojoWithCache(testId, firstStubs);
    try {
        mojo.setWebXml(new File(xmlSource, "web.xml"));
        mojo.execute();
        final List<File> assertedFiles = new ArrayList<File>();
        assertedFiles.addAll(assertDefaultContent(webAppDirectory));
        assertedFiles.addAll(assertWebXml(webAppDirectory));
        assertedFiles.addAll(assertCustomContent(webAppDirectory, firstCustomContent, "library not found"));
        // Ok now check that there is no more files/directories
        final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] { MANIFEST_PATH });
        assertWebAppContent(webAppDirectory, assertedFiles, filter);
        // Run the thing again and check it's ok
        setUpMojoWithCache(testId, secondStubs);
        mojo.execute();
        final List<File> assertedFiles2 = new ArrayList<File>();
        assertedFiles2.addAll(assertDefaultContent(webAppDirectory));
        assertedFiles2.addAll(assertWebXml(webAppDirectory));
        if (secondCustomContent != null) {
            assertedFiles2.addAll(assertCustomContent(webAppDirectory, secondCustomContent, "library not found"));
        }
        assertWebAppContent(webAppDirectory, assertedFiles2, filter);
    } finally {
        cleanDirectory(webAppDirectory);
        cleanDirectory(mojo.getWorkDirectory());
    }
}
Also used : ArrayList(java.util.ArrayList) FileFilter(java.io.FileFilter) File(java.io.File)

Example 75 with FileFilter

use of java.io.FileFilter in project jackrabbit by apache.

the class LocalFileSystem method listFiles.

/**
     * {@inheritDoc}
     */
public String[] listFiles(String folderPath) throws FileSystemException {
    File folder = new File(root, osPath(folderPath));
    File[] files = folder.listFiles(new FileFilter() {

        public boolean accept(File f) {
            return f.isFile();
        }
    });
    if (files == null) {
        String msg = folderPath + " does not denote a folder";
        log.debug(msg);
        throw new FileSystemException(msg);
    }
    String[] entries = new String[files.length];
    for (int i = 0; i < files.length; i++) {
        entries[i] = files[i].getName();
    }
    return entries;
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) FileFilter(java.io.FileFilter) File(java.io.File)

Aggregations

FileFilter (java.io.FileFilter)281 File (java.io.File)267 ArrayList (java.util.ArrayList)59 IOException (java.io.IOException)53 JarFile (java.util.jar.JarFile)22 URL (java.net.URL)17 Test (org.junit.Test)16 HashMap (java.util.HashMap)15 FileNotFoundException (java.io.FileNotFoundException)11 FilenameFilter (java.io.FilenameFilter)11 HashSet (java.util.HashSet)11 FileInputStream (java.io.FileInputStream)10 Pattern (java.util.regex.Pattern)10 WildcardFileFilter (org.apache.commons.io.filefilter.WildcardFileFilter)10 MalformedURLException (java.net.MalformedURLException)9 URI (java.net.URI)9 Map (java.util.Map)7 Path (org.apache.hadoop.fs.Path)7 NotNull (org.jetbrains.annotations.NotNull)7 Treebank (edu.stanford.nlp.trees.Treebank)6