private void updateBranch(final Repository repository) { final String branch = aliasBranch.get(repository.getAlias()); if (branch == null || hasBranchBeenRemoved(repository, branch)) { aliasBranch.put(repository.getAlias(), repository.getDefaultBranch()); } }
public static Repository makeRepository(final String alias, final String... branches) { final Repository repository = mock(Repository.class); when(repository.getAlias()).thenReturn(alias); when(repository.getBranches()).thenReturn(Arrays.asList(branches)); when(repository.getDefaultBranch()).thenReturn("master"); return repository; } }
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()); } } }
@Override public WorkspaceProject resolveProject(final Repository repository) { if (!repository.getDefaultBranch().isPresent()) { throw new IllegalStateException("New repository should always have a branch."); } return resolveProject(repository.getSpace(), repository.getDefaultBranch().get()); }
public void add(Repository repository) { repositoriesByAlias.put(repository.getAlias(), repository); if (repository.getBranches() != null) { for (final Branch branch : repository.getBranches()) { repositoriesByBranchRoot.put(Paths.normalizePath(branch.getPath()), repository); } } }
public void refreshRepository(final Repository repository) { final Space space = repository.getSpace(); final Map<String, List<ConfigGroup>> repoConfigsBySpace = configurationService.getConfigurationByNamespace(REPOSITORY); final List<ConfigGroup> repoConfigs = repoConfigsBySpace.get(space.getName()); repoConfigs.stream().filter(c -> c.getName().equals(repository.getAlias())).findFirst().ifPresent(repoConfig -> { final Repository updatedRepo = repositoryFactory.newRepository(repoConfig); update(space, updatedRepo); }); } }
private Branch resolveBranch(final org.uberfire.java.nio.file.Path repositoryRoot, final Repository repository) { final Branch defaultBranch = repository.getDefaultBranch().get(); if (!Paths.convert(defaultBranch.getPath()).equals(repositoryRoot)) { for (final Branch branch : repository.getBranches()) { if (Paths.convert(branch.getPath()).equals(repositoryRoot)) { return branch; } } } return defaultBranch; }
@Before public void setUp() throws Exception { when(itemA.getIdentifier()).thenReturn("itemA"); when(itemB.getIdentifier()).thenReturn("itemB"); when(itemA.getAlias()).thenReturn("Item A"); when(itemB.getAlias()).thenReturn("Item B"); when(resourceService.getAllRepositories()).thenReturn(Arrays.asList(itemA, itemB)); searchService = new RepositorySearchServiceImpl(resourceService); }
private void setUpRepositories() { doReturn(Optional.of(mock(Branch.class))).when(repository1).getDefaultBranch(); doReturn("repository1").when(repository1).getAlias(); doReturn("space1/repository1").when(repository1).getIdentifier(); doReturn(Optional.of(mock(Branch.class))).when(repository2).getDefaultBranch(); doReturn("repository-with-same-alias").when(repository2).getAlias(); doReturn("space1/repository-with-same-alias").when(repository2).getIdentifier(); doReturn(Optional.of(mock(Branch.class))).when(repository3).getDefaultBranch(); doReturn("repository-with-same-alias").when(repository3).getAlias(); doReturn("space2/repository-with-same-alias").when(repository3).getIdentifier(); allRepositories = new ArrayList<>(); allRepositories.add(repository1); allRepositories.add(repository2); allRepositories.add(repository3); doReturn(allRepositories).when(repositoryService).getAllRepositoriesFromAllUserSpaces(); doReturn(allRepositories).when(repositoryService).getAllRepositoriesFromAllUserSpaces(); doReturn(Arrays.asList(repository1, repository2)).when(repositoryService).getRepositories(Mockito.eq(space1)); doReturn(Arrays.asList(repository1, repository2)).when(repositoryService).getAllRepositories(Mockito.eq(space1)); doReturn(Arrays.asList(repository3)).when(repositoryService).getAllRepositories(Mockito.eq(space2)); doReturn(Collections.singletonList(repository3)).when(repositoryService).getRepositories(Mockito.eq(space2)); }
@Override public String execute(CliContext context) { StringBuffer result = new StringBuffer(); WeldContainer container = context.getContainer(); RepositoryService repositoryService = container.instance().select(RepositoryService.class).get(); Collection<Repository> repositories = repositoryService.getRepositories(); result.append("Currently available repositories: \n"); for (Repository config : repositories) { result.append("\tRepository " + config.getAlias() + "\n"); result.append("\t scheme: " + config.getScheme() + "\n"); result.append("\t uri: " + config.getUri() + "\n"); result.append("\t environment: " + printEnvironment(config.getEnvironment()) + "\n"); result.append("\t groups: " + config.getGroups() + "\n"); } return result.toString(); }
public RepositoryInfo getRepositoryInfo(final String alias) { final Repository repo = getRepository(alias); String ouName = null; for (final OrganizationalUnit ou : organizationalUnitService.getAllOrganizationalUnits()) { for (Repository repository : ou.getRepositories()) { if (repository.getAlias().equals(alias)) { ouName = ou.getName(); } } } return new RepositoryInfo(repo.getIdentifier(), alias, ouName, repo.getRoot(), repo.getPublicURIs(), getRepositoryHistory(alias, 0, HISTORY_PAGE_SIZE)); }
@Before public void setup() { permissionManager = new DefaultPermissionManager(); treeProvider = new RepositoryTreeProvider(permissionManager, new CallerMock<>(searchService)); rootNode = treeProvider.buildRootNode(); rootNode.setPermissionTree(permissionTree); when(repo1.getIdentifier()).thenReturn("r1"); when(repo2.getIdentifier()).thenReturn("r2"); when(repo1.getAlias()).thenReturn("r1"); when(repo2.getAlias()).thenReturn("r2"); when(repo1.getResourceType()).thenReturn(Repository.RESOURCE_TYPE); when(repo2.getResourceType()).thenReturn(Repository.RESOURCE_TYPE); when(permissionTree.getChildrenResourceIds(any())).thenReturn(null); when(searchService.searchByAlias(anyString(), anyInt(), anyBoolean())).thenReturn(Arrays.asList(repo1, repo2)); }
@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); }
@Override public Repository answer(InvocationOnMock invocationOnMock) throws Throwable { final Repository newRepository = mock(Repository.class); doReturn(invocationOnMock.getArguments()[2]).when(newRepository).getAlias(); doReturn(SpacesAPI.Scheme.FILE).when(newRepository).getScheme(); doReturn(space).when(newRepository).getSpace(); return newRepository; } }).when(repositoryService).createRepository(eq(organizationalUnit),
public Module get(final OrganizationalUnit organizationalUnit, final Repository repository) { if (organizationalUnit == null || repository == null || !repository.getDefaultBranch().isPresent()) { return null; } final Object obj = content.get(Pair.newPair(organizationalUnit.getName(), repository.getDefaultBranch().get().getPath()).toString()); if (obj != null && obj instanceof Module) { return (Module) obj; } return null; }
@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")); }
@Override public SocialActivitiesEvent toSocial( Object object ) { NewRepositoryEvent event = (NewRepositoryEvent) object; SocialUser socialUser = null; try { socialUser = socialUserRepositoryAPI.findSocialUser( loggedUser.getIdentifier() ); } catch(ContextNotActiveException e) { //clean repository socialUser = new SocialUser( "system" ); } String additionalInfo = "Created"; return new SocialActivitiesEvent( socialUser, ExtendedTypes.NEW_REPOSITORY_EVENT, new Date() ).withAdicionalInfo( additionalInfo ).withLink( event.getNewRepository().getAlias(), event.getNewRepository().getUri() ).withDescription( "" ); }
private Branch getBranch(final Repository repository, final Path convertedPath) { for (final Branch branch : repository.getBranches()) { if (branch.getPath().equals(convertedPath)) { return branch; } } return null; }