Search in sources :

Example 1 with FileSystemProvider

use of org.uberfire.java.nio.file.spi.FileSystemProvider in project kie-wb-common by kiegroup.

the class ProjectImportServiceImplTest method importProjectInSubdirectory.

@Test
public void importProjectInSubdirectory() {
    final OrganizationalUnit organizationalUnit = new OrganizationalUnitImpl("myteam", "org.whatever");
    organizationalUnit.getRepositories();
    final String exampleURI = "default://main@system/repo/example";
    final Path exampleRoot = PathFactory.newPath("example", exampleURI);
    final JGitFileSystem fs = mock(JGitFileSystem.class);
    final FileSystemProvider provider = mock(FileSystemProvider.class);
    when(fs.provider()).thenReturn(provider);
    final org.uberfire.java.nio.file.Path exampleRootNioPath = JGitPathImpl.create(fs, "/example", "main@system/repo", true);
    final org.uberfire.java.nio.file.Path repoRoot = exampleRootNioPath.getParent();
    when(fs.getRootDirectories()).thenReturn(() -> Stream.of(repoRoot).iterator());
    when(pathUtil.stripProtocolAndBranch(any())).then(inv -> realPathUtil.stripProtocolAndBranch(inv.getArgument(0, String.class)));
    when(pathUtil.stripRepoNameAndSpace(any())).then(inv -> realPathUtil.stripRepoNameAndSpace(inv.getArgument(0, String.class)));
    when(pathUtil.convert(Mockito.<org.uberfire.java.nio.file.Path>any())).then(inv -> realPathUtil.convert(inv.getArgument(0, org.uberfire.java.nio.file.Path.class)));
    when(pathUtil.extractBranch(any())).then(inv -> realPathUtil.extractBranch(inv.getArgument(0, String.class)));
    String repoURL = "file:///some/repo/url";
    final ImportProject importProject = new ImportProject(exampleRoot, "example", "description", repoURL, emptyList());
    when(service.getProjectRoot(importProject)).thenReturn(exampleRootNioPath);
    when(pathUtil.getNiogitRepoPath(any())).thenReturn(repoURL);
    final Repository repository = new GitRepository("example", new Space("myteam"));
    final WorkspaceProject project = new WorkspaceProject(organizationalUnit, repository, new Branch("main", mock(Path.class)), new Module());
    when(projectService.resolveProject(repository)).thenReturn(project);
    doReturn(repository).when(repoService).createRepository(same(organizationalUnit), eq(GitRepository.SCHEME.toString()), any(), any());
    final WorkspaceProject importedProject = service.importProject(organizationalUnit, importProject);
    assertSame(project, importedProject);
    final ArgumentCaptor<RepositoryEnvironmentConfigurations> configsCaptor = ArgumentCaptor.forClass(RepositoryEnvironmentConfigurations.class);
    verify(repoService).createRepository(same(organizationalUnit), eq(GitRepository.SCHEME.toString()), any(), configsCaptor.capture());
    final RepositoryEnvironmentConfigurations configs = configsCaptor.getValue();
    assertEquals(repoURL, configs.getOrigin());
    assertEquals("example", configs.getSubdirectory());
    verify(projectService).resolveProject(repository);
}
Also used : Path(org.uberfire.backend.vfs.Path) Space(org.uberfire.spaces.Space) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) Mockito.anyString(org.mockito.Mockito.anyString) OrganizationalUnitImpl(org.guvnor.structure.organizationalunit.impl.OrganizationalUnitImpl) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) ImportUtils.makeGitRepository(org.kie.workbench.common.screens.examples.backend.server.ImportUtils.makeGitRepository) ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) Repository(org.guvnor.structure.repositories.Repository) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) ImportUtils.makeGitRepository(org.kie.workbench.common.screens.examples.backend.server.ImportUtils.makeGitRepository) RepositoryEnvironmentConfigurations(org.guvnor.structure.repositories.RepositoryEnvironmentConfigurations) FileSystemProvider(org.uberfire.java.nio.file.spi.FileSystemProvider) Branch(org.guvnor.structure.repositories.Branch) Module(org.guvnor.common.services.project.model.Module) KieModule(org.kie.workbench.common.services.shared.project.KieModule) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) Test(org.junit.Test)

Example 2 with FileSystemProvider

use of org.uberfire.java.nio.file.spi.FileSystemProvider in project kie-wb-common by kiegroup.

the class BaseProjectImportService method exists.

private boolean exists(org.uberfire.java.nio.file.Path path) {
    try {
        final FileSystemProvider provider = path.getFileSystem().provider();
        provider.readAttributes(path, BasicFileAttributes.class);
        return true;
    } catch (NoSuchFileException nfe) {
        return false;
    }
}
Also used : FileSystemProvider(org.uberfire.java.nio.file.spi.FileSystemProvider) NoSuchFileException(org.uberfire.java.nio.file.NoSuchFileException)

Example 3 with FileSystemProvider

use of org.uberfire.java.nio.file.spi.FileSystemProvider in project kie-wb-common by kiegroup.

the class DefaultIncrementalCompilerEnablerTest method testReadPomsInaPrjTest.

@Test
public void testReadPomsInaPrjTest() throws Exception {
    FileSystemProvider fs = FileSystemProviders.getDefaultProvider();
    Path tmpRoot = Files.createTempDirectory("repo");
    // NIO creation and copy content
    Path temp = Files.createDirectories(Paths.get(tmpRoot.toString(), "dummy"));
    TestUtil.copyTree(Paths.get("src/test/projects/dummy_multimodule_untouched"), temp);
    // end NIO
    Path tmp = Paths.get(tmpRoot.toAbsolutePath().toString(), "dummy");
    Path mainPom = Paths.get(temp.toAbsolutePath().toString(), "pom.xml");
    byte[] encoded = Files.readAllBytes(Paths.get(temp.toAbsolutePath().toString(), "pom.xml"));
    String pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
    assertThat(pomAsAstring).doesNotContain(TestConstants.TAKARI_LIFECYCLE_ARTIFACT);
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(tmp);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE }, Boolean.FALSE);
    DefaultIncrementalCompilerEnabler enabler = new DefaultIncrementalCompilerEnabler();
    assertThat(enabler.process(req).getResult()).isTrue();
    encoded = Files.readAllBytes(Paths.get(mainPom.toString()));
    pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
    assertThat(pomAsAstring).contains(TestConstants.KIE_TAKARI_LIFECYCLE_ARTIFACT);
    assertThat(pomAsAstring.contains("kie-takari-plugin")).isFalse();
    TestUtil.rm(tmpRoot.toFile());
}
Also used : Path(org.uberfire.java.nio.file.Path) WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo) FileSystemProvider(org.uberfire.java.nio.file.spi.FileSystemProvider) DefaultIncrementalCompilerEnabler(org.kie.workbench.common.services.backend.compiler.impl.incrementalenabler.DefaultIncrementalCompilerEnabler) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) Test(org.junit.Test)

Example 4 with FileSystemProvider

use of org.uberfire.java.nio.file.spi.FileSystemProvider in project kie-wb-common by kiegroup.

the class DefaultIncrementalCompilerEnablerTest method testReadPomsInaPrjTest.

@Test
public void testReadPomsInaPrjTest() throws Exception {
    FileSystemProvider fs = FileSystemProviders.getDefaultProvider();
    Path tmpRoot = Files.createTempDirectory("repo");
    // NIO creation and copy content
    Path temp = Files.createDirectories(Paths.get(tmpRoot.toString(), "dummy"));
    TestUtil.copyTree(Paths.get("src/test/projects/dummy_multimodule_untouched"), temp);
    // end NIO
    Path tmp = Paths.get(tmpRoot.toAbsolutePath().toString(), "dummy");
    Path mainPom = Paths.get(temp.toAbsolutePath().toString(), "pom.xml");
    byte[] encoded = Files.readAllBytes(Paths.get(temp.toAbsolutePath().toString(), "pom.xml"));
    String pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
    assertFalse(pomAsAstring.contains("<artifactId>takari-lifecycle-plugin</artifactId>"));
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(tmp);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepo.toAbsolutePath().toString(), info, new String[] { MavenCLIArgs.CLEAN, MavenCLIArgs.COMPILE }, new HashMap<>(), Boolean.FALSE);
    DefaultIncrementalCompilerEnabler enabler = new DefaultIncrementalCompilerEnabler(Compilers.JAVAC);
    Assert.assertTrue(enabler.process(req).getResult());
    encoded = Files.readAllBytes(Paths.get(mainPom.toString()));
    pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
    Assert.assertTrue(pomAsAstring.contains("<artifactId>takari-lifecycle-plugin</artifactId>"));
    assertFalse(pomAsAstring.contains("kie-takari-plugin"));
    TestUtil.rm(tmpRoot.toFile());
}
Also used : Path(org.uberfire.java.nio.file.Path) FileSystemProvider(org.uberfire.java.nio.file.spi.FileSystemProvider) DefaultIncrementalCompilerEnabler(org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultIncrementalCompilerEnabler) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest) Test(org.junit.Test)

Aggregations

FileSystemProvider (org.uberfire.java.nio.file.spi.FileSystemProvider)4 Test (org.junit.Test)3 Path (org.uberfire.java.nio.file.Path)2 Module (org.guvnor.common.services.project.model.Module)1 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)1 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)1 OrganizationalUnitImpl (org.guvnor.structure.organizationalunit.impl.OrganizationalUnitImpl)1 Branch (org.guvnor.structure.repositories.Branch)1 Repository (org.guvnor.structure.repositories.Repository)1 RepositoryEnvironmentConfigurations (org.guvnor.structure.repositories.RepositoryEnvironmentConfigurations)1 GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)1 ImportUtils.makeGitRepository (org.kie.workbench.common.screens.examples.backend.server.ImportUtils.makeGitRepository)1 ExampleRepository (org.kie.workbench.common.screens.examples.model.ExampleRepository)1 ImportProject (org.kie.workbench.common.screens.examples.model.ImportProject)1 DefaultCompilationRequest (org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest)1 WorkspaceCompilationInfo (org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo)1 DefaultIncrementalCompilerEnabler (org.kie.workbench.common.services.backend.compiler.impl.incrementalenabler.DefaultIncrementalCompilerEnabler)1 DefaultCompilationRequest (org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest)1 DefaultIncrementalCompilerEnabler (org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultIncrementalCompilerEnabler)1 KieModule (org.kie.workbench.common.services.shared.project.KieModule)1