private void assertContainsPath( Path path, List<Item> items ) { boolean found = false; for ( Item item : items ) { if ( path.equals( item.getPath() ) ) { found = true; } } assertTrue( "Find path", found ); }
private void assertContainsCaption( String caption, List<Item> items ) { boolean found = false; for ( Item item : items ) { if ( caption.equals( item.getCaption() ) ) { found = true; } } assertTrue( "Find caption", found ); }
private ExplorerContent makeOutsideProjectList( final Path path, final Path projectRoot ) { final List<Item> items = outsideProjectListLoader.load( path, projectRoot ); final List<BreadCrumb> breadCrumbs = breadCrumbFactory.makeBreadCrumbs( path, breadCrumbUtilities.makeBreadCrumbExclusions( path ) ); return new ExplorerContent( items, breadCrumbs ); }
final List<Item> items = result.getItems(); assertEquals( 5, items.size() ); items.get( 0 ).getCaption() ); assertEquals( "External imports", items.get( 1 ).getCaption() ); assertEquals( ItemNames.SOURCE_JAVA, items.get( 2 ).getCaption() ); assertEquals( ItemNames.SOURCE_RESOURCES, items.get( 3 ).getCaption() ); assertEquals( "..", items.get( 4 ).getCaption() ); items.get( 0 ).getPath() ); assertEquals( makePath( "/ExplorerBackendTestProjectStructureValid/project.imports" ), items.get( 1 ).getPath() ); assertEquals( makePath( "/ExplorerBackendTestProjectStructureValid/src/main/java" ), items.get( 2 ).getPath() ); assertEquals( makePath( "/ExplorerBackendTestProjectStructureValid/src/main/resources" ), items.get( 3 ).getPath() ); assertEquals( makePath( "/" ), items.get( 4 ).getPath() ); List<BreadCrumb> breadCrumbs = result.getBreadCrumbs(); assertNotNull( breadCrumbs ); breadCrumbIndex--; assertEquals( "ExplorerBackendTestProjectStructureValid",
items.add( new FileItem( paths.convert( pChild ) ) ); items.add( new ProjectItem( paths.convert( pChild ) ) ); } else { items.add( new FolderItem( paths.convert( pChild ) ) ); items.add( new ParentFolderItem( paths.convert( pPath.getParent() ), ".." ) );
final List<Item> items = result.getItems(); assertEquals( 3, items.size() ); List<BreadCrumb> breadCrumbs = result.getBreadCrumbs(); assertNotNull( breadCrumbs ); breadCrumbIndex--; assertEquals( ItemNames.SOURCE_RESOURCES, breadCrumbs.get( breadCrumbIndex ).getCaption() ); assertEquals( makePath( "/ExplorerBackendTestProjectStructureValid/src/main/resources" ), breadCrumbs.get( breadCrumbIndex ).getPath() ); breadCrumbIndex--; assertEquals( "ExplorerBackendTestProjectStructureValid", breadCrumbs.get( breadCrumbIndex ).getCaption() ); assertEquals( makePath( "/ExplorerBackendTestProjectStructureValid" ), breadCrumbs.get( breadCrumbIndex ).getPath() );
final String projectName = pRoot.getFileName().toString(); if ( Files.exists( pomPath ) ) { items.add( new FileItem( paths.convert( pomPath ), "Project definition '" + projectName + "'" ) ); items.add( new FileItem( paths.convert( projectImportsPath ), "External imports" ) ); items.add( new FolderItem( paths.convert( srcJavaResourcesPath ), ItemNames.SOURCE_JAVA ) ); items.add( new FolderItem( paths.convert( srcResourcesPath ), ItemNames.SOURCE_RESOURCES ) ); items.add( new FolderItem( paths.convert( testJavaResourcesPath ), ItemNames.TEST_JAVA ) ); items.add( new FolderItem( paths.convert( testResourcesPath ), ItemNames.TEST_RESOURCES ) ); items.add( new ParentFolderItem( paths.convert( pRoot.getParent() ), ".." ) );
@Override public List<Item> load( final Path path, final Path projectRoot ) { //Check Path exists final List<Item> items = new ArrayList<Item>(); if ( !Files.exists( paths.convert( path ) ) ) { return items; } //Ensure Path represents a Folder org.kie.commons.java.nio.file.Path pPath = paths.convert( path ); if ( !Files.isDirectory( pPath ) ) { pPath = pPath.getParent(); } //Get list of immediate children final DirectoryStream<org.kie.commons.java.nio.file.Path> directoryStream = ioService.newDirectoryStream( pPath ); for ( final org.kie.commons.java.nio.file.Path p : directoryStream ) { if ( filter.accept( p ) ) { if ( Files.isRegularFile( p ) ) { items.add( new FileItem( paths.convert( p ) ) ); } else if ( Files.isDirectory( p ) ) { items.add( new PackageItem( paths.convert( p ) ) ); } } } //Add ability to move up one level in the hierarchy items.add( new ParentPackageItem( paths.convert( pPath.getParent() ), ".." ) ); return items; }
@Test public void testContentInScopeNonProjectPath() throws Exception { final Bean explorerServiceBean = (Bean) beanManager.getBeans( ExplorerService.class ).iterator().next(); final CreationalContext cc = beanManager.createCreationalContext( explorerServiceBean ); final ExplorerService explorerService = (ExplorerService) beanManager.getReference( explorerServiceBean, ExplorerService.class, cc ); final URL testUrl = this.getClass().getResource( "/" ); final org.kie.commons.java.nio.file.Path testNioPath = fs.getPath( testUrl.toURI() ); final Path testPath = paths.convert( testNioPath ); //Depending on where this Test runs the actual results are undetermined as the VFS root is in a sub-folder on the hosts actual FS final ExplorerContent result = explorerService.getContentInScope( testPath ); assertNotNull( result ); assertTrue( result.getItems().size() > 0 ); assertTrue( result.getBreadCrumbs().size() > 0 ); //But there should be a single Project called 'ProjectStructureValid' boolean fail = true; for ( final Item item : result.getItems() ) { if ( item instanceof ProjectItem ) { assertEquals( "ExplorerBackendTestProjectStructureValid", item.getCaption() ); if ( fail == false ) { fail( "There should be only one ProjectItem called 'ProjectStructureValid'" ); } fail = false; } } }
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; }
final List<Item> items = result.getItems(); assertEquals( 2, items.size() ); items.get( 0 ).getCaption() ); assertEquals( "..", items.get( 1 ).getCaption() ); items.get( 0 ).getPath() ); assertEquals( makePath( "/ExplorerBackendTestProjectStructureValid/src/main/resources/org/kie" ).toURI(), items.get( 1 ).getPath().toURI() ); List<BreadCrumb> breadCrumbs = result.getBreadCrumbs(); assertNotNull( breadCrumbs ); breadCrumbIndex--; assertEquals( "test", breadCrumbs.get( breadCrumbIndex ).getCaption() ); assertEquals( makePath( "/ExplorerBackendTestProjectStructureValid/src/main/resources/org/kie/test" ), breadCrumbs.get( breadCrumbIndex ).getPath() ); breadCrumbIndex--; assertEquals( "kie", breadCrumbs.get( breadCrumbIndex ).getCaption() ); assertEquals( makePath( "/ExplorerBackendTestProjectStructureValid/src/main/resources/org/kie" ), breadCrumbs.get( breadCrumbIndex ).getPath() ); breadCrumbIndex--; assertEquals( "org", breadCrumbs.get( breadCrumbIndex ).getCaption() ); assertEquals( makePath( "/ExplorerBackendTestProjectStructureValid/src/main/resources/org" ),
private ExplorerContent makeProjectNonPackageList( final Path path, final Path projectRoot ) { final List<Item> items = projectNonPackageListLoader.load( path, projectRoot ); final List<BreadCrumb> breadCrumbs = breadCrumbFactory.makeBreadCrumbs( path, breadCrumbUtilities.makeBreadCrumbExclusions( path ) ); return new ExplorerContent( items, breadCrumbs ); }
private void assertContainsPathUri( String pathUri, List<Item> items ) { boolean found = false; for ( Item item : items ) { if ( pathUri.equals( item.getPath().toURI() ) ) { found = true; } } assertTrue( "Find path uri", found ); }
private ExplorerContent makeProjectRootList( final Path path, final Path projectRoot ) { final List<Item> items = projectRootListLoader.load( path, projectRoot ); final List<BreadCrumb> breadCrumbs = breadCrumbFactory.makeBreadCrumbs( path, breadCrumbUtilities.makeBreadCrumbExclusions( path ) ); return new ExplorerContent( items, breadCrumbs ); }
private ExplorerContent makeProjectPackageList( final Path path, final Path projectRoot ) { final List<Item> items = projectPackageListLoader.load( path, projectRoot ); final List<BreadCrumb> breadCrumbs = breadCrumbFactory.makeBreadCrumbs( path, breadCrumbUtilities.makeBreadCrumbExclusions( path ), breadCrumbUtilities.makeBreadCrumbCaptionSubstitutionsForDefaultPackage( path ) ); return new ExplorerContent( items, breadCrumbs ); }