Search in sources :

Example 6 with JGitFileSystem

use of org.uberfire.java.nio.fs.jgit.JGitFileSystem 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 7 with JGitFileSystem

use of org.uberfire.java.nio.fs.jgit.JGitFileSystem in project kie-wb-common by kiegroup.

the class KieDefaultMavenCompilerTest method buildWithPullRebaseUberfireTest.

@Test
public void buildWithPullRebaseUberfireTest() throws Exception {
    // Setup origin in memory
    final URI originRepo = URI.create("git://repo");
    final JGitFileSystem origin = (JGitFileSystem) ioService.newFileSystem(originRepo, new HashMap<String, Object>() {

        {
            put("init", Boolean.TRUE);
            put("internal", Boolean.TRUE);
            put("listMode", "ALL");
        }
    });
    ioService.startBatch(origin);
    ioService.write(origin.getPath("/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/pom.xml").toPath())));
    ioService.write(origin.getPath("/dummyA/src/main/java/dummy/DummyA.java"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyA/src/main/java/dummy/DummyA.java").toPath())));
    ioService.write(origin.getPath("/dummyB/src/main/java/dummy/DummyB.java"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyB/src/main/java/dummy/DummyB.java").toPath())));
    ioService.write(origin.getPath("/dummyA/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyA/pom.xml").toPath())));
    ioService.write(origin.getPath("/dummyB/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyB/pom.xml").toPath())));
    ioService.endBatch();
    // clone into a regularfs
    Path tmpRootCloned = Files.createTempDirectory("cloned");
    Path tmpCloned = Files.createDirectories(Paths.get(tmpRootCloned.toString(), ".clone"));
    final Git cloned = Git.cloneRepository().setURI(origin.getGit().getRepository().getDirectory().toURI().toString()).setBare(false).setDirectory(tmpCloned.toFile()).call();
    assertThat(cloned).isNotNull();
    PullCommand pc = cloned.pull().setRemote("origin").setRebase(Boolean.TRUE);
    PullResult pullRes = pc.call();
    // nothing changed yet
    assertThat(pullRes.getRebaseResult().getStatus()).isEqualTo(RebaseResult.Status.UP_TO_DATE);
    RebaseCommand rb = cloned.rebase().setUpstream("origin/master");
    RebaseResult rbResult = rb.setPreserveMerges(true).call();
    assertThat(rbResult.getStatus().isSuccessful()).isTrue();
    // Compile the repo
    byte[] encoded = Files.readAllBytes(Paths.get(tmpCloned + "/pom.xml"));
    String pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
    assertThat(pomAsAstring).doesNotContain(TestConstants.TAKARI_LIFECYCLE_ARTIFACT);
    Path prjFolder = Paths.get(tmpCloned + "/");
    final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.ENABLE_LOGGING, KieDecorator.ENABLE_INCREMENTAL_BUILD));
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(prjFolder);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE }, Boolean.TRUE);
    CompilationResponse res = compiler.compile(req);
    TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(tmpCloned, res, this.getClass(), testName);
    assertThat(res.isSuccessful()).isTrue();
    Path incrementalConfiguration = Paths.get(prjFolder + TestConstants.TARGET_TAKARI_PLUGIN);
    assertThat(incrementalConfiguration.toFile()).exists();
    encoded = Files.readAllBytes(Paths.get(prjFolder + "/pom.xml"));
    pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
    assertThat(pomAsAstring).contains(TestConstants.KIE_TAKARI_LIFECYCLE_ARTIFACT);
    TestUtil.rm(tmpRootCloned.toFile());
}
Also used : Path(org.uberfire.java.nio.file.Path) PullCommand(org.eclipse.jgit.api.PullCommand) HashMap(java.util.HashMap) RebaseCommand(org.eclipse.jgit.api.RebaseCommand) CompilationResponse(org.kie.workbench.common.services.backend.compiler.CompilationResponse) URI(java.net.URI) PullResult(org.eclipse.jgit.api.PullResult) TestUtilGit(org.kie.workbench.common.services.backend.compiler.TestUtilGit) Git(org.eclipse.jgit.api.Git) WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) File(java.io.File) RebaseResult(org.eclipse.jgit.api.RebaseResult) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) AFCompiler(org.kie.workbench.common.services.backend.compiler.AFCompiler) CompilationRequest(org.kie.workbench.common.services.backend.compiler.CompilationRequest) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) Test(org.junit.Test)

Example 8 with JGitFileSystem

use of org.uberfire.java.nio.fs.jgit.JGitFileSystem in project kie-wb-common by kiegroup.

the class JGitUtilsTest method tempCloneTest.

@Test
public void tempCloneTest() throws Exception {
    final String repoName = "myrepo";
    final JGitFileSystem fs = (JGitFileSystem) ioService.newFileSystem(URI.create("git://" + repoName), new HashMap<String, Object>() {

        {
            put("init", Boolean.TRUE);
            put("internal", Boolean.TRUE);
        }
    });
    ioService.startBatch(fs);
    ioService.write(fs.getPath("/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/pom.xml").toPath())));
    ioService.write(fs.getPath("/dummyA/src/main/java/dummy/DummyA.java"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyA/src/main/java/dummy/DummyA.java").toPath())));
    ioService.write(fs.getPath("/dummyB/src/main/java/dummy/DummyB.java"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyB/src/main/java/dummy/DummyB.java").toPath())));
    ioService.write(fs.getPath("/dummyA/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyA/pom.xml").toPath())));
    ioService.write(fs.getPath("/dummyB/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyB/pom.xml").toPath())));
    ioService.endBatch();
    String uuid = UUID.randomUUID().toString();
    Git git = JGitUtils.tempClone(fs, uuid);
    assertThat(git).isNotNull();
    assertThat(git.getRepository().getBranch()).isEqualTo("master");
    assertThat(git.getRepository().getFullBranch()).isEqualTo("refs/heads/master");
    assertThat(git.getRepository().getDirectory()).exists();
    TestUtil.rm(git.getRepository().getDirectory());
}
Also used : Git(org.eclipse.jgit.api.Git) HashMap(java.util.HashMap) File(java.io.File) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) DefaultMavenCompilerTest(org.kie.workbench.common.services.backend.compiler.DefaultMavenCompilerTest) Test(org.junit.Test)

Example 9 with JGitFileSystem

use of org.uberfire.java.nio.fs.jgit.JGitFileSystem in project kie-wb-common by kiegroup.

the class JGITCompilerBeforeDecoratorTest method createFileSystem.

private FileSystem createFileSystem(String repoName) throws Exception {
    HashMap<String, Object> env = new HashMap<>();
    env.put("init", Boolean.TRUE);
    env.put("internal", Boolean.TRUE);
    final JGitFileSystem fs = (JGitFileSystem) ioService.newFileSystem(URI.create("git://" + repoName), env);
    ioService.startBatch(fs);
    ioService.write(fs.getPath("/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/pom.xml").toPath())));
    ioService.write(fs.getPath("/dummyA/src/main/java/dummy/DummyA.java"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyA/src/main/java/dummy/DummyA.java").toPath())));
    ioService.write(fs.getPath("/dummyB/src/main/java/dummy/DummyB.java"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyB/src/main/java/dummy/DummyB.java").toPath())));
    ioService.write(fs.getPath("/dummyA/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyA/pom.xml").toPath())));
    ioService.write(fs.getPath("/dummyB/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyB/pom.xml").toPath())));
    ioService.endBatch();
    return fs;
}
Also used : HashMap(java.util.HashMap) File(java.io.File) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem)

Example 10 with JGitFileSystem

use of org.uberfire.java.nio.fs.jgit.JGitFileSystem in project kie-wb-common by kiegroup.

the class DefaultMavenCompilerTest method buildWithCloneTest.

@Test
public void buildWithCloneTest() throws Exception {
    final String repoName = "myrepo";
    final JGitFileSystem fs = (JGitFileSystem) ioService.newFileSystem(URI.create("git://" + repoName), new HashMap<String, Object>() {

        {
            put("init", Boolean.TRUE);
            put("internal", Boolean.TRUE);
        }
    });
    ioService.startBatch(fs);
    ioService.write(fs.getPath("/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/pom.xml").toPath())));
    ioService.write(fs.getPath("/dummyA/src/main/java/dummy/DummyA.java"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyA/src/main/java/dummy/DummyA.java").toPath())));
    ioService.write(fs.getPath("/dummyB/src/main/java/dummy/DummyB.java"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyB/src/main/java/dummy/DummyB.java").toPath())));
    ioService.write(fs.getPath("/dummyA/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyA/pom.xml").toPath())));
    ioService.write(fs.getPath("/dummyB/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyB/pom.xml").toPath())));
    ioService.endBatch();
    Path tmpRootCloned = Files.createTempDirectory("cloned");
    Path tmpCloned = Files.createDirectories(Paths.get(tmpRootCloned.toString(), "dummy"));
    final File gitClonedFolder = new File(tmpCloned.toFile(), ".clone.git");
    final Git cloned = Git.cloneRepository().setURI(fs.getGit().getRepository().getDirectory().toURI().toString()).setBare(false).setDirectory(gitClonedFolder).call();
    assertThat(cloned).isNotNull();
    // Compile the repo
    Path prjFolder = Paths.get(gitClonedFolder + "/");
    byte[] encoded = Files.readAllBytes(Paths.get(prjFolder + "/pom.xml"));
    String pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
    assertThat(pomAsAstring).doesNotContain(TestConstants.TAKARI_LIFECYCLE_ARTIFACT);
    final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.ENABLE_LOGGING, KieDecorator.ENABLE_INCREMENTAL_BUILD));
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(prjFolder);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE }, Boolean.TRUE);
    CompilationResponse res = compiler.compile(req);
    TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(tmpCloned, res, this.getClass(), testName);
    assertThat(res.isSuccessful()).isTrue();
    Path incrementalConfiguration = Paths.get(prjFolder + TestConstants.TARGET_TAKARI_PLUGIN);
    assertThat(incrementalConfiguration.toFile()).exists();
    encoded = Files.readAllBytes(Paths.get(prjFolder + "/pom.xml"));
    pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
    assertThat(pomAsAstring).contains(TestConstants.KIE_TAKARI_LIFECYCLE_ARTIFACT);
    TestUtil.rm(tmpRootCloned.toFile());
}
Also used : Path(org.uberfire.java.nio.file.Path) Git(org.eclipse.jgit.api.Git) WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo) HashMap(java.util.HashMap) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) File(java.io.File) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) Test(org.junit.Test)

Aggregations

JGitFileSystem (org.uberfire.java.nio.fs.jgit.JGitFileSystem)30 Test (org.junit.Test)27 HashMap (java.util.HashMap)26 File (java.io.File)25 Git (org.eclipse.jgit.api.Git)19 Path (org.uberfire.java.nio.file.Path)16 URI (java.net.URI)15 CompilationResponse (org.kie.workbench.common.services.backend.compiler.CompilationResponse)13 DefaultCompilationRequest (org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest)10 WorkspaceCompilationInfo (org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo)10 RevCommit (org.eclipse.jgit.revwalk.RevCommit)9 DefaultCompilationRequest (org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest)9 PullCommand (org.eclipse.jgit.api.PullCommand)5 PullResult (org.eclipse.jgit.api.PullResult)5 RebaseCommand (org.eclipse.jgit.api.RebaseCommand)5 RebaseResult (org.eclipse.jgit.api.RebaseResult)5 AFCompiler (org.kie.workbench.common.services.backend.compiler.AFCompiler)4 CompilationRequest (org.kie.workbench.common.services.backend.compiler.CompilationRequest)4 CompilationRequest (org.kie.workbench.common.services.backend.compiler.nio.CompilationRequest)4 WorkspaceCompilationInfo (org.kie.workbench.common.services.backend.compiler.nio.WorkspaceCompilationInfo)4