Search in sources :

Example 1 with Source

use of org.guvnor.ala.source.Source 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 Source

use of org.guvnor.ala.source.Source 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 Source

use of org.guvnor.ala.source.Source 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 4 with Source

use of org.guvnor.ala.source.Source in project kie-wb-common by kiegroup.

the class InMemorySourceRegistry method getAllProjects.

@Override
public List<Project> getAllProjects(final Repository repository) {
    Path repoPath = pathByRepositoryId.get(repository.getId());
    List<Project> allProjects = new ArrayList<>();
    for (Source s : projectBySource.keySet()) {
        if (projectBySource.get(s).getRootPath().equals(repoPath)) {
            allProjects.add(projectBySource.get(s));
        }
    }
    return allProjects;
}
Also used : Path(org.uberfire.java.nio.file.Path) Project(org.guvnor.ala.build.Project) ArrayList(java.util.ArrayList) Source(org.guvnor.ala.source.Source)

Example 5 with Source

use of org.guvnor.ala.source.Source in project kie-wb-common by kiegroup.

the class RepositoryVisitorTest method repositoryVisitorDiffDeletedTest.

@Test
public void repositoryVisitorDiffDeletedTest() throws IOException {
    final IOServiceNio2WrapperImpl ioService = new IOServiceNio2WrapperImpl();
    final Optional<Source> sourceOptional = new GitConfigExecutor(new InMemorySourceRegistry()).apply(new GitConfigImpl(tempPath.getAbsolutePath(), "master", gitUrl, "users-new", "true"));
    assertTrue(sourceOptional.isPresent());
    final Source source = sourceOptional.get();
    final InputStream pomStream = org.uberfire.java.nio.file.Files.newInputStream(source.getPath().resolve("pom.xml"));
    final MavenProject project = MavenProjectLoader.parseMavenPom(pomStream);
    RepositoryVisitor repositoryVisitor = new RepositoryVisitor(source.getPath(), project.getName());
    System.out.println("Root: " + repositoryVisitor.getRoot().getAbsolutePath());
    Map<String, String> identityHash = repositoryVisitor.getIdentityHash();
    final URI originRepo = URI.create("git://users-new");
    final FileSystem fs = FileSystems.getFileSystem(originRepo);
    ioService.startBatch(fs);
    ioService.write(fs.getPath("/file.txt"), "temp");
    ioService.write(fs.getPath("/pom.xml"), "hi there" + UUID.randomUUID().toString());
    ioService.endBatch();
    ioService.delete(source.getPath().resolve("demo.iml"));
    RepositoryVisitor newRepositoryVisitor = new RepositoryVisitor(source.getPath(), repositoryVisitor.getRoot().getAbsolutePath().trim(), false);
    System.out.println("Root: " + newRepositoryVisitor.getRoot().getAbsolutePath());
    Map<String, String> newIdentityHash = newRepositoryVisitor.getIdentityHash();
    MapDifference<String, String> difference = Maps.difference(identityHash, newIdentityHash);
    Map<String, MapDifference.ValueDifference<String>> entriesDiffering = difference.entriesDiffering();
    System.out.println(" Size of Differences: " + entriesDiffering.size());
    for (String key : entriesDiffering.keySet()) {
        System.out.println("Different Value: " + key);
    }
    assertEquals(1, entriesDiffering.size());
    assertNotNull(entriesDiffering.get("/pom.xml"));
    Map<String, String> deletedFiles = difference.entriesOnlyOnLeft();
    System.out.println(" Size of Deleted Files: " + deletedFiles.size());
    for (String key : deletedFiles.keySet()) {
        System.out.println("Deleted File: " + key);
    }
    assertEquals(1, deletedFiles.size());
    assertNotNull(deletedFiles.get("/demo.iml"));
    Map<String, String> addedFiles = difference.entriesOnlyOnRight();
    System.out.println(" Size of added Files: " + addedFiles.size());
    for (String key : addedFiles.keySet()) {
        System.out.println("Added File: " + key);
    }
    assertEquals(1, addedFiles.size());
    assertNotNull(addedFiles.get("/file.txt"));
}
Also used : GitConfigImpl(org.guvnor.ala.source.git.config.impl.GitConfigImpl) InputStream(java.io.InputStream) RepositoryVisitor(org.guvnor.ala.build.maven.util.RepositoryVisitor) URI(java.net.URI) 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) IOServiceNio2WrapperImpl(org.uberfire.io.impl.IOServiceNio2WrapperImpl) FileSystem(org.uberfire.java.nio.file.FileSystem) Test(org.junit.Test)

Aggregations

Source (org.guvnor.ala.source.Source)7 Test (org.junit.Test)5 InMemorySourceRegistry (org.guvnor.ala.registry.inmemory.InMemorySourceRegistry)4 GitConfigImpl (org.guvnor.ala.source.git.config.impl.GitConfigImpl)4 GitConfigExecutor (org.guvnor.ala.source.git.executor.GitConfigExecutor)4 URI (java.net.URI)3 File (java.io.File)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 MavenProject (org.apache.maven.project.MavenProject)2 RepositoryVisitor (org.guvnor.ala.build.maven.util.RepositoryVisitor)2 GitRepository (org.guvnor.ala.source.git.GitRepository)2 UFLocal (org.guvnor.ala.source.git.UFLocal)2 FileSystem (org.uberfire.java.nio.file.FileSystem)2 Path (org.uberfire.java.nio.file.Path)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 PrintStream (java.io.PrintStream)1