Find a single main class from a given folder.

@param rootFolder the root folder to search
@return the main class or {@code null}
@throws IOException if the folder cannot be read
18699
public static String findSingleMainClass(File rootFolder) throws IOException {
        MainClassesCallback callback = new MainClassesCallback();
        MainClassFinder.doWithMainClasses(rootFolder, callback);
        return callback.getMainClass();
    }
603230
public Reader getReader() throws IOException {
        if (stream != null) {
            Reader reader = new InputStreamReader(stream, configuration.getSourceEncoding());
            stream = null;
            return reader;
        }
        return null;
    }
833629
@Nullable
  public static File findFile(@Nullable final Class<?> clazz) {
    if (null == clazz) return null;
    String name = clazz.getName();
    if (null == name) return null;
    final String path = name.replaceAll("\\.", "/").replaceAll("\\$.*", "");
    return com.simiacryptus.util.lang.CodeUtil.findFile(path + ".java");
  }
912933
def get_parent_folder(self):
        
        if self.root:
            return None
        if self.parent:
            return self.parent

        if self.parent_id:
            self.parent = self.get_folder(folder_id=self.parent_id)
        return self.parent
360575
public static List<String> listClassnames(final File parentDirectory,
                                            final List<File> classFileList) throws IOException {
    if (null == classFileList || classFileList.isEmpty()) {
      return Collections.emptyList();
    }
    final List<String> list = new ArrayList<String>(classFileList.size());
    for (final File file : classFileList) {
      list.add(extractClassNameFromFile(parentDirectory, file));
    }
    return list;
  }
154880
public @CheckForNull FilePath getWorkspaceRoot() {
        FilePath r = getRootPath();
        if(r==null) return null;
        return r.child(WORKSPACE_ROOT);
    }
1329892
public static String getRootClassPath() {
		if (rootClassPath == null) {
			try {
				// String path = PathKit.class.getClassLoader().getResource("").toURI().getPath();
				String path = getClassLoader().getResource("").toURI().getPath();
				rootClassPath = new File(path).getAbsolutePath();
			}
			catch (Exception e) {
				// String path = PathKit.class.getClassLoader().getResource("").getPath();
				// String path = getClassLoader().getResource("").getPath();
				// rootClassPath = new File(path).getAbsolutePath();
				
				try {
					String path = PathKit.class.getProtectionDomain().getCodeSource().getLocation().getPath();
					path = java.net.URLDecoder.decode(path, "UTF-8");
					if (path.endsWith(File.separator)) {
						path = path.substring(0, path.length() - 1);
					}
					rootClassPath = path;
				} catch (UnsupportedEncodingException e1) {
					throw new RuntimeException(e1);
				}
			}
		}
		return rootClassPath;
	}
251503
public void loadFolder(File folder) {
		// Remove previous files.
		LinearLayout root = this.chooser.getRootLayout();
		LinearLayout layout = (LinearLayout) root.findViewById(R.id.linearLayoutFiles);
		layout.removeAllViews();
		
		// Get the file path.
		if(folder == null || !folder.exists()) {
			if(defaultFolder != null) {
				this.currentFolder = defaultFolder;			
			} else {
				this.currentFolder = Environment.getExternalStorageDirectory();
			}
		} else {
			this.currentFolder = folder;
		}
		
		// Verify if the path exists.
		if(this.currentFolder.exists() && layout != null) {
			List<FileItem> fileItems = new LinkedList<FileItem>();
			
			// Add the parent folder.
			if(this.currentFolder.getParent() != null) {
				File parent = new File(this.currentFolder.getParent());
				if(parent.exists()) {
					fileItems.add(new FileItem(this.chooser.getContext(), parent, ".."));					
				}
			}
			
			// Verify if the file is a directory.
			if(this.currentFolder.isDirectory()) {
				// Get the folder's files.
				File[] fileList = this.currentFolder.listFiles();
				if(fileList != null) {
					// Order the files alphabetically and separating folders from files.
					Arrays.sort(fileList, new Comparator<File>() {
						public int compare(File file1, File file2) {
							if(file1 != null && file2 != null) {
								if(file1.isDirectory() && (!file2.isDirectory())) return -1;
								if(file2.isDirectory() && (!file1.isDirectory())) return 1;
								return file1.getName().compareTo(file2.getName());
							}
							return 0;
						}
					});		
					
					// Iterate all the files in the folder.
					for(int i=0; i<fileList.length; i++) {
						// Verify if file can be selected (is a directory or folder mode is not activated and the file pass the filter, if defined).
						boolean selectable = true;
						if(!fileList[i].isDirectory()) {
							selectable = !this.folderMode && (this.filter == null || fileList[i].getName().matches(this.filter));
						}
						
						// Verify if the file must be show.
						if(selectable || !this.showOnlySelectable) {
							// Create the file item and add it to the list.
							FileItem fileItem = new FileItem(this.chooser.getContext(), fileList[i]);
							fileItem.setSelectable(selectable);
							fileItems.add(fileItem);
						}
					}
				}
					
				// Set the name of the current folder.
				String currentFolderName = this.showFullPathInTitle? this.currentFolder.getPath() : this.currentFolder.getName();
				this.chooser.setCurrentFolderName(currentFolderName);
			} else {
				// The file is not a folder, add only this file.
				fileItems.add(new FileItem(this.chooser.getContext(), this.currentFolder));
			}
	
			
			// Add click listener and add the FileItem objects to the layout.
			for(int i=0; i<fileItems.size(); i++) {
				fileItems.get(i).addListener(this.fileItemClickListener);
				layout.addView(fileItems.get(i));
			}
			
			// Refresh default folder.
			defaultFolder = this.currentFolder;
		}			
	}
789859
public static function getRootFolder()
    {
        $filesystem = new Filesystem();
        $folder     = $filesystem->normalizePath(__DIR__ . '/../');

        if (! is_dir($folder)) {
            throw new RuntimeException(
                sprintf(
                    'Could not find a matching folder for folder name "%1$s".',
                    $folder
                )
            );
        }

        return $folder;
    }
715172
public static String[] getRootFolders() {
        Configuration config = ConfigUtils.getCurrentConfig();
        if (config != null) {
            return config.getStringArray(ROOT_FOLDERS_CONFIG_KEY);
        } else {
            return null;
        }
    }
24717
public static Map<String,List<String>> findImages( File rootDir ) {
		File files[] = rootDir.listFiles();
		if( files == null )
			return null;

		List<File> imageDirectories = new ArrayList<>();
		for( File f : files ) {
			if( f.isDirectory() ) {
				imageDirectories.add(f);
			}
		}
		Map<String,List<String>> out = new HashMap<>();
		for( File d : imageDirectories ) {
			List<String> images = new ArrayList<>();

			files = d.listFiles();
			if( files == null )
				throw new RuntimeException("Should be a directory!");

			for( File f : files ) {
				if( f.isHidden() || f.isDirectory() || f.getName().endsWith(".txt") ) {
					continue;
				}

				images.add( f.getPath() );
			}

			String key = d.getName().toLowerCase();

			out.put(key,images);
		}

		return out;
	}
193408
public static Iterator<String> iterateClassnames(final File parentDirectory,
                                                   final Iterator<File> classFileIterator) {
    return new Iterator<String>(){

      @Override
      public boolean hasNext() {
        return classFileIterator == null ? false : classFileIterator.hasNext();
      }

      @Override
      public String next() {
        final File classFile = classFileIterator.next();
        try {
          // possible returns null
          return extractClassNameFromFile(parentDirectory, classFile);
        } catch (final IOException e) {
          throw new RuntimeException(e.getMessage());
        }
      }

      @Override
      public void remove() {
        classFileIterator.remove();
      }
    };
  }
454349
@SuppressWarnings("unchecked")
    public static <T, K> Join<T, K> findJoinedType(Root<T> root, Class<T> rootClass, Class<K> joinClass) {
        Join<T, K> join = null;
        for (Join<T, ?> j : root.getJoins()) {
            if (j.getJavaType().equals(joinClass)) {
                join = (Join<T, K>) j;
            }
        }
        return join;
    }
717917
protected InputStream findClassContent(String className) throws IOException {
        String primaryArtifactEntryName = "WEB-INF/classes/" + className.replace('.', '/') + ".class";
        String dependencyEntryName = className.replace('.', '/') + ".class";
        ZipEntry entry = this.pluginArtifactZip.getEntry(primaryArtifactEntryName);
        if (entry != null) {
            return this.pluginArtifactZip.getInputStream(entry);
        }
        for (ZipFile zipFile : this.dependencyZips) {
            entry = zipFile.getEntry(dependencyEntryName);
            if (entry != null) {
                return zipFile.getInputStream(entry);
            }
        }
        return null;
    }
773898
public static HttpFileService forClassPath(ClassLoader classLoader, String rootDir) {
        return HttpFileServiceBuilder.forClassPath(classLoader, rootDir).build();
    }
139360
private static Entry findClassPathEntry(Entry jarEntry, URI pathUri) throws URISyntaxException, UnableToAdaptException {
        URI relativeJarUri = new URI("/").relativize(new URI(jarEntry.getPath()));
        URI targetUri = null;
        targetUri = relativeJarUri.resolve(pathUri);

        if (targetUri.toString().startsWith("..")) {
            Entry rootEntry = jarEntry.getRoot().adapt(Entry.class);
            if (rootEntry == null || rootEntry.getPath().isEmpty()) { //already at the outermost
                return null;
            }
            return findClassPathEntry(rootEntry, new URI("..").relativize(targetUri)); // <----
        } else {
            return jarEntry.getRoot().getEntry(targetUri.toString());
        }
    }
802587
@Override
    public String getRootFolderId() {
        if (rootNodeId == null) {
            Document layout = getUserLayoutDOM();

            Element rootNode =
                    this.xpathOperations.evaluate("//layout/folder", layout, XPathConstants.NODE);
            if (rootNode == null
                    || !rootNode.getAttribute(Constants.ATT_TYPE)
                            .equals(Constants.ROOT_FOLDER_ID)) {
                LOG.error(
                        "Unable to locate root node in layout of "
                                + owner.getUserName()
                                + ". Resetting corrupted layout.");
                resetLayout((String) null);

                rootNode =
                        this.xpathOperations.evaluate(
                                "//layout/folder", layout, XPathConstants.NODE);
                if (rootNode == null
                        || !rootNode.getAttribute(Constants.ATT_TYPE)
                                .equals(Constants.ROOT_FOLDER_ID)) {
                    throw new PortalException(
                            "Corrupted layout detected for "
                                    + owner.getUserName()
                                    + " and resetting layout failed.");
                }
            }
            rootNodeId = rootNode.getAttribute("ID");
        }
        return rootNodeId;
    }