use of bndtools.editor.contents.PackageInfoStyle in project bndtools by bndtools.
the class ExportPatternsListPart method generatePackageInfos.
private static void generatePackageInfos(final Collection<? extends FileVersionTuple> pkgs) throws CoreException {
final IWorkspaceRunnable wsOperation = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, pkgs.size());
MultiStatus status = new MultiStatus(Plugin.PLUGIN_ID, 0, "Errors occurred while creating packageinfo files.", null);
for (FileVersionTuple pkg : pkgs) {
IContainer[] locations = ResourcesPlugin.getWorkspace().getRoot().findContainersForLocationURI(pkg.getFile().toURI());
if (locations != null && locations.length > 0) {
IContainer container = locations[0];
PackageInfoStyle packageInfoStyle = PackageInfoStyle.calculatePackageInfoStyle(container.getProject());
IFile pkgInfoFile = container.getFile(new Path(packageInfoStyle.getFileName()));
try {
String formattedPackageInfo = packageInfoStyle.format(pkg.getVersion(), pkg.getName());
ByteArrayInputStream input = new ByteArrayInputStream(formattedPackageInfo.getBytes("UTF-8"));
if (pkgInfoFile.exists())
pkgInfoFile.setContents(input, false, true, progress.newChild(1, 0));
else
pkgInfoFile.create(input, false, progress.newChild(1, 0));
} catch (CoreException e) {
status.add(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error creating file " + pkgInfoFile.getFullPath(), e));
} catch (UnsupportedEncodingException e) {
/* just ignore, should never happen */
}
}
}
if (!status.isOK())
throw new CoreException(status);
}
};
IRunnableWithProgress uiOperation = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
ResourcesPlugin.getWorkspace().run(wsOperation, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
};
try {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().run(true, true, uiOperation);
} catch (InvocationTargetException e) {
throw (CoreException) e.getTargetException();
} catch (InterruptedException e) {
// ignore
}
}
use of bndtools.editor.contents.PackageInfoStyle in project bndtools by bndtools.
the class ExportPatternsListPart method findSourcePackagesWithoutPackageInfo.
private Collection<FileVersionTuple> findSourcePackagesWithoutPackageInfo(Collection<? extends ExportedPackage> pkgs) throws Exception {
Map<String, FileVersionTuple> result = new HashMap<String, FileVersionTuple>();
Project project = getProject();
if (project != null) {
Collection<File> sourceDirs = project.getSourcePath();
for (File sourceDir : sourceDirs) {
for (ExportedPackage pkg : pkgs) {
if (!result.containsKey(pkg.getName())) {
File pkgDir = new File(sourceDir, pkg.getName().replace('.', '/'));
if (pkgDir.isDirectory()) {
PackageInfoStyle existingPkgInfo = PackageInfoStyle.findExisting(pkgDir);
if (existingPkgInfo == null)
result.put(pkg.getName(), new FileVersionTuple(pkg.getName(), pkgDir));
}
}
}
}
}
return result.values();
}
Aggregations