@Test public void testGetResourceFileList() { RuntimeEnvironment env = RuntimeEnvironment.getInstance(); String oldSourceRootPath = env.getSourceRootPath(); AuthorizationFramework oldAuthorizationFramework = env.getAuthorizationFramework(); Map<String, Project> oldProjects = env.getProjects(); env.setSourceRoot(repository.getSourceRoot()); env.setProjectsEnabled(true); for (String file : new File(repository.getSourceRoot()).list()) { Project proj = new Project(file); proj.setIndexed(true); env.getProjects().put(file, proj); } HttpServletRequest req = createRequest("/source", "/xref", ""); PageConfig cfg = PageConfig.get(req); List<String> allFiles = new ArrayList<>(cfg.getResourceFileList()); assertTrue(allFiles.size() > 5); assertTrue(allFiles.contains("git")); assertTrue(allFiles.contains("mercurial")); env.setAuthorizationFramework(new AuthorizationFramework()); env.getAuthorizationFramework().reload(); env.getAuthorizationFramework().getStack() .add(new AuthorizationPlugin(AuthControlFlag.REQUIRED, new TestPlugin() { @Override public boolean isAllowed(HttpServletRequest request, Project project) { return !project.getName().startsWith("git") && !project.getName().startsWith("mercurial"); } })); req = createRequest("/source", "/xref", ""); cfg = PageConfig.get(req); List<String> filteredFiles = new ArrayList<>(cfg.getResourceFileList()); allFiles.removeAll(filteredFiles); assertEquals(2, allFiles.size()); assertTrue(allFiles.contains("git")); assertTrue(allFiles.contains("mercurial")); env.setAuthorizationFramework(oldAuthorizationFramework); env.setSourceRoot(oldSourceRootPath); env.setProjects(oldProjects); }
public List<String> getResourceFileList() { if (dirFileList == null) { File[] files = null; if (isDir() && getResourcePath().length() > 1) { files = getResourceFile().listFiles(); } if (files == null) { dirFileList = Collections.emptyList(); } else { List<String> listOfFiles; if (env.getListDirsFirst()) { Arrays.sort(files, new Comparator<File>() { @Override public int compare(File f1, File f2) { if (f1.isDirectory() && f2.isDirectory()) { return f1.getName().compareTo(f2.getName()); } else if (f1.isFile() && f2.isFile()) { return f1.getName().compareTo(f2.getName()); } else { if (f1.isFile() && f2.isDirectory()) { return 1; } else { return -1; } } } }); } else { Arrays.sort(files, (File f1, File f2) -> f1.getName().compareTo(f2.getName())); } listOfFiles = Arrays.asList(files).stream(). map(f -> f.getName()).collect(Collectors.toList()); if (env.hasProjects() && getPath().isEmpty()) { List<String> modifiableListOfFiles = new ArrayList<>(listOfFiles); modifiableListOfFiles.removeIf((t) -> { return !getProjectHelper().getAllProjects().stream().anyMatch((p) -> { return p.getName().equalsIgnoreCase(t); }); }); return dirFileList = Collections.unmodifiableList(modifiableListOfFiles); } dirFileList = Collections.unmodifiableList(listOfFiles); } } return dirFileList; }
PageConfig { public List<String> getResourceFileList() { if (dirFileList == null) { File[] files = null; if (isDir() && getResourcePath().length() > 1) { files = getResourceFile().listFiles(); } if (files == null) { dirFileList = Collections.emptyList(); } else { List<String> listOfFiles; if (env.getListDirsFirst()) { Arrays.sort(files, new Comparator<File>() { @Override public int compare(File f1, File f2) { if (f1.isDirectory() && f2.isDirectory()) { return f1.getName().compareTo(f2.getName()); } else if (f1.isFile() && f2.isFile()) { return f1.getName().compareTo(f2.getName()); } else { if (f1.isFile() && f2.isDirectory()) { return 1; } else { return -1; } } } }); } else { Arrays.sort(files, (File f1, File f2) -> f1.getName().compareTo(f2.getName())); } listOfFiles = Arrays.asList(files).stream(). map(f -> f.getName()).collect(Collectors.toList()); if (env.hasProjects() && getPath().isEmpty()) { List<String> modifiableListOfFiles = new ArrayList<>(listOfFiles); modifiableListOfFiles.removeIf((t) -> { return !getProjectHelper().getAllProjects().stream().anyMatch((p) -> { return p.getName().equalsIgnoreCase(t); }); }); return dirFileList = Collections.unmodifiableList(modifiableListOfFiles); } dirFileList = Collections.unmodifiableList(listOfFiles); } } return dirFileList; } }
PageConfig { public List<String> getResourceFileList() { if (dirFileList == null) { File[] files = null; if (isDir() && getResourcePath().length() > 1) { files = getResourceFile().listFiles(); } if (files == null) { dirFileList = Collections.emptyList(); } else { List<String> listOfFiles; if (env.getListDirsFirst()) { Arrays.sort(files, new Comparator<File>() { @Override public int compare(File f1, File f2) { if (f1.isDirectory() && f2.isDirectory()) { return f1.getName().compareTo(f2.getName()); } else if (f1.isFile() && f2.isFile()) { return f1.getName().compareTo(f2.getName()); } else { if (f1.isFile() && f2.isDirectory()) { return 1; } else { return -1; } } } }); } else { Arrays.sort(files, (File f1, File f2) -> f1.getName().compareTo(f2.getName())); } listOfFiles = Arrays.asList(files).stream(). map(f -> f.getName()).collect(Collectors.toList()); if (env.hasProjects() && getPath().isEmpty()) { List<String> modifiableListOfFiles = new ArrayList<>(listOfFiles); modifiableListOfFiles.removeIf((t) -> { return !getProjectHelper().getAllProjects().stream().anyMatch((p) -> { return p.getName().equalsIgnoreCase(t); }); }); return dirFileList = Collections.unmodifiableList(modifiableListOfFiles); } dirFileList = Collections.unmodifiableList(listOfFiles); } } return dirFileList; } private  PageConfig(HttpServletRequest req); }
PageConfig { public List<String> getResourceFileList() { if (dirFileList == null) { File[] files = null; if (isDir() && getResourcePath().length() > 1) { files = getResourceFile().listFiles(); } if (files == null) { dirFileList = Collections.emptyList(); } else { List<String> listOfFiles; if (env.getListDirsFirst()) { Arrays.sort(files, new Comparator<File>() { @Override public int compare(File f1, File f2) { if (f1.isDirectory() && f2.isDirectory()) { return f1.getName().compareTo(f2.getName()); } else if (f1.isFile() && f2.isFile()) { return f1.getName().compareTo(f2.getName()); } else { if (f1.isFile() && f2.isDirectory()) { return 1; } else { return -1; } } } }); } else { Arrays.sort(files, (File f1, File f2) -> f1.getName().compareTo(f2.getName())); } listOfFiles = Arrays.asList(files).stream(). map(f -> f.getName()).collect(Collectors.toList()); if (env.hasProjects() && getPath().isEmpty()) { List<String> modifiableListOfFiles = new ArrayList<>(listOfFiles); modifiableListOfFiles.removeIf((t) -> { return !getProjectHelper().getAllProjects().stream().anyMatch((p) -> { return p.getName().equalsIgnoreCase(t); }); }); return dirFileList = Collections.unmodifiableList(modifiableListOfFiles); } dirFileList = Collections.unmodifiableList(listOfFiles); } } return dirFileList; } private  PageConfig(HttpServletRequest req); void setRequestAttribute(String attr, Object val); Object getRequestAttribute(String attr); void removeAttribute(String string); void addHeaderData(String data); String getHeaderData(); DiffData getDiffData(); DiffType getDiffType(); boolean fullDiff(); String canProcess(); List<String> getResourceFileList(); long getLastModified(); String getHistoryDirs(); int getIntParam(String name, int defaultValue); int getSearchStart(); int getSearchMaxItems(); int getRevisionMessageCollapseThreshold(); int getCurrentIndexedCollapseThreshold(); int getGroupsCollapseThreshold(); List<SortOrder> getSortOrder(); QueryBuilder getQueryBuilder(); EftarFileReader getEftarReader(); String getDefineTagsIndex(); String getRequestedRevision(); boolean hasHistory(); boolean hasAnnotations(); boolean annotate(); Annotation getAnnotation(); String[] getSearchOnlyIn(); Project getProject(); String getRequestedProjectsAsString(); SortedSet<String> getRequestedProjects(); List<String> getCookieVals(String cookieName); ProjectHelper getProjectHelper(); void setTitle(String title); String getTitle(); String getCssDir(); RuntimeEnvironment getEnv(); IgnoredNames getIgnoredNames(); String getSourceRootPath(); Prefix getPrefix(); String getPath(); File getResourceFile(String path); File getResourceFile(); String getResourcePath(); boolean resourceNotAvailable(); boolean isDir(); File[] findDataFiles(List<String> filenames); File findDataFile(); String getLatestRevision(); boolean isLatestRevision(String rev); String getRevisionLocation(String revStr); String getDirectoryRedirect(); String getUriEncodedPath(); PageConfig addScript(String name); Scripts getScripts(); File getDataRoot(); SearchHelper prepareSearch(); SearchHelper prepareInternalSearch(); static PageConfig get(HttpServletRequest request); static void cleanup(ServletRequest sr); boolean isAllowed(Project t); boolean isAllowed(Group g); SortedSet<AcceptedMessage> getMessages(); SortedSet<AcceptedMessage> getMessages(String tag); String getShortPath(String path); String getSearchTitle(); String getHistoryTitle(); String getPathTitle(); void checkSourceRootExistence(); boolean isNotModified(HttpServletRequest request, HttpServletResponse response); static String getRelativePath(String root, String path); boolean evaluateMatchOffset(); }
PageConfig { public List<String> getResourceFileList() { if (dirFileList == null) { File[] files = null; if (isDir() && getResourcePath().length() > 1) { files = getResourceFile().listFiles(); } if (files == null) { dirFileList = Collections.emptyList(); } else { List<String> listOfFiles; if (env.getListDirsFirst()) { Arrays.sort(files, new Comparator<File>() { @Override public int compare(File f1, File f2) { if (f1.isDirectory() && f2.isDirectory()) { return f1.getName().compareTo(f2.getName()); } else if (f1.isFile() && f2.isFile()) { return f1.getName().compareTo(f2.getName()); } else { if (f1.isFile() && f2.isDirectory()) { return 1; } else { return -1; } } } }); } else { Arrays.sort(files, (File f1, File f2) -> f1.getName().compareTo(f2.getName())); } listOfFiles = Arrays.asList(files).stream(). map(f -> f.getName()).collect(Collectors.toList()); if (env.hasProjects() && getPath().isEmpty()) { List<String> modifiableListOfFiles = new ArrayList<>(listOfFiles); modifiableListOfFiles.removeIf((t) -> { return !getProjectHelper().getAllProjects().stream().anyMatch((p) -> { return p.getName().equalsIgnoreCase(t); }); }); return dirFileList = Collections.unmodifiableList(modifiableListOfFiles); } dirFileList = Collections.unmodifiableList(listOfFiles); } } return dirFileList; } private  PageConfig(HttpServletRequest req); void setRequestAttribute(String attr, Object val); Object getRequestAttribute(String attr); void removeAttribute(String string); void addHeaderData(String data); String getHeaderData(); DiffData getDiffData(); DiffType getDiffType(); boolean fullDiff(); String canProcess(); List<String> getResourceFileList(); long getLastModified(); String getHistoryDirs(); int getIntParam(String name, int defaultValue); int getSearchStart(); int getSearchMaxItems(); int getRevisionMessageCollapseThreshold(); int getCurrentIndexedCollapseThreshold(); int getGroupsCollapseThreshold(); List<SortOrder> getSortOrder(); QueryBuilder getQueryBuilder(); EftarFileReader getEftarReader(); String getDefineTagsIndex(); String getRequestedRevision(); boolean hasHistory(); boolean hasAnnotations(); boolean annotate(); Annotation getAnnotation(); String[] getSearchOnlyIn(); Project getProject(); String getRequestedProjectsAsString(); SortedSet<String> getRequestedProjects(); List<String> getCookieVals(String cookieName); ProjectHelper getProjectHelper(); void setTitle(String title); String getTitle(); String getCssDir(); RuntimeEnvironment getEnv(); IgnoredNames getIgnoredNames(); String getSourceRootPath(); Prefix getPrefix(); String getPath(); File getResourceFile(String path); File getResourceFile(); String getResourcePath(); boolean resourceNotAvailable(); boolean isDir(); File[] findDataFiles(List<String> filenames); File findDataFile(); String getLatestRevision(); boolean isLatestRevision(String rev); String getRevisionLocation(String revStr); String getDirectoryRedirect(); String getUriEncodedPath(); PageConfig addScript(String name); Scripts getScripts(); File getDataRoot(); SearchHelper prepareSearch(); SearchHelper prepareInternalSearch(); static PageConfig get(HttpServletRequest request); static void cleanup(ServletRequest sr); boolean isAllowed(Project t); boolean isAllowed(Group g); SortedSet<AcceptedMessage> getMessages(); SortedSet<AcceptedMessage> getMessages(String tag); String getShortPath(String path); String getSearchTitle(); String getHistoryTitle(); String getPathTitle(); void checkSourceRootExistence(); boolean isNotModified(HttpServletRequest request, HttpServletResponse response); static String getRelativePath(String root, String path); boolean evaluateMatchOffset(); static final String OPEN_GROK_PROJECT; }