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());
}
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());
}
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());
}
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);
}
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);
}
Aggregations