Search in sources :

Example 1 with JGitFileSystem

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

the class DefaultMavenCompilerTest method buildWithAllDecoratorsTest.

// 
@Test
public void buildWithAllDecoratorsTest() throws Exception {
    String alternateSettingsAbsPath = new File("src/test/settings.xml").getAbsolutePath();
    AFCompiler compiler = MavenCompilerFactory.getCompiler(Decorator.JGIT_BEFORE_AND_LOG_AFTER);
    String MASTER_BRANCH = "master";
    // 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");
        }
    });
    assertNotNull(origin);
    ioService.startBatch(origin);
    ioService.write(origin.getPath("/dummy/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/kjar-2-single-resources/pom.xml").toPath())));
    ioService.write(origin.getPath("/dummy/src/main/java/org/kie/maven/plugin/test/Person.java"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java").toPath())));
    ioService.write(origin.getPath("/dummy/src/main/resources/AllResourceTypes/simple-rules.drl"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/kjar-2-single-resources/src/main/resources/AllResourceTypes/simple-rules.drl").toPath())));
    ioService.write(origin.getPath("/dummy/src/main/resources/META-INF/kmodule.xml"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml").toPath())));
    ioService.endBatch();
    RevCommit lastCommit = origin.getGit().resolveRevCommit(origin.getGit().getRef(MASTER_BRANCH).getObjectId());
    assertNotNull(lastCommit);
    // clone into a regularfs
    Path tmpRootCloned = Files.createTempDirectory("cloned");
    Path tmpCloned = Files.createDirectories(Paths.get(tmpRootCloned.toString(), ".clone.git"));
    final Git cloned = Git.cloneRepository().setURI("git://localhost:9418/repo").setBare(false).setDirectory(tmpCloned.toFile()).call();
    assertNotNull(cloned);
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(tmpCloned + "/dummy"));
    CompilationRequest req = new DefaultCompilationRequest(mavenRepo.toAbsolutePath().toString(), info, new String[] { MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath }, new HashMap<>(), Boolean.TRUE);
    CompilationResponse res = compiler.compileSync(req);
    if (res.getMavenOutput().isPresent() && !res.isSuccessful()) {
        TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(), "KieDefaultMavenCompilerOnInMemoryFSTest.buildWithAllDecoratorsTest");
    }
    assertTrue(res.getMavenOutput().isPresent());
    assertTrue(res.isSuccessful());
    lastCommit = origin.getGit().resolveRevCommit(origin.getGit().getRef(MASTER_BRANCH).getObjectId());
    assertNotNull(lastCommit);
    // change one file and commit on the origin repo
    ioService.write(origin.getPath("/dummy/src/main/java/org/kie/maven/plugin/test/Person.java"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/Person.java").toPath())));
    RevCommit commitBefore = origin.getGit().resolveRevCommit(origin.getGit().getRef(MASTER_BRANCH).getObjectId());
    assertNotNull(commitBefore);
    assertFalse(lastCommit.getId().toString().equals(commitBefore.getId().toString()));
    // recompile
    res = compiler.compileSync(req);
    if (res.getMavenOutput().isPresent() && !res.isSuccessful()) {
        TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(), "KieDefaultMavenCompilerOnInMemoryFSTest.buildWithAllDecoratorsTest");
    }
    assertTrue(res.isSuccessful());
    assertTrue(res.getMavenOutput().isPresent());
    TestUtil.rm(tmpRootCloned.toFile());
}
Also used : Path(org.uberfire.java.nio.file.Path) HashMap(java.util.HashMap) CompilationResponse(org.kie.workbench.common.services.backend.compiler.CompilationResponse) URI(java.net.URI) Git(org.eclipse.jgit.api.Git) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest) File(java.io.File) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 2 with JGitFileSystem

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

the class DefaultMavenCompilerTest method buildWithJGitDecoratorTest.

@Test
public void buildWithJGitDecoratorTest() throws Exception {
    AFCompiler compiler = MavenCompilerFactory.getCompiler(Decorator.JGIT_BEFORE);
    String MASTER_BRANCH = "master";
    // 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");
        }
    });
    assertNotNull(origin);
    ioService.startBatch(origin);
    ioService.write(origin.getPath("/dummy/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/pom.xml").toPath())));
    ioService.write(origin.getPath("/dummy/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("/dummy/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("/dummy/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("/dummy/dummyB/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyB/pom.xml").toPath())));
    ioService.endBatch();
    RevCommit lastCommit = origin.getGit().resolveRevCommit(origin.getGit().getRef(MASTER_BRANCH).getObjectId());
    assertNotNull(lastCommit);
    // @TODO refactor and use only one between the URI or Git
    // @TODO find a way to resolve the problem of the prjname inside .git folder
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(origin.getPath("/dummy/"));
    CompilationRequest req = new DefaultCompilationRequest(mavenRepo.toAbsolutePath().toString(), info, new String[] { MavenCLIArgs.CLEAN, MavenCLIArgs.COMPILE }, new HashMap<>(), Boolean.FALSE);
    CompilationResponse res = compiler.compileSync(req);
    if (res.getMavenOutput().isPresent() && !res.isSuccessful()) {
        TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(), "KieDefaultMavenCompilerOnInMemoryFSTest.buildWithJGitDecoratorTest");
    }
    assertTrue(res.isSuccessful());
    lastCommit = origin.getGit().resolveRevCommit(origin.getGit().getRef(MASTER_BRANCH).getObjectId());
    ;
    assertNotNull(lastCommit);
    ioService.write(origin.getPath("/dummy/dummyA/src/main/java/dummy/DummyA.java"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/DummyA.java").toPath())));
    RevCommit commitBefore = origin.getGit().resolveRevCommit(origin.getGit().getRef(MASTER_BRANCH).getObjectId());
    assertNotNull(commitBefore);
    assertFalse(lastCommit.getId().toString().equals(commitBefore.getId().toString()));
    // recompile
    res = compiler.compileSync(req);
    // assert commits
    assertTrue(res.isSuccessful());
}
Also used : HashMap(java.util.HashMap) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest) CompilationResponse(org.kie.workbench.common.services.backend.compiler.CompilationResponse) URI(java.net.URI) File(java.io.File) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 3 with JGitFileSystem

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

the class KieDefaultMavenCompilerTest method buildWithAllDecoratorsTest.

// 
@Test
public void buildWithAllDecoratorsTest() throws Exception {
    String alternateSettingsAbsPath = new File("src/test/settings.xml").getAbsolutePath();
    AFCompiler compiler = KieMavenCompilerFactory.getCompiler(KieDecorator.JGIT_BEFORE_AND_LOG_AFTER);
    String MASTER_BRANCH = "master";
    // 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");
        }
    });
    assertNotNull(origin);
    ioService.startBatch(origin);
    ioService.write(origin.getPath("/dummy/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/kjar-2-single-resources/pom.xml").toPath())));
    ioService.write(origin.getPath("/dummy/src/main/java/org/kie/maven/plugin/test/Person.java"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java").toPath())));
    ioService.write(origin.getPath("/dummy/src/main/resources/AllResourceTypes/simple-rules.drl"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/kjar-2-single-resources/src/main/resources/AllResourceTypes/simple-rules.drl").toPath())));
    ioService.write(origin.getPath("/dummy/src/main/resources/META-INF/kmodule.xml"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml").toPath())));
    ioService.endBatch();
    RevCommit lastCommit = origin.getGit().resolveRevCommit(origin.getGit().getRef(MASTER_BRANCH).getObjectId());
    assertNotNull(lastCommit);
    // clone into a regularfs
    Path tmpRootCloned = Files.createTempDirectory("cloned");
    Path tmpCloned = Files.createDirectories(Paths.get(tmpRootCloned.toString(), ".clone.git"));
    // @TODO find a way to retrieve the address git://... of the repo
    final Git cloned = Git.cloneRepository().setURI("git://localhost:9418/repo").setBare(false).setDirectory(tmpCloned.toFile()).call();
    assertNotNull(cloned);
    // @TODO refactor and use only one between the URI or Git
    // @TODO find a way to resolve the problem of the prjname inside .git folder
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(tmpCloned + "/dummy"));
    CompilationRequest req = new DefaultCompilationRequest(mavenRepo.toAbsolutePath().toString(), info, new String[] { MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath }, new HashMap<>(), Boolean.TRUE);
    CompilationResponse res = compiler.compileSync(req);
    if (res.getMavenOutput().isPresent() && !res.isSuccessful()) {
        TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(), "KieDefaultMavenCompilerTest.buildWithAllDecoratorsTest");
    }
    assertTrue(res.getMavenOutput().isPresent());
    assertTrue(res.isSuccessful());
    lastCommit = origin.getGit().resolveRevCommit(origin.getGit().getRef(MASTER_BRANCH).getObjectId());
    assertNotNull(lastCommit);
    // change one file and commit on the origin repo
    ioService.write(origin.getPath("/dummy/src/main/java/org/kie/maven/plugin/test/Person.java"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/Person.java").toPath())));
    RevCommit commitBefore = origin.getGit().resolveRevCommit(origin.getGit().getRef(MASTER_BRANCH).getObjectId());
    assertNotNull(commitBefore);
    assertFalse(lastCommit.getId().toString().equals(commitBefore.getId().toString()));
    // recompile
    res = compiler.compileSync(req);
    if (res.getMavenOutput().isPresent() && !res.isSuccessful()) {
        TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(), "KieDefaultMavenCompilerTest.buildWithAllDecoratorsTest");
    }
    assertTrue(res.isSuccessful());
    assertTrue(res.getMavenOutput().isPresent());
    TestUtil.rm(tmpRootCloned.toFile());
}
Also used : Path(org.uberfire.java.nio.file.Path) HashMap(java.util.HashMap) CompilationResponse(org.kie.workbench.common.services.backend.compiler.CompilationResponse) URI(java.net.URI) Git(org.eclipse.jgit.api.Git) WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.nio.WorkspaceCompilationInfo) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest) File(java.io.File) AFCompiler(org.kie.workbench.common.services.backend.compiler.nio.AFCompiler) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) CompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.CompilationRequest) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 4 with JGitFileSystem

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

the class ProjectImportServiceImplTest method importDefaultProjectTest.

@Test
public void importDefaultProjectTest() {
    final OrganizationalUnit organizationalUnit = new OrganizationalUnitImpl("myteam", "org.whatever");
    organizationalUnit.getRepositories();
    final Path exampleRoot = mock(Path.class);
    org.uberfire.java.nio.file.Path fspath = mock(org.uberfire.java.nio.file.Path.class);
    final JGitFileSystem fileSystem = mock(JGitFileSystem.class);
    doReturn(fileSystem).when(fspath).getFileSystem();
    final org.uberfire.java.nio.file.Path exampleRootNioPath = fspath;
    String repoURL = "file:///some/repo/url";
    final ImportProject importProject = new ImportProject(exampleRoot, "example", "description", repoURL, emptyList());
    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);
    when(repoService.createRepository(same(organizationalUnit), eq(GitRepository.SCHEME.toString()), any(), any())).thenReturn(repository);
    when(service.getProjectRoot(importProject)).thenReturn(exampleRootNioPath);
    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());
    assertNull(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) 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 5 with JGitFileSystem

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

the class ProjectImportServiceImplTest method importDefaultProjectInWindowsTest.

@Test
public void importDefaultProjectInWindowsTest() {
    final OrganizationalUnit organizationalUnit = new OrganizationalUnitImpl("myteam", "org.whatever");
    organizationalUnit.getRepositories();
    final Path exampleRoot = mock(Path.class);
    org.uberfire.java.nio.file.Path fspath = mock(org.uberfire.java.nio.file.Path.class);
    final JGitFileSystem fileSystem = mock(JGitFileSystem.class);
    doReturn(fileSystem).when(fspath).getFileSystem();
    final org.uberfire.java.nio.file.Path exampleRootNioPath = fspath;
    String repoURL = "file:///C:/some/repo/url";
    final ImportProject importProject = new ImportProject(exampleRoot, "example", "description", repoURL, emptyList());
    doReturn(emptyList()).when(service).getBranches(Mockito.<org.uberfire.java.nio.file.Path>any(), any());
    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);
    when(repoService.createRepository(same(organizationalUnit), eq(GitRepository.SCHEME.toString()), any(), any())).thenReturn(repository);
    when(service.getProjectRoot(importProject)).thenReturn(exampleRootNioPath);
    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());
    assertNull(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) 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)

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