コード例 #1
0
ファイル: ProjectServiceImpl.java プロジェクト: Rawin2/guvnor
  @Override
  public void copy(final Path pathToPomXML, final String newName, final String comment) {
    try {
      final org.uberfire.java.nio.file.Path projectDirectory =
          Paths.convert(pathToPomXML).getParent();
      final org.uberfire.java.nio.file.Path newProjectPath =
          projectDirectory.resolveSibling(newName);

      final POM content = pomService.load(pathToPomXML);

      if (newProjectPath.equals(projectDirectory)) {
        return;
      }

      if (ioService.exists(newProjectPath)) {
        throw new FileAlreadyExistsException(newProjectPath.toString());
      }

      content.setName(newName);
      final Path newPathToPomXML = Paths.convert(newProjectPath.resolve("pom.xml"));
      ioService.startBatch();
      ioService.copy(projectDirectory, newProjectPath, makeCommentedOption(comment));
      pomService.save(newPathToPomXML, content, null, comment);
      ioService.endBatch();
      final Project newProject = resolveProject(Paths.convert(newProjectPath));
      newProjectEvent.fire(new NewProjectEvent(newProject, sessionInfo));

    } catch (final Exception e) {
      throw ExceptionUtilities.handleException(e);
    }
  }
コード例 #2
0
  @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);
    }
  }