@Test public void testNormalize() { final FileSystemProvider fsprovider = mock(FileSystemProvider.class); when(fsprovider.isDefault()).thenReturn(true); when(fsprovider.getScheme()).thenReturn("file"); when(fs.provider()).thenReturn(fsprovider); when(fs.getSeparator()).thenReturn("/"); final Path path = create(fs, "/path/to/", false); assertThat(path.normalize()).isNotNull().isEqualTo(path); assertThat(path.normalize().normalize()).isNotNull().isEqualTo(path.normalize()); final Path path2 = create(fs, "/some/path/../../to", false); assertThat(path2.normalize()).isNotNull(); assertThat(path2.normalize().toString()).isEqualTo("/to"); assertThat(path2.normalize().normalize()).isNotNull().isEqualTo(path2.normalize()); }
@Test public void testNormalizeWindows() { final FileSystemProvider fsprovider = mock(FileSystemProvider.class); when(fsprovider.isDefault()).thenReturn(true); when(fsprovider.getScheme()).thenReturn("file"); when(fs.provider()).thenReturn(fsprovider); when(fs.getSeparator()).thenReturn("\\"); final Path path = create(fs, "c:\\path\\to\\", false); assertThat(path.normalize()).isNotNull().isEqualTo(path); assertThat(path.normalize().normalize()).isNotNull().isEqualTo(path.normalize()); final Path path2 = create(fs, "c:\\some\\path\\..\\..\\to", false); assertThat(path2.normalize()).isNotNull(); assertThat(path2.normalize().toString()).isEqualTo("c:\\to"); assertThat(path2.normalize().normalize()).isNotNull().isEqualTo(path2.normalize()); }
@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); } }
@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 Project resolveParentProject(final Path resource) { try { //Null resource paths cannot resolve to a Project if (resource == null) { return null; } //Check if resource is the project root org.uberfire.java.nio.file.Path path = Paths.convert(resource).normalize(); if (hasPom(path)) { final Path projectRootPath = Paths.convert(path); return new Project(projectRootPath, Paths.convert(path.resolve(POM_PATH)), projectRootPath.getFileName()); } else { return null; } } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
@Override public Module resolveParentModule(final Path resource) { try { //Null resource paths cannot resolve to a Module if (resource == null) { return null; } //Check if resource is the module root final org.uberfire.java.nio.file.Path path = Paths.convert(resource).normalize(); if (hasPom(path)) { final Path moduleRootPath = Paths.convert(path); final Path pomXMLPath = Paths.convert(path.resolve(POM_PATH)); final POM pom = pomService.load(pomXMLPath); return new Module(moduleRootPath, pomXMLPath, pom); } else { return null; } } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
@Override public Module resolveParentModule(final Path resource) { try { //Null resource paths cannot resolve to a Module if (resource == null) { return null; } //Check if resource is the module root final org.uberfire.java.nio.file.Path path = Paths.convert(resource).normalize(); if (hasPom(path)) { final Path moduleRootPath = Paths.convert(path); final Path pomXMLPath = Paths.convert(path.resolve(POM_PATH)); final POM pom = pomService.load(pomXMLPath); return new Module(moduleRootPath, pomXMLPath, pom); } else { return null; } } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
@Override public Module resolveToParentModule(final Path resource) { try { //Null resource paths cannot resolve to a Module if (resource == null) { return null; } //Check if resource is the module root org.uberfire.java.nio.file.Path path = Paths.convert(resource).normalize(); org.uberfire.java.nio.file.Path parentPomPath = path.resolve(POM_PATH); if (hasPom(path)) { POM parent = pomService.load(Paths.convert(parentPomPath)); final Path moduleRootPath = Paths.convert(path); Module module = new Module(moduleRootPath, Paths.convert(parentPomPath), parent, parent.getModules()); return module; } else { return null; } } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
org.uberfire.java.nio.file.Path path = Paths.convert(resource).normalize();
@Override public Module resolveToParentModule(final Path resource) { try { //Null resource paths cannot resolve to a Module if (resource == null) { return null; } //Check if resource is the module root org.uberfire.java.nio.file.Path path = Paths.convert(resource).normalize(); org.uberfire.java.nio.file.Path parentPomPath = path.resolve(POM_PATH); if (hasPom(path)) { POM parent = pomService.load(Paths.convert(parentPomPath)); final Path moduleRootPath = Paths.convert(path); Module module = new Module(moduleRootPath, Paths.convert(parentPomPath), parent, parent.getModules()); return module; } else { return null; } } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
@Override public Project resolveToParentProject(final Path resource) { try { //Null resource paths cannot resolve to a Project if (resource == null) { return null; } //Check if resource is the project root org.uberfire.java.nio.file.Path path = Paths.convert(resource).normalize(); org.uberfire.java.nio.file.Path parentPomPath = path.resolve(POM_PATH); if (hasPom(path)) { POM parent = pomService.load(Paths.convert(parentPomPath)); final Path projectRootPath = Paths.convert(path); Project project = new Project(projectRootPath, Paths.convert(parentPomPath), projectRootPath.getFileName(), parent.getModules()); return project; } else { return null; } } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }