use of aQute.bnd.build.model.clauses.VersionedClause in project bnd by bndtools.
the class ResourceTest method testResourceToVersionedClause.
public void testResourceToVersionedClause() throws Exception {
ResourceBuilder rb = new ResourceBuilder();
rb.addManifest(Domain.domain(IO.getFile("../demo-fragment/generated/demo-fragment.jar")));
Resource resource = rb.build();
VersionedClause versionClause = ResourceUtils.toVersionClause(resource, "[===,==+)");
StringBuilder sb = new StringBuilder();
versionClause.formatTo(sb);
assertEquals("demo-fragment;version='[1.0.0,1.0.1)'", sb.toString());
}
use of aQute.bnd.build.model.clauses.VersionedClause in project intellij-plugins by JetBrains.
the class ResolveAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
VirtualFile virtualFile = event.getData(CommonDataKeys.VIRTUAL_FILE);
Project project = event.getProject();
if (virtualFile == null || project == null)
return;
Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
if (document == null)
return;
FileDocumentManager.getInstance().saveAllDocuments();
new Task.Backgroundable(project, message("bnd.resolve.requirements.title"), true) {
private Map<Resource, List<Wire>> resolveResult;
private String updatedText;
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setIndeterminate(true);
File file = new File(virtualFile.getPath());
try (Workspace workspace = Workspace.findWorkspace(file);
Run run = Run.createRun(workspace, file);
ProjectResolver projectResolver = new ProjectResolver(run)) {
resolveResult = projectResolver.resolve();
List<VersionedClause> versionedClauses = projectResolver.getRunBundles().stream().map(c -> {
Attrs attrs = new Attrs();
attrs.put(Constants.VERSION_ATTRIBUTE, c.getVersion());
return new VersionedClause(c.getBundleSymbolicName(), attrs);
}).sorted(Comparator.comparing(VersionedClause::getName)).collect(Collectors.toList());
BndEditModel editModel = new BndEditModel();
IDocument bndDocument = new aQute.bnd.properties.Document(document.getImmutableCharSequence().toString());
editModel.loadFrom(bndDocument);
editModel.setRunBundles(versionedClauses);
editModel.saveChangesTo(bndDocument);
updatedText = bndDocument.get();
} catch (ProcessCanceledException e) {
throw e;
} catch (Exception e) {
throw new WrappingException(e);
}
indicator.checkCanceled();
}
@Override
public void onSuccess() {
if (new ResolutionSucceedDialog(project, resolveResult).showAndGet() && FileModificationService.getInstance().prepareVirtualFilesForWrite(project, Collections.singleton(virtualFile))) {
writeCommandAction(project).withName("Bndrun Resolve").run(() -> document.setText(updatedText));
}
}
@Override
public void onThrowable(@NotNull Throwable t) {
Throwable cause = t instanceof WrappingException ? t.getCause() : t;
LOG.warn("Resolution failed", cause);
if (cause instanceof ResolutionException) {
new ResolutionFailedDialog(project, (ResolutionException) cause).show();
} else {
OsmorcBundle.notification(message("bnd.resolve.failed.title"), cause.getMessage(), NotificationType.ERROR).notify(project);
}
}
}.queue();
}
use of aQute.bnd.build.model.clauses.VersionedClause in project bndtools by bndtools.
the class ResolutionWizard method performFinish.
@Override
public boolean performFinish() {
Collection<Resource> resources;
ResolutionResult result = resultsPage.getResult();
if (result != null && result.getOutcome() == ResolutionResult.Outcome.Resolved) {
resources = result.getResourceWirings().keySet();
} else if (preserveRunBundleUnresolved) {
return true;
} else {
resources = Collections.emptyList();
}
// Open stream for physical paths list in target dir
PrintStream pathsStream = null;
try {
File targetDir;
Project bndProject = model.getProject();
targetDir = bndProject.getTargetDir();
if (targetDir == null)
targetDir = file.getLocation().toFile().getParentFile();
if (!targetDir.exists() && !targetDir.mkdirs()) {
throw new IOException("Could not create target directory " + targetDir);
}
File pathsFile = new File(targetDir, file.getName() + RESOLVED_PATHS_EXTENSION);
pathsStream = new PrintStream(pathsFile, "UTF-8");
} catch (Exception e) {
logger.logError("Unable to write resolved path list in target directory for project " + file.getProject().getName(), e);
}
// Generate -runbundles and path list
try {
List<VersionedClause> runBundles = new ArrayList<VersionedClause>(resources.size());
for (Resource resource : resources) {
VersionedClause runBundle = resourceToRunBundle(resource);
// [cs] Skip dups
if (runBundles.contains(runBundle)) {
continue;
}
runBundles.add(runBundle);
if (pathsStream != null) {
URI uri;
try {
uri = ResourceUtils.getURI(ResourceUtils.getContentCapability(resource));
} catch (IllegalArgumentException e) {
logger.logError("Resource has no content capability: " + ResourceUtils.getIdentity(resource), e);
continue;
}
VersionedClause runBundleWithUri = runBundle.clone();
runBundleWithUri.getAttribs().put(BndConstants.RESOLUTION_URI_ATTRIBUTE, uri.toString());
StringBuilder builder = new StringBuilder();
runBundleWithUri.formatTo(builder, clauseAttributeSorter);
pathsStream.println(builder.toString());
}
}
Collections.sort(runBundles, new Comparator<VersionedClause>() {
@Override
public int compare(VersionedClause vc1, VersionedClause vc2) {
int diff = vc1.getName().compareTo(vc2.getName());
if (diff != 0)
return diff;
String r1 = vc1.getVersionRange();
if (r1 == null)
r1 = "";
String r2 = vc2.getVersionRange();
if (r2 == null)
r2 = "";
return r1.compareTo(r2);
}
});
// Do not change the order of existing runbundles because they migh have been ordered manually
List<VersionedClause> diffAddBundles = new ArrayList<>(runBundles);
List<VersionedClause> oldRunBundles = model.getRunBundles();
if (oldRunBundles == null)
oldRunBundles = Collections.emptyList();
else
diffAddBundles.removeAll(oldRunBundles);
List<VersionedClause> diffRemvedBundles = new ArrayList<>(oldRunBundles);
diffRemvedBundles.removeAll(runBundles);
List<VersionedClause> updatedRunBundles = new ArrayList<>(oldRunBundles);
updatedRunBundles.addAll(diffAddBundles);
updatedRunBundles.removeAll(diffRemvedBundles);
// do not use getRunBundles().addAll, because it will not reflect in UI or File
model.setRunBundles(updatedRunBundles);
} finally {
if (pathsStream != null) {
IO.close(pathsStream);
}
}
return true;
}
use of aQute.bnd.build.model.clauses.VersionedClause in project bndtools by bndtools.
the class ImportPackageQuickFixProcessorTest method addBundleToRepo_createsCorrectCapability.
@Test
public // Meta-test
void addBundleToRepo_createsCorrectCapability() throws Exception {
clearRepos();
Attrs v100 = new Attrs();
v100.put(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE, "1.0.0");
Attrs v110 = new Attrs();
v110.put(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE, "1.1.0");
addBundleToRepo("Repo 1", "my.test.bundle", new VersionedClause("org.osgi.framework", v100), new VersionedClause("my.test.pkg", v110));
Map<String, Collection<Capability>> caps = repoMap.get("Repo 1");
assertThat(caps).as("map keys").containsKeys("org.osgi.framework", "my.test.pkg");
assertThat(frameworkBundles).as("framework bundle").containsExactly("my.test.bundle");
Resource bundleResource = null;
for (Map.Entry<String, Collection<Capability>> entry : caps.entrySet()) {
Collection<Capability> packageCaps = entry.getValue();
assertThat(packageCaps).isNotNull().hasSize(1);
for (Capability pkg : packageCaps) {
assertThat(pkg).as("pkg").isNotNull();
assertThat(pkg.getResource()).as("resource").isNotNull();
if (bundleResource == null) {
bundleResource = pkg.getResource();
} else {
assertThat(pkg.getResource()).as("resource").isSameAs(bundleResource);
}
}
}
assertThat(bundleResource).as("bundleResource").isNotNull();
}
use of aQute.bnd.build.model.clauses.VersionedClause in project bndtools by bndtools.
the class ImportPackageQuickFixProcessorTest method getCorrections_forBundleInTwoRepos_describesBundles.
@Test
public void getCorrections_forBundleInTwoRepos_describesBundles() {
addBundleToRepo("Repo 2", "my.test.bundle", new VersionedClause("org.osgi.framework", new Attrs()));
AddBundleCompletionProposal[] props = proposalsForImport("`org.osgi.framework'.*");
assertThat(props).haveExactly(1, suggestsBundle("my.test.bundle", "Repo 1", "Repo 2"));
}
Aggregations