Beispiel #1
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  @Override
  public void addRole(final Project project, final String role) {
    ConfigGroup thisProjectConfig = findProjectConfig(project.getRootPath());

    if (thisProjectConfig == null) {
      thisProjectConfig =
          configurationFactory.newConfigGroup(
              ConfigType.PROJECT,
              project.getRootPath().toURI(),
              "Project '" + project.getProjectName() + "' configuration");
      thisProjectConfig.addConfigItem(
          configurationFactory.newConfigItem("security:roles", new ArrayList<String>()));
      configurationService.addConfiguration(thisProjectConfig);
    }

    if (thisProjectConfig != null) {
      final ConfigItem<List> roles = thisProjectConfig.getConfigItem("security:roles");
      roles.getValue().add(role);

      configurationService.updateConfiguration(thisProjectConfig);

    } else {
      throw new IllegalArgumentException("Project " + project.getProjectName() + " not found");
    }
  }
  @Override
  public Set<MavenRepositoryMetadata> getRepositoriesResolvingArtifact(
      final GAV gav, final Project project, final MavenRepositoryMetadata... filter) {
    GAVPreferences gavPreferences = gavPreferencesProvider.get();
    final PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo =
        scopeResolutionStrategies.getUserInfoFor(
            GuvnorPreferenceScopes.PROJECT, project.getEncodedIdentifier());
    gavPreferences.load(scopeResolutionStrategyInfo);
    if (gavPreferences.isConflictingGAVCheckDisabled()) {
      return Collections.EMPTY_SET;
    }

    final Set<MavenRepositoryMetadata> repositoriesResolvingArtifact =
        new HashSet<MavenRepositoryMetadata>();

    try {
      // Load Project's pom.xml
      final Path pomXMLPath = project.getPomXMLPath();
      final org.uberfire.java.nio.file.Path nioPomXMLPath = Paths.convert(pomXMLPath);
      final String pomXML = ioService.readAllString(nioPomXMLPath);

      final InputStream pomStream =
          new ByteArrayInputStream(pomXML.getBytes(StandardCharsets.UTF_8));
      final MavenProject mavenProject = MavenProjectLoader.parseMavenPom(pomStream);
      repositoriesResolvingArtifact.addAll(getRepositoriesResolvingArtifact(gav, mavenProject));

      // Filter results if necessary
      if (filter != null && filter.length > 0) {
        repositoriesResolvingArtifact.retainAll(Arrays.asList(filter));
      }

    } catch (IllegalArgumentException iae) {
      log.error(
          "Unable to get Remote Repositories for Project '"
              + project.getProjectName()
              + "'. Returning empty Collection. ",
          iae);

    } catch (NoSuchFileException nsfe) {
      log.error(
          "Unable to get Remote Repositories for Project '"
              + project.getProjectName()
              + "'. Returning empty Collection. ",
          nsfe);

    } catch (org.uberfire.java.nio.IOException ioe) {
      log.error(
          "Unable to get Remote Repositories for Project '"
              + project.getProjectName()
              + "'. Returning empty Collection. ",
          ioe);
    }

    return repositoriesResolvingArtifact;
  }
  @Override
  public Set<MavenRepositoryMetadata> getRemoteRepositoriesMetaData(final Project project) {
    if (project == null) {
      return Collections.emptySet();
    }

    final Set<MavenRepositoryMetadata> repositories = new HashSet<MavenRepositoryMetadata>();

    try {
      // Load Project's pom.xml
      final Path pomXMLPath = project.getPomXMLPath();
      final org.uberfire.java.nio.file.Path nioPomXMLPath = Paths.convert(pomXMLPath);
      final String pomXML = ioService.readAllString(nioPomXMLPath);

      final InputStream pomStream =
          new ByteArrayInputStream(pomXML.getBytes(StandardCharsets.UTF_8));
      final MavenProject mavenProject = MavenProjectLoader.parseMavenPom(pomStream);
      final Aether aether = new Aether(mavenProject);
      final Map<MavenRepositorySource, Collection<RemoteRepository>> remoteRepositories =
          getRemoteRepositories(mavenProject);

      // Local Repository
      repositories.add(
          makeRepositoryMetaData(
              aether.getSession().getLocalRepository(), MavenRepositorySource.LOCAL));

      if (remoteRepositories.isEmpty()) {
        return repositories;
      }

      for (Map.Entry<MavenRepositorySource, Collection<RemoteRepository>> e :
          remoteRepositories.entrySet()) {
        repositories.addAll(makeRepositoriesMetaData(e.getValue(), e.getKey()));
      }

    } catch (IllegalArgumentException iae) {
      log.error(
          "Unable to get Remote Repositories for Project '%s'. Returning empty Collection. ",
          project.getProjectName(), iae);

    } catch (NoSuchFileException nsfe) {
      log.error(
          "Unable to get Remote Repositories for Project '%s'. Returning empty Collection. ",
          project.getProjectName(), nsfe);

    } catch (org.uberfire.java.nio.IOException ioe) {
      log.error(
          "Unable to get Remote Repositories for Project '%s'. Returning empty Collection. ",
          project.getProjectName(), ioe);
    }

    return repositories;
  }
  @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();
  }
Beispiel #5
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  @Override
  public void removeRole(final Project project, final String role) {
    final ConfigGroup thisProjectConfig = findProjectConfig(project.getRootPath());

    if (thisProjectConfig != null) {
      final ConfigItem<List> roles = thisProjectConfig.getConfigItem("security:roles");
      roles.getValue().remove(role);

      configurationService.updateConfiguration(thisProjectConfig);

    } else {
      throw new IllegalArgumentException("Project " + project.getProjectName() + " not found");
    }
  }
  @Override
  public String execute(CliContext context) {
    StringBuffer result = new StringBuffer();
    WeldContainer container = context.getContainer();

    OrganizationalUnitService organizationalUnitService =
        container.instance().select(OrganizationalUnitService.class).get();
    RepositoryService repositoryService =
        container.instance().select(RepositoryService.class).get();
    ExplorerService projectExplorerService =
        container.instance().select(ExplorerService.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";
    }

    OrganizationalUnit ou = null;
    Collection<OrganizationalUnit> units = organizationalUnitService.getOrganizationalUnits();
    for (OrganizationalUnit unit : units) {
      if (unit.getRepositories().contains(repo)) {
        ou = unit;
        break;
      }
    }
    if (ou == null) {
      return "Could not find Organizational Unit containing repository. Unable to proceed.";
    }

    ArrayList<Project> projects = new ArrayList<Project>();
    ProjectExplorerContentQuery query = new ProjectExplorerContentQuery(ou, repo, "master");
    query.setOptions(new ActiveOptions());
    ProjectExplorerContent content = projectExplorerService.getContent(query);
    projects.addAll(content.getProjects());
    if (projects.size() == 0) {
      return "No projects found in repository " + alias;
    }

    int projectIndex = 0;
    while (projectIndex == 0) {
      System.out.println(">>Select project:");
      for (int i = 0; i < projects.size(); i++) {
        System.out.println((i + 1) + ") " + projects.get(i).getProjectName());
      }
      try {
        projectIndex = Integer.parseInt(input.nextLine());
      } catch (NumberFormatException e) {
        System.out.println("Invalid index");
      }
      if (projectIndex < 1 || projectIndex > projects.size()) {
        projectIndex = 0;
        System.out.println("Invalid index");
      }
    }
    Project project = projects.get(projectIndex - 1);

    result.append("\tProject " + project.getProjectName() + "\n");
    result.append("\t Modules: " + project.getModules() + "\n");
    result.append("\t Root path: " + project.getRootPath().toURI() + "\n");
    result.append("\t Pom path: " + project.getPomXMLPath().toURI() + "\n");

    return result.toString();
  }
  @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);
    }
  }