diff options
author | Pierre <pierre.guillot@sonarsource.com> | 2022-06-30 11:55:04 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-06-30 20:03:10 +0000 |
commit | ba2118d645faad8ef419cc5b301bcaf394d2571e (patch) | |
tree | d2ab4bf23ee077c4158e81f020dee262a1bcbe3b /sonar-duplications/src/main/java/org/sonar | |
parent | 0e9d44d4b0b4d4017c360bf686dcb1a8855c3f23 (diff) | |
download | sonarqube-ba2118d645faad8ef419cc5b301bcaf394d2571e.tar.gz sonarqube-ba2118d645faad8ef419cc5b301bcaf394d2571e.zip |
SONAR-16591 remove PMD dependency and related, deprecated code
Diffstat (limited to 'sonar-duplications/src/main/java/org/sonar')
4 files changed, 0 insertions, 198 deletions
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/cpd/CodeLoaderWithoutCache.java b/sonar-duplications/src/main/java/org/sonar/duplications/cpd/CodeLoaderWithoutCache.java deleted file mode 100644 index 41c48da888d..00000000000 --- a/sonar-duplications/src/main/java/org/sonar/duplications/cpd/CodeLoaderWithoutCache.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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.duplications.cpd; - -import java.util.List; - -import net.sourceforge.pmd.cpd.SourceCode.CodeLoader; - -public abstract class CodeLoaderWithoutCache extends CodeLoader { - - @Override - public final List<String> getCode() { - return load(); - } -} diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/cpd/FileCodeLoaderWithoutCache.java b/sonar-duplications/src/main/java/org/sonar/duplications/cpd/FileCodeLoaderWithoutCache.java deleted file mode 100644 index f30db7f44e7..00000000000 --- a/sonar-duplications/src/main/java/org/sonar/duplications/cpd/FileCodeLoaderWithoutCache.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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.duplications.cpd; - -import java.io.Reader; - -public class FileCodeLoaderWithoutCache extends CodeLoaderWithoutCache { - - private final String fileName; - private final Reader fileReader; - - public FileCodeLoaderWithoutCache(String fileName, Reader fileReader) { - this.fileName = fileName; - this.fileReader = fileReader; - } - - @Override - public Reader getReader() throws Exception { - return fileReader; - } - - @Override - public String getFileName() { - return fileName; - } -} diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/cpd/package-info.java b/sonar-duplications/src/main/java/org/sonar/duplications/cpd/package-info.java deleted file mode 100644 index 4602f8c1b55..00000000000 --- a/sonar-duplications/src/main/java/org/sonar/duplications/cpd/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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. - */ -@ParametersAreNonnullByDefault -package org.sonar.duplications.cpd; - -import javax.annotation.ParametersAreNonnullByDefault; - diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/TokenizerBridge.java b/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/TokenizerBridge.java deleted file mode 100644 index 4c0ff81f631..00000000000 --- a/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/TokenizerBridge.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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.duplications.internal.pmd; - -import java.io.Reader; -import java.util.ArrayList; -import java.util.List; -import net.sourceforge.pmd.cpd.SourceCode; -import net.sourceforge.pmd.cpd.TokenEntry; -import net.sourceforge.pmd.cpd.Tokenizer; -import net.sourceforge.pmd.cpd.Tokens; -import org.sonar.api.batch.sensor.cpd.internal.TokensLine; -import org.sonar.duplications.block.Block; -import org.sonar.duplications.cpd.FileCodeLoaderWithoutCache; - -/** - * Bridge, which allows to convert list of {@link TokenEntry} produced by {@link Tokenizer} into list of {@link TokensLine}s. - */ -public class TokenizerBridge { - - private final Tokenizer tokenizer; - private final PmdBlockChunker blockBuilder; - - public TokenizerBridge(Tokenizer tokenizer, int blockSize) { - this.tokenizer = tokenizer; - this.blockBuilder = new PmdBlockChunker(blockSize); - } - - public List<Block> chunk(String resourceId, String fileName, Reader fileReader) { - return blockBuilder.chunk(resourceId, chunk(fileName, fileReader)); - } - - public List<TokensLine> chunk(String fileName, Reader fileReader) { - SourceCode sourceCode = new SourceCode(new FileCodeLoaderWithoutCache(fileName, fileReader)); - Tokens tokens = new Tokens(); - TokenEntry.clearImages(); - try { - tokenizer.tokenize(sourceCode, tokens); - } catch (RuntimeException e) { - throw e; - } catch (Exception e) { - throw new RuntimeException(e); - } - TokenEntry.clearImages(); - return convert(tokens.getTokens()); - } - - /** - * We expect that implementation of {@link Tokenizer} is correct: - * tokens ordered by occurrence in source code and last token is EOF. - */ - public static List<TokensLine> convert(List<TokenEntry> tokens) { - List<TokensLine> result = new ArrayList<>(); - StringBuilder sb = new StringBuilder(); - int startLine = Integer.MIN_VALUE; - int startIndex = 0; - int currentIndex = 0; - for (TokenEntry token : tokens) { - if (token != TokenEntry.EOF) { - String value = token.getValue(); - int line = token.getBeginLine(); - if (line != startLine) { - addNewTokensLine(result, startIndex, currentIndex, startLine, sb); - startIndex = currentIndex + 1; - startLine = line; - } - currentIndex++; - sb.append(value); - } - } - addNewTokensLine(result, startIndex, currentIndex, startLine, sb); - return result; - } - - private static void addNewTokensLine(List<TokensLine> result, int startUnit, int endUnit, int startLine, StringBuilder sb) { - if (sb.length() != 0) { - result.add(new TokensLine(startUnit, endUnit, startLine, sb.toString())); - sb.setLength(0); - } - } - -} |