org.apache.commons.io.comparator.PathFileComparator Java Examples
The following examples show how to use
org.apache.commons.io.comparator.PathFileComparator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultGenerator.java From openapi-generator with Apache License 2.0 | 5 votes |
/** * Generates a file at .openapi-generator/FILES to track the files created by the user's latest run. * This is ideal for CI and regeneration of code without stale/unused files from older generations. * * @param files The list tracking generated files */ private void generateFilesMetadata(List<File> files) { if (generateMetadata) { try { StringBuilder sb = new StringBuilder(); File outDir = new File(this.config.getOutputDir()); List<File> filesToSort = new ArrayList<>(); // Avoid side-effecting sort in this path when generateMetadata=true files.forEach(f -> { // We have seen NPE on CI for getPath() returning null, so guard against this (to be fixed in 5.0 template management refactor) //noinspection ConstantConditions if (f != null && f.getPath() != null) { filesToSort.add(f); } }); filesToSort.sort(PathFileComparator.PATH_COMPARATOR); filesToSort.forEach(f -> { String relativePath = outDir.toPath().relativize(f.toPath()).toString(); if (!relativePath.equals(METADATA_DIR + File.separator + "VERSION")) { sb.append(relativePath).append(System.lineSeparator()); } }); String targetFile = config.outputFolder() + File.separator + METADATA_DIR + File.separator + "FILES"; File filesFile = this.templateProcessor.writeToFile(targetFile, sb.toString().getBytes(StandardCharsets.UTF_8)); if (filesFile != null) { files.add(filesFile); } } catch (Exception e) { LOGGER.warn("Failed to write FILES metadata to track generated files."); } } }
Example #2
Source File: CommonsIOUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void whenSortDirWithPathFileComparator_thenFirstFileaaatxt() throws IOException { PathFileComparator pathFileComparator = new PathFileComparator(IOCase.INSENSITIVE); String path = FilenameUtils.getFullPath(getClass().getClassLoader().getResource("fileTest.txt").getPath()); File dir = new File(path); File[] files = dir.listFiles(); pathFileComparator.sort(files); Assert.assertEquals("aaa.txt", files[0].getName()); }
Example #3
Source File: SystemHelper.java From azure-devops-intellij with MIT License | 2 votes |
/** * Compares to file paths to see if they are the same based on the OS that is being used * * @param path1 * @param path2 * @return */ public static boolean areFilePathsSame(final String path1, final String path2) { return PathFileComparator.PATH_SYSTEM_COMPARATOR.compare(new File(path1), new File(path2)) == 0 ? true : false; }