*
* @since 2.2
*/
-public class HttpDownloader implements UriReader.SchemeProcessor, BatchComponent, ServerComponent {
+public class HttpDownloader extends UriReader.SchemeProcessor implements BatchComponent, ServerComponent {
public static final int TIMEOUT_MILLISECONDS = 20 * 1000;
return Joiner.on(", ").join(descriptions);
}
- public String description(URI uri) {
+ String description(URI uri) {
return String.format("%s (%s)", uri.toString(), getProxySynthesis(uri));
}
}
}
- public String[] getSupportedSchemes() {
+ String[] getSupportedSchemes() {
return new String[]{"http", "https"};
}
- public byte[] readBytes(URI uri) {
+ byte[] readBytes(URI uri) {
return download(uri);
}
- public String readString(URI uri, Charset charset) {
+ String readString(URI uri, Charset charset) {
return downloadPlainText(uri, charset.name());
}
- public InputStream openStream(URI uri) {
+ InputStream openStream(URI uri) {
try {
HttpURLConnection connection = newHttpConnection(uri);
return connection.getInputStream();
return processor;
}
- static interface SchemeProcessor extends BatchComponent, ServerComponent {
- String[] getSupportedSchemes();
+ abstract static class SchemeProcessor implements BatchComponent, ServerComponent {
+ abstract String[] getSupportedSchemes();
- byte[] readBytes(URI uri);
+ abstract byte[] readBytes(URI uri);
- String readString(URI uri, Charset charset);
+ abstract String readString(URI uri, Charset charset);
- InputStream openStream(URI uri);
+ abstract InputStream openStream(URI uri);
- String description(URI uri);
+ abstract String description(URI uri);
}
/**
* This implementation is not exposed in API and is kept private.
*/
- private static class FileProcessor implements SchemeProcessor {
+ private static class FileProcessor extends SchemeProcessor {
public String[] getSupportedSchemes() {
return new String[]{"file"};
}
- public byte[] readBytes(URI uri) {
+ byte[] readBytes(URI uri) {
try {
return Files.toByteArray(new File(uri));
} catch (IOException e) {
}
}
- public String readString(URI uri, Charset charset) {
+ String readString(URI uri, Charset charset) {
try {
return Files.toString(new File(uri), charset);
} catch (IOException e) {
}
}
- public InputStream openStream(URI uri) {
+ InputStream openStream(URI uri) {
try {
return Files.newInputStreamSupplier(new File(uri)).getInput();
} catch (IOException e) {
}
}
- public String description(URI uri) {
+ String description(URI uri) {
return new File(uri).getAbsolutePath();
}
}
import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;
+import org.sonar.api.config.Settings;
import org.sonar.api.utils.SonarException;
import org.sonar.api.utils.UriReader;
import org.sonar.updatecenter.common.UpdateCenter;
@Before
public void startServer() throws Exception {
reader = mock(UriReader.class);
- client = new UpdateCenterClient(reader, new URI(BASE_URL));
+ Settings settings = new Settings().setProperty(UpdateCenterClient.URL_PROPERTY, BASE_URL);
+ client = new UpdateCenterClient(reader, settings);
}
@Test
UpdateCenter center = client.getCenter();
verify(reader, times(1)).openStream(new URI(BASE_URL));
assertThat(center.getSonar().getVersions()).containsOnly(Version.create("2.2"), Version.create("2.3"));
+ assertThat(client.getLastRefreshDate()).isNotNull();
}
+ @Test
+ public void not_available_before_initialization() {
+ assertThat(client.getLastRefreshDate()).isNull();
+ }
+
@Test
public void ignore_connection_errors() {
when(reader.openStream(any(URI.class))).thenThrow(new SonarException());