Search in sources :

Example 6 with RepositoryProxyHandler

use of org.apache.archiva.proxy.model.RepositoryProxyHandler in project archiva by apache.

the class ArchivaProxyRegistry method updateConnectors.

private void updateConnectors() {
    List<ProxyConnectorConfiguration> proxyConnectorConfigurations = getArchivaConfiguration().getConfiguration().getProxyConnectors();
    connectorList = proxyConnectorConfigurations.stream().map(this::buildProxyConnector).filter(Optional::isPresent).map(Optional::get).sorted(comparator).collect(Collectors.toList());
    connectorMap = connectorList.stream().collect(Collectors.groupingBy(a -> a.getSourceRepository().getId()));
    for (RepositoryProxyHandler handler : repositoryProxyHandlers) {
        handler.setProxyConnectors(connectorList);
    }
}
Also used : ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) RepositoryProxyHandler(org.apache.archiva.proxy.model.RepositoryProxyHandler)

Example 7 with RepositoryProxyHandler

use of org.apache.archiva.proxy.model.RepositoryProxyHandler in project archiva by apache.

the class AbstractProxyTestCase method setUp.

@Before
public void setUp() throws Exception {
    config = (MockConfiguration) applicationContext.getBean("archivaConfiguration#mock", ArchivaConfiguration.class);
    config.getConfiguration().setManagedRepositories(new ArrayList<ManagedRepositoryConfiguration>());
    config.getConfiguration().setRemoteRepositories(new ArrayList<RemoteRepositoryConfiguration>());
    config.getConfiguration().setProxyConnectors(new ArrayList<ProxyConnectorConfiguration>());
    ArchivaRuntimeConfiguration runtimeConfiguration = new ArchivaRuntimeConfiguration();
    List<String> checksumTypes = new ArrayList<>();
    checksumTypes.add("md5");
    checksumTypes.add("sha256");
    checksumTypes.add("sha1");
    checksumTypes.add("asc");
    runtimeConfiguration.setChecksumTypes(checksumTypes);
    config.getConfiguration().setArchivaRuntimeConfiguration(runtimeConfiguration);
    repositoryRegistry.setArchivaConfiguration(config);
    // Setup source repository (using default layout)
    String name = getClass().getSimpleName();
    Path repoPath = Paths.get("target/test-repository/managed/" + name);
    managedDefaultRepository = createRepository(ID_DEFAULT_MANAGED, "Default Managed Repository", repoPath.toString(), "default");
    managedDefaultDir = repoPath.resolve(ID_DEFAULT_MANAGED);
    org.apache.archiva.repository.ManagedRepository repoConfig = repositoryRegistry.getManagedRepository(ID_DEFAULT_MANAGED);
    // Setup target (proxied to) repository.
    saveRemoteRepositoryConfig(ID_PROXIED1, "Proxied Repository 1", Paths.get(REPOPATH_PROXIED1).toUri().toURL().toExternalForm(), "default");
    // Setup target (proxied to) repository.
    saveRemoteRepositoryConfig(ID_PROXIED2, "Proxied Repository 2", Paths.get(REPOPATH_PROXIED2).toUri().toURL().toExternalForm(), "default");
    repositoryRegistry.reload();
    repositoryRegistry.putRepository(repoConfig);
    // Setup the proxy handler.
    // proxyHandler = applicationContext.getBean (RepositoryProxyHandler) lookup( RepositoryProxyHandler.class.getName() );
    proxyHandler = applicationContext.getBean("repositoryProxyHandler#test", RepositoryProxyHandler.class);
    assertNotNull(proxyRegistry);
    assertTrue(proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).contains(proxyHandler));
    // Setup the wagon mock.
    wagonMock = mock(Wagon.class);
    delegate = (WagonDelegate) applicationContext.getBean("wagon#http", Wagon.class);
    delegate.setDelegate(wagonMock);
    log.info("\n.\\ {}() \\._________________________________________\n", name);
}
Also used : Path(java.nio.file.Path) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ArrayList(java.util.ArrayList) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) Wagon(org.apache.maven.wagon.Wagon) ManagedRepository(org.apache.archiva.repository.ManagedRepository) ArchivaRuntimeConfiguration(org.apache.archiva.configuration.model.ArchivaRuntimeConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RepositoryProxyHandler(org.apache.archiva.proxy.model.RepositoryProxyHandler) Before(org.junit.Before)

Example 8 with RepositoryProxyHandler

use of org.apache.archiva.proxy.model.RepositoryProxyHandler in project archiva by apache.

the class Maven2RepositoryStorage method applyServerSideRelocation.

@Override
public ItemSelector applyServerSideRelocation(ManagedRepository managedRepository, ItemSelector artifactSelector) throws ProxyDownloadException {
    if ("pom".equals(artifactSelector.getType())) {
        return artifactSelector;
    }
    // Build the artifact POM reference
    BaseRepositoryContentLayout layout;
    try {
        layout = managedRepository.getContent().getLayout(BaseRepositoryContentLayout.class);
    } catch (LayoutException e) {
        throw new ProxyDownloadException("Could not set layout " + e.getMessage(), new HashMap<>());
    }
    RepositoryType repositoryType = managedRepository.getType();
    if (!proxyRegistry.hasHandler(repositoryType)) {
        throw new ProxyDownloadException("No proxy handler found for repository type " + repositoryType, new HashMap<>());
    }
    ItemSelector selector = ArchivaItemSelector.builder().withNamespace(artifactSelector.getNamespace()).withProjectId(artifactSelector.getArtifactId()).withArtifactId(artifactSelector.getArtifactId()).withVersion(artifactSelector.getVersion()).withArtifactVersion(artifactSelector.getVersion()).withType("pom").build();
    Artifact pom = layout.getArtifact(selector);
    RepositoryProxyHandler proxyHandler = proxyRegistry.getHandler(repositoryType).get(0);
    // Get the artifact POM from proxied repositories if needed
    proxyHandler.fetchFromProxies(managedRepository, pom);
    if (!pom.exists()) {
        return artifactSelector;
    }
    try {
        // MavenXpp3Reader leaves the file open, so we need to close it ourselves.
        Model model;
        try (Reader reader = Channels.newReader(pom.getAsset().getReadChannel(), Charset.defaultCharset().name())) {
            model = MAVEN_XPP_3_READER.read(reader);
        }
        DistributionManagement dist = model.getDistributionManagement();
        if (dist != null) {
            Relocation relocation = dist.getRelocation();
            if (relocation != null) {
                ArchivaItemSelector.Builder relocatedBuilder = ArchivaItemSelector.builder();
                // artifact is relocated : update the repositoryPath
                if (relocation.getGroupId() != null) {
                    relocatedBuilder.withNamespace(relocation.getGroupId());
                } else {
                    relocatedBuilder.withNamespace(artifactSelector.getNamespace());
                }
                if (relocation.getArtifactId() != null) {
                    relocatedBuilder.withArtifactId(relocation.getArtifactId());
                } else {
                    relocatedBuilder.withArtifactId(artifactSelector.getArtifactId());
                }
                if (relocation.getVersion() != null) {
                    relocatedBuilder.withVersion(relocation.getVersion());
                } else {
                    relocatedBuilder.withVersion(artifactSelector.getVersion());
                }
                return relocatedBuilder.withArtifactVersion(artifactSelector.getArtifactVersion()).withClassifier(artifactSelector.getClassifier()).withType(artifactSelector.getType()).withProjectId(artifactSelector.getProjectId()).withExtension(artifactSelector.getExtension()).build();
            }
        }
    } catch (IOException e) {
    // Unable to read POM : ignore.
    } catch (XmlPullParserException e) {
    // Invalid POM : ignore
    }
    return artifactSelector;
}
Also used : ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) HashMap(java.util.HashMap) RepositoryType(org.apache.archiva.repository.RepositoryType) MavenMetadataReader(org.apache.archiva.maven.metadata.MavenMetadataReader) Reader(java.io.Reader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) IOException(java.io.IOException) ProxyDownloadException(org.apache.archiva.policies.ProxyDownloadException) Artifact(org.apache.archiva.repository.content.Artifact) ItemSelector(org.apache.archiva.repository.content.ItemSelector) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) LayoutException(org.apache.archiva.repository.content.LayoutException) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) Model(org.apache.maven.model.Model) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) DistributionManagement(org.apache.maven.model.DistributionManagement) Relocation(org.apache.maven.model.Relocation) RepositoryProxyHandler(org.apache.archiva.proxy.model.RepositoryProxyHandler)

Aggregations

RepositoryProxyHandler (org.apache.archiva.proxy.model.RepositoryProxyHandler)8 Path (java.nio.file.Path)2 NetworkProxyConfiguration (org.apache.archiva.configuration.model.NetworkProxyConfiguration)2 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)2 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)2 ProxyDownloadException (org.apache.archiva.policies.ProxyDownloadException)2 RepositoryType (org.apache.archiva.repository.RepositoryType)2 ItemSelector (org.apache.archiva.repository.content.ItemSelector)2 LayoutException (org.apache.archiva.repository.content.LayoutException)2 ArchivaItemSelector (org.apache.archiva.repository.content.base.ArchivaItemSelector)2 StorageAsset (org.apache.archiva.repository.storage.StorageAsset)2 Wagon (org.apache.maven.wagon.Wagon)2 Before (org.junit.Before)2 IOException (java.io.IOException)1 Reader (java.io.Reader)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 ArchivaRuntimeConfiguration (org.apache.archiva.configuration.model.ArchivaRuntimeConfiguration)1