use of aQute.bnd.osgi.repository.SimpleIndexer in project bndtools by bndtools.
the class GenerateIndexJob method run.
@Override
protected IStatus run(IProgressMonitor monitor) {
SubMonitor progress = SubMonitor.convert(monitor);
// Generate index
try {
new SimpleIndexer().files(files).base(base).compress(compress).name(name).index(outputFile);
} catch (Exception e) {
return new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error indexing files.", e);
}
// Make eclipse aware of the new/changed resource
final IWorkspace ws = ResourcesPlugin.getWorkspace();
final IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
IFile[] outputResources = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(outputFile.toURI());
if (outputResources != null) {
for (IFile resource : outputResources) {
resource.refreshLocal(IResource.DEPTH_ZERO, monitor);
}
}
}
};
try {
ws.run(runnable, progress.newChild(1, SubMonitor.SUPPRESS_NONE));
} catch (CoreException e) {
return new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error refreshing workspace files.", e);
}
return Status.OK_STATUS;
}
use of aQute.bnd.osgi.repository.SimpleIndexer in project bndtools by bndtools.
the class BuiltBundleIndexer method builtBundles.
@Override
public void builtBundles(final IProject project, IPath[] paths) {
IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
final URI workspaceRootUri = wsroot.getLocationURI();
Set<File> files = new HashSet<File>();
for (IPath path : paths) {
try {
IFile ifile = wsroot.getFile(path);
IPath location = ifile.getLocation();
if (location != null)
files.add(location.toFile());
} catch (IllegalArgumentException e) {
System.err.println("### Error processing path: " + path);
e.printStackTrace();
}
}
// Generate the index file
File indexFile;
try {
Project model = Central.getProject(project);
File target = model.getTarget();
indexFile = new File(target, INDEX_FILENAME);
IFile indexPath = wsroot.getFile(Central.toPath(indexFile));
new SimpleIndexer().files(files).base(project.getLocation().toFile().toURI()).name(project.getName()).analyzer((f, rb) -> {
Capability cap = new CapabilityBuilder("bndtools.workspace").addAttribute("bndtools.workspace", workspaceRootUri.toString()).addAttribute("project.path", project.getFullPath().toString()).buildSyntheticCapability();
rb.addCapability(cap);
}).index(indexFile);
indexPath.refreshLocal(IResource.DEPTH_ZERO, null);
if (indexPath.exists())
indexPath.setDerived(true, null);
} catch (Exception e) {
logger.logError(MessageFormat.format("Failed to generate index file for bundles in project {0}.", project.getName()), e);
return;
}
// Parse the index and add to the workspace repository
try (InputStream input = IO.stream(indexFile)) {
WorkspaceR5Repository workspaceRepo = Central.getWorkspaceR5Repository();
workspaceRepo.loadProjectIndex(project, input, project.getLocation().toFile().toURI());
} catch (Exception e) {
logger.logError("Failed to update workspace index.", e);
}
}
Aggregations