Fix MavenTestCase to use Maven mirror only when it available
This commit is contained in:
@@ -47,11 +47,35 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public abstract class MavenTestCase extends UsefulTestCase {
|
public abstract class MavenTestCase extends UsefulTestCase {
|
||||||
|
|
||||||
|
private static final String mavenMirrorUrl = System.getProperty("idea.maven.test.mirror",
|
||||||
|
// use JB maven proxy server for internal use by default, see details at
|
||||||
|
// https://confluence.jetbrains.com/display/JBINT/Maven+proxy+server
|
||||||
|
"http://maven.labs.intellij.net/repo1");
|
||||||
|
private static boolean mirrorDiscoverable = false;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
URL url = new URL(mavenMirrorUrl);
|
||||||
|
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
|
||||||
|
urlConnection.setConnectTimeout(1000);
|
||||||
|
int responseCode = urlConnection.getResponseCode();
|
||||||
|
if(responseCode < 400) {
|
||||||
|
mirrorDiscoverable = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
mirrorDiscoverable = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private File ourTempDir;
|
private File ourTempDir;
|
||||||
|
|
||||||
protected IdeaProjectTestFixture myTestFixture;
|
protected IdeaProjectTestFixture myTestFixture;
|
||||||
@@ -319,16 +343,22 @@ public abstract class MavenTestCase extends UsefulTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static String createSettingsXmlContent(String content) {
|
private static String createSettingsXmlContent(String content) {
|
||||||
String mirror = System.getProperty("idea.maven.test.mirror",
|
|
||||||
// use JB maven proxy server for internal use by default, see details at
|
if (!mirrorDiscoverable) {
|
||||||
// https://confluence.jetbrains.com/display/JBINT/Maven+proxy+server
|
System.err.println("Maven mirror at " + mavenMirrorUrl + " not reachable, so not using it.");
|
||||||
"http://maven.labs.intellij.net/repo1");
|
|
||||||
|
return "<settings>" +
|
||||||
|
content +
|
||||||
|
"</settings>";
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Using Maven mirror at " + mavenMirrorUrl);
|
||||||
return "<settings>" +
|
return "<settings>" +
|
||||||
content +
|
content +
|
||||||
"<mirrors>" +
|
"<mirrors>" +
|
||||||
" <mirror>" +
|
" <mirror>" +
|
||||||
" <id>jb-central-proxy</id>" +
|
" <id>jb-central-proxy</id>" +
|
||||||
" <url>" + mirror + "</url>" +
|
" <url>" + mavenMirrorUrl + "</url>" +
|
||||||
" <mirrorOf>external:*</mirrorOf>" +
|
" <mirrorOf>external:*</mirrorOf>" +
|
||||||
" </mirror>" +
|
" </mirror>" +
|
||||||
"</mirrors>" +
|
"</mirrors>" +
|
||||||
|
|||||||
Reference in New Issue
Block a user