예제 #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());
  }
예제 #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);
    }
  }
  @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"));
  }
 @Override
 public int hashCode() {
   int result = pom != null ? pom.hashCode() : 0;
   result = 31 * result + (KModule != null ? KModule.hashCode() : 0);
   result = ~~result;
   result = 31 * result + (POMMetaData != null ? POMMetaData.hashCode() : 0);
   result = ~~result;
   result = 31 * result + (KModuleMetaData != null ? KModuleMetaData.hashCode() : 0);
   result = ~~result;
   result = 31 * result + (projectImports != null ? projectImports.hashCode() : 0);
   result = ~~result;
   result = 31 * result + (projectImportsMetaData != null ? projectImportsMetaData.hashCode() : 0);
   result = ~~result;
   result = 31 * result + (projectTagsMetaData != null ? projectTagsMetaData.hashCode() : 0);
   result = ~~result;
   result = 31 * result + (pathToPOM != null ? pathToPOM.hashCode() : 0);
   result = ~~result;
   result = 31 * result + (pathToKModule != null ? pathToKModule.hashCode() : 0);
   result = ~~result;
   result = 31 * result + (pathToImports != null ? pathToImports.hashCode() : 0);
   result = ~~result;
   result = 31 * result + (pathToWhiteList != null ? pathToWhiteList.hashCode() : 0);
   result = ~~result;
   result = 31 * result + (whiteList != null ? whiteList.hashCode() : 0);
   result = ~~result;
   result = 31 * result + (whiteListMetaData != null ? whiteListMetaData.hashCode() : 0);
   result = ~~result;
   return result;
 }
예제 #6
0
  public void setPOM(POM model, boolean isReadOnly) {
    if (isReadOnly) {
      view.setReadOnly();
    }

    this.model = model;

    view.setName(model.getName());
    view.setDescription(model.getDescription());
    if (model.hasParent()) {
      view.setParentGAV(model.getParent());
      view.showParentGAV();
      view.disableGroupID("");
      view.disableVersion("");
    } else {
      view.hideParentGAV();
      view.enableGroupID();
      view.enableVersion();
    }
    view.setGAV(model.getGav());
    view.addArtifactIdChangeHandler(
        new ArtifactIdChangeHandler() {
          @Override
          public void onChange(String newArtifactId) {
            setTitle(newArtifactId);
          }
        });
    setTitle(model.getGav().getArtifactId());
  }
  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    ProjectScreenModel that = (ProjectScreenModel) o;

    if (KModule != null ? !KModule.equals(that.KModule) : that.KModule != null) {
      return false;
    }
    if (KModuleMetaData != null
        ? !KModuleMetaData.equals(that.KModuleMetaData)
        : that.KModuleMetaData != null) {
      return false;
    }
    if (POMMetaData != null ? !POMMetaData.equals(that.POMMetaData) : that.POMMetaData != null) {
      return false;
    }
    if (pathToImports != null
        ? !pathToImports.equals(that.pathToImports)
        : that.pathToImports != null) {
      return false;
    }
    if (pathToKModule != null
        ? !pathToKModule.equals(that.pathToKModule)
        : that.pathToKModule != null) {
      return false;
    }
    if (pathToPOM != null ? !pathToPOM.equals(that.pathToPOM) : that.pathToPOM != null) {
      return false;
    }
    if (pom != null ? !pom.equals(that.pom) : that.pom != null) {
      return false;
    }
    if (projectTagsMetaData != null
        ? !projectTagsMetaData.equals(that.projectTagsMetaData)
        : that.projectTagsMetaData != null) {
      return false;
    }
    if (projectImports != null
        ? !projectImports.equals(that.projectImports)
        : that.projectImports != null) {
      return false;
    }
    if (projectImportsMetaData != null
        ? !projectImportsMetaData.equals(that.projectImportsMetaData)
        : that.projectImportsMetaData != null) {
      return false;
    }
    if (pathToWhiteList != null
        ? !pathToWhiteList.equals(that.pathToWhiteList)
        : that.pathToWhiteList != null) {
      return false;
    }
    if (whiteList != null ? !whiteList.equals(that.whiteList) : that.whiteList != null) {
      return false;
    }
    if (whiteListMetaData != null
        ? !whiteListMetaData.equals(that.whiteListMetaData)
        : that.whiteListMetaData != null) {
      return false;
    }

    return true;
  }
  @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);
    }
  }