@Override public Path getPath(final URI uri) throws IllegalArgumentException, FileSystemNotFoundException, SecurityException { checkNotNull("uri", uri); checkCondition("uri scheme not supported", uri.getScheme().equals(getScheme()) || uri.getScheme().equals("default")); return getDefaultFileSystem().getPath(uri.getPath()); }
@PostConstruct public void setup() { Path defaultRoot = null; for (final Path path : fs.getRootDirectories()) { if (path.toUri().toString().contains("/master@")) { defaultRoot = path; break; } } if (defaultRoot == null) { throw new RuntimeException("Could not resolve 'systemFS' main root directory."); } // enable monitor by default if (System.getProperty(MONITOR_DISABLED) == null) { watchService = fs.newWatchService(); configUpdates = new CheckConfigurationUpdates(watchService); final ConfigServiceWatchServiceExecutor configServiceWatchServiceExecutor = getWatchServiceExecutor(); jobs.add(executorService.submit(new DescriptiveRunnable() { @Override public String getDescription() { return configUpdates.getDescription(); } @Override public void run() { configUpdates.execute(configServiceWatchServiceExecutor); } })); } }
public Path getPath(Path path, String version) throws URISyntaxException { String authority = path.toUri().getAuthority(); // master@uf-playground authority = version + authority.substring(authority.indexOf("@")); String scheme = path.getFileSystem().provider().getScheme(); // git String rawPath = path.toUri().getRawPath(); // projectname/org/something/file.txt String uri = scheme + "://" + authority + rawPath; return ioService.get(new URI(uri)); }
public static FileSystem convert(final org.uberfire.java.nio.file.FileSystem fs) { if (!cache.containsKey(fs)) { final Map<String, String> roots = new HashMap<>(); for (final org.uberfire.java.nio.file.Path root : fs.getRootDirectories()) { roots.put(root.toUri().toString(), root.getFileName() == null ? "/" : root.getFileName().toString()); } cache.put(fs, FileSystemFactory.newFS(roots, fs.supportedFileAttributeViews())); } return cache.get(fs); }
private void cleanupDeletedFS(FileSystem fs) { WatchService ws = watchServicesByFS.remove(fs.getName()); if (ws != null && !ws.isClose()) { ws.close(); } fs.getRootDirectories().forEach(rootPath -> indexEngine.delete(KObjectUtil.toKCluster(rootPath))); }
@Before public void setup() throws Exception { rootUri = new URI(ROOT_URI); when(fileSystem.supportedFileAttributeViews()).thenReturn(FS_ATTRIBUTES); when(rootPath.toUri()).thenReturn(rootUri); when(rootPath.getFileSystem()).thenReturn(fileSystem); doAnswer((Answer<org.uberfire.java.nio.file.Path>) invocationOnMock -> { final URI arg = (URI) invocationOnMock.getArguments()[0]; return arg.toURL().toString().equals(ROOT_URI) ? rootPath : null; }).when(ioService).get(any(URI.class)); tested = new VFSServicesServerImpl(ioService); }
public void createDeploymentDescriptor( @Observes NewProjectEvent newProjectEvent ) { KieProject project = (KieProject) newProjectEvent.getProject(); URI projectRootURI = URI.create( project.getRootPath().toURI() ); String repositoryAlias = projectRootURI.getHost(); String metaInfPath = Paths.convert( project.getKModuleXMLPath() ).getParent().toUri().toString(); String separator = Paths.convert( project.getRootPath() ).getFileSystem().getSeparator(); String deploymentDescriptorPath = metaInfPath + separator + "kie-deployment-descriptor.xml"; Path ddVFSPath = ioService.get( URI.create( deploymentDescriptorPath ) ); if ( !ioService.exists( ddVFSPath ) ) { DeploymentDescriptor dd = new DeploymentDescriptorManager( "org.jbpm.domain" ).getDefaultDescriptor(); Set<String> groups = new HashSet<String>( project.getGroups() ); Repository repo = repositoryService.getRepository( repositoryAlias ); if ( repo != null ) { groups.addAll( repo.getGroups() ); } dd.getBuilder().setRequiredRoles( new ArrayList<String>( groups ) ); String xmlDescriptor = dd.toXml(); ioService.write( ddVFSPath, xmlDescriptor ); } }
public void configurePackage(@Observes NewPackageEvent pkg) { if (isCaseProject(Paths.convert(pkg.getPackage().getModuleRootPath()))) { String resourcesPathStr = Paths.convert(pkg.getPackage().getPackageMainResourcesPath()).toUri().toString(); String separator = Paths.convert(pkg.getPackage().getModuleRootPath()).getFileSystem().getSeparator(); Path resourcesPath = ioService.get(URI.create(resourcesPathStr + separator + WORK_DEFINITION_FILE)); addWorkDefinitions(resourcesPath); } }
@SuppressWarnings("unchecked") private WatchEvent<?> mockWatchEvent(WatchEvent.Kind kind, String originalPathURI, String newPathURI, String sessionId, String userId, String commitMessage) throws URISyntaxException { WatchEvent<?> event = mock(WatchEvent.class); when(event.kind()).thenReturn(kind); FileSystem fileSystem = mock(FileSystem.class); Set<String> supportedViews = new HashSet<>(); when(fileSystem.supportedFileAttributeViews()).thenReturn(supportedViews); WatchContext context = mock(WatchContext.class); when(context.getSessionId()).thenReturn(sessionId); when(context.getUser()).thenReturn(userId); when(context.getMessage()).thenReturn(commitMessage); Path oldPath = mock(Path.class); URI oldPathUri = new URI(originalPathURI); when(oldPath.toUri()).thenReturn(oldPathUri); when(oldPath.getFileSystem()).thenReturn(fileSystem); Path path = mock(Path.class); URI pathUri = new URI(newPathURI); when(path.toUri()).thenReturn(pathUri); when(path.getFileSystem()).thenReturn(fileSystem); when(context.getOldPath()).thenReturn(oldPath); when(context.getPath()).thenReturn(path); when(event.context()).thenReturn(context); return event; }
@Test public void testMoveAndAddOnBatchShouldTriggerRenameAndModifyEvent() { final Path init = ioService.get(URI.create("git://amend-repo-test/file.txt")); final Path initMoved = ioService.get(URI.create("git://amend-repo-test/fileMoved.txt")); final WatchService ws = init.getFileSystem().newWatchService(); ioService.write(init, "init!", new CommentedOption("User Tester", final Path aNewFile = ioService.get(URI.create("git://amend-repo-test/aNewFile.txt")); final Path aNewFileMoved = ioService.get(URI.create("git://amend-repo-test/aNewFileMoved.txt")); ioService.startBatch(aNewFile.getFileSystem()); ioService.move(aNewFile, aNewFileMoved, new CommentedOption("moved"));
public IOService getIOService() throws Exception { if (ioService == null) { ioService = mock(IOService.class); FileSystem fileSystem = mock(FileSystem.class); Iterable iterable = mock(Iterable.class); Iterator iterator = mock(Iterator.class); Path path = mock(Path.class); when(ioService.newFileSystem(any(URI.class), any(Map.class))).thenReturn(fileSystem); when(ioService.getFileSystem(any(URI.class))).thenReturn(fileSystem); when(fileSystem.getRootDirectories()).thenReturn(iterable); when(fileSystem.supportedFileAttributeViews()).thenReturn(new HashSet<String>()); when(iterable.iterator()).thenReturn(iterator); when(iterator.next()).thenReturn(path); when(path.resolve(anyString())).thenReturn(path); when(path.resolve(any(Path.class))).thenReturn(path); when(path.toUri()).thenReturn(new URI("uri")); when(path.getFileName()).thenReturn(path); when(path.getFileSystem()).thenReturn(fileSystem); } return ioService; } }
@Test public void recreatingFileSystemMakesNewWatchService() throws Exception { URI uri = new URI("test:///some/path"); Map<String, ?> env = Collections.emptyMap(); FileSystem fs1 = ioService.newFileSystem(uri, env); verify(fs1).newWatchService(); FSPath fsPath = mock(FSPath.class); when(fsPath.getFileSystem()).thenReturn(fs1); ioService.delete(fsPath); verify(fs1.newWatchService()).close(); FileSystem fs2 = ioService.newFileSystem(uri, env); // Stubs are reused so this will have been invoked one above in IOService, and once in this test in a verify method. verify(fs2, times(3)).newWatchService(); }
@Test public void testRelativeToURIUnix() { 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/file.txt", false); final URI uri = path.toUri(); assertThat(path).isNotNull(); assertThat(uri).isNotNull(); assertThat(uri.toString()).isEqualTo("default://" + DEFAULT_PATH + "path/to/file.txt"); assertThat(path.toRealPath().toUri().toString()).isEqualTo("file://" + DEFAULT_PATH + "path/to/file.txt"); }
private FileSystem getFileSystem() throws URISyntaxException { URI uri = new URI("test:///some/path"); Map<String, ?> env = Collections.emptyMap(); final FileSystem fileSystem = ioService.newFileSystem(uri, env); final Path fsRootDirectory1 = mock(JGitPathImpl.class); when(fsRootDirectory1.getFileSystem()).thenReturn(fileSystem); when(fsRootDirectory1.getRoot()).thenReturn(fsRootDirectory1); when(((JGitPathImpl) fsRootDirectory1).getAttrStorage()).thenReturn(mock(AttrsStorage.class)); final Path fsRootDirectory2 = mock(JGitPathImpl.class); when(fsRootDirectory2.getFileSystem()).thenReturn(fileSystem); when(fsRootDirectory2.getRoot()).thenReturn(fsRootDirectory2); when(((JGitPathImpl) fsRootDirectory2).getAttrStorage()).thenReturn(mock(AttrsStorage.class)); final Collection<Path> fsRootDirectories = Arrays.asList(fsRootDirectory1, fsRootDirectory2); doReturn(fsRootDirectories).when(fileSystem).getRootDirectories(); return fileSystem; } }
@Override public void addBranch(final String newBranchName, final String baseBranchName, final WorkspaceProject project) { Branch baseBranch = project.getRepository().getBranch(baseBranchName) .orElseThrow(() -> new IllegalStateException("The base branch does not exists")); final org.uberfire.java.nio.file.Path baseBranchPath = pathUtil.convert(baseBranch.getPath()); final String newBranchPathURI = pathUtil.replaceBranch(newBranchName, baseBranch.getPath().toURI()); try { final org.uberfire.java.nio.file.Path newBranchPath = ioService.get(new URI(newBranchPathURI)); baseBranchPath.getFileSystem().provider().copy(baseBranchPath, newBranchPath); repositoryExternalUpdate.fire(new RepositoryExternalUpdateEvent(project.getRepository())); fireNewBranchEvent(pathUtil.convert(newBranchPath), newBranchPath); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
public static Path convert(final org.uberfire.java.nio.file.Path path) { if (path == null) { return null; } if (path.getFileName() == null) { return newPath("/", path.toUri().toString(), new HashMap<String, Object>(1) {{ put(PathFactory.VERSION_PROPERTY, path.getFileSystem().supportedFileAttributeViews().contains("version")); }}); } return newPath(path.getFileName().toString(), path.toUri().toString(), new HashMap<String, Object>(1) {{ put(PathFactory.VERSION_PROPERTY, path.getFileSystem().supportedFileAttributeViews().contains("version")); }}); }
@Test public void deleteOnBatchEventShouldKeepUserInfo() { final Path init = ioService.get(URI.create("git://amend-repo-test/file.txt")); final WatchService ws = init.getFileSystem().newWatchService(); String user = "dora"; String message = "message"; ioService.write(init, "init!", new CommentedOption(user, message)); { List<WatchEvent<?>> events = ws.poll().pollEvents(); } ioService.startBatch(init.getFileSystem()); ioService.delete(init, new CommentedOption(user, message)); ioService.endBatch(); { List<WatchEvent<?>> events = ws.poll().pollEvents(); JGitWatchEvent event = (JGitWatchEvent) events.get(0); WatchContext context = (WatchContext) event.context(); assertEquals(user, context.getUser()); } }
@PostConstruct public void setup() { try { fileSystem = ioService.newFileSystem(URI.create("default://bpmn"), new HashMap<String, Object>() {{ put("init", Boolean.TRUE); put("internal", Boolean.TRUE); }}); } catch (final FileSystemAlreadyExistsException e) { fileSystem = ioService.getFileSystem(URI.create("default://bpmn")); } this.root = fileSystem.getRootDirectories().iterator().next(); ioService.write(root.resolve("file1.bpmn"), BpmnPersistence.getInstance().marshal(new ProcessNode())); saveAndRenameService.init(this); }
@Before public void setup() { // attach test logging appender final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); logger.addAppender(mockAppender); // configure project and kmodule paths when(kmodulePath.toURI()).thenReturn("default://p0/Evaluation/src/main/resources/META-INF/kmodule.xml"); when(projectPath.toURI()).thenReturn("default://p0/Evaluation"); // configure deployment descriptor path when(ddPath.toUri()).thenReturn(URI.create("default://p0/Evaluation/src/main/resources/META-INF/kie-deployment-descriptor.xml")); when(ddPath.getParent()).thenReturn(Mockito.mock(Path.class)); FileSystem fileSystem = Mockito.mock(FileSystem.class); when(fileSystem.supportedFileAttributeViews()).thenReturn(new HashSet<String>()); when(ddPath.getFileSystem()).thenReturn(fileSystem); // configure services when(ioService.get(any(URI.class))).thenReturn(ddPath); when(ddEditorService.load(any())).thenReturn(new DeploymentDescriptorModel()); // configure the project when(kieModule.getKModuleXMLPath()).thenReturn(kmodulePath); when(kieModule.getRootPath()).thenReturn(projectPath); caseProjectService = new CaseProjectServiceImpl(ddEditorService, ioService); }
@Test public void simpleWatcherTest() { final Path init = ioService.get(URI.create("git://amend-repo-test/dora1.txt")); final WatchService ws = init.getFileSystem().newWatchService(); ioService.write(init, "init!"); { List<WatchEvent<?>> events = ws.poll().pollEvents(); WatchEvent.Kind<?> kind = events.get(0).kind(); assertEquals(kind.name(), StandardWatchEventKind.ENTRY_CREATE.name()); assertEquals(1, events.size()); } ioService.write(init, "init 2!"); { List<WatchEvent<?>> events = ws.poll().pollEvents(); WatchEvent.Kind<?> kind = events.get(0).kind(); assertEquals(kind.name(), StandardWatchEventKind.ENTRY_MODIFY.name()); assertEquals(1, events.size()); } } }