Search in sources :

Example 1 with GitConfigExecutor

use of org.guvnor.ala.source.git.executor.GitConfigExecutor in project kie-wb-common by kiegroup.

the class WildflyRuntimeTest method waitForAppBuildTest.

@Test
public void waitForAppBuildTest() {
    final Optional<Source> _source = new GitConfigExecutor(new InMemorySourceRegistry()).apply(new GitConfigImpl(tempPath.getAbsolutePath(), "master", gitUrl, "drools-workshop-build", "true"));
    assertTrue(_source.isPresent());
    final Source source = _source.get();
    assertNotNull(source);
    List<String> goals = new ArrayList<>();
    goals.add("package");
    Properties properties = new Properties();
    properties.setProperty("failIfNoTests", "false");
    final Path projectRoot = source.getPath();
    final InputStream pomStream = org.uberfire.java.nio.file.Files.newInputStream(projectRoot.resolve("pom.xml"));
    final MavenProject project = MavenProjectLoader.parseMavenPom(pomStream);
    RepositoryVisitor repositoryVisitor = new RepositoryVisitor(projectRoot, project.getName());
    final String expectedBinary = project.getArtifact().getArtifactId() + "-" + project.getArtifact().getVersion() + "." + project.getArtifact().getType();
    final org.guvnor.ala.build.maven.model.MavenProject mavenProject = new MavenProjectImpl(project.getId(), project.getArtifact().getType(), project.getName(), expectedBinary, source.getPath(), source.getPath(), source.getPath().resolve("target").resolve(expectedBinary).toAbsolutePath(), repositoryVisitor.getRoot().getAbsolutePath(), null);
    final File pom = new File(mavenProject.getTempDir(), "pom.xml");
    MavenBuildExecutor.executeMaven(pom, properties, goals.toArray(new String[0]));
    final File file = new File(repositoryVisitor.getRoot().getAbsolutePath() + "/target/" + mavenProject.getExpectedBinary());
    WildflyClient wildflyClient = new WildflyClient("", "admin", "Admin#70365", ip, 8080, 9990);
    wildflyClient.deploy(file);
    final String id = file.getName();
    WildflyAppState appState = wildflyClient.getAppState(id);
    assertNotNull(appState);
    assertTrue(appState.getState().equals(RUNNING));
    wildflyClient.undeploy(id);
    appState = wildflyClient.getAppState(id);
    assertNotNull(appState);
    assertTrue(appState.getState().equals(UNKNOWN));
    wildflyClient.deploy(file);
    appState = wildflyClient.getAppState(id);
    assertNotNull(appState);
    assertTrue(appState.getState().equals(RUNNING));
}
Also used : Path(org.uberfire.java.nio.file.Path) GitConfigImpl(org.guvnor.ala.source.git.config.impl.GitConfigImpl) InputStream(java.io.InputStream) RepositoryVisitor(org.guvnor.ala.build.maven.util.RepositoryVisitor) ArrayList(java.util.ArrayList) WildflyClient(org.guvnor.ala.wildfly.access.WildflyClient) MavenProjectImpl(org.guvnor.ala.build.maven.model.impl.MavenProjectImpl) Properties(java.util.Properties) WildflyAppState(org.guvnor.ala.wildfly.access.WildflyAppState) Source(org.guvnor.ala.source.Source) GitConfigExecutor(org.guvnor.ala.source.git.executor.GitConfigExecutor) InMemorySourceRegistry(org.guvnor.ala.registry.inmemory.InMemorySourceRegistry) MavenProject(org.apache.maven.project.MavenProject) File(java.io.File) Test(org.junit.Test)

Example 2 with GitConfigExecutor

use of org.guvnor.ala.source.git.executor.GitConfigExecutor in project kie-wb-common by kiegroup.

the class MavenCliOutputTest method buildAppAndWaitForMavenOutputTest.

@Test
public void buildAppAndWaitForMavenOutputTest() throws IOException {
    final Optional<Source> _source = new GitConfigExecutor(new InMemorySourceRegistry()).apply(new GitConfigImpl(tempPath.getAbsolutePath(), "master", gitUrl, "drools-workshop", "true"));
    assertTrue(_source.isPresent());
    final Source source = _source.get();
    boolean buildProcessReady = false;
    Throwable error = null;
    PipedOutputStream baosOut = new PipedOutputStream();
    PipedOutputStream baosErr = new PipedOutputStream();
    final PrintStream out = new PrintStream(baosOut, true);
    final PrintStream err = new PrintStream(baosErr, true);
    // Build the project in a different thread
    new Thread(() -> {
        buildMavenProject(source, out, err);
    }).start();
    // Use the PipeOutputStream to read the execution output and validate that the application was built.
    StringBuilder sb = new StringBuilder();
    BufferedReader bufferedReader;
    bufferedReader = new BufferedReader(new InputStreamReader(new PipedInputStream(baosOut)));
    String line;
    while (!(buildProcessReady || error != null)) {
        if ((line = bufferedReader.readLine()) != null) {
            sb.append(line).append("\n");
            if (line.contains("Building war:")) {
                buildProcessReady = true;
                out.close();
                err.close();
                baosOut.close();
                baosErr.close();
            }
        }
    }
    assertTrue(sb.toString().contains("Building war:"));
    assertTrue(buildProcessReady);
    assertTrue(error == null);
}
Also used : PrintStream(java.io.PrintStream) InputStreamReader(java.io.InputStreamReader) GitConfigImpl(org.guvnor.ala.source.git.config.impl.GitConfigImpl) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) Source(org.guvnor.ala.source.Source) GitConfigExecutor(org.guvnor.ala.source.git.executor.GitConfigExecutor) InMemorySourceRegistry(org.guvnor.ala.registry.inmemory.InMemorySourceRegistry) BufferedReader(java.io.BufferedReader) Test(org.junit.Test)

Example 3 with GitConfigExecutor

use of org.guvnor.ala.source.git.executor.GitConfigExecutor in project kie-wb-common by kiegroup.

the class MavenProjectConfigExecutorTest method testAPI.

@Test
public void testAPI() {
    final SourceRegistry sourceRegistry = new InMemorySourceRegistry();
    final BuildRegistry buildRegistry = new InMemoryBuildRegistry();
    final Pipeline pipe = PipelineFactory.newBuilder().addConfigStage("Git Source", new MyGitConfig()).addConfigStage("Maven Project", new MavenProjectConfigImpl()).addConfigStage("Maven Build Config", new MavenBuildConfigImpl()).addConfigStage("Maven Build", new MavenBuildExecConfigImpl()).buildAs("my pipe");
    final PipelineExecutor executor = new PipelineExecutor(asList(new GitConfigExecutor(sourceRegistry), new MavenProjectConfigExecutor(sourceRegistry), new MavenBuildConfigExecutor(), new MavenBuildExecConfigExecutor(buildRegistry)));
    executor.execute(new Input() {

        {
            put("repo-name", "drools-workshop-pipe");
            put("create-repo", "true");
            put("branch", "master");
            put("out-dir", tempPath.getAbsolutePath());
            put("origin", gitUrl);
        }
    }, pipe, System.out::println);
    List<Repository> allRepositories = sourceRegistry.getAllRepositories();
    assertEquals(1, allRepositories.size());
    Repository repo = allRepositories.get(0);
    List<Project> allProjects = sourceRegistry.getAllProjects(repo);
    assertEquals(1, allProjects.size());
    List<Binary> allBinaries = buildRegistry.getAllBinaries();
    assertEquals(1, allBinaries.size());
    assertMavenBinary(allBinaries.get(0), allProjects.get(0));
    final String tempDir = sourceRegistry.getAllProjects(repo).get(0).getTempDir();
    executor.execute(new Input() {

        {
            put("project-temp-dir", tempDir);
            put("repo-name", "drools-workshop-pipe");
            put("branch", "master");
        }
    }, pipe, System.out::println);
    allRepositories = sourceRegistry.getAllRepositories();
    assertEquals(1, allRepositories.size());
    repo = allRepositories.get(0);
    allProjects = sourceRegistry.getAllProjects(repo);
    assertEquals(2, allProjects.size());
    allBinaries = buildRegistry.getAllBinaries();
    assertEquals(1, allBinaries.size());
    assertMavenBinary(allBinaries.get(0), allProjects.get(1));
}
Also used : InMemoryBuildRegistry(org.guvnor.ala.registry.inmemory.InMemoryBuildRegistry) MavenProjectConfigImpl(org.guvnor.ala.build.maven.config.impl.MavenProjectConfigImpl) InMemorySourceRegistry(org.guvnor.ala.registry.inmemory.InMemorySourceRegistry) SourceRegistry(org.guvnor.ala.registry.SourceRegistry) PipelineExecutor(org.guvnor.ala.pipeline.execution.PipelineExecutor) Pipeline(org.guvnor.ala.pipeline.Pipeline) Project(org.guvnor.ala.build.Project) MavenProject(org.apache.maven.project.MavenProject) GitConfigExecutor(org.guvnor.ala.source.git.executor.GitConfigExecutor) Input(org.guvnor.ala.pipeline.Input) Repository(org.guvnor.ala.source.Repository) InMemorySourceRegistry(org.guvnor.ala.registry.inmemory.InMemorySourceRegistry) MavenBuildExecConfigImpl(org.guvnor.ala.build.maven.config.impl.MavenBuildExecConfigImpl) BuildRegistry(org.guvnor.ala.registry.BuildRegistry) InMemoryBuildRegistry(org.guvnor.ala.registry.inmemory.InMemoryBuildRegistry) MavenBuildConfigImpl(org.guvnor.ala.build.maven.config.impl.MavenBuildConfigImpl) Binary(org.guvnor.ala.build.Binary) MavenBinary(org.guvnor.ala.build.maven.model.MavenBinary) Test(org.junit.Test)

Example 4 with GitConfigExecutor

use of org.guvnor.ala.source.git.executor.GitConfigExecutor in project kie-wb-common by kiegroup.

the class CloneTestJUnitTest method hello.

@Test
public void hello() throws Exception {
    final String repoName = "drools-workshop-build";
    final Optional<Source> source = new GitConfigExecutor(new InMemorySourceRegistry()).apply(new GitConfigImpl(tempPath.getAbsolutePath(), "master", gitUrl, repoName, "true"));
    assertTrue(source.isPresent());
    final String targetRepoDir = tempPath.getAbsolutePath() + "/" + repoName + ".git";
    Git git = Git.open(new File(targetRepoDir));
    assertNotNull(git.getRepository().exactRef(Constants.HEAD));
}
Also used : GitConfigExecutor(org.guvnor.ala.source.git.executor.GitConfigExecutor) InMemorySourceRegistry(org.guvnor.ala.registry.inmemory.InMemorySourceRegistry) Git(org.eclipse.jgit.api.Git) GitConfigImpl(org.guvnor.ala.source.git.config.impl.GitConfigImpl) File(java.io.File) Source(org.guvnor.ala.source.Source) Test(org.junit.Test)

Example 5 with GitConfigExecutor

use of org.guvnor.ala.source.git.executor.GitConfigExecutor in project kie-wb-common by kiegroup.

the class MavenProjectConfigExecutorTest method testReuseTmpDirectoryAPI.

@Test
public void testReuseTmpDirectoryAPI() {
    final SourceRegistry sourceRegistry = new InMemorySourceRegistry();
    final BuildRegistry buildRegistry = new InMemoryBuildRegistry();
    final Pipeline pipe = PipelineFactory.newBuilder().addConfigStage("Git Source", new MyGitConfig()).addConfigStage("Maven Project", new MavenProjectConfigImpl()).addConfigStage("Maven Build Config", new MavenBuildConfigImpl()).addConfigStage("Maven Build", new MavenBuildExecConfigImpl()).buildAs("my pipe");
    final PipelineExecutor executor = new PipelineExecutor(asList(new GitConfigExecutor(sourceRegistry), new MavenProjectConfigExecutor(sourceRegistry), new MavenBuildConfigExecutor(), new MavenBuildExecConfigExecutor(buildRegistry)));
    executor.execute(new Input() {

        {
            put("repo-name", "drools-workshop-pipe2");
            put("create-repo", "true");
            put("branch", "master");
            put("out-dir", tempPath.getAbsolutePath());
            put("origin", gitUrl);
        }
    }, pipe, System.out::println);
    List<Repository> allRepositories = sourceRegistry.getAllRepositories();
    assertEquals(1, allRepositories.size());
    Repository repo = allRepositories.get(0);
    List<Project> allProjects = sourceRegistry.getAllProjects(repo);
    assertEquals(1, allProjects.size());
    List<Binary> allBinaries = buildRegistry.getAllBinaries();
    assertEquals(1, allBinaries.size());
    assertMavenBinary(allBinaries.get(0), allProjects.get(0));
    final String tempDir = sourceRegistry.getAllProjects(repo).get(0).getTempDir();
    executor.execute(new Input() {

        {
            put("project-temp-dir", tempDir);
            put("repo-name", "drools-workshop-pipe2");
            put("branch", "master");
        }
    }, pipe, System.out::println);
    allRepositories = sourceRegistry.getAllRepositories();
    assertEquals(1, allRepositories.size());
    repo = allRepositories.get(0);
    allProjects = sourceRegistry.getAllProjects(repo);
    assertEquals(2, allProjects.size());
    allBinaries = buildRegistry.getAllBinaries();
    assertEquals(1, allBinaries.size());
    assertMavenBinary(allBinaries.get(0), allProjects.get(1));
}
Also used : InMemoryBuildRegistry(org.guvnor.ala.registry.inmemory.InMemoryBuildRegistry) MavenProjectConfigImpl(org.guvnor.ala.build.maven.config.impl.MavenProjectConfigImpl) InMemorySourceRegistry(org.guvnor.ala.registry.inmemory.InMemorySourceRegistry) SourceRegistry(org.guvnor.ala.registry.SourceRegistry) PipelineExecutor(org.guvnor.ala.pipeline.execution.PipelineExecutor) Pipeline(org.guvnor.ala.pipeline.Pipeline) Project(org.guvnor.ala.build.Project) MavenProject(org.apache.maven.project.MavenProject) GitConfigExecutor(org.guvnor.ala.source.git.executor.GitConfigExecutor) Input(org.guvnor.ala.pipeline.Input) Repository(org.guvnor.ala.source.Repository) InMemorySourceRegistry(org.guvnor.ala.registry.inmemory.InMemorySourceRegistry) MavenBuildExecConfigImpl(org.guvnor.ala.build.maven.config.impl.MavenBuildExecConfigImpl) BuildRegistry(org.guvnor.ala.registry.BuildRegistry) InMemoryBuildRegistry(org.guvnor.ala.registry.inmemory.InMemoryBuildRegistry) MavenBuildConfigImpl(org.guvnor.ala.build.maven.config.impl.MavenBuildConfigImpl) Binary(org.guvnor.ala.build.Binary) MavenBinary(org.guvnor.ala.build.maven.model.MavenBinary) Test(org.junit.Test)

Aggregations

InMemorySourceRegistry (org.guvnor.ala.registry.inmemory.InMemorySourceRegistry)9 GitConfigExecutor (org.guvnor.ala.source.git.executor.GitConfigExecutor)9 Test (org.junit.Test)9 Input (org.guvnor.ala.pipeline.Input)5 Pipeline (org.guvnor.ala.pipeline.Pipeline)5 PipelineExecutor (org.guvnor.ala.pipeline.execution.PipelineExecutor)5 BuildRegistry (org.guvnor.ala.registry.BuildRegistry)5 SourceRegistry (org.guvnor.ala.registry.SourceRegistry)5 InMemoryBuildRegistry (org.guvnor.ala.registry.inmemory.InMemoryBuildRegistry)5 GitConfigImpl (org.guvnor.ala.source.git.config.impl.GitConfigImpl)5 MavenProject (org.apache.maven.project.MavenProject)4 MavenBuildConfigImpl (org.guvnor.ala.build.maven.config.impl.MavenBuildConfigImpl)3 MavenBuildExecConfigImpl (org.guvnor.ala.build.maven.config.impl.MavenBuildExecConfigImpl)3 MavenProjectConfigImpl (org.guvnor.ala.build.maven.config.impl.MavenProjectConfigImpl)3 MavenBuildConfigExecutor (org.guvnor.ala.build.maven.executor.MavenBuildConfigExecutor)3 MavenBuildExecConfigExecutor (org.guvnor.ala.build.maven.executor.MavenBuildExecConfigExecutor)3 MavenProjectConfigExecutor (org.guvnor.ala.build.maven.executor.MavenProjectConfigExecutor)3 InMemoryRuntimeRegistry (org.guvnor.ala.registry.inmemory.InMemoryRuntimeRegistry)3 Runtime (org.guvnor.ala.runtime.Runtime)3 Source (org.guvnor.ala.source.Source)3