MRM-594 support for custom legacy-path-2-artifact-reference resolution

Web UI to register new exceptions to the artifact resolution algorithm.


git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@603891 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nicolas De Loof 2007-12-13 11:36:18 +00:00
parent 678173ca42
commit 95271f756e
7 changed files with 556 additions and 3 deletions

View File

@ -0,0 +1,111 @@
package org.apache.maven.archiva.web.action.admin.legacy;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
import org.apache.maven.archiva.configuration.LegacyArtifactPath;
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.plexus.xwork.action.PlexusActionSupport;
import com.opensymphony.xwork.Preparable;
/**
* Add a LegacyArtifactPath to archiva configuration
*
*
* @plexus.component role="com.opensymphony.xwork.Action" role-hint="addLegacyArtifactPathAction"
*/
public class AddLegacyArtifactPathAction
extends PlexusActionSupport
implements Preparable
{
/**
* @plexus.requirement
*/
private ArchivaConfiguration archivaConfiguration;
/**
* @plexus.requirement role-hint="legacy"
*/
private ManagedRepositoryContent repositoryContent;
private LegacyArtifactPath legacyArtifactPath;
public void prepare()
{
this.legacyArtifactPath = new LegacyArtifactPath();
}
public String input()
{
return INPUT;
}
public String commit()
{
ArtifactReference artifact = this.legacyArtifactPath.getArtifactReference();
String path = repositoryContent.toPath( artifact );
if ( ! path.equals( this.legacyArtifactPath.getPath() ) )
{
addActionError( "artifact reference does not match the initial path : " + path );
return ERROR;
}
Configuration configuration = archivaConfiguration.getConfiguration();
configuration.addLegacyArtifactPath( legacyArtifactPath );
return saveConfiguration( configuration );
}
public LegacyArtifactPath getLegacyArtifactPath()
{
return legacyArtifactPath;
}
public void setLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath )
{
this.legacyArtifactPath = legacyArtifactPath;
}
protected String saveConfiguration( Configuration configuration )
{
try
{
archivaConfiguration.save( configuration );
addActionMessage( "Successfully saved configuration" );
}
catch ( IndeterminateConfigurationException e )
{
addActionError( e.getMessage() );
return INPUT;
}
catch ( RegistryException e )
{
addActionError( "Configuration Registry Exception: " + e.getMessage() );
return INPUT;
}
return SUCCESS;
}
}

View File

@ -0,0 +1,92 @@
package org.apache.maven.archiva.web.action.admin.legacy;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
import java.util.Iterator;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
import org.apache.maven.archiva.configuration.LegacyArtifactPath;
import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.plexus.xwork.action.PlexusActionSupport;
/**
* Delete a LegacyArtifactPath to archiva configuration
*
*
* @plexus.component role="com.opensymphony.xwork.Action" role-hint="deleteLegacyArtifactPathAction"
*/
public class DeleteLegacyArtifactPathAction
extends PlexusActionSupport
{
/**
* @plexus.requirement
*/
private ArchivaConfiguration archivaConfiguration;
private String path;
public String delete()
{
getLogger().info( "remove [" + path + "] from legacy artifact path resolution" );
Configuration configuration = archivaConfiguration.getConfiguration();
for ( Iterator iterator = configuration.getLegacyArtifactPaths().iterator(); iterator.hasNext(); )
{
LegacyArtifactPath legacyArtifactPath = (LegacyArtifactPath) iterator.next();
if (legacyArtifactPath.match( path ))
{
iterator.remove();
}
}
return saveConfiguration( configuration );
}
protected String saveConfiguration( Configuration configuration )
{
try
{
archivaConfiguration.save( configuration );
addActionMessage( "Successfully saved configuration" );
}
catch ( IndeterminateConfigurationException e )
{
addActionError( e.getMessage() );
return INPUT;
}
catch ( RegistryException e )
{
addActionError( "Configuration Registry Exception: " + e.getMessage() );
return INPUT;
}
return SUCCESS;
}
public String getPath()
{
return path;
}
public void setPath( String path )
{
this.path = path;
}
}

View File

@ -0,0 +1,96 @@
package org.apache.maven.archiva.web.action.admin.legacy;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.LegacyArtifactPath;
import org.apache.maven.archiva.security.ArchivaRoleConstants;
import org.apache.maven.archiva.web.util.ContextUtils;
import org.codehaus.plexus.redback.rbac.Resource;
import org.codehaus.plexus.redback.xwork.interceptor.SecureAction;
import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle;
import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException;
import org.codehaus.plexus.xwork.action.PlexusActionSupport;
import com.opensymphony.webwork.interceptor.ServletRequestAware;
import com.opensymphony.xwork.Preparable;
/**
* Shows the LegacyArtifactPath Tab for the administrator.
*
* @plexus.component role="com.opensymphony.xwork.Action" role-hint="legacyArtifactPathAction"
*/
public class LegacyArtifactPathAction
extends PlexusActionSupport
implements SecureAction, ServletRequestAware, Preparable
{
/**
* @plexus.requirement
*/
private ArchivaConfiguration archivaConfiguration;
private List<LegacyArtifactPath> legacyArtifactPaths;
/**
* Used to construct the repository WebDAV URL in the repository action.
*/
private String baseUrl;
public void setServletRequest( HttpServletRequest request )
{
// TODO: is there a better way to do this?
this.baseUrl = ContextUtils.getBaseURL( request, "repository" );
}
public SecureActionBundle getSecureActionBundle()
throws SecureActionException
{
SecureActionBundle bundle = new SecureActionBundle();
bundle.setRequiresAuthentication( true );
bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION,
Resource.GLOBAL );
return bundle;
}
public void prepare()
{
Configuration config = archivaConfiguration.getConfiguration();
legacyArtifactPaths = new ArrayList<LegacyArtifactPath>( config.getLegacyArtifactPaths() );
}
public List<LegacyArtifactPath> getLegacyArtifactPaths()
{
return legacyArtifactPaths;
}
public String getBaseUrl()
{
return baseUrl;
}
}

View File

@ -399,6 +399,30 @@
<param name="namespace">/admin</param>
</result>
</action>
<!-- .\ LEGACY SUPPORT \.__________________________________________ -->
<action name="legacyArtifactPath" class="legacyArtifactPathAction" method="input">
<result name="input">/WEB-INF/jsp/admin/legacyArtifactPath.jsp</result>
<result name="success" type="redirect-action">
<param name="actionName">legacyArtifactPath</param>
</result>
</action>
<action name="addLegacyArtifactPath" class="addLegacyArtifactPathAction" method="input">
<result name="input">/WEB-INF/jsp/admin/addLegacyArtifactPath.jsp</result>
<result name="error">/WEB-INF/jsp/admin/addLegacyArtifactPath.jsp</result>
<result name="success" type="redirect-action">legacyArtifactPath</result>
<interceptor-ref name="configuredPrepareParamsStack"/>
</action>
<action name="deleteLegacyArtifactPath" class="deleteLegacyArtifactPathAction" method="delete">
<result name="input">/WEB-INF/jsp/admin/legacyArtifactPath.jsp</result>
<result name="error">/WEB-INF/jsp/admin/legacyArtifactPath.jsp</result>
<result name="success" type="redirect-action">legacyArtifactPath</result>
<interceptor-ref name="configuredPrepareParamsStack"/>
</action>
</package>
<package name="report" namespace="/report" extends="base">

View File

@ -0,0 +1,110 @@
<%--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you 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 prefix="ww" uri="/webwork" %>
<html>
<head>
<title>Admin: Add Legacy artifact path</title>
<ww:head/>
</head>
<body>
<h1>Admin: Add Legacy artifact path</h1>
<div id="contentArea">
<script type="text/javascript">
function parse( path )
{
var group = path.indexOf( "/" );
if ( group > 0 )
{
document.getElementById( "addLegacyArtifactPath_groupId" ).value
= path.substring( 0, group );
group += 1;
var type = path.indexOf( "/", group );
if ( type > 0 )
{
document.getElementById( "addLegacyArtifactPath_type" ).value
= path.substring( group, type - 1 );
}
type += 1;
var version = path.indexOf( "-", type );
var ext = path.lastIndexOf( "." );
if ( version > 0 )
{
document.getElementById( "addLegacyArtifactPath_artifactId" ).value
= path.substring( type, version );
document.getElementById( "addLegacyArtifactPath_version" ).value
= path.substring( version + 1, ext );
}
}
}
function computeArtifactReference()
{
document.getElementById("addLegacyArtifactPath_legacyArtifactPath_artifact").value
= document.getElementById("addLegacyArtifactPath_groupId").value
+ ":"
+ document.getElementById("addLegacyArtifactPath_artifactId").value
+ ":"
+ document.getElementById("addLegacyArtifactPath_version").value
+ ":"
+ document.getElementById("addLegacyArtifactPath_classifier").value
+ ":"
+ document.getElementById("addLegacyArtifactPath_type").value;
}
</script>
<ww:actionmessage/>
<ww:actionerror/>
<ww:form method="post" action="addLegacyArtifactPath!commit" namespace="/admin" validate="true" onsubmit="computeArtifactReference()">
<ww:textfield name="legacyArtifactPath.path" label="Path" size="50" required="true" onchange="parse( this.value )"/>
<ww:textfield name="groupId" label="GroupId" size="20" required="true" disabled="true"/>
<ww:textfield name="artifactId" label="ArtifactId" size="20" required="true"/>
<ww:textfield name="version" label="Version" size="20" required="true"/>
<ww:textfield name="classifier" label="Classifier" size="20" required="false"/>
<ww:textfield name="type" label="Type" size="20" required="true" disabled="true"/>
<ww:hidden name="legacyArtifactPath.artifact"/>
<ww:submit value="Add Legacy Artifact Path"/>
</ww:form>
<script type="text/javascript">
var ref = document.getElementById("addLegacyArtifactPath_legacyArtifactPath_artifact").value;
var i = ref.indexOf( ":" );
document.getElementById("addLegacyArtifactPath_groupId").value = ref.substring( 0, i );
var j = i + 1;
var i = ref.indexOf( ":", j );
document.getElementById("addLegacyArtifactPath_artifactId").value = ref.substring( j, i );
var j = i + 1;
var i = ref.indexOf( ":", j );
document.getElementById("addLegacyArtifactPath_version").value = ref.substring( j, i );
var j = i + 1;
var i = ref.indexOf( ":", j );
document.getElementById("addLegacyArtifactPath_classifier").value = ref.substring( j, i );
document.getElementById("addLegacyArtifactPath_legacyArtifactPath_path").focus();
</script>
</div>
</body>
</html>

View File

@ -0,0 +1,117 @@
<%--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you 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 prefix="ww" uri="/webwork" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="redback" uri="http://plexus.codehaus.org/redback/taglib-1.0" %>
<%@ taglib prefix="archiva" uri="http://maven.apache.org/archiva" %>
<html>
<head>
<title>Administration - Legacy support</title>
<ww:head/>
</head>
<body>
<h1>Administration - Legacy artifacts path resolution</h1>
<div id="contentArea">
<ww:actionerror/>
<ww:actionmessage/>
<div class="admin">
<div class="controls">
<redback:ifAuthorized permission="archiva-manage-configuration">
<ww:url id="addLegacyArtifactPathUrl" action="addLegacyArtifactPath"/>
<ww:a href="%{addLegacyArtifactPathUrl}">
<img src="<c:url value="/images/icons/create.png" />" alt="" width="16" height="16"/>
Add
</ww:a>
</redback:ifAuthorized>
</div>
<h2>Legacy artifacts path resolution</h2>
<c:choose>
<c:when test="${empty(legacyArtifactPaths)}">
<%-- No Managed Repositories. --%>
<strong>There are no legacy artifact path configured yet.</strong>
</c:when>
<c:otherwise>
<%-- Display the repositories. --%>
<c:forEach items="${legacyArtifactPaths}" var="legacyArtifactPath" varStatus="i">
<c:choose>
<c:when test='${(i.index)%2 eq 0}'>
<c:set var="rowColor" value="dark" scope="page"/>
</c:when>
<c:otherwise>
<c:set var="rowColor" value="lite" scope="page"/>
</c:otherwise>
</c:choose>
<div class="legacyArtifactPath ${rowColor}">
<div class="controls">
<%-- TODO: make some icons --%>
<redback:ifAnyAuthorized permissions="archiva-manage-configuration">
<ww:url id="deleteLegacyArtifactPath" action="deleteLegacyArtifactPath">
<ww:param name="path" value="%{'${legacyArtifactPath.path}'}"/>
</ww:url>
<ww:a href="%{deleteLegacyArtifactPath}">
<img src="<c:url value="/images/icons/delete.gif" />" alt="" width="16" height="16"/>
Delete
</ww:a>
</redback:ifAnyAuthorized>
</div>
<div style="float: left">
<img src="<c:url value="/images/archiva-splat-32.gif"/>" alt="" width="32" height="32"/>
</div>
<table class="infoTable">
<tr>
<th>Path</th>
<td>
<code>${legacyArtifactPath.path}</code>
</td>
</tr>
<tr>
<th>Artifact</th>
<td>
<code>${legacyArtifactPath.artifact}</code>
</td>
</tr>
</table>
</div>
</c:forEach>
</c:otherwise>
</c:choose>
</div>
</div>
</body>
</html>

View File

@ -136,6 +136,9 @@
<li class="none">
<my:currentWWUrl action="proxyConnectors" namespace="/admin">Proxy Connectors</my:currentWWUrl>
</li>
<li class="none">
<my:currentWWUrl action="legacyArtifactPath" namespace="/admin">Legacy support</my:currentWWUrl>
</li>
<li class="none">
<my:currentWWUrl action="networkProxies" namespace="/admin">Network Proxies</my:currentWWUrl>
</li>