Пример #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();
    }
  }
  @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";
    }
    System.out.print(">>Security groups (comma separated list):");
    String groupsIn = input.nextLine();
    if (groupsIn.trim().length() > 0) {

      String[] groups = groupsIn.split(",");
      for (String group : groups) {
        if (repo.getGroups().contains(group)) {
          continue;
        }
        repositoryService.addGroup(repo, group);
        result.append(
            "Group " + group + " added successfully to repository " + repo.getAlias() + "\n");
      }
    }

    return result.toString();
  }
  @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());
  }
Пример #4
0
 void updateRepository(final String alias, final Map<String, Object> environment) {
   if (repositories != null) {
     for (Repository repository : repositories) {
       if (repository.getAlias().equals(alias)) {
         repository.getEnvironment().clear();
         repository.getEnvironment().putAll(environment);
       }
     }
   }
 }
  @Before
  public void setup() {
    ApplicationPreferences.setUp(new HashMap<String, String>());

    // The BuildOptions widget is manipulated in the Presenter so we need some nasty mocking
    when(view.getBuildOptionsButton()).thenReturn(buildOptions);
    when(buildOptions.getWidget(eq(0))).thenReturn(buildOptionsButton1);
    when(buildOptions.getWidget(eq(1))).thenReturn(buildOptionsMenu);
    when(buildOptionsMenu.getWidget(eq(0))).thenReturn(buildOptionsMenuButton1);
    when(buildOptionsMenu.getWidget(eq(1))).thenReturn(buildOptionsMenuButton1);

    constructProjectScreenPresenter(
        new CallerMock<BuildService>(buildService),
        new CallerMock<AssetManagementService>(assetManagementServiceMock));

    // Mock ProjectScreenService
    final POM pom = new POM(new GAV("groupId", "artifactId", "version"));
    model = new ProjectScreenModel();
    model.setPOM(pom);
    when(projectScreenService.load(any(org.uberfire.backend.vfs.Path.class))).thenReturn(model);

    // Mock BuildService
    when(buildService.buildAndDeploy(any(Project.class))).thenReturn(new BuildResults());

    // Mock LockManager initialisation
    final Path path = mock(Path.class);
    final Metadata pomMetadata = mock(Metadata.class);
    model.setPOMMetaData(pomMetadata);
    when(pomMetadata.getPath()).thenReturn(path);
    final Metadata kmoduleMetadata = mock(Metadata.class);
    model.setKModuleMetaData(kmoduleMetadata);
    when(kmoduleMetadata.getPath()).thenReturn(path);
    final Metadata importsMetadata = mock(Metadata.class);
    model.setProjectImportsMetaData(importsMetadata);
    when(importsMetadata.getPath()).thenReturn(path);

    // Mock ProjectContext
    final Repository repository = mock(Repository.class);
    when(context.getActiveRepository()).thenReturn(repository);
    when(repository.getAlias()).thenReturn("repository");
    when(repository.getCurrentBranch()).thenReturn("master");

    final Project project = mock(Project.class);
    when(project.getProjectName()).thenReturn("project");

    when(context.getActiveProject()).thenReturn(project);

    // Trigger initialisation of view. Unfortunately this is the only way to initialise a Project in
    // the Presenter
    context.onProjectContextChanged(
        new ProjectContextChangeEvent(mock(OrganizationalUnit.class), repository, project));

    verify(view, times(1)).showBusyIndicator(eq(CommonConstants.INSTANCE.Loading()));
    verify(view, times(1)).hideBusyIndicator();
  }
Пример #6
0
 public void loadBranches(String repository) {
   for (Repository r : repositories) {
     if ((r.getAlias()).equals(repository)) {
       view.getChooseSourceBranchBox().addItem(constants.Select_A_Branch());
       for (String branch : r.getBranches()) {
         view.getChooseSourceBranchBox().addItem(branch, branch);
       }
       view.getChooseTargetBranchBox().addItem(constants.Select_A_Branch());
       for (String branch : r.getBranches()) {
         view.getChooseTargetBranchBox().addItem(branch, branch);
       }
     }
   }
 }
  @Test
  public void testLoadBranch1() throws Exception {

    rootDirectories.add(createPath("default://origin@uf-playground"));
    rootDirectories.add(createPath("default://master@uf-playground"));
    rootDirectories.add(createPath("default://branch1@uf-playground"));

    ConfigGroup configGroup = getConfigGroup();
    configGroup.setName("test");

    Repository repository = helper.newRepository(configGroup, "branch1");

    assertEquals(3, repository.getBranches().size());
    assertEquals("branch1", repository.getCurrentBranch());
  }
  @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"));
  }
Пример #9
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  @Override
  public void removeGroup(Repository repository, String group) {
    final ConfigGroup thisRepositoryConfig = findRepositoryConfig(repository.getAlias());

    if (thisRepositoryConfig != null) {
      final ConfigItem<List> groups =
          backward.compat(thisRepositoryConfig).getConfigItem("security:groups");
      groups.getValue().remove(group);

      configurationService.updateConfiguration(thisRepositoryConfig);

      configuredRepositories.update(repositoryFactory.newRepository(thisRepositoryConfig));
    } else {
      throw new IllegalArgumentException("Repository " + repository.getAlias() + " not found");
    }
  }
Пример #10
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));
  }
Пример #11
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;
  }
Пример #12
0
  @Override
  public Repository updateRepositoryConfiguration(
      final Repository repository,
      final RepositoryEnvironmentConfigurations repositoryEnvironmentConfigurations) {
    final ConfigGroup thisRepositoryConfig = findRepositoryConfig(repository.getAlias());

    if (thisRepositoryConfig != null && repositoryEnvironmentConfigurations != null) {

      try {
        configurationService.startBatch();

        for (final Map.Entry<String, Object> entry :
            repositoryEnvironmentConfigurations.getConfigurationMap().entrySet()) {

          ConfigItem configItem = thisRepositoryConfig.getConfigItem(entry.getKey());
          if (configItem == null) {
            thisRepositoryConfig.addConfigItem(
                configurationFactory.newConfigItem(entry.getKey(), entry.getValue()));
          } else {
            configItem.setValue(entry.getValue());
          }
        }

        configurationService.updateConfiguration(thisRepositoryConfig);

        final Repository updatedRepo = repositoryFactory.newRepository(thisRepositoryConfig);
        configuredRepositories.update(updatedRepo);

        return updatedRepo;
      } catch (final Exception e) {
        logger.error("Error during remove repository", e);
        throw new RuntimeException(e);
      } finally {
        configurationService.endBatch();
      }

    } else {
      throw new IllegalArgumentException("Repository " + repository.getAlias() + " not found");
    }
  }
 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;
 }
Пример #14
0
 boolean isTheActiveRepository(final String alias) {
   return activeRepository != null && activeRepository.getAlias().equals(alias);
 }
  @Override
  public ExecutionResults execute(CommandContext ctx) throws Exception {
    try {
      ExecutionResults executionResults = new ExecutionResults();

      String repository = (String) getParameter(ctx, "GitRepository");
      if (repository.endsWith(".git")) {
        repository = repository.substring(0, repository.length() - 4);
      }
      String branchToUpdate = (String) getParameter(ctx, "BranchName");
      String version = (String) getParameter(ctx, "Version");
      if (version == null) {
        version = "1.0.0";
      } else if (!version.endsWith("-SNAPSHOT")) {
        version = version.concat("-SNAPSHOT");
      }

      BeanManager beanManager = CDIUtils.lookUpBeanManager(ctx);
      logger.debug("BeanManager " + beanManager);

      POMService pomService = CDIUtils.createBean(POMService.class, beanManager);
      logger.debug("POMService " + pomService);

      IOService ioService =
          CDIUtils.createBean(IOService.class, beanManager, new NamedLiteral("ioStrategy"));
      logger.debug("IoService " + ioService);
      if (ioService != null) {

        ProjectService projectService =
            CDIUtils.createBean(new TypeLiteral<ProjectService<?>>() {}.getType(), beanManager);

        RepositoryService repositoryService =
            CDIUtils.createBean(RepositoryService.class, beanManager);
        logger.debug("RepositoryService " + repositoryService);

        if (repositoryService != null) {

          Repository repo = repositoryService.getRepository(repository);

          repo =
              repositoryService.getRepository(repo.getBranchRoot(branchToUpdate + "-" + version));
          logger.debug("Updated repository " + repo);

          // update all pom.xml files of projects on the dev branch
          Set<Project> projects = getProjects(repo, ioService, projectService);

          for (Project project : projects) {

            POM pom = pomService.load(project.getPomXMLPath());
            pom.getGav().setVersion(version);
            pomService.save(
                project.getPomXMLPath(), pom, null, "Update project version on development branch");
            executionResults.setData(project.getProjectName() + "-GAV", pom.getGav().toString());
          }
        }
      }

      return executionResults;
    } catch (Throwable e) {
      throw new AssetManagementRuntimeException(e);
    }
  }