*/
package org.sonar.batch.repository;
+import org.sonar.api.utils.HttpDownloader.HttpException;
+
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;
+
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.Map;
+
import javax.annotation.Nullable;
+
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.mutable.MutableBoolean;
import org.slf4j.Logger;
}
return processStream(result.get(), projectKey);
} catch (IllegalStateException e) {
- LOG.debug("Couldn't get project repositories - continuing without it", e);
+ if (shouldThrow(e)) {
+ throw e;
+ }
+
+ LOG.debug("Project repository not available - continuing without it", e);
return new ProjectRepositories();
}
}
builder.append(BATCH_PROJECT_URL)
.append("?key=").append(BatchUtils.encodeForUrl(projectKey));
if (issuesMode) {
- builder.append("&issues=true");
+ builder.append("&issues_mode=true");
}
return builder.toString();
}
+ private static boolean shouldThrow(Exception e) {
+ if (e.getCause() != null && e.getCause() instanceof HttpException) {
+ HttpException http = (HttpException) e.getCause();
+ return http.getResponseCode() != 404;
+ }
+
+ return false;
+ }
+
private static ProjectRepositories processStream(InputStream is, String projectKey) {
try {
WsProjectResponse response = WsProjectResponse.parseFrom(is);
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URI;
+
+import org.sonar.api.utils.HttpDownloader.HttpException;
import org.apache.commons.lang.mutable.MutableBoolean;
import org.junit.Before;
import org.junit.Rule;
import org.sonar.batch.cache.WSLoader;
import org.sonar.batch.cache.WSLoaderResult;
import org.sonarqube.ws.WsBatch.WsProjectResponse;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
assertThat(proj.exists()).isEqualTo(false);
}
+ @Test(expected = IllegalStateException.class)
+ public void failFastHttpError() {
+ HttpException http = new HttpException(URI.create("uri"), 403);
+ IllegalStateException e = new IllegalStateException("http error", http);
+ when(wsLoader.loadStream(anyString())).thenThrow(e);
+ loader.load(PROJECT_KEY, false, null);
+ }
+
@Test
public void passIssuesModeParameter() {
loader.load(PROJECT_KEY, false, null);
verify(wsLoader).loadStream("/batch/project.protobuf?key=foo%3F");
loader.load(PROJECT_KEY, true, null);
- verify(wsLoader).loadStream("/batch/project.protobuf?key=foo%3F&issues=true");
+ verify(wsLoader).loadStream("/batch/project.protobuf?key=foo%3F&issues_mode=true");
}
@Test