public List<org.kie.commons.java.nio.file.Path> makeBreadCrumbExclusions( final Path path ) { final List<org.kie.commons.java.nio.file.Path> exclusions = new ArrayList<org.kie.commons.java.nio.file.Path>(); final org.uberfire.backend.vfs.Path projectRoot = projectService.resolveProject( path ); if ( projectRoot == null ) { return exclusions; } final org.kie.commons.java.nio.file.Path e0 = paths.convert( projectRoot ); final org.kie.commons.java.nio.file.Path e1 = e0.resolve( "src" ); final org.kie.commons.java.nio.file.Path e2 = e1.resolve( "main" ); final org.kie.commons.java.nio.file.Path e3 = e1.resolve( "test" ); exclusions.add( e1 ); exclusions.add( e2 ); exclusions.add( e3 ); return exclusions; }
@Override public boolean accepts( final Path path ) { final String pattern = getPattern(); final String suffix = "." + pattern; final String uri = path.toUri().toString(); return uri.substring( uri.length() - suffix.length() ).equals( suffix ); }
private Path doResolveTestPackage( final Path resource, final Path projectRoot ) { //The pom.xml and kmodule.xml files are not within a package if ( isPom( resource ) || isKModule( resource ) ) { return null; } //The Path must be within a Project's src/test/java or src/test/resources path boolean resolved = false; org.kie.commons.java.nio.file.Path path = paths.convert( resource ).normalize(); final org.kie.commons.java.nio.file.Path testJavaPath = paths.convert( projectRoot ).resolve( TEST_JAVA_PATH ); final org.kie.commons.java.nio.file.Path testResourcesPath = paths.convert( projectRoot ).resolve( TEST_RESOURCES_PATH ); //Check if path resides within a Java or Resources path if ( path.startsWith( testJavaPath ) ) { resolved = true; } else if ( path.startsWith( testResourcesPath ) ) { resolved = true; } if ( !resolved ) { return null; } //If the Path is already a folder simply return it if ( Files.isDirectory( path ) ) { return resource; } path = path.getParent(); return paths.convert( path ); }
public static Path dot( final Path path ) { if ( path.getFileName() == null ) { return path.resolve( ".root" ); } return path.resolveSibling( "." + path.getFileName() ); }
public String[] listUsers() { //TODO: a temporary hack to retrieve user list. Please refactor later. List<String> userList = new ArrayList<String>(); org.kie.commons.java.nio.file.Path userRoot = bootstrapRoot.resolve( "/.metadata/.users/" ); final Iterator<org.kie.commons.java.nio.file.Path> userIterator = userRoot.iterator(); if ( userIterator.hasNext() ) { org.kie.commons.java.nio.file.Path userDir = userIterator.next(); userList.add( userDir.getFileName().toString() ); } String[] result = new String[ userList.size() ]; return userList.toArray( result ); }
@Override public Path resolveSibling( final Path other ) { checkNotNull( "other", other ); final Path parent = this.getParent(); if ( parent == null || other.isAbsolute() ) { return other; } return parent.resolve( other ); }
@Test public void testSimpleBranchedGitRoot() { when(fs.getSeparator()).thenReturn("/"); final Path path = JGitPathImpl.create(fs, "/", "master@my-host", false); assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isTrue(); assertThat(path.toString()).isEqualTo("/"); assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/"); assertThat(path.getRoot().toString()).isEqualTo("/"); assertThat(path.getNameCount()).isEqualTo(0); }
Iterable<Path> availableForms = null; Path processPath = fileService.getPath(processAssetPath); Path formsPath = fileService.getPath(processPath.getParent().toUri().toString() + "/forms/"); try { if(availableForms != null){ for (Path p : availableForms) { if (p.getFileName().toString().contains(processId)) { selectedForm = p; try { if (selectedForm == null) { String rootPath = processPath.getRoot().toUri().toString(); if (!rootPath.endsWith(processPath.getFileSystem().getSeparator())) { rootPath +=processPath.getFileSystem().getSeparator();
@Test(expected = FileAlreadyExistsException.class) public void copyFileAlreadyExistsException() { final Path path = getDirectoryPath().resolveSibling( "alreadyExistsTest" ); ioService().deleteIfExists( path ); ioService().createDirectories( path ); ioService().write( path.resolve( "myFile.txt" ), "ooooo!" ); ioService().write( path.resolve( "mytarget" ), "xooooo!" ); ioService().copy( path.resolve( "myFile.txt" ), path.resolve( "mytarget" ) ); }
final Path projectRoot = project.getRootPath(); final org.kie.commons.java.nio.file.Path nioProjectRoot = paths.convert( projectRoot ); final org.kie.commons.java.nio.file.Path nioMainSrcPath = nioProjectRoot.resolve( MAIN_SRC_PATH ); final org.kie.commons.java.nio.file.Path nioTestSrcPath = nioProjectRoot.resolve( TEST_SRC_PATH ); final org.kie.commons.java.nio.file.Path nioMainResourcesPath = nioProjectRoot.resolve( MAIN_RESOURCES_PATH ); final org.kie.commons.java.nio.file.Path nioTestResourcesPath = nioProjectRoot.resolve( TEST_RESOURCES_PATH ); nioResource = nioResource.getParent(); 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( "/", "." ); boolean includeAttributes = Files.exists( nioMainSrcPath.resolve( packagePath ) ); final Path mainSrcPath = paths.convert( nioMainSrcPath.resolve( packagePath ), includeAttributes );
final org.kie.commons.java.nio.file.Path pomPath = pRoot.resolve( POM_PATH ); final String projectName = pRoot.getFileName().toString(); if ( Files.exists( pomPath ) ) { items.add( new FileItem( paths.convert( pomPath ), final org.kie.commons.java.nio.file.Path projectImportsPath = pRoot.resolve( PROJECT_IMPORTS_PATH ); if ( Files.exists( projectImportsPath ) ) { items.add( new FileItem( paths.convert( projectImportsPath ), final org.kie.commons.java.nio.file.Path srcJavaResourcesPath = pRoot.resolve( SOURCE_JAVA_RESOURCES_PATH ); if ( Files.exists( srcJavaResourcesPath ) ) { items.add( new FolderItem( paths.convert( srcJavaResourcesPath ), final org.kie.commons.java.nio.file.Path srcResourcesPath = pRoot.resolve( SOURCE_RESOURCES_PATH ); if ( Files.exists( srcResourcesPath ) ) { items.add( new FolderItem( paths.convert( srcResourcesPath ), final org.kie.commons.java.nio.file.Path testJavaResourcesPath = pRoot.resolve( TEST_JAVA_RESOURCES_PATH ); if ( Files.exists( testJavaResourcesPath ) ) { items.add( new FolderItem( paths.convert( testJavaResourcesPath ), final org.kie.commons.java.nio.file.Path testResourcesPath = pRoot.resolve( TEST_RESOURCES_PATH ); if ( Files.exists( testResourcesPath ) ) { items.add( new FolderItem( paths.convert( testResourcesPath ), items.add( new ParentFolderItem( paths.convert( pRoot.getParent() ), ".." ) );
public static Path createDirectories( final Path dir, final FileAttribute<?>... attrs ) throws UnsupportedOperationException, FileAlreadyExistsException, IOException, SecurityException { checkNotNull( "dir", dir ); final Path absoluteDir = dir.toAbsolutePath(); if ( !notExists( absoluteDir ) ) { throw new FileAlreadyExistsException( absoluteDir.toString() ); } Path parent = absoluteDir.getParent(); while ( parent != null ) { try { providerOf( parent ).checkAccess( parent ); break; } catch ( NoSuchFileException x ) { } parent = parent.getParent(); } if ( parent == null ) { throw new IOException( "Root directory does not exist" ); } // create directories Path child = parent; for ( final Path name : parent.relativize( dir ) ) { child = child.resolve( name ); providerOf( child ).createDirectory( child, attrs ); } return dir; }
protected boolean isFileScheme( final Path path ) { if ( path == null || path.getFileSystem() == null || path.getFileSystem().provider() == null ) { return false; } return path.getFileSystem().provider().getScheme().equals( "file" ); }
@Override public Path pathToRelatedKModuleFileIfAny( final Path pathToPomXML ) { final org.kie.commons.java.nio.file.Path directory = paths.convert( pathToPomXML ).getParent(); final org.kie.commons.java.nio.file.Path pathToKModuleXML = directory.resolve( "src/main/resources/META-INF/kmodule.xml" ); if ( ioService.exists( pathToKModuleXML ) ) { return paths.convert( pathToKModuleXML ); } else { return null; } }
@Override public boolean isPom( final Path resource ) { //Null resource paths cannot resolve to a Project if ( resource == null ) { return false; } //Check if path equals pom.xml final Path projectRoot = resolveProject( resource ); final org.kie.commons.java.nio.file.Path path = paths.convert( resource ).normalize(); final org.kie.commons.java.nio.file.Path pomFilePath = paths.convert( projectRoot ).resolve( POM_PATH ); return path.startsWith( pomFilePath ); }
org.kie.commons.java.nio.file.Path path = paths.convert( resource ).normalize(); path = path.getParent(); while ( path.getNameCount() > 0 && !path.getFileName().toString().equals( SOURCE_FILENAME ) ) { path = path.getParent(); if ( path.getNameCount() == 0 ) { return null; path = path.getParent(); if ( path.getNameCount() == 0 || path == null ) { return null;
public List<BreadCrumb> makeBreadCrumbs( final Path path, final List<org.kie.commons.java.nio.file.Path> exclusions, final Map<org.kie.commons.java.nio.file.Path, String> captionSubstitutions ) { final List<BreadCrumb> breadCrumbs = new ArrayList<BreadCrumb>(); org.kie.commons.java.nio.file.Path nioPath = paths.convert( path ); org.kie.commons.java.nio.file.Path nioFileName = nioPath.getFileName(); while ( nioFileName != null ) { if ( includePath( nioPath, exclusions ) ) { String caption = nioFileName.toString(); if ( captionSubstitutions.containsKey( nioPath ) ) { caption = captionSubstitutions.get( nioPath ); } final BreadCrumb breadCrumb = new BreadCrumb( paths.convert( nioPath ), caption ); breadCrumbs.add( 0, breadCrumb ); } nioPath = nioPath.getParent(); nioFileName = nioPath.getFileName(); } breadCrumbs.add( 0, new BreadCrumb( paths.convert( nioPath ), getRootDirectory( nioPath ) ) ); return breadCrumbs; }
@Test public void testParent() throws URISyntaxException { final URL parentUrl = this.getClass().getResource( "/" ); final org.kie.commons.java.nio.file.Path parentNioPath = fs.getPath( parentUrl.toURI() ); final URL childUrl = this.getClass().getResource( "/ExplorerBackendTestProjectStructureValid" ); final org.kie.commons.java.nio.file.Path childNioPath = fs.getPath( childUrl.toURI() ); final org.kie.commons.java.nio.file.Path childParentNioPath = childNioPath.getParent(); assertEquals( parentNioPath, childParentNioPath ); }
@Test public void testGetPath() { final URI newRepo = URI.create( "git://new-get-repo-name" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final Path path = PROVIDER.getPath( URI.create( "git://master@new-get-repo-name/home" ) ); assertThat( path ).isNotNull(); assertThat( path.getRoot().toString() ).isEqualTo( "/" ); assertThat( path.getRoot().toRealPath().toUri().toString() ).isEqualTo( "git://master@new-get-repo-name/" ); assertThat( path.toString() ).isEqualTo( "/home" ); final Path pathRelative = PROVIDER.getPath( URI.create( "git://master@new-get-repo-name/:home" ) ); assertThat( pathRelative ).isNotNull(); assertThat( pathRelative.toRealPath().toUri().toString() ).isEqualTo( "git://master@new-get-repo-name/:home" ); assertThat( pathRelative.getRoot().toString() ).isEqualTo( "" ); assertThat( pathRelative.toString() ).isEqualTo( "home" ); }