use of aQute.bnd.build.model.clauses.ExportedPackage in project bnd by bndtools.
the class BndEditModel method setExportedPackages.
public void setExportedPackages(List<? extends ExportedPackage> exports) {
boolean referencesBundleVersion = false;
if (exports != null) {
for (ExportedPackage pkg : exports) {
String versionString = pkg.getVersionString();
if (versionString != null && versionString.indexOf(BUNDLE_VERSION_MACRO) > -1) {
referencesBundleVersion = true;
}
}
}
List<ExportedPackage> oldValue = getExportedPackages();
doSetObject(Constants.EXPORT_PACKAGE, oldValue, exports, headerClauseListFormatter);
if (referencesBundleVersion && getBundleVersionString() == null) {
setBundleVersion(Version.emptyVersion.toString());
}
}
use of aQute.bnd.build.model.clauses.ExportedPackage in project bndtools by bndtools.
the class PkgRenameParticipant method createChange.
@Override
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
final Map<IFile, TextChange> fileChanges = new HashMap<IFile, TextChange>();
IResourceProxyVisitor visitor = new IResourceProxyVisitor() {
@Override
public boolean visit(IResourceProxy proxy) throws CoreException {
if ((proxy.getType() == IResource.FOLDER) || (proxy.getType() == IResource.PROJECT)) {
return true;
}
if (!((proxy.getType() == IResource.FILE) && proxy.getName().toLowerCase().endsWith(".bnd"))) {
return false;
}
/* we're dealing with a *.bnd file */
/* get the proxied file */
IFile resource = (IFile) proxy.requestResource();
/* read the file as a single string */
String bndFileText = null;
try {
bndFileText = FileUtils.readFully(resource).get();
} catch (Exception e) {
String str = "Could not read file " + proxy.getName();
logger.logError(str, e);
throw new OperationCanceledException(str);
}
/*
* get the previous change for this file if it exists, or otherwise create a new change for it, but do
* not store it yet: wait until we know if there are actually changes in the file
*/
TextChange fileChange = getTextChange(resource);
final boolean fileChangeIsNew = (fileChange == null);
if (fileChange == null) {
fileChange = new TextFileChange(proxy.getName(), resource);
fileChange.setEdit(new MultiTextEdit());
}
TextEdit rootEdit = fileChange.getEdit();
BndEditModel model = new BndEditModel();
Document document = new Document(bndFileText);
try {
model.loadFrom(document);
} catch (IOException e) {
String str = "Could not load document " + proxy.getName();
logger.logError(str, e);
throw new OperationCanceledException(str);
}
/* loop over all renames to perform */
for (Map.Entry<IPackageFragment, RenameArguments> entry : pkgFragments.entrySet()) {
IPackageFragment pkgFragment = entry.getKey();
RenameArguments arguments = entry.getValue();
final String oldName = pkgFragment.getElementName();
final String newName = arguments.getNewName();
List<ImportPattern> newImportedPackages = makeNewHeaders(model.getImportPatterns(), oldName, newName);
if (newImportedPackages != null) {
model.setImportPatterns(newImportedPackages);
}
List<ExportedPackage> newExportedPackages = makeNewHeaders(model.getExportedPackages(), oldName, newName);
if (newExportedPackages != null) {
model.setExportedPackages(newExportedPackages);
}
List<String> newPrivatePackages = makeNewHeaders(model.getPrivatePackages(), oldName, newName);
if (newPrivatePackages != null) {
model.setPrivatePackages(newPrivatePackages);
}
Map<String, String> changes = model.getDocumentChanges();
for (Iterator<Entry<String, String>> iter = changes.entrySet().iterator(); iter.hasNext(); ) {
Entry<String, String> change = iter.next();
String propertyName = change.getKey();
String stringValue = change.getValue();
addEdit(document, rootEdit, propertyName, stringValue);
iter.remove();
}
Pattern pattern = Pattern.compile(/* match start boundary */
"(^|" + grammarSeparator + ")" + /* match bundle activator */
"(Bundle-Activator\\s*:\\s*)" + /* match itself / package name */
"(" + Pattern.quote(oldName) + ")" + /* match class name */
"(\\.[^\\.]+)" + /* match end boundary */
"(" + grammarSeparator + "|" + Pattern.quote("\\") + "|$)");
/* find all matches to replace and add them to the root edit */
Matcher matcher = pattern.matcher(bndFileText);
while (matcher.find()) {
rootEdit.addChild(new ReplaceEdit(matcher.start(3), matcher.group(3).length(), newName));
}
}
/*
* only store the changes when no changes were stored before for this file and when there are actually
* changes.
*/
if (fileChangeIsNew && rootEdit.hasChildren()) {
fileChanges.put(resource, fileChange);
}
return false;
}
};
/* determine which projects have to be visited */
Set<IProject> projectsToVisit = new HashSet<IProject>();
for (IPackageFragment pkgFragment : pkgFragments.keySet()) {
projectsToVisit.add(pkgFragment.getResource().getProject());
for (IProject projectToVisit : pkgFragment.getResource().getProject().getReferencingProjects()) {
projectsToVisit.add(projectToVisit);
}
for (IProject projectToVisit : pkgFragment.getResource().getProject().getReferencedProjects()) {
projectsToVisit.add(projectToVisit);
}
}
/* visit the projects */
for (IProject projectToVisit : projectsToVisit) {
projectToVisit.accept(visitor, IContainer.NONE);
}
if (fileChanges.isEmpty()) {
/* no changes at all */
return null;
}
/* build a composite change with all changes */
CompositeChange cs = new CompositeChange(changeTitle);
for (TextChange fileChange : fileChanges.values()) {
cs.add(fileChange);
}
return cs;
}
use of aQute.bnd.build.model.clauses.ExportedPackage in project bndtools by bndtools.
the class BndEditorContentOutlinePage method createControl.
@Override
public void createControl(Composite parent) {
super.createControl(parent);
TreeViewer viewer = getTreeViewer();
viewer.setAutoExpandLevel(2);
viewer.setContentProvider(new BndEditorContentOutlineProvider(viewer));
viewer.setLabelProvider(new BndEditorContentOutlineLabelProvider());
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
Object element = selection.getFirstElement();
if (element instanceof String) {
if (BndEditorContentOutlineProvider.EXPORTS.equals(element)) {
editor.setActivePage(BndEditor.CONTENT_PAGE);
} else if (BndEditorContentOutlineProvider.IMPORT_PATTERNS.equals(element)) {
editor.setActivePage(BndEditor.CONTENT_PAGE);
} else if (BndEditorContentOutlineProvider.PRIVATE_PKGS.equals(element)) {
editor.setActivePage(BndEditor.CONTENT_PAGE);
} else if (BndEditorContentOutlineProvider.PLUGINS.equals(element)) {
editor.setActivePage(BndEditor.WORKSPACE_PAGE);
} else {
editor.setActivePage((String) element);
}
} else if (element instanceof ExportedPackage) {
BundleContentPage contentsPage = (BundleContentPage) editor.setActivePage(BndEditor.CONTENT_PAGE);
if (contentsPage != null) {
contentsPage.setSelectedExport((ExportedPackage) element);
}
} else if (element instanceof PrivatePkg) {
BundleContentPage contentsPage = (BundleContentPage) editor.setActivePage(BndEditor.CONTENT_PAGE);
if (contentsPage != null) {
contentsPage.setSelectedPrivatePkg(((PrivatePkg) element).pkg);
}
} else if (element instanceof ImportPattern) {
BundleContentPage contentsPage = (BundleContentPage) editor.setActivePage(BndEditor.CONTENT_PAGE);
if (contentsPage != null) {
contentsPage.setSelectedImport((ImportPattern) element);
}
} else if (element instanceof PluginClause) {
WorkspacePage workspacePage = (WorkspacePage) editor.setActivePage(BndEditor.WORKSPACE_PAGE);
if (workspacePage != null)
workspacePage.setSelectedPlugin(((PluginClause) element).header);
}
}
});
viewer.setInput(model);
}
use of aQute.bnd.build.model.clauses.ExportedPackage 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();
}
use of aQute.bnd.build.model.clauses.ExportedPackage in project bndtools by bndtools.
the class EnrouteProjectTemplate method generateBndFile.
private Resource generateBndFile(String projectName, String pkg) {
BndEditModel model = new BndEditModel();
model.setPrivatePackages(Arrays.asList(new String[] { pkg + ".provider" }));
model.setExportedPackages(Arrays.asList(new ExportedPackage(projectName + ".api", new Attrs())));
model.setBundleDescription("${warning:please explain what this bundle does}");
model.setBundleVersion("1.0.0.${tstamp}");
List<VersionedClause> buildPath = new ArrayList<VersionedClause>();
List<VersionedClause> tmp;
tmp = model.getBuildPath();
if (tmp != null)
buildPath.addAll(tmp);
Attrs attrs = new Attrs();
attrs.put("version", "@1.0");
buildPath.add(new VersionedClause("osgi.enroute.base.api", attrs));
buildPath.add(new VersionedClause("osgi.enroute.base.junit", attrs));
model.setBuildPath(buildPath);
Document doc = new Document("");
model.saveChangesTo(doc);
StringResource bndBndResource = new StringResource(doc.get());
return bndBndResource;
}
Aggregations