Merge branch 'colezlaw-master'

Former-commit-id: fdb3a7414550752692ed807d71782f54cabbdac6
This commit is contained in:
Jeremy Long
2014-11-10 05:41:10 -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. * 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. * The phase in which this analyzer runs.
@@ -62,19 +62,19 @@ public class CentralAnalyzer extends AbstractFileTypeAnalyzer {
boolean retval = false; boolean retval = false;
try { 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) if (!Settings.getBoolean(Settings.KEYS.ANALYZER_NEXUS_ENABLED)
|| NexusAnalyzer.DEFAULT_URL.equals(Settings.getString(Settings.KEYS.ANALYZER_NEXUS_URL))) { || 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; retval = true;
} else { } else {
LOGGER.info("Nexus analyzer is enabled, disabling Solr"); LOGGER.info("Nexus analyzer is enabled, disabling Central");
} }
} else { } else {
LOGGER.info("Solr analyzer disabled"); LOGGER.info("Central analyzer disabled");
} }
} catch (InvalidSettingException ise) { } catch (InvalidSettingException ise) {
LOGGER.warning("Invalid setting. Disabling the Solr analyzer"); LOGGER.warning("Invalid setting. Disabling the Central analyzer");
} }
return retval; return retval;
@@ -87,11 +87,11 @@ public class CentralAnalyzer extends AbstractFileTypeAnalyzer {
*/ */
@Override @Override
public void initializeFileTypeAnalyzer() throws Exception { public void initializeFileTypeAnalyzer() throws Exception {
LOGGER.fine("Initializing Solr analyzer"); LOGGER.fine("Initializing Central analyzer");
LOGGER.fine(String.format("Solr analyzer enabled: %s", isEnabled())); LOGGER.fine(String.format("Central analyzer enabled: %s", isEnabled()));
if (isEnabled()) { if (isEnabled()) {
final String searchUrl = Settings.getString(Settings.KEYS.ANALYZER_SOLR_URL); final String searchUrl = Settings.getString(Settings.KEYS.ANALYZER_CENTRAL_URL);
LOGGER.fine(String.format("Solr Analyzer URL: %s", searchUrl)); LOGGER.fine(String.format("Central Analyzer URL: %s", searchUrl));
searcher = new CentralSearch(new URL(searchUrl)); searcher = new CentralSearch(new URL(searchUrl));
} }
} }
@@ -112,7 +112,7 @@ public class CentralAnalyzer extends AbstractFileTypeAnalyzer {
*/ */
@Override @Override
protected String getAnalyzerEnabledSettingKey() { 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) { } catch (FileNotFoundException fnfe) {
LOGGER.fine(String.format("Artifact not found in repository: '%s", dependency.getFileName())); LOGGER.fine(String.format("Artifact not found in repository: '%s", dependency.getFileName()));
} catch (IOException ioe) { } 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; errorFlag = true;
} }
} }

View File

@@ -52,7 +52,7 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
*/ */
public class NexusAnalyzer extends AbstractFileTypeAnalyzer { 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/"; 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; 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 * @author colezlaw
*/ */
public class CentralSearch { public class CentralSearch {
/** /**
* The URL for the Solr service * The URL for the Central service
*/ */
private final URL rootURL; private final URL rootURL;
@@ -55,22 +55,17 @@ public class CentralSearch {
*/ */
public CentralSearch(URL rootURL) { public CentralSearch(URL rootURL) {
this.rootURL = rootURL; this.rootURL = rootURL;
try { if (null != Settings.getString(Settings.KEYS.PROXY_SERVER)) {
if (null != Settings.getString(Settings.KEYS.PROXY_SERVER)
&& Settings.getBoolean(Settings.KEYS.ANALYZER_SOLR_PROXY)) {
useProxy = true; useProxy = true;
LOGGER.fine("Using proxy"); LOGGER.fine("Using proxy");
} else { } else {
useProxy = false; useProxy = false;
LOGGER.fine("Not using proxy"); LOGGER.fine("Not using proxy");
} }
} catch (InvalidSettingException ise) {
useProxy = false;
}
} }
/** /**
* 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. * <code>MavenArtifact</code> is populated with the GAV.
* *
* @param sha1 the SHA-1 hash string for which to search * @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)); 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: // 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 // 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) { if (missing) {
throw new FileNotFoundException("Artifact not found in Solr"); throw new FileNotFoundException("Artifact not found in Central");
} }
} else { } 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()); conn.getResponseCode(), conn.getResponseMessage());
LOGGER.fine(msg); LOGGER.fine(msg);
throw new IOException(msg); throw new IOException(msg);

View File

@@ -60,8 +60,5 @@ analyzer.nexus.url=https://repository.sonatype.org/service/local/
analyzer.nexus.proxy=true analyzer.nexus.proxy=true
# the URL for searching search.maven.org for SHA-1 and whether it's enabled # the URL for searching search.maven.org for SHA-1 and whether it's enabled
analyzer.solr.enabled=true analyzer.central.enabled=true
analyzer.solr.url=http://search.maven.org/solrsearch/select analyzer.central.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

View File

@@ -22,9 +22,9 @@ public class CentralSearchTest extends BaseTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
String solrUrl = Settings.getString(Settings.KEYS.ANALYZER_SOLR_URL); String centralUrl = Settings.getString(Settings.KEYS.ANALYZER_CENTRAL_URL);
LOGGER.fine(solrUrl); LOGGER.fine(centralUrl);
searcher = new CentralSearch(new URL(solrUrl)); searcher = new CentralSearch(new URL(centralUrl));
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
@@ -54,7 +54,7 @@ public class CentralSearchTest extends BaseTest {
searcher.searchSha1("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); searcher.searchSha1("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
} }
// This test should give us multiple results back from Solr // This test should give us multiple results back from Central
@Test @Test
public void testMultipleReturns() throws Exception { public void testMultipleReturns() throws Exception {
List<MavenArtifact> ma = searcher.searchSha1("94A9CE681A42D0352B3AD22659F67835E560D107"); 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 analyzer.nexus.proxy=true
# the URL for searching search.maven.org for SHA-1 and whether it's enabled # the URL for searching search.maven.org for SHA-1 and whether it's enabled
analyzer.solr.enabled=true analyzer.central.enabled=true
analyzer.solr.url=http://search.maven.org/solrsearch/select analyzer.central.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

View File

@@ -189,17 +189,13 @@ public final class Settings {
*/ */
public static final String ANALYZER_NEXUS_PROXY = "analyzer.nexus.proxy"; 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"; public static final String ANALYZER_CENTRAL_URL = "analyzer.central.url";
/**
* The properties key for using the proxy to reach Solr.
*/
public static final String ANALYZER_SOLR_PROXY = "analyzer.solr.proxy";
/** /**
* The path to mono, if available. * The path to mono, if available.
*/ */