private String getModuleName(final String pomDirectory) { final String normalisedRootPath = FileUtils.ensureTrailingSeparator(projectRootDirectory); final String normalisedPomDirectory = FileUtils.ensureTrailingSeparator(pomDirectory); final String moduleDirectory = StringUtils.removeStart(normalisedPomDirectory, normalisedRootPath); return FilenameUtils.getBaseName(StringUtils.stripEnd(moduleDirectory, SEPARATOR)); }
/** * Indicates whether the presented canonical path is a child of the current * {@link FileDetails} instance. Put differently, returning true indicates * the current instance is a parent directory of the presented * possibleChildCanonicalPath. * <p> * This method will return true if the presented child is a child of the * current instance, or if the presented child is identical to the current * instance. * * @param possibleChildCanonicalPath to evaluate (required) * @return true if the presented possible child is indeed a child of the * current instance */ public boolean isParentOf(final String possibleChildCanonicalPath) { Validate.notBlank(possibleChildCanonicalPath, "Possible child to evaluate is required"); return FileUtils.ensureTrailingSeparator(possibleChildCanonicalPath).startsWith( FileUtils.ensureTrailingSeparator(getCanonicalPath())); }
public Pom getModuleForFileIdentifier(final String fileIdentifier) { updatePomCache(); String startingPoint = FileUtils.getFirstDirectory(fileIdentifier); String pomPath = FileUtils.ensureTrailingSeparator(startingPoint) + DEFAULT_POM_NAME; File pom = new File(pomPath); while (!pom.exists()) { if (startingPoint.equals(SEPARATOR)) { break; } startingPoint = StringUtils.removeEnd(startingPoint, SEPARATOR); if (startingPoint.lastIndexOf(SEPARATOR) < 0) { break; } startingPoint = startingPoint.substring(0, startingPoint.lastIndexOf(SEPARATOR)); startingPoint = StringUtils.removeEnd(startingPoint, SEPARATOR); pomPath = FileUtils.ensureTrailingSeparator(startingPoint) + DEFAULT_POM_NAME; pom = new File(pomPath); } return getPomFromPath(pomPath); }
public String getIdentifier(final LogicalPath path, final String relativePath) { return FileUtils.ensureTrailingSeparator(rootModulePaths.get(path.getPath()).getLocationPath()) + relativePath; }
public String getIdentifier(final LogicalPath logicalPath, final String relativePath) { Validate.notNull(logicalPath, "Path required"); Validate.notNull(relativePath, "Relative path cannot be null, although it can be empty"); String initialPath = FileUtils.getCanonicalPath(getPath(logicalPath)); initialPath = FileUtils.ensureTrailingSeparator(initialPath); return initialPath + StringUtils.strip(relativePath, File.separator); }
/** * Returns the canonical path of the given {@link Path} within this module, * plus a trailing separator if found * * @param path the path for which to get the canonical location (required) * @return <code>null</code> if this module has no such path */ public String getPathLocation(final Path path) { final PhysicalPath modulePath = getPhysicalPath(path); if (modulePath == null) { return null; } return FileUtils.ensureTrailingSeparator(modulePath.getLocationPath()); }
private String getProposedJavaType(final String fileCanonicalPath) { Validate.notBlank(fileCanonicalPath, "File canonical path required"); // Determine the JavaType for this file String relativePath = ""; final Pom moduleForFileIdentifier = getProjectOperations().getModuleForFileIdentifier(fileCanonicalPath); if (moduleForFileIdentifier == null) { return relativePath; } for (final PhysicalPath physicalPath : moduleForFileIdentifier.getPhysicalPaths()) { final String moduleCanonicalPath = FileUtils.ensureTrailingSeparator(FileUtils.getCanonicalPath(physicalPath.getLocation())); if (fileCanonicalPath.startsWith(moduleCanonicalPath)) { relativePath = File.separator + StringUtils.replace(fileCanonicalPath, moduleCanonicalPath, "", 1); break; } } Validate.notBlank(relativePath, "Could not determine compilation unit name for file '%s'", fileCanonicalPath); Validate.isTrue(relativePath.startsWith(File.separator), "Relative path unexpectedly dropped the '%s' prefix (received '%s' from '%s')", File.separator, relativePath, fileCanonicalPath); relativePath = relativePath.substring(1); Validate.isTrue(relativePath.endsWith(".java"), "The relative path unexpectedly dropped the .java extension for file '%s'", fileCanonicalPath); relativePath = relativePath.substring(0, relativePath.lastIndexOf(".java")); return relativePath.replace(File.separatorChar, '.'); }
private PhysicalPath getPhysicalPath(final JavaType javaType) { Validate.notNull(javaType, "Java type required"); final String parentPath = getParentPath(javaType); if (parentPath == null) { return null; } for (final Pom pom : getProjectOperations().getPoms()) { for (final PhysicalPath physicalPath : pom.getPhysicalPaths()) { if (physicalPath.isSource()) { final String pathLocation = FileUtils.ensureTrailingSeparator(physicalPath.getLocationPath()); if (pathLocation.startsWith(parentPath)) { getTypeCache().cacheTypeAgainstModule(pom, javaType); return physicalPath; } } } } return null; }
private void initTypeMap() { for (final Pom pom : getProjectOperations().getPoms()) { for (final PhysicalPath path : pom.getPhysicalPaths()) { if (path.isSource()) { final String allJavaFiles = FileUtils.ensureTrailingSeparator(path.getLocationPath()) + JAVA_FILES_ANT_PATH; for (final FileDetails file : getFileManager().findMatchingAntPath(allJavaFiles)) { cacheType(file.getCanonicalPath()); } } } } }
/** * Indicates whether the presented canonical path is a child of the current * {@link FileDetails} instance. Put differently, returning true indicates * the current instance is a parent directory of the presented * possibleChildCanonicalPath. * <p> * This method will return true if the presented child is a child of the * current instance, or if the presented child is identical to the current * instance. * * @param possibleChildCanonicalPath to evaluate (required) * @return true if the presented possible child is indeed a child of the * current instance */ public boolean isParentOf(final String possibleChildCanonicalPath) { Validate.notBlank(possibleChildCanonicalPath, "Possible child to evaluate is required"); return FileUtils.ensureTrailingSeparator(possibleChildCanonicalPath).startsWith( FileUtils.ensureTrailingSeparator(getCanonicalPath())); }
private String getProposedJavaType(final String fileCanonicalPath) { Validate.notBlank(fileCanonicalPath, "File canonical path required"); // Determine the JavaType for this file String relativePath = ""; final Pom moduleForFileIdentifier = getProjectOperations().getModuleForFileIdentifier(fileCanonicalPath); if (moduleForFileIdentifier == null) { return relativePath; } for (final PhysicalPath physicalPath : moduleForFileIdentifier.getPhysicalPaths()) { final String moduleCanonicalPath = FileUtils.ensureTrailingSeparator(FileUtils.getCanonicalPath(physicalPath.getLocation())); if (fileCanonicalPath.startsWith(moduleCanonicalPath)) { relativePath = File.separator + StringUtils.replace(fileCanonicalPath, moduleCanonicalPath, "", 1); break; } } Validate.notBlank(relativePath, "Could not determine compilation unit name for file '%s'", fileCanonicalPath); Validate.isTrue(relativePath.startsWith(File.separator), "Relative path unexpectedly dropped the '%s' prefix (received '%s' from '%s')", File.separator, relativePath, fileCanonicalPath); relativePath = relativePath.substring(1); Validate.isTrue(relativePath.endsWith(".java"), "The relative path unexpectedly dropped the .java extension for file '%s'", fileCanonicalPath); relativePath = relativePath.substring(0, relativePath.lastIndexOf(".java")); return relativePath.replace(File.separatorChar, '.'); }
private PhysicalPath getPhysicalPath(final JavaType javaType) { Validate.notNull(javaType, "Java type required"); final String parentPath = getParentPath(javaType); if (parentPath == null) { return null; } for (final Pom pom : getProjectOperations().getPoms()) { for (final PhysicalPath physicalPath : pom.getPhysicalPaths()) { if (physicalPath.isSource()) { final String pathLocation = FileUtils.ensureTrailingSeparator(physicalPath.getLocationPath()); if (pathLocation.startsWith(parentPath)) { getTypeCache().cacheTypeAgainstModule(pom, javaType); return physicalPath; } } } } return null; }
private void initTypeMap() { for (final Pom pom : getProjectOperations().getPoms()) { for (final PhysicalPath path : pom.getPhysicalPaths()) { if (path.isSource()) { final String allJavaFiles = FileUtils.ensureTrailingSeparator(path.getLocationPath()) + JAVA_FILES_ANT_PATH; for (final FileDetails file : getFileManager().findMatchingAntPath(allJavaFiles)) { cacheType(file.getCanonicalPath()); } } } } }