Search in sources :

Example 91 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 92 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 93 with Workspace

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

the class RepositoriesView method createActions.

void createActions() {
    collapseAllAction = new Action() {

        @Override
        public void run() {
            viewer.collapseAll();
        }
    };
    collapseAllAction.setEnabled(false);
    collapseAllAction.setText("Collapse All");
    collapseAllAction.setToolTipText("Collapse All");
    collapseAllAction.setImageDescriptor(Icons.desc("collapse"));
    collapseAllAction.setDisabledImageDescriptor(Icons.desc("collapse.disabled"));
    refreshAction = new Action() {

        @Override
        public void run() {
            new WorkspaceJob("Refresh repositories") {

                @Override
                public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
                    if (monitor == null)
                        monitor = new NullProgressMonitor();
                    monitor.subTask("Refresh all repositories");
                    try {
                        refreshAction.setEnabled(false);
                        Central.refreshPlugins();
                    } catch (Exception e) {
                        return new Status(Status.ERROR, Plugin.PLUGIN_ID, "Failed to refresh plugins", e);
                    } finally {
                        refreshAction.setEnabled(true);
                    }
                    return Status.OK_STATUS;
                }
            }.schedule();
        }
    };
    refreshAction.setEnabled(false);
    refreshAction.setText("Refresh");
    refreshAction.setToolTipText("Refresh Repositories Tree");
    refreshAction.setImageDescriptor(Icons.desc("refresh"));
    refreshAction.setDisabledImageDescriptor(Icons.desc("refresh.disabled"));
    addBundlesAction = new Action() {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            Object element = selection.getFirstElement();
            if (element != null && element instanceof RepositoryPlugin) {
                RepositoryPlugin repo = (RepositoryPlugin) element;
                if (repo.canWrite()) {
                    AddFilesToRepositoryWizard wizard = new AddFilesToRepositoryWizard(repo, new File[0]);
                    WizardDialog dialog = new WizardDialog(getViewSite().getShell(), wizard);
                    dialog.open();
                    viewer.refresh(repo);
                }
            }
        }
    };
    addBundlesAction.setEnabled(false);
    addBundlesAction.setText("Add");
    addBundlesAction.setToolTipText("Add Bundles to Repository");
    addBundlesAction.setImageDescriptor(Icons.desc("add"));
    addBundlesAction.setDisabledImageDescriptor(Icons.desc("add.disabled"));
    advancedSearchAction = new Action("Advanced Search", Action.AS_CHECK_BOX) {

        @Override
        public void run() {
            if (advancedSearchAction.isChecked()) {
                AdvancedSearchDialog dialog = new AdvancedSearchDialog(getSite().getShell());
                if (advancedSearchState != null) {
                    try {
                        XMLMemento memento = XMLMemento.createReadRoot(new StringReader(advancedSearchState));
                        dialog.restoreState(memento);
                    } catch (Exception e) {
                        logger.logError("Failed to load dialog state", e);
                    }
                }
                if (Window.OK == dialog.open()) {
                    Requirement req = dialog.getRequirement();
                    contentProvider.setRequirementFilter(req);
                    SWTUtil.recurseEnable(false, filterPanel);
                    viewer.refresh();
                    viewer.expandToLevel(2);
                } else {
                    advancedSearchAction.setChecked(false);
                }
                try {
                    XMLMemento memento = XMLMemento.createWriteRoot("search");
                    dialog.saveState(memento);
                    StringWriter writer = new StringWriter();
                    memento.save(writer);
                    advancedSearchState = writer.toString();
                } catch (Exception e) {
                    logger.logError("Failed to save dialog state", e);
                }
            } else {
                contentProvider.setRequirementFilter(null);
                SWTUtil.recurseEnable(true, filterPanel);
                viewer.refresh();
            }
        }
    };
    advancedSearchAction.setEnabled(false);
    advancedSearchAction.setText("Advanced Search");
    advancedSearchAction.setToolTipText("Toggle Advanced Search");
    advancedSearchAction.setImageDescriptor(Icons.desc("search"));
    advancedSearchAction.setDisabledImageDescriptor(Icons.desc("search.disabled"));
    downloadAction = new Action() {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            // The set of Repos included in the selection; they will be completely downloaded.
            Set<RemoteRepositoryPlugin> repos = new IdentityHashSet<>(selectionByType(selection, RemoteRepositoryPlugin.class));
            // The set of Bundles included in the selection.
            Set<RepositoryBundle> bundles = new IdentityHashSet<RepositoryBundle>();
            for (RepositoryBundle bundle : selectionByType(selection, RepositoryBundle.class)) {
                // filter out bundles that come from already-selected repos.
                if (!repos.contains(bundle.getRepo()))
                    bundles.add(bundle);
            }
            // The set of Bundle Versions included in the selection
            Set<RepositoryBundleVersion> bundleVersions = new IdentityHashSet<RepositoryBundleVersion>();
            for (RepositoryBundleVersion bundleVersion : selectionByType(selection, RepositoryBundleVersion.class)) {
                // filter out bundles that come from already-selected repos.
                if (!repos.contains(bundleVersion.getRepo()))
                    bundleVersions.add(bundleVersion);
            }
            RepoDownloadJob downloadJob = new RepoDownloadJob(repos, bundles, bundleVersions);
            downloadJob.schedule();
        }

        private <T> List<T> selectionByType(IStructuredSelection selection, Class<T> type) {
            List<T> result = new ArrayList<T>(selection.size());
            @SuppressWarnings("unchecked") Iterator<Object> iterator = selection.iterator();
            while (iterator.hasNext()) {
                Object item = iterator.next();
                if (type.isInstance(item)) {
                    @SuppressWarnings("unchecked") T cast = (T) item;
                    result.add(cast);
                }
            }
            return result;
        }
    };
    downloadAction.setEnabled(false);
    downloadAction.setText("Download Repository Content");
    downloadAction.setImageDescriptor(Icons.desc("download"));
    downloadAction.setDisabledImageDescriptor(Icons.desc("download.disabled"));
    offlineAction = new Action("Online/Offline Mode", Action.AS_CHECK_BOX) {

        @Override
        public void run() {
            Workspace workspace = Central.getWorkspaceIfPresent();
            if (workspace != null) {
                prefs.setWorkspaceOffline(offlineAction.isChecked());
            }
        }
    };
    offlineAction.setEnabled(false);
    offlineAction.setToolTipText("Go Offline");
    offlineAction.setImageDescriptor(Icons.desc("connected"));
    offlineAction.setDisabledImageDescriptor(Icons.desc("connected.disabled"));
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            boolean enable = false;
            @SuppressWarnings("unchecked") List<Object> list = selection.toList();
            for (Object item : list) {
                if (item instanceof RemoteRepositoryPlugin) {
                    enable = true;
                    break;
                } else if (item instanceof RepositoryEntry) {
                    if (!((RepositoryEntry) item).isLocal()) {
                        enable = true;
                        break;
                    }
                }
            }
            downloadAction.setEnabled(enable);
        }
    });
}
Also used : RepositoryBundle(bndtools.model.repo.RepositoryBundle) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Action(org.eclipse.jface.action.Action) RepositoryBundleVersion(bndtools.model.repo.RepositoryBundleVersion) Set(java.util.Set) IdentityHashSet(org.bndtools.utils.collections.IdentityHashSet) AddFilesToRepositoryWizard(bndtools.wizards.workspace.AddFilesToRepositoryWizard) RemoteRepositoryPlugin(aQute.bnd.service.RemoteRepositoryPlugin) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryEntry(bndtools.model.repo.RepositoryEntry) StringWriter(java.io.StringWriter) SWT(org.eclipse.swt.SWT) StringReader(java.io.StringReader) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) RemoteRepositoryPlugin(aQute.bnd.service.RemoteRepositoryPlugin) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) Requirement(org.osgi.resource.Requirement) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) XMLMemento(org.eclipse.ui.XMLMemento) IFile(org.eclipse.core.resources.IFile) File(java.io.File) JarFile(java.util.jar.JarFile) WizardDialog(org.eclipse.jface.wizard.WizardDialog) Workspace(aQute.bnd.build.Workspace)

Example 94 with Workspace

use of aQute.bnd.build.Workspace in project intellij-plugins by JetBrains.

the class BndWrapper method build.

/**
   * Builds the .jar file for the given module.
   */
public void build(@NotNull File bndFile, @NotNull File[] classPath, @NotNull File[] srcPath, @NotNull File outputFile) throws Exception {
    Workspace workspace = Workspace.findWorkspace(bndFile);
    if (workspace != null) {
        try (Project project = new Project(workspace, null, bndFile);
            ProjectBuilder projectBuilder = project.getBuilder(null)) {
            for (Builder sub : projectBuilder.getSubBuilders()) {
                File source = sub == projectBuilder ? bndFile : sub.getPropertiesFile();
                String prevSource = myReporter.setReportSource(source.getPath());
                try (Builder builder = new ReportingProjectBuilder(myReporter, (ProjectBuilder) sub)) {
                    builder.setProperties(source);
                    File output = sub == projectBuilder ? outputFile : new File(outputFile.getParent(), sub.getBsn() + ".jar");
                    doBuild(builder, output);
                } finally {
                    myReporter.setReportSource(prevSource);
                }
            }
        }
    } else {
        try (Builder mainBuilder = new Builder()) {
            mainBuilder.setProperties(bndFile);
            mainBuilder.setPedantic(false);
            for (Builder sub : mainBuilder.getSubBuilders()) {
                File source = sub == mainBuilder ? bndFile : sub.getPropertiesFile();
                String prevSource = myReporter.setReportSource(source.getPath());
                try (Builder builder = new ReportingBuilder(myReporter, sub)) {
                    builder.setProperties(source);
                    builder.setPedantic(false);
                    builder.setClasspath(classPath);
                    builder.setSourcepath(srcPath);
                    File output = sub == mainBuilder ? outputFile : new File(outputFile.getParent(), sub.getBsn() + ".jar");
                    doBuild(builder, output);
                } finally {
                    myReporter.setReportSource(prevSource);
                }
            }
        }
    }
}
Also used : Project(aQute.bnd.build.Project) ProjectBuilder(aQute.bnd.build.ProjectBuilder) ProjectBuilder(aQute.bnd.build.ProjectBuilder) JarFile(java.util.jar.JarFile) File(java.io.File) Workspace(aQute.bnd.build.Workspace)

Example 95 with Workspace

use of aQute.bnd.build.Workspace in project intellij-plugins by JetBrains.

the class BndModuleImportProvider method canImport.

@Override
public boolean canImport(@NotNull VirtualFile fileOrDir, @Nullable Project project) {
    Workspace ws = BndProjectImporter.getWorkspace(project);
    if (ws == null)
        return false;
    File projectDir = fileOrDir.isDirectory() ? new File(fileOrDir.getPath()) : new File(fileOrDir.getPath()).getParentFile();
    return FileUtil.filesEqual(ws.getBase(), projectDir.getParentFile()) && projectDir.isDirectory() && new File(projectDir, BndProjectImporter.BND_FILE).isFile();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Workspace(aQute.bnd.build.Workspace)

Aggregations

Workspace (aQute.bnd.build.Workspace)164 Project (aQute.bnd.build.Project)69 File (java.io.File)62 Processor (aQute.bnd.osgi.Processor)26 IOException (java.io.IOException)20 HashMap (java.util.HashMap)20 Container (aQute.bnd.build.Container)15 ArrayList (java.util.ArrayList)15 Version (aQute.bnd.version.Version)13 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)12 IProject (org.eclipse.core.resources.IProject)10 Run (aQute.bnd.build.Run)9 CoreException (org.eclipse.core.runtime.CoreException)9 Description (aQute.lib.getopt.Description)7 Collection (java.util.Collection)6 BndEditModel (aQute.bnd.build.model.BndEditModel)5 Jar (aQute.bnd.osgi.Jar)5 HttpTestServer (aQute.http.testservers.HttpTestServer)5 BuildException (org.apache.tools.ant.BuildException)5 IResource (org.eclipse.core.resources.IResource)5