001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.java;
031:
032: import com.caucho.util.IntMap;
033: import com.caucho.vfs.WriteStream;
034:
035: import java.io.IOException;
036: import java.util.Iterator;
037:
038: /**
039: * LineMapWriter writes the *.map files.
040: */
041: public class LineMapWriter {
042: private WriteStream _os;
043: private String _sourceType = "JSP";
044:
045: /**
046: * Creates the writer.
047: */
048: public LineMapWriter(WriteStream os) {
049: _os = os;
050: }
051:
052: /**
053: * Sets the source-type, e.g. JSP
054: */
055: public void setSourceType(String type) {
056: _sourceType = type;
057: }
058:
059: /**
060: * Writes the line map
061: */
062: public void write(LineMap lineMap) throws IOException {
063: _os.println("SMAP");
064: _os.println(lineMap.getDestFilename());
065: _os.println(_sourceType);
066: _os.println("*S " + _sourceType);
067:
068: IntMap fileMap = new IntMap();
069:
070: _os.println("*F");
071: Iterator<LineMap.Line> iter = lineMap.iterator();
072: while (iter.hasNext()) {
073: LineMap.Line line = iter.next();
074:
075: String filename = line.getSourceFilename();
076: int index = fileMap.get(filename);
077: if (index < 0) {
078: index = fileMap.size() + 1;
079: fileMap.put(filename, index);
080:
081: if (filename.indexOf('/') >= 0) {
082: int p = filename.lastIndexOf('/');
083:
084: _os.println("+ " + index + " "
085: + filename.substring(p + 1));
086: // XXX: _os.println(filename);
087:
088: if (filename.startsWith("/"))
089: _os.println(filename.substring(1));
090: else
091: _os.println(filename);
092: } else
093: _os.println(index + " " + filename);
094: }
095: }
096:
097: _os.println("*L");
098: int size = lineMap.size();
099: int lastIndex = 0;
100: for (int i = 0; i < size; i++) {
101: LineMap.Line line = lineMap.get(i);
102:
103: String filename = line.getSourceFilename();
104: int index = fileMap.get(filename);
105:
106: String fileMarker = "";
107:
108: _os.print(line.getSourceLine());
109: _os.print("#" + index);
110:
111: if (line.getRepeatCount() > 1)
112: _os.print("," + line.getRepeatCount());
113:
114: _os.print(":");
115: _os.print(line.getDestinationLine());
116: if (line.getDestinationIncrement() > 1)
117: _os.print("," + line.getDestinationIncrement());
118: _os.println();
119: }
120:
121: _os.println("*E");
122: }
123: }
|