use of aQute.bnd.build.model.clauses.VersionedClause in project bndtools by bndtools.
the class RepositoryBundleUtils method convertRepoBundleVersion.
public static VersionedClause convertRepoBundleVersion(RepositoryBundleVersion bundleVersion, DependencyPhase phase) {
Attrs attribs = new Attrs();
if (RepoUtils.isWorkspaceRepo(bundleVersion.getParentBundle().getRepo()))
attribs.put(Constants.VERSION_ATTRIBUTE, VERSION_LATEST);
else {
StringBuilder builder = new StringBuilder();
builder.append(bundleVersion.getVersion().getMajor());
builder.append('.').append(bundleVersion.getVersion().getMinor());
if (phase != DependencyPhase.Build)
builder.append('.').append(bundleVersion.getVersion().getMicro());
attribs.put(Constants.VERSION_ATTRIBUTE, builder.toString());
}
return new VersionedClause(bundleVersion.getParentBundle().getBsn(), attribs);
}
use of aQute.bnd.build.model.clauses.VersionedClause in project bnd by bndtools.
the class ResourceTest method testSnapshotResourceToVersionedClause.
public void testSnapshotResourceToVersionedClause() throws Exception {
ResourceBuilder rb = new ResourceBuilder();
rb.addManifest(Domain.domain(IO.getFile("../demo-fragment/generated/demo-fragment.jar")));
Attrs attrs = new Attrs();
attrs.put("bnd.workspace.project", "demo-fragment");
rb.addCapability(CapabilityBuilder.createCapReqBuilder("bnd.workspace.project", attrs));
Resource resource = rb.build();
VersionedClause versionClause = ResourceUtils.toVersionClause(resource, "[===,==+)");
StringBuilder sb = new StringBuilder();
versionClause.formatTo(sb);
assertEquals("demo-fragment;version=snapshot", 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 bnd by bndtools.
the class RunconfigToDistributionTask method execute.
@Override
public void execute() throws BuildException {
try {
createReleaseDir();
BndEditModel model = new BndEditModel();
model.loadFrom(bndFile);
Project bndProject = new Project(new Workspace(rootDir), buildProject, bndFile);
List<RepositoryPlugin> repositories = bndProject.getPlugins(RepositoryPlugin.class);
if (allowSnapshots) {
snapshots = indexBundleSnapshots();
}
for (VersionedClause runBundle : model.getRunBundles()) {
String bsn = runBundle.getName();
if (bsn.endsWith(".jar")) {
bsn = bsn.substring(0, bsn.indexOf(".jar"));
}
if (allowSnapshots && snapshots.containsKey(bsn)) {
Jar jar = snapshots.get(bsn);
jar.write(new File(outputDir, jar.getName() + "-" + jar.getVersion() + ".jar"));
} else {
Version version = null;
File foundJar = null;
for (RepositoryPlugin repo : repositories) {
SortedSet<Version> versions = repo.versions(bsn);
for (Version availableVersion : versions) {
VersionRange range = null;
if (runBundle.getVersionRange() != null && !runBundle.getVersionRange().equals(Constants.VERSION_ATTR_LATEST)) {
range = new VersionRange(runBundle.getVersionRange());
}
boolean rangeMatches = range == null || range.includes(availableVersion);
boolean availableMatches = version == null || availableVersion.compareTo(version) > 0;
if (rangeMatches && availableMatches) {
version = availableVersion;
foundJar = repo.get(bsn, version, null);
}
}
}
if (foundJar != null) {
File outputFile = new File(outputDir, foundJar.getName());
Files.copy(foundJar.toPath(), outputFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
} else {
log(bsn + " could not be found in any repository");
}
}
}
bndProject.close();
} catch (Exception e) {
e.printStackTrace();
throw new BuildException(e);
}
}
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());
}
Aggregations