protected boolean isHidden(Path path) { return path.getFileName().startsWith("."); }
private String getPackagePathSuffix(final org.uberfire.java.nio.file.Path nioModuleRootPath, final org.uberfire.java.nio.file.Path nioPackagePath) { final org.uberfire.java.nio.file.Path nioMainSrcPath = nioModuleRootPath.resolve(MAIN_SRC_PATH); final org.uberfire.java.nio.file.Path nioTestSrcPath = nioModuleRootPath.resolve(TEST_SRC_PATH); final org.uberfire.java.nio.file.Path nioMainResourcesPath = nioModuleRootPath.resolve(MAIN_RESOURCES_PATH); final org.uberfire.java.nio.file.Path nioTestResourcesPath = nioModuleRootPath.resolve(TEST_RESOURCES_PATH); String packageName = null; org.uberfire.java.nio.file.Path packagePath = null; if (nioPackagePath.startsWith(nioMainSrcPath)) { packagePath = nioMainSrcPath.relativize(nioPackagePath); packageName = packagePath.toString(); } else if (nioPackagePath.startsWith(nioTestSrcPath)) { packagePath = nioTestSrcPath.relativize(nioPackagePath); packageName = packagePath.toString(); } else if (nioPackagePath.startsWith(nioMainResourcesPath)) { packagePath = nioMainResourcesPath.relativize(nioPackagePath); packageName = packagePath.toString(); } else if (nioPackagePath.startsWith(nioTestResourcesPath)) { packagePath = nioTestResourcesPath.relativize(nioPackagePath); packageName = packagePath.toString(); } return packageName; }
private String getPackagePathSuffix(final org.uberfire.java.nio.file.Path nioProjectRootPath, final org.uberfire.java.nio.file.Path nioPackagePath) { final org.uberfire.java.nio.file.Path nioMainSrcPath = nioProjectRootPath.resolve(MAIN_SRC_PATH); final org.uberfire.java.nio.file.Path nioTestSrcPath = nioProjectRootPath.resolve(TEST_SRC_PATH); final org.uberfire.java.nio.file.Path nioMainResourcesPath = nioProjectRootPath.resolve(MAIN_RESOURCES_PATH); final org.uberfire.java.nio.file.Path nioTestResourcesPath = nioProjectRootPath.resolve(TEST_RESOURCES_PATH); String packageName = null; org.uberfire.java.nio.file.Path packagePath = null; if (nioPackagePath.startsWith(nioMainSrcPath)) { packagePath = nioMainSrcPath.relativize(nioPackagePath); packageName = packagePath.toString(); } else if (nioPackagePath.startsWith(nioTestSrcPath)) { packagePath = nioTestSrcPath.relativize(nioPackagePath); packageName = packagePath.toString(); } else if (nioPackagePath.startsWith(nioMainResourcesPath)) { packagePath = nioMainResourcesPath.relativize(nioPackagePath); packageName = packagePath.toString(); } else if (nioPackagePath.startsWith(nioTestResourcesPath)) { packagePath = nioTestResourcesPath.relativize(nioPackagePath); packageName = packagePath.toString(); } return packageName; }
private String getPackagePathSuffix(final org.uberfire.java.nio.file.Path nioModuleRootPath, final org.uberfire.java.nio.file.Path nioPackagePath) { final org.uberfire.java.nio.file.Path nioMainSrcPath = nioModuleRootPath.resolve(MAIN_SRC_PATH); final org.uberfire.java.nio.file.Path nioTestSrcPath = nioModuleRootPath.resolve(TEST_SRC_PATH); final org.uberfire.java.nio.file.Path nioMainResourcesPath = nioModuleRootPath.resolve(MAIN_RESOURCES_PATH); final org.uberfire.java.nio.file.Path nioTestResourcesPath = nioModuleRootPath.resolve(TEST_RESOURCES_PATH); String packageName = null; org.uberfire.java.nio.file.Path packagePath = null; if (nioPackagePath.startsWith(nioMainSrcPath)) { packagePath = nioMainSrcPath.relativize(nioPackagePath); packageName = packagePath.toString(); } else if (nioPackagePath.startsWith(nioTestSrcPath)) { packagePath = nioTestSrcPath.relativize(nioPackagePath); packageName = packagePath.toString(); } else if (nioPackagePath.startsWith(nioMainResourcesPath)) { packagePath = nioMainResourcesPath.relativize(nioPackagePath); packageName = packagePath.toString(); } else if (nioPackagePath.startsWith(nioTestResourcesPath)) { packagePath = nioTestResourcesPath.relativize(nioPackagePath); packageName = packagePath.toString(); } return packageName; }
@Test public void startsWithPath() { final Path path = GeneralPathImpl.create(fs, "/path/to/file.txt", false); assertThatThrownBy(() -> path.startsWith((Path) null)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Parameter named 'other' should be not null!"); }
@Test public void startsWith() { final Path path = GeneralPathImpl.create(fs, "/path/to/file.txt", false); assertThatThrownBy(() -> path.startsWith((String) null)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Parameter named 'other' should be not null!"); }
/** * Given a path within a module calculates the expected class name for the given class. */ public String calculateClassName(final Module module, final org.uberfire.backend.vfs.Path path) { PortablePreconditions.checkNotNull("module", module); if (path == null) { return null; } final Package defaultPackage = moduleService.resolveDefaultPackage(module); if (defaultPackage == null) { return null; } final Path mainSrcNioPath = Paths.convert(defaultPackage.getPackageMainSrcPath()); final Path testSrcNioPath = Paths.convert(defaultPackage.getPackageTestSrcPath()); final Path nioPath = Paths.convert(path); Path relativePath = null; if (mainSrcNioPath != null && nioPath.startsWith(mainSrcNioPath)) { relativePath = mainSrcNioPath.relativize(nioPath); } else if (testSrcNioPath != null && nioPath.startsWith(testSrcNioPath)) { relativePath = testSrcNioPath.relativize(nioPath); } if (relativePath != null) { String className = relativePath.toString().replace("/", "."); return className.substring(0, className.lastIndexOf(".java")); } return null; }
/** * Substring the second path from the first. This can be used to for example to substring the repository prefix from a Path. * @param wholePath What we want to substring from the first Path * @param prefixToRemove The Path we want to substring * @return The result. For example the File URI from the Repository root or from a submodule root. * @throws IllegalStateException When the the prefix is longer than the URI where it is removed from. */ public static String removePrefix(final Path wholePath, final Path prefixToRemove) { PortablePreconditions.checkNotNull("prefixToRemove", prefixToRemove); PortablePreconditions.checkNotNull("wholePath", wholePath); if (prefixToRemove.toURI().length() > wholePath.toURI().length()) { throw new IllegalArgumentException("Prefix is longer than the URI where it is being removed from."); } final org.uberfire.java.nio.file.Path nioWholePath = convert(wholePath); final org.uberfire.java.nio.file.Path nioPrefixToRemove = convert(prefixToRemove); if (!nioWholePath.startsWith(nioPrefixToRemove)) { throw new IllegalArgumentException("The beginning of the whole Path " + nioWholePath + " does not match the prefix path " + nioPrefixToRemove + "."); } return nioPrefixToRemove.relativize(nioWholePath).toString(); }
if (nioResource.startsWith(nioMainSrcPath)) { packagePath = nioMainSrcPath.relativize(nioResource); packageName = packagePath.toString().replaceAll("/", "."); } else if (nioResource.startsWith(nioTestSrcPath)) { packagePath = nioTestSrcPath.relativize(nioResource); packageName = packagePath.toString().replaceAll("/", "."); } else if (nioResource.startsWith(nioMainResourcesPath)) { packagePath = nioMainResourcesPath.relativize(nioResource); packageName = packagePath.toString().replaceAll("/", "."); } else if (nioResource.startsWith(nioTestResourcesPath)) { packagePath = nioTestResourcesPath.relativize(nioResource); packageName = packagePath.toString().replaceAll("/",
if (nioResource.startsWith(nioMainSrcPath)) { packagePath = nioMainSrcPath.relativize(nioResource); packageName = packagePath.toString().replaceAll("/", "."); } else if (nioResource.startsWith(nioTestSrcPath)) { packagePath = nioTestSrcPath.relativize(nioResource); packageName = packagePath.toString().replaceAll("/", "."); } else if (nioResource.startsWith(nioMainResourcesPath)) { packagePath = nioMainResourcesPath.relativize(nioResource); packageName = packagePath.toString().replaceAll("/", "."); } else if (nioResource.startsWith(nioTestResourcesPath)) { packagePath = nioTestResourcesPath.relativize(nioResource); packageName = packagePath.toString().replaceAll("/",
if (nioResource.startsWith(nioMainSrcPath)) { packagePath = nioMainSrcPath.relativize(nioResource); packageName = packagePath.toString().replaceAll("/", "."); } else if (nioResource.startsWith(nioTestSrcPath)) { packagePath = nioTestSrcPath.relativize(nioResource); packageName = packagePath.toString().replaceAll("/", "."); } else if (nioResource.startsWith(nioMainResourcesPath)) { packagePath = nioMainResourcesPath.relativize(nioResource); packageName = packagePath.toString().replaceAll("/", "."); } else if (nioResource.startsWith(nioTestResourcesPath)) { packagePath = nioTestResourcesPath.relativize(nioResource); packageName = packagePath.toString().replaceAll("/",
@Override public boolean isPom(final Path resource) { try { //Null resource paths cannot resolve to a Project if (resource == null) { return false; } //Check if path equals pom.xml final Project project = resolveProject(resource); //It's possible that the Incremental Build attempts to act on a Project file before the project has been fully created. //This should be a short-term issue that will be resolved when saving a project batches pom.xml, kmodule.xml and project.imports //etc into a single git-batch. At present they are saved individually leading to multiple Incremental Build requests. if (project == null) { return false; } final org.uberfire.java.nio.file.Path path = Paths.convert(resource).normalize(); final org.uberfire.java.nio.file.Path pomFilePath = Paths.convert(project.getPomXMLPath()); return path.startsWith(pomFilePath); } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
@Override public boolean isPom(final Path resource) { try { //Null resource paths cannot resolve to a Module if (resource == null) { return false; } //Check if path equals pom.xml final Module module = resolveModule(resource); //It's possible that the Incremental Build attempts to act on a Module file before the module has been fully created. //This should be a short-term issue that will be resolved when saving a module batches pom.xml, kmodule.xml and project.imports //etc into a single git-batch. At present they are saved individually leading to multiple Incremental Build requests. if (module == null) { return false; } final org.uberfire.java.nio.file.Path path = Paths.convert(resource).normalize(); final org.uberfire.java.nio.file.Path pomFilePath = Paths.convert(module.getPomXMLPath()); return path.startsWith(pomFilePath); } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
@Override public boolean isKModule(final Path resource) { try { //Null resource paths cannot resolve to a Module if (resource == null) { return false; } //Check if path equals kmodule.xml final KieModule module = moduleService.resolveModule(resource, false); //It's possible that the Incremental Build attempts to act on a Module file before the module has been fully created. //This should be a short-term issue that will be resolved when saving a module batches pom.xml, kmodule.xml and project.imports //etc into a single git-batch. At present they are saved individually leading to multiple Incremental Build requests. if (module == null) { return false; } final org.uberfire.java.nio.file.Path path = Paths.convert(resource).normalize(); final org.uberfire.java.nio.file.Path kmoduleFilePath = Paths.convert(module.getKModuleXMLPath()); return path.startsWith(kmoduleFilePath); } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
@Override public boolean isPom(final Path resource) { try { //Null resource paths cannot resolve to a Module if (resource == null) { return false; } //Check if path equals pom.xml final Module module = resolveModule(resource); //It's possible that the Incremental Build attempts to act on a Module file before the module has been fully created. //This should be a short-term issue that will be resolved when saving a module batches pom.xml, kmodule.xml and project.imports //etc into a single git-batch. At present they are saved individually leading to multiple Incremental Build requests. if (module == null) { return false; } final org.uberfire.java.nio.file.Path path = Paths.convert(resource).normalize(); final org.uberfire.java.nio.file.Path pomFilePath = Paths.convert(module.getPomXMLPath()); return path.startsWith(pomFilePath); } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
assertTrue(path.startsWith(create(fs, "c:\\", false))); assertTrue(path.startsWith(create(fs, "c:\\path", false))); assertTrue(path.startsWith(create(fs, "c:\\path\\to\\", false))); assertTrue(path.startsWith(create(fs, "c:\\path\\to\\file.txt", false))); assertFalse(path.startsWith(create(fs, "c:\\to\\file.txt", false))); assertFalse(path.startsWith(create(fs, "d:\\", false))); assertFalse(path.startsWith(create(fs, "/d:/", false))); assertFalse(path.startsWith(create(fs, "d:\\path\\to\\file.txt", false))); assertTrue(path.startsWith(create(fs, "/c:/", false))); assertTrue(path.startsWith(create(fs, "/c:/path/",
false); assertTrue(path.startsWith(create(fs, "/path", false))); assertTrue(path.startsWith(create(fs, "/path/to", false))); assertTrue(path.startsWith(create(fs, "/path/to/file.txt", false))); assertFalse(path.startsWith(create(fs, "/p/th/to/file.txt", false))); assertFalse(path.startsWith(create(fs, "/some/other/path/to/file.txt", false))); assertFalse(path.startsWith(create(fs, "path/to/file.txt", false))); assertFalse(path.startsWith(create(fs, "path/to", false))); assertFalse(path.startsWith(create(fs, "to", false)));