예제 #1
0
  @Override
  public void removeRepository(final String alias) {
    final ConfigGroup thisRepositoryConfig = findRepositoryConfig(alias);

    try {
      configurationService.startBatch();
      if (thisRepositoryConfig != null) {
        configurationService.removeConfiguration(thisRepositoryConfig);
      }

      final Repository repo = configuredRepositories.remove(alias);
      if (repo != null) {
        repositoryRemovedEvent.fire(new RepositoryRemovedEvent(repo));
        ioService.delete(convert(repo.getRoot()).getFileSystem().getPath(null));
      }

      // Remove reference to Repository from Organizational Units
      final Collection<OrganizationalUnit> organizationalUnits =
          organizationalUnitService.getOrganizationalUnits();
      for (OrganizationalUnit ou : organizationalUnits) {
        for (Repository repository : ou.getRepositories()) {
          if (repository.getAlias().equals(alias)) {
            organizationalUnitService.removeRepository(ou, repository);
          }
        }
      }
    } catch (final Exception e) {
      logger.error("Error during remove repository", e);
      throw new RuntimeException(e);
    } finally {
      configurationService.endBatch();
    }
  }
  @Test
  public void testNewProjectCreation() throws URISyntaxException {
    final URI fs = new URI("git://test");
    try {
      FileSystems.getFileSystem(fs);
    } catch (FileSystemNotFoundException e) {
      FileSystems.newFileSystem(fs, new HashMap<String, Object>());
    }

    final Repository repository = mock(Repository.class);
    final String name = "p0";
    final POM pom = new POM();
    final String baseURL = "/";

    final Path repositoryRootPath = mock(Path.class);
    when(repository.getRoot()).thenReturn(repositoryRootPath);
    when(repositoryRootPath.toURI()).thenReturn("git://test");

    pom.getGav().setGroupId("org.kie.workbench.services");
    pom.getGav().setArtifactId("kie-wb-common-services-test");
    pom.getGav().setVersion("1.0.0-SNAPSHOT");

    when(pomService.load(any(Path.class))).thenReturn(pom);

    final AbstractProjectService projectServiceSpy = spy(projectService);

    final Project project = projectServiceSpy.newProject(repository, name, pom, baseURL);

    verify(projectServiceSpy, times(1))
        .simpleProjectInstance(any(org.uberfire.java.nio.file.Path.class));

    assertEquals(pom, project.getPom());
  }
  @Test
  public void testPackageNameWhiteList() throws URISyntaxException {
    final URI fs = new URI("git://test");
    try {
      FileSystems.getFileSystem(fs);
    } catch (FileSystemNotFoundException e) {
      FileSystems.newFileSystem(fs, new HashMap<String, Object>());
    }

    final Map<String, String> writes = new HashMap<String, String>();

    final Repository repository = mock(Repository.class);
    final String name = "p0";
    final POM pom = new POM();
    final String baseURL = "/";

    final Path repositoryRootPath = mock(Path.class);
    when(repository.getRoot()).thenReturn(repositoryRootPath);
    when(repositoryRootPath.toURI()).thenReturn("git://test");

    when(ioService.write(any(org.uberfire.java.nio.file.Path.class), anyString()))
        .thenAnswer(
            new Answer<Object>() {
              @Override
              public Object answer(final InvocationOnMock invocation) throws Throwable {
                if (invocation.getArguments().length == 2) {
                  final String path =
                      ((org.uberfire.java.nio.file.Path) invocation.getArguments()[0])
                          .toUri()
                          .getPath();
                  final String content = ((String) invocation.getArguments()[1]);
                  writes.put(path, content);
                }
                return invocation.getArguments()[0];
              }
            });

    pom.getGav().setGroupId("org.kie.workbench.services");
    pom.getGav().setArtifactId("kie-wb-common-services-test");
    pom.getGav().setVersion("1.0.0-SNAPSHOT");

    projectService.newProject(repository, name, pom, baseURL);

    assertTrue(writes.containsKey("/p0/package-names-white-list"));
    assertEquals(
        "org.kie.workbench.services.kie_wb_common_services_test.**",
        writes.get("/p0/package-names-white-list"));
  }
예제 #4
0
  public RepositoryInfo getRepositoryInfo(final String alias) {
    final Repository repo = getRepository(alias);
    String ouName = null;
    for (final OrganizationalUnit ou : organizationalUnitService.getOrganizationalUnits()) {
      for (Repository repository : ou.getRepositories()) {
        if (repository.getAlias().equals(alias)) {
          ouName = ou.getName();
        }
      }
    }

    return new RepositoryInfo(
        alias,
        ouName,
        repo.getRoot(),
        repo.getPublicURIs(),
        getRepositoryHistory(alias, 0, HISTORY_PAGE_SIZE));
  }
예제 #5
0
  @Override
  public List<VersionRecord> getRepositoryHistory(String alias, int startIndex, int endIndex) {
    final Repository repo = getRepository(alias);

    // This is a work-around for https://bugzilla.redhat.com/show_bug.cgi?id=1199215
    // org.kie.workbench.common.screens.contributors.backend.dataset.ContributorsManager is trying
    // to
    // load a Repository's history for a Repository associated with an Organizational Unit before
    // the
    // Repository has been setup.
    if (repo == null) {
      return Collections.EMPTY_LIST;
    }

    final VersionAttributeView versionAttributeView =
        ioService.getFileAttributeView(convert(repo.getRoot()), VersionAttributeView.class);
    final List<VersionRecord> records = versionAttributeView.readAttributes().history().records();

    if (startIndex < 0) {
      startIndex = 0;
    }
    if (endIndex < 0 || endIndex > records.size()) {
      endIndex = records.size();
    }
    if (startIndex >= records.size() || startIndex >= endIndex) {
      return Collections.emptyList();
    }

    Collections.reverse(records);

    final List<VersionRecord> result = new ArrayList<VersionRecord>(endIndex - startIndex);
    for (VersionRecord record : records.subList(startIndex, endIndex)) {
      result.add(
          new PortableVersionRecord(
              record.id(),
              record.author(),
              record.email(),
              record.comment(),
              record.date(),
              record.uri()));
    }

    return result;
  }
 private Set<Project> getProjects(
     final Repository repository, final IOService ioService, final ProjectService projectService) {
   final Set<Project> authorizedProjects = new HashSet<Project>();
   if (repository == null) {
     return authorizedProjects;
   }
   final Path repositoryRoot = Paths.convert(repository.getRoot());
   final DirectoryStream<Path> nioRepositoryPaths = ioService.newDirectoryStream(repositoryRoot);
   for (Path nioRepositoryPath : nioRepositoryPaths) {
     if (Files.isDirectory(nioRepositoryPath)) {
       final org.uberfire.backend.vfs.Path projectPath = Paths.convert(nioRepositoryPath);
       final Project project = projectService.resolveProject(projectPath);
       if (project != null) {
         authorizedProjects.add(project);
       }
     }
   }
   return authorizedProjects;
 }