use of io.fabric8.agent.download.StreamProvider in project fabric8 by jboss-fuse.
the class ArchetypeGenerateAction method fetchArchetype.
/**
* Fetches archetype from the configured repositories
* TODO: make this code available to hawt.io/JMX too
*/
private File fetchArchetype(Archetype archetype) throws IOException {
MavenResolver resolver = MavenResolvers.createMavenResolver(new Hashtable<String, String>(), "org.ops4j.pax.url.mvn");
DownloadManager dm = DownloadManagers.createDownloadManager(resolver, Executors.newSingleThreadScheduledExecutor());
final AtomicReference<File> file = new AtomicReference<>();
String url = String.format("mvn:%s/%s/%s", archetype.groupId, archetype.artifactId, archetype.version);
Downloader downloader = dm.createDownloader();
downloader.download(url, new DownloadCallback() {
@Override
public void downloaded(StreamProvider provider) throws Exception {
file.set(provider.getFile());
}
});
// wait for download
try {
boolean init = false;
for (int i = 0; i < 2 * 60 && file.get() == null; i++) {
// dont do anything in the first 3 seconds as we likely can download it faster
if (i > 3) {
if (!init) {
System.out.print("Downloading archetype in progress: ");
init = true;
}
System.out.print(".");
}
// only sleep 0.5 sec so we can react faster
Thread.sleep(500);
}
} catch (InterruptedException e) {
System.err.println("\nFailed to download " + archetype);
throw new IOException(e.getMessage(), e);
}
try {
downloader.await();
return file.get();
} catch (Exception e) {
System.err.println("\nFailed to download archetype within 60 seconds: " + archetype);
throw new IOException("Failed to download archetype within 60 seconds: " + archetype);
}
}
use of io.fabric8.agent.download.StreamProvider in project fabric8 by jboss-fuse.
the class Deployer method getBundleInputStream.
protected InputStream getBundleInputStream(Resource resource, Map<String, StreamProvider> providers) throws IOException {
String uri = getUri(resource);
if (uri == null) {
throw new IllegalStateException("Resource has no uri");
}
StreamProvider provider = providers.get(uri);
if (provider == null) {
throw new IllegalStateException("Resource " + uri + " has no StreamProvider");
}
return new FileInputStream(provider.getFile());
}
use of io.fabric8.agent.download.StreamProvider in project fabric8 by jboss-fuse.
the class AgentUtils method downloadRepositories.
public static Callable<Map<String, Repository>> downloadRepositories(DownloadManager manager, Set<String> uris) throws MultiException, InterruptedException, MalformedURLException {
final Map<String, Repository> repositories = new HashMap<>();
final Downloader downloader = manager.createDownloader();
final File targetLocation = getDefaultKarafRepository();
for (String uri : uris) {
downloader.download(uri, new DownloadCallback() {
@Override
public void downloaded(StreamProvider provider) throws Exception {
String uri = provider.getUrl();
Repository repository = new Repository(URI.create(uri));
repository.load(new FileInputStream(provider.getFile()), true);
synchronized (repositories) {
repositories.put(uri, repository);
}
for (URI repo : repository.getRepositories()) {
downloader.download(repo.toASCIIString(), this);
}
Artifact artifact = Utils.mvnurlToArtifact(uri, true);
if (artifact == null || artifact.getVersion() == null || !artifact.getVersion().endsWith("-SNAPSHOT")) {
// we need a feature repository to be available in ${karaf.home}/${karaf.default.repository}
// it makes patching much easier
// ENTESB-6931: don't store SNAPSHOT feature repositories in ${karaf.home}/${karaf.default.repository}
storeInDefaultKarafRepository(targetLocation, provider.getFile(), uri);
}
}
});
}
return new Callable<Map<String, Repository>>() {
@Override
public Map<String, Repository> call() throws Exception {
downloader.await();
return repositories;
}
};
}
Aggregations