git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1133091 13f79535-47bb-0310-9956-ffa450edef68tags/archiva-1.4-M1
import junit.framework.TestCase; | import junit.framework.TestCase; | ||||
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; | import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; | ||||
import org.apache.commons.io.FileUtils; | |||||
import org.apache.commons.lang.ArrayUtils; | import org.apache.commons.lang.ArrayUtils; | ||||
import org.apache.commons.lang.StringUtils; | import org.apache.commons.lang.StringUtils; | ||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration; | import org.apache.maven.archiva.configuration.ArchivaConfiguration; | ||||
import org.apache.maven.archiva.policies.SnapshotsPolicy; | import org.apache.maven.archiva.policies.SnapshotsPolicy; | ||||
import org.apache.maven.archiva.repository.ManagedRepositoryContent; | import org.apache.maven.archiva.repository.ManagedRepositoryContent; | ||||
import org.apache.maven.wagon.Wagon; | import org.apache.maven.wagon.Wagon; | ||||
import org.codehaus.plexus.util.FileUtils; | |||||
import org.easymock.ArgumentsMatcher; | import org.easymock.ArgumentsMatcher; | ||||
import org.easymock.MockControl; | import org.easymock.MockControl; | ||||
import org.junit.Before; | import org.junit.Before; | ||||
actualFile.getCanonicalPath() ); | actualFile.getCanonicalPath() ); | ||||
assertEquals( "Check file path matches.", expectedFile.getAbsolutePath(), actualFile.getAbsolutePath() ); | assertEquals( "Check file path matches.", expectedFile.getAbsolutePath(), actualFile.getAbsolutePath() ); | ||||
String expectedContents = FileUtils.readFileToString( sourceFile, null ); | |||||
String actualContents = FileUtils.readFileToString( actualFile, null ); | |||||
String expectedContents = org.apache.commons.io.FileUtils.readFileToString( sourceFile, null ); | |||||
String actualContents = org.apache.commons.io.FileUtils.readFileToString( actualFile, null ); | |||||
assertEquals( "Check file contents.", expectedContents, actualContents ); | assertEquals( "Check file contents.", expectedContents, actualContents ); | ||||
} | } | ||||
return; | return; | ||||
} | } | ||||
Collection<File> tmpFiles = FileUtils.listFiles( workingDir, new String[]{ "tmp" }, false ); | |||||
Collection<File> tmpFiles = org.apache.commons.io.FileUtils.listFiles( workingDir, new String[]{ "tmp" }, false ); | |||||
if ( !tmpFiles.isEmpty() ) | if ( !tmpFiles.isEmpty() ) | ||||
{ | { | ||||
StringBuffer emsg = new StringBuffer(); | StringBuffer emsg = new StringBuffer(); | ||||
{ | { | ||||
destination = destination.getParentFile(); | destination = destination.getParentFile(); | ||||
FileUtils.copyFile( file, new File( destination, file.getName() ), false ); | |||||
org.apache.commons.io.FileUtils.copyFile( file, new File( destination, file.getName() ), false ); | |||||
// TODO: Change when there is a FileUtils.copyFileToDirectory(file, destination, boolean) option | // TODO: Change when there is a FileUtils.copyFileToDirectory(file, destination, boolean) option | ||||
//FileUtils.copyFileToDirectory( file, destination ); | //FileUtils.copyFileToDirectory( file, destination ); | ||||
} | } |
import com.opensymphony.xwork2.Preparable; | import com.opensymphony.xwork2.Preparable; | ||||
import com.opensymphony.xwork2.Validateable; | import com.opensymphony.xwork2.Validateable; | ||||
import org.apache.archiva.audit.AuditEvent; | import org.apache.archiva.audit.AuditEvent; | ||||
import org.apache.commons.lang.StringUtils; | |||||
import org.apache.maven.archiva.configuration.Configuration; | import org.apache.maven.archiva.configuration.Configuration; | ||||
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; | import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; | ||||
import org.codehaus.plexus.redback.role.RoleManagerException; | import org.codehaus.plexus.redback.role.RoleManagerException; | ||||
import org.codehaus.plexus.scheduler.CronExpressionValidator; | |||||
import org.codehaus.redback.components.scheduler.CronExpressionValidator; | |||||
import java.io.File; | import java.io.File; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import org.apache.commons.lang.StringUtils; | |||||
/** | /** | ||||
* AddManagedRepositoryAction | * AddManagedRepositoryAction |
import org.apache.maven.archiva.configuration.Configuration; | import org.apache.maven.archiva.configuration.Configuration; | ||||
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; | import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; | ||||
import org.codehaus.plexus.redback.role.RoleManagerException; | import org.codehaus.plexus.redback.role.RoleManagerException; | ||||
import org.codehaus.plexus.scheduler.CronExpressionValidator; | |||||
import org.codehaus.redback.components.scheduler.CronExpressionValidator; | |||||
import java.io.File; | import java.io.File; | ||||
import java.io.IOException; | import java.io.IOException; |
import org.codehaus.plexus.redback.system.SecuritySession; | import org.codehaus.plexus.redback.system.SecuritySession; | ||||
import org.codehaus.plexus.redback.users.UserManager; | import org.codehaus.plexus.redback.users.UserManager; | ||||
import org.codehaus.plexus.redback.users.UserNotFoundException; | import org.codehaus.plexus.redback.users.UserNotFoundException; | ||||
import org.codehaus.plexus.spring.PlexusToSpringUtils; | |||||
import org.codehaus.redback.integration.filter.authentication.HttpAuthenticator; | import org.codehaus.redback.integration.filter.authentication.HttpAuthenticator; | ||||
import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
import org.springframework.web.context.WebApplicationContext; | import org.springframework.web.context.WebApplicationContext; | ||||
import org.springframework.web.context.support.WebApplicationContextUtils; | import org.springframework.web.context.support.WebApplicationContextUtils; | ||||
import javax.servlet.ServletException; | |||||
import javax.servlet.http.HttpServlet; | |||||
import javax.servlet.http.HttpServletRequest; | |||||
import javax.servlet.http.HttpServletResponse; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Collections; | import java.util.Collections; | ||||
import java.util.HashMap; | import java.util.HashMap; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | import java.util.Map; | ||||
import javax.servlet.ServletException; | |||||
import javax.servlet.http.HttpServlet; | |||||
import javax.servlet.http.HttpServletRequest; | |||||
import javax.servlet.http.HttpServletResponse; | |||||
/** | /** | ||||
* Servlet for handling rss feed requests. | * Servlet for handling rss feed requests. | ||||
{ | { | ||||
super.init( servletConfig ); | super.init( servletConfig ); | ||||
wac = WebApplicationContextUtils.getRequiredWebApplicationContext( servletConfig.getServletContext() ); | wac = WebApplicationContextUtils.getRequiredWebApplicationContext( servletConfig.getServletContext() ); | ||||
userRepositories = (UserRepositories) wac.getBean( PlexusToSpringUtils.buildSpringId( | |||||
UserRepositories.class.getName() ) ); | |||||
servletAuth = (ServletAuthenticator) wac.getBean( PlexusToSpringUtils.buildSpringId( | |||||
ServletAuthenticator.class.getName() ) ); | |||||
httpAuth = (HttpAuthenticator) wac.getBean( PlexusToSpringUtils.buildSpringId( HttpAuthenticator.ROLE, | |||||
"basic" ) ); | |||||
userRepositories = wac.getBean( UserRepositories.class ); | |||||
servletAuth = wac.getBean( ServletAuthenticator.class ); | |||||
httpAuth = wac.getBean( "httpAuthenticator#basic", HttpAuthenticator.class ); | |||||
// TODO: what if there are other types? | // TODO: what if there are other types? | ||||
repositorySessionFactory = (RepositorySessionFactory) wac.getBean( PlexusToSpringUtils.buildSpringId( | |||||
RepositorySessionFactory.class.getName() ) ); | |||||
repositorySessionFactory = wac.getBean( RepositorySessionFactory.class ); | |||||
} | } | ||||
public void doGet( HttpServletRequest req, HttpServletResponse res ) | public void doGet( HttpServletRequest req, HttpServletResponse res ) | ||||
if ( repoId != null ) | if ( repoId != null ) | ||||
{ | { | ||||
// new artifacts in repo feed request | // new artifacts in repo feed request | ||||
processor = (RssFeedProcessor) wac.getBean( PlexusToSpringUtils.buildSpringId( | |||||
RssFeedProcessor.class.getName(), "new-artifacts" ) ); | |||||
processor = wac.getBean( "rssFeedProcessor#new-artifacts", RssFeedProcessor.class ); | |||||
map.put( RssFeedProcessor.KEY_REPO_ID, repoId ); | map.put( RssFeedProcessor.KEY_REPO_ID, repoId ); | ||||
} | } | ||||
else if ( ( groupId != null ) && ( artifactId != null ) ) | else if ( ( groupId != null ) && ( artifactId != null ) ) | ||||
{ | { | ||||
// TODO: this only works for guest - we could pass in the list of repos | // TODO: this only works for guest - we could pass in the list of repos | ||||
// new versions of artifact feed request | // new versions of artifact feed request | ||||
processor = (RssFeedProcessor) wac.getBean( PlexusToSpringUtils.buildSpringId( | |||||
RssFeedProcessor.class.getName(), "new-versions" ) ); | |||||
processor = wac.getBean( "rssFeedProcessor#new-versions", RssFeedProcessor.class ); | |||||
map.put( RssFeedProcessor.KEY_GROUP_ID, groupId ); | map.put( RssFeedProcessor.KEY_GROUP_ID, groupId ); | ||||
map.put( RssFeedProcessor.KEY_ARTIFACT_ID, artifactId ); | map.put( RssFeedProcessor.KEY_ARTIFACT_ID, artifactId ); | ||||
} | } |
* under the License. | * under the License. | ||||
*/ | */ | ||||
import org.apache.archiva.scheduler.ArchivaTaskScheduler; | |||||
import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler; | import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler; | ||||
import org.apache.maven.archiva.common.ArchivaException; | import org.apache.maven.archiva.common.ArchivaException; | ||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.StoppingException; | |||||
import org.codehaus.plexus.scheduler.DefaultScheduler; | |||||
import org.codehaus.plexus.spring.PlexusToSpringUtils; | |||||
import org.codehaus.plexus.spring.PlexusWebApplicationContext; | |||||
import org.codehaus.plexus.taskqueue.Task; | import org.codehaus.plexus.taskqueue.Task; | ||||
import org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor; | |||||
import org.codehaus.plexus.taskqueue.execution.ThreadedTaskQueueExecutor; | import org.codehaus.plexus.taskqueue.execution.ThreadedTaskQueueExecutor; | ||||
import org.springframework.context.support.ClassPathXmlApplicationContext; | |||||
import org.codehaus.redback.components.scheduler.DefaultScheduler; | |||||
import org.quartz.SchedulerException; | |||||
import org.springframework.web.context.WebApplicationContext; | import org.springframework.web.context.WebApplicationContext; | ||||
import org.springframework.web.context.support.WebApplicationContextUtils; | import org.springframework.web.context.support.WebApplicationContextUtils; | ||||
public void contextInitialized( ServletContextEvent contextEvent ) | public void contextInitialized( ServletContextEvent contextEvent ) | ||||
{ | { | ||||
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext( | |||||
contextEvent.getServletContext() ); | |||||
WebApplicationContext wac = | |||||
WebApplicationContextUtils.getRequiredWebApplicationContext( contextEvent.getServletContext() ); | |||||
SecuritySynchronization securitySync = (SecuritySynchronization) wac.getBean( PlexusToSpringUtils.buildSpringId( | |||||
SecuritySynchronization.class ) ); | |||||
SecuritySynchronization securitySync = wac.getBean( SecuritySynchronization.class ); | |||||
repositoryTaskScheduler = (RepositoryArchivaTaskScheduler) wac.getBean( PlexusToSpringUtils.buildSpringId( | |||||
ArchivaTaskScheduler.class, "repository" ) ); | |||||
repositoryTaskScheduler = wac.getBean( "archivaTaskScheduler#repository", RepositoryArchivaTaskScheduler.class ); | |||||
tqeRepoScanning = (ThreadedTaskQueueExecutor) wac.getBean( PlexusToSpringUtils.buildSpringId( | |||||
TaskQueueExecutor.class, "repository-scanning" ) ); | |||||
tqeRepoScanning = wac.getBean( "taskQueueExecutor#repository-scanning", ThreadedTaskQueueExecutor.class ); | |||||
tqeIndexing = (ThreadedTaskQueueExecutor) wac.getBean( PlexusToSpringUtils.buildSpringId( | |||||
TaskQueueExecutor.class, "indexing" ) ); | |||||
tqeIndexing = wac.getBean( "taskQueueExecutor#indexing", ThreadedTaskQueueExecutor.class ); | |||||
try | try | ||||
{ | { | ||||
public void contextDestroyed( ServletContextEvent contextEvent ) | public void contextDestroyed( ServletContextEvent contextEvent ) | ||||
{ | { | ||||
WebApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext( | |||||
contextEvent.getServletContext() ); | |||||
WebApplicationContext applicationContext = | |||||
WebApplicationContextUtils.getRequiredWebApplicationContext( contextEvent.getServletContext() ); | |||||
// TODO check this stop | |||||
/* | |||||
if ( applicationContext != null && applicationContext instanceof ClassPathXmlApplicationContext ) | if ( applicationContext != null && applicationContext instanceof ClassPathXmlApplicationContext ) | ||||
{ | { | ||||
( (ClassPathXmlApplicationContext) applicationContext ).close(); | ( (ClassPathXmlApplicationContext) applicationContext ).close(); | ||||
} | |||||
} */ | |||||
if ( applicationContext != null && applicationContext instanceof PlexusWebApplicationContext ) | |||||
if ( applicationContext != null ) //&& applicationContext instanceof PlexusWebApplicationContext ) | |||||
{ | { | ||||
// stop task queue executors | // stop task queue executors | ||||
stopTaskQueueExecutor( tqeDbScanning ); | stopTaskQueueExecutor( tqeDbScanning ); | ||||
{ | { | ||||
repositoryTaskScheduler.stop(); | repositoryTaskScheduler.stop(); | ||||
} | } | ||||
catch ( StoppingException e ) | |||||
catch ( SchedulerException e ) | |||||
{ | { | ||||
e.printStackTrace(); | e.printStackTrace(); | ||||
} | } | ||||
} | } | ||||
// close the application context | // close the application context | ||||
( (PlexusWebApplicationContext) applicationContext ).close(); | |||||
//applicationContext.close(); | |||||
// TODO fix close call | |||||
//applicationContext. | |||||
} | } | ||||
} | } | ||||
* under the License. | * under the License. | ||||
*/ | */ | ||||
import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException; | |||||
import org.apache.commons.collections.CollectionUtils; | import org.apache.commons.collections.CollectionUtils; | ||||
import org.apache.commons.collections.IteratorUtils; | import org.apache.commons.collections.IteratorUtils; | ||||
import org.apache.commons.lang.StringUtils; | import org.apache.commons.lang.StringUtils; | ||||
DependencyTree deptree; | DependencyTree deptree; | ||||
try | try | ||||
{ | { | ||||
deptree = (DependencyTree) PlexusTagUtil.lookup( pageContext, DependencyTree.class.getName() ); | |||||
deptree = (DependencyTree) PlexusTagUtil.lookup( pageContext, DependencyTree.class ); | |||||
} | } | ||||
catch ( ComponentLookupException e ) | |||||
catch ( PlexusSisuBridgeException e ) | |||||
{ | { | ||||
throw new JspException( "Unable to lookup DependencyTree: " + e.getMessage(), e ); | throw new JspException( "Unable to lookup DependencyTree: " + e.getMessage(), e ); | ||||
} | } |
* under the License. | * under the License. | ||||
*/ | */ | ||||
import org.codehaus.plexus.PlexusConstants; | |||||
import org.codehaus.plexus.PlexusContainer; | |||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException; | |||||
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; | |||||
import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException; | |||||
import org.springframework.web.context.WebApplicationContext; | |||||
import org.springframework.web.context.support.WebApplicationContextUtils; | |||||
import javax.servlet.ServletContext; | import javax.servlet.ServletContext; | ||||
import javax.servlet.jsp.PageContext; | import javax.servlet.jsp.PageContext; | ||||
/** | /** | ||||
* PlexusTagUtil | |||||
* PlexusTagUtil | |||||
* | * | ||||
* @version $Id$ | * @version $Id$ | ||||
*/ | */ | ||||
public class PlexusTagUtil | public class PlexusTagUtil | ||||
{ | { | ||||
public static Object lookup( PageContext pageContext, Class<?> clazz ) | public static Object lookup( PageContext pageContext, Class<?> clazz ) | ||||
throws ComponentLookupException | |||||
throws PlexusSisuBridgeException | |||||
{ | { | ||||
return getContainer( pageContext ).lookup( clazz ); | return getContainer( pageContext ).lookup( clazz ); | ||||
} | } | ||||
public static Object lookup( PageContext pageContext, String role ) | |||||
throws ComponentLookupException | |||||
{ | |||||
return getContainer( pageContext ).lookup( role ); | |||||
} | |||||
public static Object lookup( PageContext pageContext, Class<?> clazz, String hint ) | |||||
throws ComponentLookupException | |||||
{ | |||||
return getContainer( pageContext ).lookup( clazz, hint ); | |||||
} | |||||
public static Object lookup( PageContext pageContext, String role, String hint ) | |||||
throws ComponentLookupException | |||||
{ | |||||
return getContainer( pageContext ).lookup( role, hint ); | |||||
} | |||||
public static PlexusContainer getContainer( PageContext pageContext ) | |||||
throws ComponentLookupException | |||||
private static PlexusSisuBridge getContainer( PageContext pageContext ) | |||||
{ | { | ||||
ServletContext servletContext = pageContext.getServletContext(); | ServletContext servletContext = pageContext.getServletContext(); | ||||
PlexusContainer xworkContainer = (PlexusContainer) servletContext.getAttribute( "webwork.plexus.container" ); | |||||
WebApplicationContext webApplicationContext = | |||||
WebApplicationContextUtils.getRequiredWebApplicationContext( pageContext.getServletContext() ); | |||||
if ( xworkContainer != null ) | |||||
{ | |||||
servletContext.setAttribute( PlexusConstants.PLEXUS_KEY, xworkContainer ); | |||||
return webApplicationContext.getBean( PlexusSisuBridge.class ); | |||||
return xworkContainer; | |||||
} | |||||
PlexusContainer container = (PlexusContainer) servletContext.getAttribute( PlexusConstants.PLEXUS_KEY ); | |||||
if ( container == null ) | |||||
{ | |||||
throw new ComponentLookupException( "PlexusContainer is null." ); | |||||
} | |||||
return container; | |||||
} | } | ||||
} | } |
{ | { | ||||
String cron = (String) getFieldValue( "cron", obj ); | String cron = (String) getFieldValue( "cron", obj ); | ||||
org.codehaus.plexus.scheduler.CronExpressionValidator cronExpressionValidator = | |||||
new org.codehaus.plexus.scheduler.CronExpressionValidator(); | |||||
org.codehaus.redback.components.scheduler.CronExpressionValidator cronExpressionValidator = | |||||
new org.codehaus.redback.components.scheduler.CronExpressionValidator(); | |||||
ValidatorContext ctxt = getValidatorContext(); | ValidatorContext ctxt = getValidatorContext(); | ||||
if ( !cronExpressionValidator.validate( String.valueOf( cron ) ) ) | if ( !cronExpressionValidator.validate( String.valueOf( cron ) ) ) |