Example usage for com.google.common.io Resources getResource

List of usage examples for com.google.common.io Resources getResource

Introduction

In this page you can find the example usage for com.google.common.io Resources getResource.

Prototype

public static URL getResource(Class<?> contextClass, String resourceName) 

Source Link

Document

Given a resourceName that is relative to contextClass , returns a URL pointing to the named resource.

Usage

From source file:com.netflix.simianarmy.chaos.ScriptChaosType.java

/**
 * Runs the script./*from   ww w  .ja  v a  2s.com*/
 */
@Override
public void apply(ChaosInstance instance) {
    LOGGER.info("Running script for {} on instance {}", getKey(), instance.getInstanceId());

    SshClient ssh = instance.connectSsh();

    String filename = getKey().toLowerCase() + ".sh";
    URL url = Resources.getResource(ScriptChaosType.class, "/scripts/" + filename);
    String script;
    try {
        script = Resources.toString(url, Charsets.UTF_8);
    } catch (IOException e) {
        throw new IllegalStateException("Error reading script resource", e);
    }

    ssh.put("/tmp/" + filename, script);
    ExecResponse response = ssh.exec("/bin/bash /tmp/" + filename);
    if (response.getExitStatus() != 0) {
        LOGGER.warn("Got non-zero output from running script: {}", response);
    }
    ssh.disconnect();
}

From source file:org.sonar.server.plugins.ws.AvailablePluginsWsAction.java

@Override
public void define(WebService.NewController controller) {
    controller.createAction("available").setDescription(
            "Get the list of all the plugins available for installation on the SonarQube instance, sorted by plugin name."
                    + "<br/>"
                    + "Update status values are: [COMPATIBLE, INCOMPATIBLE, REQUIRES_UPGRADE, DEPS_REQUIRE_UPGRADE]")
            .setSince("5.2").setHandler(this)
            .setResponseExample(Resources.getResource(this.getClass(), "example-available_plugins.json"));
}

From source file:org.sonar.server.platform.ws.HealthActionSupport.java

void define(WebService.NewController controller, SystemWsAction handler) {
    controller.createAction("health").setDescription("Provide health status of SonarQube."
            + "<p>Require 'Administer System' permission or authentication with passcode</p>" + "<p> " + " <ul>"
            + " <li>GREEN: SonarQube is fully operational</li>"
            + " <li>YELLOW: SonarQube is usable, but it needs attention in order to be fully operational</li>"
            + " <li>RED: SonarQube is not operational</li>" + " </ul>" + "</p>").setSince("6.6")
            .setResponseExample(Resources.getResource(this.getClass(), "example-health.json"))
            .setHandler(handler);//from w w w  . j  a v  a  2s  . c o  m
}

From source file:net.minecraftforge.gradle.patcher.TaskGenSubprojects.java

public TaskGenSubprojects() throws IOException {
    super();//  w  w  w. j  a v  a  2 s .  c  o  m
    resource = Resources.toString(Resources.getResource(TaskGenSubprojects.class, "globalGradle"),
            Constants.CHARSET);
}

From source file:io.soliton.time.TimeClient.java

private static SSLContext getSslContext() throws Exception {
    // startcom.crt contains the root and intermediate certificates
    URL certificates = Resources.getResource(TimeClient.class, "startcom.crt");
    InputStream certificatesStream = Resources.newInputStreamSupplier(certificates).getInput();

    KeyStore keyStore = KeyStore.getInstance("JKS");
    keyStore.load(null, null);/*  ww  w .j  a va  2s.co  m*/
    CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
    int i = 0;
    for (Certificate cert : certificateFactory.generateCertificates(certificatesStream)) {
        keyStore.setCertificateEntry(String.valueOf(i), cert);
        i++;
    }
    TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("PKIX");
    trustManagerFactory.init(keyStore);
    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
    return sslContext;
}

From source file:org.sonar.server.measure.custom.ws.MetricsAction.java

@Override
public void define(WebService.NewController context) {
    WebService.NewAction action = context.createAction(ACTION).setSince("5.2").setInternal(true)
            .setHandler(this).setResponseExample(Resources.getResource(getClass(), "example-metrics.json"))
            .setDescription(//from  w  ww.j a va2s.co m
                    "List all custom metrics for which no custom measure already exists on a given project.<br /> "
                            + "The project id or project key must be provided.<br />"
                            + "Requires 'Administer System' permission or 'Administer' permission on the project.");

    action.createParam(PARAM_PROJECT_ID).setDescription("Project id")
            .setExampleValue("ce4c03d6-430f-40a9-b777-ad877c00aa4d");

    action.createParam(PARAM_PROJECT_KEY).setDescription("Project key")
            .setExampleValue(KEY_PROJECT_EXAMPLE_001);
}

From source file:org.apache.mahout.cf.taste.example.grouplens.GroupLensDataModel.java

public static File readResourceToTempFile(String resourceName) throws IOException {
    InputSupplier<? extends InputStream> inSupplier;
    try {/*from  w  w  w  . j  a v  a2  s  .  c om*/
        URL resourceURL = Resources.getResource(GroupLensRecommender.class, resourceName);
        inSupplier = Resources.newInputStreamSupplier(resourceURL);
    } catch (IllegalArgumentException iae) {
        File resourceFile = new File("src/main/java" + resourceName);
        inSupplier = Files.newInputStreamSupplier(resourceFile);
    }
    File tempFile = File.createTempFile("taste", null);
    tempFile.deleteOnExit();
    Files.copy(inSupplier, tempFile);
    return tempFile;
}

From source file:org.sonar.server.issue.ws.ComponentTagsAction.java

@Override
public void define(WebService.NewController controller) {
    NewAction action = controller.createAction(ACTION_COMPONENT_TAGS).setHandler(this).setSince("5.1")
            .setInternal(true)/*  www .j ava2 s .  c om*/
            .setDescription(
                    "List tags for the issues under a given component (including issues on the descendants of the component)")
            .setResponseExample(Resources.getResource(getClass(), "component-tags-example.json"));
    action.createParam(PARAM_COMPONENT_UUID).setDescription("A component UUID").setRequired(true)
            .setExampleValue("7d8749e8-3070-4903-9188-bdd82933bb92");
    action.createParam(PARAM_CREATED_AFTER).setDescription(
            "To retrieve tags on issues created after the given date (inclusive). Format: date or datetime ISO formats")
            .setExampleValue("2013-05-01 (or 2013-05-01T13:00:00+0100)");
    action.createParam(PAGE_SIZE).setDescription("The maximum size of the list to return").setExampleValue("25")
            .setDefaultValue("10");
}

From source file:org.apache.mahout.cf.taste.similarity.precompute.example.GroupLensDataModel.java

public static File readResourceToTempFile(String resourceName) throws IOException {
    InputSupplier<? extends InputStream> inSupplier;
    try {/*from w w w  .  j a  v a 2 s.co m*/
        URL resourceURL = Resources.getResource(GroupLensDataModel.class, resourceName);
        inSupplier = Resources.newInputStreamSupplier(resourceURL);
    } catch (IllegalArgumentException iae) {
        File resourceFile = new File("src/main/java" + resourceName);
        inSupplier = Files.newInputStreamSupplier(resourceFile);
    }
    File tempFile = File.createTempFile("taste", null);
    tempFile.deleteOnExit();
    Files.copy(inSupplier, tempFile);
    return tempFile;
}

From source file:org.sonar.server.source.ws.ShowAction.java

@Override
public void define(WebService.NewController controller) {
    WebService.NewAction action = controller.createAction("show")
            .setDescription("Get source code. Require See Source Code permission on file's project<br/>"
                    + "Each element of the result array is composed of:" + "<ol>" + "<li>Line number</li>"
                    + "<li>Content of the line</li>" + "</ol>")
            .setSince("4.4").setResponseExample(Resources.getResource(getClass(), "example-show.json"))
            .setHandler(this);

    action.createParam("key").setRequired(true).setDescription("File key")
            .setExampleValue("my_project:/src/foo/Bar.php");

    action.createParam("from").setDescription("First line to return. Starts at 1").setExampleValue("10")
            .setDefaultValue("1");

    action.createParam("to").setDescription("Last line to return (inclusive)").setExampleValue("20");
}