@Test public void shouldLogJSErrors() throws IOException { driverChrome.get(httpServer.url("/form.html")); try { ((JavascriptExecutor) driverChrome).executeScript("NOT_FOUND();"); fail("should fail"); } catch (WebDriverException e) { // ok } File[] files = tempFolder.listFiles((FileFilter) new AbstractFileFilter() { @Override public boolean accept(File file) { return file.getName().endsWith(".log"); } }); assertThat(files.length).isEqualTo(1); String contentOfLogFile = FileUtils.readFileToString(files[0], Charset.defaultCharset()); assertThat(contentOfLogFile).contains("unknown error: NOT_FOUND is not defined"); }
/** * This method is called during initialization, and does nothing by default. Subclasses should override it to perform one-time startup logic. */ @Override public void initialize() throws ResourceInitializationException { super.initialize(); mInDir = new File(inputDirectoryPath); if(mInDir == null || !mInDir.exists() || !mInDir.isDirectory()) throw new ResourceInitializationException("Input Directory does not exist or is not a directory!", null); if(StringUtils.isNotBlank(fileNameFilterJSON) && StringUtils.isNotBlank(fileNameFilterName)) { try { Class<?> filterClass = Class.forName(fileNameFilterName); filenameFilter = new Gson().fromJson(fileNameFilterJSON, (Class<? extends AbstractFileFilter>) filterClass); } catch (ClassNotFoundException e) { throw new ResourceInitializationException(e); } } findFiles(mInDir); mFileIndex = 0; }
@Bean public IOFileFilter expectedRootFilesFilter() { final String validatedRepositoryAbsolutePath = validatorContext().getValidatedRepository().getAbsolutePath(); final String[] expectedRootFiles = expectedRootFiles(); IOFileFilter expectedRootFileFilter = new AbstractFileFilter() { @Override public boolean accept(File dir, String name) { if (dir.getAbsolutePath().equals(validatedRepositoryAbsolutePath) && ArrayUtils.contains(expectedRootFiles, name.toLowerCase())) { return true; } return false; } }; return expectedRootFileFilter; }
private static String[] tileFilenames(File directory) { return directory.list(new AbstractFileFilter() { @Override public boolean accept(File dir, String name) { return name.matches("\\d*"); } }); }
/** * Returns a collection of traffic entry log files which are relevant to the given time window * * @param startDate Time window start date * @param endDate Time window end date * @return Collection<File> - Collection of file objects that represent the traffic entry log files which are * relevant to the given time window */ public Collection<File> readFiles(Date startDate, Date endDate) { IOFileFilter trafficLogFileFilter = new AbstractFileFilter() { @Override public boolean accept(File file) { String logFileName = file.getName(); return logFileName.contains(LOG_PREFIX) && logFileName.contains(LOG_SUFFIX); } }; Collection<File> collection = FileUtils.listFiles(logDir, trafficLogFileFilter, DirectoryFileFilter.DIRECTORY); List<File> trafficLogFiles = Lists.newArrayList(collection); Collections.sort(trafficLogFiles); List<File> selectedFiles = new ArrayList<>(); for (File logFile : trafficLogFiles) { Date[] logFileDates = getLogFileDates(logFile); //Sanity check if (logFileDates.length != 2) { throw new RuntimeException("Could not read log file dates."); } //Sanity check Date logFileStartDate = logFileDates[0]; Date logFileEndDate = logFileDates[1]; if ((logFileStartDate == null) || (logFileEndDate == null)) { throw new RuntimeException("Log file dates cannot be null."); } boolean withinRange = isDateWithinRange(logFileStartDate, logFileEndDate, startDate, endDate); if (withinRange) { selectedFiles.add(logFile); } } return selectedFiles; }
private void readWorkflowsFromDisk(String workflowsDir) { File wfDir = new File(workflowsDir); workflow = new ArrayList<String>(); if (wfDir.exists() && wfDir.canRead()) { //get file names IOFileFilter workflowFileFilter = new AbstractFileFilter() { @Override public boolean accept(File file) { try { if (LeroyUtils.isWorkflow(file)) { return true; } } catch (Throwable t) { t.printStackTrace(); } return false; } }; Iterator<File> fileIterator = FileUtils.iterateFiles(new File(workflowsDir), workflowFileFilter, TrueFileFilter.INSTANCE); if (fileIterator != null) { URI workFlowsBase = new File(workflowsDir).toURI(); while (fileIterator.hasNext()) { // get relative path using workflow folder as a base and remove extension File wf = fileIterator.next(); String relative = workFlowsBase.relativize(wf.toURI()).getPath(); String wfName = relative.substring(0, relative.lastIndexOf('.')); workflow.add(wfName); } } } }
/** * Checks if a file having somewhat the current tested application name is contained in the given directory. This * method follows the default maven semantic. The final file is expected to have a name compliant with the * following rules: <code>artifactId-version.jar</code>. If the version ends with <code>-SNAPSHOT</code>, * it just checks for <code>artifactId-stripped_version</code>, where stripped version is the version without the * <code>SNAPSHOT</code> part. * <p> * The artifactId and version are read from the <code>target/osgi/osgi.properties</code> file, * that should have been written by the Wisdom build process. * * @param directory the directory * @return the bundle file if found * @throws java.io.IOException if something bad happens. */ public static File detectApplicationBundleIfExist(File directory) throws IOException { Properties properties = getMavenProperties(); if (properties == null || directory == null || !directory.isDirectory()) { return null; } final String artifactId = properties.getProperty("project.artifactId"); final String groupId = properties.getProperty("project.groupId"); final String bsn = getBundleSymbolicName(groupId, artifactId); String version = properties.getProperty("project.version"); final String strippedVersion; if (version.endsWith("-SNAPSHOT")) { strippedVersion = version.substring(0, version.length() - "-SNAPSHOT".length()); } else { strippedVersion = version; } Iterator<File> files = FileUtils.iterateFiles(directory, new AbstractFileFilter() { @Override public boolean accept(File file) { return file.isFile() && file.getName().startsWith(bsn + "-" + strippedVersion) && file.getName().endsWith(".jar"); } }, TrueFileFilter.INSTANCE); if (files.hasNext()) { return files.next(); } return null; }
@Override public void importFrom(ImportSettings settings) { final MutableStatusHolder multiStatusHolder = settings.getStatusHolder(); multiStatusHolder.status("Starting build info import", log); dbService.invokeInTransaction("BuildImport-deleteAllBuilds", new Callable<Object>() { @Override public Object call() throws Exception { try { // delete all existing builds buildStoreService.deleteAllBuilds(); } catch (Exception e) { multiStatusHolder.error("Failed to delete builds root node", e, log); } return null; } }); File buildsFolder = new File(settings.getBaseDir(), BUILDS_EXPORT_DIR); String buildsFolderPath = buildsFolder.getPath(); if (!buildsFolder.exists()) { multiStatusHolder.status("'" + buildsFolderPath + "' folder is either non-existent or not a " + "directory. Build info import was not performed", log); return; } IOFileFilter buildExportFileFilter = new AbstractFileFilter() { @Override public boolean accept(File file) { String fileName = file.getName(); return fileName.startsWith("build") && fileName.endsWith(".xml"); } }; Collection<File> buildExportFiles = FileUtils.listFiles(buildsFolder, buildExportFileFilter, DirectoryFileFilter.DIRECTORY); if (buildExportFiles.isEmpty()) { multiStatusHolder.status("'" + buildsFolderPath + "' folder does not contain build export files. " + "Build info import was not performed", log); return; } importBuildFiles(settings, buildExportFiles); multiStatusHolder.status("Finished build info import", log); }
@Override public AbstractFileFilter modelledFilesFilter() { return tokenizer.getFileFilter(); }
@Override public AbstractFileFilter modelledFilesFilter() { return getTokenizer().getFileFilter(); }
@Override public AbstractFileFilter modelledFilesFilter() { return baseNgram.modelledFilesFilter(); }
@Override public AbstractFileFilter getFileFilter() { return baseTokenizer.getFileFilter(); }
@Override public AbstractFileFilter getFileFilter() { return javaCodeFiler; }
@Override public AbstractFileFilter getFileFilter() { return javaCodeFilter; }
@Override public AbstractFileFilter getFileFilter() { final TokenizerImplementation tok = new TokenizerImplementation(); return tok.getFileFilter(); }
@Override public AbstractFileFilter getFileFilter() { return javaCodeFileFilter; }
@Override public AbstractFileFilter getFileFilter() { return codeFilter; }
@Override public AbstractFileFilter getFileFilter() { return C_CODE_TOKENIZER; }
@Override public AbstractFileFilter getFileFilter() { return CPP_CODE_FILTER; }
@Override public AbstractFileFilter getFileFilter() { return pythonCodeFilter; }
@Override public AbstractFileFilter getFileFilter() { return JAVASCRIPT_CODE_FILTER; }