*/
private ConfigurationStore configurationStore;
- private static final String NO_RESULTS = "noResults";
-
private static final String RESULTS = "results";
private static final String ARTIFACT = "artifact";
return ERROR;
}
- // TODO! this is correct, but ugly
MultiFieldQueryParser parser = new MultiFieldQueryParser( new String[]{StandardIndexRecordFields.GROUPID,
StandardIndexRecordFields.ARTIFACTID, StandardIndexRecordFields.BASE_VERSION,
StandardIndexRecordFields.CLASSIFIER, StandardIndexRecordFields.CLASSES, StandardIndexRecordFields.FILES,
StandardIndexRecordFields.PROJECT_DESCRIPTION}, new StandardAnalyzer() );
searchResults = index.search( new LuceneQuery( parser.parse( q ) ) );
+ if ( searchResults.isEmpty() )
+ {
+ addActionError( "No results found" );
+ return INPUT;
+ }
+
return SUCCESS;
}
if ( searchResults.isEmpty() )
{
- return NO_RESULTS;
+ addActionError( "No results found" );
+ return INPUT;
}
if ( searchResults.size() == 1 )
{
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.project.MavenProject;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* Browse the repository.
private final String artifactId;
- private List versions = new ArrayList();
+ /**
+ * Versions added. We ignore duplicates since you might add those with varying classifiers.
+ */
+ private Set versions = new HashSet();
private String version;
return classifier;
}
+ private static class Ver
+ {
+ private int buildNumber;
+
+ private int major;
+
+ private int minor;
+
+ private int incremental;
+
+ private String qualifier;
+
+
+ }
+
public void addVersion( String version )
{
- versions.add( version );
+ // We use DefaultArtifactVersion to get the correct sorting order later, however it does not have
+ // hashCode properly implemented, so we add it here.
+ // TODO: add these methods to the actual DefaultArtifactVersion and use that.
+ versions.add( new DefaultArtifactVersion( version )
+ {
+ public int hashCode()
+ {
+ int result;
+ result = getBuildNumber();
+ result = 31 * result + getMajorVersion();
+ result = 31 * result + getMinorVersion();
+ result = 31 * result + getIncrementalVersion();
+ result = 31 * result + ( getQualifier() != null ? getQualifier().hashCode() : 0 );
+ return result;
+ }
+
+ public boolean equals( Object o )
+ {
+ if ( this == o )
+ {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() )
+ {
+ return false;
+ }
+
+ DefaultArtifactVersion that = (DefaultArtifactVersion) o;
+
+ if ( getBuildNumber() != that.getBuildNumber() )
+ {
+ return false;
+ }
+ if ( getIncrementalVersion() != that.getIncrementalVersion() )
+ {
+ return false;
+ }
+ if ( getMajorVersion() != that.getMajorVersion() )
+ {
+ return false;
+ }
+ if ( getMinorVersion() != that.getMinorVersion() )
+ {
+ return false;
+ }
+ if ( getQualifier() != null ? !getQualifier().equals( that.getQualifier() )
+ : that.getQualifier() != null )
+ {
+ return false;
+ }
+
+ return true;
+ }
+ } );
if ( versions.size() == 1 )
{
else
{
this.version = null;
- // TODO: use version comparator!
- Collections.sort( versions );
}
}
public List getVersions()
{
+ List versions = new ArrayList( this.versions );
+ Collections.sort( versions );
return versions;
}
<result name="input">/WEB-INF/jsp/quickSearch.jsp</result>
<result>/WEB-INF/jsp/results.jsp</result>
<result name="error">/WEB-INF/jsp/quickSearch.jsp</result>
- <result name="noResults">/WEB-INF/jsp/noResults.jsp</result>
- <!-- TODO! -->
</action>
<action name="findArtifact" class="searchAction" method="input">
<result name="input">/WEB-INF/jsp/findArtifact.jsp</result>
<result name="results">/WEB-INF/jsp/results.jsp</result>
<result name="error">/WEB-INF/jsp/findArtifact.jsp</result>
- <result name="noResults">/WEB-INF/jsp/noResults.jsp</result>
- <!-- TODO! -->
<result name="artifact" type="redirect">
/browse/${searchResults[0].groupId}/${searchResults[0].artifactId}/${searchResults[0].version}
</result>