aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-channel/src/main/java
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2014-03-14 22:13:57 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2014-03-14 22:13:57 +0100
commitbeaaed4bc33977b4c61013a553563758eeff35c4 (patch)
treec59a8b972c34bde84a69895acde9d34fda73949a /sonar-channel/src/main/java
parent9509868d743145761211e1ce74c26f01057cc67f (diff)
downloadsonarqube-beaaed4bc33977b4c61013a553563758eeff35c4.tar.gz
sonarqube-beaaed4bc33977b4c61013a553563758eeff35c4.zip
SONAR-5128 Package a release version of sonar-channel
Diffstat (limited to 'sonar-channel/src/main/java')
-rw-r--r--sonar-channel/src/main/java/org/sonar/channel/Channel.java35
-rw-r--r--sonar-channel/src/main/java/org/sonar/channel/ChannelCodeReaderFilter.java99
-rw-r--r--sonar-channel/src/main/java/org/sonar/channel/ChannelDispatcher.java141
-rw-r--r--sonar-channel/src/main/java/org/sonar/channel/ChannelException.java36
-rw-r--r--sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java267
-rw-r--r--sonar-channel/src/main/java/org/sonar/channel/CodeReader.java209
-rw-r--r--sonar-channel/src/main/java/org/sonar/channel/CodeReaderConfiguration.java108
-rw-r--r--sonar-channel/src/main/java/org/sonar/channel/CodeReaderFilter.java131
-rw-r--r--sonar-channel/src/main/java/org/sonar/channel/EndMatcher.java25
-rw-r--r--sonar-channel/src/main/java/org/sonar/channel/RegexChannel.java64
-rw-r--r--sonar-channel/src/main/java/org/sonar/channel/package-info.java41
11 files changed, 0 insertions, 1156 deletions
diff --git a/sonar-channel/src/main/java/org/sonar/channel/Channel.java b/sonar-channel/src/main/java/org/sonar/channel/Channel.java
deleted file mode 100644
index a88a55130f4..00000000000
--- a/sonar-channel/src/main/java/org/sonar/channel/Channel.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.channel;
-
-public abstract class Channel<O> {
-
- /**
- * Tries to consume the character stream at the current reading cursor position (provided by the {@link org.sonar.channel.CodeReader}). If
- * the character stream is consumed the method must return true and the OUTPUT object can be fed.
- *
- * @param code
- * the handle on the input character stream
- * @param output
- * the OUTPUT that can be optionally fed by the Channel
- * @return false if the Channel doesn't want to consume the character stream, true otherwise.
- */
- public abstract boolean consume(CodeReader code, O output);
-}
diff --git a/sonar-channel/src/main/java/org/sonar/channel/ChannelCodeReaderFilter.java b/sonar-channel/src/main/java/org/sonar/channel/ChannelCodeReaderFilter.java
deleted file mode 100644
index 8db1236b6ca..00000000000
--- a/sonar-channel/src/main/java/org/sonar/channel/ChannelCodeReaderFilter.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.channel;
-
-import java.io.IOException;
-import java.io.Reader;
-
-/**
- * This class is a special CodeReaderFilter that uses Channels to filter the character stream before it is passed to the main channels
- * declared for the CodeReader.
- *
- */
-public final class ChannelCodeReaderFilter<O> extends CodeReaderFilter<O> {
-
- @SuppressWarnings("unchecked")
- private Channel<O>[] channels = new Channel[0];
-
- private CodeReader internalCodeReader;
-
- /**
- * Creates a CodeReaderFilter that will use the provided Channels to filter the character stream it gets from its reader.
- *
- * @param channels
- * the different channels
- */
- public ChannelCodeReaderFilter(Channel<O>... channels) {
- super();
- this.channels = channels;
- }
-
- /**
- * Creates a CodeReaderFilter that will use the provided Channels to filter the character stream it gets from its reader. And optionally,
- * it can push token to the provided output object.
- *
- * @param output
- * the object that may accept tokens
- * @param channels
- * the different channels
- */
- public ChannelCodeReaderFilter(O output, Channel<O>... channels) {
- super(output);
- this.channels = channels;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void setReader(Reader reader) {
- super.setReader(reader);
- internalCodeReader = new CodeReader(reader, getConfiguration());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int read(char[] filteredBuffer, int offset, int length) throws IOException {
- if (internalCodeReader.peek() == -1) {
- return -1;
- }
- int initialOffset = offset;
- while (offset < filteredBuffer.length) {
- if (internalCodeReader.peek() == -1) {
- break;
- }
- boolean consumed = false;
- for (Channel<O> channel : channels) {
- if (channel.consume(internalCodeReader, getOutput())) {
- consumed = true;
- break;
- }
- }
- if ( !consumed) {
- int charRead = internalCodeReader.pop();
- filteredBuffer[offset++] = (char) charRead;
- }
- }
- return offset - initialOffset;
- }
-
-}
diff --git a/sonar-channel/src/main/java/org/sonar/channel/ChannelDispatcher.java b/sonar-channel/src/main/java/org/sonar/channel/ChannelDispatcher.java
deleted file mode 100644
index ebb1f218b58..00000000000
--- a/sonar-channel/src/main/java/org/sonar/channel/ChannelDispatcher.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.channel;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class ChannelDispatcher<O> extends Channel<O> {
-
- private static final Logger LOG = LoggerFactory.getLogger(ChannelDispatcher.class);
- private final boolean failIfNoChannelToConsumeOneCharacter;
-
- private final Channel<O>[] channels;
-
- /**
- * @deprecated in version 2.9. Please use the builder() method
- */
- @SuppressWarnings("rawtypes")
- @Deprecated
- public ChannelDispatcher(List<Channel> channels) {
- this(channels, false);
- }
-
- /**
- * @deprecated in version 2.9. Please use the builder() method
- */
- @SuppressWarnings("rawtypes")
- @Deprecated
- public ChannelDispatcher(Channel... channels) {
- this(Arrays.asList(channels), false);
- }
-
- /**
- * @deprecated in version 2.9. Please use the builder() method
- */
- @SuppressWarnings("rawtypes")
- @Deprecated
- public ChannelDispatcher(List<Channel> channels, boolean failIfNoChannelToConsumeOneCharacter) {
- this.channels = channels.toArray(new Channel[channels.size()]);
- this.failIfNoChannelToConsumeOneCharacter = failIfNoChannelToConsumeOneCharacter;
- }
-
- private ChannelDispatcher(Builder builder) {
- this.channels = builder.channels.toArray(new Channel[builder.channels.size()]);
- this.failIfNoChannelToConsumeOneCharacter = builder.failIfNoChannelToConsumeOneCharacter;
- }
-
- @Override
- public boolean consume(CodeReader code, O output) {
- int nextChar = code.peek();
- while (nextChar != -1) {
- boolean characterConsumed = false;
- for (Channel<O> channel : channels) {
- if (channel.consume(code, output)) {
- characterConsumed = true;
- break;
- }
- }
- if ( !characterConsumed) {
- if (LOG.isDebugEnabled() || failIfNoChannelToConsumeOneCharacter) {
- String message = "None of the channel has been able to handle character '" + (char) code.peek() + "' (decimal value "
- + code.peek() + ") at line " + code.getLinePosition() + ", column " + code.getColumnPosition();
- if (failIfNoChannelToConsumeOneCharacter) {
- throw new IllegalStateException(message);
- }
- LOG.debug(message);
- }
- code.pop();
- }
- nextChar = code.peek();
- }
- return true;
- }
-
- Channel[] getChannels() {
- return channels;
- }
-
- /**
- * Get a Builder instance to build a new ChannelDispatcher
- */
- public static Builder builder() {
- return new Builder();
- }
-
- public static final class Builder {
-
- private List<Channel> channels = new ArrayList<Channel>();
- private boolean failIfNoChannelToConsumeOneCharacter = false;
-
- private Builder() {
- }
-
- public Builder addChannel(Channel channel) {
- channels.add(channel);
- return this;
- }
-
- public Builder addChannels(Channel... c) {
- for (Channel channel : c) {
- addChannel(channel);
- }
- return this;
- }
-
- /**
- * If this option is activated, an IllegalStateException will be thrown as soon as a character won't be consumed by any channel.
- */
- public Builder failIfNoChannelToConsumeOneCharacter() {
- failIfNoChannelToConsumeOneCharacter = true;
- return this;
- }
-
- public <O> ChannelDispatcher<O> build() {
- return new ChannelDispatcher<O>(this);
- }
-
- }
-}
diff --git a/sonar-channel/src/main/java/org/sonar/channel/ChannelException.java b/sonar-channel/src/main/java/org/sonar/channel/ChannelException.java
deleted file mode 100644
index 67293e02435..00000000000
--- a/sonar-channel/src/main/java/org/sonar/channel/ChannelException.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.channel;
-
-public class ChannelException extends RuntimeException {
-
- public ChannelException(String message, Exception cause) {
- super(message, cause);
- }
-
- public ChannelException(String message) {
- super(message);
- }
-
- public ChannelException(String message, Throwable cause) {
- super(message, cause);
- }
-
-}
diff --git a/sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java b/sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java
deleted file mode 100644
index a4ff4ba3a51..00000000000
--- a/sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java
+++ /dev/null
@@ -1,267 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.channel;
-
-import java.io.FilterReader;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-
-import org.apache.commons.io.IOUtils;
-
-/**
- * The CodeBuffer class provides all the basic features required to manipulate a source code character stream. Those features are :
- * <ul>
- * <li>Read and consume next source code character : pop()</li>
- * <li>Retrieve last consumed character : lastChar()</li>
- * <li>Read without consuming next source code character : peek()</li>
- * <li>Read without consuming character at the specified index after the cursor</li>
- * <li>Position of the pending cursor : line and column</li>
- * </ul>
- */
-public class CodeBuffer implements CharSequence {
-
- private int lastChar = -1;
- private Cursor cursor;
- private char[] buffer;
- private int bufferPosition = 0;
- private static final char LF = '\n';
- private static final char CR = '\r';
- private int tabWidth;
-
- private boolean recordingMode = false;
- private StringBuilder recordedCharacters = new StringBuilder();
-
- protected CodeBuffer(String code, CodeReaderConfiguration configuration) {
- this(new StringReader(code), configuration);
- }
-
- /**
- * Note that this constructor will read everything from reader and will close it.
- */
- protected CodeBuffer(Reader initialCodeReader, CodeReaderConfiguration configuration) {
- Reader reader = null;
-
- try {
- lastChar = -1;
- cursor = new Cursor();
- tabWidth = configuration.getTabWidth();
-
- /* Setup the filters on the reader */
- reader = initialCodeReader;
- for (CodeReaderFilter<?> codeReaderFilter : configuration.getCodeReaderFilters()) {
- reader = new Filter(reader, codeReaderFilter, configuration);
- }
-
- buffer = IOUtils.toCharArray(reader);
- } catch (IOException e) {
- throw new ChannelException(e.getMessage(), e);
- } finally {
- IOUtils.closeQuietly(reader);
- }
- }
-
- /**
- * Read and consume the next character
- *
- * @return the next character or -1 if the end of the stream is reached
- */
- public final int pop() {
- if (bufferPosition >= buffer.length) {
- return -1;
- }
- int character = buffer[bufferPosition++];
- updateCursorPosition(character);
- if (recordingMode) {
- recordedCharacters.append((char)character);
- }
- lastChar = character;
- return character;
- }
-
- private void updateCursorPosition(int character) {
- // see Java Language Specification : http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.4
- if (character == LF || (character == CR && peek() != LF)) {
- cursor.line++;
- cursor.column = 0;
- } else if (character == '\t') {
- cursor.column += tabWidth;
- } else {
- cursor.column++;
- }
- }
-
- /**
- * Looks at the last consumed character
- *
- * @return the last character or -1 if the no character has been yet consumed
- */
- public final int lastChar() {
- return lastChar;
- }
-
- /**
- * Looks at the next character without consuming it
- *
- * @return the next character or -1 if the end of the stream has been reached
- */
- public final int peek() {
- return intAt(0);
- }
-
- /**
- * @return the current line of the cursor
- */
- public final int getLinePosition() {
- return cursor.line;
- }
-
- public final Cursor getCursor() {
- return cursor;
- }
-
- /**
- * @return the current column of the cursor
- */
- public final int getColumnPosition() {
- return cursor.column;
- }
-
- /**
- * Overrides the current column position
- */
- public final CodeBuffer setColumnPosition(int cp) {
- this.cursor.column = cp;
- return this;
- }
-
- /**
- * Overrides the current line position
- */
- public final void setLinePosition(int lp) {
- this.cursor.line = lp;
- }
-
- public final void startRecording() {
- recordingMode = true;
- }
-
- public final CharSequence stopRecording() {
- recordingMode = false;
- CharSequence result = recordedCharacters;
- recordedCharacters = new StringBuilder();
- return result;
- }
-
- /**
- * Returns the character at the specified index after the cursor without consuming it
- *
- * @param index
- * the relative index of the character to be returned
- * @return the desired character
- * @see java.lang.CharSequence#charAt(int)
- */
- public final char charAt(int index) {
- return (char)intAt(index);
- }
-
- protected final int intAt(int index) {
- if (bufferPosition + index >= buffer.length) {
- return -1;
- }
- return buffer[bufferPosition + index];
- }
-
- /**
- * Returns the relative length of the string (i.e. excluding the popped chars)
- */
- public final int length() {
- return buffer.length - bufferPosition;
- }
-
- public final CharSequence subSequence(int start, int end) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public final String toString() {
- StringBuilder result = new StringBuilder();
- result.append("CodeReader(");
- result.append("line:").append(cursor.line);
- result.append("|column:").append(cursor.column);
- result.append("|cursor value:'").append((char) peek()).append("'");
- result.append(")");
- return result.toString();
- }
-
- public final class Cursor implements Cloneable {
-
- private int line = 1;
- private int column = 0;
-
- public int getLine() {
- return line;
- }
-
- public int getColumn() {
- return column;
- }
-
- @Override
- public Cursor clone() {
- Cursor clone = new Cursor();
- clone.column = column;
- clone.line = line;
- return clone;
- }
- }
-
- /**
- * Bridge class between CodeBuffer and CodeReaderFilter
- */
- static final class Filter extends FilterReader {
-
- private CodeReaderFilter<?> codeReaderFilter;
-
- public Filter(Reader in, CodeReaderFilter<?> codeReaderFilter, CodeReaderConfiguration configuration) {
- super(in);
- this.codeReaderFilter = codeReaderFilter;
- this.codeReaderFilter.setConfiguration(configuration.cloneWithoutCodeReaderFilters());
- this.codeReaderFilter.setReader(in);
- }
-
- @Override
- public int read() throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public int read(char[] cbuf, int off, int len) throws IOException {
- int read = codeReaderFilter.read(cbuf, off, len);
- return read == 0 ? -1 : read;
- }
-
- @Override
- public long skip(long n) throws IOException {
- throw new UnsupportedOperationException();
- }
-
- }
-}
diff --git a/sonar-channel/src/main/java/org/sonar/channel/CodeReader.java b/sonar-channel/src/main/java/org/sonar/channel/CodeReader.java
deleted file mode 100644
index 5fdf1ee0a55..00000000000
--- a/sonar-channel/src/main/java/org/sonar/channel/CodeReader.java
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.channel;
-
-import java.io.IOException;
-import java.io.Reader;
-import java.util.regex.Matcher;
-
-/**
- * The CodeReader class provides some advanced features to read a source code. The most important one is the ability to try consuming the
- * next characters in the stream according to a regular expression.
- */
-public class CodeReader extends CodeBuffer {
-
- private Cursor previousCursor;
-
- /*
- * Constructor needed to be backward compatible (before using CodeReaderFilter)
- */
- public CodeReader(Reader code) {
- super(code, new CodeReaderConfiguration());
- }
-
- /*
- * Constructor needed to be backward compatible (before using CodeReaderFilter)
- */
- public CodeReader(String code) {
- super(code, new CodeReaderConfiguration());
- }
-
- /**
- * Creates a code reader with specific configuration parameters.
- * Note that this constructor will read everything from reader and will close it.
- *
- * @param code
- * the Reader to read code from
- * @param configuration
- * the configuration parameters
- */
- public CodeReader(Reader code, CodeReaderConfiguration configuration) {
- super(code, configuration);
- }
-
- /**
- * Creates a code reader with specific configuration parameters.
- *
- * @param code
- * the code itself
- * @param configuration
- * the configuration parameters
- */
- public CodeReader(String code, CodeReaderConfiguration configuration) {
- super(code, configuration);
- }
-
- /**
- * Read and consume the next character
- *
- * @param appendable
- * the read character is appended to appendable
- */
- public final void pop(Appendable appendable) {
- try {
- appendable.append((char) pop());
- } catch (IOException e) {
- throw new ChannelException(e.getMessage(), e);
- }
- }
-
- /**
- * Read without consuming the next characters
- *
- * @param length
- * number of character to read
- * @return array of characters
- */
- public final char[] peek(int length) {
- char[] result = new char[length];
- int index = 0;
- int nextChar = intAt(index);
- while (nextChar != -1 && index < length) {
- result[index] = (char) nextChar;
- nextChar = intAt(++index);
- }
- return result;
- }
-
- /**
- * Read without consuming the next characters until a condition is reached (EndMatcher)
- *
- * @param matcher
- * the EndMatcher used to stop the reading
- * @param appendable
- * the read characters is appended to appendable
- */
- public final void peekTo(EndMatcher matcher, Appendable appendable) {
- int index = 0;
- char nextChar = charAt(index);
- try {
- while (!matcher.match(nextChar) && nextChar != -1) {
- appendable.append(nextChar);
- nextChar = charAt(++index);
- }
- } catch (IOException e) {
- throw new ChannelException(e.getMessage(), e);
- }
- }
-
- /**
- * @deprecated in 2.2, use {@link #peekTo(EndMatcher matcher, Appendable appendable)} instead
- */
- @Deprecated
- public final String peekTo(EndMatcher matcher) {
- StringBuilder sb = new StringBuilder();
- peekTo(matcher, sb);
- return sb.toString();
- }
-
- /**
- * @deprecated in 2.2, use {@link #popTo(Matcher matcher, Appendable appendable)} instead
- */
- @Deprecated
- public final void popTo(EndMatcher matcher, Appendable appendable) {
- previousCursor = getCursor().clone();
- try {
- do {
- appendable.append((char) pop());
- } while (!matcher.match(peek()) && peek() != -1);
- } catch (IOException e) {
- throw new ChannelException(e.getMessage(), e);
- }
- }
-
- /**
- * Read and consume the next characters according to a given regular expression
- *
- * @param matcher
- * the regular expression matcher
- * @param appendable
- * the consumed characters are appended to this appendable
- * @return number of consumed characters or -1 if the next input sequence doesn't match this matcher's pattern
- */
- public final int popTo(Matcher matcher, Appendable appendable) {
- return popTo(matcher, null, appendable);
- }
-
- /**
- * Read and consume the next characters according to a given regular expression. Moreover the character sequence immediately following the
- * desired characters must also match a given regular expression.
- *
- * @param matcher
- * the Matcher used to try consuming next characters
- * @param afterMatcher
- * the Matcher used to check character sequence immediately following the consumed characters
- * @param appendable
- * the consumed characters are appended to this appendable
- * @return number of consumed characters or -1 if one of the two Matchers doesn't match
- */
- public final int popTo(Matcher matcher, Matcher afterMatcher, Appendable appendable) {
- try {
- matcher.reset(this);
- if (matcher.lookingAt()) {
- if (afterMatcher != null) {
- afterMatcher.reset(this);
- afterMatcher.region(matcher.end(), length());
- if (!afterMatcher.lookingAt()) {
- return -1;
- }
- }
- previousCursor = getCursor().clone();
- for (int i = 0; i < matcher.end(); i++) {
- appendable.append((char) pop());
- }
- return matcher.end();
- }
- } catch (StackOverflowError e) {
- throw new ChannelException("Unable to apply regular expression '" + matcher.pattern().pattern()
- + "' at line " + getCursor().getLine() + " and column " + getCursor().getColumn()
- + ", because it led to a stack overflow error."
- + " This error may be due to an inefficient use of alternations - see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5050507", e);
- } catch (IndexOutOfBoundsException e) {
- return -1;
- } catch (IOException e) {
- throw new ChannelException(e.getMessage(), e);
- }
- return -1;
- }
-
- public final Cursor getPreviousCursor() {
- return previousCursor;
- }
-}
diff --git a/sonar-channel/src/main/java/org/sonar/channel/CodeReaderConfiguration.java b/sonar-channel/src/main/java/org/sonar/channel/CodeReaderConfiguration.java
deleted file mode 100644
index 25fbff974b9..00000000000
--- a/sonar-channel/src/main/java/org/sonar/channel/CodeReaderConfiguration.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.channel;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * Configuration parameters used by a CodeReader to handle some specificities.
- */
-public class CodeReaderConfiguration {
-
- /**
- * @deprecated in 2.12, do not use anymore.
- */
- @Deprecated
- public static final int DEFAULT_BUFFER_CAPACITY = 8000;
-
- public static final int DEFAULT_TAB_WIDTH = 1;
-
- private int tabWidth = DEFAULT_TAB_WIDTH;
-
- private List<CodeReaderFilter<?>> codeReaderFilters = new ArrayList<CodeReaderFilter<?>>();
-
- /**
- * @deprecated in 2.12, do not use anymore.
- * @return the constant Integer.MAX_VALUE
- */
- @Deprecated
- public int getBufferCapacity() {
- return Integer.MAX_VALUE;
- }
-
- /**
- * @deprecated in 2.12, do not use anymore.
- * @param bufferCapacity
- * the bufferCapacity to set
- */
- @Deprecated
- public void setBufferCapacity(int bufferCapacity) {
- }
-
- /**
- * @return the tabWidth
- */
- public int getTabWidth() {
- return tabWidth;
- }
-
- /**
- * @param tabWidth
- * the tabWidth to set
- */
- public void setTabWidth(int tabWidth) {
- this.tabWidth = tabWidth;
- }
-
- /**
- * @return the codeReaderFilters
- */
- @SuppressWarnings("rawtypes")
- public CodeReaderFilter[] getCodeReaderFilters() {
- return codeReaderFilters.toArray(new CodeReaderFilter[codeReaderFilters.size()]);
- }
-
- /**
- * @param codeReaderFilters
- * the codeReaderFilters to set
- */
- public void setCodeReaderFilters(CodeReaderFilter<?>... codeReaderFilters) {
- this.codeReaderFilters = new ArrayList<CodeReaderFilter<?>>(Arrays.asList(codeReaderFilters));
- }
-
- /**
- * Adds a code reader filter
- *
- * @param codeReaderFilter
- * the codeReaderFilter to add
- */
- public void addCodeReaderFilters(CodeReaderFilter<?> codeReaderFilter) {
- this.codeReaderFilters.add(codeReaderFilter);
- }
-
- public CodeReaderConfiguration cloneWithoutCodeReaderFilters() {
- CodeReaderConfiguration clone = new CodeReaderConfiguration();
- clone.setTabWidth(tabWidth);
- return clone;
- }
-
-}
diff --git a/sonar-channel/src/main/java/org/sonar/channel/CodeReaderFilter.java b/sonar-channel/src/main/java/org/sonar/channel/CodeReaderFilter.java
deleted file mode 100644
index 676f2814606..00000000000
--- a/sonar-channel/src/main/java/org/sonar/channel/CodeReaderFilter.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.channel;
-
-import java.io.IOException;
-import java.io.Reader;
-
-/**
- * This class can be extended to provide filtering capabilities for the CodeReader class. <br>
- * The purpose is to filter the character flow before the CodeReader class passes it to the different channels. It is possible to give
- * several filters to a CodeReader: they will be called one after another, following the declaration order in the CodeReader constructor, to
- * sequentially filter the character flow.
- *
- * @see CodeReader
- * @see CodeBufferTest#testCodeReaderFilter()
- * @see CodeBufferTest#testSeveralCodeReaderFilter()
- *
- */
-public abstract class CodeReaderFilter<O> {
-
- private Reader reader;
-
- private O output;
-
- private CodeReaderConfiguration configuration;
-
- public CodeReaderFilter() {
- }
-
- public CodeReaderFilter(O output) {
- this.output = output;
- }
-
- /**
- * Returns the reader from which this class reads the character stream.
- *
- * @return the reader
- */
- public Reader getReader() {
- return reader;
- }
-
- /**
- * Sets the reader from which this class will read the character stream.
- *
- * @param reader
- * the reader
- */
- public void setReader(Reader reader) {
- this.reader = reader;
- }
-
- /**
- * Returns the output object.
- *
- * @return the output
- */
- public O getOutput() {
- return output;
- }
-
- /**
- * Sets the output object
- *
- * @param output
- * the output to set
- */
- public void setOutput(O output) {
- this.output = output;
- }
-
- /**
- * Returns the configuration used for the CodeReader
- *
- * @return the configuration
- */
- public CodeReaderConfiguration getConfiguration() {
- return configuration;
- }
-
- /**
- * Sets the configuration that must be used by the CodeReader
- *
- * @param configuration
- * the configuration to set
- */
- public void setConfiguration(CodeReaderConfiguration configuration) {
- this.configuration = configuration;
- }
-
- /**
- * This method implements the filtering logic, that is:
- * <ul>
- * <li>
- * get the characters from the reader,</li>
- * <li>
- * filter the character flow (and grab more characters from the reader if the filtering removes some),</li>
- * <li>
- * and fill the given buffer to its full capacity with the filtered data.</li>
- * </ul>
- *
- * @param filteredBuffer
- * the output buffer that must contain the filtered data
- * @param offset
- * the offset to start reading from the reader
- * @param length
- * the number of characters to read from the reader
- * @return The number of characters read, or -1 if the end of the stream has been reached
- * @throws IOException
- * If an I/O error occurs
- */
- public abstract int read(char[] filteredBuffer, int offset, int length) throws IOException;
-
-}
diff --git a/sonar-channel/src/main/java/org/sonar/channel/EndMatcher.java b/sonar-channel/src/main/java/org/sonar/channel/EndMatcher.java
deleted file mode 100644
index 708da323e3b..00000000000
--- a/sonar-channel/src/main/java/org/sonar/channel/EndMatcher.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.channel;
-
-public interface EndMatcher {
-
- boolean match(int toMatch);
-}
diff --git a/sonar-channel/src/main/java/org/sonar/channel/RegexChannel.java b/sonar-channel/src/main/java/org/sonar/channel/RegexChannel.java
deleted file mode 100644
index 8d1f80bc7ea..00000000000
--- a/sonar-channel/src/main/java/org/sonar/channel/RegexChannel.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.channel;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * The RegexChannel can be used to be called each time the next characters in the character stream match a regular expression
- */
-public abstract class RegexChannel<O> extends Channel<O> {
-
- private final StringBuilder tmpBuilder = new StringBuilder();
- private final Matcher matcher;
-
- /**
- * Create a RegexChannel object with the required regular expression
- *
- * @param regex
- * regular expression to be used to try matching the next characters in the stream
- */
- public RegexChannel(String regex) {
- matcher = Pattern.compile(regex).matcher("");
- }
-
- @Override
- public final boolean consume(CodeReader code, O output) {
- if (code.popTo(matcher, tmpBuilder) > 0) {
- consume(tmpBuilder, output);
- tmpBuilder.delete(0, tmpBuilder.length());
- return true;
- }
- return false;
- }
-
- /**
- * The consume method is called each time the regular expression used to create the RegexChannel object matches the next characters in the
- * character streams.
- *
- * @param token
- * the token consumed in the character stream and matching the regular expression
- * @param the
- * OUPUT object which can be optionally fed
- */
- protected abstract void consume(CharSequence token, O output);
-
-}
diff --git a/sonar-channel/src/main/java/org/sonar/channel/package-info.java b/sonar-channel/src/main/java/org/sonar/channel/package-info.java
deleted file mode 100644
index 3ce372d79b4..00000000000
--- a/sonar-channel/src/main/java/org/sonar/channel/package-info.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-/**
- * Provides a basic framework to sequentially read any kind of character stream in order to feed a generic OUTPUT.
- *
- * This framework can used for instance in order to :
- * <ul>
- * <li>Create a lexer in charge to generate a list of tokens from a character stream</li>
- * <li>Create a source code syntax highligther in charge to decorate a source code with HTML tags</li>
- * <li>Create a javadoc generator</li>
- * <li>...</li>
- * </ul>
- *
- * The entry point of this framework is the {@link org.sonar.channel.ChannelDispatcher} class.
- * This class must be initialized with a {@link org.sonar.channel.CodeReader} and a list of {@link org.sonar.channel.Channel}.
- *
- * The {@link org.sonar.channel.CodeReader} encapsulates any character stream in order to provide all mechanisms to Channels
- * in order to look ahead and look behind the current reading cursor position.
- *
- * A {@link org.sonar.channel.Channel} is in charge to consume the character stream through the CodeReader in order to feed
- * the OUTPUT.
- */
-package org.sonar.channel;
-