Search in sources :

Example 6 with VersionedClause

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);
}
Also used : VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) Attrs(aQute.bnd.header.Attrs)

Example 7 with VersionedClause

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());
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) Attrs(aQute.bnd.header.Attrs) Resource(org.osgi.resource.Resource)

Example 8 with VersionedClause

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteCommandAction.writeCommandAction(com.intellij.openapi.command.WriteCommandAction.writeCommandAction) Constants(aQute.bnd.osgi.Constants) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Task(com.intellij.openapi.progress.Task) Workspace(aQute.bnd.build.Workspace) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) Map(java.util.Map) Project(com.intellij.openapi.project.Project) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) Logger(com.intellij.openapi.diagnostic.Logger) OsmorcBundle.message(org.osmorc.i18n.OsmorcBundle.message) BndEditModel(aQute.bnd.build.model.BndEditModel) OsmorcBundle(org.osmorc.i18n.OsmorcBundle) ProjectResolver(biz.aQute.resolve.ProjectResolver) FileModificationService(com.intellij.codeInsight.FileModificationService) Resource(org.osgi.resource.Resource) AnAction(com.intellij.openapi.actionSystem.AnAction) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Run(aQute.bnd.build.Run) Collectors(java.util.stream.Collectors) File(java.io.File) NotificationType(com.intellij.notification.NotificationType) BndFileType(org.jetbrains.osgi.bnd.BndFileType) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) IDocument(aQute.bnd.properties.IDocument) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) Attrs(aQute.bnd.header.Attrs) Wire(org.osgi.resource.Wire) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ResolutionException(org.osgi.service.resolver.ResolutionException) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) Collections(java.util.Collections) javax.swing(javax.swing) Task(com.intellij.openapi.progress.Task) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) ProjectResolver(biz.aQute.resolve.ProjectResolver) Attrs(aQute.bnd.header.Attrs) Document(com.intellij.openapi.editor.Document) IDocument(aQute.bnd.properties.IDocument) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) BndEditModel(aQute.bnd.build.model.BndEditModel) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Resource(org.osgi.resource.Resource) Run(aQute.bnd.build.Run) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ResolutionException(org.osgi.service.resolver.ResolutionException) ResolutionException(org.osgi.service.resolver.ResolutionException) Project(com.intellij.openapi.project.Project) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) IDocument(aQute.bnd.properties.IDocument) Workspace(aQute.bnd.build.Workspace)

Example 9 with VersionedClause

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);
    }
}
Also used : VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) VersionRange(aQute.bnd.version.VersionRange) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) Project(aQute.bnd.build.Project) Version(aQute.bnd.version.Version) Jar(aQute.bnd.osgi.Jar) BuildException(org.apache.tools.ant.BuildException) BndEditModel(aQute.bnd.build.model.BndEditModel) File(java.io.File) Workspace(aQute.bnd.build.Workspace)

Example 10 with VersionedClause

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());
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) Resource(org.osgi.resource.Resource)

Aggregations

VersionedClause (aQute.bnd.build.model.clauses.VersionedClause)15 Attrs (aQute.bnd.header.Attrs)8 File (java.io.File)6 BndEditModel (aQute.bnd.build.model.BndEditModel)5 ArrayList (java.util.ArrayList)5 Resource (org.osgi.resource.Resource)5 Document (aQute.bnd.properties.Document)3 WizardDialog (org.eclipse.jface.wizard.WizardDialog)3 Project (aQute.bnd.build.Project)2 Workspace (aQute.bnd.build.Workspace)2 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)2 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)2 Version (aQute.bnd.version.Version)2 VersionRange (aQute.bnd.version.VersionRange)2 AndFilter (aQute.libg.filters.AndFilter)2 Filter (aQute.libg.filters.Filter)2 LiteralFilter (aQute.libg.filters.LiteralFilter)2 SimpleFilter (aQute.libg.filters.SimpleFilter)2 ProjectBundle (bndtools.model.repo.ProjectBundle)2 RepositoryBundle (bndtools.model.repo.RepositoryBundle)2