Search in sources :

Example 1 with ExampleRepository

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);
}
Also used : ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) Repository(org.guvnor.structure.repositories.Repository) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) Module(org.guvnor.common.services.project.model.Module)

Example 2 with ExampleRepository

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);
    }
}
Also used : ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) ZipEntry(java.util.zip.ZipEntry) IOException(org.uberfire.java.nio.IOException) URL(java.net.URL) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) ZipInputStream(java.util.zip.ZipInputStream) Git(org.eclipse.jgit.api.Git) FileOutputStream(java.io.FileOutputStream) File(java.io.File) PostConstruct(javax.annotation.PostConstruct)

Example 3 with ExampleRepository

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"))));
}
Also used : Path(org.uberfire.backend.vfs.Path) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) Branch(org.guvnor.structure.repositories.Branch) ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) ConfigGroup(org.guvnor.structure.server.config.ConfigGroup) Module(org.guvnor.common.services.project.model.Module) KieModule(org.kie.workbench.common.services.shared.project.KieModule) ExampleProject(org.kie.workbench.common.screens.examples.model.ExampleProject) KieModule(org.kie.workbench.common.services.shared.project.KieModule) POM(org.guvnor.common.services.project.model.POM) Test(org.junit.Test)

Example 4 with ExampleRepository

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);
}
Also used : ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) Repository(org.guvnor.structure.repositories.Repository) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) ConfigGroup(org.guvnor.structure.server.config.ConfigGroup) ConfigType(org.guvnor.structure.server.config.ConfigType) Test(org.junit.Test)

Example 5 with ExampleRepository

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;
    }
}
Also used : ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository)

Aggregations

ExampleRepository (org.kie.workbench.common.screens.examples.model.ExampleRepository)27 Test (org.junit.Test)19 ExampleProject (org.kie.workbench.common.screens.examples.model.ExampleProject)11 GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)6 ConfigGroup (org.guvnor.structure.server.config.ConfigGroup)6 Module (org.guvnor.common.services.project.model.Module)4 Branch (org.guvnor.structure.repositories.Branch)3 Repository (org.guvnor.structure.repositories.Repository)3 KieModule (org.kie.workbench.common.services.shared.project.KieModule)3 Path (org.uberfire.backend.vfs.Path)3 HashSet (java.util.HashSet)2 ConfigType (org.guvnor.structure.server.config.ConfigType)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 ZipEntry (java.util.zip.ZipEntry)1 ZipInputStream (java.util.zip.ZipInputStream)1 PostConstruct (javax.annotation.PostConstruct)1 Git (org.eclipse.jgit.api.Git)1