1 11 package org.eclipse.pde.internal.ui.model.build; 12 13 import java.io.*; 14 import java.util.*; 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.jface.text.*; 17 import org.eclipse.pde.core.*; 18 import org.eclipse.pde.core.build.*; 19 import org.eclipse.pde.internal.ui.model.*; 20 21 public class Build implements IBuild { 22 23 private BuildModel fModel; 24 private HashMap fEntries = new HashMap(); 25 26 public Build(BuildModel model) { 27 fModel = model; 28 } 29 30 33 public void add(IBuildEntry entry) throws CoreException { 34 fEntries.put(entry.getName(), entry); 35 fModel.fireModelChanged(new ModelChangedEvent(fModel, 36 IModelChangedEvent.INSERT, new Object []{entry}, null)); 37 } 38 41 public IBuildEntry[] getBuildEntries() { 42 return (IBuildEntry[])fEntries.values().toArray(new IBuildEntry[fEntries.size()]); 43 } 44 47 public IBuildEntry getEntry(String name) { 48 return (IBuildEntry)fEntries.get(name); 49 } 50 53 public void remove(IBuildEntry entry) throws CoreException { 54 fEntries.remove(entry.getName()); 55 fModel.fireModelChanged(new ModelChangedEvent(fModel, 56 IModelChangedEvent.REMOVE, new Object []{entry}, null)); 57 } 58 64 public void write(String indent, PrintWriter writer) { 65 } 66 67 public void load(InputStream source) throws IOException { 68 fEntries.clear(); 69 Properties properties = new Properties(); 70 properties.load(source); 71 Enumeration keys = properties.keys(); 72 while (keys.hasMoreElements()) { 73 String name = keys.nextElement().toString(); 74 BuildEntry entry = (BuildEntry)fModel.getFactory().createEntry(name); 75 entry.processEntry(properties.get(name).toString()); 76 fEntries.put(name, entry); 77 } 78 adjustOffsets(fModel.getDocument()); 79 } 80 81 public void adjustOffsets(IDocument document) { 82 int lines = document.getNumberOfLines(); 83 try { 84 IDocumentKey currentKey = null; 85 for (int i = 0; i < lines; i++) { 86 int offset = document.getLineOffset(i); 87 int length = document.getLineLength(i); 88 String line = document.get(offset, length); 89 if (line.startsWith("#") | line.startsWith("!")) { if (currentKey != null) { 91 currentKey.setLength(offset - 1 - currentKey.getOffset()); 92 currentKey = null; 93 } 94 continue; 95 } 96 97 line = line.trim(); 98 if (line.length() == 0) 99 continue; 100 101 if (currentKey != null) { 102 if (!line.endsWith("\\")) { currentKey.setLength(offset + document.getLineLength(i) - currentKey.getOffset()); 104 currentKey = null; 105 } 106 } else { 107 int index = line.indexOf('='); 108 if (index == -1) 109 index = line.indexOf(':'); 110 if (index == -1) 111 index = line.indexOf(' '); 112 if (index == -1) 113 index = line.indexOf('\t'); 114 String name = (index != -1) ? line.substring(0, index).trim() : line; 115 currentKey = (IDocumentKey)getEntry(name); 116 if (currentKey != null) { 117 while (Character.isSpaceChar(document.getChar(offset))) { 118 offset += 1; 119 } 120 currentKey.setOffset(offset); 121 if (!line.endsWith("\\")) { currentKey.setLength(document.getLineOffset(i) + document.getLineLength(i) - currentKey.getOffset()); 123 currentKey = null; 124 } 125 } 126 } 127 } 128 } catch (BadLocationException e) { 129 } 130 } 131 132 } 133 | Popular Tags |