Java Code Examples for org.codehaus.groovy.runtime.ResourceGroovyMethods#getText()
The following examples show how to use
org.codehaus.groovy.runtime.ResourceGroovyMethods#getText() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GroovyCodeSource.java From groovy with Apache License 2.0 | 6 votes |
public GroovyCodeSource(URL url) { if (url == null) { throw new RuntimeException("Could not construct a GroovyCodeSource from a null URL"); } this.url = url; // TODO: GROOVY-6561: GroovyMain got the name this way: script.substring(script.lastIndexOf('/') + 1) this.name = url.toExternalForm(); this.codeSource = new CodeSource(url, (java.security.cert.Certificate[]) null); try { String contentEncoding = getContentEncoding(url); if (contentEncoding != null) { this.scriptText = ResourceGroovyMethods.getText(url, contentEncoding); } else { this.scriptText = ResourceGroovyMethods.getText(url); // falls-back on default encoding } } catch (IOException e) { throw new RuntimeException("Impossible to read the text content from " + name, e); } }
Example 2
Source File: GroovyRootDocBuilder.java From groovy with Apache License 2.0 | 5 votes |
private void setOverview() { String path = properties.getProperty("overviewFile"); if (path != null && path.length() > 0) { try { String content = ResourceGroovyMethods.getText(new File(path)); calcThenSetOverviewDescription(content); } catch (IOException e) { System.err.println("Unable to load overview file: " + e.getMessage()); } } }
Example 3
Source File: ResourceServiceImplTest.java From jwala with Apache License 2.0 | 4 votes |
@Test public void testGenerateResourceFile() { File httpdTemplate = new File("../jwala-common/src/test/resources/HttpdConfTemplate.tpl"); try { List<Group> groups = new ArrayList<>(); List<Jvm> jvms = new ArrayList<>(); List<WebServer> webServers = new ArrayList<>(); List<Application> applications = new ArrayList<>(); Group group = new Group(new Identifier<Group>(1111L), "groupName", new HashSet<>(jvms), new HashSet<>(webServers), new HashSet<History>(), new HashSet<>(applications)); groups.add(group); applications.add(new Application(new Identifier<Application>(111L), "hello-world-1", "d:/jwala/app/archive", "/hello-world-1", group, true, true, false, "testWar.war", "d:/test1/deployPath")); applications.add(new Application(new Identifier<Application>(222L), "hello-world-2", "d:/jwala/app/archive", "/hello-world-2", group, true, true, false, "testWar.war", "d:/test2/deployPath")); applications.add(new Application(new Identifier<Application>(333L), "hello-world-3", "d:/jwala/app/archive", "/hello-world-3", group, true, true, false, "testWar.war", "d:/test3/deployPath")); WebServer webServer = new WebServer(new Identifier<WebServer>(1L), groups, "Apache2.4", "localhost", 80, 443, new com.cerner.jwala.common.domain.model.path.Path("/statusPath"), WebServerReachableState.WS_UNREACHABLE, null); webServers.add(webServer); jvms.add(new Jvm(new Identifier<Jvm>(11L), "tc1", "someHostGenerateMe", new HashSet<>(groups), 11010, 11011, 11012, -1, 11013, new com.cerner.jwala.common.domain.model.path.Path("/statusPath"), "EXAMPLE_OPTS=%someEvn%/someVal", JvmState.JVM_STOPPED, "", null, null, null, null, null, null, null)); jvms.add(new Jvm(new Identifier<Jvm>(22L), "tc2", "someHostGenerateMe", new HashSet<>(groups), 11020, 11021, 11022, -1, 11023, new com.cerner.jwala.common.domain.model.path.Path("/statusPath"), "EXAMPLE_OPTS=%someEvn%/someVal", JvmState.JVM_STOPPED, "", null, null, null, null, null, null, null)); when(Config.mockGroupPesistenceService.getGroups()).thenReturn(groups); when(Config.mockAppPersistenceService.findApplicationsBelongingTo(anyString())).thenReturn(applications); when(Config.mockJvmPersistenceService.getJvmsAndWebAppsByGroupName(anyString())).thenReturn(jvms); when(Config.mockWebServerPersistenceService.getWebServersByGroupName(anyString())).thenReturn(webServers); System.setProperty(ApplicationProperties.PROPERTIES_ROOT_PATH, this.getClass().getClassLoader().getResource("vars.properties").getPath().replace("vars.properties", "")); final ResourceGroup resourceGroup = resourceService.generateResourceGroup(); String output = resourceService.generateResourceFile(ResourceGroovyMethods.getText(httpdTemplate), ResourceGroovyMethods.getText(httpdTemplate), resourceGroup, webServer, ResourceGeneratorType.TEMPLATE); String expected = ResourceGroovyMethods.getText(new File("../jwala-common/src/test/resources/HttpdConfTemplate-EXPECTED.conf")); expected = expected.replaceAll("\\r", "").replaceAll("\\n", ""); output = output.replaceAll("\\r", "").replaceAll("\\n", ""); String diff = StringUtils.difference(output, expected); assertEquals(expected, output); } catch (IOException e) { fail(e.getMessage()); } }
Example 4
Source File: GroovyRootDocBuilder.java From groovy with Apache License 2.0 | 4 votes |
private void processFile(String filename, File srcFile, boolean isAbsolute) throws IOException { String src = ResourceGroovyMethods.getText(srcFile); String relPackage = GroovyDocUtil.getPath(filename).replace('\\', FS); String packagePath = isAbsolute ? "DefaultPackage" : relPackage; String file = GroovyDocUtil.getFile(filename); SimpleGroovyPackageDoc packageDoc = null; if (!isAbsolute) { packageDoc = (SimpleGroovyPackageDoc) rootDoc.packageNamed(packagePath); } // todo: this might not work correctly for absolute paths if (filename.endsWith("package.html") || filename.endsWith("package-info.java") || filename.endsWith("package-info.groovy")) { if (packageDoc == null) { packageDoc = new SimpleGroovyPackageDoc(relPackage); packagePath = relPackage; } processPackageInfo(src, filename, packageDoc); rootDoc.put(packagePath, packageDoc); return; } try { GroovyDocParserI docParser = new GroovyDocParser(links, properties); Map<String, GroovyClassDoc> classDocs = docParser.getClassDocsFromSingleSource(packagePath, file, src); rootDoc.putAllClasses(classDocs); if (isAbsolute) { Iterator<Map.Entry<String, GroovyClassDoc>> iterator = classDocs.entrySet().iterator(); if (iterator.hasNext()) { final Map.Entry<String, GroovyClassDoc> docEntry = iterator.next(); String fullPath = docEntry.getValue().getFullPathName(); int slash = fullPath.lastIndexOf(FS); if (slash > 0) packagePath = fullPath.substring(0, slash); packageDoc = (SimpleGroovyPackageDoc) rootDoc.packageNamed(packagePath); } } if (packageDoc == null) { packageDoc = new SimpleGroovyPackageDoc(packagePath); } packageDoc.putAll(classDocs); rootDoc.put(packagePath, packageDoc); } catch (RuntimeException e) { e.printStackTrace(System.err); log.error("ignored due to parsing exception: " + filename + " [" + e.getMessage() + "]"); log.debug("ignored due to parsing exception: " + filename + " [" + e.getMessage() + "]", e); } }
Example 5
Source File: GroovyMain.java From groovy with Apache License 2.0 | 3 votes |
/** * Get the text of the Groovy script at the given location. * If the location is a file path and it does not exist as given, * then {@link GroovyMain#huntForTheScriptFile(String)} is called to try * with some Groovy extensions appended. * * This method is not used to process scripts and is retained for backward * compatibility. If you want to modify how GroovyMain processes scripts * then use {@link GroovyMain#getScriptSource(boolean, String)}. * * @param uriOrFilename * @return the text content at the location * @throws IOException * @deprecated */ @Deprecated public String getText(String uriOrFilename) throws IOException { if (URI_PATTERN.matcher(uriOrFilename).matches()) { try { return ResourceGroovyMethods.getText(new URL(uriOrFilename)); } catch (Exception e) { throw new GroovyRuntimeException("Unable to get script from URL: ", e); } } return ResourceGroovyMethods.getText(huntForTheScriptFile(uriOrFilename)); }