Package aQute.bnd.build.model

Examples of aQute.bnd.build.model.BndEditModel


    }

    Project getProject() {
        Project project = null;
        try {
            BndEditModel model = (BndEditModel) getManagedForm().getInput();
            File bndFile = model.getBndResource();
            IPath path = Central.toPath(bndFile);
            IFile resource = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
            File projectDir = resource.getProject().getLocation().toFile();
            project = Central.getProject(projectDir);
        } catch (Exception e) {
View Full Code Here


     * @param monitor
     */
    @Override
    protected BndEditModel generateBndModel(IProgressMonitor monitor) {
        ProjectPaths bndPaths = ProjectPaths.get(ProjectLayout.BND);
        BndEditModel model = super.generateBndModel(monitor);

        ProjectPaths projectPaths = ProjectPaths.get(pageOne.getProjectLayout());

        IProjectTemplate template = templatePage.getTemplate();
        if (template != null) {
            String name = pageTwo.getJavaProject().getProject().getName();
            model.setBundleVersion(DEFAULT_BUNDLE_VERSION);
            template.modifyInitialBndModel(model, name, projectPaths);
        }
        try {
            Map<String,String> sourceOutputLocations = JavaProjectUtils.getSourceOutputLocations(pageTwo.getJavaProject());
            if (sourceOutputLocations != null) {
                int nr = 1;
                for (Map.Entry<String,String> entry : sourceOutputLocations.entrySet()) {
                    String src = entry.getKey();
                    String bin = entry.getValue();

                    if (nr == 1) {
                        if (!bndPaths.getSrc().equals(src)) {
                            model.genericSet(Constants.DEFAULT_PROP_SRC_DIR, src);
                        }
                        if (!bndPaths.getBin().equals(bin)) {
                            model.genericSet(Constants.DEFAULT_PROP_BIN_DIR, bin);
                        }
                        nr = 2;
                    } else if (nr == 2) {
                        if (!bndPaths.getTestSrc().equals(src)) {
                            model.genericSet(Constants.DEFAULT_PROP_TESTSRC_DIR, src);
                        }
                        if (!bndPaths.getTestBin().equals(bin)) {
                            model.genericSet(Constants.DEFAULT_PROP_TESTBIN_DIR, bin);
                        }
                        nr = 2;
                    } else {
                        // if for some crazy reason we end up with more than 2 paths, we log them in
                        // extension properties (we cannot write comments) but this should never happen
                        // anyway since the second page will not complete if there are not exactly 2 paths
                        // so this could only happen if someone adds another page (that changes them again)
                        model.genericSet("X-WARN-" + nr, "Ignoring source path " + src + " -> " + bin);
                        nr++;
                    }
                }
            }

            String projectTargetDir = projectPaths.getTargetDir();
            if (!bndPaths.getTargetDir().equals(projectTargetDir)) {
                model.genericSet(Constants.DEFAULT_PROP_TARGET_DIR, projectTargetDir);
            }
        } catch (Exception e) {
            ErrorDialog.openError(getShell(), "Error", "", new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Error setting paths in Bnd project descriptor file ({0}).", Project.BNDFILE), e));
        }

View Full Code Here

     */
    @SuppressWarnings({
            "static-method", "unused"
    })
    protected BndEditModel generateBndModel(IProgressMonitor monitor) {
        return new BndEditModel();
    }
View Full Code Here

                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            SubMonitor progress = SubMonitor.convert(monitor, 3);

                            // Generate the Bnd model
                            final BndEditModel bndModel = generateBndModel(progress.newChild(1));

                            // Make changes to the project
                            final IWorkspaceRunnable op = new IWorkspaceRunnable() {
                                public void run(IProgressMonitor monitor) throws CoreException {
                                    processGeneratedProject(ProjectPaths.get(pageOne.getProjectLayout()), bndModel, javaProj, monitor);
View Full Code Here

        if (container == null || !container.exists())
            throw newCoreException("Container path does not exist", null);

        // Create new project model
        BndEditModel newBundleModel = new BndEditModel();

        // Load project file and model
        IFile projectFile = container.getProject().getFile(Project.BNDFILE);
        BndEditModel projectModel;
        final Document projectDocument;
        try {
            if (projectFile.exists()) {
                byte[] bytes = FileUtils.readFully(projectFile.getContents());
                projectDocument = new Document(new String(bytes, projectFile.getCharset()));
            } else {
                projectDocument = new Document("");
            }
            projectModel = new BndEditModel();
            projectModel.loadFrom(projectDocument);
        } catch (IOException e) {
            throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, e.getMessage(), e));
        }

        // Check if we need to enable sub-bundles on the project file
        boolean enableSubs;
        List<String> subBndFiles = projectModel.getSubBndFiles();
        List<String> availableHeaders = calculateProjectOnlyHeaders(projectModel.getAllPropertyNames());
        Collection<String> bundleSpecificHeaders = calculateBundleSpecificHeaders(availableHeaders);

        if (subBndFiles == null || subBndFiles.isEmpty()) {
            final EnableSubBundlesDialog subBundlesDialog = new EnableSubBundlesDialog(parentShell, availableHeaders, bundleSpecificHeaders);

            if (subBundlesDialog.open() != Window.OK) {
                monitor.setCanceled(true);
                return;
            }

            enableSubs = subBundlesDialog.isEnableSubBundles();
            bundleSpecificHeaders = subBundlesDialog.getSelectedProperties();
        } else {
            enableSubs = false;
        }

        // Enable subs and copy entries from project model to new bundle model
        if (enableSubs) {
            projectModel.setSubBndFiles(Arrays.asList(new String[] {
                "*.bnd"
            }));
            for (String propertyName : bundleSpecificHeaders) {
                Object value = projectModel.genericGet(propertyName);
                projectModel.genericSet(propertyName, null);
                newBundleModel.genericSet(propertyName, value);
            }

            // Save the project model
            projectModel.saveChangesTo(projectDocument);
            FileUtils.writeFully(projectDocument.get(), projectFile, false);
        }

        // Generate the new bundle model
        Document newBundleDocument = new Document("");
View Full Code Here

    }

    Project getProject() {
        Project project = null;
        try {
            BndEditModel model = (BndEditModel) getManagedForm().getInput();
            File bndFile = model.getBndResource();
            IPath path = Central.toPath(bndFile);
            IFile resource = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
            File projectDir = resource.getProject().getLocation().toFile();
            if (Project.BNDFILE.equals(resource.getName())) {
                project = Central.getProject(projectDir);
View Full Code Here

    }

    Project getProject() {
        Project project = null;
        try {
            BndEditModel model = (BndEditModel) getManagedForm().getInput();
            File bndFile = model.getBndResource();
            IPath path = Central.toPath(bndFile);
            IFile resource = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
            File projectDir = resource.getProject().getLocation().toFile();
            project = Central.getProject(projectDir);
        } catch (Exception e) {
View Full Code Here

    }

    Project getProject() {
        Project project = null;
        try {
            BndEditModel model = (BndEditModel) getManagedForm().getInput();
            File bndFile = model.getBndResource();
            IPath path = Central.toPath(bndFile);
            IFile resource = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
            File projectDir = resource.getProject().getLocation().toFile();
            if (Project.BNDFILE.equals(resource.getName())) {
                project = Central.getProject(projectDir);
View Full Code Here

        return true;
    }

    private void updateBundleBlueprintAndIncludeResource(IFile blueprintFile, IFile bndFile) throws Exception {

        BndEditModel editModel;
        IEditorPart editor = ResourceUtil.findEditor(workbench.getActiveWorkbenchWindow().getActivePage(), bndFile);
        IDocument doc = null;
        if (editor instanceof BndEditor) {
            editModel = ((BndEditor) editor).getEditModel();
        } else {
            editModel = new BndEditModel();
            doc = FileUtils.readFully(bndFile);
            editModel.loadFrom(new IDocumentWrapper(doc));
        }

        String blueprintrelativePath = blueprintFile.getProjectRelativePath().toString();

        updateBundleBlueprintIfNecessary(editModel, blueprintrelativePath);

        updateIncludeResourceIfNecessary(editModel, blueprintrelativePath, blueprintFile);

        if (editor == null) {
            editModel.saveChangesTo(new IDocumentWrapper(doc));
            FileUtils.writeFully(doc, bndFile, false);
        }
    }
View Full Code Here

        super.addPages();
    }

    @Override
    protected BndEditModel generateBndModel(IProgressMonitor monitor) {
        BndEditModel model = super.generateBndModel(null);

        List<ExportedPackage> exports = new ArrayList<ExportedPackage>();
        List<VersionedClause> buildPath = new ArrayList<VersionedClause>();

        // Add JARs to project build path
        IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
        Collection<IPath> paths = classPathPage.getPaths();
        if (paths != null && !paths.isEmpty()) {
            int workRemaining = paths.size();
            SubMonitor progress = SubMonitor.convert(monitor, workRemaining);

            for (IPath path : paths) {
                File file = FileUtils.toFile(wsroot, path);
                if (file != null && file.isFile() && file.getName().toLowerCase().endsWith(".jar")) {
                    VersionedClause buildPathEntry = new VersionedClause("lib/" + file.getName(), new Attrs());
                    buildPathEntry.setVersionRange("file");
                    buildPath.add(buildPathEntry);
                }
                progress.setWorkRemaining(--workRemaining);
            }
        }

        // Add package exports
        List<IPath> selectedPackages = packageListPage.getSelectedPackages();
        for (IPath pkg : selectedPackages) {
            Attrs props = new Attrs();
            props.put(Constants.VERSION_ATTRIBUTE, BndEditModel.BUNDLE_VERSION_MACRO);
            ExportedPackage export = new ExportedPackage(pkg.toString().replace('/', '.'), props);

            exports.add(export);
        }

        model.setBuildPath(buildPath);
        model.setExportedPackages(exports);

        return model;
    }
View Full Code Here

TOP

Related Classes of aQute.bnd.build.model.BndEditModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.