Search in sources :

Example 1 with Specfile

use of org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile in project linuxtools by eclipse.

the class RpmMacroOccurrencesUpdater method update.

/**
 * Updates the drawn annotations.
 *
 * @param viewer
 *            The viewer to get the document and annotation model from
 */
public void update(ISourceViewer viewer) {
    try {
        IDocument document = viewer.getDocument();
        IAnnotationModel model = viewer.getAnnotationModel();
        if (document == null || model == null) {
            return;
        }
        removeOldAnnotations(model);
        String currentSelectedWord = getWordAtSelection(fEditor.getSelectionProvider().getSelection(), document);
        if (isMacro(currentSelectedWord)) {
            Specfile spec = fEditor.getSpecfile();
            SpecfileDefine define = spec.getDefine(currentSelectedWord);
            // $NON-NLS-1$
            String word = currentSelectedWord + ": ";
            if (define != null) {
                word += define.getStringValue();
            } else {
                // If there's no such define we try to see if it corresponds
                // to
                // a Source or Patch declaration
                String retrivedValue = RPMUtils.getSourceOrPatchValue(spec, currentSelectedWord.toLowerCase());
                if (retrivedValue != null) {
                    word += retrivedValue;
                } else {
                    // If it does not correspond to a Patch or Source macro,
                    // try to find it
                    // in the macro proposals list.
                    retrivedValue = RPMUtils.getMacroValueFromMacroList(currentSelectedWord);
                    if (retrivedValue != null) {
                        word += retrivedValue;
                    }
                }
            }
            createNewAnnotations(currentSelectedWord, word, document, model);
        }
    } catch (BadLocationException e) {
        SpecfileLog.logError(e);
    }
}
Also used : Specfile(org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile) SpecfileDefine(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileDefine) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 2 with Specfile

use of org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile in project linuxtools by eclipse.

the class SpecfileCompletionProcessor method computeCompletionProposals.

@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
    List<ICompletionProposal> result = new ArrayList<>();
    Specfile specfile = new SpecfileParser().parse(viewer.getDocument());
    String prefix = completionWord(viewer.getDocument(), offset);
    Region region = new Region(offset - prefix.length(), prefix.length());
    // RPM macro's are useful in the whole specfile.
    List<ICompletionProposal> rpmMacroProposals = computeRpmMacroProposals(region, specfile, prefix);
    // Sources completion
    List<ICompletionProposal> sourcesProposals = computeSourcesProposals(region, specfile, prefix);
    result.addAll(sourcesProposals);
    // Get the current content type
    String currentContentType = viewer.getDocument().getDocumentPartitioner().getContentType(region.getOffset());
    if (currentContentType.equals(SpecfilePartitionScanner.SPEC_PREP)) {
        List<ICompletionProposal> patchesProposals = computePatchesProposals(region, specfile, prefix);
        result.addAll(patchesProposals);
    }
    if (currentContentType.equals(SpecfilePartitionScanner.SPEC_PACKAGES)) {
        // don't show template in the RPM packages content type.
        // (when the line begin with Requires, BuildRequires etc...)
        List<ICompletionProposal> rpmPackageProposals = computeRpmPackageProposals(region, prefix);
        result.addAll(rpmPackageProposals);
        result.addAll(rpmMacroProposals);
    } else {
        // don't show RPM packages proposals in all others content type.
        List<? extends ICompletionProposal> templateProposals = computeTemplateProposals(viewer, region, specfile, prefix);
        result.addAll(templateProposals);
        result.addAll(rpmMacroProposals);
    }
    if (currentContentType.equals(SpecfilePartitionScanner.SPEC_GROUP)) {
        IDocument document = viewer.getDocument();
        try {
            int lineNumber = document.getLineOfOffset(region.getOffset());
            int lineOffset = document.getLineOffset(lineNumber);
            if (region.getOffset() - lineOffset > 5) {
                result.clear();
                String groupPrefix = getGroupPrefix(viewer, offset);
                result.addAll(computeRpmGroupProposals(region, groupPrefix));
            }
        } catch (BadLocationException e) {
            SpecfileLog.logError(e);
        }
    }
    return result.toArray(new ICompletionProposal[result.size()]);
}
Also used : Specfile(org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) SpecfileParser(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 3 with Specfile

use of org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile in project linuxtools by eclipse.

the class SpecfileHover method getHoverInfo.

@Override
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
    if (hoverRegion == null || hoverRegion.getLength() == 0) {
        return null;
    }
    Specfile spec = new SpecfileParser().parse(textViewer.getDocument());
    String currentSelection;
    try {
        currentSelection = textViewer.getDocument().get(hoverRegion.getOffset() + 1, hoverRegion.getLength() - 1);
    } catch (BadLocationException e) {
        return null;
    }
    // First we try to get a define based on the given name
    SpecfileDefine define = spec.getDefine(currentSelection);
    // $NON-NLS-1$
    String value = currentSelection + ": ";
    if (define != null) {
        return value + define.getStringValue();
    }
    String macroLower = currentSelection.toLowerCase();
    // If there's no such define we try to see if it corresponds to
    // a Source or Patch declaration
    String retrivedValue = RPMUtils.getSourceOrPatchValue(spec, macroLower);
    if (retrivedValue != null) {
        return value + retrivedValue;
    } else {
        // If it does not correspond to a Patch or Source macro, try to find
        // it
        // in the macro proposals list.
        retrivedValue = RPMUtils.getMacroValueFromMacroList(currentSelection);
        if (retrivedValue != null) {
            return value + retrivedValue;
        } else {
            // If it does not correspond to a macro in the list, try to find
            // it
            // in the RPM list.
            retrivedValue = Activator.getDefault().getRpmPackageList().getValue(// $NON-NLS-1$ //$NON-NLS-2$
            currentSelection.replaceFirst(":", ""));
            if (retrivedValue != null) {
                return retrivedValue;
            }
        }
    }
    // for unrecognized macros and RPM packages.
    return null;
}
Also used : Specfile(org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile) SpecfileDefine(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileDefine) SpecfileParser(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 4 with Specfile

use of org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile in project linuxtools by eclipse.

the class SpecfileReconcilingStrategy method reconcile.

private void reconcile() {
    Specfile specfile = editor.getSpecfile();
    if (specfile != null) {
        editor.setSpecfile(editor.getParser().parse(documentProvider.getDocument(editor.getEditorInput())));
        outline.update();
        updateFolding();
        updateEditor();
    }
}
Also used : Specfile(org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile)

Example 5 with Specfile

use of org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile in project linuxtools by eclipse.

the class SpecfileChangelogFormatter method formatDateLine.

@Override
public String formatDateLine(String authorName, String authorEmail) {
    String dateLine;
    Specfile specfile = getParsedSpecfile();
    // $NON-NLS-1$
    String epoch = specfile.getEpoch() == -1 ? EMPTY_STRING : (specfile.getEpoch() + ":");
    String version = specfile.getVersion();
    String release = specfile.getRelease();
    // remove the dist macro if it exist in the release string.
    // $NON-NLS-1$
    release = release.replaceAll("\\%\\{\\?dist\\}", EMPTY_STRING);
    // default format
    dateLine = // $NON-NLS-1$
    MessageFormat.format(// $NON-NLS-1$
    "* {0} {1} <{2}> {3}{4}-{5}", // $NON-NLS-1$
    formatTodaysDate(), // $NON-NLS-1$
    authorName, authorEmail, epoch, version, release);
    String format = store.getString(PreferenceConstants.P_CHANGELOG_ENTRY_FORMAT);
    if (format.equals(PreferenceConstants.P_CHANGELOG_ENTRY_FORMAT_VERSIONED_WITH_SEPARATOR)) {
        dateLine = // $NON-NLS-1$
        MessageFormat.format(// $NON-NLS-1$
        "* {0} {1} <{2}> - {3}{4}-{5}", // $NON-NLS-1$
        formatTodaysDate(), authorName, authorEmail, epoch, version, release);
    } else if (format.equals(PreferenceConstants.P_CHANGELOG_ENTRY_FORMAT_UNVERSIONED)) {
        // $NON-NLS-1$
        dateLine = MessageFormat.format("* {0} {1} <{2}>", formatTodaysDate(), authorName, authorEmail);
    }
    dateLine = UiUtils.resolveDefines(specfile, dateLine);
    return dateLine;
}
Also used : Specfile(org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile)

Aggregations

Specfile (org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile)13 BadLocationException (org.eclipse.jface.text.BadLocationException)6 SpecfileParser (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser)6 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 IFile (org.eclipse.core.resources.IFile)2 IResource (org.eclipse.core.resources.IResource)2 CoreException (org.eclipse.core.runtime.CoreException)2 Job (org.eclipse.core.runtime.jobs.Job)2 IDocument (org.eclipse.jface.text.IDocument)2 RPMProject (org.eclipse.linuxtools.rpm.core.RPMProject)2 DownloadJob (org.eclipse.linuxtools.rpm.core.utils.DownloadJob)2 SpecfileDefine (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileDefine)2 SpecfilePackage (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackage)2 SpecfileSection (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileSection)2 Shell (org.eclipse.swt.widgets.Shell)2 IOException (java.io.IOException)1 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1