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.component.ws.ResourcesWs.java
private void defineIndexAction(NewController controller) { NewAction action = controller.createAction("index") .setDescription("Gets a list of components. Requires Browse permission on resource.<br>" + "The web service is deprecated and you're invited to use the alternatives: " + "<ul>" + "<li>if you need one component without measures: api/components/show</li>" + "<li>if you need one component with measures: api/measures/component</li>" + "<li>if you need several components without measures: api/components/tree</li>" + "<li>if you need several components with measures: api/measures/component_tree</li>" + "</ul>" + "When you provide one metric, the number of results is limited to 500. When several metrics are provided, the number of measures is limited to 10000. " + "The number of components is limited to 500." + "This is a known limitation and it won't be fixed. You're invited to use the alternatives suggested above.") .setSince("2.10").setDeprecatedSince("5.4").setHandler(RailsHandler.INSTANCE) .setResponseExample(Resources.getResource(this.getClass(), "resources-example-index.json")); action.createParam("resource").setDescription("id or key of the resource") .setExampleValue(KEY_PROJECT_EXAMPLE_001); action.createParam("metrics").setDescription( "Comma-separated list of <a href=\"http://redirect.sonarsource.com/doc/metric-definitions.html\">metric keys/ids</a>. " + "Load measures on selected metrics. If only one metric is set, then measures are ordered by value") .setExampleValue("lines,blocker_violations"); action.createParam("depth").setDescription("Used only when resource is set:<br/>" + "<ul>" + "<li>0: only selected resource</li>" + "<li>-1: all children, including selected resource</li>" + "<li>>0: depth toward the selected resource</li>" + "</ul>").setDefaultValue("0") .setExampleValue("-1"); action.createParam("scopes") .setDescription("Comma-separated list of scopes:<br/>" + "<ul>" + "<li>PRJ: project/module</li>" + "<li>DIR: directory (like Java package)</li>" + "<li>FIL: file</li>" + "</ul>") .setExampleValue("PRJ,DIR"); action.createParam("qualifiers") .setDescription("Comma-separated list of qualifiers:<br/>" + "<ul>" + "<li>VW: view</li>" + "<li>SVW: sub-view</li>" + "<li>TRK: project</li>" + "<li>BRC: module</li>" + "<li>UTS: unit test</li>" + "<li>DIR: directory</li>" + "<li>FIL: file</li>" + "<li>DEV: developer</li>" + "</ul>") .setExampleValue("TRK,BRC"); action.createParam("verbose").setDescription("Add some data to response").setBooleanPossibleValues() .setDefaultValue(String.valueOf(false)); action.createParam("limit") .setDescription("Limit the number of results. Only used if one metric, and only one, is set") .setExampleValue("10"); action.createParam("includetrends") .setDescription("Include period variations in response: add nodes <p*> for period variations") .setDefaultValue(String.valueOf(false)).setBooleanPossibleValues(); action.createParam("includealerts") .setDescription("Include alerts data: add nodes <alert> (ERROR, WARN, OK) and <alert_text>") .setBooleanPossibleValues().setDefaultValue(String.valueOf(false)); action.createParam("rules").setDescription( "Filter on rules: setting it to true will return rules id and rule name for measure having such info " + "(such as 'blocker_violations', 'critical_violations', ..., 'new_blocker_violations', ...). Possible values: true | false | list of rule ids") .setBooleanPossibleValues().setDefaultValue(String.valueOf(true)); RailsHandler.addFormatParam(action); }
From source file:org.apache.provisionr.amazon.activities.SetupAdminAccess.java
@Override public Map<String, String> createAdditionalFiles(Pool pool, Machine machine) { try {// ww w. j ava 2 s .c o m return ImmutableMap.of("/tmp/sshd_config", Mustache.toString(getClass(), SSHD_CONFIG_TEMPLATE, ImmutableMap.of("user", pool.getAdminAccess().getUsername())), "/tmp/sudoers", Resources.toString(Resources.getResource(getClass(), SUDOERS_TEMPLATE), Charsets.UTF_8)); } catch (IOException e) { throw Throwables.propagate(e); } }
From source file:org.sonar.server.source.ws.ScmAction.java
@Override public void define(WebService.NewController controller) { WebService.NewAction action = controller.createAction("scm").setDescription( "Get SCM information of source files. 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>Author of the commit</li>" + "<li>Datetime of the commit (before 5.2 it was only the Date)</li>" + "<li>Revision of the commit (added in 5.2)</li>" + "</ol>") .setSince("4.4").setResponseExample(Resources.getResource(getClass(), "example-scm.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"); action.createParam("commits_by_line").setDescription( "Group lines by SCM commit if value is false, else display commits for each line, even if two " + "consecutive lines relate to the same commit.") .setBooleanPossibleValues().setDefaultValue("false"); }
From source file:com.axemblr.provisionr.amazon.activities.RunOnDemandInstances.java
@Override public void execute(AmazonEC2 client, Pool pool, DelegateExecution execution) throws IOException { final String businessKey = execution.getProcessBusinessKey(); final String securityGroupName = SecurityGroups.formatNameFromBusinessKey(businessKey); final String keyPairName = KeyPairs.formatNameFromBusinessKey(businessKey); final String instanceType = pool.getHardware().getType(); final String imageId = getImageIdFromProcessVariablesOrQueryImageTable(execution, pool.getProvider(), instanceType);/* ww w . j a v a2s. c o m*/ final String userData = Resources.toString( Resources.getResource(RunOnDemandInstances.class, "/com/axemblr/provisionr/amazon/userdata.sh"), Charsets.UTF_8); final RunInstancesRequest request = new RunInstancesRequest().withClientToken(businessKey) .withSecurityGroups(securityGroupName).withKeyName(keyPairName).withInstanceType(instanceType) .withImageId(imageId).withMinCount(pool.getMinSize()).withMaxCount(pool.getExpectedSize()) .withUserData(Base64.encodeBytes(userData.getBytes(Charsets.UTF_8))); // TODO allow for more options (e.g. monitoring & termination protection etc.) LOG.info(">> Sending RunInstances request: {}", request); RunInstancesResult result = client.runInstances(request); LOG.info("<< Got RunInstances result: {}", result); // TODO tag instances: managed-by: Axemblr Provisionr, business-key: ID etc. execution.setVariable(ProcessVariables.RESERVATION_ID, result.getReservation().getReservationId()); execution.setVariable(ProcessVariables.INSTANCE_IDS, collectInstanceIdsAsList(result.getReservation().getInstances())); }
From source file:com.facebook.buck.util.PackagedResource.java
private Path unpack() { try (InputStream inner = Preconditions .checkNotNull(Resources.getResource(relativeTo, name), "Unable to find: %s", name).openStream(); BufferedInputStream stream = new BufferedInputStream(inner)) { Path outputPath = filesystem.getBuckPaths().getResDir().resolve(relativeTo.getCanonicalName()) .resolve(filename);/*w w w. jav a2 s. co m*/ // If the path already exists, delete it. if (filesystem.exists(outputPath)) { filesystem.deleteRecursivelyIfExists(outputPath); } String extension = com.google.common.io.Files.getFileExtension(filename.toString()); if (extension.equals("zip")) { filesystem.mkdirs(outputPath); // Copy the zip to a temporary file, and mark that for deletion once the VM exits. Path zip = Files.createTempFile(filename.toString(), ".zip"); // Ensure we tidy up Files.copy(stream, zip, REPLACE_EXISTING); Unzip.extractZipFile(zip, filesystem, outputPath, OVERWRITE); Files.delete(zip); } else { filesystem.createParentDirs(outputPath); Path tempFilePath = filesystem.createTempFile(outputPath.getParent(), outputPath.getFileName().toString() + ".", ".tmp"); try (OutputStream outputStream = filesystem.newFileOutputStream(tempFilePath)) { ByteStreams.copy(stream, outputStream); } filesystem.move(tempFilePath, outputPath); } return outputPath; } catch (IOException ioe) { throw new RuntimeException("Unable to unpack " + name, ioe); } }
From source file:org.isisaddons.app.kitchensink.fixture.blobclob.BlobClobObjectsFixture.java
private Blob newBlob(final String name, final String mimeType, final String resourceName) throws IOException { final byte[] pdfBytes = Resources.toByteArray(Resources.getResource(getClass(), resourceName)); return new Blob(name + "-" + resourceName, mimeType, pdfBytes); }
From source file:org.sonar.server.issue.ws.DeleteCommentAction.java
@Override public void define(WebService.NewController context) { WebService.NewAction action = context.createAction(ACTION_DELETE_COMMENT) .setDescription("Delete 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 the removed comment.<br/>" + "Since 6.3, 'key' parameter has been renamed to %s", PARAM_COMMENT) .setSince("3.6").setHandler(this) .setResponseExample(Resources.getResource(this.getClass(), "delete_comment-example.json")) .setPost(true);//from ww w .j a va 2 s . co m action.createParam(PARAM_COMMENT).setDescription("Comment key").setDeprecatedKey("key", "6.3") .setSince("6.3").setRequired(true).setExampleValue(UUID_EXAMPLE_01); }
From source file:org.opendaylight.controller.blueprint.ext.DataStoreAppConfigDefaultXMLReader.java
private static URL getURL(final Class<?> testClass, final String defaultAppConfigFileName) { return Resources.getResource(testClass, defaultAppConfigFileName); }
From source file:com.facebook.buck.tools.documentation.generator.skylark.rendering.SoyTemplateSkylarkSignatureRenderer.java
private static String loadTemplate(String templateName) throws IOException { URL template = Resources.getResource(SoyTemplateSkylarkSignatureRenderer.class, templateName); return Resources.toString(template, StandardCharsets.UTF_8); }
From source file:uk.ac.susx.tag.method51.twitter.geocoding.TimezoneFilter.java
public TimezoneFilter(Options options) { super(options); JSONObject gmtOffsets = null;// www.j a v a2s . co m try { gmtOffsets = (JSONObject) JSONValue.parse( new InputStreamReader(Resources.getResource(this.getClass(), "gmt-offsets.json").openStream())); } catch (IOException e) { LOG.error("", e); throw new RuntimeException("Unable to find gmt-offsets file."); } try { torqbakTimezones = (JSONObject) JSONValue.parse(new InputStreamReader( Resources.getResource(this.getClass(), "iso-timezones.json").openStream())); } catch (IOException e) { LOG.error("", e); throw new RuntimeException("Unable to find torqbak-timezones file."); } Set<String> timezones = options.acceptedTimezones.get(); if (timezones.size() == 0) { throw new IllegalArgumentException("Must include at least one timezone for TimezoneFilter"); } acceptedTimezones = new double[timezones.size()]; int i = 0; for (String tz : timezones) { if (!isLegitTimezone(tz)) { throw new RuntimeException(tz + " is not a legit timezone"); } acceptedTimezones[i++] = (Double) ((Map) torqbakTimezones.get(tz)).get("lon"); } twitterTimezones = new Object2DoubleRBTreeMap<>(); for (String twitterTimezone : (Set<String>) gmtOffsets.keySet()) { twitterTimezones.put(twitterTimezone, offsetToLongitude(((Number) gmtOffsets.get(twitterTimezone)).doubleValue())); } }