Example usage for org.apache.commons.io.filefilter NameFileFilter NameFileFilter

List of usage examples for org.apache.commons.io.filefilter NameFileFilter NameFileFilter

Introduction

In this page you can find the example usage for org.apache.commons.io.filefilter NameFileFilter NameFileFilter.

Prototype

public NameFileFilter(List names) 

Source Link

Document

Constructs a new case-sensitive name file filter for a list of names.

Usage

From source file:com.silverpeas.admin.components.Instanciateur.java

static String getDescriptorFullPath(String componentName) throws IOException {
    IOFileFilter filter = new NameFileFilter(componentName + ".xml");
    List<File> list = new ArrayList<File>(
            FileUtils.listFiles(new File(xmlPackage), filter, TrueFileFilter.INSTANCE));
    if (!list.isEmpty()) {
        return list.get(0).getCanonicalPath();
    }/*from  ww  w.ja v a2  s. c o m*/
    return new File(xmlPackage, componentName + ".xml").getCanonicalPath();
}

From source file:gov.va.vinci.leo.descriptors.LeoTypeSystemDescription.java

/**
 * Generate the .java files for the types in this TypeSystem then compile them into byte code
 * to the bin directory specified./*  w  ww  . j a  va2  s.  c om*/
 *
 * @param srcDirectory Path to the root source directory where the .java files will be generated, including package names
 * @param binDirectory Bin directory where .class files will be generated.
 * @throws Exception If there is no type system or there is an error generating the .java files
 */
public void jCasGen(String srcDirectory, String binDirectory) throws Exception {
    //If there is no type system throw an Exception
    if (this.myTypeSystemDescription == null) {
        throw new Exception("Cannot generate a null TypeSystem");
    } //if

    //Throw and exception if we are missing one of our parameters
    if (StringUtils.isBlank(srcDirectory) || StringUtils.isBlank(binDirectory)) {
        throw new Exception("Both the source directory and bin directory are required arguments");
    } //if

    //Generate the TypeSystemDescription xml
    this.toXML(this.mDescriptorLocator);

    //Get the classpath
    String classpath = System.getProperty("java.class.path");

    //Create an instance of the Jg class and call the "main" method to generate the java files
    String[] args = { "-jcasgeninput", this.mDescriptorLocator.trim(), "-jcasgenoutput", srcDirectory,
            "=jcasgenclasspath", classpath };
    Jg jcasGen = new Jg();
    int ret = jcasGen.main1(args);
    if (ret == -1) {
        //Error generating the java files
        throw new Exception("Error occurred generating the Java source files");
    } //if

    List<String> fileNames = new ArrayList<String>();
    for (TypeDescription td : getTypes()) {
        String name = td.getName().substring(td.getName().lastIndexOf('.') + 1, td.getName().length());
        fileNames.add(name + ".java");
        fileNames.add(name + "_Type.java");
    } //for

    NameFileFilter fnf = new NameFileFilter(fileNames);
    List<File> javaSrcFiles = LeoUtils.listFiles(new File(srcDirectory), fnf, true);
    if (javaSrcFiles == null) {
        log.warn("No Java Source files found to compile in jCasGen");
        return;
    } //if

    //Iterate through the list of java files and compile them all
    try {
        AutoCompile.compileFiles(javaSrcFiles.toArray(new File[0]), binDirectory);
    } catch (Exception e) {
        log.warn("Exception Thrown compiling files in test", e);
    }
}

From source file:com.revetkn.ios.analyzer.ArtworkAnalyzer.java

/** @return All image files in the project. */
protected SortedSet<File> extractAllImageFiles(File projectRootDirectory) {
    SortedSet<File> allImageFiles = new TreeSet<File>();

    for (File pngFile : listFiles(projectRootDirectory,
            new SuffixFileFilter(new ArrayList<String>(imageFileSuffixes())),
            new NotFileFilter(new NameFileFilter(new ArrayList<String>(ignoredDirectoryNames())))))
        allImageFiles.add(pngFile);//from   www.ja  v a2 s.c o m

    return allImageFiles;
}

From source file:com.github.mjdetullio.jenkins.plugins.multibranch.AbstractMultiBranchProject.java

/**
 * Migrates <code>SyncBranchesTrigger</code> to {@link hudson.triggers.TimerTrigger} and copies the
 * template's {@link hudson.security.AuthorizationMatrixProperty} to the parent as a
 * {@link com.cloudbees.hudson.plugins.folder.properties.AuthorizationMatrixProperty}.
 *///from w w w.  ja va2  s  .com
@SuppressWarnings(UNUSED)
@Initializer(before = InitMilestone.PLUGINS_STARTED)
public static void migrate() throws IOException {
    final String projectAmpStartTag = "<hudson.security.AuthorizationMatrixProperty>";

    final File projectsDir = new File(Jenkins.getActiveInstance().getRootDir(), "jobs");

    if (!projectsDir.getCanonicalFile().isDirectory()) {
        return;
    }

    Collection<File> configFiles = FileUtils.listFiles(projectsDir, new NameFileFilter("config.xml"),
            TrueFileFilter.TRUE);

    for (final File configFile : configFiles) {
        String xml = FileUtils.readFileToString(configFile);

        // Rename and wrap trigger open tag
        xml = xml.replaceFirst("(?m)^  <syncBranchesTrigger>(\r?\n)    <spec>",
                "  <triggers>\n    <hudson.triggers.TimerTrigger>\n      <spec>");

        // Rename and wrap trigger close tag
        xml = xml.replaceFirst("(?m)^  </syncBranchesTrigger>",
                "    </hudson.triggers.TimerTrigger>\n  </triggers>");

        // Copy AMP from template if parent does not have a properties tag
        if (!xml.matches("(?ms).+(\r?\n)  <properties.+")
                // Long line is long
                && xml.matches(
                        "(?ms).*<((freestyle|maven)-multi-branch-project|com\\.github\\.mjdetullio\\.jenkins\\.plugins\\.multibranch\\.(FreeStyle|Maven)MultiBranchProject)( plugin=\".*?\")?.+")) {

            File templateConfigFile = new File(new File(configFile.getParentFile(), TEMPLATE), "config.xml");

            if (templateConfigFile.isFile()) {
                String templateXml = FileUtils.readFileToString(templateConfigFile);

                int start = templateXml.indexOf(projectAmpStartTag);
                int end = templateXml.indexOf("</hudson.security.AuthorizationMatrixProperty>");

                if (start != -1 && end != -1) {
                    String ampSettings = templateXml.substring(start + projectAmpStartTag.length(), end);

                    xml = xml.replaceFirst("(?m)^  ", "  <properties>\n    "
                            + "<com.cloudbees.hudson.plugins.folder.properties.AuthorizationMatrixProperty>"
                            + ampSettings
                            + "</com.cloudbees.hudson.plugins.folder.properties.AuthorizationMatrixProperty>"
                            + "\n  </properties>\n  ");
                }
            }
        }

        FileUtils.writeStringToFile(configFile, xml);
    }
}

From source file:net.sourceforge.vulcan.git.GitRepository.java

@Override
public void createPristineWorkingCopy(BuildDetailCallback buildDetailCallback)
        throws RepositoryException, InterruptedException {
    if (globals.isPurgeEnabled()) {
        buildDetailCallback.setDetailMessage("hg.activity.update", null);
        tryInvoke(Command.update, "--clean", getSelectedBranch());

        buildDetailCallback.setDetailMessage("hg.activity.purge", null);
        tryInvoke(Command.purge, "--all", "--config", "extensions.purge=");
    } else {/*w  w  w . j  av  a 2 s .  c  o m*/
        buildDetailCallback.setDetailMessage("hg.activity.remove.working.copy", null);
        tryInvoke(Command.update, "--clean", "null");

        buildDetailCallback.setDetailMessage("hg.activity.purge", null);

        try {
            fileSystem.cleanDirectory(getLocalRepositoryPath(), new NameFileFilter(".hg"));
        } catch (IOException e) {
            throw new RepositoryException("hg.errors.delete.files", e);
        }

        buildDetailCallback.setDetailMessage("hg.activity.update", null);
        tryInvoke(Command.update, getSelectedBranch());
    }
}

From source file:net.sourceforge.vulcan.git.MercurialRepository.java

public void createPristineWorkingCopy(BuildDetailCallback buildDetailCallback)
        throws RepositoryException, InterruptedException {
    if (globals.isPurgeEnabled()) {
        buildDetailCallback.setDetailMessage("hg.activity.update", null);
        tryInvoke(Command.update, "--clean", getSelectedBranch());

        buildDetailCallback.setDetailMessage("hg.activity.purge", null);
        tryInvoke(Command.purge, "--all", "--config", "extensions.purge=");
    } else {/* www.jav  a 2s.com*/
        buildDetailCallback.setDetailMessage("hg.activity.remove.working.copy", null);
        tryInvoke(Command.update, "--clean", "null");

        buildDetailCallback.setDetailMessage("hg.activity.purge", null);

        try {
            fileSystem.cleanDirectory(getLocalRepositoryPath(), new NameFileFilter(".hg"));
        } catch (IOException e) {
            throw new RepositoryException("hg.errors.delete.files", e);
        }

        buildDetailCallback.setDetailMessage("hg.activity.update", null);
        tryInvoke(Command.update, getSelectedBranch());
    }
}

From source file:nl.armatiek.xslweb.configuration.Context.java

private void initWebApps() throws Exception {
    File webAppsDir = new File(homeDir, "webapps");
    File[] dirs = webAppsDir.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY);
    for (File dir : dirs) {
        File[] webAppFiles = dir.listFiles((FilenameFilter) new NameFileFilter("webapp.xml"));
        if (webAppFiles.length == 0) {
            continue;
        }// ww w .ja  va  2 s.c o m
        File file = webAppFiles[0];
        try {
            WebApp webApp = new WebApp(webAppFiles[0]);
            webApps.put(webApp.getName(), webApp);
            webApp.open();
        } catch (Exception e) {
            logger.error(String.format("Error creating webapp \"%s\"", file.getAbsolutePath()), e);
        }
    }
}

From source file:org.ado.minesync.minecraft.MinecraftData.java

private long getWorldsModificationDate(File worldDirectory) {
    Collection<File> files = FileUtils.listFiles(worldDirectory, new NameFileFilter(FILE_LEVEL_DAT),
            FalseFileFilter.FALSE);//from   www  . ja  v  a  2  s .c  o  m
    if (files != null && files.size() == 1) {
        ALog.v(TAG, "using modification date from file " + FILE_LEVEL_DAT);
        return files.iterator().next().lastModified();
    } else {
        ALog.v(TAG, "using modification date from world directory");
        return worldDirectory.lastModified();
    }
}

From source file:org.apache.fop.fotreetest.FOTreeTestSuite.java

private static void addXMLTestCases(TestSuite suite) throws IOException {
    File mainDir = new File("test/fotree");

    final FOTreeTester tester = new FOTreeTester();

    IOFileFilter filter;//from w w w.j  a va  2  s  . c  o m
    String single = System.getProperty("fop.fotree.single");
    String startsWith = System.getProperty("fop.fotree.starts-with");
    if (single != null) {
        filter = new NameFileFilter(single);
    } else if (startsWith != null) {
        filter = new PrefixFileFilter(startsWith);
        filter = new AndFileFilter(filter, new SuffixFileFilter(".fo"));
    } else {
        filter = new SuffixFileFilter(".fo");
        filter = LayoutEngineTestSuite.decorateWithDisabledList(filter);
    }
    Collection files = FileUtils.listFiles(new File(mainDir, "testcases"), filter, TrueFileFilter.INSTANCE);
    String privateTests = System.getProperty("fop.fotree.private");
    if ("true".equalsIgnoreCase(privateTests)) {
        Collection privateFiles = FileUtils.listFiles(new File(mainDir, "private-testcases"), filter,
                TrueFileFilter.INSTANCE);
        files.addAll(privateFiles);
    }
    Iterator i = files.iterator();
    while (i.hasNext()) {
        File f = (File) i.next();
        addTestCase(suite, tester, f);
    }
}

From source file:org.apache.fop.layoutengine.LayoutEngineTestSuite.java

public static IOFileFilter decorateWithDisabledList(IOFileFilter filter) throws IOException {
    String disabled = System.getProperty("fop.layoutengine.disabled");
    if (disabled != null && disabled.length() > 0) {
        filter = new AndFileFilter(
                new NotFileFilter(new NameFileFilter(readDisabledTestcases(new File(disabled)))), filter);
    }// w  w w  . j a  v a  2s  . c o  m
    return filter;
}