org.guvnor.structure.repositories.Repository.getBranch()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(11.6k)|赞(0)|评价(0)|浏览(116)

本文整理了Java中org.guvnor.structure.repositories.Repository.getBranch方法的一些代码示例,展示了Repository.getBranch的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Repository.getBranch方法的具体详情如下:
包路径:org.guvnor.structure.repositories.Repository
类名称:Repository
方法名:getBranch

Repository.getBranch介绍

[英]Returns "read-only" view of all branches available in this repository.
[中]返回此存储库中所有可用分支的“只读”视图。

代码示例

代码示例来源:origin: org.kie.workbench.screens/kie-wb-common-examples-screen-backend

@Override
public Set<ImportProject> getProjects(final ExampleRepository repository) {
  if (repository == null) {
    return Collections.emptySet();
  }
  final String repositoryURL = repository.getUrl();
  if (repositoryURL == null || repositoryURL.trim().isEmpty()) {
    return Collections.emptySet();
  }
  Repository gitRepository = resolveGitRepository(repository);
  if (gitRepository == null) {
    return Collections.emptySet();
  }
  Set<ImportProject> importProjects = convert(gitRepository.getBranch("master").get(),
                        repository);
  return validateProjects(importProjects);
}

代码示例来源:origin: org.uberfire/uberfire-structure-backend

@Test
public void testLoadMultiBranch() throws Exception {
  final Repository single = configuredRepositories.getRepositoryByRepositoryAlias(SPACE1,
                                          REPO2S1);
  assertEquals(3,
         single.getBranches().size());
  assertNotNull(single.getBranch("master"));
  assertNotNull(single.getBranch("dev"));
  assertNotNull(single.getBranch("release"));
}

代码示例来源:origin: kiegroup/appformer

@Test
public void testLoadMultiBranch() throws Exception {
  final Repository single = configuredRepositories.getRepositoryByRepositoryAlias(SPACE1,
                                          REPO2S1);
  assertEquals(3,
         single.getBranches().size());
  assertNotNull(single.getBranch("master"));
  assertNotNull(single.getBranch("dev"));
  assertNotNull(single.getBranch("release"));
}

代码示例来源:origin: org.kie.workbench.screens/kie-wb-common-library-backend

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());
  }
}

代码示例来源:origin: org.uberfire/uberfire-structure-backend

@Test
public void testLoadSingle() throws Exception {
  final Repository single = configuredRepositories.getRepositoryByRepositoryAlias(SPACE1,
                                          REPO1S1);
  assertEquals(1,
         single.getBranches().size());
  assertNotNull(single.getBranch("master"));
}

代码示例来源:origin: kiegroup/appformer

public void onNewBranch(final @Observes NewBranchEvent event) {
  for (final GuvnorStructureContextChangeHandler handler : handlers.values()) {
    final Optional<Branch> branchOptional = event.getRepository().getBranch(event.getNewBranchName());
    if (branchOptional.isPresent()) {
      handler.onNewBranchAdded(event.getRepository().getAlias(),
                   event.getNewBranchName(),
                   branchOptional.get().getPath());
    }
  }
}

代码示例来源:origin: kiegroup/appformer

@Test
public void testLoadSingle() throws Exception {
  final Repository single = configuredRepositories.getRepositoryByRepositoryAlias(SPACE1,
                                          REPO1S1);
  assertEquals(1,
         single.getBranches().size());
  assertNotNull(single.getBranch("master"));
}

代码示例来源:origin: org.kie.workbench.screens/kie-wb-common-library-client

public void newBranchEvent(@Observes final NewBranchEvent newBranchEvent) {
  final User user = newBranchEvent.getUser();
  final Repository repository = newBranchEvent.getRepository();
  if (libraryPlaces.isThisUserAccessingThisRepository(user, repository)) {
    libraryPlaces.goToProject(libraryPlaces.getActiveWorkspace(), repository.getBranch(newBranchEvent.getNewBranchName()).get());
  }
}

代码示例来源:origin: org.kie.workbench.screens/kie-wb-common-library-api

private WorkspaceProject makeProject(final String spaceName,
                   final String repoAlias,
                   final String... branchNames) {
  final Space space = mock(Space.class);
  final Repository repository = mock(Repository.class);
  final WorkspaceProject project = mock(WorkspaceProject.class);
  doReturn(space).when(project).getSpace();
  doReturn(repository).when(project).getRepository();
  doReturn(spaceName).when(space).getName();
  doReturn(repoAlias).when(repository).getAlias();
  final List<Branch> branches = new ArrayList<>();
  for (String branchName : branchNames) {
    branches.add(makeBranch(branchName));
  }
  doReturn(branches).when(repository).getBranches();
  doAnswer(invocationOnMock -> branches.stream().filter(b -> b.getName().equals(invocationOnMock.getArgumentAt(0, String.class))).findFirst()).when(repository).getBranch(anyString());
  return project;
}

代码示例来源:origin: kiegroup/appformer

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());
  }
}

代码示例来源:origin: kiegroup/appformer

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());
  }
}

代码示例来源:origin: kiegroup/appformer

@Override
public void addNewRepository(final Repository repository,
               final String branchName) {
  final FSTreeItem repositoryRootItem = rootTreeItem.addItem(FSTreeItem.FSType.FOLDER,
                                repository.getAlias());
  repositoryRootItem.setUserObject(repository);
  repositoryRootItem.setState(FSTreeItem.State.OPEN,
                false,
                false);
  repositoryToTreeItemMap.put(repository,
                repositoryRootItem);
  repository.getBranch(branchName).ifPresent(branch -> presenter.loadDirectoryContent(new FileExplorerItem(repositoryRootItem),
                                            branch.getPath()));
}

代码示例来源:origin: org.kie.workbench/kie-wb-common-ala-ui-backend

@Test
public void testProjects() {
  final Repository repository = mock(Repository.class);
  final Branch branch = new Branch(BRANCH_NAME,
                   mock(Path.class));
  doReturn(Optional.of(branch)).when(repository).getBranch(eq(BRANCH_NAME));
  @SuppressWarnings("unchecked")
  final Set<Module> modules = mock(Set.class);
  when(repositoryService.getRepositoryFromSpace(SPACE, REPO_NAME)).thenReturn(repository);
  when(moduleService.getAllModules(branch)).thenReturn(modules);
  final Collection<Module> result = service.getModules(SPACE,
                             REPO_NAME,
                             BRANCH_NAME);
  assertEquals(modules,
         result);
}

代码示例来源:origin: org.uberfire/uberfire-rest-backend

@Before
public void setUp() throws Exception {
  fileSystemProvider = new SimpleFileSystemProvider();
  final Path root = fileSystemProvider.getPath(URI.create("default://master@myRepository/"));
  final Branch masterBranch = new Branch("master",
                      Paths.convert(root));
  final String spaceName = "space";
  final Repository repository = mock(Repository.class);
  when(repositoryService.getRepositoryFromSpace(eq(new Space(spaceName)), eq("myRepository"))).thenReturn(repository);
  when(repository.getDefaultBranch()).thenReturn(Optional.of(masterBranch));
  when(repository.getBranch("master")).thenReturn(Optional.of(masterBranch));
  OrganizationalUnit ou = mock(OrganizationalUnit.class);
  when(ou.getName()).thenReturn(spaceName);
  when(organizationalUnitService.getOrganizationalUnit(any())).thenReturn(ou);
}

代码示例来源:origin: kiegroup/appformer

@Before
public void setUp() throws Exception {
  fileSystemProvider = new SimpleFileSystemProvider();
  final Path root = fileSystemProvider.getPath(URI.create("default://master@myRepository/"));
  final Branch masterBranch = new Branch("master",
                      Paths.convert(root));
  final String spaceName = "space";
  final Repository repository = mock(Repository.class);
  when(repositoryService.getRepositoryFromSpace(eq(new Space(spaceName)), eq("myRepository"))).thenReturn(repository);
  when(repository.getDefaultBranch()).thenReturn(Optional.of(masterBranch));
  when(repository.getBranch("master")).thenReturn(Optional.of(masterBranch));
  OrganizationalUnit ou = mock(OrganizationalUnit.class);
  when(ou.getName()).thenReturn(spaceName);
  when(organizationalUnitService.getOrganizationalUnit(any())).thenReturn(ou);
}

代码示例来源:origin: org.uberfire/uberfire-rest-backend

@Test
public void projectDoesNotExist() throws Exception {
  final Path path = mock(Path.class);
  when(path.getFileName()).thenReturn("");
  when(path.toURI()).thenReturn("file://project/");
  final Branch masterBranch = new Branch("master",
                      path);
  when(repository.getDefaultBranch()).thenReturn(Optional.of(masterBranch));
  when(repository.getBranch("master")).thenReturn(Optional.of(masterBranch));
  final JobResult jobResult = helper.testProject(null,
                          space.getName(),
                          "project");
  assertEquals(JobStatus.RESOURCE_NOT_EXIST,
         jobResult.getStatus());
}

代码示例来源:origin: kiegroup/appformer

@Test
public void projectDoesNotExist() throws Exception {
  final Path path = mock(Path.class);
  when(path.getFileName()).thenReturn("");
  when(path.toURI()).thenReturn("file://project/");
  final Branch masterBranch = new Branch("master",
                      path);
  when(repository.getDefaultBranch()).thenReturn(Optional.of(masterBranch));
  when(repository.getBranch("master")).thenReturn(Optional.of(masterBranch));
  final JobResult jobResult = helper.testProject(null,
                          space.getName(),
                          "project");
  assertEquals(JobStatus.RESOURCE_NOT_EXIST,
         jobResult.getStatus());
}

代码示例来源:origin: kiegroup/appformer

@Override
public List<FileDiff> diff(final PullRequest pullRequest) {
  final Repository repository = repositoryService.getRepositoryFromSpace(spaces.getSpace(pullRequest.getTargetSpace()), pullRequest.getTargetRepository());
  this.createHiddenBranch(pullRequest);
  String diff = String.format("diff:%s,%s",
                pullRequest.getTargetBranch(),
                this.buildHiddenBranchName(pullRequest));
  final List<FileDiff> diffs = (List<FileDiff>) this.ioService.readAttributes(convert(repository.getBranch(pullRequest.getSourceBranch()).get().getPath()),
                                        diff);
  this.deleteHiddenBranch(pullRequest);
  return diffs;
}

代码示例来源:origin: org.uberfire/uberfire-structure-backend

@Test
public void testRemoveMultiBranch() throws Exception {
  final Branch devBranch = configuredRepositories.getRepositoryByRepositoryAlias(SPACE1,
                                          REPO2S1).getBranch("dev").get();
  assertNotNull(configuredRepositories.getRepositoryByRootPath(SPACE1,
                                 devBranch.getPath()));
  assertNotNull(configuredRepositories.remove(SPACE1,
                        REPO2S1));
  assertFalse(configuredRepositories.containsAlias(SPACE1,
                           REPO2S1));
  assertNull(configuredRepositories.getRepositoryByRootPath(SPACE1,
                               devBranch.getPath()));
}

代码示例来源:origin: kiegroup/appformer

@Test
public void testRemoveMultiBranch() throws Exception {
  final Branch devBranch = configuredRepositories.getRepositoryByRepositoryAlias(SPACE1,
                                          REPO2S1).getBranch("dev").get();
  assertNotNull(configuredRepositories.getRepositoryByRootPath(SPACE1,
                                 devBranch.getPath()));
  assertNotNull(configuredRepositories.remove(SPACE1,
                        REPO2S1));
  assertFalse(configuredRepositories.containsAlias(SPACE1,
                           REPO2S1));
  assertNull(configuredRepositories.getRepositoryByRootPath(SPACE1,
                               devBranch.getPath()));
}

相关文章