You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by oc...@apache.org on 2006/06/15 13:05:05 UTC
svn commit: r414556 - in
/maven/repository-manager/trunk/maven-repository-webapp: ./
src/main/java/org/apache/maven/repository/manager/web/action/
src/main/java/org/apache/maven/repository/manager/web/utils/
src/main/resources/ src/main/webapp/WEB-INF/...
Author: oching
Date: Thu Jun 15 04:05:04 2006
New Revision: 414556
URL: http://svn.apache.org/viewvc?rev=414556&view=rev
Log:
PR: MRM-67
Created ConfigurationManager class that creates and updates the xml configuration file. Added web interface for setting and updating configuration used for indexing and discovery.
Added:
maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/IndexConfigurationAction.java
maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/utils/
maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/utils/ConfigurationManager.java
maven/repository-manager/trunk/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/indexConfigUpdateSuccess.jsp
maven/repository-manager/trunk/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/indexconfig.jsp
Modified:
maven/repository-manager/trunk/maven-repository-webapp/pom.xml
maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BaseAction.java
maven/repository-manager/trunk/maven-repository-webapp/src/main/resources/xwork.xml
maven/repository-manager/trunk/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/index.jsp
Modified: maven/repository-manager/trunk/maven-repository-webapp/pom.xml
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-webapp/pom.xml?rev=414556&r1=414555&r2=414556&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-webapp/pom.xml (original)
+++ maven/repository-manager/trunk/maven-repository-webapp/pom.xml Thu Jun 15 04:05:04 2006
@@ -65,6 +65,11 @@
<artifactId>plexus-quartz</artifactId>
<version>1.0-alpha-2</version>
</dependency>
+ <dependency>
+ <groupId>dom4j</groupId>
+ <artifactId>dom4j</artifactId>
+ <version>1.6.1</version>
+ </dependency>
</dependencies>
<build>
<finalName>maven-repository-webapp</finalName>
Modified: maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BaseAction.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BaseAction.java?rev=414556&r1=414555&r2=414556&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BaseAction.java (original)
+++ maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BaseAction.java Thu Jun 15 04:05:04 2006
@@ -16,12 +16,16 @@
* limitations under the License.
*/
-import com.opensymphony.xwork.Action;
+import com.opensymphony.xwork.ActionSupport;
+import com.opensymphony.webwork.interceptor.ParameterAware;
import org.apache.maven.repository.configuration.Configuration;
import org.apache.maven.repository.manager.web.execution.DiscovererExecution;
import org.apache.maven.repository.manager.web.job.DiscovererScheduler;
+import org.apache.maven.repository.manager.web.utils.ConfigurationManager;
import java.io.File;
+import java.util.Map;
+import java.util.HashMap;
/**
* This is the Action class of index.jsp, which is the initial page of the web application.
@@ -30,7 +34,8 @@
* @plexus.component role="com.opensymphony.xwork.Action" role-hint="org.apache.maven.repository.manager.web.action.BaseAction"
*/
public class BaseAction
- implements Action
+ extends ActionSupport
+ implements ParameterAware
{
/**
* @plexus.requirement
@@ -43,6 +48,21 @@
private DiscovererScheduler discovererScheduler;
/**
+ * @plexus.requirement
+ */
+ private ConfigurationManager configManager;
+
+ private Map parameters;
+
+ public Map getParameters() {
+ return parameters;
+ }
+
+ public void setParameters(Map parameters) {
+ this.parameters = parameters;
+ }
+
+ /**
* Method that executes the action
*
* @return a String that specifies if the action executed was a success or a failure
@@ -51,9 +71,17 @@
{
try
{
- Configuration configuration = new Configuration(); // TODO!
- execution.executeDiscovererIfIndexDoesNotExist( new File( configuration.getIndexPath() ) );
- discovererScheduler.setSchedule( configuration.getDiscoveryCronExpression() );
+ Configuration config = configManager.getConfiguration();
+ Map parameters = new HashMap();
+ parameters.put( ConfigurationManager.INDEXPATH, config.getIndexPath() );
+ parameters.put( ConfigurationManager.MIN_INDEXPATH, config.getMinimalIndexPath() );
+ parameters.put( ConfigurationManager.DISCOVERY_BLACKLIST_PATTERNS, config.getDiscoveryBlackListPatterns() );
+ parameters.put( ConfigurationManager.DISCOVER_SNAPSHOTS, new Boolean( config.isDiscoverSnapshots() ) );
+ setParameters( parameters );
+
+ //Configuration configuration = new Configuration(); // TODO!
+ execution.executeDiscovererIfIndexDoesNotExist( new File( config.getIndexPath() ) );
+ discovererScheduler.setSchedule( config.getDiscoveryCronExpression() );
}
catch ( Exception e )
{
Added: maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/IndexConfigurationAction.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/IndexConfigurationAction.java?rev=414556&view=auto
==============================================================================
--- maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/IndexConfigurationAction.java (added)
+++ maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/IndexConfigurationAction.java Thu Jun 15 04:05:04 2006
@@ -0,0 +1,74 @@
+package org.apache.maven.repository.manager.web.action;
+
+import com.opensymphony.xwork.Action;
+import com.opensymphony.webwork.interceptor.ParameterAware;
+
+import java.util.Map;
+import java.util.HashMap;
+
+import org.apache.maven.repository.manager.web.utils.ConfigurationManager;
+
+
+/**
+ * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
+ *
+ * @plexus.component role="com.opensymphony.xwork.Action" role-hint="org.apache.maven.repository.manager.web.action.IndexConfigurationAction"
+ */
+public class IndexConfigurationAction
+ implements Action, ParameterAware
+{
+ private Map parameters;
+
+ /**
+ * @plexus.requirement
+ */
+ private ConfigurationManager configManager;
+
+ public Map getParameters() {
+ return parameters;
+ }
+
+ public void setParameters(Map parameters) {
+ this.parameters = parameters;
+ }
+
+ /**
+ * Method that is executed when the action is invoked.
+ *
+ * @return a String that specifies where to go to next
+ * @throws Exception
+ */
+ public String execute()
+ throws Exception
+ {
+ String[] indexPath = (String[]) parameters.get( ConfigurationManager.INDEXPATH );
+ Map map = new HashMap();
+
+ if ( indexPath != null && indexPath.length == 1 && indexPath[0] != null )
+ {
+ String[] discoverSnapshots = (String[]) parameters.get( ConfigurationManager.DISCOVER_SNAPSHOTS );
+ String[] minimalIndexPath = (String[]) parameters.get( ConfigurationManager.MIN_INDEXPATH );
+ if( minimalIndexPath != null && minimalIndexPath.length == 1 && minimalIndexPath[0] != null )
+ {
+ map.put( ConfigurationManager.MIN_INDEXPATH, minimalIndexPath[0] );
+ }
+
+ map.put( ConfigurationManager.INDEXPATH, indexPath[0] );
+ map.put( ConfigurationManager.DISCOVER_SNAPSHOTS, discoverSnapshots[0] );
+
+ String[] blacklistPatterns = ( String[] ) parameters.get( ConfigurationManager.DISCOVERY_BLACKLIST_PATTERNS );
+ if( blacklistPatterns != null && blacklistPatterns.length == 1 && blacklistPatterns[0] != null )
+ {
+ map.put( ConfigurationManager.DISCOVERY_BLACKLIST_PATTERNS, blacklistPatterns[0] );
+ }
+
+ configManager.updateConfiguration( map );
+
+ return SUCCESS;
+ }
+ else
+ {
+ return ERROR;
+ }
+ }
+}
Added: maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/utils/ConfigurationManager.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/utils/ConfigurationManager.java?rev=414556&view=auto
==============================================================================
--- maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/utils/ConfigurationManager.java (added)
+++ maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/utils/ConfigurationManager.java Thu Jun 15 04:05:04 2006
@@ -0,0 +1,296 @@
+package org.apache.maven.repository.manager.web.utils;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
+import org.apache.maven.repository.configuration.Configuration;
+import org.apache.maven.repository.configuration.io.xpp3.ConfigurationXpp3Writer;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * This class updates the configuration in plexus.xml
+ *
+ * @plexus.component role="org.apache.maven.repository.manager.web.utils.ConfigurationManager"
+ */
+public class ConfigurationManager
+{
+ public static final String WEB_XML_FILE = "web.xml";
+
+ public static final String INDEX_CONFIG_FILE = "mrm-admin-config.xml";
+
+ public static final String CONFIGURATION = "configuration";
+
+ public static final String DISCOVER_SNAPSHOTS = "discoverSnapshots";
+
+ public static final String DISCOVERY_CRON_EXPRESSION = "discoveryCronExpression";
+
+ public static final String INDEXPATH = "indexPath";
+
+ public static final String MIN_INDEXPATH = "minimalIndexPath";
+
+ public static final String REPOSITORY_LAYOUT = "repositoryLayout";
+
+ public static final String REPOSITORY_DIRECTORY = "repositoryDirectory";
+
+ public static final String DISCOVERY_BLACKLIST_PATTERNS = "discoveryBlacklistPatterns";
+
+
+ private Configuration config;
+
+ private File plexusDescriptor;
+
+ private Document document;
+
+ /**
+ * Method for updating the configuration in plexus.xml
+ *
+ * @param map contains the fields and the values to be updated in the configuration
+ */
+ public void updateConfiguration( Map map )
+ throws IOException
+ {
+ File file = getConfigFile();
+
+ try
+ {
+ document = readXmlDocument( file );
+ }
+ catch ( DocumentException de )
+ {
+ de.printStackTrace();
+ }
+
+ Element rootElement = document.getRootElement();
+ for( Iterator iter2 = rootElement.elementIterator(); iter2.hasNext(); )
+ {
+ Element field = (Element) iter2.next();
+ if( !map.containsKey( field.getName() ) )
+ {
+ map.put( field.getName(), field.getData() );
+ }
+ }
+
+ for( Iterator iter = map.entrySet().iterator();iter.hasNext(); )
+ {
+ Map.Entry entry = (Map.Entry) iter.next();
+ String name = (String) entry.getKey();
+ String value = ( String ) entry.getValue();
+
+ if( name.equals( DISCOVERY_CRON_EXPRESSION ) )
+ {
+ config.setDiscoveryCronExpression( value );
+ }
+ if( name.equals( REPOSITORY_LAYOUT ) )
+ {
+ config.setRepositoryLayout( value );
+ }
+ if( name.equals( DISCOVER_SNAPSHOTS ) )
+ {
+ config.setDiscoverSnapshots( Boolean.getBoolean( value ) );
+ }
+ if( name.equals( REPOSITORY_DIRECTORY ) )
+ {
+ config.setRepositoryDirectory( value );
+ }
+ if( name.equals( INDEXPATH ) )
+ {
+ config.setIndexPath( value );
+ }
+ if( name.equals( MIN_INDEXPATH ) )
+ {
+ config.setMinimalIndexPath( value );
+ }
+ if( name.equals( DISCOVERY_BLACKLIST_PATTERNS ) )
+ {
+ config.setDiscoveryBlackListPatterns( value );
+ }
+ }
+
+ writeXmlDocument( getConfigFile() );
+ }
+
+ /**
+ * Method that gets the properties set in the index-config.xml for the configuration fields
+ * used in the schedule, indexing and discovery
+ *
+ * @return a Map that contains the elements in the properties of the configuration object
+ */
+ public Configuration getConfiguration()
+ throws IOException
+ {
+ Map map = null;
+ File file = getConfigFile();
+ config = new Configuration();
+
+ if( !file.exists() )
+ {
+ writeXmlDocument( getConfigFile() );
+ }
+ else
+ {
+ try
+ {
+ document = readXmlDocument( file );
+ }
+ catch ( DocumentException de )
+ {
+ de.printStackTrace();
+ }
+
+ map = new HashMap();
+ Element rootElement = document.getRootElement();
+ for( Iterator iter2 = rootElement.elementIterator(); iter2.hasNext(); )
+ {
+ Element field = (Element) iter2.next();
+ map.put( field.getName(), field.getData() );
+ }
+
+ if( map.get( DISCOVERY_CRON_EXPRESSION ) != null && !"".equals( map.get( DISCOVERY_CRON_EXPRESSION ) ) )
+ {
+ config.setDiscoveryCronExpression( ( String ) map.get( DISCOVERY_CRON_EXPRESSION ) );
+ }
+
+ if( map.get( REPOSITORY_LAYOUT ) != null && !"".equals( map.get( REPOSITORY_LAYOUT ) ) )
+ {
+ config.setRepositoryLayout( (String ) map.get( REPOSITORY_LAYOUT ) );
+ }
+
+ if( map.get( DISCOVER_SNAPSHOTS ) != null && !"".equals( map.get( DISCOVER_SNAPSHOTS ) ) )
+ {
+ config.setDiscoverSnapshots( ( ( Boolean ) map.get( DISCOVER_SNAPSHOTS ) ).booleanValue() );
+ }
+
+ if( map.get( REPOSITORY_DIRECTORY ) != null && !"".equals( map.get( REPOSITORY_DIRECTORY ) ) )
+ {
+ config.setRepositoryDirectory( ( String ) map.get( REPOSITORY_DIRECTORY ) );
+ }
+
+ if( map.get( INDEXPATH ) != null && !"".equals( map.get( INDEXPATH ) ) )
+ {
+ config.setIndexPath( ( String ) map.get( INDEXPATH ) );
+ }
+
+ if( map.get( MIN_INDEXPATH ) != null && !"".equals( map.get( MIN_INDEXPATH ) ) )
+ {
+ config.setMinimalIndexPath( ( String ) map.get( MIN_INDEXPATH ) );
+ }
+
+ if( map.get( DISCOVERY_BLACKLIST_PATTERNS ) != null && !"".equals( map.get( DISCOVERY_BLACKLIST_PATTERNS ) ) )
+ {
+ config.setDiscoveryBlackListPatterns( ( String ) map.get( DISCOVERY_BLACKLIST_PATTERNS ) );
+ }
+ }
+
+ return config;
+ }
+
+ /**
+ * Method that reads the xml file and puts it in a Document object
+ *
+ * @param file the xml file to be read
+ * @return a Document object that represents the contents of the xml file
+ * @throws DocumentException
+ */
+ protected Document readXmlDocument( File file )
+ throws DocumentException
+ {
+ SAXReader reader = new SAXReader();
+ if ( file.exists() )
+ {
+ return reader.read( file );
+ }
+
+ return null;
+ }
+
+ /**
+ * Method for removing the specified element from the document
+ *
+ * @param element
+ * @param name
+ */
+ protected void removeElement( Element element, String name )
+ {
+ for( Iterator children = element.elementIterator(); children.hasNext(); )
+ {
+ Element child = (Element) children.next();
+ if( child.getName().equals( name ) )
+ {
+ element.remove( child );
+ }
+ }
+ }
+
+ protected Element addElement( Element element, String name )
+ {
+ return element.addElement( name );
+ }
+
+ protected void setElementValue( Element element, String value )
+ {
+ element.setText( value );
+ }
+
+ protected Element addAndSetElement( Element element, String elementName, String elementValue )
+ {
+ Element retElement = addElement( element, elementName );
+
+ setElementValue( retElement, elementValue );
+
+ return retElement;
+ }
+
+ /**
+ * Method for writing the document object into its corresponding
+ * xml file.
+ *
+ * @param file the file where the document will be written to
+ */
+ protected void writeXmlDocument( File file )
+ throws IOException
+ {
+ Writer writer = new FileWriter( file );
+ ConfigurationXpp3Writer configWriter = new ConfigurationXpp3Writer();
+ configWriter.write( writer, config );
+ }
+
+ /**
+ * Method that returns the index-config.xml file
+ *
+ * @return a File that references the plexus.xml
+ */
+ protected File getConfigFile()
+ {
+ URL indexConfigXml = getClass().getClassLoader().getResource( "../" + INDEX_CONFIG_FILE );
+
+ if( indexConfigXml != null )
+ {
+ plexusDescriptor = new File( indexConfigXml.getFile() );
+ }
+ else
+ {
+ URL xmlPath = getClass().getClassLoader().getResource( "../" + WEB_XML_FILE );
+ String path = xmlPath.getFile();
+ int lastIndex = path.lastIndexOf( '/' );
+ path = path.substring( 0, lastIndex + 1 );
+ path = path + INDEX_CONFIG_FILE;
+ plexusDescriptor = new File ( path );
+ }
+
+ return plexusDescriptor;
+ }
+
+ protected Document getDocument()
+ {
+ return document;
+ }
+}
Modified: maven/repository-manager/trunk/maven-repository-webapp/src/main/resources/xwork.xml
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-webapp/src/main/resources/xwork.xml?rev=414556&r1=414555&r2=414556&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-webapp/src/main/resources/xwork.xml (original)
+++ maven/repository-manager/trunk/maven-repository-webapp/src/main/resources/xwork.xml Thu Jun 15 04:05:04 2006
@@ -46,6 +46,12 @@
<result name="success" type="dispatcher">/WEB-INF/jsp/browse.jsp</result>
<result name="error" type="dispatcher">/WEB-INF/jsp/browse.jsp</result>
</action>
+
+ <action name="configureIndex" class="org.apache.maven.repository.manager.web.action.IndexConfigurationAction">
+ <result name="success" type="dispatcher">/WEB-INF/jsp/indexConfigUpdateSuccess.jsp</result>
+ <result name="error" type="dispatcher">/WEB-INF/jsp/index.jsp</result>
+ </action>
+
</package>
</xwork>
Modified: maven/repository-manager/trunk/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/index.jsp
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/index.jsp?rev=414556&r1=414555&r2=414556&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/index.jsp (original)
+++ maven/repository-manager/trunk/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/index.jsp Thu Jun 15 04:05:04 2006
@@ -25,6 +25,9 @@
<h1>Maven Repository Manager</h1>
<%@ include file="form.jspf" %>
+<p/>
+<%@ include file="indexconfig.jsp" %>
+<p/>
</body>
-</html>
\ No newline at end of file
+</html>
Added: maven/repository-manager/trunk/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/indexConfigUpdateSuccess.jsp
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/indexConfigUpdateSuccess.jsp?rev=414556&view=auto
==============================================================================
--- maven/repository-manager/trunk/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/indexConfigUpdateSuccess.jsp (added)
+++ maven/repository-manager/trunk/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/indexConfigUpdateSuccess.jsp Thu Jun 15 04:05:04 2006
@@ -0,0 +1,24 @@
+<%@ taglib uri="webwork" prefix="ww" %>
+<html>
+<head>
+ <title>Maven Repository Manager</title>
+</head>
+
+<body>
+
+<h1>Index Configuration</h1>
+<br>
+Index configuration was updated successfully.
+<br>
+<%--
+Index Path: <ww:property value="parameters.indexPath"/>
+<br>
+Blacklist Patterns: <ww:property value="parameters.blacklistPatterns"/>
+<br>
+Include Snapshots: <ww:property value="parameters.includeSnapshots"/>
+<br>
+Convert Snapshots: <ww:property value="parameters.convertSnapshots"/>
+--%>
+
+</body>
+</html>
\ No newline at end of file
Added: maven/repository-manager/trunk/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/indexconfig.jsp
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/indexconfig.jsp?rev=414556&view=auto
==============================================================================
--- maven/repository-manager/trunk/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/indexconfig.jsp (added)
+++ maven/repository-manager/trunk/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/indexconfig.jsp Thu Jun 15 04:05:04 2006
@@ -0,0 +1,36 @@
+<%--
+ ~ Copyright 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" %>
+
+<br>
+<p>
+<b>INDEX CONFIGURATION:</b>
+</p>
+
+<form action="configureIndex.action" method="get">
+ Index Path: <input type="text" name="indexPath" value="<ww:property value="parameters.indexPath"/>"/>
+ <br>
+ Minimal Index Path: <input type="text" name="minimalIndexPath" value="<ww:property value="parameters.minimalIndexPath"/>"/>
+ <br>
+ Blacklist Patterns: <input type="text" name="discoveryBlacklistPatterns" value="<ww:property value="parameters.discoveryBlacklistPatterns"/>"/>
+ <br>
+ Discover Snapshots: <input type="text" name="discoverSnapshots" value="<ww:property value="parameters.discoverSnapshots"/>"/>
+ <input type="submit" value="Update"/>
+</form>
+
+