Search in sources :

Example 1 with RefreshFileJob

use of bndtools.central.RefreshFileJob in project bndtools by bndtools.

the class AddFilesToRepositoryWizard method performFinishAddFiles.

private IStatus performFinishAddFiles(IProgressMonitor monitor) {
    MultiStatus status = new MultiStatus(Plugin.PLUGIN_ID, 0, "Failed to install one or more bundles", null);
    List<File> files = fileSelectionPage.getFiles();
    selectedBundles = new LinkedList<Pair<String, String>>();
    monitor.beginTask("Processing files", files.size());
    for (File file : files) {
        monitor.subTask(file.getName());
        try (Jar jar = new Jar(file)) {
            jar.setDoNotTouchManifest();
            Attributes mainAttribs = jar.getManifest().getMainAttributes();
            String bsn = BundleUtils.getBundleSymbolicName(mainAttribs);
            String version = mainAttribs.getValue(Constants.BUNDLE_VERSION);
            if (version == null)
                version = "0";
            selectedBundles.add(Pair.newInstance(bsn, version));
        } catch (Exception e) {
            status.add(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Failed to analyse JAR: {0}", file.getPath()), e));
            continue;
        }
        try {
            RepositoryPlugin.PutResult result = repository.put(new BufferedInputStream(IO.stream(file)), new RepositoryPlugin.PutOptions());
            if (result.artifact != null && result.artifact.getScheme().equals("file")) {
                File newFile = new File(result.artifact);
                RefreshFileJob refreshJob = new RefreshFileJob(newFile, false);
                if (refreshJob.needsToSchedule())
                    refreshJob.schedule();
            }
        } catch (Exception e) {
            status.add(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Failed to add JAR to repository: {0}", file.getPath()), e));
            continue;
        }
        monitor.worked(1);
    }
    return status;
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Attributes(java.util.jar.Attributes) MultiStatus(org.eclipse.core.runtime.MultiStatus) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) RefreshFileJob(bndtools.central.RefreshFileJob) CoreException(org.eclipse.core.runtime.CoreException) BufferedInputStream(java.io.BufferedInputStream) Jar(aQute.bnd.osgi.Jar) File(java.io.File) Pair(bndtools.types.Pair)

Aggregations

Jar (aQute.bnd.osgi.Jar)1 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)1 RefreshFileJob (bndtools.central.RefreshFileJob)1 Pair (bndtools.types.Pair)1 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 Attributes (java.util.jar.Attributes)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 Status (org.eclipse.core.runtime.Status)1