Search in sources :

Example 1 with ImportPattern

use of aQute.bnd.build.model.clauses.ImportPattern in project liferay-ide by liferay.

the class PortletTemplate method modifyInitialBndModel.

@Override
public void modifyInitialBndModel(BndEditModel model, String projectName, ProjectPaths projectPaths) {
    super.modifyInitialBndModel(model, projectName, projectPaths);
    String buildpath = "${buildpath-rule}";
    model.setBuildPath(Collections.singletonList(new VersionedClause(buildpath, Attrs.EMPTY_ATTRS)));
    model.setIncludeResource(Collections.singletonList("${includeresource-rule}"));
    ImportPattern[] patterns = { new ImportPattern("${imports-rule}", Attrs.EMPTY_ATTRS), new ImportPattern("*", new Attrs()) };
    patterns[1].setOptional(true);
    model.setImportPatterns(Arrays.asList(patterns));
    model.setGenericString("Web-ContextPath", "/" + projectName);
    String safePackageName = safePackageName(projectName);
    String wholePackageName = "(osgi.identity=" + safePackageName + ")";
    CapReqBuilder cap = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE);
    cap.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, wholePackageName);
    model.setRunRequires(Collections.singletonList(cap.buildSyntheticRequirement()));
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) ImportPattern(aQute.bnd.build.model.clauses.ImportPattern) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) Attrs(aQute.bnd.header.Attrs)

Example 2 with ImportPattern

use of aQute.bnd.build.model.clauses.ImportPattern in project bndtools by bndtools.

the class ImportPatternsListPart method doAddClauses.

@Override
protected void doAddClauses(Collection<? extends ImportPattern> clauses, int index, boolean select) {
    boolean appendStar = getClauses().isEmpty();
    super.doAddClauses(clauses, index, select);
    if (appendStar) {
        // $NON-NLS-1$
        ImportPattern starPattern = new ImportPattern("*", new Attrs());
        super.doAddClauses(Arrays.asList(starPattern), -1, false);
    }
}
Also used : ImportPattern(aQute.bnd.build.model.clauses.ImportPattern) Attrs(aQute.bnd.header.Attrs)

Example 3 with ImportPattern

use of aQute.bnd.build.model.clauses.ImportPattern in project bndtools by bndtools.

the class ImportPatternsListPart method propertyChange.

@Override
public void propertyChange(PropertyChangeEvent evt) {
    if (PROP_SELECTION.equals(evt.getPropertyName())) {
        final List<ImportPattern> selectedClauses = getSelection();
        modifyLock.modifyOperation(new Runnable() {

            @Override
            public void run() {
                if (selectedClauses.isEmpty()) {
                    SWTUtil.recurseEnable(false, pnlDetails);
                    txtPattern.setText("");
                    txtVersion.setText("");
                    btnOptional.setSelection(false);
                } else if (selectedClauses.size() == 1) {
                    SWTUtil.recurseEnable(true, pnlDetails);
                    ImportPattern pattern = selectedClauses.get(0);
                    txtPattern.setText(pattern.getName() != null ? pattern.getName() : "");
                    txtVersion.setText(pattern.getVersionRange() != null ? pattern.getVersionRange() : "");
                    btnOptional.setSelection(pattern.isOptional());
                } else {
                    SWTUtil.recurseEnable(false, pnlDetails);
                    btnOptional.setEnabled(true);
                    pnlDetails.setEnabled(true);
                    boolean differs = false;
                    boolean first = selectedClauses.get(0).isOptional();
                    for (ImportPattern pattern : selectedClauses) {
                        if (first != pattern.isOptional()) {
                            differs = true;
                            break;
                        }
                    }
                    if (differs) {
                        btnOptional.setGrayed(true);
                    } else {
                        btnOptional.setGrayed(false);
                        btnOptional.setSelection(first);
                    }
                }
            }
        });
    } else {
        super.propertyChange(evt);
    }
}
Also used : ImportPattern(aQute.bnd.build.model.clauses.ImportPattern)

Example 4 with ImportPattern

use of aQute.bnd.build.model.clauses.ImportPattern in project bndtools by bndtools.

the class ImportPatternsListPart method validate.

@Override
public void validate() {
    IMessageManager msgs = getManagedForm().getMessageManager();
    msgs.setDecorationPosition(SWT.TOP | SWT.RIGHT);
    String noStarWarning = null;
    String actionMessage = null;
    List<ImportPattern> patterns = getClauses();
    if (!patterns.isEmpty()) {
        for (Iterator<ImportPattern> iter = patterns.iterator(); iter.hasNext(); ) {
            ImportPattern pattern = iter.next();
            if (pattern.getName().equals("*") && iter.hasNext()) {
                noStarWarning = "The catch-all pattern \"*\" should be in the last position.";
                actionMessage = "Move \"*\" pattern to the last position.";
                break;
            }
        }
        if (noStarWarning == null) {
            ImportPattern last = patterns.get(patterns.size() - 1);
            if (!last.getName().equals("*")) {
                noStarWarning = "The catch-all pattern \"*\" should be present and in the last position.";
                actionMessage = "Add missing \"*\" pattern.";
            }
        }
    }
    if (noStarWarning != null) {
        msgs.addMessage("_warning_no_star", noStarWarning, new FixMissingStarsAction(actionMessage), IMessageProvider.WARNING);
    } else {
        msgs.removeMessage("_warning_no_star");
    }
}
Also used : ImportPattern(aQute.bnd.build.model.clauses.ImportPattern) IMessageManager(org.eclipse.ui.forms.IMessageManager)

Example 5 with ImportPattern

use of aQute.bnd.build.model.clauses.ImportPattern in project bndtools by bndtools.

the class ImportPatternsListPart method createSection.

@Override
protected void createSection(Section section, FormToolkit toolkit) {
    super.createSection(section, toolkit);
    Composite parentComposite = (Composite) getSection().getClient();
    pnlDetails = toolkit.createComposite(parentComposite);
    toolkit.createLabel(pnlDetails, "Pattern:");
    txtPattern = toolkit.createText(pnlDetails, "");
    toolkit.createLabel(pnlDetails, "Version:");
    txtVersion = toolkit.createText(pnlDetails, "", SWT.BORDER);
    btnOptional = toolkit.createButton(pnlDetails, "Optional", SWT.CHECK);
    pnlDetails.setLayout(new GridLayout(5, false));
    txtPattern.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    txtVersion.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    pnlDetails.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    SWTUtil.recurseEnable(false, pnlDetails);
    txtPattern.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            if (!modifyLock.isUnderModification()) {
                List<ImportPattern> selectedClauses = getSelection();
                if (selectedClauses.size() == 1) {
                    selectedClauses.get(0).setName(txtPattern.getText());
                    updateLabels(selectedClauses);
                    validate();
                    markDirty();
                }
            }
        }
    });
    txtVersion.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            if (!modifyLock.isUnderModification()) {
                String text = txtVersion.getText();
                if (text.length() == 0)
                    text = null;
                List<ImportPattern> selectedClauses = getSelection();
                for (ImportPattern clause : selectedClauses) {
                    clause.getAttribs().put(Constants.VERSION_ATTRIBUTE, text);
                }
                updateLabels(selectedClauses);
                validate();
                markDirty();
            }
        }
    });
    btnOptional.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (!modifyLock.isUnderModification()) {
                boolean optional = btnOptional.getSelection();
                List<ImportPattern> patterns = getSelection();
                for (ImportPattern pattern : patterns) {
                    pattern.setOptional(optional);
                }
                updateLabels(patterns);
                validate();
                markDirty();
            }
        }
    });
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ImportPattern(aQute.bnd.build.model.clauses.ImportPattern) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) LinkedList(java.util.LinkedList) List(java.util.List)

Aggregations

ImportPattern (aQute.bnd.build.model.clauses.ImportPattern)7 ExportedPackage (aQute.bnd.build.model.clauses.ExportedPackage)2 Attrs (aQute.bnd.header.Attrs)2 BndEditModel (aQute.bnd.build.model.BndEditModel)1 VersionedClause (aQute.bnd.build.model.clauses.VersionedClause)1 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)1 Document (aQute.bnd.properties.Document)1 IDocument (aQute.bnd.properties.IDocument)1 BundleContentPage (bndtools.editor.pages.BundleContentPage)1 WorkspacePage (bndtools.editor.pages.WorkspacePage)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 IFile (org.eclipse.core.resources.IFile)1