Search in sources :

Example 1 with MavenRepositoryMetadata

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

the class ModuleRepositoriesSynchronizerTest method testAddAndRemoveModuleRepository.

@Test
public void testAddAndRemoveModuleRepository() {
    final ResourceUpdatedEvent event = new ResourceUpdatedEvent(pomPath, "", sessionInfo);
    final Set<ModuleRepositories.ModuleRepository> repositories = new HashSet<ModuleRepositories.ModuleRepository>() {

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

        {
            add(new MavenRepositoryMetadata("remote-id", "remote-url", MavenRepositorySource.PROJECT));
        }
    });
    synchronizer.onResourceUpdated(event);
    final ArgumentCaptor<ModuleRepositories> moduleRepositoriesArgumentCaptor = ArgumentCaptor.forClass(ModuleRepositories.class);
    verify(moduleRepositoriesService, times(1)).save(eq(moduleRepositoriesPath), moduleRepositoriesArgumentCaptor.capture(), any(String.class));
    final ModuleRepositories saved = moduleRepositoriesArgumentCaptor.getValue();
    assertNotNull(saved);
    assertEquals(1, saved.getRepositories().size());
    final ModuleRepositories.ModuleRepository repository = saved.getRepositories().iterator().next();
    assertTrue(repository.isIncluded());
    assertEquals("remote-id", repository.getMetadata().getId());
    assertEquals("remote-url", repository.getMetadata().getUrl());
    assertEquals(MavenRepositorySource.PROJECT, repository.getMetadata().getSource());
}
Also used : ModuleRepositories(org.guvnor.common.services.project.model.ModuleRepositories) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) ResourceUpdatedEvent(org.uberfire.workbench.events.ResourceUpdatedEvent) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with MavenRepositoryMetadata

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

the class PomEditorServiceImpl method checkRepositories.

private void checkRepositories(final Path pomPath, final String pomXml) {
    // Check is the POM's GAV has been changed.
    final KieModule module = moduleService.resolveModule(pomPath);
    POM pom = new POM(GAV_UNDETERMINED);
    try {
        pom = pomContentHandler.toModel(pomXml);
        if (pom.getGav().equals(module.getPom().getGav())) {
            return;
        }
    } catch (IOException ioe) {
        logger.warn("Unable to load pom.xml. It is therefore impossible to ascertain GAV.", ioe);
    } catch (XmlPullParserException pe) {
        logger.warn("Unable to load pom.xml. It is therefore impossible to ascertain GAV.", pe);
    }
    // Check is the POM's GAV resolves to any pre-existing artifacts.
    // Filter resolved Repositories by those enabled for the Module.
    final ModuleRepositories moduleRepositories = moduleRepositoriesService.load(module.getRepositoriesPath());
    final Set<MavenRepositoryMetadata> repositories = repositoryResolver.getRepositoriesResolvingArtifact(pomXml, moduleRepositories.filterByIncluded());
    if (repositories.size() > 0) {
        throw new GAVAlreadyExistsException(pom.getGav(), 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) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) KieModule(org.kie.workbench.common.services.shared.project.KieModule) POM(org.guvnor.common.services.project.model.POM)

Example 3 with MavenRepositoryMetadata

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

the class ProjectScreenModelSaver method checkRepositories.

private void checkRepositories(final Path pathToPomXML, final ProjectScreenModel model) {
    // Check is the POM's GAV has been changed.
    final GAV gav = model.getPOM().getGav();
    final KieModule project = moduleService.resolveModule(pathToPomXML);
    if (gav.equals(project.getPom().getGav())) {
        return;
    }
    // Check is the Module's "proposed" GAV resolves to any pre-existing artifacts.
    // Use the Repositories in the model since the User may update the Repositories filter and save.
    final ModuleRepositories moduleRepositories = model.getRepositories();
    final Set<MavenRepositoryMetadata> repositories = repositoryResolver.getRepositoriesResolvingArtifact(gav, project, moduleRepositories.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) KieModule(org.kie.workbench.common.services.shared.project.KieModule)

Example 4 with MavenRepositoryMetadata

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

the class PomEditorServiceImplTest method testSaveClashingGAVChangeToGAV.

@Test
public void testSaveClashingGAVChangeToGAV() {
    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));
        }
    };
    final ArgumentCaptor<MavenRepositoryMetadata> resolvedRepositoriesCaptor = ArgumentCaptor.forClass(MavenRepositoryMetadata.class);
    when(repositoryResolver.getRepositoriesResolvingArtifact(eq(pomXml), resolvedRepositoriesCaptor.capture())).thenReturn(clashingRepositories);
    when(pom.getGav()).thenReturn(new GAV("groupId", "artifactId", "0.0.2"));
    try {
        service.save(pomPath, pomXml, metaData, comment, DeploymentMode.VALIDATED);
    } catch (GAVAlreadyExistsException e) {
    // This is expected! We catch here rather than let JUnit handle it with
    // @Test(expected = GAVAlreadyExistsException.class) so we can verify
    // that only the expected methods have been invoked.
    } catch (Exception e) {
        fail(e.getMessage());
    }
    verify(moduleService, times(1)).resolveModule(pomPath);
    verify(moduleRepositoriesService, times(1)).load(moduleRepositoriesPath);
    verify(repositoryResolver, times(1)).getRepositoriesResolvingArtifact(eq(pomXml), any(MavenRepositoryMetadata.class));
    final List<MavenRepositoryMetadata> resolvedRepositories = resolvedRepositoriesCaptor.getAllValues();
    assertNotNull(resolvedRepositories);
    assertEquals(1, resolvedRepositories.size());
    final MavenRepositoryMetadata repositoryMetadata = resolvedRepositories.get(0);
    assertEquals("local-id", repositoryMetadata.getId());
    assertEquals("local-url", repositoryMetadata.getUrl());
    assertEquals(MavenRepositorySource.LOCAL, repositoryMetadata.getSource());
    verify(ioService, never()).startBatch(any(FileSystem.class));
    verify(ioService, never()).write(any(org.uberfire.java.nio.file.Path.class), eq(pomXml), eq(attributes), any(CommentedOption.class));
    verify(ioService, never()).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) 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 5 with MavenRepositoryMetadata

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

the class PomEditorServiceImplTest method testSaveNonClashingGAVFilteredChangeToGAV.

@Test
public void testSaveNonClashingGAVFilteredChangeToGAV() {
    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 ArgumentCaptor<MavenRepositoryMetadata> resolvedRepositoriesCaptor = ArgumentCaptor.forClass(MavenRepositoryMetadata.class);
    when(repositoryResolver.getRepositoriesResolvingArtifact(eq(pomXml), resolvedRepositoriesCaptor.capture())).thenReturn(Collections.EMPTY_SET);
    when(pom.getGav()).thenReturn(new GAV("groupId", "artifactId", "0.0.2"));
    service.save(pomPath, pomXml, metaData, comment, DeploymentMode.VALIDATED);
    verify(moduleService, times(1)).resolveModule(pomPath);
    verify(moduleRepositoriesService, times(1)).load(moduleRepositoriesPath);
    verify(repositoryResolver, times(1)).getRepositoriesResolvingArtifact(eq(pomXml), any(MavenRepositoryMetadata.class));
    final List<MavenRepositoryMetadata> resolvedRepositories = resolvedRepositoriesCaptor.getAllValues();
    assertNotNull(resolvedRepositories);
    assertEquals(1, resolvedRepositories.size());
    final MavenRepositoryMetadata repositoryMetadata = resolvedRepositories.get(0);
    assertEquals("local-id", repositoryMetadata.getId());
    assertEquals("local-url", repositoryMetadata.getUrl());
    assertEquals(MavenRepositorySource.LOCAL, repositoryMetadata.getSource());
    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) 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)

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