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);
}
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();
}
}
}
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());
}
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;
}
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;
}
Aggregations