aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-10-14 14:31:54 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-10-14 14:31:54 +0200
commitcd802907369ae4ff25e8aaa6c93c7a3d2f8bcc17 (patch)
tree348aa66ae9a0c513cffe1579aa51e0bc351748d9 /sonar-batch
parent7df58c2fc0dbab0d82c5587104a9ad1d2fa369ac (diff)
parent5e7744ae006b41948359fe60841e8e66701fc5f9 (diff)
downloadsonarqube-cd802907369ae4ff25e8aaa6c93c7a3d2f8bcc17.tar.gz
sonarqube-cd802907369ae4ff25e8aaa6c93c7a3d2f8bcc17.zip
Merge remote-tracking branch 'origin/branch-4.5'
Conflicts: sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java sonar-batch/src/main/java/org/sonar/batch/scan/LastSnapshots.java sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java11
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java8
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/LastSnapshots.java3
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java7
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ModuleFileSystemInitializer.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/ServerClientTest.java5
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java14
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java31
-rw-r--r--sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/sonar-project.properties6
l---------sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/testx1
l---------sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/xources1
12 files changed, 80 insertions, 13 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java
index 86130986d1f..0acc0a94232 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java
@@ -36,7 +36,9 @@ import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
import java.net.URI;
+import java.net.URLEncoder;
/**
* Replace the deprecated org.sonar.batch.ServerMetadata
@@ -144,4 +146,13 @@ public class ServerClient implements BatchComponent {
private String getPassword() {
return props.property(CoreProperties.PASSWORD);
}
+
+ public static String encodeForUrl(String url) {
+ try {
+ return URLEncoder.encode(url, "UTF-8");
+
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalStateException("Encoding not supported", e);
+ }
+ }
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java
index fbf973640ed..b665d9d3279 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java
@@ -36,7 +36,7 @@ public class TempFolderProvider extends ProviderAdapter {
public TempFolder provide(BootstrapProperties bootstrapProps) {
if (tempFolder == null) {
String workingDirPath = StringUtils.defaultIfBlank(bootstrapProps.property(CoreProperties.WORKING_DIRECTORY), CoreProperties.WORKING_DIRECTORY_DEFAULT_VALUE);
- File workingDir = new File(workingDirPath);
+ File workingDir = new File(workingDirPath).getAbsoluteFile();
File tempDir = new File(workingDir, ".sonartmp");
try {
FileUtils.forceMkdir(tempDir);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java b/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java
index b86dd4e1cf7..f2519a186eb 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java
@@ -44,8 +44,6 @@ import org.sonar.core.source.db.SnapshotDataDto;
import javax.persistence.Query;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@@ -77,11 +75,7 @@ public class DefaultProjectReferentialsLoader implements ProjectReferentialsLoad
if (taskProperties.properties().containsKey(ModuleQProfiles.SONAR_PROFILE_PROP)) {
LOG.warn("Ability to set quality profile from command line using '" + ModuleQProfiles.SONAR_PROFILE_PROP
+ "' is deprecated and will be dropped in a future SonarQube version. Please configure quality profile used by your project on SonarQube server.");
- try {
- url += "&profile=" + URLEncoder.encode(taskProperties.properties().get(ModuleQProfiles.SONAR_PROFILE_PROP), "UTF-8");
- } catch (UnsupportedEncodingException e) {
- throw new IllegalStateException("Unable to encode URL", e);
- }
+ url += "&profile=" + ServerClient.encodeForUrl(taskProperties.properties().get(ModuleQProfiles.SONAR_PROFILE_PROP));
}
url += "&preview=" + analysisMode.isPreview();
ProjectReferentials ref = ProjectReferentials.fromJson(serverClient.request(url));
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/LastSnapshots.java b/sonar-batch/src/main/java/org/sonar/batch/scan/LastSnapshots.java
index 980129c0311..9f04b206fb3 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/LastSnapshots.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/LastSnapshots.java
@@ -62,7 +62,8 @@ public class LastSnapshots implements BatchComponent {
private String loadSourceFromWs(Resource resource) {
TimeProfiler profiler = new TimeProfiler(LOG).start("Load previous source code of: " + resource.getEffectiveKey()).setLevelToDebug();
try {
- return server.request("/api/sources?resource=" + resource.getEffectiveKey() + "&format=txt", "GET", false, analysisMode.getPreviewReadTimeoutSec() * 1000);
+ return server
+ .request("/api/sources?resource=" + ServerClient.encodeForUrl(resource.getEffectiveKey()) + "&format=txt", "GET", false, analysisMode.getPreviewReadTimeoutSec() * 1000);
} catch (HttpDownloader.HttpException he) {
if (he.getResponseCode() == 404) {
return "";
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java
index 1e185487a05..65a7585555e 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java
@@ -22,6 +22,8 @@ package org.sonar.batch.scan.filesystem;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.CharMatcher;
import com.google.common.io.Files;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.sonar.api.BatchComponent;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.SonarIndex;
@@ -44,6 +46,8 @@ import org.sonar.batch.util.DeprecatedKeyUtils;
*/
public class ComponentIndexer implements BatchComponent {
+ private static final Logger LOG = LoggerFactory.getLogger(ComponentIndexer.class);
+
private final Languages languages;
private final Settings settings;
private final SonarIndex sonarIndex;
@@ -62,6 +66,9 @@ public class ComponentIndexer implements BatchComponent {
migration.migrateIfNeeded(module, fs);
boolean shouldImportSource = settings.getBoolean(CoreProperties.CORE_IMPORT_SOURCES_PROPERTY);
+ if (!shouldImportSource) {
+ LOG.warn("Not importing source will prevent issues to be properly tracked between consecutive analyses");
+ }
for (InputFile inputFile : fs.inputFiles(fs.predicates().all())) {
String languageKey = inputFile.language();
boolean unitTest = InputFile.Type.TEST == inputFile.type();
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ModuleFileSystemInitializer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ModuleFileSystemInitializer.java
index 2c9c2473194..3f25a94c6c7 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ModuleFileSystemInitializer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ModuleFileSystemInitializer.java
@@ -109,6 +109,10 @@ public class ModuleFileSystemInitializer implements BatchComponent {
return testDirsOrFiles;
}
+ /**
+ * @deprecated since 4.5.1 use SonarQube Java specific API
+ */
+ @Deprecated
List<File> binaryDirs() {
return binaryDirs;
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ServerClientTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ServerClientTest.java
index 34060a4ee30..9c9b930f99d 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ServerClientTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ServerClientTest.java
@@ -135,6 +135,11 @@ public class ServerClientTest {
newServerClient().request("/foo");
}
+ @Test
+ public void testEncode() {
+ assertThat(ServerClient.encodeForUrl("my value")).isEqualTo("my+value");
+ }
+
private ServerClient newServerClient() {
when(bootstrapProps.property("sonar.host.url")).thenReturn("http://localhost:" + server.getPort());
return new ServerClient(bootstrapProps, new EnvironmentInformation("Junit", "4"));
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java
index 08ac9d7e3cd..5429cbd860c 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java
@@ -29,6 +29,7 @@ import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.utils.MessageException;
+import org.sonar.api.utils.System2;
import org.sonar.batch.mediumtest.BatchMediumTester;
import org.sonar.batch.mediumtest.BatchMediumTester.TaskResult;
import org.sonar.batch.protocol.input.ActiveRule;
@@ -38,6 +39,7 @@ import java.io.File;
import java.io.IOException;
import static org.fest.assertions.Assertions.assertThat;
+import static org.junit.Assume.assumeFalse;
public class FileSystemMediumTest {
@@ -169,4 +171,16 @@ public class FileSystemMediumTest {
}
+ // SONAR-5330
+ @Test
+ public void scanProjectWithSourceSymlink() throws Exception {
+ assumeFalse(System2.INSTANCE.isOsWindows());
+ File projectDir = new File("src/test/resources/mediumtest/xoo/sample-with-symlink");
+ TaskResult result = tester
+ .newScanTask(new File(projectDir, "sonar-project.properties"))
+ .start();
+
+ assertThat(result.inputFiles()).hasSize(3);
+ }
+
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java
index 145332981d4..66acae88fa3 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java
@@ -37,7 +37,10 @@ import java.net.URISyntaxException;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
public class LastSnapshotsTest {
@@ -88,7 +91,21 @@ public class LastSnapshotsTest {
String source = lastSnapshots.getSource(newFile());
assertThat(source).isEqualTo("downloaded source of Bar.c");
- verify(server).request("/api/sources?resource=myproject:org/foo/Bar.c&format=txt", "GET", false, 30 * 1000);
+ verify(server).request("/api/sources?resource=myproject%3Aorg%2Ffoo%2FBar.c&format=txt", "GET", false, 30 * 1000);
+ }
+
+ @Test
+ public void should_download_source_with_space_from_ws_if_preview_mode() {
+ db.prepareDbUnit(getClass(), "last_snapshot.xml");
+ ServerClient server = mock(ServerClient.class);
+ when(server.request(anyString(), eq("GET"), eq(false), eq(30 * 1000))).thenReturn("downloaded source of Foo Bar.c");
+
+ when(mode.isPreview()).thenReturn(true);
+ LastSnapshots lastSnapshots = new LastSnapshots(mode, new SnapshotSourceDao(db.myBatis()), server);
+
+ String source = lastSnapshots.getSource(newFile());
+ assertThat(source).isEqualTo("downloaded source of Foo Bar.c");
+ verify(server).request("/api/sources?resource=myproject%3Aorg%2Ffoo%2FBar.c&format=txt", "GET", false, 30 * 1000);
}
@Test
@@ -113,9 +130,9 @@ public class LastSnapshotsTest {
when(mode.isPreview()).thenReturn(true);
LastSnapshots lastSnapshots = new LastSnapshots(mode, new SnapshotSourceDao(db.myBatis()), server);
- String source = lastSnapshots.getSource(newFile());
+ String source = lastSnapshots.getSource(newFileWithSpace());
assertThat(source).isEqualTo("");
- verify(server).request("/api/sources?resource=myproject:org/foo/Bar.c&format=txt", "GET", false, 30 * 1000);
+ verify(server).request("/api/sources?resource=myproject%3Aorg%2Ffoo%2FFoo+Bar.c&format=txt", "GET", false, 30 * 1000);
}
@Test
@@ -134,4 +151,10 @@ public class LastSnapshotsTest {
file.setEffectiveKey("myproject:org/foo/Bar.c");
return file;
}
+
+ private File newFileWithSpace() {
+ File file = new File("org/foo", "Foo Bar.c");
+ file.setEffectiveKey("myproject:org/foo/Foo Bar.c");
+ return file;
+ }
}
diff --git a/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/sonar-project.properties b/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/sonar-project.properties
new file mode 100644
index 00000000000..8810e376701
--- /dev/null
+++ b/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/sonar-project.properties
@@ -0,0 +1,6 @@
+sonar.projectKey=sample
+sonar.projectName=Sample
+sonar.projectVersion=0.1-SNAPSHOT
+sonar.sources=xources
+sonar.tests=testx
+sonar.language=xoo
diff --git a/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/testx b/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/testx
new file mode 120000
index 00000000000..7385ebd51cf
--- /dev/null
+++ b/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/testx
@@ -0,0 +1 @@
+../sample/testx/ \ No newline at end of file
diff --git a/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/xources b/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/xources
new file mode 120000
index 00000000000..15dca9d90d2
--- /dev/null
+++ b/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/xources
@@ -0,0 +1 @@
+../sample/xources/ \ No newline at end of file