Search in sources :

Example 16 with RemoteRepositoryConfiguration

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

the class RepositoryRegistryTest method putRemoteRepositoryFromConfigWithoutSave.

@Test
public void putRemoteRepositoryFromConfigWithoutSave() throws Exception {
    Configuration configuration = archivaConfiguration.getConfiguration();
    RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration();
    cfg.setId("test002");
    cfg.setName("This is test 002");
    RemoteRepository repo = repositoryRegistry.putRepository(cfg, configuration);
    assertNotNull(repo);
    assertEquals("test002", repo.getId());
    assertEquals("This is test 002", repo.getName());
    assertNotNull(repo.getContent());
    archivaConfiguration.reload();
    assertEquals(1, archivaConfiguration.getConfiguration().getRemoteRepositories().size());
    Collection<RemoteRepository> repos = repositoryRegistry.getRemoteRepositories();
    assertEquals(2, repos.size());
    RemoteRepository internalRepo = repositoryRegistry.getRemoteRepository("central");
    cfg = new RemoteRepositoryConfiguration();
    cfg.setId("central");
    cfg.setName("This is central test 002");
    repo = repositoryRegistry.putRepository(cfg, configuration);
    assertTrue(internalRepo == repo);
    assertEquals("This is central test 002", repo.getName());
    assertEquals(2, repositoryRegistry.getRemoteRepositories().size());
    repositoryRegistry.reload();
    assertEquals(1, repositoryRegistry.getRemoteRepositories().size());
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Configuration(org.apache.archiva.configuration.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) Test(org.junit.Test)

Example 17 with RemoteRepositoryConfiguration

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

the class AbstractRepositoryServletProxiedTestCase method setupSnapshotsRemoteRepo.

protected void setupSnapshotsRemoteRepo() throws Exception {
    remoteSnapshots = createServer("snapshots");
    assertServerSetupCorrectly(remoteSnapshots);
    RemoteRepositoryConfiguration remoteRepositoryConfiguration = archivaConfiguration.getConfiguration().getRemoteRepositoriesAsMap().get(remoteSnapshots.id);
    if (remoteRepositoryConfiguration != null) {
        archivaConfiguration.getConfiguration().removeRemoteRepository(remoteRepositoryConfiguration);
    }
    archivaConfiguration.getConfiguration().addRemoteRepository(remoteSnapshots.config);
    setupCleanRepo(remoteSnapshots.root);
}
Also used : RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration)

Example 18 with RemoteRepositoryConfiguration

use of org.apache.archiva.configuration.RemoteRepositoryConfiguration 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)

Example 19 with RemoteRepositoryConfiguration

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

the class RepositoryRegistry method clone.

/**
 * Creates a new repository instance with the same settings as this one. The cloned repository is not
 * registered or saved to the configuration.
 *
 * @param repo The origin repository
 * @return The cloned repository.
 */
public RemoteRepository clone(RemoteRepository repo, String newId) throws RepositoryException {
    if (managedRepositories.containsKey(newId) || remoteRepositories.containsKey(newId)) {
        throw new RepositoryException("The given id exists already " + newId);
    }
    RepositoryProvider provider = getProvider(repo.getType());
    RemoteRepositoryConfiguration cfg = provider.getRemoteConfiguration(repo);
    cfg.setId(newId);
    RemoteRepository cloned = provider.createRemoteInstance(cfg);
    cloned.addListener(this);
    return cloned;
}
Also used : RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration)

Example 20 with RemoteRepositoryConfiguration

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

the class RepositoryRegistry method replaceOrAddRepositoryConfig.

private void replaceOrAddRepositoryConfig(RemoteRepositoryConfiguration remoteRepositoryConfiguration, Configuration configuration) {
    RemoteRepositoryConfiguration oldCfg = configuration.findRemoteRepositoryById(remoteRepositoryConfiguration.getId());
    if (oldCfg != null) {
        configuration.removeRemoteRepository(oldCfg);
    }
    configuration.addRemoteRepository(remoteRepositoryConfiguration);
}
Also used : RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration)

Aggregations

RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)26 Configuration (org.apache.archiva.configuration.Configuration)9 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)8 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)7 ProxyConnectorConfiguration (org.apache.archiva.configuration.ProxyConnectorConfiguration)7 Test (org.junit.Test)6 ContextConfiguration (org.springframework.test.context.ContextConfiguration)6 RemoteIndexFeature (org.apache.archiva.repository.features.RemoteIndexFeature)5 ArrayList (java.util.ArrayList)4 PasswordCredentials (org.apache.archiva.repository.PasswordCredentials)4 Before (org.junit.Before)4 IndeterminateConfigurationException (org.apache.archiva.configuration.IndeterminateConfigurationException)3 WagonFactory (org.apache.archiva.proxy.common.WagonFactory)3 WagonFactoryRequest (org.apache.archiva.proxy.common.WagonFactoryRequest)3 RegistryException (org.apache.archiva.redback.components.registry.RegistryException)3 RepositoryCredentials (org.apache.archiva.repository.RepositoryCredentials)3 RepositoryException (org.apache.archiva.repository.RepositoryException)3 IndexCreationFeature (org.apache.archiva.repository.features.IndexCreationFeature)3 Wagon (org.apache.maven.wagon.Wagon)3 URI (java.net.URI)2