@Override public Repository getRepository(String alias) { Repository result = repositoryService.getRepository(alias); remoteCallback.callback(result); return result; }
@Override public Repository getRepository(Path root) { Repository result = repositoryService.getRepository(root); remoteCallback.callback(result); return result; }
private void fireNewBranchEvent(final Path targetRoot, final org.uberfire.java.nio.file.Path nioTargetRepositoryRoot) { final Repository repository = repoService.getRepository(targetRoot); final Optional<Branch> branch = repository.getBranch(Paths.convert(nioTargetRepositoryRoot.getRoot())); if (branch.isPresent()) { newBranchEvent.fire(new NewBranchEvent(repository, branch.get().getName(), sessionInfo.getIdentity())); } else { throw new IllegalStateException("Could not find a branch that was just created. The Path used was " + nioTargetRepositoryRoot.getRoot()); } }
@Override public Repository getRepository(Space space, Path root) { Repository result = repositoryService.getRepository(space, root); remoteCallback.callback(result); return result; }
@Override public Repository getRepository(Path root) { Repository result = repositoryService.getRepository(root); remoteCallback.callback(result); return result; }
@Before public void setUp() throws Exception { when(repositoryService.getRepository("repositoryAlias")).thenReturn(repository); }
private void fireNewBranchEvent(final Path targetRoot, final org.uberfire.java.nio.file.Path nioTargetRepositoryRoot) { configuredRepositories.reloadRepositories(); final Repository repository = repositoryService.getRepository(targetRoot); final Optional<Branch> branch = repository.getBranch(Paths.convert(nioTargetRepositoryRoot.getRoot())); if (branch.isPresent()) { newBranchEventEvent.fire(new NewBranchEvent(repository, branch.get().getName(), sessionInfo.getIdentity())); } else { throw new IllegalStateException("Could not find a branch that was just created. The Path used was " + nioTargetRepositoryRoot.getRoot()); } }
private void fireNewBranchEvent(final Space space, final Path targetRoot, final org.uberfire.java.nio.file.Path nioTargetRepositoryRoot) { configuredRepositories.reloadRepositories(); final Repository repository = repositoryService.getRepository(space, targetRoot); final Optional<Branch> branch = repository.getBranch(Paths.convert(nioTargetRepositoryRoot.getRoot())); if (branch.isPresent()) { newBranchEventEvent.fire(new NewBranchEvent(repository, branch.get().getName(), sessionInfo.getIdentity())); } else { throw new IllegalStateException("Could not find a branch that was just created. The Path used was " + nioTargetRepositoryRoot.getRoot()); } }
@Override public String execute(CliContext context) { StringBuffer result = new StringBuffer(); WeldContainer container = context.getContainer(); RepositoryService repositoryService = container.instance().select(RepositoryService.class).get(); InputReader input = context.getInput(); System.out.print(">>Repository alias:"); String alias = input.nextLine(); Repository repo = repositoryService.getRepository(alias); if (repo == null) { return "No repository " + alias + " was found, exiting"; } repositoryService.removeRepository(alias); result.append("Repository " + alias + " was removed successfully"); container.getBeanManager().fireEvent(new SystemRepositoryChangedEvent(), new AnnotationLiteral<OrgUnit>() {}); return result.toString(); }
@Test public void testGetBranches() { List<String> branches = new ArrayList<>(); branches.add("branch1"); branches.add("branch2"); branches.add("branch3"); Repository repository = mock(Repository.class); when(repository.getBranches()).thenReturn(branches); when(repositoryService.getRepository(REPO_NAME)).thenReturn(repository); Collection<String> result = service.getBranches(REPO_NAME); assertEquals(branches, result); }
@Test public void testProjects() { Repository repository = mock(Repository.class); @SuppressWarnings("unchecked") Set<Project> projects = mock(Set.class); when(repositoryService.getRepository(REPO_NAME)).thenReturn(repository); when(projectService.getProjects(repository, BRANCH_NAME)).thenReturn(projects); Collection<Project> result = service.getProjects(REPO_NAME, BRANCH_NAME); assertEquals(projects, result); }
@Before public void setUp() throws Exception { fileSystemProvider = new SimpleFileSystemProvider(); final Repository repository = mock(Repository.class); when(repositoryService.getRepository("myRepository")).thenReturn(repository); when(repository.getDefaultBranch()).thenReturn("master"); final Path root = fileSystemProvider.getPath(URI.create("default://master@myRepository/")); when(repository.getBranchRoot("master")).thenReturn(Paths.convert(root)); }
@Test public void testUseRepoServiceToDeleteRootModule() { when(path.getFileName()).thenReturn("pom.xml"); when(path.toURI()).thenReturn("file:///space/project1/pom.xml"); when(resourceResolver.resolveModule(any(Path.class))).thenReturn(module); when(pomService.load(any())).thenReturn(mock(POM.class)); Repository repo = mock(Repository.class); when(repoService.getRepository(eq(org.uberfire.backend.server.util.Paths.convert(Paths.get("file:///space/project1"))))).thenReturn(repo); String alias = "repo-alias"; when(repo.getAlias()).thenReturn(alias); Space space = new Space("space"); when(repo.getSpace()).thenReturn(space); abstractProjectService.delete(path, ""); verify(repoService).removeRepository(eq(space), eq(alias)); verify(ioService, times(0)).delete(any(), any()); }
@Test public void testUseRepoServiceToDeleteRootModule() { when(path.getFileName()).thenReturn("pom.xml"); when(path.toURI()).thenReturn("file:///space/project1/pom.xml"); when(resourceResolver.resolveModule(any(Path.class))).thenReturn(module); when(pomService.load(any())).thenReturn(mock(POM.class)); Repository repo = mock(Repository.class); when(repoService.getRepository(eq(org.uberfire.backend.server.util.Paths.convert(Paths.get("file:///space/project1"))))).thenReturn(repo); String alias = "repo-alias"; when(repo.getAlias()).thenReturn(alias); Space space = new Space("space"); when(repo.getSpace()).thenReturn(space); abstractProjectService.delete(path, ""); verify(repoService).removeRepository(eq(space), eq(alias)); verify(ioService, times(0)).delete(any(), any()); }
@Override public void bootstrapProject( String repoAlias, String group, String artifact, String version ) { GAV gav = new GAV( group, artifact, version ); try { Repository repository = repositoryService.getRepository( repoAlias ); if ( repository != null ) { String projectLocation = repository.getUri() + ioService.getFileSystem( URI.create( repository.getUri() ) ).getSeparator() + artifact; if ( !ioService.exists( ioService.get( URI.create( projectLocation ) ) ) ) { projectService.newProject( repository.getBranchRoot( repository.getDefaultBranch() ), new POM( gav ), "/" ); } } else { logger.error( "Repository " + repoAlias + " was not found, cannot add project" ); } } catch ( Exception e ) { logger.error( "Unable to bootstrap project {} in repository {}", gav, repoAlias, e ); } }
@Test public void testUseIOServiceToDeleteSubModule() { when(path.getFileName()).thenReturn("pom.xml"); when(path.toURI()).thenReturn("file://space/project1/subproject/pom.xml"); when(ioService.exists(any())).thenReturn(true); when(resourceResolver.resolveModule(any(Path.class))).thenReturn(module); when(pomService.load(any())).thenReturn(mock(POM.class)); Repository repo = mock(Repository.class); when(repoService.getRepository(path)).thenReturn(repo); String alias = "repo-alias"; when(repo.getAlias()).thenReturn(alias); Space space = new Space("space"); when(repo.getSpace()).thenReturn(space); abstractProjectService.delete(path, ""); verify(repoService, times(0)).removeRepository(any(), any()); verify(ioService).delete(eq(Paths.get("file://space/project1/subproject")), anyVararg()); } }
@Test public void testUseIOServiceToDeleteSubModule() { when(path.getFileName()).thenReturn("pom.xml"); when(path.toURI()).thenReturn("file://space/project1/subproject/pom.xml"); when(ioService.exists(any())).thenReturn(true); when(resourceResolver.resolveModule(any(Path.class))).thenReturn(module); when(pomService.load(any())).thenReturn(mock(POM.class)); Repository repo = mock(Repository.class); when(repoService.getRepository(path)).thenReturn(repo); String alias = "repo-alias"; when(repo.getAlias()).thenReturn(alias); Space space = new Space("space"); when(repo.getSpace()).thenReturn(space); abstractProjectService.delete(path, ""); verify(repoService, times(0)).removeRepository(any(), any()); verify(ioService).delete(eq(Paths.get("file://space/project1/subproject")), anyVararg()); } }
@Override public ProjectExplorerContent getContent(final String _path, final ActiveOptions activeOptions) { checkNotEmpty("path", _path); final Path path = Paths.convert(ioService.get(URI.create(_path.trim()))); final Module module = moduleService.resolveModule(path); final Path convertedPath = Paths.convert(Paths.convert(path).getRoot()); final Repository repo = repositoryService.getRepository(convertedPath); final Branch branch = getBranch(repo, convertedPath); return getContent(new ProjectExplorerContentQuery(repo, branch, module, activeOptions)); }
@Override public WorkspaceProject resolveProject(final Space space, final Path path) { final org.uberfire.java.nio.file.Path repositoryRoot = Paths.convert(path).getRoot(); final Repository repository = repositoryService.getRepository(space, Paths.convert(repositoryRoot)); final Branch branch = resolveBranch(repositoryRoot, repository); return new WorkspaceProject(organizationalUnitService.getOrganizationalUnit(repository.getSpace().getName()), repository, branch, moduleService.resolveModule(Paths.convert(Paths.convert(branch.getPath()).getRoot()))); }
@Override public WorkspaceProject resolveProject(final Space space, final Path path) { final org.uberfire.java.nio.file.Path repositoryRoot = Paths.convert(path).getRoot(); final Repository repository = repositoryService.getRepository(space, Paths.convert(repositoryRoot)); final Branch branch = resolveBranch(repositoryRoot, repository); return new WorkspaceProject(organizationalUnitService.getOrganizationalUnit(repository.getSpace().getName()), repository, branch, moduleService.resolveModule(Paths.convert(Paths.convert(branch.getPath()).getRoot()))); }