List of usage examples for org.apache.commons.io FileUtils writeLines
public static void writeLines(File file, Collection lines) throws IOException
toString()
value of each item in a collection to the specified File
line by line. From source file:org.kuali.kfs.sys.context.SchemaBuilder.java
/** * Iterates through build schema files processing validation place-holders and outputting to static directory. Include file * for referenced schema types is also written out * /*from w w w . j ava2 s. c o m*/ * @param buildSchemaFiles collection of File objects for build schema files * @param staticDirectoryPath path that processed schema files will be written to * @param buildDirectoryPath path of build schema files * @param useDataDictionaryValidation indicates whether data dictionary validation should be used, if false the general xsd * datatype in the place-holder will be used * @param externalizableContentUrl URL to set for externalizable.static.content.url token * @throws IOException thrown for any read/write errors encountered */ protected static void buildSchemaFiles(Collection buildSchemaFiles, String staticDirectoryPath, String buildDirectoryPath, boolean useDataDictionaryValidation, String externalizableContentUrl, boolean rebuildDDTypes) throws IOException { // initialize dd type schema Collection typesSchemaLines = initalizeDataDictionaryTypesSchema(); Set<String> builtTypes = new HashSet<String>(); // convert static directory path to abstract path File staticDirectory = new File(staticDirectoryPath); String staticPathName = staticDirectory.getAbsolutePath(); for (Iterator iterator = buildSchemaFiles.iterator(); iterator.hasNext();) { File buildSchemFile = (File) iterator.next(); if (LOG.isDebugEnabled()) { LOG.debug("Processing schema file: " + buildSchemFile.getName()); } String outSchemaFilePathName = staticPathName + getRelativeFilePathName(buildSchemFile, buildDirectoryPath); LOG.info("Building schema file: " + outSchemaFilePathName); buildSchemaFile(buildSchemFile, outSchemaFilePathName, useDataDictionaryValidation, typesSchemaLines, externalizableContentUrl, builtTypes, rebuildDDTypes); } // finalize dd type schema typesSchemaLines.addAll(finalizeDataDictionaryTypesSchema()); if (rebuildDDTypes) { LOG.debug("Writing ddTypes schema file"); File ddTypesFile = new File(staticPathName + File.separator + "xsd" + File.separator + "sys" + File.separator + "ddTypes.xsd"); File ddTypesFileBuild = new File(buildDirectoryPath + File.separator + "xsd" + File.separator + "sys" + File.separator + "ddTypes.xsd"); FileUtils.writeLines(ddTypesFile, typesSchemaLines); FileUtils.copyFile(ddTypesFile, ddTypesFileBuild); } }
From source file:org.kuali.kfs.sys.context.SchemaBuilder.java
/** * Process a single schema file (setting validation and externalizable token) and outputs to static directory. Any new data * dictionary types encountered are added to the given Collection for later writing to the types include file * //from ww w.j ava2 s .co m * @param buildSchemFile build schema file that should be processed * @param outSchemaFilePathName full file path name for the outputted schema * @param useDataDictionaryValidation indicates whether data dictionary validation should be used, if false the general xsd * datatype in the place-holder will be used * @param typesSchemaLines collection of type XML lines to add to for any new types * @param externalizableContentUrl URL to set for externalizable.static.content.url token * @param builtTypes - Set of attribute names for which a schema validation type has been built * @throws IOException thrown for any read/write errors encountered */ protected static void buildSchemaFile(File buildSchemFile, String outSchemaFilePathName, boolean useDataDictionaryValidation, Collection typesSchemaLines, String externalizableContentUrl, Set<String> builtTypes, boolean rebuildDDTypes) throws IOException { Collection buildSchemaLines = FileUtils.readLines(buildSchemFile); Collection outSchemaLines = new ArrayList(); int lineCount = 1; for (Iterator iterator = buildSchemaLines.iterator(); iterator.hasNext();) { if (LOG.isDebugEnabled()) { LOG.debug("Processing line " + lineCount + "of file " + buildSchemFile.getAbsolutePath()); } String buildLine = (String) iterator.next(); String outLine = buildLine; // check for externalizable.static.content.url token and replace if found if (StringUtils.contains(buildLine, "@externalizable.static.content.url@")) { outLine = StringUtils.replace(buildLine, "@externalizable.static.content.url@", externalizableContentUrl); } // check for validation place-holder and process if found else if (StringUtils.contains(buildLine, SCHEMA_FILE_DD_VALIDATION_PLACEHOLDER_BEGIN) && StringUtils.contains(buildLine, SCHEMA_FILE_DD_VALIDATION_PLACEHOLDER_END)) { String validationPlaceholder = StringUtils.substringBetween(buildLine, SCHEMA_FILE_DD_VALIDATION_PLACEHOLDER_BEGIN, SCHEMA_FILE_DD_VALIDATION_PLACEHOLDER_END); if (StringUtils.isBlank(validationPlaceholder)) { logAndThrowException(String.format("File %s line %s: validation placeholder cannot be blank", buildSchemFile.getAbsolutePath(), lineCount)); } if (LOG.isDebugEnabled()) { LOG.debug("Found dd validation placeholder: " + validationPlaceholder); } if (!StringUtils.contains(validationPlaceholder, ",")) { logAndThrowException(String.format( "File %s, line %s: Invalid format of placehoder value: %s, must contain a ',' seperating parts", buildSchemFile.getAbsolutePath(), lineCount, validationPlaceholder)); } outLine = processValidationPlaceholder(validationPlaceholder, buildLine, buildSchemFile.getAbsolutePath(), lineCount, useDataDictionaryValidation, typesSchemaLines, builtTypes, rebuildDDTypes); } outSchemaLines.add(outLine); lineCount++; } LOG.debug("Writing schema file to static directory"); File schemaFile = new File(outSchemaFilePathName); FileUtils.writeLines(schemaFile, outSchemaLines); }
From source file:org.kurento.test.base.BrowserTest.java
@FailedTest public static void storeBrowsersLogs() { List<String> lines = new ArrayList<>(); for (String browserKey : browserLogs.keySet()) { for (LogEntry logEntry : browserLogs.get(browserKey)) { lines.add(logEntry.toString()); }/*from ww w .ja va 2s . c o m*/ File file = new File(getDefaultOutputTestPath() + browserKey + ".log"); try { FileUtils.writeLines(file, lines); } catch (IOException e) { log.error("Error while writing browser log to a file", e); } } }
From source file:org.lahab.clucene.queryStresser.QueryParserTest.java
@Test public void testQueryParser() throws Exception { JSONObject obj = new JSONObject(); File file = new File("test.json"); file.createNewFile();/*from ww w . java 2s . co m*/ FileUtils.writeLines(file, queries); obj.accumulate("queryFile", "test.json"); obj.accumulate("nbQueries", 4); obj.accumulate("uniform", true); obj.accumulate("gaussian", JSONSerializer.toJSON("{\"mean\": 2, \"stddev\": 0.2}")); Uqp = new QueryParser(new JSONConfiguration(obj)); assertTrue(Uqp._mean == 0.0); assertTrue(Uqp._stddev == 0.0); assertSame(Uqp._uniform, true); for (int i = 0; i < Uqp._queries.length; i++) { assertEquals(Uqp._queries[i], queries.get(i)); } obj = new JSONObject(); obj.accumulate("queryFile", "test.json"); obj.accumulate("nbQueries", 3); obj.accumulate("gaussian", JSONSerializer.toJSON("{\"mean\": 1, \"stddev\": 0.2}")); Nqp = new QueryParser(new JSONConfiguration(obj)); assertTrue(Nqp._mean == 1); assertTrue(Nqp._stddev == 0.2); assertFalse(Nqp._uniform); for (int i = 0; i < Nqp._queries.length; i++) { assertEquals(Nqp._queries[i], queries.get(i)); } file.delete(); }
From source file:org.nuxeo.ecm.core.test.FakeSmtpMailServerFeature.java
@Override public void beforeSetup(FeaturesRunner runner) throws Exception { server = SimpleSmtpServer.start(SERVER_PORT); if (Framework.isInitialized()) { File file = new File(Environment.getDefault().getConfig(), "mail.properties"); file.getParentFile().mkdirs();/* w ww.j a va2s . c o m*/ List<String> mailProperties = new ArrayList<String>(); mailProperties.add(String.format("mail.smtp.host = %s", SERVER_HOST)); mailProperties.add(String.format("mail.smtp.port = %s", SERVER_PORT)); FileUtils.writeLines(file, mailProperties); Framework.getProperties().put("mail.transport.host", SERVER_HOST); Framework.getProperties().put("mail.transport.port", SERVER_PORT); } }
From source file:org.openengsb.core.services.internal.deployer.connector.ConnectorDeployerServiceTest.java
@Test public void testUpdateServiceViaPersistence_shouldNotOverwriteProperties() throws Exception { File connectorFile = temporaryFolder.newFile(TEST_FILE_NAME); FileUtils.writeLines(connectorFile, Arrays.asList("domainType=mydomain", "connectorType=aconnector", "property.foo=bar", "attribute.x=y")); connectorDeployerService.install(connectorFile); ConnectorDescription desc = serviceManager.getAttributeValues(testConnectorId); desc.getProperties().put("foo", "42"); serviceManager.update(testConnectorId, desc); FileUtils.writeLines(connectorFile, Arrays.asList("domainType=mydomain", "connectorType=aconnector", "property.foo=bar", "attribute.x=y", "property.x=y")); connectorDeployerService.update(connectorFile); assertThat(bundleContext.getServiceReferences(NullDomain.class.getName(), "(foo=42)"), not(nullValue())); assertThat(bundleContext.getServiceReferences(NullDomain.class.getName(), "(x=y)"), not(nullValue())); }
From source file:org.openengsb.core.services.internal.deployer.connector.ConnectorDeployerServiceTest.java
@Test public void testUpdateAttributeViaPersistence_shouldNotOverwrite() throws Exception { File connectorFile = temporaryFolder.newFile(TEST_FILE_NAME); FileUtils.writeLines(connectorFile, Arrays.asList("domainType=mydomain", "connectorType=aconnector", "property.foo=bar", "attribute.x=y")); connectorDeployerService.install(connectorFile); ConnectorDescription desc = serviceManager.getAttributeValues(testConnectorId); ConnectorDescription newDesc = new ConnectorDescription("mydomain", "aconnector", ImmutableMap.of("x", "z"), desc.getProperties());/*from w w w .ja v a 2 s . c om*/ serviceManager.update(testConnectorId, newDesc); FileUtils.writeLines(connectorFile, Arrays.asList("domainType=mydomain", "connectorType=aconnector", "property.foo=bar", "attribute.x=y", "property.x=y")); connectorDeployerService.update(connectorFile); ConnectorDescription attributeValues = serviceManager.getAttributeValues(testConnectorId); assertThat(attributeValues.getAttributes().get("x"), is("z")); }
From source file:org.openengsb.core.services.internal.deployer.connector.ConnectorDeployerServiceTest.java
@Test public void testRemovePropertyFromConfig_shouldRemoveProperty() throws Exception { File connectorFile = temporaryFolder.newFile(TEST_FILE_NAME); FileUtils.writeLines(connectorFile, Arrays.asList("domainType=mydomain", "connectorType=aconnector", "property.foo=bar", "attribute.x=y")); connectorDeployerService.install(connectorFile); FileUtils.writeLines(connectorFile,//from w w w. j av a 2 s.c om Arrays.asList("domainType=mydomain", "connectorType=aconnector", "attribute.x=y", "property.x=y")); connectorDeployerService.update(connectorFile); assertThat(bundleContext.getServiceReferences(NullDomain.class.getName(), "(foo=bar)"), nullValue()); assertThat(bundleContext.getServiceReferences(NullDomain.class.getName(), "(x=y)"), not(nullValue())); }
From source file:org.openengsb.core.services.internal.deployer.connector.ConnectorDeployerServiceTest.java
@Test public void testModifyAttributeInBothPlaces_shouldThrowException() throws Exception { File connectorFile = temporaryFolder.newFile(TEST_FILE_NAME); FileUtils.writeLines(connectorFile, Arrays.asList("domainType=mydomain", "connectorType=aconnector", "property.foo=bar", "attribute.x=original-file-value")); connectorDeployerService.install(connectorFile); String id = testConnectorId;//from w w w . j av a 2 s . c om ConnectorDescription desc = serviceManager.getAttributeValues(id); Map<String, String> attributes = ImmutableMap.of("x", "new-persistence-value"); ConnectorDescription newDesc = new ConnectorDescription("mydomain", "aconnector", attributes, desc.getProperties()); serviceManager.update(id, newDesc); FileUtils.writeLines(connectorFile, Arrays.asList("property.foo=bar", "attribute.x=new-value-value")); try { connectorDeployerService.update(connectorFile); fail("update should have failed, because of a merge-conflict"); } catch (MergeException e) { assertThat(serviceManager.getAttributeValues(id).getAttributes().get("x"), is("new-persistence-value")); } }
From source file:org.openengsb.core.services.internal.deployer.connector.ConnectorDeployerServiceTest.java
@Test public void testRemovePropertyOnBothEnds_shouldStayRemovedWithoutError() throws Exception { File connectorFile = temporaryFolder.newFile(TEST_FILE_NAME); FileUtils.writeLines(connectorFile, Arrays.asList("domainType=mydomain", "connectorType=aconnector", "property.foo=bar", "attribute.x=original-file-value")); connectorDeployerService.install(connectorFile); ConnectorDescription desc = serviceManager.getAttributeValues(testConnectorId); Map<String, Object> properties = new Hashtable<String, Object>(); ConnectorDescription newDesc = new ConnectorDescription("mydomain", "aconnector", desc.getAttributes(), properties);//from w ww.j ava 2 s .c o m serviceManager.update(testConnectorId, newDesc); FileUtils.writeLines(connectorFile, Arrays.asList("domainType=mydomain", "connectorType=aconnector", "attribute.x=original-file-value")); connectorDeployerService.update(connectorFile); assertThat(bundleContext.getServiceReferences(NullDomain.class.getName(), "(foo=bar)"), nullValue()); }