List of usage examples for org.apache.commons.lang SystemUtils LINE_SEPARATOR
String LINE_SEPARATOR
To view the source code for org.apache.commons.lang SystemUtils LINE_SEPARATOR.
Click Source Link
The line.separator
System Property.
From source file:com.healthmarketscience.jackcess.impl.CustomToStringStyle.java
private static String indent(Object obj) { return ((obj != null) ? obj.toString().replaceAll(SystemUtils.LINE_SEPARATOR, ML_FIELD_SEP) : null); }
From source file:au.com.dw.testdatacapturej.reflection.TestGenNullTest.java
/** * Test for null Array field.//from www.j a v a 2 s .c o m */ @Test public void nullArrayTest() { try { logger.logObject(builder, handler.handle(new NullArrayHolder())); String result = builder.getLog(); String expected = SystemUtils.LINE_SEPARATOR + "au.com.dw.testdatacapturej.mock.dataholder.NullArrayHolder nullArrayHolder0 = new au.com.dw.testdatacapturej.mock.dataholder.NullArrayHolder();" + SystemUtils.LINE_SEPARATOR + "nullArrayHolder0.setNullField(null);" + SystemUtils.LINE_SEPARATOR + "nullArrayHolder0.setPrimitiveNullField(null);" + SystemUtils.LINE_SEPARATOR; System.out.println(result); assertEquals(expected, result); } catch (Exception e) { e.printStackTrace(); fail(); } }
From source file:com.gs.obevo.db.apps.reveng.AbstractDdlReveng.java
private void revengMain(AquaRevengArgs args) { String schema = args.getDbSchema(); File file = args.getInputPath(); boolean generateBaseline = args.isGenerateBaseline(); File outputDir = args.getOutputPath(); MutableList<ChangeEntry> changeEntries = Lists.mutable.empty(); final MutableList<String> dataLines; if (file.isFile()) { dataLines = FileUtilsCobra.readLines(file); } else {/*w ww.j a va 2 s. c o m*/ dataLines = ArrayAdapter.adapt(file.listFiles()).select(new Predicate<File>() { @Override public boolean accept(File file) { return file.isFile(); } }).flatCollect(new Function<File, Iterable<String>>() { @Override public Iterable<String> valueOf(File file) { return FileUtilsCobra.readLines(file); } }); } dataLines.forEachWithIndex(new ObjectIntProcedure<String>() { @Override public void value(String line, int i) { if (line.startsWith("--------------------") && dataLines.get(i + 1).startsWith("-- DDL Statements") && dataLines.get(i + 2).startsWith("--------------------")) { dataLines.set(i, ""); dataLines.set(i + 1, ""); dataLines.set(i + 2, ""); } else if (line.startsWith("--------------------") && dataLines.get(i + 2).startsWith("-- DDL Statements") && dataLines.get(i + 4).startsWith("--------------------")) { dataLines.set(i, ""); dataLines.set(i + 1, ""); dataLines.set(i + 2, ""); dataLines.set(i + 3, ""); dataLines.set(i + 4, ""); } else if (line.startsWith("-- DDL Statements for ")) { dataLines.set(i, ""); } } }); String data = dataLines.makeString(SystemUtils.LINE_SEPARATOR); MutableList<String> entries = stringSplitter.valueOf(data); String candidateObject = "UNKNOWN"; ChangeType candidateObjectType = UnclassifiedChangeType.INSTANCE; int selfOrder = 0; int objectOrder = 0; // Find object names MutableSet<String> objectNames = Sets.mutable.empty(); for (String candidateLine : entries) { candidateLine = StringUtils.stripStart(candidateLine, "\r\n \t"); if (StringUtils.isNotBlank(candidateLine) && Predicates.noneOf(skipPredicates).accept(candidateLine)) { candidateLine = candidateLine.replaceAll(schema + "\\.dbo\\.", ""); // sybase ASE candidateLine = candidateLine.replaceAll("'dbo\\.", "'"); // sybase ASE candidateLine = candidateLine.replaceAll("\"" + schema + "\\s*\"\\.", ""); // DB2 candidateLine = candidateLine.replaceAll(schema + "\\.", ""); // alternate DB2 for views candidateLine = removeQuotesFromProcxmode(candidateLine); // sybase ASE RevengPattern chosenRevengPattern = null; String secondaryName = null; for (RevengPattern revengPattern : revengPatterns) { RevengPatternOutput patternMatch = revengPattern.evaluate(candidateLine); if (patternMatch != null) { System.out.println("OBJECT NAME " + patternMatch.getPrimaryName()); objectNames.add(patternMatch.getPrimaryName()); chosenRevengPattern = revengPattern; candidateObject = patternMatch.getPrimaryName(); if (patternMatch.getSecondaryName() != null) { secondaryName = patternMatch.getSecondaryName(); } candidateObjectType = platform.getChangeType(revengPattern.getChangeType()); objectOrder = 0; break; } } } } MutableMap<String, AtomicInteger> countByObject = Maps.mutable.empty(); for (String candidateLine : entries) { try { candidateLine = StringUtils.stripStart(candidateLine, "\r\n \t"); if (StringUtils.isNotBlank(candidateLine) && Predicates.noneOf(skipPredicates).accept(candidateLine)) { for (String objectName : objectNames) { candidateLine = candidateLine.replaceAll(schema + "\\s*\\." + objectName, objectName); // sybase ASE candidateLine = candidateLine.replaceAll( schema.toLowerCase() + "\\s*\\." + objectName.toLowerCase(), objectName.toLowerCase()); // sybase ASE } candidateLine = candidateLine.replaceAll(schema + "\\.dbo\\.", ""); // sybase ASE candidateLine = candidateLine.replaceAll("'dbo\\.", "'"); // sybase ASE candidateLine = candidateLine.replaceAll("\"" + schema + "\\s*\"\\.", ""); // DB2 candidateLine = candidateLine.replaceAll(schema + "\\.", ""); // alternate DB2 for views candidateLine = removeQuotesFromProcxmode(candidateLine); // sybase ASE RevengPattern chosenRevengPattern = null; String secondaryName = null; for (RevengPattern revengPattern : revengPatterns) { RevengPatternOutput patternMatch = revengPattern.evaluate(candidateLine); if (patternMatch != null) { chosenRevengPattern = revengPattern; candidateObject = patternMatch.getPrimaryName(); if (patternMatch.getSecondaryName() != null) { secondaryName = patternMatch.getSecondaryName(); } candidateObjectType = platform.getChangeType(revengPattern.getChangeType()); objectOrder = 0; break; } } AtomicInteger objectOrder2 = countByObject.getIfAbsentPut(candidateObject, new Function0<AtomicInteger>() { @Override public AtomicInteger value() { return new AtomicInteger(0); } }); if (secondaryName == null) { secondaryName = "change" + objectOrder2.getAndIncrement(); } RevEngDestination destination = new RevEngDestination(schema, candidateObjectType, candidateObject, false); String annotation = chosenRevengPattern != null ? chosenRevengPattern.getAnnotation() : null; MutableList<Function<String, LineParseOutput>> postProcessSqls = chosenRevengPattern != null ? chosenRevengPattern.getPostProcessSqls() : Lists.mutable.<Function<String, LineParseOutput>>empty(); for (Function<String, LineParseOutput> postProcessSql : postProcessSqls) { LineParseOutput lineParseOutput = postProcessSql.valueOf(candidateLine); candidateLine = lineParseOutput.getLineOutput(); } ChangeEntry change = new ChangeEntry(destination, candidateLine + "\nGO", secondaryName, annotation, selfOrder++); postProcessChange.value(change, candidateLine); changeEntries.add(change); } } catch (RuntimeException e) { throw new RuntimeException("Failed parsing on statement " + candidateLine, e); } } new RevengWriter().write(platform, changeEntries, outputDir, generateBaseline, RevengWriter.defaultShouldOverwritePredicate(), args.getDbHost(), args.getDbPort(), args.getDbServer()); }
From source file:au.com.dw.testdatacapturej.reflection.TestGenFieldTest.java
@Test public void testPrimitiveHolder() { FieldPrimitiveHolder holder = new FieldPrimitiveHolder(); holder.setByteField(createByte());//from ww w.ja va 2 s. c o m holder.setIntField(createInt()); holder.setLongField(createLong()); holder.setFloatField(createFloat()); holder.setDoubleField(createDouble()); holder.setCharField(createChar()); holder.setBooleanField(createBoolean()); try { logger.logObject(builder, handler.handle(holder)); String result = builder.getLog(); String expected = SystemUtils.LINE_SEPARATOR + "au.com.dw.testdatacapturej.mock.dataholder.FieldPrimitiveHolder fieldPrimitiveHolder0 = new au.com.dw.testdatacapturej.mock.dataholder.FieldPrimitiveHolder();" + SystemUtils.LINE_SEPARATOR + "fieldPrimitiveHolder0.setByteField(1);" + SystemUtils.LINE_SEPARATOR + "fieldPrimitiveHolder0.setIntField(2);" + SystemUtils.LINE_SEPARATOR + "fieldPrimitiveHolder0.setLongField(3L);" + SystemUtils.LINE_SEPARATOR + "fieldPrimitiveHolder0.setFloatField(10.1f);" + SystemUtils.LINE_SEPARATOR + "fieldPrimitiveHolder0.setDoubleField(20.1d);" + SystemUtils.LINE_SEPARATOR + "fieldPrimitiveHolder0.setCharField('a');" + SystemUtils.LINE_SEPARATOR + "fieldPrimitiveHolder0.setBooleanField(true);" + SystemUtils.LINE_SEPARATOR; System.out.println(result); assertEquals(expected, result); } catch (Exception e) { e.printStackTrace(); fail("testPrimitiveHolder"); } }
From source file:au.com.dw.testing.AssertUtil.java
/** * Version of assertEquals() for comparing strings with the new line formatting * removed.//from w ww. ja v a2 s.co m * * This should make the comparison of generated logs more robust since don't have to * worry about changes in new line formatting. * * @param expected * @param actual */ public static void assertEqualsWithoutFormatting(String expected, String actual) { String expectedWithoutFormatting = null; String actualWithoutFormatting = null; if (expected != null) { expectedWithoutFormatting = expected.replaceAll(SystemUtils.LINE_SEPARATOR, ""); } if (actual != null) { actualWithoutFormatting = actual.replaceAll(SystemUtils.LINE_SEPARATOR, ""); } assertEquals(expectedWithoutFormatting, actualWithoutFormatting); }
From source file:au.com.dw.testdatacapturej.reflection.TestGenNullTest.java
/** * Test for null Map field./* w ww.j av a 2 s . c om*/ */ @Test public void nullMapTest() { try { logger.logObject(builder, handler.handle(new NullMapHolder())); String result = builder.getLog(); String expected = SystemUtils.LINE_SEPARATOR + "au.com.dw.testdatacapturej.mock.dataholder.NullMapHolder nullMapHolder0 = new au.com.dw.testdatacapturej.mock.dataholder.NullMapHolder();" + SystemUtils.LINE_SEPARATOR + "nullMapHolder0.setNullField(null);" + SystemUtils.LINE_SEPARATOR + "nullMapHolder0.setImplNullField(null);" + SystemUtils.LINE_SEPARATOR; System.out.println(result); assertEquals(expected, result); } catch (Exception e) { e.printStackTrace(); fail(); } }
From source file:hello.jaxrs.GreetingsResource.java
@GET @Produces(MediaType.TEXT_PLAIN)//w w w . ja va2 s.c o m public Response showGreetings() { // read greetings Collection<String> greetings; try { greetings = getGreetingService().getGreetings(); } catch (final IllegalStateException e) { // no service is available; lets report that properly return Response.status(Status.SERVICE_UNAVAILABLE).type(MediaType.TEXT_PLAIN_TYPE) .entity(e.getMessage()).build(); } catch (final Exception e) { // this looks like an issue deeper in some underlying code; we should log this properly return Response.serverError().type(MediaType.TEXT_PLAIN_TYPE) .entity(ExceptionUtils.getFullStackTrace(e)).build(); } return Response.ok(StringUtils.join(greetings, SystemUtils.LINE_SEPARATOR), MediaType.TEXT_PLAIN).build(); }
From source file:de.pdark.dsmp.RequestHandler.java
public static void generateChecksum(File source, File f, String ext) { try {//from w w w .ja va 2 s . co m String checksum = null; if ("md5".equals(ext)) { Md5Digester digester = new Md5Digester(); checksum = digester.calc(source); } else if ("sha1".equals(ext)) { Sha1Digester digester = new Sha1Digester(); checksum = digester.calc(source); } if (checksum != null) { FileWriter w = new FileWriter(f); w.write(checksum); w.write(SystemUtils.LINE_SEPARATOR); w.close(); } } catch (DigesterException e) { log.warn("Error creating " + ext.toUpperCase() + " checksum for " + source.getAbsolutePath(), e); } catch (IOException e) { log.warn("Error writing " + ext.toUpperCase() + " checksum for " + source.getAbsolutePath() + " to " + f.getAbsolutePath(), e); } }
From source file:com.google.api.ads.adwords.keywordoptimizer.KeywordCollection.java
@Override public String toString() { StringBuilder out = new StringBuilder(); for (KeywordInfo keyword : keywords.values()) { out.append(keyword.toString()).append(SystemUtils.LINE_SEPARATOR); }//from www .j av a 2s . c om return out.toString(); }
From source file:au.com.dw.testdatacapturej.reflection.TestGenNullTest.java
/** * Test for Collection field with null elements. *//*from w ww . j a v a 2 s . c o m*/ @Test public void nullCollectionElementTest() { try { logger.logObject(builder, handler.handle(new NullCollectionElementHolder())); String result = builder.getLog(); String expected = SystemUtils.LINE_SEPARATOR + "au.com.dw.testdatacapturej.mock.dataholder.NullCollectionElementHolder nullCollectionElementHolder0 = new au.com.dw.testdatacapturej.mock.dataholder.NullCollectionElementHolder();" + SystemUtils.LINE_SEPARATOR + SystemUtils.LINE_SEPARATOR + "java.util.ArrayList arrayList0 = new java.util.ArrayList();" + SystemUtils.LINE_SEPARATOR + "arrayList0.add(null);" + SystemUtils.LINE_SEPARATOR + SystemUtils.LINE_SEPARATOR + "nullCollectionElementHolder0.setNullField(arrayList0);" + SystemUtils.LINE_SEPARATOR + SystemUtils.LINE_SEPARATOR + "java.util.ArrayList arrayList1 = new java.util.ArrayList();" + SystemUtils.LINE_SEPARATOR + "arrayList1.add(null);" + SystemUtils.LINE_SEPARATOR + SystemUtils.LINE_SEPARATOR + "nullCollectionElementHolder0.setImplNullField(arrayList1);" + SystemUtils.LINE_SEPARATOR; System.out.println(result); assertEquals(expected, result); } catch (Exception e) { e.printStackTrace(); fail(); } }