Search in sources :

Example 11 with SpecfileSource

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

the class Specfile method organizePatches.

public void organizePatches() {
    List<SpecfileSource> patches = getPatches();
    int newPatchNumber = 0;
    int oldPatchNumber = -1;
    Map<Integer, SpecfileSource> newPatches = new HashMap<>();
    for (SpecfileSource thisPatch : patches) {
        if (thisPatch.getSpecfile() == null) {
            thisPatch.setSpecfile(this);
        }
        oldPatchNumber = thisPatch.getNumber();
        thisPatch.setNumber(newPatchNumber);
        thisPatch.changeDeclaration(oldPatchNumber);
        thisPatch.changeReferences(oldPatchNumber);
        newPatches.put(Integer.valueOf(newPatchNumber), thisPatch);
        newPatchNumber++;
    }
    setPatches(newPatches);
}
Also used : SpecfileSource(org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileSource) HashMap(java.util.HashMap)

Example 12 with SpecfileSource

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

the class SourceComparatorTest method testPatchComparator.

@Test
public void testPatchComparator() {
    String specText = "Patch3: somefilesomewhere.patch" + "\n" + "Patch2: someotherfile.patch";
    newFile(specText);
    Collection<SpecfileSource> patches = specfile.getPatches();
    int i = 1;
    for (SpecfileSource patch : patches) {
        i++;
        if (i == 2) {
            assertEquals(2, patch.getNumber());
        } else if (i == 3) {
            assertEquals(3, patch.getNumber());
        } else {
            fail();
        }
    }
}
Also used : SpecfileSource(org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileSource) Test(org.junit.Test)

Example 13 with SpecfileSource

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

the class SpecfileTest method testOrganizePatches.

@Test
public void testOrganizePatches() throws BadLocationException {
    String specText = "Patch3: somefilesomewhere.patch" + "\n" + "%patch3";
    newFile(specText);
    assertEquals("Patch3: somefilesomewhere.patch", specfile.getLine(0));
    assertEquals("%patch3", specfile.getLine(1));
    assertEquals(0, specfile.getPatch(3).getLineNumber());
    SpecfileSource patch = specfile.getPatch(3);
    List<Integer> linesUsed = patch.getLinesUsed();
    assertEquals(1, linesUsed.size());
    Integer lineUsedNumber = linesUsed.get(0);
    assertEquals(1, lineUsedNumber.intValue());
    specfile.organizePatches();
    assertEquals("Patch0: somefilesomewhere.patch", specfile.getLine(0));
    assertEquals("%patch0", specfile.getLine(1));
    assertEquals(0, specfile.getPatch(0).getLineNumber());
    patch = specfile.getPatch(3);
    assertNull(patch);
    patch = specfile.getPatch(0);
    assertEquals(0, patch.getNumber());
    linesUsed = patch.getLinesUsed();
    assertEquals(1, linesUsed.size());
    lineUsedNumber = linesUsed.get(0);
    assertEquals(1, lineUsedNumber.intValue());
}
Also used : SpecfileSource(org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileSource) Test(org.junit.Test)

Example 14 with SpecfileSource

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

the class RPMUtils method getSourceOrPatchValue.

public static String getSourceOrPatchValue(Specfile spec, String patchOrSourceName) {
    String value = null;
    // $NON-NLS-1$
    Pattern p = Pattern.compile("(source|patch)(\\d*)");
    Matcher m = p.matcher(patchOrSourceName);
    if (m.matches()) {
        String digits = m.group(2);
        SpecfileSource source = null;
        int number = -1;
        if (digits != null && digits.isEmpty()) {
            number = 0;
        } else if (digits != null && !digits.isEmpty()) {
            number = Integer.parseInt(digits);
        }
        if (number != -1) {
            if (m.group(1).equals("source")) {
                // $NON-NLS-1$
                source = spec.getSource(number);
            } else if (m.group(1).equals("patch")) {
                // $NON-NLS-1$
                source = spec.getPatch(number);
            }
            if (source != null) {
                value = source.getFileName();
            }
        }
    }
    return value;
}
Also used : Pattern(java.util.regex.Pattern) SpecfileSource(org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileSource) Matcher(java.util.regex.Matcher)

Example 15 with SpecfileSource

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

the class SpecfileCompletionProcessor method getSources.

/**
 * Get sources as a String key->value pair for a given specfile and prefix.
 *
 * @param specfile
 *            to get defines from.
 * @param prefix
 *            used to find defines.
 * @return a <code>HashMap</code> of defines.
 */
private Map<String, String> getSources(Specfile specfile, String prefix) {
    Collection<SpecfileSource> sources = specfile.getSources();
    Map<String, String> ret = new HashMap<>();
    String sourceName;
    for (SpecfileSource source : sources) {
        sourceName = ISpecfileSpecialSymbols.MACRO_START_LONG + SOURCE + source.getNumber() + ISpecfileSpecialSymbols.MACRO_END_LONG;
        if (sourceName.startsWith(prefix)) {
            ret.put(sourceName, RPMUtils.getSourceOrPatchValue(specfile, SOURCE + source.getNumber()));
        }
    }
    return ret;
}
Also used : SpecfileSource(org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileSource) HashMap(java.util.HashMap)

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