Search in sources :

Example 1 with Repository

use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.

the class SourceServiceImpl method getModules.

@Override
public Collection<Module> getModules(final Space space, final String repositoryAlias, final String branchName) {
    checkNotNull("repositoryAlias", repositoryAlias);
    checkNotNull("branchName", branchName);
    final Repository repository = repositoryService.getRepositoryFromSpace(space, repositoryAlias);
    if (repository == null) {
        return new ArrayList<>();
    } else {
        final Optional<Branch> branch = repository.getBranch(branchName);
        if (branch.isPresent()) {
            return moduleService.getAllModules(branch.get());
        } else {
            return new ArrayList<>();
        }
    }
}
Also used : Repository(org.guvnor.structure.repositories.Repository) Branch(org.guvnor.structure.repositories.Branch) ArrayList(java.util.ArrayList)

Example 2 with Repository

use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.

the class SourceServiceImpl method getBranches.

@Override
public Collection<String> getBranches(final Space space, final String repositoryName) {
    checkNotNull("repositoryName", repositoryName);
    final Repository repository = repositoryService.getRepositoryFromSpace(space, repositoryName);
    return repository != null ? toBranchNames(repository.getBranches()) : new ArrayList<>();
}
Also used : Repository(org.guvnor.structure.repositories.Repository)

Example 3 with Repository

use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.

the class SourceServiceImplTest method testProjects.

@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);
}
Also used : Path(org.uberfire.backend.vfs.Path) Repository(org.guvnor.structure.repositories.Repository) Branch(org.guvnor.structure.repositories.Branch) Module(org.guvnor.common.services.project.model.Module) Test(org.junit.Test)

Example 4 with Repository

use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.

the class KieMultipleDocumentEditorTest method testOnRepositoryRemoved.

@Test
public void testOnRepositoryRemoved() {
    final Repository repository = mock(Repository.class);
    when(workbenchContext.getActiveWorkspaceProject()).thenReturn(Optional.of(new WorkspaceProject(mock(OrganizationalUnit.class), repository, mock(Branch.class), mock(Module.class))));
    editor.setupMenuBar();
    editor.onRepositoryRemoved(new RepositoryRemovedEvent(repository));
    verify(editor, times(1)).enableMenus(eq(false));
    verify(editor, times(4)).enableMenuItem(eq(false), any(MenuItems.class));
    verify(saveMenuItem, times(1)).setEnabled(eq(false));
    verify(versionManagerMenuItem, times(1)).setEnabled(eq(false));
}
Also used : Repository(org.guvnor.structure.repositories.Repository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) Branch(org.guvnor.structure.repositories.Branch) MenuItems(org.uberfire.ext.editor.commons.client.menu.MenuItems) Module(org.guvnor.common.services.project.model.Module) RepositoryRemovedEvent(org.guvnor.structure.repositories.RepositoryRemovedEvent) Test(org.junit.Test)

Example 5 with Repository

use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.

the class ModuleSaverTest method testDuplicatedChildInManagedRepositoryPrevention.

/**
 * This test checks that when we have a managed repository and the user tries to create a module "module1" in the
 * given repository, and a module "module1" already exists. Then the parent pom.xml for the managed repository
 * must remain untouched. i.e. If the module "module1" already exists then the parent pom.xml shouldn't be modified.
 * In this way the parent pom.xml remains consistent with the already existing structure.
 */
@Test
public void testDuplicatedChildInManagedRepositoryPrevention() throws URISyntaxException, IOException {
    final POM parentPom = mock(POM.class);
    final POM newPOM = mock(POM.class);
    final Repository repository = mock(Repository.class);
    final String baseURL = "/";
    final File test = File.createTempFile("test", Long.toString(System.nanoTime()));
    final Path repositoryRootPath = paths.convert(fs.getPath(test.toURI()));
    FileAlreadyExistsException fileExistsException = null;
    when(repository.getDefaultBranch()).thenReturn(Optional.of(new Branch("master", repositoryRootPath)));
    // name for the module we are trying to re-create over an existing one.
    when(newPOM.getName()).thenReturn("existingModule");
    // path that will be calculated for looking for the parent pom.xml for the managed repository. (the parent pom.xml
    // lies basically in the root of the repository by definition.)
    final org.uberfire.java.nio.file.Path parentPomNioPath = paths.convert(repositoryRootPath).resolve("pom.xml");
    final Path parentPomVFSPath = paths.convert(parentPomNioPath);
    // path that will be calculated for saving the module pom.xml for the module that are about to be created.
    final org.uberfire.java.nio.file.Path moduleNioPath = paths.convert(repositoryRootPath).resolve("existingModule").resolve("pom.xml");
    when(pomService.load(parentPomVFSPath)).thenReturn(parentPom);
    // emulate the module already exists
    when(ioService.exists(any())).thenReturn(true);
    try {
        saver.save(Paths.convert(moduleNioPath), newPOM, baseURL);
    } catch (FileAlreadyExistsException e) {
        fileExistsException = e;
    }
    // The file already exists must have been thrown, since the module already exists.
    assertNotNull(fileExistsException);
    // And also the parent pom must have never been updated/modified.
    verify(pomService, never()).save(eq(parentPomVFSPath), any(POM.class), any(Metadata.class), any(String.class));
}
Also used : Path(org.uberfire.backend.vfs.Path) Repository(org.guvnor.structure.repositories.Repository) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException) Branch(org.guvnor.structure.repositories.Branch) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) File(java.io.File) POM(org.guvnor.common.services.project.model.POM) Test(org.junit.Test)

Aggregations

Repository (org.guvnor.structure.repositories.Repository)51 Test (org.junit.Test)25 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)21 Branch (org.guvnor.structure.repositories.Branch)21 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)20 GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)15 Module (org.guvnor.common.services.project.model.Module)14 ArrayList (java.util.ArrayList)13 Path (org.uberfire.backend.vfs.Path)13 ExampleRepository (org.kie.workbench.common.screens.examples.model.ExampleRepository)10 POM (org.guvnor.common.services.project.model.POM)7 KieModule (org.kie.workbench.common.services.shared.project.KieModule)7 ExampleOrganizationalUnit (org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit)5 HashMap (java.util.HashMap)4 MavenRepositoryMetadata (org.guvnor.common.services.project.model.MavenRepositoryMetadata)4 Before (org.junit.Before)4 Metadata (org.guvnor.common.services.shared.metadata.model.Metadata)3 RepositoryEnvironmentConfigurations (org.guvnor.structure.repositories.RepositoryEnvironmentConfigurations)3 ConfigGroup (org.guvnor.structure.server.config.ConfigGroup)3 Space (org.uberfire.spaces.Space)3