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

Compatibility with SonarQube 7.4 #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
96 changes: 63 additions & 33 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.sonarsource.parent</groupId>
<artifactId>parent</artifactId>
<version>29</version>
<relativePath />
</parent>
<groupId>org.sonarsource.scm.perforce</groupId>
<artifactId>sonar-scm-perforce-plugin</artifactId>
<name>SonarQube :: Plugins :: SCM :: Perforce</name>
<version>1.5-SNAPSHOT</version>
<version>1.6-SNAPSHOT</version>

<!-- this is important for sonar-packaging-maven-plugin -->
<packaging>sonar-plugin</packaging>
<description>Perforce SCM Provider.</description>
<url>http://redirect.sonarsource.com/plugins/scmperforce.html</url>
<inceptionYear>2014</inceptionYear>

<licenses>


<licenses>
<license>
<name>GNU LGPL 3</name>
<url>http://www.gnu.org/licenses/lgpl.txt</url>
Expand All @@ -31,14 +24,12 @@
<timezone>+1</timezone>
</developer>
</developers>

<scm>
<connection>scm:git:[email protected]:SonarQubeCommunity/sonar-scm-perforce.git</connection>
<developerConnection>scm:git:[email protected]:SonarQubeCommunity/sonar-scm-perforce.git</developerConnection>
<url>https://github.com/SonarQubeCommunity/sonar-scm-perforce</url>
<tag>HEAD</tag>
</scm>

<issueManagement>
<system>GitHub Issues</system>
<url>https://github.com/SonarQubeCommunity/sonar-scm-perforce/issues</url>
Expand All @@ -48,15 +39,14 @@
<system>Travis</system>
<url>https://travis-ci.org/SonarQubeCommunity/sonar-scm-perforce</url>
</ciManagement>

<properties>
<sonar.buildVersion>5.0</sonar.buildVersion>
<sonar.pluginName>Perforce</sonar.pluginName>
<sonar.pluginClass>org.sonar.plugins.scm.perforce.PerforcePlugin</sonar.pluginClass>
<gitRepositoryName>sonar-scm-perforce</gitRepositoryName>
</properties>


<dependencies>
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>7.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.perforce</groupId>
<artifactId>p4java</artifactId>
Expand All @@ -68,13 +58,7 @@
<version>2.0.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>${sonar.buildVersion}</version>
<scope>provided</scope>
</dependency>


<!-- unit tests -->
<dependency>
<groupId>junit</groupId>
Expand All @@ -94,6 +78,52 @@
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-lang/commons-lang -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>r05</version>
</dependency>

</dependencies>

</project>

<build>
<plugins>
<plugin>
<groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
<version>1.17</version>
<extensions>true</extensions>
<configuration>
<!-- the entry-point class that extends org.sonar.api.SonarPlugin -->
<pluginClass>org.sonar.plugins.scm.perforce.PerforcePlugin</pluginClass>
<pluginDescription>PerforcePlugin</pluginDescription>

</configuration>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.1</version>
<executions>
<execution>
<id>attach-descriptor</id>
<goals>
<goal>attach-descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public class PerforceBlameCommand extends BlameCommand {

private static final Logger LOG = LoggerFactory.getLogger(PerforceBlameCommand.class);
private final PerforceConfiguration config;
private final Map<Integer, IFileRevisionData> revisionDataByChangelistId = new HashMap<>();
private final Map<Integer, IChangelist> changelistCache = new HashMap<>();
private final Map<Integer, IFileRevisionData> revisionDataByChangelistId = new HashMap<Integer, IFileRevisionData>();
private final Map<Integer, IChangelist> changelistCache = new HashMap<Integer, IChangelist>();

public PerforceBlameCommand(PerforceConfiguration config) {
this.config = config;
Expand All @@ -64,6 +64,7 @@ public void blame(BlameInput input, BlameOutput output) {
FileSystem fs = input.fileSystem();
LOG.debug("Working directory: " + fs.baseDir().getAbsolutePath());
PerforceExecutor executor = new PerforceExecutor(config, fs.baseDir());

try {
for (InputFile inputFile : input.filesToBlame()) {
blame(inputFile, executor.getServer(), output);
Expand Down Expand Up @@ -116,7 +117,7 @@ void blame(InputFile inputFile, IOptionsServer server, BlameOutput output) throw
*/
private List<BlameLine> computeBlame(InputFile inputFile, IOptionsServer server, List<IFileAnnotation> fileAnnotations)
throws ConnectionException, RequestException, AccessException {
List<BlameLine> lines = new ArrayList<>();
List<BlameLine> lines = new ArrayList<BlameLine>();
for (IFileAnnotation fileAnnotation : fileAnnotations) {
int lowerChangelistId = fileAnnotation.getLower();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,24 @@
*/
package org.sonar.plugins.scm.perforce;

import com.google.common.collect.ImmutableList;
import com.perforce.p4java.impl.mapbased.rpc.RpcPropertyDefs;
import org.sonar.api.BatchComponent;
import java.util.Arrays;
import java.util.List;

import javax.annotation.CheckForNull;

import org.sonar.api.CoreProperties;
import org.sonar.api.PropertyType;
import org.sonar.api.batch.InstantiationStrategy;
import org.sonar.api.batch.ScannerSide;
import org.sonar.api.config.Configuration;
import org.sonar.api.config.PropertyDefinition;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.Qualifiers;

import javax.annotation.CheckForNull;

import java.util.List;
import com.perforce.p4java.impl.mapbased.rpc.RpcPropertyDefs;

@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
public class PerforceConfiguration implements BatchComponent {
@ScannerSide
public class PerforceConfiguration {

private static final String FALSE = "false";
private static final String CATEGORY_PERFORCE = "Perforce";
Expand All @@ -47,14 +49,15 @@ public class PerforceConfiguration implements BatchComponent {
private static final String CHARSET_PROP_KEY = "sonar.perforce.charset";
private static final String SOCKSOTIMEOUT_PROP_KEY = "sonar.perforce.sockSoTimeout";

private final Settings settings;

public PerforceConfiguration(Settings settings) {

private final Configuration settings;

public PerforceConfiguration(Configuration settings) {
this.settings = settings;
}

public static List<PropertyDefinition> getProperties() {
return ImmutableList.of(
return Arrays.asList(
PropertyDefinition.builder(PORT_PROP_KEY)
.name("Perforce service port")
.description("The host and port number of the Perforce service with which to communicate. Format is host:port.")
Expand Down Expand Up @@ -133,40 +136,40 @@ public static List<PropertyDefinition> getProperties() {

@CheckForNull
public String port() {
return settings.getString(PORT_PROP_KEY);
return settings.get(PORT_PROP_KEY).orElse(null);
}

@CheckForNull
public String username() {
return settings.getString(USER_PROP_KEY);
return settings.get(USER_PROP_KEY).orElse(null);
}

@CheckForNull
public String password() {
return settings.getString(PASSWORD_PROP_KEY);
return settings.get(PASSWORD_PROP_KEY).orElse(null);
}

@CheckForNull
public String charset() {
return settings.getString(CHARSET_PROP_KEY);
return settings.get(CHARSET_PROP_KEY).orElse(null);
}

public boolean useSsl() {
return settings.getBoolean(USESSL_PROP_KEY);
public Boolean useSsl() {
return settings.getBoolean(USESSL_PROP_KEY).orElse(null);
}

@CheckForNull
public String clientName() {
return settings.getString(CLIENT_PROP_KEY);
return settings.get(CLIENT_PROP_KEY).orElse(null);
}

@CheckForNull
public String clientImpersonatedHostname() {
return settings.getString(CLIENT_IMPERSONATED_HOST_PROP_KEY);
return settings.get(CLIENT_IMPERSONATED_HOST_PROP_KEY).orElse(null);
}

public int sockSoTimeout() {
return settings.getInt(SOCKSOTIMEOUT_PROP_KEY);
public Integer sockSoTimeout() {
return settings.getInt(SOCKSOTIMEOUT_PROP_KEY).orElse(null);
}

}
24 changes: 14 additions & 10 deletions src/main/java/org/sonar/plugins/scm/perforce/PerforceExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@
*/
package org.sonar.plugins.scm.perforce;

import java.io.File;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Optional;
import java.util.Properties;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.utils.MessageException;

import com.perforce.p4java.client.IClient;
import com.perforce.p4java.client.IClientViewMapping;
import com.perforce.p4java.core.file.FileSpecBuilder;
Expand All @@ -34,16 +48,6 @@
import com.perforce.p4java.server.IOptionsServer;
import com.perforce.p4java.server.ServerFactory;
import com.perforce.p4java.server.callback.ICommandCallback;
import java.io.File;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Properties;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.utils.MessageException;

public class PerforceExecutor {

Expand Down
32 changes: 18 additions & 14 deletions src/main/java/org/sonar/plugins/scm/perforce/PerforcePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,27 @@
*/
package org.sonar.plugins.scm.perforce;

import com.google.common.collect.ImmutableList;
import org.sonar.api.SonarPlugin;

import java.util.ArrayList;
import java.util.List;

public final class PerforcePlugin extends SonarPlugin {
import org.sonar.api.Plugin;

import com.google.common.collect.ImmutableList;

public final class PerforcePlugin implements Plugin {

@Override
public void define(Context context) {
context.addExtensions(getExtensions());

@Override
public List getExtensions() {
List result = new ArrayList();
result.addAll(ImmutableList.of(
PerforceScmProvider.class,
PerforceBlameCommand.class,
PerforceConfiguration.class));
result.addAll(PerforceConfiguration.getProperties());
return result;
}
}

public List getExtensions() {
List result = new ArrayList();
result.addAll(
ImmutableList.of(PerforceScmProvider.class,
PerforceBlameCommand.class, PerforceConfiguration.class, PerforceExecutor.class));
result.addAll(PerforceConfiguration.getProperties());
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void testBlameSubmittedFile() throws Exception {
when(line5ChangeList4.getDepotPath()).thenReturn("foo/bar/src/Foo.java");
when(line5ChangeList4.getLower()).thenReturn(4);

Map<IFileSpec, List<IFileRevisionData>> result = new HashMap<>();
Map<IFileSpec, List<IFileRevisionData>> result = new HashMap<IFileSpec, List<IFileRevisionData>>();
IFileSpec fileSpecResult = mock(IFileSpec.class);
when(fileSpecResult.getOpStatus()).thenReturn(FileSpecOpStatus.VALID);
IFileRevisionData revision3 = mock(IFileRevisionData.class);
Expand Down
Loading