private List<String> getRepositoryAliases(final Collection<Repository> repositories) {
   final List<String> repositoryList = new ArrayList<String>();
   for (Repository repo : repositories) {
     repositoryList.add(repo.getAlias());
   }
   return repositoryList;
 }
Beispiel #2
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);
    }
  }
  @SuppressWarnings({"unchecked", "rawtypes"})
  @Override
  public void removeRepository(
      final OrganizationalUnit organizationalUnit, final Repository repository) {
    final ConfigGroup thisGroupConfig = findGroupConfig(organizationalUnit.getName());

    if (thisGroupConfig != null) {
      final ConfigItem<List> repositories = thisGroupConfig.getConfigItem("repositories");
      repositories.getValue().remove(repository.getAlias());

      configurationService.updateConfiguration(thisGroupConfig);

      final OrganizationalUnit updatedOrganizationalUnit =
          organizationalUnitFactory.newOrganizationalUnit(thisGroupConfig);
      registeredOrganizationalUnits.put(
          updatedOrganizationalUnit.getName(), updatedOrganizationalUnit);
    } else {
      throw new IllegalArgumentException(
          "OrganizationalUnit " + organizationalUnit.getName() + " not found");
    }
  }