Search in sources :

Example 6 with MavenManagedRepository

use of org.apache.archiva.repository.maven2.MavenManagedRepository 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 7 with MavenManagedRepository

use of org.apache.archiva.repository.maven2.MavenManagedRepository in project archiva by apache.

the class MavenIndexManagerTest method createTestContext.

private ArchivaIndexingContext createTestContext() throws URISyntaxException, IndexCreationFailedException, IOException {
    indexPath = Paths.get("target/repositories/test-repo/.index-test");
    FileUtils.deleteDirectory(indexPath);
    repository = new MavenManagedRepository("test-repo", "Test Repo", Paths.get("target/repositories"));
    repository.setLocation(new URI("test-repo"));
    IndexCreationFeature icf = repository.getFeature(IndexCreationFeature.class).get();
    icf.setIndexPath(new URI(".index-test"));
    ctx = mavenIndexManager.createContext(repository);
    return ctx;
}
Also used : IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) MavenManagedRepository(org.apache.archiva.repository.maven2.MavenManagedRepository) URI(java.net.URI)

Example 8 with MavenManagedRepository

use of org.apache.archiva.repository.maven2.MavenManagedRepository in project archiva by apache.

the class DavResourceTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    session = new ArchivaDavSession();
    baseDir = Paths.get("target/DavResourceTest");
    Files.createDirectories(baseDir);
    repository = new MavenManagedRepository("repo001", "repo001", baseDir);
    myResource = baseDir.resolve("myresource.jar");
    Files.createFile(myResource);
    resourceFactory = new RootContextDavResourceFactory();
    resourceLocator = (ArchivaDavResourceLocator) new ArchivaDavLocatorFactory().createResourceLocator("/", REPOPATH);
    resource = getDavResource(resourceLocator.getHref(false), myResource);
    lockManager = new SimpleLockManager();
    resource.addLockManager(lockManager);
}
Also used : MavenManagedRepository(org.apache.archiva.repository.maven2.MavenManagedRepository) SimpleLockManager(org.apache.jackrabbit.webdav.lock.SimpleLockManager) Before(org.junit.Before)

Example 9 with MavenManagedRepository

use of org.apache.archiva.repository.maven2.MavenManagedRepository in project archiva by apache.

the class AbstractRepositoryLayerTestCase method createManagedRepositoryContent.

protected ManagedRepositoryContent createManagedRepositoryContent(String id, String name, Path location, String layout) throws Exception {
    MavenManagedRepository repo = new MavenManagedRepository(id, name, location.getParent());
    repo.setLocation(location.toAbsolutePath().toUri());
    repo.setLayout(layout);
    RepositoryContentProvider provider = applicationContext.getBean("repositoryContentProvider#maven", RepositoryContentProvider.class);
    ManagedRepositoryContent repoContent = provider.createManagedContent(repo);
    return repoContent;
}
Also used : MavenManagedRepository(org.apache.archiva.repository.maven2.MavenManagedRepository)

Example 10 with MavenManagedRepository

use of org.apache.archiva.repository.maven2.MavenManagedRepository in project archiva by apache.

the class ManagedDefaultRepositoryContentTest method setUp.

@Before
public void setUp() throws Exception {
    Path repoDir = Paths.get("src/test/repositories/default-repository");
    MavenManagedRepository repository = createRepository("testRepo", "Unit Test Repo", repoDir);
    FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get(0);
    fileType.addPattern("**/*.xml");
    assertEquals(FileTypes.ARTIFACTS, fileType.getId());
    fileTypes.afterConfigurationChange(null, "fileType", null);
    repoContent = new ManagedDefaultRepositoryContent(artifactMappingProviders, fileTypes);
    // repoContent = (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class, "default" );
    repoContent.setRepository(repository);
}
Also used : Path(java.nio.file.Path) FileType(org.apache.archiva.configuration.FileType) MavenManagedRepository(org.apache.archiva.repository.maven2.MavenManagedRepository) ManagedDefaultRepositoryContent(org.apache.archiva.repository.content.maven2.ManagedDefaultRepositoryContent) Before(org.junit.Before)

Aggregations

MavenManagedRepository (org.apache.archiva.repository.maven2.MavenManagedRepository)10 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)5 RepositoryContentProvider (org.apache.archiva.repository.RepositoryContentProvider)5 Path (java.nio.file.Path)4 URI (java.net.URI)3 Before (org.junit.Before)3 ArrayList (java.util.ArrayList)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 ManagedRepositoryAdmin (org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin)1 DefaultManagedRepositoryAdmin (org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin)1 VersionComparator (org.apache.archiva.common.utils.VersionComparator)1 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)1 FileType (org.apache.archiva.configuration.FileType)1 NetworkProxyConfiguration (org.apache.archiva.configuration.NetworkProxyConfiguration)1 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)1 VersionedReference (org.apache.archiva.model.VersionedReference)1 RepositoryProxyConnectors (org.apache.archiva.proxy.model.RepositoryProxyConnectors)1 RepositoryRegistry (org.apache.archiva.repository.RepositoryRegistry)1 ManagedDefaultRepositoryContent (org.apache.archiva.repository.content.maven2.ManagedDefaultRepositoryContent)1