org.gradle.util.TextUtil Java Examples

The following examples show how to use org.gradle.util.TextUtil. 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: ClasspathAddingInitScriptBuilder.java    From paraphrase with Apache License 2.0 6 votes vote down vote up
public void build(File initScriptFile, final List<File> classpath) {
  IoActions.writeTextFile(initScriptFile, new ErroringAction<Writer>() {
    @Override
    protected void doExecute(Writer writer) throws Exception {
      writer.write("allprojects {\n");
      writer.write("  buildscript {\n");
      writer.write("    dependencies {\n");
      writer.write("      classpath files(\n");
      int i = 0;
      for (File file : classpath) {
        writer.write(
            String.format("        '%s'", TextUtil.escapeString(file.getAbsolutePath())));
        if (++i != classpath.size()) {
          writer.write(",\n");
        }
      }
      writer.write("\n");
      writer.write("      )\n");
      writer.write("    }\n");
      writer.write("  }\n");
      writer.write("}\n");
    }
  });
}
 
Example #2
Source File: XmlTransformer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void doWriteTo(Writer writer, String encoding) {
    writeXmlDeclaration(writer, encoding);

    try {
        if (node != null) {
            printNode(node, writer);
        } else if (element != null) {
            printDomNode(element, writer);
        } else if (builder != null) {
            writer.append(TextUtil.toPlatformLineSeparators(stripXmlDeclaration(builder)));
        } else {
            writer.append(TextUtil.toPlatformLineSeparators(stripXmlDeclaration(stringValue)));
        }
    } catch (IOException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
 
Example #3
Source File: XmlTransformer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void doWriteTo(Writer writer, String encoding) {
    writeXmlDeclaration(writer, encoding);

    try {
        if (node != null) {
            printNode(node, writer);
        } else if (element != null) {
            printDomNode(element, writer);
        } else if (builder != null) {
            writer.append(TextUtil.toPlatformLineSeparators(stripXmlDeclaration(builder)));
        } else {
            writer.append(TextUtil.toPlatformLineSeparators(stripXmlDeclaration(stringValue)));
        }
    } catch (IOException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
 
Example #4
Source File: XmlTransformer.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void doWriteTo(Writer writer, String encoding) {
    writeXmlDeclaration(writer, encoding);

    try {
        if (node != null) {
            printNode(node, writer);
        } else if (element != null) {
            printDomNode(element, writer);
        } else if (builder != null) {
            writer.append(TextUtil.toPlatformLineSeparators(stripXmlDeclaration(builder)));
        } else {
            writer.append(TextUtil.toPlatformLineSeparators(stripXmlDeclaration(stringValue)));
        }
    } catch (IOException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
 
Example #5
Source File: XmlTransformer.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void doWriteTo(Writer writer, String encoding) {
    writeXmlDeclaration(writer, encoding);

    try {
        if (node != null) {
            printNode(node, writer);
        } else if (element != null) {
            printDomNode(element, writer);
        } else if (builder != null) {
            writer.append(TextUtil.toPlatformLineSeparators(stripXmlDeclaration(builder)));
        } else {
            writer.append(TextUtil.toPlatformLineSeparators(stripXmlDeclaration(stringValue)));
        }
    } catch (IOException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
 
Example #6
Source File: TestEventLogger.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onOutput(TestDescriptor descriptor, TestOutputEvent outputEvent) {
    if (outputEvent.getDestination() == TestOutputEvent.Destination.StdOut
            && isLoggedEventType(TestLogEvent.STANDARD_OUT)) {
        logEvent(descriptor, TestLogEvent.STANDARD_OUT, TextUtil.indent(outputEvent.getMessage(), INDENT) + "\n");
    } else if (outputEvent.getDestination() == TestOutputEvent.Destination.StdErr
            && isLoggedEventType(TestLogEvent.STANDARD_ERROR)) {
        logEvent(descriptor, TestLogEvent.STANDARD_ERROR, TextUtil.indent(outputEvent.getMessage(), INDENT) + "\n");
    }
}
 
Example #7
Source File: TestCountLogger.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void afterSuite(TestDescriptor suite, TestResult result) {
    if (suite.getParent() == null) {
        if (failedTests > 0) {
            logger.error(TextUtil.getPlatformLineSeparator() + summary());
        }
        progressLogger.completed();

        if (result.getResultType() == TestResult.ResultType.FAILURE) {
            hadFailures = true;
        }
    }
}
 
Example #8
Source File: TestEventLogger.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onOutput(TestDescriptor descriptor, TestOutputEvent outputEvent) {
    if (outputEvent.getDestination() == TestOutputEvent.Destination.StdOut
            && isLoggedEventType(TestLogEvent.STANDARD_OUT)) {
        logEvent(descriptor, TestLogEvent.STANDARD_OUT, TextUtil.indent(outputEvent.getMessage(), INDENT) + "\n");
    } else if (outputEvent.getDestination() == TestOutputEvent.Destination.StdErr
            && isLoggedEventType(TestLogEvent.STANDARD_ERROR)) {
        logEvent(descriptor, TestLogEvent.STANDARD_ERROR, TextUtil.indent(outputEvent.getMessage(), INDENT) + "\n");
    }
}
 
Example #9
Source File: AbstractTestLogger.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected void logEvent(TestDescriptor descriptor, TestLogEvent event, @Nullable String details) {
    StyledTextOutput output = textOutputFactory.create("TestEventLogger", logLevel);
    if (!descriptor.equals(lastSeenTestDescriptor) || event != lastSeenTestEvent) {
        output.println().append(getEventPath(descriptor));
        output.withStyle(getStyle(event)).println(event.toString());
    }
    lastSeenTestDescriptor = descriptor;
    lastSeenTestEvent = event;
    if (details != null) {
        output.append(TextUtil.toPlatformLineSeparators(details));
    }
}
 
Example #10
Source File: FullExceptionFormatter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void printException(TestDescriptor descriptor, Throwable exception,
                            @Nullable List<StackTraceElement> parentTrace, int exceptionLevel, StringBuilder builder) {
    String exceptionIndent = Strings.repeat(INDENT, exceptionLevel + 1);
    String exceptionText = exceptionLevel == 0 ? exception.toString() : "\nCaused by:\n" + exception.toString();
    String indentedText = TextUtil.indent(exceptionText, exceptionIndent);
    builder.append(indentedText);
    builder.append('\n');

    String stackTraceIndent = exceptionIndent + INDENT;
    List<StackTraceElement> stackTrace = null;

    if (testLogging.getShowStackTraces()) {
        stackTrace = filterStackTrace(exception, descriptor);
        int commonElements = countCommonElements(stackTrace, parentTrace);
        for (int i = 0; i < stackTrace.size() - commonElements; i++) {
            builder.append(stackTraceIndent);
            builder.append("at ");
            builder.append(stackTrace.get(i));
            builder.append('\n');
        }
        if (commonElements != 0) {
            builder.append(stackTraceIndent);
            builder.append("... ");
            builder.append(commonElements);
            builder.append(" more");
            builder.append('\n');
        }
    }

    if (testLogging.getShowCauses() && exception.getCause() != null) {
        printException(descriptor, exception.getCause(), stackTrace, exceptionLevel + 1, builder);
    }
}
 
Example #11
Source File: FullExceptionFormatter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void printException(TestDescriptor descriptor, Throwable exception,
                            @Nullable List<StackTraceElement> parentTrace, int exceptionLevel, StringBuilder builder) {
    String exceptionIndent = Strings.repeat(INDENT, exceptionLevel + 1);
    String exceptionText = exceptionLevel == 0 ? exception.toString() : "\nCaused by:\n" + exception.toString();
    String indentedText = TextUtil.indent(exceptionText, exceptionIndent);
    builder.append(indentedText);
    builder.append('\n');

    String stackTraceIndent = exceptionIndent + INDENT;
    List<StackTraceElement> stackTrace = null;

    if (testLogging.getShowStackTraces()) {
        stackTrace = filterStackTrace(exception, descriptor);
        int commonElements = countCommonElements(stackTrace, parentTrace);
        for (int i = 0; i < stackTrace.size() - commonElements; i++) {
            builder.append(stackTraceIndent);
            builder.append("at ");
            builder.append(stackTrace.get(i));
            builder.append('\n');
        }
        if (commonElements != 0) {
            builder.append(stackTraceIndent);
            builder.append("... ");
            builder.append(commonElements);
            builder.append(" more");
            builder.append('\n');
        }
    }

    if (testLogging.getShowCauses() && exception.getCause() != null) {
        printException(descriptor, exception.getCause(), stackTrace, exceptionLevel + 1, builder);
    }
}
 
Example #12
Source File: AbstractTestLogger.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected void logEvent(TestDescriptor descriptor, TestLogEvent event, @Nullable String details) {
    StyledTextOutput output = textOutputFactory.create("TestEventLogger", logLevel);
    if (!descriptor.equals(lastSeenTestDescriptor) || event != lastSeenTestEvent) {
        output.println().append(getEventPath(descriptor));
        output.withStyle(getStyle(event)).println(event.toString());
    }
    lastSeenTestDescriptor = descriptor;
    lastSeenTestEvent = event;
    if (details != null) {
        output.append(TextUtil.toPlatformLineSeparators(details));
    }
}
 
Example #13
Source File: TestCountLogger.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void afterSuite(TestDescriptor suite, TestResult result) {
    if (suite.getParent() == null) {
        if (failedTests > 0) {
            logger.error(TextUtil.getPlatformLineSeparator() + summary());
        }
        progressLogger.completed();

        if (result.getResultType() == TestResult.ResultType.FAILURE) {
            hadFailures = true;
        }
    }
}
 
Example #14
Source File: TestEventLogger.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onOutput(TestDescriptor descriptor, TestOutputEvent outputEvent) {
    if (outputEvent.getDestination() == TestOutputEvent.Destination.StdOut
            && isLoggedEventType(TestLogEvent.STANDARD_OUT)) {
        logEvent(descriptor, TestLogEvent.STANDARD_OUT, TextUtil.indent(outputEvent.getMessage(), INDENT) + "\n");
    } else if (outputEvent.getDestination() == TestOutputEvent.Destination.StdErr
            && isLoggedEventType(TestLogEvent.STANDARD_ERROR)) {
        logEvent(descriptor, TestLogEvent.STANDARD_ERROR, TextUtil.indent(outputEvent.getMessage(), INDENT) + "\n");
    }
}
 
Example #15
Source File: AbstractTestLogger.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected void logEvent(TestDescriptor descriptor, TestLogEvent event, @Nullable String details) {
    StyledTextOutput output = textOutputFactory.create("TestEventLogger", logLevel);
    if (!descriptor.equals(lastSeenTestDescriptor) || event != lastSeenTestEvent) {
        output.println().append(getEventPath(descriptor));
        output.withStyle(getStyle(event)).println(event.toString());
    }
    lastSeenTestDescriptor = descriptor;
    lastSeenTestEvent = event;
    if (details != null) {
        output.append(TextUtil.toPlatformLineSeparators(details));
    }
}
 
Example #16
Source File: FullExceptionFormatter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void printException(TestDescriptor descriptor, Throwable exception,
                            @Nullable List<StackTraceElement> parentTrace, int exceptionLevel, StringBuilder builder) {
    String exceptionIndent = Strings.repeat(INDENT, exceptionLevel + 1);
    String exceptionText = exceptionLevel == 0 ? exception.toString() : "\nCaused by:\n" + exception.toString();
    String indentedText = TextUtil.indent(exceptionText, exceptionIndent);
    builder.append(indentedText);
    builder.append('\n');

    String stackTraceIndent = exceptionIndent + INDENT;
    List<StackTraceElement> stackTrace = null;

    if (testLogging.getShowStackTraces()) {
        stackTrace = filterStackTrace(exception, descriptor);
        int commonElements = countCommonElements(stackTrace, parentTrace);
        for (int i = 0; i < stackTrace.size() - commonElements; i++) {
            builder.append(stackTraceIndent);
            builder.append("at ");
            builder.append(stackTrace.get(i));
            builder.append('\n');
        }
        if (commonElements != 0) {
            builder.append(stackTraceIndent);
            builder.append("... ");
            builder.append(commonElements);
            builder.append(" more");
            builder.append('\n');
        }
    }

    if (testLogging.getShowCauses() && exception.getCause() != null) {
        printException(descriptor, exception.getCause(), stackTrace, exceptionLevel + 1, builder);
    }
}
 
Example #17
Source File: FullExceptionFormatter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void printException(TestDescriptor descriptor, Throwable exception,
                            @Nullable List<StackTraceElement> parentTrace, int exceptionLevel, StringBuilder builder) {
    String exceptionIndent = Strings.repeat(INDENT, exceptionLevel + 1);
    String exceptionText = exceptionLevel == 0 ? exception.toString() : "\nCaused by:\n" + exception.toString();
    String indentedText = TextUtil.indent(exceptionText, exceptionIndent);
    builder.append(indentedText);
    builder.append('\n');

    String stackTraceIndent = exceptionIndent + INDENT;
    List<StackTraceElement> stackTrace = null;

    if (testLogging.getShowStackTraces()) {
        stackTrace = filterStackTrace(exception, descriptor);
        int commonElements = countCommonElements(stackTrace, parentTrace);
        for (int i = 0; i < stackTrace.size() - commonElements; i++) {
            builder.append(stackTraceIndent);
            builder.append("at ");
            builder.append(stackTrace.get(i));
            builder.append('\n');
        }
        if (commonElements != 0) {
            builder.append(stackTraceIndent);
            builder.append("... ");
            builder.append(commonElements);
            builder.append(" more");
            builder.append('\n');
        }
    }

    if (testLogging.getShowCauses() && exception.getCause() != null) {
        printException(descriptor, exception.getCause(), stackTrace, exceptionLevel + 1, builder);
    }
}
 
Example #18
Source File: TestEventLogger.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onOutput(TestDescriptor descriptor, TestOutputEvent outputEvent) {
    if (outputEvent.getDestination() == TestOutputEvent.Destination.StdOut
            && isLoggedEventType(TestLogEvent.STANDARD_OUT)) {
        logEvent(descriptor, TestLogEvent.STANDARD_OUT, TextUtil.indent(outputEvent.getMessage(), INDENT) + "\n");
    } else if (outputEvent.getDestination() == TestOutputEvent.Destination.StdErr
            && isLoggedEventType(TestLogEvent.STANDARD_ERROR)) {
        logEvent(descriptor, TestLogEvent.STANDARD_ERROR, TextUtil.indent(outputEvent.getMessage(), INDENT) + "\n");
    }
}
 
Example #19
Source File: TestCountLogger.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void afterSuite(TestDescriptor suite, TestResult result) {
    if (suite.getParent() == null) {
        if (failedTests > 0) {
            logger.error(TextUtil.getPlatformLineSeparator() + summary());
        }
        progressLogger.completed();

        if (result.getResultType() == TestResult.ResultType.FAILURE) {
            hadFailures = true;
        }
    }
}
 
Example #20
Source File: TestCountLogger.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void afterSuite(TestDescriptor suite, TestResult result) {
    if (suite.getParent() == null) {
        if (failedTests > 0) {
            logger.error(TextUtil.getPlatformLineSeparator() + summary());
        }
        progressLogger.completed();

        if (result.getResultType() == TestResult.ResultType.FAILURE) {
            hadFailures = true;
        }
    }
}
 
Example #21
Source File: AbstractTestLogger.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected void logEvent(TestDescriptor descriptor, TestLogEvent event, @Nullable String details) {
    StyledTextOutput output = textOutputFactory.create("TestEventLogger", logLevel);
    if (!descriptor.equals(lastSeenTestDescriptor) || event != lastSeenTestEvent) {
        output.println().append(getEventPath(descriptor));
        output.withStyle(getStyle(event)).println(event.toString());
    }
    lastSeenTestDescriptor = descriptor;
    lastSeenTestEvent = event;
    if (details != null) {
        output.append(TextUtil.toPlatformLineSeparators(details));
    }
}
 
Example #22
Source File: AbstractGradleExecuter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public GradleExecuter withStdIn(String text) {
    this.stdin = new ByteArrayInputStream(TextUtil.toPlatformLineSeparators(text).getBytes());
    return this;
}
 
Example #23
Source File: IvyXmlModuleDescriptorParser.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected void checkErrors() throws ParseException {
    if (!errors.isEmpty()) {
        throw new ParseException(Joiner.on(TextUtil.getPlatformLineSeparator()).join(errors), 0);
    }
}
 
Example #24
Source File: AbstractGradleExecuter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public GradleExecuter withStdIn(String text) {
    this.stdin = new ByteArrayInputStream(TextUtil.toPlatformLineSeparators(text).getBytes());
    return this;
}
 
Example #25
Source File: IvyXmlModuleDescriptorParser.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected void checkErrors() throws ParseException {
    if (!errors.isEmpty()) {
        throw new ParseException(Joiner.on(TextUtil.getPlatformLineSeparator()).join(errors), 0);
    }
}
 
Example #26
Source File: AbstractGradleExecuter.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public GradleExecuter withStdIn(String text) {
    this.stdin = new ByteArrayInputStream(TextUtil.toPlatformLineSeparators(text).getBytes());
    return this;
}
 
Example #27
Source File: IvyXmlModuleDescriptorParser.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected void checkErrors() throws ParseException {
    if (!errors.isEmpty()) {
        throw new ParseException(Joiner.on(TextUtil.getPlatformLineSeparator()).join(errors), 0);
    }
}
 
Example #28
Source File: AbstractGradleExecuter.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public GradleExecuter withStdIn(String text) {
    this.stdin = new ByteArrayInputStream(TextUtil.toPlatformLineSeparators(text).getBytes());
    return this;
}
 
Example #29
Source File: IvyXmlModuleDescriptorParser.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected void checkErrors() throws ParseException {
    if (!errors.isEmpty()) {
        throw new ParseException(Joiner.on(TextUtil.getPlatformLineSeparator()).join(errors), 0);
    }
}