Search in sources :

Example 6 with RemoteRepositoryConfiguration

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

the class AbstractRepositoryServletTestCase method createRemoteRepository.

protected RemoteRepositoryConfiguration createRemoteRepository(String id, String name, String url) {
    RemoteRepositoryConfiguration repo = new RemoteRepositoryConfiguration();
    repo.setId(id);
    repo.setName(name);
    repo.setUrl(url);
    return repo;
}
Also used : RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)

Example 7 with RemoteRepositoryConfiguration

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

the class RepositoryProviderMock method getRemoteConfiguration.

@Override
public RemoteRepositoryConfiguration getRemoteConfiguration(RemoteRepository remoteRepository) throws RepositoryException {
    RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration();
    configuration.setId(remoteRepository.getId());
    configuration.setName(remoteRepository.getName());
    configuration.setDescription(remoteRepository.getDescription());
    configuration.setLayout(remoteRepository.getLayout());
    configuration.setRefreshCronExpression(remoteRepository.getSchedulingDefinition());
    configuration.setCheckPath(remoteRepository.getCheckPath());
    configuration.setExtraHeaders(remoteRepository.getExtraHeaders());
    configuration.setExtraParameters(remoteRepository.getExtraParameters());
    configuration.setTimeout((int) remoteRepository.getTimeout().getSeconds());
    RepositoryCredentials creds = remoteRepository.getLoginCredentials();
    if (creds != null) {
        PasswordCredentials pwdCreds = (PasswordCredentials) creds;
        configuration.setUsername(pwdCreds.getUsername());
        configuration.setPassword(new String(pwdCreds.getPassword()));
    }
    configuration.setUrl(remoteRepository.getLocation() == null ? "" : remoteRepository.getLocation().toString());
    RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class);
    configuration.setDownloadRemoteIndex(rif.isDownloadRemoteIndex());
    configuration.setDownloadRemoteIndexOnStartup(rif.isDownloadRemoteIndexOnStartup());
    configuration.setIndexDir(rif.getIndexUri() == null ? "" : rif.getIndexUri().toString());
    configuration.setRemoteDownloadNetworkProxyId(rif.getProxyId());
    return configuration;
}
Also used : RepositoryCredentials(org.apache.archiva.repository.RepositoryCredentials) PasswordCredentials(org.apache.archiva.repository.base.PasswordCredentials) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature)

Example 8 with RemoteRepositoryConfiguration

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

the class HttpProxyTransferTest method setUp.

@Before
public void setUp() throws Exception {
    proxyHandler = applicationContext.getBean("repositoryProxyHandler#test", RepositoryProxyHandler.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);
    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);
    ((MockConfiguration) config).triggerChange("networkProxies.networkProxy(0).host", "localhost");
    // 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);
    Wagon wagon = new HttpWagon();
    WagonDelegate delegate = (WagonDelegate) applicationContext.getBean("wagon#http", Wagon.class);
    delegate.setDelegate(wagon);
    proxyRegistry.reload();
    repositoryRegistry.reload();
    managedDefaultRepository = createRepository(MANAGED_ID, "Default Managed Repository", repoPath, "default");
}
Also used : Path(java.nio.file.Path) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HttpWagon(org.apache.maven.wagon.providers.http.HttpWagon) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) Handler(org.eclipse.jetty.server.Handler) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) RepositoryProxyHandler(org.apache.archiva.proxy.model.RepositoryProxyHandler) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpWagon(org.apache.maven.wagon.providers.http.HttpWagon) Wagon(org.apache.maven.wagon.Wagon) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServerConnector(org.eclipse.jetty.server.ServerConnector) NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RepositoryProxyHandler(org.apache.archiva.proxy.model.RepositoryProxyHandler) Before(org.junit.Before)

Example 9 with RemoteRepositoryConfiguration

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

the class MavenRepositoryProvider method getRemoteConfiguration.

@Override
public RemoteRepositoryConfiguration getRemoteConfiguration(RemoteRepository remoteRepository) throws RepositoryException {
    if (!(remoteRepository instanceof MavenRemoteRepository)) {
        log.error("Wrong remote repository type " + remoteRepository.getClass().getName());
        throw new RepositoryException("The given repository type cannot be handled by the maven provider: " + remoteRepository.getClass().getName());
    }
    RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration();
    cfg.setType(remoteRepository.getType().toString());
    cfg.setId(remoteRepository.getId());
    cfg.setName(remoteRepository.getName());
    cfg.setDescription(remoteRepository.getDescription());
    cfg.setUrl(remoteRepository.getLocation().toString());
    cfg.setTimeout((int) remoteRepository.getTimeout().toMillis() / 1000);
    cfg.setCheckPath(remoteRepository.getCheckPath());
    RepositoryCredentials creds = remoteRepository.getLoginCredentials();
    if (creds != null) {
        if (creds instanceof PasswordCredentials) {
            PasswordCredentials pCreds = (PasswordCredentials) creds;
            cfg.setPassword(new String(pCreds.getPassword()));
            cfg.setUsername(pCreds.getUsername());
        }
    }
    cfg.setLayout(remoteRepository.getLayout());
    cfg.setExtraParameters(remoteRepository.getExtraParameters());
    cfg.setExtraHeaders(remoteRepository.getExtraHeaders());
    cfg.setRefreshCronExpression(remoteRepository.getSchedulingDefinition());
    IndexCreationFeature indexCreationFeature = remoteRepository.getFeature(IndexCreationFeature.class);
    cfg.setIndexDir(convertUriToPath(indexCreationFeature.getIndexPath()));
    cfg.setPackedIndexDir(convertUriToPath(indexCreationFeature.getPackedIndexPath()));
    RemoteIndexFeature remoteIndexFeature = remoteRepository.getFeature(RemoteIndexFeature.class);
    if (remoteIndexFeature.getIndexUri() == null) {
        cfg.setRemoteIndexUrl("");
    } else {
        cfg.setRemoteIndexUrl(remoteIndexFeature.getIndexUri().toString());
    }
    cfg.setRemoteDownloadTimeout((int) remoteIndexFeature.getDownloadTimeout().get(ChronoUnit.SECONDS));
    cfg.setDownloadRemoteIndexOnStartup(remoteIndexFeature.isDownloadRemoteIndexOnStartup());
    cfg.setDownloadRemoteIndex(remoteIndexFeature.isDownloadRemoteIndex());
    cfg.setRemoteDownloadNetworkProxyId(remoteIndexFeature.getProxyId());
    if (StringUtils.isEmpty(remoteIndexFeature.getProxyId())) {
        cfg.setRemoteDownloadNetworkProxyId("");
    } else {
        cfg.setRemoteDownloadNetworkProxyId(remoteIndexFeature.getProxyId());
    }
    return cfg;
}
Also used : RepositoryCredentials(org.apache.archiva.repository.RepositoryCredentials) PasswordCredentials(org.apache.archiva.repository.base.PasswordCredentials) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) RepositoryException(org.apache.archiva.repository.RepositoryException)

Example 10 with RemoteRepositoryConfiguration

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

the class RemoteRepositoryHandler method newInstancesFromConfig.

@Override
public Map<String, RemoteRepository> newInstancesFromConfig() {
    try {
        List<RemoteRepositoryConfiguration> remoteRepoConfigs = new ArrayList<>(getConfigurationHandler().getBaseConfiguration().getRemoteRepositories());
        if (remoteRepoConfigs == null) {
            return Collections.emptyMap();
        }
        Map<String, RemoteRepository> result = new HashMap<>();
        for (RemoteRepositoryConfiguration repoConfig : remoteRepoConfigs) {
            RemoteRepository repo = newInstance(repoConfig);
            result.put(repo.getId(), repo);
        }
        return result;
    } catch (Throwable e) {
        log.error("Could not initialize repositories from config: {}", e.getMessage(), e);
        return new HashMap<>();
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RemoteRepository(org.apache.archiva.repository.RemoteRepository) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository)

Aggregations

RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)46 Configuration (org.apache.archiva.configuration.model.Configuration)17 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)14 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)14 RemoteRepository (org.apache.archiva.repository.RemoteRepository)12 ContextConfiguration (org.springframework.test.context.ContextConfiguration)11 ArrayList (java.util.ArrayList)9 ArchivaConfiguration (org.apache.archiva.configuration.provider.ArchivaConfiguration)9 EditableRemoteRepository (org.apache.archiva.repository.EditableRemoteRepository)9 RepositoryException (org.apache.archiva.repository.RepositoryException)8 Test (org.junit.Test)8 Path (java.nio.file.Path)7 NetworkProxyConfiguration (org.apache.archiva.configuration.model.NetworkProxyConfiguration)7 RemoteIndexFeature (org.apache.archiva.repository.features.RemoteIndexFeature)7 Test (org.junit.jupiter.api.Test)7 HashMap (java.util.HashMap)6 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)6 PasswordCredentials (org.apache.archiva.repository.base.PasswordCredentials)6 Iterator (java.util.Iterator)5 List (java.util.List)5