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:no.ssb.vtl.test.junit.GrammarRule.java

private void before() {
    try {//  w ww. ja v  a2  s  .c  o  m
        if (grammarURL == null) {
            try {
                Class<?> vtlParserClass = ClassLoader.getSystemClassLoader()
                        .loadClass("no.ssb.vtl.parser.VTLParser");
                grammarURL = Resources.getResource(vtlParserClass, "VTL.g4");
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(
                        "could not find no.ssb.vtl.parser.VTLParser.class, did you compile antlr project?");
            }
        }
        String grammarString = Resources.toString(grammarURL, Charset.defaultCharset());
        grammar = new Grammar(grammarString);
    } catch (IOException | RecognitionException e) {
        throw new IllegalArgumentException("could not create grammar", e);
    }
}

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

@Override
public void define(WebService.NewController controller) {
    controller.createAction("updates").setDescription(
            "Lists plugins installed on the SonarQube instance for which at least one newer version is available, sorted by plugin name."
                    + "br/>"
                    + "Each newer version is a separate entry in the returned list, with its update/compatibility status."
                    + "<br/>"
                    + "Update status values are: [COMPATIBLE, INCOMPATIBLE, REQUIRES_UPGRADE, DEPS_REQUIRE_UPGRADE]")
            .setSince("5.2").setHandler(this)
            .setResponseExample(Resources.getResource(this.getClass(), "example-updates_plugins.json"));
}

From source file:app.QuickStartApplication.java

private static String readLines(final String resourceName) {
    try {//from   www  .j  a v  a2 s  . c  o  m
        List<String> readLines = Resources.readLines(Resources.getResource(QuickStartApplication.class, resourceName), Charset.defaultCharset());
        final String aboutText = Joiner.on("${symbol_escape}n").join(readLines);
        return aboutText;
    } catch (IOException e) {
        return "This is Quick Start";
    }
}

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

@Override
public void define(WebService.NewController controller) {
    NewAction action = controller.createAction("tags").setHandler(this).setSince("5.1")
            .setDescription("List tags matching a given query")
            .setResponseExample(Resources.getResource(getClass(), "tags-example.json"));
    action.createParam(Param.TEXT_QUERY).setDescription("A pattern to match tags against")
            .setExampleValue("misra");
    action.createParam(PAGE_SIZE).setDescription("The size of the list to return").setExampleValue("25")
            .setDefaultValue("10");
    action.createParam(PARAM_ORGANIZATION).setDescription("Organization key").setRequired(false)
            .setInternal(true).setExampleValue("my-org").setSince("6.4");
}

From source file:domainapp.webapp.DomainApplication.java

private static String readLines(final Class<?> contextClass, final String resourceName) {
    try {//from   w w  w .j  a  va2 s  .c  o  m
        List<String> readLines = Resources.readLines(Resources.getResource(contextClass, resourceName),
                Charset.defaultCharset());
        final String aboutText = Joiner.on("\n").join(readLines);
        return aboutText;
    } catch (IOException e) {
        return "This is a simple app";
    }
}

From source file:org.sonar.server.authentication.ws.ValidateAction.java

@Override
public void define(WebService.NewController controller) {
    controller.createAction("validate").setDescription("Check credentials.").setSince("3.3")
            .setHandler(ServletFilterHandler.INSTANCE)
            .setResponseExample(Resources.getResource(this.getClass(), "example-validate.json"));
}

From source file:org.eclipse.che.util.GwtXmlGenerator.java

/**
 * Get the template for typescript//from ww  w.j  a  v a  2  s.  co m
 *
 * @return the String Template
 */
protected ST getTemplate() {
    URL url = Resources.getResource(GwtXmlGenerator.class, TEMPLATE_NAME);
    try {
        return new ST(Resources.toString(url, UTF_8), '$', '$');
    } catch (IOException e) {
        throw new IllegalArgumentException("Unable to read template", e);
    }

}

From source file:org.sonar.server.branch.ws.DeleteAction.java

@Override
public void define(NewController context) {
    WebService.NewAction action = context.createAction(ACTION_DELETE).setSince("6.6")
            .setDescription("Delete a non-main branch of a project.<br/>"
                    + "Requires 'Administer' rights on the specified project.")
            .setResponseExample(Resources.getResource(getClass(), "list-example.json")).setPost(true)
            .setHandler(this);

    addProjectParam(action);//from  w  w w . ja  v  a2s.c  o  m
    addBranchParam(action);
}

From source file:org.sonar.server.webhook.ws.WebhookDeliveriesAction.java

@Override
public void define(WebService.NewController controller) {
    WebService.NewAction action = controller.createAction("deliveries").setSince("6.2")
            .setDescription("Get the recent deliveries for a specified project or Compute Engine task.<br/>"
                    + "Require 'Administer' permission on the related project.<br/>"
                    + "Note that additional information are returned by api/webhooks/delivery.")
            .setResponseExample(Resources.getResource(this.getClass(), "example-deliveries.json"))
            .setHandler(this);

    action.createParam(COMPONENT_PARAM).setDescription("Key of the project").setExampleValue("my-project");

    action.createParam(TASK_PARAM).setDescription("Id of the Compute Engine task")
            .setExampleValue(Uuids.UUID_EXAMPLE_01);
}

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

@Override
public void define(WebService.NewController controller) {
    controller.createAction("db_migration_status")
            .setDescription(//from w ww  . j a  v  a2 s. co  m
                    "Display the database migration status of SonarQube." + "<br/>" + statusDescription())
            .setSince("5.2").setHandler(this)
            .setResponseExample(Resources.getResource(this.getClass(), "example-migrate_db.json"));
}