Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace deprecated cpd mapping #941

Merged
merged 1 commit into from
Sep 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions integration-tests/features/multimodule_analysis.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ Feature: cpp-multimodule-project
| comment_lines_density | 30 |
| comment_lines | 24 |
# duplications
| duplicated_lines_density | 57.3 |
| duplicated_lines | 86 |
| duplicated_lines_density | 56.0 |
| duplicated_lines | 84 |
| duplicated_blocks | 2 |
| duplicated_files | 2 |
# complexity
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/features/smoketest.feature
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ Feature: Smoketest
| comment_lines_density | 30 |
| comment_lines | 24 |
# duplications
| duplicated_lines_density | 57.0 |
| duplicated_lines | 86 |
| duplicated_lines_density | 55.6 |
| duplicated_lines | 84 |
| duplicated_blocks | 2 |
| duplicated_files | 2 |
# complexity
Expand Down
26 changes: 21 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
<parent>
<groupId>org.sonarsource.parent</groupId>
<artifactId>parent</artifactId>
<version>32</version>
<!--
When updating to parent 37 or above, check if <version.sonar-packaging.plugin> defined in the new
parent is 1.17 or above. If it is, remove the temporary override of <version.sonar-packaging.plugin>
below in this file.
-->
<version>36</version>
</parent>

<groupId>org.sonarsource.sonarqube-plugins.cxx</groupId>
Expand Down Expand Up @@ -165,7 +170,10 @@
<license.mailto>http://github.com/SonarOpenCommunity/sonar-cxx</license.mailto>
<maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile>
<sonar.version>5.6</sonar.version>
<!-- Temporary override of plugin version 1.16 inherited from parent 36 -->
<version.sonar-packaging.plugin>1.17</version.sonar-packaging.plugin>
<sslr.version>1.21</sslr.version>
<sslr-squid-bridge.version>2.6.1</sslr-squid-bridge.version>
<sonar.pluginClass>org.sonar.plugins.cxx.CxxPlugin</sonar.pluginClass>
<sonar.artifact.path>target/${project.artifactId}-${project.version}.jar</sonar.artifact.path>
<sonar.pluginName>C++ (Community)</sonar.pluginName>
Expand Down Expand Up @@ -213,19 +221,27 @@
<dependency>
<groupId>org.sonarsource.sslr-squid-bridge</groupId>
<artifactId>sslr-squid-bridge</artifactId>
<version>2.6.1</version>
<version>${sslr-squid-bridge.version}</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.sonar.sslr</groupId>
<artifactId>sslr-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.sonar.sslr</groupId>
<artifactId>sslr-xpath</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-plugin-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.sonar.sslr</groupId>
<artifactId>sslr-xpath</artifactId>
<groupId>org.picocontainer</groupId>
<artifactId>picocontainer</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
Expand Down Expand Up @@ -257,7 +273,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.2</version>
<version>1.7.21</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ public void define(Context context) {
l.add(CxxLanguage.class);
l.add(CxxMetrics.class);
l.add(CxxSquidSensor.class);
l.add(CxxCpdMapping.class);
l.add(CxxRatsRuleRepository.class);
l.add(CxxRatsSensor.class);
l.add(CxxXunitSensor.class);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Sonar C++ Plugin (Community)
* Copyright (C) 2010-2016 SonarOpenCommunity
* http://github.com/SonarOpenCommunity/sonar-cxx
*
* 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.plugins.cxx.cpd;

import java.io.File;
import javax.annotation.Nullable;

import com.sonar.sslr.api.AstAndTokenVisitor;
import com.sonar.sslr.api.AstNode;
import com.sonar.sslr.api.GenericTokenType;
import com.sonar.sslr.api.Grammar;
import com.sonar.sslr.api.Token;
import org.sonar.squidbridge.SquidAstVisitor;

import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.TextRange;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.cpd.NewCpdTokens;
import org.sonar.cxx.api.CxxTokenType;

public class CxxCpdVisitor extends SquidAstVisitor<Grammar> implements AstAndTokenVisitor {

private final SensorContext sensorContext;
private InputFile inputFile;
private NewCpdTokens cpdTokens;

public CxxCpdVisitor(SensorContext sensorContext) {
this.sensorContext = sensorContext;
}

@Override
public void visitFile(@Nullable AstNode astNode) {
File file = getContext().getFile();
inputFile = sensorContext.fileSystem().inputFile(sensorContext.fileSystem().predicates().is(file));
cpdTokens = sensorContext.newCpdTokens().onFile(inputFile);
}

@Override
public void leaveFile(@Nullable AstNode astNode) {
cpdTokens.save();
}

@Override
public void visitToken(Token token) {
if (!token.isGeneratedCode()) {
String text;
if (token.getType().equals(CxxTokenType.NUMBER)) {
text = "_N";
} else if (token.getType().equals(CxxTokenType.STRING)) {
text = "_S";
} else if (token.getType().equals(CxxTokenType.CHARACTER)) {
text = "_C";
} else if (token.getType().equals(GenericTokenType.IDENTIFIER)) {
text = "_I";
} else if (token.getType().equals(GenericTokenType.EOF)) {
return;
} else {
text = token.getValue();
}

TextRange range = inputFile.newRange(token.getLine(), token.getColumn(), token.getLine(), token.getColumn() + token.getValue().length());
cpdTokens.addToken(range, text);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,11 @@
* 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.plugins.cxx;

import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.mock;

import org.junit.Test;
import org.sonar.api.batch.fs.FileSystem;

public class CxxCpdMappingTest {
/**
* Package with visitor to define tokens used by CPD algorithm on files.
*/
@ParametersAreNonnullByDefault
package org.sonar.plugins.cxx.cpd;

@Test
public void testMapping() {
CxxLanguage language = mock(CxxLanguage.class);
FileSystem fs = TestUtils.mockFileSystem();
CxxCpdMapping mapping = new CxxCpdMapping(language, fs);
assertThat(mapping.getLanguage()).isSameAs(language);
assertThat(mapping.getTokenizer()).isInstanceOf(CxxTokenizer.class);
}
}
import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import org.sonar.api.ce.measure.RangeDistributionBuilder;
import org.sonar.api.rule.RuleKey;
import org.sonar.cxx.parser.CxxParser;
import org.sonar.plugins.cxx.cpd.CxxCpdVisitor;
import org.sonar.plugins.cxx.highlighter.CxxHighlighter;


Expand Down Expand Up @@ -111,6 +112,7 @@ public void describe(SensorDescriptor descriptor) {
public void execute(SensorContext context) {
List<SquidAstVisitor<Grammar>> visitors = new ArrayList<>((Collection) checks.all());
visitors.add(new CxxHighlighter(context));
visitors.add(new CxxCpdVisitor(context));
this.scanner = CxxAstScanner.create(createConfiguration(context.fileSystem(), this.settings), context,
visitors.toArray(new SquidAstVisitor[visitors.size()]));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public void testGetExtensions() throws Exception {
Plugin.Context context = new Plugin.Context(SonarQubeVersion.V5_6);
CxxPlugin plugin = new CxxPlugin();
plugin.define(context);
assertThat(context.getExtensions()).hasSize(63);
assertThat(context.getExtensions()).hasSize(62);
}
}

This file was deleted.

Loading