Esempio n. 1
0
  @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);
    }
  }
  @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());
  }
Esempio n. 3
0
  @Override
  public Project newProject(
      final Repository repository, final String projectName, final POM pom, final String baseUrl) {
    try {
      // Projects are always created in the FS root
      final Path fsRoot = repository.getRoot();
      final Path projectRootPath = Paths.convert(Paths.convert(fsRoot).resolve(projectName));

      // Set-up project structure and KModule.xml
      kModuleService.setUpKModuleStructure(projectRootPath);

      // Create POM.xml
      pomService.create(projectRootPath, baseUrl, pom);

      // Create Project configuration
      final Path projectConfigPath =
          Paths.convert(Paths.convert(projectRootPath).resolve(PROJECT_IMPORTS_PATH));
      ioService.createFile(Paths.convert(projectConfigPath));
      ioService.write(
          Paths.convert(projectConfigPath),
          projectConfigurationContentHandler.toString(createProjectImports()));

      // Raise an event for the new project
      final Project project = resolveProject(projectRootPath);
      newProjectEvent.fire(new NewProjectEvent(project, sessionInfo));

      // Create a default workspace based on the GAV
      final String legalJavaGroupId[] =
          IdentifierUtils.convertMavenIdentifierToJavaIdentifier(
              pom.getGav().getGroupId().split("\\.", -1));
      final String legalJavaArtifactId[] =
          IdentifierUtils.convertMavenIdentifierToJavaIdentifier(
              pom.getGav().getArtifactId().split("\\.", -1));
      final String defaultWorkspacePath =
          StringUtils.join(legalJavaGroupId, "/")
              + "/"
              + StringUtils.join(legalJavaArtifactId, "/");
      final Path defaultPackagePath =
          Paths.convert(Paths.convert(projectRootPath).resolve(MAIN_RESOURCES_PATH));
      final Package defaultPackage = resolvePackage(defaultPackagePath);
      final Package defaultWorkspacePackage = doNewPackage(defaultPackage, defaultWorkspacePath);

      // Raise an event for the new project's default workspace
      newPackageEvent.fire(new NewPackageEvent(defaultWorkspacePackage));

      // Return new project
      return project;

    } catch (Exception e) {
      throw ExceptionUtilities.handleException(e);
    }
  }
  @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);
    }
  }