List of usage examples for com.google.common.io Resources getResource
public static URL getResource(Class<?> contextClass, String resourceName)
From source file:org.sonar.server.platform.ws.MigrateDbAction.java
@Override public void define(WebService.NewController controller) { controller.createAction("migrate_db") .setDescription("Migrate the database to match the current version of SonarQube." + "<br/>" + "Sending a POST request to this URL starts the DB migration. " + "It is strongly advised to <strong>make a database backup</strong> before invoking this WS." + "<br/>" + statusDescription()) .setSince("5.2").setPost(true).setHandler(this) .setResponseExample(Resources.getResource(this.getClass(), "example-migrate_db.json")); }
From source file:uk.ac.susx.tag.method51.text.Tokeniser.java
public Tokeniser(Options options) { this.removeAts = options.removeAts.get(); this.removePunctuation = options.removePunctuation.get(); this.removeHashes = options.removeHashes.get(); this.preserveURLs = options.preserveURLs.get(); hashtagsOnly = options.hashtagsOnly.get(); if (options.filterStopwords.get()) { try {// w w w . ja v a 2 s .c o m File stopwordFile = options.stopwordFile.get(); String raw = Files .getText(new InputStreamReader( Resources.getResource(this.getClass(), stopwordFile.getPath()).openStream()), true) .toString(); if (lowercase) { raw = raw.toLowerCase(); } String[] words = raw.split("\n"); stopwords = new ObjectOpenHashSet<>(words); if (options.filterStopwordsIncKeywords.get()) { stopwords.addAll(options.keywords.get()); } } catch (IOException e) { LOG.error("could not open stop word list file!", e); throw new RuntimeException(e); } } else { stopwords = Collections.emptySet(); } }
From source file:org.apache.isis.core.runtime.services.userreg.EmailNotificationServiceDefault.java
protected String loadResource(final String resourceName) { final URL templateUrl = Resources.getResource(EmailNotificationServiceDefault.class, resourceName); try {/* w ww. j a v a2 s .c o m*/ return Resources.toString(templateUrl, Charsets.UTF_8); } catch (IOException e) { throw new IllegalStateException(String.format("Unable to read resource URL '%s'", templateUrl)); } }
From source file:com.nesscomputing.httpclient.testsupport.LocalHttpService.java
private static Connector getSSLClientCertHttpConnector(String truststore, String truststorePassword, String keystore, String keystorePassword, String keystoreType) { final URL keystoreUrl = Resources.getResource(LocalHttpService.class, keystore); final SslContextFactory contextFactory = new SslContextFactory(); contextFactory.setKeyStorePath(keystoreUrl.toString()); contextFactory.setKeyStorePassword(keystorePassword); contextFactory.setKeyManagerPassword(keystorePassword); contextFactory.setKeyStoreType(keystoreType); final URL truststoreUrl = Resources.getResource(LocalHttpService.class, truststore); contextFactory.setTrustStore(truststoreUrl.toString()); contextFactory.setTrustStorePassword(truststorePassword); contextFactory.setTrustStoreType("JKS"); contextFactory.setNeedClientAuth(true); final SslSelectChannelConnector scc = new SslSelectChannelConnector(contextFactory); scc.setPort(0);//w w w . ja v a 2 s. com scc.setHost("localhost"); return scc; }
From source file:org.apache.drill.exec.expr.fn.FunctionConverter.java
private CompilationUnit get(Class<?> c) throws IOException { String path = c.getName();// w w w. j a v a 2s. com path = path.replaceFirst("\\$.*", ""); path = path.replace(".", FileUtils.separator); path = "/" + path + ".java"; CompilationUnit cu = functionUnits.get(path); if (cu != null) { return cu; } URL u = Resources.getResource(c, path); InputSupplier<InputStream> supplier = Resources.newInputStreamSupplier(u); try (InputStream is = supplier.getInput()) { if (is == null) { throw new IOException(String.format( "Failure trying to located source code for Class %s, tried to read on classpath location %s", c.getName(), path)); } String body = IO.toString(is); //TODO: Hack to remove annotations so Janino doesn't choke. Need to reconsider this problem... body = body.replaceAll("@\\w+(?:\\([^\\\\]*?\\))?", ""); try { cu = new Parser(new Scanner(null, new StringReader(body))).parseCompilationUnit(); functionUnits.put(path, cu); return cu; } catch (CompileException e) { logger.warn("Failure while parsing function class:\n{}", body, e); return null; } } }
From source file:org.sonar.server.plugins.ws.AvailableAction.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/>" + "Plugin information is retrieved from Update Center. Date and time at which Update Center was last refreshed is provided in the response." + "<br/>" + "Update status values are: " + "<ul>" + "<li>COMPATIBLE: plugin is compatible with current SonarQube instance.</li>" + "<li>INCOMPATIBLE: plugin is not compatible with current SonarQube instance.</li>" + "<li>REQUIRES_SYSTEM_UPGRADE: plugin requires SonarQube to be upgraded before being installed.</li>" + "<li>DEPS_REQUIRE_SYSTEM_UPGRADE: at least one plugin on which the plugin is dependent requires SonarQube to be upgraded.</li>" + "</ul>" + "Require 'Administer System' permission.") .setSince("5.2").setHandler(this) .setResponseExample(Resources.getResource(this.getClass(), "example-available_plugins.json")); }
From source file:org.isisaddons.app.kitchensink.fixture.blobclob.BlobClobObjectsFixture.java
private Clob newClob(final String name, final String mimeType, final String resourceName) throws IOException { final String contents = Resources.toString(Resources.getResource(getClass(), resourceName), Charset.forName("Cp1252")); return new Clob(name + "-" + resourceName, mimeType, contents); }
From source file:org.sonar.server.component.ws.ProjectsWs.java
private void defineCreateAction(NewController controller) { WebService.NewAction action = controller.createAction("create") .setDescription("Provision a project. Requires Provision Projects permission").setSince("4.0") .setPost(true).setHandler(RailsHandler.INSTANCE) .setResponseExample(Resources.getResource(this.getClass(), "projects-example-create.json")); action.createParam("key").setDescription("Key of the project").setRequired(true) .setExampleValue("org.codehaus.sonar:sonar"); action.createParam("name").setDescription("Name of the project").setRequired(true) .setExampleValue("SonarQube"); RailsHandler.addFormatParam(action); }
From source file:org.sonar.server.issue.ws.ChangelogAction.java
@Override public void define(WebService.NewController context) { WebService.NewAction action = context.createAction(ACTION_CHANGELOG) .setDescription("Display changelog of an issue.<br/>" + "Require the 'Browse' permission on the project of the specified issue.<br/>" + "Since 6.3, changes on effort are returning raw value in minutes, it doesn't return anymore the duration.") .setSince("4.1").setHandler(this) .setResponseExample(Resources.getResource(IssuesWs.class, "changelog-example.json")); action.createParam(PARAM_ISSUE).setDescription("Issue key").setRequired(true) .setExampleValue(UUID_EXAMPLE_01); }
From source file:org.sonar.server.issue.ws.EditCommentAction.java
@Override public void define(WebService.NewController context) { WebService.NewAction action = context.createAction(ACTION_EDIT_COMMENT) .setDescription("Edit a comment.<br/>" + "Requires authentication and the following permission: 'Browse' on the project of the specified issue.<br/>" + "Since 6.3, the response contains the issue with all details, not only the edited comment.<br/>" + "Since 6.3, 'key' parameter has been renamed %s", PARAM_COMMENT) .setSince("3.6").setHandler(this) .setResponseExample(Resources.getResource(this.getClass(), "edit_comment-example.json")) .setPost(true);/* w w w . ja v a 2 s.c o m*/ action.createParam(PARAM_COMMENT).setDescription("Comment key").setDeprecatedKey("key", "6.3") .setSince("6.3").setRequired(true).setExampleValue(UUID_EXAMPLE_01); action.createParam(PARAM_TEXT).setDescription("Comment text").setRequired(true) .setExampleValue("Won't fix because it doesn't apply to the context"); }