public static Path dot( final Path path ) { if ( path.getFileName() == null ) { return path.resolve( ".root" ); } return path.resolveSibling( "." + path.getFileName() ); }
private boolean hasPom( final org.kie.commons.java.nio.file.Path path ) { final org.kie.commons.java.nio.file.Path pomPath = path.resolve( POM_PATH ); return Files.exists( pomPath ); }
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 ); }
@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" ) ); }
@Override protected Path convertPath( final String fileName, final String contextPath ) throws URISyntaxException { final org.kie.commons.java.nio.file.Path path = ioService.get( new URI( contextPath ) ); return paths.convert( path.resolve( fileName ), false ); }
@Test(expected = FileAlreadyExistsException.class) public void createDirectoriesFileAlreadyExistsException() { final Path path = getDirectoryPath().resolveSibling( "otherDir" ).resolve( "innerDir" ); ioService().deleteIfExists( path ); ioService().createDirectories( path ); ioService().createDirectories( path ); }
private Path getProjectRootPath( final Path fsRoot, final String projectName ) { return paths.convert( paths.convert( fsRoot ).resolve( projectName ), false ); }
@Test(expected = DirectoryNotEmptyException.class) public void deleteDirectoryNotEmptyException() { final Path path = getDirectoryPath().resolveSibling( "dirToBug" ); ioService().createDirectories( path ); ioService().write( path.resolve( "myFile.txt" ), "ooooo!" ); ioService().delete( path ); }
@Override public Path newDirectory( final Path contextPath, final String dirName ) { final Path directoryPath = paths.convert( ioService.createDirectory( paths.convert( contextPath ).resolve( dirName ) ) ); //Signal creation to interested parties resourceAddedEvent.fire( new ResourceAddedEvent( directoryPath ) ); return directoryPath; }
@Test(expected = DirectoryNotEmptyException.class) public void deleteIfExistsDirectoryNotEmptyException() { final Path path = getDirectoryPath().resolveSibling( "dirToBugIfExists" ); ioService().createDirectories( path ); ioService().write( path.resolve( "myFile.txt" ), "ooooo!" ); ioService().deleteIfExists( path ); }
@Override public Path resolvePathToPom( final Path resource ) { final Path projectPath = resolveProject( resource ); if ( projectPath == null ) { return null; } final org.kie.commons.java.nio.file.Path pom = paths.convert( projectPath ).resolve( POM_PATH ); if ( pom == null ) { return null; } return paths.convert( pom ); }
@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 ); }
@Override public Categories getCategoriesFromResource( final Path resource ) { final org.kie.commons.java.nio.file.Path categoriesPath = paths.convert( resource ).getRoot().resolve( "categories.xml" ); return getContent( paths.convert( categoriesPath ) ); } }
@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 Path getTargetPath() { try { final File dir = createTempDirectory(); return ioService().get( dir.toURI() ).resolve( "myTargetFile.txt" ); } catch ( IOException e ) { throw new RuntimeException( e ); } }
@Override public Path getComposedDirectoryPath() { try { final File dir = createTempDirectory(); return ioService().get( dir.toURI() ).resolve( "path/to/myDir" ); } catch ( IOException e ) { throw new RuntimeException( e ); } }
@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 ); }
@Override public boolean isKModule( final Path resource ) { //Null resource paths cannot resolve to a Project if ( resource == null ) { return false; } //Check if path equals kmodule.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 kmoduleFilePath = paths.convert( projectRoot ).resolve( KMODULE_PATH ); return path.startsWith( kmoduleFilePath ); }
@Override public Path getFilePath() { try { final File dir = createTempDirectory(); return ioService().get( dir.toURI() ).resolve( "myTempFile.txt" ); } catch ( IOException e ) { throw new RuntimeException( e ); } }
@Override public Path getDirectoryPath() { try { final File dir = createTempDirectory(); return ioService().get( dir.toURI() ).resolve( "myDir" ); } catch ( IOException e ) { throw new RuntimeException( e ); } }