Search in sources :

Example 1 with SpecfileSource

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

the class LinePositionTest method testLineNumber.

@Test
public void testLineNumber() {
    String specText = "Patch3: somefilesomewhere.patch" + "\n" + "Patch2: someotherfile.patch";
    newFile(specText);
    Collection<SpecfileSource> patches = specfile.getPatches();
    for (SpecfileSource patch : patches) {
        if (patch.getNumber() == 2)
            assertEquals(1, patch.getLineNumber());
        else if (patch.getNumber() == 3)
            assertEquals(0, patch.getLineNumber());
        else
            fail("Found patch with number different from the expected numbers (2 or 3).");
    }
}
Also used : SpecfileSource(org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileSource) Test(org.junit.Test)

Example 2 with SpecfileSource

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

the class LinePositionTest method testLineNumber2.

@Test
public void testLineNumber2() {
    String specText = "Patch3: somefilesomewhere.patch" + "\n" + "%patch3";
    newFile(specText);
    Collection<SpecfileSource> patches = specfile.getPatches();
    for (SpecfileSource patch : patches) {
        if (patch.getNumber() == 3) {
            assertEquals(0, patch.getLineNumber());
            assertEquals(1, patch.getLinesUsed().get(0).intValue());
        } else
            fail("Found patch with number different from the expected 3.");
    }
}
Also used : SpecfileSource(org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileSource) Test(org.junit.Test)

Example 3 with SpecfileSource

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

the class PatchApplicationTest method testMultiplePatchLineNumbers.

@Test
public void testMultiplePatchLineNumbers() {
    String specText = "Patch3: somefilesomewhere.patch" + "\n" + "%patch3" + "\n" + "blah" + "\n" + "%patch3";
    newFile(specText);
    SpecfileSource thisPatch = specfile.getPatch(3);
    List<Integer> usedList = new ArrayList<>(2);
    usedList.add(Integer.valueOf(1));
    usedList.add(Integer.valueOf(3));
    assertEquals(thisPatch.getLinesUsed(), usedList);
}
Also used : SpecfileSource(org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileSource) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with SpecfileSource

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

the class PatchApplicationTest method testPatchLineNumber.

@Test
public void testPatchLineNumber() {
    String specText = "Patch3: somefilesomewhere.patch" + "\n" + "%patch3";
    newFile(specText);
    SpecfileSource thisPatch = specfile.getPatch(3);
    List<Integer> usedList = new ArrayList<>(1);
    usedList.add(Integer.valueOf(1));
    assertEquals(thisPatch.getLinesUsed(), usedList);
}
Also used : SpecfileSource(org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileSource) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with SpecfileSource

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

the class SpecfileElementHyperlinkDetector method detectHyperlinks.

@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
    if (region == null || textViewer == null) {
        return null;
    }
    IDocument document = textViewer.getDocument();
    if (document == null) {
        return null;
    }
    // until a SpecfileEditor#editorSaved is called
    if (specfile == null) {
        SpecfileEditor a = this.getAdapter(SpecfileEditor.class);
        if (a != null && a.getSpecfile() != null) {
            specfile = a.getSpecfile();
        } else {
            SpecfileParser parser = new SpecfileParser();
            specfile = parser.parse(document);
        }
    }
    int offset = region.getOffset();
    IRegion lineInfo;
    String line;
    try {
        lineInfo = document.getLineInformationOfOffset(offset);
        line = document.get(lineInfo.getOffset(), lineInfo.getLength());
    } catch (BadLocationException ex) {
        return null;
    }
    int offsetInLine = offset - lineInfo.getOffset();
    StringTokenizer tokens = new StringTokenizer(line);
    // $NON-NLS-1$
    String word = "";
    int tempLineOffset = 0;
    int wordOffsetInLine = 0;
    while (tokens.hasMoreTokens()) {
        String tempWord = tokens.nextToken();
        // $NON-NLS-1$
        Pattern defineRegexp = Pattern.compile("%\\{(.*?)\\}");
        Matcher fit = defineRegexp.matcher(tempWord);
        while (fit.find()) {
            if ((fit.start() + tempLineOffset <= offsetInLine) && (offsetInLine <= fit.end() + tempLineOffset)) {
                tempWord = fit.group();
                wordOffsetInLine = fit.start();
                tempLineOffset += fit.start();
                break;
            }
        }
        tempLineOffset += tempWord.length();
        word = tempWord;
        if (tempLineOffset > offsetInLine) {
            break;
        }
    }
    if (word.startsWith(SOURCE_IDENTIFIER)) {
        int sourceNumber = Integer.valueOf(word.substring(SOURCE_IDENTIFIER.length(), word.length() - 1)).intValue();
        SpecfileSource source = specfile.getSource(sourceNumber);
        if (source != null) {
            return prepareHyperlink(lineInfo, line, word, source);
        }
    } else if (word.startsWith(PATCH_IDENTIFIER)) {
        int sourceNumber = Integer.valueOf(word.substring(PATCH_IDENTIFIER.length(), word.length())).intValue();
        SpecfileSource source = specfile.getPatch(sourceNumber);
        if (source != null) {
            return prepareHyperlink(lineInfo, line, word, source);
        }
    } else {
        String defineName = getDefineName(word);
        SpecfileDefine define = specfile.getDefine(defineName);
        if (define != null) {
            return prepareHyperlink(lineInfo, line, defineName, define, wordOffsetInLine);
        }
    }
    return null;
}
Also used : Pattern(java.util.regex.Pattern) StringTokenizer(com.ibm.icu.util.StringTokenizer) SpecfileSource(org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileSource) Matcher(java.util.regex.Matcher) SpecfileDefine(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileDefine) SpecfileEditor(org.eclipse.linuxtools.internal.rpm.ui.editor.SpecfileEditor) SpecfileParser(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser) IDocument(org.eclipse.jface.text.IDocument) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

SpecfileSource (org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileSource)18 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 HttpURLConnection (java.net.HttpURLConnection)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 URLConnection (java.net.URLConnection)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 IFile (org.eclipse.core.resources.IFile)2 Path (org.eclipse.core.runtime.Path)2 Job (org.eclipse.core.runtime.jobs.Job)2 IRegion (org.eclipse.jface.text.IRegion)2 SourceComparator (org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SourceComparator)2 DownloadJob (org.eclipse.linuxtools.rpm.core.utils.DownloadJob)2 SpecfileDefine (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileDefine)2 SpecfileParser (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser)2 StringTokenizer (com.ibm.icu.util.StringTokenizer)1