Search in sources :

Example 11 with MavenRepositoryMetadata

use of org.guvnor.common.services.project.model.MavenRepositoryMetadata in project kie-wb-common by kiegroup.

the class PomEditorServiceImplTest method testSaveClashingGAVForced.

@Test
public void testSaveClashingGAVForced() {
    final Set<ModuleRepositories.ModuleRepository> moduleRepositoriesMetadata = new HashSet<ModuleRepositories.ModuleRepository>() {

        {
            add(new ModuleRepositories.ModuleRepository(true, new MavenRepositoryMetadata("local-id", "local-url", MavenRepositorySource.LOCAL)));
        }
    };
    final ModuleRepositories moduleRepositories = new ModuleRepositories(moduleRepositoriesMetadata);
    when(moduleRepositoriesService.load(moduleRepositoriesPath)).thenReturn(moduleRepositories);
    final Set<MavenRepositoryMetadata> clashingRepositories = new HashSet<MavenRepositoryMetadata>() {

        {
            add(new MavenRepositoryMetadata("local-id", "local-url", MavenRepositorySource.LOCAL));
        }
    };
    when(repositoryResolver.getRepositoriesResolvingArtifact(eq(pomXml), any(MavenRepositoryMetadata.class))).thenReturn(clashingRepositories);
    when(pom.getGav()).thenReturn(new GAV("groupId", "artifactId", "0.0.1"));
    try {
        service.save(pomPath, pomXml, metaData, comment, DeploymentMode.FORCED);
    } catch (GAVAlreadyExistsException e) {
        fail(e.getMessage());
    }
    verify(moduleService, never()).resolveModule(pomPath);
    verify(moduleRepositoriesService, never()).load(pomPath);
    verify(repositoryResolver, never()).getRepositoriesResolvingArtifact(eq(pomXml), any(MavenRepositoryMetadata.class));
    verify(ioService, times(1)).startBatch(any(FileSystem.class));
    verify(ioService, times(1)).write(any(org.uberfire.java.nio.file.Path.class), eq(pomXml), eq(attributes), any(CommentedOption.class));
    verify(ioService, times(1)).endBatch();
}
Also used : Path(org.uberfire.backend.vfs.Path) ModuleRepositories(org.guvnor.common.services.project.model.ModuleRepositories) GAVAlreadyExistsException(org.guvnor.common.services.project.service.GAVAlreadyExistsException) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) FileSystem(org.uberfire.java.nio.file.FileSystem) GAV(org.guvnor.common.services.project.model.GAV) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with MavenRepositoryMetadata

use of org.guvnor.common.services.project.model.MavenRepositoryMetadata in project kie-wb-common by kiegroup.

the class ProjectScreenServiceImplTest method testSaveClashingGAVForced.

@Test()
public void testSaveClashingGAVForced() {
    when(pathToPom.toURI()).thenReturn("default://p0/pom.xml");
    final ProjectScreenModel model = new ProjectScreenModel();
    model.setPOM(pom);
    model.setPOMMetaData(pomMetaData);
    model.setPathToPOM(pathToPom);
    model.setKModule(kmodule);
    model.setKModuleMetaData(kmoduleMetaData);
    model.setPathToKModule(pathToKieModule);
    model.setProjectImports(projectImports);
    model.setProjectImportsMetaData(projectImportsMetaData);
    model.setPathToImports(pathToModuleImports);
    model.setRepositories(moduleRepositories);
    model.setPathToRepositories(pathToModuleRepositories);
    final MavenRepositoryMetadata repositoryMetadata = new MavenRepositoryMetadata("id", "url", MavenRepositorySource.LOCAL);
    moduleRepositories.getRepositories().add(new ModuleRepositories.ModuleRepository(true, repositoryMetadata));
    when(repositoryResolver.getRepositoriesResolvingArtifact(eq(gav), eq(module), eq(repositoryMetadata))).thenReturn(new HashSet<MavenRepositoryMetadata>() {

        {
            add(repositoryMetadata);
        }
    });
    final String comment = "comment";
    final WorkspaceProject projectToBeReturned = new WorkspaceProject();
    doReturn(projectToBeReturned).when(projectService).resolveProject(pathToPom);
    try {
        final WorkspaceProject project = service.save(pathToPom, model, comment, DeploymentMode.FORCED);
        assertEquals(projectToBeReturned, project);
    } catch (GAVAlreadyExistsException e) {
        fail("Unexpected exception thrown: " + e.getMessage());
    }
    verify(pomService, times(1)).save(eq(pathToPom), eq(model.getPOM()), eq(pomMetaData), eq(comment));
    verify(kModuleService, times(1)).save(eq(pathToKieModule), eq(kmodule), eq(kmoduleMetaData), eq(comment));
    verify(importsService, times(1)).save(eq(pathToModuleImports), eq(projectImports), eq(projectImportsMetaData), eq(comment));
    verify(repositoriesService, times(1)).save(eq(pathToModuleRepositories), eq(moduleRepositories), eq(comment));
}
Also used : ModuleRepositories(org.guvnor.common.services.project.model.ModuleRepositories) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) GAVAlreadyExistsException(org.guvnor.common.services.project.service.GAVAlreadyExistsException) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) Test(org.junit.Test)

Example 13 with MavenRepositoryMetadata

use of org.guvnor.common.services.project.model.MavenRepositoryMetadata in project kie-wb-common by kiegroup.

the class ProjectScreenServiceImplTest method testSaveClashingGAVFilteredRepositoryNoChangeToGAV.

@Test()
public void testSaveClashingGAVFilteredRepositoryNoChangeToGAV() {
    when(pathToPom.toURI()).thenReturn("default://p0/pom.xml");
    final ProjectScreenModel model = new ProjectScreenModel();
    model.setPOM(pom);
    model.setPOMMetaData(pomMetaData);
    model.setPathToPOM(pathToPom);
    model.setKModule(kmodule);
    model.setKModuleMetaData(kmoduleMetaData);
    model.setPathToKModule(pathToKieModule);
    model.setProjectImports(projectImports);
    model.setProjectImportsMetaData(projectImportsMetaData);
    model.setPathToImports(pathToModuleImports);
    model.setRepositories(moduleRepositories);
    model.setPathToRepositories(pathToModuleRepositories);
    final MavenRepositoryMetadata repositoryMetadata = new MavenRepositoryMetadata("id", "url", MavenRepositorySource.LOCAL);
    moduleRepositories.getRepositories().add(new ModuleRepositories.ModuleRepository(false, repositoryMetadata));
    final ArgumentCaptor<MavenRepositoryMetadata> filterCaptor = ArgumentCaptor.forClass(MavenRepositoryMetadata.class);
    when(repositoryResolver.getRepositoriesResolvingArtifact(eq(gav), eq(module), filterCaptor.capture())).thenReturn(new HashSet<MavenRepositoryMetadata>());
    final String comment = "comment";
    try {
        service.save(pathToPom, model, comment);
    } catch (GAVAlreadyExistsException e) {
        // This should not be thrown if we're filtering out the Repository from the check
        fail(e.getMessage());
    }
    final List<MavenRepositoryMetadata> filter = filterCaptor.getAllValues();
    assertEquals(0, filter.size());
    verify(repositoryResolver, never()).getRepositoriesResolvingArtifact(eq(model.getPOM().getGav()), eq(module));
    verify(ioService, times(1)).startBatch(any(FileSystem.class), any(CommentedOption.class));
    verify(pomService, times(1)).save(eq(pathToPom), eq(model.getPOM()), eq(pomMetaData), eq(comment));
    verify(kModuleService, times(1)).save(eq(pathToKieModule), eq(kmodule), eq(kmoduleMetaData), eq(comment));
    verify(importsService, times(1)).save(eq(pathToModuleImports), eq(projectImports), eq(projectImportsMetaData), eq(comment));
    verify(repositoriesService, times(1)).save(eq(pathToModuleRepositories), eq(moduleRepositories), eq(comment));
    verify(ioService, times(1)).endBatch();
}
Also used : ModuleRepositories(org.guvnor.common.services.project.model.ModuleRepositories) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) GAVAlreadyExistsException(org.guvnor.common.services.project.service.GAVAlreadyExistsException) CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) FileSystem(org.uberfire.java.nio.file.FileSystem) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) Test(org.junit.Test)

Example 14 with MavenRepositoryMetadata

use of org.guvnor.common.services.project.model.MavenRepositoryMetadata in project kie-wb-common by kiegroup.

the class DeploymentVerifier method verifyWithException.

/**
 * Verifies if a given module can be deployed in current server for the given deployment mode.
 * An example of when a module can't be deployed is when the deployment mode is DeploymentMode.VALIDATED and the
 * module was already deployed. This case will raise a GAVAlreadyExistsException.
 * @param module the module to verify.
 * @param deploymentMode the deployment mode for doing the verification.
 */
public void verifyWithException(final Module module, DeploymentMode deploymentMode) {
    if (DeploymentMode.VALIDATED.equals(deploymentMode)) {
        // Check is the POM's GAV resolves to any pre-existing artifacts.
        final GAV gav = module.getPom().getGav();
        if (gav.isSnapshot()) {
            return;
        }
        final ModuleRepositories projectRepositories = moduleRepositoriesService.load(((KieModule) module).getRepositoriesPath());
        final Set<MavenRepositoryMetadata> repositories = repositoryResolver.getRepositoriesResolvingArtifact(gav, module, projectRepositories.filterByIncluded());
        if (repositories.size() > 0) {
            throw new GAVAlreadyExistsException(gav, repositories);
        }
    }
}
Also used : ModuleRepositories(org.guvnor.common.services.project.model.ModuleRepositories) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) GAVAlreadyExistsException(org.guvnor.common.services.project.service.GAVAlreadyExistsException) GAV(org.guvnor.common.services.project.model.GAV)

Example 15 with MavenRepositoryMetadata

use of org.guvnor.common.services.project.model.MavenRepositoryMetadata in project kie-wb-common by kiegroup.

the class ModuleRepositoriesSynchronizer method syncModuleRepositories.

private void syncModuleRepositories(final org.uberfire.backend.vfs.Path _path) {
    // Load existing Repository definitions for Module
    final Path path = ioService.get(URI.create(_path.toURI()));
    final KieModule module = moduleFactory.simpleModuleInstance(path.getParent());
    final ModuleRepositories moduleRepositories = moduleRepositoriesService.load(module.getRepositoriesPath());
    // Load all Repository definitions resolved for the Module
    final Set<MavenRepositoryMetadata> mavenRepositories = repositoryResolver.getRemoteRepositoriesMetaData(module);
    // Identify Module Repositories to be removed (they're not in the Repositories resolved for the Module)
    final Set<MavenRepositoryMetadata> existingMavenRepositories = new HashSet<MavenRepositoryMetadata>();
    final Set<ModuleRepositories.ModuleRepository> repositoriesToRemove = new HashSet<ModuleRepositories.ModuleRepository>();
    for (ModuleRepositories.ModuleRepository moduleRepository : moduleRepositories.getRepositories()) {
        final MavenRepositoryMetadata existingMavenRepository = moduleRepository.getMetadata();
        if (mavenRepositories.contains(existingMavenRepository)) {
            existingMavenRepositories.add(existingMavenRepository);
        } else {
            repositoriesToRemove.add(moduleRepository);
        }
    }
    // Identify Maven Repositories to be added (they're not in the Module Repositories)
    final Set<MavenRepositoryMetadata> repositoriesToAdd = new HashSet<MavenRepositoryMetadata>();
    for (MavenRepositoryMetadata mavenRepository : mavenRepositories) {
        if (!existingMavenRepositories.contains(mavenRepository)) {
            repositoriesToAdd.add(mavenRepository);
        }
    }
    // Delete identified Maven Repositories
    for (ModuleRepositories.ModuleRepository repository : repositoriesToRemove) {
        moduleRepositories.getRepositories().remove(repository);
    }
    // Add identified Maven Repositories
    for (MavenRepositoryMetadata repository : repositoriesToAdd) {
        moduleRepositories.getRepositories().add(new ModuleRepositories.ModuleRepository(true, repository));
    }
    // TODO: project.repositories file does what?
    // Update project.repositories file
    moduleRepositoriesService.save(module.getRepositoriesPath(), moduleRepositories, "Automatic synchronization");
}
Also used : Path(org.uberfire.java.nio.file.Path) ModuleRepositories(org.guvnor.common.services.project.model.ModuleRepositories) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) KieModule(org.kie.workbench.common.services.shared.project.KieModule) HashSet(java.util.HashSet)

Aggregations

MavenRepositoryMetadata (org.guvnor.common.services.project.model.MavenRepositoryMetadata)19 ModuleRepositories (org.guvnor.common.services.project.model.ModuleRepositories)17 Test (org.junit.Test)15 GAVAlreadyExistsException (org.guvnor.common.services.project.service.GAVAlreadyExistsException)11 GAV (org.guvnor.common.services.project.model.GAV)8 HashSet (java.util.HashSet)7 Path (org.uberfire.backend.vfs.Path)6 CommentedOption (org.uberfire.java.nio.base.options.CommentedOption)6 FileSystem (org.uberfire.java.nio.file.FileSystem)6 POM (org.guvnor.common.services.project.model.POM)5 ProjectScreenModel (org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel)5 KieModule (org.kie.workbench.common.services.shared.project.KieModule)5 ResourceUpdatedEvent (org.uberfire.workbench.events.ResourceUpdatedEvent)3 Branch (org.guvnor.structure.repositories.Branch)2 Repository (org.guvnor.structure.repositories.Repository)2 IOException (java.io.IOException)1 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)1 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)1 Path (org.uberfire.java.nio.file.Path)1