No more separate proxy configuration for Central search. Renamed everything to do with Solr to Central.

Former-commit-id: 4bcee86abf4415bfafc386d10018d9fcb2f6cec4
This commit is contained in:
Will Stranathan
2014-11-09 21:07:26 -05:00
7 changed files with 36 additions and 50 deletions

View File

@@ -29,7 +29,7 @@ public class CentralAnalyzer extends AbstractFileTypeAnalyzer {
/**
* The name of the analyzer.
*/
private static final String ANALYZER_NAME = "Solr Analyzer";
private static final String ANALYZER_NAME = "Central Analyzer";
/**
* The phase in which this analyzer runs.
@@ -62,19 +62,19 @@ public class CentralAnalyzer extends AbstractFileTypeAnalyzer {
boolean retval = false;
try {
if (Settings.getBoolean(Settings.KEYS.ANALYZER_SOLR_ENABLED)) {
if (Settings.getBoolean(Settings.KEYS.ANALYZER_CENTRAL_ENABLED)) {
if (!Settings.getBoolean(Settings.KEYS.ANALYZER_NEXUS_ENABLED)
|| NexusAnalyzer.DEFAULT_URL.equals(Settings.getString(Settings.KEYS.ANALYZER_NEXUS_URL))) {
LOGGER.info("Enabling the Solr analyzer");
LOGGER.info("Enabling the Central analyzer");
retval = true;
} else {
LOGGER.info("Nexus analyzer is enabled, disabling Solr");
LOGGER.info("Nexus analyzer is enabled, disabling Central");
}
} else {
LOGGER.info("Solr analyzer disabled");
LOGGER.info("Central analyzer disabled");
}
} catch (InvalidSettingException ise) {
LOGGER.warning("Invalid setting. Disabling the Solr analyzer");
LOGGER.warning("Invalid setting. Disabling the Central analyzer");
}
return retval;
@@ -87,11 +87,11 @@ public class CentralAnalyzer extends AbstractFileTypeAnalyzer {
*/
@Override
public void initializeFileTypeAnalyzer() throws Exception {
LOGGER.fine("Initializing Solr analyzer");
LOGGER.fine(String.format("Solr analyzer enabled: %s", isEnabled()));
LOGGER.fine("Initializing Central analyzer");
LOGGER.fine(String.format("Central analyzer enabled: %s", isEnabled()));
if (isEnabled()) {
final String searchUrl = Settings.getString(Settings.KEYS.ANALYZER_SOLR_URL);
LOGGER.fine(String.format("Solr Analyzer URL: %s", searchUrl));
final String searchUrl = Settings.getString(Settings.KEYS.ANALYZER_CENTRAL_URL);
LOGGER.fine(String.format("Central Analyzer URL: %s", searchUrl));
searcher = new CentralSearch(new URL(searchUrl));
}
}
@@ -112,7 +112,7 @@ public class CentralAnalyzer extends AbstractFileTypeAnalyzer {
*/
@Override
protected String getAnalyzerEnabledSettingKey() {
return Settings.KEYS.ANALYZER_SOLR_ENABLED;
return Settings.KEYS.ANALYZER_CENTRAL_ENABLED;
}
/**
@@ -160,7 +160,7 @@ public class CentralAnalyzer extends AbstractFileTypeAnalyzer {
} catch (FileNotFoundException fnfe) {
LOGGER.fine(String.format("Artifact not found in repository: '%s", dependency.getFileName()));
} catch (IOException ioe) {
LOGGER.log(Level.FINE, "Could not connect to Solr search", ioe);
LOGGER.log(Level.FINE, "Could not connect to Central search", ioe);
errorFlag = true;
}
}

View File

@@ -52,7 +52,7 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
*/
public class NexusAnalyzer extends AbstractFileTypeAnalyzer {
/**
* The default URL - this will be used by the SolrAnalyzer to determine whether to enable this.
* The default URL - this will be used by the CentralAnalyzer to determine whether to enable this.
*/
public static final String DEFAULT_URL = "https://repository.sonatype.org/service/local/";

View File

@@ -21,13 +21,13 @@ import java.util.List;
import java.util.logging.Logger;
/**
* Class of methods to search Maven Central via Solr.
* Class of methods to search Maven Central via Central.
*
* @author colezlaw
*/
public class CentralSearch {
/**
* The URL for the Solr service
* The URL for the Central service
*/
private final URL rootURL;
@@ -55,22 +55,17 @@ public class CentralSearch {
*/
public CentralSearch(URL rootURL) {
this.rootURL = rootURL;
try {
if (null != Settings.getString(Settings.KEYS.PROXY_SERVER)
&& Settings.getBoolean(Settings.KEYS.ANALYZER_SOLR_PROXY)) {
useProxy = true;
LOGGER.fine("Using proxy");
} else {
useProxy = false;
LOGGER.fine("Not using proxy");
}
} catch (InvalidSettingException ise) {
if (null != Settings.getString(Settings.KEYS.PROXY_SERVER)) {
useProxy = true;
LOGGER.fine("Using proxy");
} else {
useProxy = false;
LOGGER.fine("Not using proxy");
}
}
/**
* Searches the configured Solr URL for the given sha1 hash. If the artifact is found, a
* Searches the configured Central URL for the given sha1 hash. If the artifact is found, a
* <code>MavenArtifact</code> is populated with the GAV.
*
* @param sha1 the SHA-1 hash string for which to search
@@ -85,7 +80,7 @@ public class CentralSearch {
final URL url = new URL(rootURL + String.format("?q=1:\"%s\"&wt=xml", sha1));
LOGGER.info(String.format("Searching Solr url %s", url.toString()));
LOGGER.info(String.format("Searching Central url %s", url.toString()));
// Determine if we need to use a proxy. The rules:
// 1) If the proxy is set, AND the setting is set to true, use the proxy
@@ -132,10 +127,10 @@ public class CentralSearch {
}
if (missing) {
throw new FileNotFoundException("Artifact not found in Solr");
throw new FileNotFoundException("Artifact not found in Central");
}
} else {
final String msg = String.format("Could not connect to Solr received response code: %d %s",
final String msg = String.format("Could not connect to Central received response code: %d %s",
conn.getResponseCode(), conn.getResponseMessage());
LOGGER.fine(msg);
throw new IOException(msg);

View File

@@ -60,8 +60,5 @@ analyzer.nexus.url=https://repository.sonatype.org/service/local/
analyzer.nexus.proxy=true
# the URL for searching search.maven.org for SHA-1 and whether it's enabled
analyzer.solr.enabled=true
analyzer.solr.url=http://search.maven.org/solrsearch/select
# If set to true, the proxy will still ONLY be used if the proxy properties (proxy.url, proxy.port)
# are configured
analyzer.solr.proxy=true
analyzer.central.enabled=true
analyzer.central.url=http://search.maven.org/solrsearch/select

View File

@@ -22,9 +22,9 @@ public class CentralSearchTest extends BaseTest {
@Before
public void setUp() throws Exception {
String solrUrl = Settings.getString(Settings.KEYS.ANALYZER_SOLR_URL);
LOGGER.fine(solrUrl);
searcher = new CentralSearch(new URL(solrUrl));
String centralUrl = Settings.getString(Settings.KEYS.ANALYZER_CENTRAL_URL);
LOGGER.fine(centralUrl);
searcher = new CentralSearch(new URL(centralUrl));
}
@Test(expected = IllegalArgumentException.class)
@@ -54,7 +54,7 @@ public class CentralSearchTest extends BaseTest {
searcher.searchSha1("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
}
// This test should give us multiple results back from Solr
// This test should give us multiple results back from Central
@Test
public void testMultipleReturns() throws Exception {
List<MavenArtifact> ma = searcher.searchSha1("94A9CE681A42D0352B3AD22659F67835E560D107");

View File

@@ -61,7 +61,5 @@ analyzer.nexus.url=https://repository.sonatype.org/service/local/
analyzer.nexus.proxy=true
# the URL for searching search.maven.org for SHA-1 and whether it's enabled
analyzer.solr.enabled=true
analyzer.solr.url=http://search.maven.org/solrsearch/select
# If set to true, the proxy will still ONLY be used if the proxy properties (proxy.url, proxy.port)
# are configured
analyzer.central.enabled=true
analyzer.central.url=http://search.maven.org/solrsearch/select

View File

@@ -189,17 +189,13 @@ public final class Settings {
*/
public static final String ANALYZER_NEXUS_PROXY = "analyzer.nexus.proxy";
/**
* The properties key for whether the Solr analyzer is enabled.
* The properties key for whether the Central analyzer is enabled.
*/
public static final String ANALYZER_SOLR_ENABLED = "analyzer.solr.enabled";
public static final String ANALYZER_CENTRAL_ENABLED = "analyzer.central.enabled";
/**
* The properties key for the Solr search URL.
* The properties key for the Central search URL.
*/
public static final String ANALYZER_SOLR_URL = "analyzer.solr.url";
/**
* The properties key for using the proxy to reach Solr.
*/
public static final String ANALYZER_SOLR_PROXY = "analyzer.solr.proxy";
public static final String ANALYZER_CENTRAL_URL = "analyzer.central.url";
/**
* The path to mono, if available.
*/