PR: MRM-81

Submitted by: John Tolentino

Applied patch for general search webapp and configuration

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@381994 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Edwin L. Punzalan 2006-03-01 11:39:07 +00:00
parent a6887b9758
commit 8d1880e028
7 changed files with 299 additions and 3 deletions

View File

@ -0,0 +1,83 @@
package org.apache.maven.repository.manager.web.action;
import com.opensymphony.xwork.Action;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.repository.indexing.ArtifactRepositoryIndex;
import org.apache.maven.repository.indexing.RepositoryIndexException;
import org.apache.maven.repository.indexing.RepositoryIndexSearchException;
import org.apache.maven.repository.indexing.RepositoryIndexSearchLayer;
import org.apache.maven.repository.indexing.RepositoryIndexingFactory;
import org.apache.maven.repository.manager.web.job.Configuration;
import java.io.File;
import java.net.MalformedURLException;
import java.util.List;
/**
* Searches for searchString in all indexed fields.
*
* @plexus.component role="com.opensymphony.xwork.Action" role-hint="org.apache.maven.repository.manager.web.action.GeneralSearchAction"
*/
public class GeneralSearchAction
implements Action
{
private String searchString;
private List searchResult;
/**
* @plexus.requirement
*/
private RepositoryIndexingFactory factory;
/**
* @plexus.requirement
*/
private ArtifactRepositoryFactory repositoryFactory;
/**
* @plexus.requirement
*/
private Configuration configuration;
public String execute()
throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException
{
if ( searchString != null && searchString.length() != 0 )
{
String indexPath = configuration.getIndexDirectory();
// TODO: reduce the amount of lookup?
File repositoryDirectory = new File( configuration.getRepositoryDirectory() );
String repoDir = repositoryDirectory.toURL().toString();
ArtifactRepository repository =
repositoryFactory.createArtifactRepository( "test", repoDir, configuration.getLayout(), null, null );
ArtifactRepositoryIndex index = factory.createArtifactRepositoryIndex( indexPath, repository );
RepositoryIndexSearchLayer searchLayer = factory.createRepositoryIndexSearchLayer( index );
searchResult = searchLayer.searchGeneral( searchString );
return SUCCESS;
}
else
{
return ERROR;
}
}
public void setSearchString( String searchString )
{
this.searchString = searchString;
}
public List getSearchResult()
{
return searchResult;
}
}

View File

@ -21,13 +21,12 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.repository.indexing.ArtifactRepositoryIndex;
import org.apache.maven.repository.indexing.DefaultRepositoryIndexSearcher;
import org.apache.maven.repository.indexing.RepositoryIndexException;
import org.apache.maven.repository.indexing.RepositoryIndexSearchException;
import org.apache.maven.repository.indexing.RepositoryIndexingFactory;
import org.apache.maven.repository.indexing.DefaultRepositoryIndexSearcher;
import org.apache.maven.repository.indexing.query.SinglePhraseQuery;
import org.codehaus.plexus.scheduler.Scheduler;
import org.codehaus.plexus.scheduler.configuration.SchedulerConfiguration;
import java.io.File;
import java.net.MalformedURLException;
@ -89,7 +88,7 @@ public class PackageSearchAction
}
// TODO: better config
String indexPath = "c:/home/brett/repository/.index";
String indexPath = "C:/0John/java/projects/repository-manager/maven-repository-indexer/target/index";
// TODO: reduce the amount of lookup?
ArtifactRepository repository = repositoryFactory.createArtifactRepository( "repository", new File(

View File

@ -0,0 +1,83 @@
package org.apache.maven.repository.manager.web.job;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.artifact.repository.layout.LegacyRepositoryLayout;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import java.util.Properties;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
*
*/
public class Configuration
implements Initializable
{
private Properties props;
public void initialize()
throws InitializationException
{
System.out.println( "Configuration initialized" );
}
public void setProperties( Properties properties )
{
this.props = properties;
}
public Properties getProperties()
{
return props;
}
public ArtifactRepositoryLayout getLayout()
{
ArtifactRepositoryLayout layout;
if ( "legacy".equals( props.getProperty( "layout" ) ) )
{
layout = new LegacyRepositoryLayout();
}
else
{
layout = new DefaultRepositoryLayout();
}
return layout;
}
public String getIndexDirectory()
{
return props.getProperty( "index.path" );
}
public String getRepositoryDirectory()
{
String repositoryDir = "";
if ( "default".equals( props.getProperty( "layout" ) ) )
{
repositoryDir = props.getProperty( "default.repository.dir" );
}
else if ( "legacy".equals( props.getProperty( "layout" ) ) )
{
repositoryDir = props.getProperty( "legacy.repository.dir" );
}
return repositoryDir;
}
}

View File

@ -31,6 +31,11 @@
<result name="success" type="dispatcher">/WEB-INF/jsp/index.jsp</result>
</action>
<action name="searchg" class="org.apache.maven.repository.manager.web.action.GeneralSearchAction">
<result name="success" type="dispatcher">/WEB-INF/jsp/generalresults.jsp</result>
<result name="error" type="dispatcher">/WEB-INF/jsp/index.jsp</result>
</action>
<action name="search" class="org.apache.maven.repository.manager.web.action.PackageSearchAction">
<result name="success" type="dispatcher">/WEB-INF/jsp/results.jsp</result>
<result name="error" type="dispatcher">/WEB-INF/jsp/index.jsp</result>

View File

@ -84,6 +84,13 @@
<!--"END_CONVERTED_APPLET"-->
</p>
<p>Search:
<form action="searchg.action">
<input name="searchString" type="text"/>
<input type="submit" value="Search"/>
</form>
</p>
<p>Search by Java Package:
<form action="search.action">
<input name="packageName" type="text"/>

View File

@ -0,0 +1,67 @@
<%--
~ Copyright 2005-2006 The Apache Software Foundation.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
--%>
<%@ taglib uri="webwork" prefix="ww" %>
<html>
<head>
<title>Maven Repository Manager</title>
</head>
<body>
<h1>Maven Repository Manager</h1>
<%@include file="form.jspf"%>
<table border="1px" cellspacing="0">
<tr>
<th>Group ID</th>
<th>Artifact ID</th>
<th>Version</th>
<th>Hits</th>
</tr>
<ww:iterator value="searchResult">
<tr>
<td valign="top">
<ww:property value="Artifact.getGroupId()"/>
</td>
<td valign="top">
<ww:property value="Artifact.getArtifactId()"/>
</td>
<td valign="top">
<ww:property value="Artifact.getVersion()"/>
</td>
<td valign="top">
<table border="1px" width="100%" cellspacing="0">
<ww:iterator value="FieldMatchesEntrySet">
<tr>
<td valign="top" width="15%" align="right"><ww:property value="Key"/></td>
<td valign="top">
<ww:iterator value="Value" id="test" status="" >
<ww:property />
</ww:iterator>
<br/>
</td>
</tr>
</ww:iterator>
</table>
</td>
</tr>
</ww:iterator>
</table>
</body>
</html>

View File

@ -28,15 +28,67 @@
</load-on-start>
-->
<components>
<!--
| Object factory for WebWork
-->
<component>
<role>com.opensymphony.xwork.ObjectFactory</role>
<implementation>org.codehaus.plexus.xwork.PlexusObjectFactory</implementation>
</component>
<component>
<role>org.apache.maven.repository.manager.web.job.Configuration</role>
<implementation>org.apache.maven.repository.manager.web.job.Configuration</implementation>
<configuration>
<properties>
<property>
<name>layout</name>
<value>default</value>
</property>
<property>
<name>default.repository.dir</name>
<value>C:/TEST_REPOS/repository</value>
</property>
<property>
<name>legacy.repository.dir</name>
<value>C:/TEST_REPOS/.maven/repository/</value>
</property>
<property>
<name>index.path</name>
<value>C:/INDEX</value>
</property>
<property>
<name>cron.expression</name>
<value>0 0 8 * * ?</value>
</property>
<property>
<name>blacklist.patterns</name>
<value>null</value>
</property>
<property>
<name>include.snapshots</name>
<value>true</value>
</property>
<property>
<name>convert.snapshots</name>
<value>true</value>
</property>
</properties>
</configuration>
</component>
<!--
<component>
<role>org.apache.maven.repository.manager.web.job.DiscovererJob</role>
</component>
-->
<!--
| Logger manager