Search in sources :

Example 21 with Workspace

use of aQute.bnd.build.Workspace in project bnd by bndtools.

the class OSGiRepository method getIndex.

synchronized OSGiIndex getIndex(boolean refresh) throws Exception {
    HttpClient client = registry.getPlugin(HttpClient.class);
    Workspace ws = registry.getPlugin(Workspace.class);
    if (ws == null) {
        ws = Workspace.createDefaultWorkspace();
    }
    String cachePath = config.cache();
    File cache = (cachePath == null) ? ws.getCache(config.name()) : ws.getFile(cachePath);
    if (refresh)
        IO.delete(cache);
    List<String> strings = Strings.split(config.locations());
    List<URI> urls = new ArrayList<>(strings.size());
    for (String s : strings) {
        urls.add(new URI(s));
    }
    if (poller == null) {
        if (!(ws.getGestalt().containsKey(Constants.GESTALT_BATCH) || ws.getGestalt().containsKey(Constants.GESTALT_CI) || ws.getGestalt().containsKey(Constants.GESTALT_OFFLINE))) {
            int polltime = config.poll_time(DEFAULT_POLL_TIME);
            if (polltime > 0) {
                poller = Processor.getScheduledExecutor().scheduleAtFixedRate(new Runnable() {

                    @Override
                    public void run() {
                        if (inPoll.getAndSet(true))
                            return;
                        try {
                            poll();
                        } catch (Exception e) {
                            logger.debug("During polling", e);
                        } finally {
                            inPoll.set(false);
                        }
                    }
                }, polltime, polltime, TimeUnit.SECONDS);
            }
        }
    }
    index = new OSGiIndex(config.name(), client, cache, urls, config.max_stale(YEAR), refresh);
    stale = false;
    return index;
}
Also used : HttpClient(aQute.bnd.http.HttpClient) ArrayList(java.util.ArrayList) File(java.io.File) URI(java.net.URI) IOException(java.io.IOException) Workspace(aQute.bnd.build.Workspace)

Example 22 with Workspace

use of aQute.bnd.build.Workspace in project bnd by bndtools.

the class MavenBndRepository method startPoll.

private void startPoll(final IndexFile index) {
    Workspace ws = registry.getPlugin(Workspace.class);
    if ((ws != null) && (ws.getGestalt().containsKey(Constants.GESTALT_BATCH) || ws.getGestalt().containsKey(Constants.GESTALT_CI) || ws.getGestalt().containsKey(Constants.GESTALT_OFFLINE))) {
        return;
    }
    final AtomicBoolean busy = new AtomicBoolean();
    indexPoller = Processor.getScheduledExecutor().scheduleAtFixedRate(new Runnable() {

        @Override
        public void run() {
            if (busy.getAndSet(true))
                return;
            try {
                poll();
            } catch (Exception e) {
                reporter.error("Error when polling index for %s for change", this);
            } finally {
                busy.set(false);
            }
        }
    }, 5000, 5000, TimeUnit.MILLISECONDS);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) Workspace(aQute.bnd.build.Workspace)

Example 23 with Workspace

use of aQute.bnd.build.Workspace in project bnd by bndtools.

the class TestingMojo method testing.

private void testing(File runFile, FileSetRepository fileSetRepository) throws Exception {
    if (!runFile.exists()) {
        logger.error("Could not find bnd run file {}", runFile);
        errors++;
        return;
    }
    String bndrun = getNamePart(runFile);
    File workingDir = new File(cwd, bndrun);
    File cnf = new File(workingDir, Workspace.CNFDIR);
    IO.mkdirs(cnf);
    try (Bndrun run = Bndrun.createBndrun(null, runFile)) {
        run.setBase(workingDir);
        Workspace workspace = run.getWorkspace();
        workspace.setBuildDir(cnf);
        workspace.setOffline(session.getSettings().isOffline());
        workspace.addBasicPlugin(fileSetRepository);
        for (RepositoryPlugin repo : workspace.getRepositories()) {
            repo.list(null);
        }
        run.getInfo(workspace);
        report(run);
        if (!run.isOk()) {
            return;
        }
        if (resolve) {
            try {
                String runBundles = run.resolve(failOnChanges, false);
                if (!run.isOk()) {
                    return;
                }
                run.setProperty(Constants.RUNBUNDLES, runBundles);
            } catch (ResolutionException re) {
                logger.error("Unresolved requirements: {}", ResolveProcess.format(re.getUnresolvedRequirements()));
                throw re;
            } finally {
                report(run);
            }
        }
        try {
            run.test(new File(reportsDir, bndrun), null);
        } finally {
            report(run);
        }
    }
}
Also used : ResolutionException(org.osgi.service.resolver.ResolutionException) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) File(java.io.File) Bndrun(biz.aQute.resolve.Bndrun) Workspace(aQute.bnd.build.Workspace)

Example 24 with Workspace

use of aQute.bnd.build.Workspace in project bnd by bndtools.

the class ResolveCommand method _repos.

public void _repos(RepoOptions options) throws Exception {
    Workspace ws = bnd.getWorkspace(options.workspace());
    if (ws == null) {
        error("No workspace");
        return;
    }
    List<Repository> plugins = ws.getPlugins(Repository.class);
    bnd.out.println(Strings.join("\n", plugins));
}
Also used : Repository(org.osgi.service.repository.Repository) Workspace(aQute.bnd.build.Workspace)

Example 25 with Workspace

use of aQute.bnd.build.Workspace in project bnd by bndtools.

the class bnd method _sync.

/**
	 * Force a cache update of the workspace
	 * 
	 * @throws Exception
	 */
public void _sync(projectOptions options) throws Exception {
    Workspace ws = getWorkspace((File) null);
    if (ws == null) {
        error("Cannot find workspace, either reside in a project directory, point to a project with --project, or reside in the workspace directory");
        return;
    }
    ws.syncCache();
}
Also used : Workspace(aQute.bnd.build.Workspace)

Aggregations

Workspace (aQute.bnd.build.Workspace)171 Project (aQute.bnd.build.Project)71 File (java.io.File)66 Processor (aQute.bnd.osgi.Processor)27 HashMap (java.util.HashMap)22 IOException (java.io.IOException)20 ArrayList (java.util.ArrayList)19 Container (aQute.bnd.build.Container)17 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)13 Version (aQute.bnd.version.Version)13 Run (aQute.bnd.build.Run)11 IProject (org.eclipse.core.resources.IProject)11 CoreException (org.eclipse.core.runtime.CoreException)10 IResource (org.eclipse.core.resources.IResource)8 BndEditModel (aQute.bnd.build.model.BndEditModel)7 Description (aQute.lib.getopt.Description)7 Bndrun (biz.aQute.resolve.Bndrun)7 Attrs (aQute.bnd.header.Attrs)5 HttpClient (aQute.bnd.http.HttpClient)5 Jar (aQute.bnd.osgi.Jar)5