mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-20 08:14:44 +01:00
Merge branch 'hansjoachim-comment'
Former-commit-id: 028894f4e5050e40a93a3fc7ec99c3ca149b9624
This commit is contained in:
@@ -31,8 +31,9 @@ import org.owasp.dependencycheck.utils.Settings;
|
|||||||
*/
|
*/
|
||||||
public class DependencyCheckTaskTest extends BuildFileTest {
|
public class DependencyCheckTaskTest extends BuildFileTest {
|
||||||
//TODO: The use of deprecated class BuildFileTestcan possibly
|
//TODO: The use of deprecated class BuildFileTestcan possibly
|
||||||
//be replaced with BuildFileRule. However, it doesn't seem to be included
|
//be replaced with BuildFileRule. However, it currently isn't included in the ant-testutil jar.
|
||||||
//in the ant-testutil jar.
|
//This should be fixed in ant-testutil 1.9.5, so we can check back once that has been released.
|
||||||
|
//Reference: http://mail-archives.apache.org/mod_mbox/ant-user/201406.mbox/%3C000001cf87ba$8949b690$9bdd23b0$@de%3E
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ public final class CpeMemoryIndex {
|
|||||||
private Analyzer createIndexingAnalyzer() {
|
private Analyzer createIndexingAnalyzer() {
|
||||||
final Map fieldAnalyzers = new HashMap();
|
final Map fieldAnalyzers = new HashMap();
|
||||||
fieldAnalyzers.put(Fields.DOCUMENT_KEY, new KeywordAnalyzer());
|
fieldAnalyzers.put(Fields.DOCUMENT_KEY, new KeywordAnalyzer());
|
||||||
return new PerFieldAnalyzerWrapper(new FieldAnalyzer(LuceneUtils.CURRENT_VERSION), fieldAnalyzers);
|
return new PerFieldAnalyzerWrapper(new FieldAnalyzer(), fieldAnalyzers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -165,12 +165,12 @@ public final class CpeMemoryIndex {
|
|||||||
private Analyzer createSearchingAnalyzer() {
|
private Analyzer createSearchingAnalyzer() {
|
||||||
final Map<String, Analyzer> fieldAnalyzers = new HashMap<String, Analyzer>();
|
final Map<String, Analyzer> fieldAnalyzers = new HashMap<String, Analyzer>();
|
||||||
fieldAnalyzers.put(Fields.DOCUMENT_KEY, new KeywordAnalyzer());
|
fieldAnalyzers.put(Fields.DOCUMENT_KEY, new KeywordAnalyzer());
|
||||||
productSearchFieldAnalyzer = new SearchFieldAnalyzer(LuceneUtils.CURRENT_VERSION);
|
productSearchFieldAnalyzer = new SearchFieldAnalyzer();
|
||||||
vendorSearchFieldAnalyzer = new SearchFieldAnalyzer(LuceneUtils.CURRENT_VERSION);
|
vendorSearchFieldAnalyzer = new SearchFieldAnalyzer();
|
||||||
fieldAnalyzers.put(Fields.PRODUCT, productSearchFieldAnalyzer);
|
fieldAnalyzers.put(Fields.PRODUCT, productSearchFieldAnalyzer);
|
||||||
fieldAnalyzers.put(Fields.VENDOR, vendorSearchFieldAnalyzer);
|
fieldAnalyzers.put(Fields.VENDOR, vendorSearchFieldAnalyzer);
|
||||||
|
|
||||||
return new PerFieldAnalyzerWrapper(new FieldAnalyzer(LuceneUtils.CURRENT_VERSION), fieldAnalyzers);
|
return new PerFieldAnalyzerWrapper(new FieldAnalyzer(), fieldAnalyzers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import org.apache.lucene.analysis.core.LowerCaseFilter;
|
|||||||
import org.apache.lucene.analysis.core.StopAnalyzer;
|
import org.apache.lucene.analysis.core.StopAnalyzer;
|
||||||
import org.apache.lucene.analysis.core.StopFilter;
|
import org.apache.lucene.analysis.core.StopFilter;
|
||||||
import org.apache.lucene.analysis.miscellaneous.WordDelimiterFilter;
|
import org.apache.lucene.analysis.miscellaneous.WordDelimiterFilter;
|
||||||
import org.apache.lucene.util.Version;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -36,19 +35,11 @@ import org.apache.lucene.util.Version;
|
|||||||
*/
|
*/
|
||||||
public class FieldAnalyzer extends Analyzer {
|
public class FieldAnalyzer extends Analyzer {
|
||||||
|
|
||||||
/**
|
|
||||||
* The Lucene Version used.
|
|
||||||
*/
|
|
||||||
private final Version version;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new FieldAnalyzer.
|
* Creates a new FieldAnalyzer.
|
||||||
*
|
*
|
||||||
* @param version the Lucene version
|
|
||||||
*/
|
*/
|
||||||
public FieldAnalyzer(Version version) {
|
public FieldAnalyzer() { }
|
||||||
this.version = version;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the TokenStreamComponents
|
* Creates the TokenStreamComponents
|
||||||
@@ -73,7 +64,7 @@ public class FieldAnalyzer extends Analyzer {
|
|||||||
| WordDelimiterFilter.STEM_ENGLISH_POSSESSIVE, null);
|
| WordDelimiterFilter.STEM_ENGLISH_POSSESSIVE, null);
|
||||||
|
|
||||||
stream = new LowerCaseFilter(stream);
|
stream = new LowerCaseFilter(stream);
|
||||||
stream = new StopFilter(version, stream, StopAnalyzer.ENGLISH_STOP_WORDS_SET);
|
stream = new StopFilter(stream, StopAnalyzer.ENGLISH_STOP_WORDS_SET);
|
||||||
|
|
||||||
return new TokenStreamComponents(source, stream);
|
return new TokenStreamComponents(source, stream);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.owasp.dependencycheck.data.lucene;
|
package org.owasp.dependencycheck.data.lucene;
|
||||||
|
|
||||||
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
import org.apache.lucene.util.Version;
|
import org.apache.lucene.util.Version;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,7 +47,7 @@ public final class LuceneUtils {
|
|||||||
* @param text the data to be escaped
|
* @param text the data to be escaped
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("fallthrough")
|
@SuppressWarnings("fallthrough")
|
||||||
@edu.umd.cs.findbugs.annotations.SuppressWarnings(
|
@SuppressFBWarnings(
|
||||||
value = "SF_SWITCH_NO_DEFAULT",
|
value = "SF_SWITCH_NO_DEFAULT",
|
||||||
justification = "The switch below does have a default.")
|
justification = "The switch below does have a default.")
|
||||||
public static void appendEscapedLuceneQuery(StringBuilder buf,
|
public static void appendEscapedLuceneQuery(StringBuilder buf,
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import org.apache.lucene.analysis.core.LowerCaseFilter;
|
|||||||
import org.apache.lucene.analysis.core.StopAnalyzer;
|
import org.apache.lucene.analysis.core.StopAnalyzer;
|
||||||
import org.apache.lucene.analysis.core.StopFilter;
|
import org.apache.lucene.analysis.core.StopFilter;
|
||||||
import org.apache.lucene.analysis.miscellaneous.WordDelimiterFilter;
|
import org.apache.lucene.analysis.miscellaneous.WordDelimiterFilter;
|
||||||
import org.apache.lucene.util.Version;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Lucene field analyzer used to analyzer queries against the CPE data.
|
* A Lucene field analyzer used to analyzer queries against the CPE data.
|
||||||
@@ -34,10 +33,6 @@ import org.apache.lucene.util.Version;
|
|||||||
*/
|
*/
|
||||||
public class SearchFieldAnalyzer extends Analyzer {
|
public class SearchFieldAnalyzer extends Analyzer {
|
||||||
|
|
||||||
/**
|
|
||||||
* The Lucene Version used.
|
|
||||||
*/
|
|
||||||
private final Version version;
|
|
||||||
/**
|
/**
|
||||||
* A local reference to the TokenPairConcatenatingFilter so that we can clear any left over state if this analyzer
|
* A local reference to the TokenPairConcatenatingFilter so that we can clear any left over state if this analyzer
|
||||||
* is re-used.
|
* is re-used.
|
||||||
@@ -47,11 +42,8 @@ public class SearchFieldAnalyzer extends Analyzer {
|
|||||||
/**
|
/**
|
||||||
* Constructs a new SearchFieldAnalyzer.
|
* Constructs a new SearchFieldAnalyzer.
|
||||||
*
|
*
|
||||||
* @param version the Lucene version
|
|
||||||
*/
|
*/
|
||||||
public SearchFieldAnalyzer(Version version) {
|
public SearchFieldAnalyzer() { }
|
||||||
this.version = version;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a the TokenStreamComponents used to analyze the stream.
|
* Creates a the TokenStreamComponents used to analyze the stream.
|
||||||
@@ -78,7 +70,7 @@ public class SearchFieldAnalyzer extends Analyzer {
|
|||||||
stream = new UrlTokenizingFilter(stream);
|
stream = new UrlTokenizingFilter(stream);
|
||||||
concatenatingFilter = new TokenPairConcatenatingFilter(stream);
|
concatenatingFilter = new TokenPairConcatenatingFilter(stream);
|
||||||
stream = concatenatingFilter;
|
stream = concatenatingFilter;
|
||||||
stream = new StopFilter(version, stream, StopAnalyzer.ENGLISH_STOP_WORDS_SET);
|
stream = new StopFilter(stream, StopAnalyzer.ENGLISH_STOP_WORDS_SET);
|
||||||
|
|
||||||
return new TokenStreamComponents(source, stream);
|
return new TokenStreamComponents(source, stream);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public class FieldAnalyzerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testAnalyzers() throws Exception {
|
public void testAnalyzers() throws Exception {
|
||||||
|
|
||||||
Analyzer analyzer = new FieldAnalyzer(LuceneUtils.CURRENT_VERSION);
|
Analyzer analyzer = new FieldAnalyzer();
|
||||||
Directory index = new RAMDirectory();
|
Directory index = new RAMDirectory();
|
||||||
|
|
||||||
String field1 = "product";
|
String field1 = "product";
|
||||||
@@ -83,12 +83,12 @@ public class FieldAnalyzerTest {
|
|||||||
//Analyzer searchingAnalyzer = new SearchFieldAnalyzer(LuceneUtils.CURRENT_VERSION);
|
//Analyzer searchingAnalyzer = new SearchFieldAnalyzer(LuceneUtils.CURRENT_VERSION);
|
||||||
String querystr = "product:\"(Spring Framework Core)\" vendor:(SpringSource)";
|
String querystr = "product:\"(Spring Framework Core)\" vendor:(SpringSource)";
|
||||||
|
|
||||||
SearchFieldAnalyzer searchAnalyzerProduct = new SearchFieldAnalyzer(LuceneUtils.CURRENT_VERSION);
|
SearchFieldAnalyzer searchAnalyzerProduct = new SearchFieldAnalyzer();
|
||||||
SearchFieldAnalyzer searchAnalyzerVendor = new SearchFieldAnalyzer(LuceneUtils.CURRENT_VERSION);
|
SearchFieldAnalyzer searchAnalyzerVendor = new SearchFieldAnalyzer();
|
||||||
HashMap<String, Analyzer> map = new HashMap<String, Analyzer>();
|
HashMap<String, Analyzer> map = new HashMap<String, Analyzer>();
|
||||||
map.put(field1, searchAnalyzerProduct);
|
map.put(field1, searchAnalyzerProduct);
|
||||||
map.put(field2, searchAnalyzerVendor);
|
map.put(field2, searchAnalyzerVendor);
|
||||||
PerFieldAnalyzerWrapper wrapper = new PerFieldAnalyzerWrapper(new StandardAnalyzer(LuceneUtils.CURRENT_VERSION), map);
|
PerFieldAnalyzerWrapper wrapper = new PerFieldAnalyzerWrapper(new StandardAnalyzer(), map);
|
||||||
QueryParser parser = new QueryParser(field1, wrapper);
|
QueryParser parser = new QueryParser(field1, wrapper);
|
||||||
|
|
||||||
Query q = parser.parse(querystr);
|
Query q = parser.parse(querystr);
|
||||||
|
|||||||
Reference in New Issue
Block a user