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