Search in sources :

Example 11 with FixedIndexedRepo

use of aQute.bnd.deployer.repository.FixedIndexedRepo in project bndtools by bndtools.

the class ReposTemplateLoader method loadRepo.

private static FixedIndexedRepo loadRepo(List<String> uris) throws IOException, URISyntaxException {
    FixedIndexedRepo repo = new FixedIndexedRepo();
    StringBuilder sb = new StringBuilder();
    for (Iterator<String> iter = uris.iterator(); iter.hasNext(); ) {
        sb.append(iter.next());
        if (iter.hasNext())
            sb.append(',');
    }
    repo.setLocations(sb.toString());
    return repo;
}
Also used : FixedIndexedRepo(aQute.bnd.deployer.repository.FixedIndexedRepo)

Example 12 with FixedIndexedRepo

use of aQute.bnd.deployer.repository.FixedIndexedRepo in project bnd by bndtools.

the class AetherRepository method init.

protected final synchronized void init() throws Exception {
    if (initialised)
        return;
    // Initialise Aether
    DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
    locator.addService(ArtifactDescriptorReader.class, DefaultArtifactDescriptorReader.class);
    locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
    locator.addService(TransporterFactory.class, FileTransporterFactory.class);
    locator.addService(TransporterFactory.class, HttpTransporterFactory.class);
    locator.setErrorHandler(new ErrorHandler() {

        @Override
        public void serviceCreationFailed(Class<?> type, Class<?> impl, Throwable exception) {
            if (reporter != null)
                reporter.error("Service creation failed for type %s using impl %s: %s", type, impl, exception.getLocalizedMessage());
            exception.printStackTrace();
        }
    });
    repoSystem = locator.getService(RepositorySystem.class);
    if (repoSystem == null)
        throw new IllegalArgumentException("Failed to initialise Aether repository system");
    Builder builder = new RemoteRepository.Builder("remote", "default", mainUri.toString());
    if (username != null) {
        AuthenticationBuilder authBuilder = new AuthenticationBuilder().addUsername(username);
        if (password != null)
            authBuilder.addPassword(password);
        builder.setAuthentication(authBuilder.build());
    }
    remoteRepo = builder.build();
    localRepo = new LocalRepository(new File(cacheDir, "aether-local"));
    // Initialise Index
    if (indexUri == null) {
        indexedRepo = null;
    } else {
        // Test whether the index URI exists and is available.
        HttpURLConnection connection = (HttpURLConnection) indexUri.toURL().openConnection();
        try {
            connection.setRequestMethod("HEAD");
            int responseCode = connection.getResponseCode();
            if (responseCode >= 400) {
                indexedRepo = null;
            } else {
                indexedRepo = new FixedIndexedRepo();
                Map<String, String> config = new HashMap<String, String>();
                indexedRepo.setReporter(this.reporter);
                indexedRepo.setRegistry(registry);
                config.put(FixedIndexedRepo.PROP_CACHE, cacheDir.getAbsolutePath());
                config.put(FixedIndexedRepo.PROP_LOCATIONS, indexUri.toString());
                indexedRepo.setProperties(config);
            }
        } catch (UnknownHostException e) {
            return;
        } finally {
            connection.disconnect();
        }
    }
    initialised = true;
}
Also used : ErrorHandler(org.eclipse.aether.impl.DefaultServiceLocator.ErrorHandler) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) UnknownHostException(java.net.UnknownHostException) HashMap(java.util.HashMap) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) Builder(org.eclipse.aether.repository.RemoteRepository.Builder) LocalRepository(org.eclipse.aether.repository.LocalRepository) DefaultServiceLocator(org.eclipse.aether.impl.DefaultServiceLocator) RepositorySystem(org.eclipse.aether.RepositorySystem) HttpURLConnection(java.net.HttpURLConnection) File(java.io.File) FixedIndexedRepo(aQute.bnd.deployer.repository.FixedIndexedRepo)

Aggregations

FixedIndexedRepo (aQute.bnd.deployer.repository.FixedIndexedRepo)12 File (java.io.File)3 HashMap (java.util.HashMap)3 Workspace (aQute.bnd.build.Workspace)2 HttpTestServer (aQute.http.testservers.HttpTestServer)2 Resource (org.osgi.resource.Resource)2 Processor (aQute.bnd.osgi.Processor)1 BndPreferences (bndtools.preferences.BndPreferences)1 IOException (java.io.IOException)1 HttpURLConnection (java.net.HttpURLConnection)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 RepositorySystem (org.eclipse.aether.RepositorySystem)1 DefaultServiceLocator (org.eclipse.aether.impl.DefaultServiceLocator)1 ErrorHandler (org.eclipse.aether.impl.DefaultServiceLocator.ErrorHandler)1 LocalRepository (org.eclipse.aether.repository.LocalRepository)1 Builder (org.eclipse.aether.repository.RemoteRepository.Builder)1 AuthenticationBuilder (org.eclipse.aether.util.repository.AuthenticationBuilder)1