use of org.kie.workbench.common.screens.examples.model.ExampleRepository in project kie-wb-common by kiegroup.
the class ExamplesServiceImpl method getProjects.
@Override
public Set<ExampleProject> getProjects(final ExampleRepository repository) {
if (repository == null) {
return Collections.emptySet();
}
final String repositoryURL = repository.getUrl();
if (repositoryURL == null || repositoryURL.trim().isEmpty()) {
return Collections.emptySet();
}
// Avoid cloning playground repository multiple times
Repository gitRepository = resolveGitRepository(repository);
if (gitRepository == null) {
return Collections.emptySet();
}
final Set<Module> modules = moduleService.getAllModules(gitRepository.getBranch("master").get());
return convert(modules);
}
use of org.kie.workbench.common.screens.examples.model.ExampleRepository in project kie-wb-common by kiegroup.
the class ExamplesServiceImpl method initPlaygroundRepository.
@PostConstruct
public void initPlaygroundRepository() {
try {
String userDir = System.getProperty("user.dir");
File playgroundDirectory = new File(userDir, ".kie-wb-playground");
if (playgroundDirectory.exists()) {
cleanPlaygroundDirectory(playgroundDirectory.toPath());
}
playgroundDirectory.mkdirs();
URL resource = getClass().getClassLoader().getResource(KIE_WB_PLAYGROUND_ZIP);
if (resource == null) {
logger.warn("Playground repository jar not found on classpath.");
return;
}
try (ZipInputStream inputStream = new ZipInputStream(resource.openStream())) {
ZipEntry zipEntry = null;
while ((zipEntry = inputStream.getNextEntry()) != null) {
byte[] buffer = new byte[1024];
File file = new File(playgroundDirectory, zipEntry.getName());
if (zipEntry.isDirectory()) {
file.mkdirs();
} else {
try (FileOutputStream fos = new FileOutputStream(file)) {
int read = -1;
while ((read = inputStream.read(buffer)) != -1) {
fos.write(buffer, 0, read);
}
}
}
}
final Git git = Git.init().setBare(false).setDirectory(playgroundDirectory).call();
git.add().addFilepattern(".").call();
git.commit().setMessage("Initial commit").call();
String repositoryUrl = resolveRepositoryUrl(playgroundDirectory.getAbsolutePath());
playgroundRepository = new ExampleRepository(repositoryUrl);
}
} catch (java.io.IOException | GitAPIException e) {
logger.error("Unable to initialize playground git repository. Only custom repository definition will be available in the Workbench.", e);
}
}
use of org.kie.workbench.common.screens.examples.model.ExampleRepository in project kie-wb-common by kiegroup.
the class ExamplesServiceImplTest method testGetProjects_PomDescription.
@Test
public void testGetProjects_PomDescription() {
final Path moduleRoot = mock(Path.class);
final POM pom = mock(POM.class);
final KieModule module = mock(KieModule.class);
when(pom.getDescription()).thenReturn("pom description");
when(module.getRootPath()).thenReturn(moduleRoot);
when(module.getModuleName()).thenReturn("module1");
when(module.getPom()).thenReturn(pom);
when(moduleRoot.toURI()).thenReturn("default:///module1");
when(metadataService.getTags(any(Path.class))).thenReturn(Arrays.asList("tag1", "tag2"));
final GitRepository repository = makeGitRepository();
when(repositoryFactory.newRepository(any(ConfigGroup.class))).thenReturn(repository);
when(moduleService.getAllModules(any(Branch.class))).thenReturn(new HashSet<Module>() {
{
add(module);
}
});
final Set<ExampleProject> modules = service.getProjects(new ExampleRepository("https://github.com/guvnorngtestuser1/guvnorng-playground.git"));
assertNotNull(modules);
assertEquals(1, modules.size());
assertTrue(modules.contains(new ExampleProject(moduleRoot, "module1", "pom description", Arrays.asList("tag1", "tag2"))));
}
use of org.kie.workbench.common.screens.examples.model.ExampleRepository in project kie-wb-common by kiegroup.
the class ExamplesServiceImplTest method resolveGitRepositoryNotClonedBefore.
@Test
public void resolveGitRepositoryNotClonedBefore() {
ExampleRepository playgroundRepository = new ExampleRepository("file:///home/user/folder/.kie-wb-playground");
service.setPlaygroundRepository(playgroundRepository);
ConfigGroup configGroup = new ConfigGroup();
when(configurationFactory.newConfigGroup(any(ConfigType.class), anyString(), anyString(), anyString())).thenReturn(configGroup);
doCallRealMethod().when(configurationFactory).newConfigItem(anyString(), anyBoolean());
doCallRealMethod().when(configurationFactory).newConfigItem(anyString(), anyString());
doCallRealMethod().when(configurationFactory).newConfigItem(anyString(), any(Object.class));
Repository repository = mock(Repository.class);
when(repositoryFactory.newRepository(configGroup)).thenReturn(repository);
Repository result = service.resolveGitRepository(playgroundRepository);
assertEquals(repository, result);
assertEquals(false, configGroup.getConfigItem(EnvironmentParameters.MIRROR).getValue());
verify(repositoryFactory, times(1)).newRepository(configGroup);
}
use of org.kie.workbench.common.screens.examples.model.ExampleRepository in project kie-wb-common by kiegroup.
the class ProjectPage method prepareView.
@Override
public void prepareView() {
final ExampleRepository sourceRepository = model.getSourceRepository();
final ExampleRepository selectedRepository = model.getSelectedRepository();
if (!isRepositorySelected(selectedRepository)) {
activeView = noRepositoryURLView;
} else if (!selectedRepository.isUrlValid()) {
activeView = noRepositoryURLView;
} else if (!selectedRepository.equals(sourceRepository)) {
activeView = fetchingRepositoryView;
fetchRepository(selectedRepository);
} else {
activeView = projectsView;
}
}
Aggregations