Java Code Examples for io.fabric8.utils.IOHelpers#readFully()

The following examples show how to use io.fabric8.utils.IOHelpers#readFully() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArchetypeTest.java    From ipaas-quickstarts with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if we can find a system test Java file which uses the nice <code>isPodReadyForPeriod()</code>
 * assertions
 */
protected boolean hasGoodSystemTest(File file) {
    if (file.isFile()) {
        String name = file.getName();
        if (name.endsWith("KT.java")) {
            try {
                String text = IOHelpers.readFully(file);
                if (text.contains("isPodReadyForPeriod(")) {
                    LOG.info("Found good system test at " + file.getAbsolutePath() + " so not generating a new one for this archetype");
                    return true;
                }
            } catch (IOException e) {
                LOG.warn("Failed to load file " + file + ". " + e, e);
            }
        }
    }
    File[] files = file.listFiles();
    if (files != null) {
        for (File child : files) {
            if (hasGoodSystemTest(child)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 2
Source File: ProcessHelper.java    From updatebot with Apache License 2.0 5 votes vote down vote up
protected static String loadFile(File file) {
    String output = null;
    if (Files.isFile(file)) {
        try {
            output = IOHelpers.readFully(file);
        } catch (IOException e) {
            LOG.error("Failed to load " + file + ". " + e, e);
        }
    }
    return output;
}
 
Example 3
Source File: RootResource.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@GET
@Produces(MediaType.TEXT_HTML)
public String index() throws IOException {
    URL resource = getClass().getResource("index.html");
    if (resource != null) {
        InputStream in = resource.openStream();
        if (in != null) {
            return IOHelpers.readFully(in);
        }
    }
    return null;
}
 
Example 4
Source File: DevOpsSave.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
private static String getFlowContent(String flow, UIContext context) {
    File dir = getJenkinsWorkflowFolder(context);
    if (dir != null) {
        File file = new File(dir, flow);
        if (file.isFile() && file.exists()) {
            try {
                return IOHelpers.readFully(file);
            } catch (IOException e) {
                LOG.warn("Failed to load local pipeline " + file + ". " + e, e);
            }
        }
    }
    return null;
}
 
Example 5
Source File: ApplyStepExecution.java    From kubernetes-pipeline-plugin with Apache License 2.0 5 votes vote down vote up
private void runProcess(String commands, boolean verbose) throws IOException {
    ProcessBuilder builder = new ProcessBuilder("bash", "-c", commands);
    Process process = builder.start();

    String out = IOHelpers.readFully(process.getInputStream());
    String err = IOHelpers.readFully(process.getErrorStream());
    if (verbose) {
        listener.getLogger().println("command: " + commands + " out: " + out);
        listener.getLogger().println("command: " + commands + " err: " + err);
    }
}
 
Example 6
Source File: CatalogBuilder.java    From ipaas-quickstarts with Apache License 2.0 5 votes vote down vote up
/**
 * Starts generation of Archetype Catalog (see: http://maven.apache.org/xsd/archetype-catalog-1.0.0.xsd)
 *
 * @throws IOException
 */
public void configure() throws IOException {
    if (archetypesPomFile != null) {
        archetypesPomArtifactIds = loadArchetypesPomArtifactIds(archetypesPomFile);
    }
    catalogXmlFile.getParentFile().mkdirs();
    LOG.info("Writing catalog: " + catalogXmlFile);
    printWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(catalogXmlFile), "UTF-8"));

    printWriter.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
        "<archetype-catalog xmlns=\"http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0\"\n" +
        indent + indent + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
        indent + indent + "xsi:schemaLocation=\"http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0 http://maven.apache.org/xsd/archetype-catalog-1.0.0.xsd\">\n" +
        indent + "<archetypes>");

    if (bomFile != null && bomFile.exists()) {
        // read all properties of the bom, so we have default values for ${ } placeholders
        String text = IOHelpers.readFully(bomFile);
        Document doc = archetypeUtils.parseXml(new InputSource(new StringReader(text)));
        Element root = doc.getDocumentElement();

        // lets load all the properties defined in the <properties> element in the bom pom.
        NodeList propertyElements = root.getElementsByTagName("properties");
        if (propertyElements.getLength() > 0)  {
            Element propertyElement = (Element) propertyElements.item(0);
            NodeList children = propertyElement.getChildNodes();
            for (int cn = 0; cn < children.getLength(); cn++) {
                Node e = children.item(cn);
                if (e instanceof Element) {
                    versionProperties.put(e.getNodeName(), e.getTextContent());
                }
            }
        }
        if (LOG.isDebugEnabled()) {
            for (Map.Entry<String, String> entry : versionProperties.entrySet()) {
                LOG.debug("bom property: {}={}", entry.getKey(), entry.getValue());
            }
        }
    }
}
 
Example 7
Source File: ForgeTestSupport.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
protected Build assertCodeChangeTriggersWorkingBuild(final String projectName, Build firstBuild) throws Exception {
    File cloneDir = new File(getBasedir(), "target/projects/" + projectName);

    String gitUrl = asserGetAppGitCloneURL(forgeClient, projectName);
    Git git = ForgeClientAsserts.assertGitCloneRepo(gitUrl, cloneDir);

    // lets make a dummy commit...
    File readme = new File(cloneDir, "ReadMe.md");
    boolean mustAdd = false;
    String text = "";
    if (readme.exists()) {
        text = IOHelpers.readFully(readme);
    } else {
        mustAdd = true;
    }
    text += "\nupdated at: " + new Date();
    Files.writeToFile(readme, text, Charset.defaultCharset());

    if (mustAdd) {
        AddCommand add = git.add().addFilepattern("*").addFilepattern(".");
        add.call();
    }


    LOG.info("Committing change to " + readme);

    CommitCommand commit = git.commit().setAll(true).setAuthor(forgeClient.getPersonIdent()).setMessage("dummy commit to trigger a rebuild");
    commit.call();
    PushCommand command = git.push();
    command.setCredentialsProvider(forgeClient.createCredentialsProvider());
    command.setRemote("origin").call();

    LOG.info("Git pushed change to " + readme);

    // now lets wait for the next build to start
    int nextBuildNumber = firstBuild.getNumber() + 1;


    Asserts.assertWaitFor(10 * 60 * 1000, new Block() {
        @Override
        public void invoke() throws Exception {
            JobWithDetails job = assertJob(projectName);
            Build lastBuild = job.getLastBuild();
            assertThat(lastBuild.getNumber()).describedAs("Waiting for latest build for job " + projectName + " to start").isGreaterThanOrEqualTo(nextBuildNumber);
        }
    });

    return ForgeClientAsserts.assertBuildCompletes(forgeClient, projectName);
}