Skip to content

Commit

Permalink
Merge pull request #568 from stephan-herrmann/issue521_core_after_564
Browse files Browse the repository at this point in the history
Remove guava in wikitext
  • Loading branch information
gnl42 authored Jul 14, 2024
2 parents d3f73ee + ae3ce9d commit 61054a0
Show file tree
Hide file tree
Showing 51 changed files with 509 additions and 221 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ Bundle-Vendor: Eclipse Mylyn
Fragment-Host: org.eclipse.mylyn.wikitext.commonmark
Bundle-RequiredExecutionEnvironment: JavaSE-17
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=17))"
Import-Package: com.google.common.escape;version="[33.0,34.0)",
org.apache.commons.lang3;version="[3.14.0,4.0.0)",
Import-Package: org.apache.commons.lang3;version="[3.14.0,4.0.0)",
org.eclipse.mylyn.wikitext.parser;version="[4.2,5)",
org.eclipse.mylyn.wikitext.parser.builder;version="[4.2,5)",
org.eclipse.mylyn.wikitext.parser.builder.event;version="4.4.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void lookAheadFailsFast() {
private void assertLookAheadFailsFast(LineSequence lineSequence) {
LineSequence lookAhead = lineSequence.lookAhead();
lineSequence.advance();
assertThrows(IllegalArgumentException.class, () -> lookAhead.advance());
assertThrows(IllegalStateException.class, () -> lookAhead.advance());
}

private void assertAdvance(LineSequence lineSequence) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.mylyn.wikitext.parser.Locator;
import org.junit.Test;

Expand Down Expand Up @@ -74,7 +73,7 @@ public void toStringTest() {
assertEquals("Line{lineNumber=1, offset=15, text=1}", new Line(1, 15, "1").toString());
assertEquals("Line{lineNumber=2, offset=0, text=\\t\\r\\nabc}", new Line(2, 0, "\t\r\nabc").toString());
assertEquals("Line{lineNumber=0, offset=0, text=aaaaaaaaaaaaaaaaaaaa...}",
new Line(0, 0, StringUtils.repeat("a", 100)).toString());
new Line(0, 0, "a".repeat(100)).toString());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.junit.Test;

@SuppressWarnings("nls")
Expand Down Expand Up @@ -87,7 +86,7 @@ public void toStringTest() {
assertEquals("TextSegment{text=one\ntwo\nthree four}",
new TextSegment(createLines("one\ntwo\r\nthree four")).toString());
assertEquals("TextSegment{text=0123456789012345678901234567890123456789}",
new TextSegment(createLines(StringUtils.repeat("0123456789", 4))).toString());
new TextSegment(createLines("0123456789".repeat(4))).toString());
}

private Iterable<Line> createLines(String content) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import static org.junit.Assert.assertEquals;

import org.apache.commons.lang3.StringUtils;
import org.junit.Test;

@SuppressWarnings("nls")
Expand All @@ -27,7 +26,7 @@ public void toStringValue() {
assertEquals(null, ToStringHelper.toStringValue(null));
assertEquals("", ToStringHelper.toStringValue(""));
assertEquals("abc", ToStringHelper.toStringValue("abc"));
assertEquals("01234567890123456789...", ToStringHelper.toStringValue(StringUtils.repeat("0123456789", 10)));
assertEquals("01234567890123456789...", ToStringHelper.toStringValue("0123456789".repeat(10)));
assertEquals("a\\r\\n\\tb", ToStringHelper.toStringValue("a\r\n\tb"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.mylyn.wikitext.commonmark.internal.LineSequence;
import org.junit.Test;

Expand All @@ -34,14 +33,14 @@ public void canStart() {
assertFalse(block.canStart(LineSequence.create("a")));
assertFalse(block.canStart(LineSequence.create(" ***")));
for (char c : "*_-".toCharArray()) {
String hrIndicator = StringUtils.repeat("" + c, 3);
String hrIndicator = String.valueOf(c).repeat(3);
assertTrue(block.canStart(LineSequence.create(" " + hrIndicator)));
assertTrue(block.canStart(LineSequence.create(" " + hrIndicator)));
assertTrue(block.canStart(LineSequence.create(" " + hrIndicator)));
assertFalse(block.canStart(LineSequence.create(" " + hrIndicator)));
assertTrue(block.canStart(LineSequence.create(hrIndicator)));
assertTrue(block.canStart(LineSequence.create(StringUtils.repeat("" + c, 4))));
assertTrue(block.canStart(LineSequence.create(StringUtils.repeat("" + c, 14))));
assertTrue(block.canStart(LineSequence.create(String.valueOf(c).repeat(4))));
assertTrue(block.canStart(LineSequence.create(String.valueOf(c).repeat(14))));
}

// Bug 472390:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
import org.eclipse.mylyn.wikitext.commonmark.internal.Line;
import org.junit.Test;

import com.google.common.escape.Escaper;
import com.google.common.net.UrlEscapers;

@SuppressWarnings("nls")
public class PotentialBracketEndDelimiterTest {

Expand Down Expand Up @@ -168,19 +165,18 @@ public void eligibleForReferenceDefinitionLinkIndented() {
@Test
public void replaceHtmlEntities() {
PotentialBracketEndDelimiter delimiter = new PotentialBracketEndDelimiter(line, 0);
Escaper escaper = UrlEscapers.urlFormParameterEscaper();
assertEquals("asf", delimiter.replaceHtmlEntities("asf", escaper));
assertEquals("&amp", delimiter.replaceHtmlEntities("&amp", escaper));
assertEquals("&amp ;", delimiter.replaceHtmlEntities("&amp ;", escaper));
assertEquals("%26", delimiter.replaceHtmlEntities("&amp;", escaper));
assertEquals("a%26", delimiter.replaceHtmlEntities("a&amp;", escaper));
assertEquals("a%26b", delimiter.replaceHtmlEntities("a&amp;b", escaper));
assertEquals("%C3%A4", delimiter.replaceHtmlEntities("&auml;", escaper));
assertEquals("&", delimiter.replaceHtmlEntities("&amp;", null));
assertEquals("\"", delimiter.replaceHtmlEntities("&quot;", null));
assertEquals("\u00e4", delimiter.replaceHtmlEntities("&auml;", null));
assertEquals("&xdfsldk;", delimiter.replaceHtmlEntities("&xdfsldk;", null));
assertEquals("&0;", delimiter.replaceHtmlEntities("&0;", null));
assertEquals("asf", delimiter.replaceHtmlEntities("asf", true));
assertEquals("&amp", delimiter.replaceHtmlEntities("&amp", true));
assertEquals("&amp ;", delimiter.replaceHtmlEntities("&amp ;", true));
assertEquals("%26", delimiter.replaceHtmlEntities("&amp;", true));
assertEquals("a%26", delimiter.replaceHtmlEntities("a&amp;", true));
assertEquals("a%26b", delimiter.replaceHtmlEntities("a&amp;b", true));
assertEquals("%C3%A4", delimiter.replaceHtmlEntities("&auml;", true));
assertEquals("&", delimiter.replaceHtmlEntities("&amp;", false));
assertEquals("\"", delimiter.replaceHtmlEntities("&quot;", false));
assertEquals("\u00e4", delimiter.replaceHtmlEntities("&auml;", false));
assertEquals("&xdfsldk;", delimiter.replaceHtmlEntities("&xdfsldk;", false));
assertEquals("&0;", delimiter.replaceHtmlEntities("&0;", false));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class CommonMarkSpecTest {
4425, // Lists
4664, // Lists
4681 // Lists
, 6700 // TODO
);

public static class Expectation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ Bundle-Name: Mylyn WikiText CommonMark
Bundle-Vendor: Eclipse Mylyn
Bundle-RequiredExecutionEnvironment: JavaSE-17
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=17))"
Import-Package: com.google.common.base;version="[33.0,34.0)",
com.google.common.escape;version="[33.0,34.0)",
com.google.common.net;version="[33.2.0,34.0.0)",
org.apache.commons.io;version="[2.16.0,3.0.0)",
org.apache.commons.lang3;version="[3.14.0,4.0.0)",
Import-Package: org.apache.commons.io;version="[2.16.0,3.0.0)",
org.apache.commons.lang3.builder;version="[3.14.0,4.0.0)",
org.eclipse.mylyn.wikitext.parser;version="[4.2,5)",
org.eclipse.mylyn.wikitext.parser.builder;version="[4.2,5)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,14 @@
import java.util.Locale;

import org.eclipse.mylyn.wikitext.parser.markup.IdGenerationStrategy;

import com.google.common.base.CharMatcher;
import org.eclipse.mylyn.wikitext.util.IDStrategies;

public class CommonMarkIdGenerationStrategy extends IdGenerationStrategy {

private final CharMatcher hyphenMatcher = CharMatcher.is('-');

@Override
public String generateId(String headingText) {
String id = headingText.toLowerCase(Locale.ENGLISH).replaceAll("[^a-z0-9_]", "-"); //$NON-NLS-1$//$NON-NLS-2$
id = hyphenMatcher.trimAndCollapseFrom(id, '-');
return id;
String id = headingText.toLowerCase(Locale.ENGLISH);
return IDStrategies.computeID(id);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@

package org.eclipse.mylyn.wikitext.commonmark.internal;

import static org.eclipse.mylyn.wikitext.util.Preconditions.checkArgument;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import org.apache.commons.lang3.Validate;
import org.eclipse.mylyn.wikitext.commonmark.internal.LineSequence.ForwardLineSequence;
import org.eclipse.mylyn.wikitext.util.LocationTrackingReader;

Expand Down Expand Up @@ -62,7 +63,7 @@ public Line getNextLine() {

@Override
Line getNextLine(int index) {
Validate.isTrue(index >= 0);
checkArgument(index >= 0);
while (followingLines.size() <= index) {
Line line = readLine();
if (line == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@

package org.eclipse.mylyn.wikitext.commonmark.internal;

import static org.eclipse.mylyn.wikitext.util.Preconditions.checkArgument;

import java.util.Objects;

import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.eclipse.mylyn.wikitext.parser.Locator;
import org.eclipse.mylyn.wikitext.util.Strings;
import org.eclipse.mylyn.wikitext.util.WikiToStringStyle;

import com.google.common.base.CharMatcher;

public class Line {

private final String text;
Expand All @@ -33,15 +33,15 @@ public class Line {
private final int lineNumber;

public Line(int lineNumber, int offset, String text) {
Validate.isTrue(offset >= 0);
Validate.isTrue(lineNumber >= 0);
checkArgument(offset >= 0);
checkArgument(lineNumber >= 0);
this.lineNumber = lineNumber;
this.offset = offset;
this.text = Objects.requireNonNull(text);
}

public boolean isEmpty() {
return !CharMatcher.whitespace().negate().matchesAnyOf(text);
return Strings.isBlank(text);
}

public String getText() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

package org.eclipse.mylyn.wikitext.commonmark.internal;

import static org.eclipse.mylyn.wikitext.util.Preconditions.checkArgument;

import java.util.Iterator;
import java.util.function.Function;
import java.util.function.Predicate;

import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.eclipse.mylyn.wikitext.util.WikiToStringStyle;

Expand All @@ -41,7 +41,7 @@ public static LineSequence create(String content) {
public abstract void advance();

public void advance(int count) {
Validate.isTrue(count >= 0);
checkArgument(count >= 0);
for (int x = 0; x < count; ++x) {
advance();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

package org.eclipse.mylyn.wikitext.commonmark.internal;

import org.apache.commons.lang3.Validate;
import static org.eclipse.mylyn.wikitext.util.Preconditions.checkState;

class LookAheadLineSequence extends LineSequence {

Expand Down Expand Up @@ -59,7 +59,7 @@ public void advance() {
}

private void checkConcurrentModification() {
Validate.isTrue(referenceLine == lineSequence.getCurrentLine());
checkState(referenceLine == lineSequence.getCurrentLine());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
import java.util.Locale;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.mylyn.wikitext.commonmark.internal.ProcessingContext.NamedUriWithTitle;
import org.eclipse.mylyn.wikitext.commonmark.internal.inlines.InlineParser;
import org.eclipse.mylyn.wikitext.parser.IdGenerator;
import org.eclipse.mylyn.wikitext.parser.markup.IdGenerationStrategy;
import org.eclipse.mylyn.wikitext.util.Strings;

public class ProcessingContextBuilder {

Expand All @@ -33,7 +33,7 @@ public class ProcessingContextBuilder {
private InlineParser inlineParser;

public ProcessingContextBuilder referenceDefinition(String name, String href, String title) {
if (StringUtils.isNotEmpty(name)) {
if (!Strings.isNullOrEmpty(name)) {
String key = name.toLowerCase(Locale.ROOT);
if (!linkByName.containsKey(key)) {
linkByName.put(key, new NamedUriWithTitle(name, href, title));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
package org.eclipse.mylyn.wikitext.commonmark.internal;

import static java.util.Objects.requireNonNull;
import static org.eclipse.mylyn.wikitext.util.Preconditions.checkArgument;

import java.util.List;
import java.util.stream.StreamSupport;

import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.eclipse.mylyn.wikitext.util.WikiToStringStyle;

Expand Down Expand Up @@ -55,7 +54,7 @@ public List<Line> getLines() {
}

public int offsetOf(int textOffset) {
Validate.isTrue(textOffset >= 0);
checkArgument(textOffset >= 0);
int textOffsetOfLine = 0;
int remainder = textOffset;
for (Line line : lines) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@

package org.eclipse.mylyn.wikitext.commonmark.internal.blocks;

import static org.eclipse.mylyn.wikitext.util.Preconditions.checkState;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.Validate;
import org.eclipse.mylyn.wikitext.commonmark.internal.Line;
import org.eclipse.mylyn.wikitext.commonmark.internal.LineSequence;
import org.eclipse.mylyn.wikitext.commonmark.internal.ProcessingContext;
Expand All @@ -39,7 +40,7 @@ public void process(ProcessingContext context, DocumentBuilder builder, LineSequ

if (firstLine.equals(line)) {
Matcher matcher = startPattern().matcher(lineText);
Validate.isTrue(matcher.matches());
checkState(matcher.matches());
int offset = matcher.end(1);
if (offset < lineText.length() - 1) {
Matcher closeMatcher = closePattern().matcher(lineText);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@

package org.eclipse.mylyn.wikitext.commonmark.internal.blocks;

import static org.eclipse.mylyn.wikitext.util.Preconditions.checkState;

import java.util.Collections;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.Validate;
import org.eclipse.mylyn.wikitext.commonmark.internal.Line;
import org.eclipse.mylyn.wikitext.commonmark.internal.LineSequence;
import org.eclipse.mylyn.wikitext.commonmark.internal.ProcessingContext;
Expand All @@ -37,7 +38,7 @@ public class AtxHeaderBlock extends SourceBlock {
public void process(ProcessingContext context, DocumentBuilder builder, LineSequence lineSequence) {
Line currentLine = lineSequence.getCurrentLine();
Matcher matcher = PATTERN.matcher(currentLine.getText());
Validate.isTrue(matcher.matches());
checkState(matcher.matches());

lineSequence.advance();

Expand Down
Loading

0 comments on commit 61054a0

Please sign in to comment.