@Override public IFile file(String path) { return _delegate.file(path); }
@Override public String getName() { return _delegate.getName(); }
private void findTestTypesImpl(IDirectory root, IDirectory entry, TestClassFindType findType, ArrayList<IType> types) { if (entry.exists()) { for (IFile iFile : entry.listFiles()) { possiblyAddTest(iFile, root, findType, types); } for (IDirectory subDir : entry.listDirs()) { findTestTypesImpl(root, subDir, findType, types); } } }
private static IDirectory findParentDirectory(IDirectory root, List<String> relativePath) { IDirectory parent = root; for (String pathComponent : relativePath) { if (pathComponent.equals(".")) { // Do nothing } else if (pathComponent.equals("..")) { parent = parent.getParent(); } else { parent = parent.dir(pathComponent); } } return parent; }
private void addClassNames(final IDirectory root, IDirectory dir, final ClassPathFilter filter) { for (IFile file : dir.listFiles()) { if( isClassFileName( file.getName() ) ) { String strClassName = getClassNameFromFile( root, file ); if( isValidClassName( strClassName ) ) { putClassName( file, strClassName, filter ); } } } for (IDirectory subDir : dir.listDirs()) { addClassNames(root, subDir, filter); } }
private static void allContainedFilesExcludingIgnored(IDirectory root, IDirectory dir, DynamicArray<IFile> files) { files.addAll(dir.listFiles()); for (IDirectory subDir : dir.listDirs()) { if (!CommonServices.getPlatformHelper().isPathIgnored(root.relativePath(subDir))) { allContainedFilesExcludingIgnored(root, subDir, files); } } }
private void processDirectory(PackageToClassPathEntryTreeMap node, IFileSystemGosuClassRepository.ClassPathEntry entry, IDirectory path) { IDirectory entryPath = entry.getPath(); if (entryPath.equals(path) || !CommonServices.getPlatformHelper().isPathIgnored(entryPath.relativePath(path))) { List<? extends IDirectory> dirs = path.listDirs(); for (IDirectory dir : dirs) { if (isValidDirectory(dir)) { PackageToClassPathEntryTreeMap child = node.createChildForDir(entry, dir.getName()); processDirectory(child, entry, dir); } } } }
@Override public ResourcePath getPath() { return _delegate.getPath(); }
public Set<TypeName> getTypeNames(Set<String> extensions, ITypeLoader loader) { Set<TypeName> names = new HashSet<TypeName>(); for (PackageToClassPathEntryTreeMap child : _children.values()) { String name = child._strFullPackageName; name = name.substring(name.lastIndexOf('.') + 1); names.add(new TypeName(name, loader, TypeName.Kind.NAMESPACE, TypeName.Visibility.PUBLIC)); } for (IFileSystemGosuClassRepository.ClassPathEntry classPathEntry : _classPathEntries) { IDirectory entryPath = classPathEntry.getPath().dir(_strFullPackageName.replace('.', '/')); List<? extends IFile> files = entryPath.listFiles(); for (IFile file : files) { String extension = "." + file.getExtension(); if (extensions.contains(extension)) { String fqn = entryPath.relativePath(file).replace('/', '.'); fqn = fqn.substring(0, fqn.lastIndexOf('.')); names.add(new TypeName(_strFullPackageName + "." + fqn, loader, TypeName.Kind.TYPE, TypeName.Visibility.PUBLIC)); } } } return names; } }
private static IDirectory executeOnSourceDirectory(IDirectory dir, SourceDirectoryBlock block){ IFile moduleFile = dir.file("pom.xml"); IDirectory foundModule = null; if (moduleFile != null && moduleFile.exists()) { // This entry is itself a module, so return that block.doIt(dir, moduleFile); } else if (!dir.getName().endsWith(".jar")) { IDirectory parentDir = dir.getParent(); if (parentDir != null) { IFile parentModuleFile = parentDir.file("pom.xml"); if (parentModuleFile.exists() && moduleContainsSourceDir(parentModuleFile, dir)) { // Module.xml file in the parent directory, so that directory is a module block.doIt(parentDir, parentModuleFile); } else { // No module.xml file in the parent directory either, the original directory is the module block.doIt(dir, null); } } else { // No parent directory at all, so just the original directory is the module block.doIt(dir, null); } } else { // It's a jar file with no module.xml inside, so the jar is the module block.doIt(dir, null); } return foundModule; }
public List<Pair<String, IFile>> findAllFilesByExtension(String extension) { List<Pair<String, IFile>> results = new ArrayList<Pair<String, IFile>>(); for (IDirectory dir : _module.getRoots()) { IDirectory configDir = dir.dir(IModule.CONFIG_RESOURCE_PREFIX); if (configDir.exists()) { addAllLocalResourceFilesByExtensionInternal(IModule.CONFIG_RESOURCE_PREFIX, configDir, extension, results); } } for (IDirectory sourceEntry : _module.getSourcePath()) { if (sourceEntry.exists() && !sourceEntry.getName().equals(IModule.CONFIG_RESOURCE_PREFIX)) { addAllLocalResourceFilesByExtensionInternal("", sourceEntry, extension, results); } } return results; }
public static void getExtensions(Collection<String> result, IDirectory dir, String headerName) { IFile manifestFile = dir.file( "META-INF/MANIFEST.MF" ); if (manifestFile == null || !manifestFile.exists()) { return; } InputStream in = null; try { in = manifestFile.openInputStream(); Manifest manifest = new Manifest(in); scanManifest(result, manifest, headerName); } catch (Exception e) { // FIXME: For some reason, WebSphere changes JARs in WEB-INF/lib, breaking signatures. So ignore errors. ResourcePath path = dir.getPath(); String str = path != null ? path.getFileSystemPathString() : dir.toString(); CommonServices.getEntityAccess().getLogger().warn("Cannot read manifest from jar " + str + ", ignoring"); } finally { if (in != null) { try { in.close(); } catch (IOException e) { // Ignore } } } }
public void initWatching() { _directoryWatcher = new DirectoryWatcher(); List<? extends IDirectory> sourceEntries = TypeSystem.getCurrentModule().getSourcePath(); for (IDirectory sourceEntry : sourceEntries) { // Ignore /classes directories and jar files if (!sourceEntry.getPath().getName().equals("classes") && !sourceEntry.getPath().getName().endsWith(".jar") && sourceEntry.isJavaFile()) { _directoryWatcher.watchDirectoryTree(sourceEntry.toJavaFile().toPath()); } } }
public List<Pair<String, IFile>> findAllFilesByExtension(String extension) { List<Pair<String, IFile>> results = new ArrayList<>(); for (IDirectory sourceEntry : _module.getSourcePath()) { if (sourceEntry.exists()) { String prefix = sourceEntry.getName().equals(IModule.CONFIG_RESOURCE_PREFIX) ? IModule.CONFIG_RESOURCE_PREFIX : ""; addAllLocalResourceFilesByExtensionInternal(prefix, sourceEntry, extension, results); } } return results; }
private IFile getFileMatchCase( IDirectory dir, String strFileName ) { if (dir.hasChildFile(strFileName)) { IFile file = dir.file( strFileName ); try { if( doesFileMatchCase( strFileName, file ) ) { return file; } else { return null; } } catch( IOException e ) { throw new RuntimeException( e ); } } else { return null; } }
/** * Reads a pom.xml file into a GosuPathEntry object * * @param moduleFile the pom.xml file to convert to GosuPathEntry * @return an ordered list of GosuPathEntries created based on the algorithm described above */ public static GosuPathEntry createPathEntryForModuleFile(IFile moduleFile) { try { InputStream is = moduleFile.openInputStream(); try { SimpleXmlNode moduleNode = SimpleXmlNode.parse(is); IDirectory rootDir = moduleFile.getParent(); List<IDirectory> sourceDirs = new ArrayList<IDirectory>(); for (String child : new String[] { "gsrc", "gtest" }) { IDirectory dir = rootDir.dir(child); if (dir.exists()) { sourceDirs.add(dir); } } return new GosuPathEntry(rootDir, sourceDirs); } finally { is.close(); } } catch (IOException e) { throw new RuntimeException(e); } } }
@Override public String relativePath(IResource resource) { return _delegate.relativePath(resource); }
public boolean isPathIgnored(String relativePath) { if (relativePath == null) { return true; } final IFile file = CommonServices.getFileSystem().getIFile(new File(relativePath)); // AHK - We use file.getParent().hasChild() instead of file.exists() since we don't want to hit the disk // for the file existence check if we don't have to, and hasChild() will usually work off the cached sub-files // of a given directory if (file != null && file.getParent() != null && file.getParent().hasChildFile(file.getName()) && isConfigFile(file)) { final IModule module = TypeSystem.getExecutionEnvironment().getModule(file); if (module != null) { for (IDirectory dir : module.getSourcePath()) { if ("config".equals(dir.getName()) && file.isDescendantOf(dir)) { return false; } } } //System.out.println("Ignoring: " + relativePath); return true; } // for (String pattern : IGNORE_DIRECTORY_PATTERNS) { // if (relativePath.contains(pattern)) { // return true; // } // } return HASH.matches(relativePath); }