mirror of https://github.com/apache/archiva.git
refactor indexer to remove large section of duplicated code
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@412023 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
26e9c3b257
commit
ce80e898d9
|
@ -17,9 +17,9 @@ package org.apache.maven.repository.indexing;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
|
import org.apache.lucene.analysis.CharTokenizer;
|
||||||
import org.apache.lucene.analysis.SimpleAnalyzer;
|
import org.apache.lucene.analysis.SimpleAnalyzer;
|
||||||
import org.apache.lucene.analysis.TokenStream;
|
import org.apache.lucene.analysis.TokenStream;
|
||||||
import org.apache.lucene.analysis.CharTokenizer;
|
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
import org.apache.lucene.index.IndexWriter;
|
import org.apache.lucene.index.IndexWriter;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
|
@ -29,6 +29,7 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract class for RepositoryIndexers
|
* Abstract class for RepositoryIndexers
|
||||||
|
@ -300,6 +301,37 @@ public abstract class AbstractRepositoryIndex
|
||||||
return KEYWORD_FIELDS.contains( field );
|
return KEYWORD_FIELDS.contains( field );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to test a zip entry if it is a java class, and adds it to the classes buffer
|
||||||
|
*
|
||||||
|
* @param entry the zip entry to test for java class
|
||||||
|
* @param classes the String buffer to add the java class if the test result as true
|
||||||
|
* @return true if the zip entry is a java class and was successfully added to the buffer
|
||||||
|
*/
|
||||||
|
protected boolean addIfClassEntry( ZipEntry entry, StringBuffer classes )
|
||||||
|
{
|
||||||
|
boolean isAdded = false;
|
||||||
|
|
||||||
|
String name = entry.getName();
|
||||||
|
if ( name.endsWith( ".class" ) )
|
||||||
|
{
|
||||||
|
// TODO verify if class is public or protected
|
||||||
|
if ( name.lastIndexOf( "$" ) == -1 )
|
||||||
|
{
|
||||||
|
int idx = name.lastIndexOf( '/' );
|
||||||
|
if ( idx < 0 )
|
||||||
|
{
|
||||||
|
idx = 0;
|
||||||
|
}
|
||||||
|
String classname = name.substring( idx + 1, name.length() - 6 );
|
||||||
|
classes.append( classname ).append( "\n" );
|
||||||
|
isAdded = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return isAdded;
|
||||||
|
}
|
||||||
|
|
||||||
private class ArtifactRepositoryIndexAnalyzer
|
private class ArtifactRepositoryIndexAnalyzer
|
||||||
extends Analyzer
|
extends Analyzer
|
||||||
{
|
{
|
||||||
|
|
|
@ -174,37 +174,6 @@ public class ArtifactRepositoryIndex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method to test a zip entry if it is a java class, and adds it to the classes buffer
|
|
||||||
*
|
|
||||||
* @param entry the zip entry to test for java class
|
|
||||||
* @param classes the String buffer to add the java class if the test result as true
|
|
||||||
* @return true if the zip entry is a java class and was successfully added to the buffer
|
|
||||||
*/
|
|
||||||
private boolean addIfClassEntry( ZipEntry entry, StringBuffer classes )
|
|
||||||
{
|
|
||||||
boolean isAdded = false;
|
|
||||||
|
|
||||||
String name = entry.getName();
|
|
||||||
if ( name.endsWith( ".class" ) )
|
|
||||||
{
|
|
||||||
// TODO verify if class is public or protected
|
|
||||||
if ( name.lastIndexOf( "$" ) == -1 )
|
|
||||||
{
|
|
||||||
int idx = name.lastIndexOf( '/' );
|
|
||||||
if ( idx < 0 )
|
|
||||||
{
|
|
||||||
idx = 0;
|
|
||||||
}
|
|
||||||
String classname = name.substring( idx + 1, name.length() - 6 );
|
|
||||||
classes.append( classname ).append( "\n" );
|
|
||||||
isAdded = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return isAdded;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to add a class package to the buffer of packages
|
* Method to add a class package to the buffer of packages
|
||||||
*
|
*
|
||||||
|
|
|
@ -29,11 +29,11 @@ import org.apache.maven.repository.digest.Digester;
|
||||||
import org.codehaus.plexus.util.FileUtils;
|
import org.codehaus.plexus.util.FileUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
|
@ -214,37 +214,6 @@ public class EclipseRepositoryIndex
|
||||||
return outputFile;
|
return outputFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method to test a zip entry if it is a java class, and adds it to the classes buffer
|
|
||||||
*
|
|
||||||
* @param entry the zip entry to test for java class
|
|
||||||
* @param classes the String buffer to add the java class if the test result as true
|
|
||||||
* @return true if the zip entry is a java class and was successfully added to the buffer
|
|
||||||
*/
|
|
||||||
protected boolean addIfClassEntry( ZipEntry entry, StringBuffer classes )
|
|
||||||
{
|
|
||||||
boolean isAdded = false;
|
|
||||||
|
|
||||||
String name = entry.getName();
|
|
||||||
if ( name.endsWith( ".class" ) )
|
|
||||||
{
|
|
||||||
// TODO verify if class is public or protected
|
|
||||||
if ( name.lastIndexOf( "$" ) == -1 )
|
|
||||||
{
|
|
||||||
int idx = name.lastIndexOf( '/' );
|
|
||||||
if ( idx < 0 )
|
|
||||||
{
|
|
||||||
idx = 0;
|
|
||||||
}
|
|
||||||
String classname = name.substring( idx + 1, name.length() - 6 );
|
|
||||||
classes.append( classname ).append( "\n" );
|
|
||||||
isAdded = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return isAdded;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see AbstractRepositoryIndex#deleteIfIndexed(Object)
|
* @see AbstractRepositoryIndex#deleteIfIndexed(Object)
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue