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:org.sonar.server.plugins.ws.InstalledAction.java

@Override
public void define(WebService.NewController controller) {
    WebService.NewAction action = controller.createAction("installed").setDescription(
            "Get the list of all the plugins installed on the SonarQube instance, sorted by plugin name.<br/>"
                    + "Require 'Administer System' permission.")
            .setSince("5.2").setHandler(this)
            .setResponseExample(Resources.getResource(this.getClass(), "example-installed_plugins.json"));

    action.createFieldsParam(singleton("category")).setDescription(format(
            "Comma-separated list of the additional fields to be returned in response. No additional field is returned by default. Possible values are:"
                    + "<ul>"
                    + "<li>%s - category as defined in the Update Center. A connection to the Update Center is needed</li>"
                    + "</lu>",
            FIELD_CATEGORY)).setSince("5.6");
}

From source file:org.sonar.server.project.ws.GhostsAction.java

@Override
public void define(WebService.NewController context) {
    WebService.NewAction action = context.createAction(ACTION);

    action.setChangelog(new Change("6.4", "The 'uuid' field is deprecated in the response"));

    action.setDescription("List ghost projects.<br /> " + "Requires 'Administer System' permission.")
            .setResponseExample(Resources.getResource(getClass(), "projects-example-ghosts.json"))
            .setSince("5.2").addPagingParams(100, MAX_LIMIT).addFieldsParam(POSSIBLE_FIELDS)
            .addSearchQuery("sonar", "names", "keys").setHandler(this);

    action.createParam(PARAM_ORGANIZATION).setDescription("Organization key").setRequired(false)
            .setInternal(true).setSince("6.3");
}

From source file:com.opentable.requestid.LocalHttpService.java

private static Connector getSSLHttpConnector(Server server) {
    final URL keystoreUrl = Resources.getResource(LocalHttpService.class, "/ssl-server-keystore.jks");

    final SslContextFactory contextFactory = new SslContextFactory();

    contextFactory.setKeyStorePath(keystoreUrl.toString());
    contextFactory.setKeyStorePassword("changeit");

    final HttpConfiguration config = new HttpConfiguration();
    config.addCustomizer(new SecureRequestCustomizer());

    final ServerConnector scc = new ServerConnector(server,
            new SslConnectionFactory(contextFactory, "http/1.1"), new HttpConnectionFactory(config));
    scc.setPort(0);/*from  w  ww .j a  v a  2s . c o  m*/
    scc.setHost("localhost");

    return scc;
}

From source file:com.google.cloud.spanner.ReadFormatTestRunner.java

@Override
protected List<JSONObject> getChildren() {
    try {/*ww w .  j  a  v  a2s .co m*/
        List<JSONObject> children = new ArrayList<>();
        String jsonStr = Resources.toString(Resources.getResource(this.getClass(), "read_tests.json"),
                StandardCharsets.UTF_8);
        JSONObject json = new JSONObject(jsonStr);
        JSONArray testCases = json.getJSONArray("tests");
        for (int i = 0; i < testCases.length(); i++) {
            JSONObject testCase = testCases.getJSONObject(i);
            children.add(testCase);
        }
        return children;
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}

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

@Override
public void define(WebService.NewController controller) {
    WebService.NewAction action = controller.createAction(ACTION_DO_TRANSITION).setDescription(
            "Do workflow transition on an issue. Requires authentication and Browse permission on project.<br/>"
                    + "The transitions '" + DefaultTransitions.WONT_FIX + "' and '"
                    + DefaultTransitions.FALSE_POSITIVE + "' require the permission 'Administer Issues'.")
            .setSince("3.6").setHandler(this)
            .setResponseExample(Resources.getResource(this.getClass(), "do_transition-example.json"))
            .setPost(true);/*from w  w w . ja va 2s  .  c om*/

    action.createParam(PARAM_ISSUE).setDescription("Issue key").setRequired(true)
            .setExampleValue(Uuids.UUID_EXAMPLE_01);
    action.createParam(PARAM_TRANSITION).setDescription("Transition").setRequired(true)
            .setPossibleValues(DefaultTransitions.ALL);
}

From source file:io.soliton.protobuf.plugin.ProtoServiceHandler.java

public void handle(ServiceDescriptorProto service) throws IOException {
    ImmutableList.Builder<ServiceHandlerData.Method> methods = ImmutableList.builder();
    for (MethodDescriptorProto method : service.getMethodList()) {
        ServiceHandlerData.Method methodData = new ServiceHandlerData.Method(method.getName(),
                CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, method.getName()),
                types.lookup(method.getInputType()).toString(),
                types.lookup(method.getOutputType()).toString());
        methods.add(methodData);// ww  w  . j av a2  s  .  c  o m
    }

    String fullName = Joiner.on('.').skipNulls().join(protoPackage, service.getName());

    ServiceHandlerData.Service serviceData = new ServiceHandlerData.Service(service.getName(), fullName,
            methods.build());
    ServiceHandlerData data = new ServiceHandlerData(javaPackage, multipleFiles, serviceData);

    String template = Resources.toString(Resources.getResource(this.getClass(), "service_class.mvel"),
            Charsets.UTF_8);
    String serviceFile = (String) TemplateRuntime.eval(template,
            ImmutableMap.<String, Object>of("handler", data));

    CodeGeneratorResponse.Builder response = CodeGeneratorResponse.newBuilder();
    CodeGeneratorResponse.File.Builder file = CodeGeneratorResponse.File.newBuilder();
    file.setContent(serviceFile);
    file.setName(javaPackage.replace('.', '/') + '/' + service.getName() + ".java");
    if (!multipleFiles) {
        file.setName(javaPackage.replace('.', '/') + '/' + outerClassName + ".java");
        file.setInsertionPoint("outer_class_scope");
    }
    response.addFile(file);
    response.build().writeTo(output);
}

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

@Override
public void define(WebService.NewController controller) {
    NewAction action = controller.createAction(ACTION_SET_TAGS).setPost(true).setSince("5.1")
            .setDescription(//  www.  j a  va2s.c o m
                    "Set tags on an issue. <br/>" + "Requires authentication and Browse permission on project")
            .setChangelog(new Change("6.4", "response contains issue information instead of list of tags"))
            .setResponseExample(Resources.getResource(this.getClass(), "set_tags-example.json"))
            .setHandler(this);
    action.createParam(PARAM_ISSUE).setDescription("Issue key").setSince("6.3").setDeprecatedKey("key", "6.3")
            .setExampleValue(Uuids.UUID_EXAMPLE_01).setRequired(true);
    action.createParam(PARAM_TAGS)
            .setDescription(
                    "Comma-separated list of tags. All tags are removed if parameter is empty or not set.")
            .setExampleValue("security,cwe,misra-c");
}

From source file:uk.ac.susx.tag.method51.twitter.geocoding.geonames.GeonamesSPARQLLocationDatabase.java

public GeonamesSPARQLLocationDatabase(String host, int port) throws IOException {

    this.host = host;
    this.port = port;

    try (BufferedReader reader = new BufferedReader(new InputStreamReader(
            Resources.getResource(this.getClass(), "location_lookup.rq").openStream()));) {
        sparqlQuery = Files.getText(reader).toString();
    }/*  w  w  w. ja  v a  2  s .c  o  m*/

    featureCodeScores = new HashMap<>();

    featureCodeScores.put(CODE_PREFIX + "P.PPLL", 3);
    featureCodeScores.put(CODE_PREFIX + "P.PPL", 4);
    featureCodeScores.put(CODE_PREFIX + "P.PPLX", 5);
    featureCodeScores.put(CODE_PREFIX + "P.PPLA4", 6);
    featureCodeScores.put(CODE_PREFIX + "P.PPLA3", 7);
    featureCodeScores.put(CODE_PREFIX + "P.PPLA2", 8);
    featureCodeScores.put(CODE_PREFIX + "P.PPLA", 9);
    featureCodeScores.put(CODE_PREFIX + "P.PPLC", 10);

    featureCodeScores.put(CODE_PREFIX + "A.ADM1", 10);
    featureCodeScores.put(CODE_PREFIX + "A.ADM2", 10);
    featureCodeScores.put(CODE_PREFIX + "A.ADM3", 10);
    featureCodeScores.put(CODE_PREFIX + "A.ADM4", 10);
    featureCodeScores.put(CODE_PREFIX + "A.ADM5", 10);

    populationScore = 25;

    double gbScore = 0;

    defaultScore = 3;

    populationThreshold = 2000000;

    distanceTolerance = 20;
}

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

@Override
public void define(WebService.NewController controller) {
    WebService.NewAction action = controller.createAction(ACTION_SET_SEVERITY)
            .setDescription("Change severity.<br/>" + "Requires the following permissions:" + "<ul>"
                    + "  <li>'Authentication'</li>"
                    + "  <li>'Browse' rights on project of the specified issue</li>"
                    + "  <li>'Administer Issues' rights on project of the specified issue</li>" + "</ul>")
            .setSince("3.6").setHandler(this)
            .setResponseExample(Resources.getResource(this.getClass(), "set_severity-example.json"))
            .setPost(true);//w  w w .j ava  2 s  .c  om

    action.createParam(PARAM_ISSUE).setDescription("Issue key").setRequired(true)
            .setExampleValue(Uuids.UUID_EXAMPLE_01);
    action.createParam(PARAM_SEVERITY).setDescription("New severity").setRequired(true)
            .setPossibleValues(Severity.ALL);
}

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

@Override
public void define(WebService.NewController controller) {
    WebService.NewAction action = controller.createAction(ACTION_SET_TYPE)
            .setDescription("Change type of issue, for instance from 'code smell' to 'bug'.<br/>"
                    + "Requires the following permissions:" + "<ul>" + "  <li>'Authentication'</li>"
                    + "  <li>'Browse' rights on project of the specified issue</li>"
                    + "  <li>'Administer Issues' rights on project of the specified issue</li>" + "</ul>")
            .setSince("5.5").setHandler(this)
            .setResponseExample(Resources.getResource(this.getClass(), "set_type-example.json")).setPost(true);

    action.createParam(PARAM_ISSUE).setDescription("Issue key").setRequired(true)
            .setExampleValue(Uuids.UUID_EXAMPLE_01);
    action.createParam(PARAM_TYPE).setDescription("New type").setRequired(true)
            .setPossibleValues(RuleType.names());
}