Search in sources :

Example 6 with ArchivaConfiguration

use of org.apache.archiva.configuration.ArchivaConfiguration in project archiva by apache.

the class RepositoryContentConsumersTest method lookupRepositoryConsumers.

private RepositoryContentConsumers lookupRepositoryConsumers() throws Exception {
    ArchivaConfiguration configuration = applicationContext.getBean("archivaConfiguration#test-conf", ArchivaConfiguration.class);
    ArchivaAdministrationStub administrationStub = new ArchivaAdministrationStub(configuration);
    RepositoryContentConsumers consumerUtilStub = new RepositoryContentConsumersStub(administrationStub);
    RepositoryContentConsumers consumerUtil = applicationContext.getBean("repositoryContentConsumers#test", RepositoryContentConsumers.class);
    ApplicationContext context = new // 
    MockApplicationContext(// 
    consumerUtil.getAvailableKnownConsumers(), consumerUtil.getAvailableInvalidConsumers());
    consumerUtilStub.setApplicationContext(context);
    consumerUtilStub.setSelectedInvalidConsumers(consumerUtil.getSelectedInvalidConsumers());
    consumerUtilStub.setSelectedKnownConsumers(consumerUtil.getSelectedKnownConsumers());
    consumerUtilStub.setArchivaAdministration(administrationStub);
    assertNotNull("RepositoryContentConsumers should not be null.", consumerUtilStub);
    return consumerUtilStub;
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration)

Example 7 with ArchivaConfiguration

use of org.apache.archiva.configuration.ArchivaConfiguration in project archiva by apache.

the class NexusIndexerConsumerTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    scheduler = new ArchivaTaskSchedulerStub();
    ArchivaConfiguration configuration = applicationContext.getBean(ArchivaConfiguration.class);
    FileTypes filetypes = applicationContext.getBean(FileTypes.class);
    nexusIndexerConsumer = new NexusIndexerConsumer(scheduler, configuration, filetypes, indexCreators, managedRepositoryAdmin);
    // initialize to set the file types to be processed
    nexusIndexerConsumer.initialize();
    repositoryConfig = new BasicManagedRepository("test-repo", "Test Repository", Paths.get("target/test-classes"));
    repositoryConfig.setLocation(new URI("target/test-classes/test-repo"));
    repositoryConfig.setLayout("default");
    repositoryConfig.setScanned(true);
    repositoryConfig.addActiveReleaseScheme(ReleaseScheme.RELEASE);
    repositoryConfig.removeActiveReleaseScheme(ReleaseScheme.SNAPSHOT);
    repositoryRegistry.putRepository(repositoryConfig);
}
Also used : BasicManagedRepository(org.apache.archiva.repository.BasicManagedRepository) FileTypes(org.apache.archiva.configuration.FileTypes) URI(java.net.URI) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) Before(org.junit.Before)

Example 8 with ArchivaConfiguration

use of org.apache.archiva.configuration.ArchivaConfiguration in project archiva by apache.

the class AbstractRepositoryServletTestCase method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    String appserverBase = Paths.get("target/appserver-base").toAbsolutePath().toString();
    System.setProperty("appserver.base", appserverBase);
    Path testConf = Paths.get("src/test/resources/repository-archiva.xml");
    Path testConfDest = Paths.get(appserverBase, "conf/archiva.xml");
    if (Files.exists(testConfDest)) {
        org.apache.archiva.common.utils.FileUtils.deleteQuietly(testConfDest);
    }
    FileUtils.copyFile(testConf.toFile(), testConfDest.toFile());
    repoRootInternal = Paths.get(appserverBase, "data/repositories/internal");
    repoRootLegacy = Paths.get(appserverBase, "data/repositories/legacy");
    Configuration config = archivaConfiguration.getConfiguration();
    config.getManagedRepositories().clear();
    config.addManagedRepository(createManagedRepository(REPOID_INTERNAL, "Internal Test Repo", repoRootInternal, true));
    repositoryRegistry.reload();
    config.getProxyConnectors().clear();
    config.getRemoteRepositories().clear();
    saveConfiguration(archivaConfiguration);
    CacheManager.getInstance().clearAll();
}
Also used : Path(java.nio.file.Path) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) Configuration(org.apache.archiva.configuration.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Before(org.junit.Before)

Example 9 with ArchivaConfiguration

use of org.apache.archiva.configuration.ArchivaConfiguration in project archiva by apache.

the class RepositoryServlet method initServers.

public synchronized void initServers(ServletConfig servletConfig) throws RepositoryAdminException {
    long start = System.currentTimeMillis();
    WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletConfig.getServletContext());
    configuration = wac.getBean("archivaConfiguration#default", ArchivaConfiguration.class);
    configuration.addListener(this);
    managedRepositoryAdmin = wac.getBean(ManagedRepositoryAdmin.class);
    repositoryMap = managedRepositoryAdmin.getManagedRepositoriesAsMap();
    for (ManagedRepository repo : repositoryMap.values()) {
        Path repoDir = Paths.get(repo.getLocation());
        if (!Files.exists(repoDir)) {
            try {
                Files.createDirectories(repoDir);
            } catch (IOException e) {
                log.info("Unable to create missing directory for {}", repo.getLocation());
                continue;
            }
        }
    }
    resourceFactory = wac.getBean("davResourceFactory#archiva", DavResourceFactory.class);
    locatorFactory = new ArchivaDavLocatorFactory();
    ServletAuthenticator servletAuth = wac.getBean(ServletAuthenticator.class);
    HttpAuthenticator httpAuth = wac.getBean("httpAuthenticator#basic", HttpAuthenticator.class);
    sessionProvider = new ArchivaDavSessionProvider(servletAuth, httpAuth);
    long end = System.currentTimeMillis();
    log.debug("initServers done in {} ms", (end - start));
}
Also used : Path(java.nio.file.Path) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) DavResourceFactory(org.apache.jackrabbit.webdav.DavResourceFactory) ServletAuthenticator(org.apache.archiva.security.ServletAuthenticator) ManagedRepositoryAdmin(org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin) HttpAuthenticator(org.apache.archiva.redback.integration.filter.authentication.HttpAuthenticator) IOException(java.io.IOException) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 10 with ArchivaConfiguration

use of org.apache.archiva.configuration.ArchivaConfiguration in project archiva by apache.

the class HttpProxyTransferTest method setUp.

@Before
public void setUp() throws Exception {
    proxyHandler = applicationContext.getBean("repositoryProxyConnectors#test", RepositoryProxyConnectors.class);
    config = applicationContext.getBean("archivaConfiguration#mock", ArchivaConfiguration.class);
    // clear from previous tests - TODO the spring context should be initialised per test instead, or the config
    // made a complete mock
    config.getConfiguration().getProxyConnectors().clear();
    // Setup source repository (using default layout)
    String repoPath = "target/test-repository/managed/" + getClass().getSimpleName();
    Path destRepoDir = Paths.get(repoPath);
    // Cleanout destination dirs.
    if (Files.exists(destRepoDir)) {
        FileUtils.deleteDirectory(destRepoDir.toFile());
    }
    // Make the destination dir.
    Files.createDirectories(destRepoDir);
    MavenManagedRepository repo = new MavenManagedRepository(MANAGED_ID, "Default Managed Repository", Paths.get(repoPath).getParent());
    repo.setLocation(new URI(repoPath));
    repo.setLayout("default");
    RepositoryContentProvider provider = applicationContext.getBean("repositoryContentProvider#maven", RepositoryContentProvider.class);
    ManagedRepositoryContent repoContent = provider.createManagedContent(repo);
    managedDefaultRepository = repoContent;
    ((DefaultManagedRepositoryAdmin) applicationContext.getBean(ManagedRepositoryAdmin.class)).setArchivaConfiguration(config);
    RepositoryRegistry managedRepositoryAdmin = applicationContext.getBean(RepositoryRegistry.class);
    if (managedRepositoryAdmin.getManagedRepository(repo.getId()) == null) {
        managedRepositoryAdmin.putRepository(repo);
    }
    // config.getConfiguration().addManagedRepository( repo );
    Handler handler = new AbstractHandler() {

        @Override
        public void handle(String s, Request request, HttpServletRequest httpServletRequest, HttpServletResponse response) throws IOException, ServletException {
            response.setContentType("text/plain");
            response.setStatus(HttpServletResponse.SC_OK);
            response.getWriter().print("get-default-layout-1.0.jar\n\n");
            assertNotNull(request.getHeader("Proxy-Connection"));
            ((Request) request).setHandled(true);
        }

        public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException {
            response.setContentType("text/plain");
            response.setStatus(HttpServletResponse.SC_OK);
            response.getWriter().print("get-default-layout-1.0.jar\n\n");
            assertNotNull(request.getHeader("Proxy-Connection"));
            ((Request) request).setHandled(true);
        }
    };
    server = new Server();
    ServerConnector serverConnector = new ServerConnector(server, new HttpConnectionFactory());
    server.addConnector(serverConnector);
    server.setHandler(handler);
    server.start();
    int port = serverConnector.getLocalPort();
    NetworkProxyConfiguration proxyConfig = new NetworkProxyConfiguration();
    proxyConfig.setHost("localhost");
    proxyConfig.setPort(port);
    proxyConfig.setProtocol("http");
    proxyConfig.setId(PROXY_ID);
    config.getConfiguration().addNetworkProxy(proxyConfig);
    // Setup target (proxied to) repository.
    RemoteRepositoryConfiguration repoConfig = new RemoteRepositoryConfiguration();
    repoConfig.setId(PROXIED_ID);
    repoConfig.setName("Proxied Repository 1");
    repoConfig.setLayout("default");
    repoConfig.setUrl("http://www.example.com/");
    config.getConfiguration().addRemoteRepository(repoConfig);
}
Also used : Path(java.nio.file.Path) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) MavenManagedRepository(org.apache.archiva.repository.maven2.MavenManagedRepository) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) Handler(org.eclipse.jetty.server.Handler) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HttpServletResponse(javax.servlet.http.HttpServletResponse) RepositoryProxyConnectors(org.apache.archiva.proxy.model.RepositoryProxyConnectors) URI(java.net.URI) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) DefaultManagedRepositoryAdmin(org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServerConnector(org.eclipse.jetty.server.ServerConnector) RepositoryContentProvider(org.apache.archiva.repository.RepositoryContentProvider) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) ManagedRepositoryAdmin(org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin) DefaultManagedRepositoryAdmin(org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin) NetworkProxyConfiguration(org.apache.archiva.configuration.NetworkProxyConfiguration) RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) Before(org.junit.Before)

Aggregations

ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)15 Path (java.nio.file.Path)7 Before (org.junit.Before)7 Configuration (org.apache.archiva.configuration.Configuration)6 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)5 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)3 ManagedRepositoryAdmin (org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin)3 ContextConfiguration (org.springframework.test.context.ContextConfiguration)3 URI (java.net.URI)2 DefaultManagedRepositoryAdmin (org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin)2 FileType (org.apache.archiva.configuration.FileType)2 FileTypes (org.apache.archiva.configuration.FileTypes)2 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)2 HttpAuthenticator (org.apache.archiva.redback.integration.filter.authentication.HttpAuthenticator)2 RepositoryContentFactory (org.apache.archiva.repository.RepositoryContentFactory)2 ServletAuthenticator (org.apache.archiva.security.ServletAuthenticator)2 Test (org.junit.Test)2 ApplicationContext (org.springframework.context.ApplicationContext)2 WebApplicationContext (org.springframework.web.context.WebApplicationContext)2 IOException (java.io.IOException)1