| 1 | | | |
| 2 | | | |
| 3 | | | |
| 4 | | | |
| 5 | | | |
| 6 | | | |
| 7 | | | |
| 8 | | | |
| 9 | | | |
| 10 | | | |
| 11 | | | |
| 12 | | | |
| 13 | | | |
| 14 | | | |
| 15 | | | |
| 16 | | | |
| 17 | | | |
| 18 | | | |
| 19 | | | |
| 20 | | | |
| 21 | | | |
| 22 | | | |
| 23 | | | |
| 24 | | | |
| 25 | | | |
| 26 | | | |
| 27 | | | |
| 28 | | | |
| 29 | | | |
| 30 | | | |
| 31 | | | |
| 32 | | | |
| 33 | | | package org.jcoderz.phoenix.report; |
| 34 | | | |
| 35 | | | import java.io.Serializable; |
| 36 | | | import java.util.Comparator; |
| 37 | | | import java.util.regex.Matcher; |
| 38 | | | import java.util.regex.Pattern; |
| 39 | | | |
| 40 | | | import javax.xml.bind.JAXBException; |
| 41 | | | |
| 42 | | | import org.jcoderz.phoenix.report.GenericReportReader.SourceFile; |
| 43 | | | import org.jcoderz.phoenix.report.ftf.jaxb.FindingDescription; |
| 44 | | | import org.jcoderz.phoenix.report.jaxb.Item; |
| 45 | | | import org.jcoderz.phoenix.report.jaxb.ObjectFactory; |
| 46 | | | |
| 47 | | | |
| 48 | | | |
| 49 | | | |
| 50 | | | |
| 51 | | | @author |
| 52 | | | |
| 53 | 0 | | public final class GenericFindingType |
| 54 | | | extends FindingType |
| 55 | | | { |
| 56 | | | private final Pattern mPattern; |
| 57 | | | private final int mPriority; |
| 58 | | | private final FindingDescription mFindingDescription; |
| 59 | | | private final int mTextPos; |
| 60 | | | private final int mLineStart; |
| 61 | | | private final int mLineEnd; |
| 62 | | | private final int mColumnStart; |
| 63 | | | private final int mColumnEnd; |
| 64 | | | private final int mSourceText; |
| 65 | | | private final boolean mSourceColumnByCaret; |
| 66 | | | private final Severity mSeverity; |
| 67 | | | private final boolean mIsGlobal; |
| 68 | | | |
| 69 | 0 | | private final ObjectFactory mOf = new ObjectFactory(); |
| 70 | | | |
| 71 | | | |
| 72 | | | |
| 73 | | | |
| 74 | | | |
| 75 | | | @param |
| 76 | | | @param |
| 77 | | | |
| 78 | | | public GenericFindingType ( |
| 79 | | | FindingDescription root, FindingDescription fd) |
| 80 | | | { |
| 81 | 0 | | super(fd.getSymbol(), fd.getShortDescription(), |
| 82 | | | fd.getDescription()); |
| 83 | | | |
| 84 | 0 | | mPriority = fd.getPriority(); |
| 85 | 0 | | mPattern = Pattern.compile( |
| 86 | | | fd.getPattern(), Pattern.MULTILINE + Pattern.UNIX_LINES); |
| 87 | 0 | | mFindingDescription = fd; |
| 88 | 0 | | mTextPos = fd.isSetTextPos() ? Integer.parseInt(fd.getTextPos()) : -1; |
| 89 | 0 | | mLineStart = fd.isSetLineStartPos() |
| 90 | | | ? Integer.parseInt(fd.getLineStartPos()) : -1; |
| 91 | 0 | | mLineEnd = fd.isSetLineEndPos() |
| 92 | | | ? Integer.parseInt(fd.getLineEndPos()) : -1; |
| 93 | 0 | | if (fd.isSetColumnStartPos() && "caret".equals(fd.getColumnStartPos())) |
| 94 | | | { |
| 95 | 0 | | mColumnStart = -1; |
| 96 | 0 | | mSourceColumnByCaret = true; |
| 97 | | | } |
| 98 | | | else |
| 99 | | | { |
| 100 | 0 | | mColumnStart = fd.isSetColumnStartPos() |
| 101 | | | ? Integer.parseInt(fd.getColumnStartPos()) : -1; |
| 102 | 0 | | mSourceColumnByCaret = false; |
| 103 | | | } |
| 104 | 0 | | mColumnEnd = fd.isSetColumnEndPos() |
| 105 | | | ? Integer.parseInt(fd.getColumnEndPos()) : -1; |
| 106 | 0 | | mSourceText = fd.isSetSourceTextPos() |
| 107 | | | ? Integer.parseInt(fd.getSourceTextPos()) : -1; |
| 108 | 0 | | mSeverity = fd.isSetSeverity() ? fd.getSeverity() : null; |
| 109 | 0 | | mIsGlobal = fd.isGlobal(); |
| 110 | 0 | | } |
| 111 | | | |
| 112 | | | |
| 113 | | | |
| 114 | | | |
| 115 | | | |
| 116 | | | @param |
| 117 | | | @param |
| 118 | | | @return |
| 119 | | | @throws |
| 120 | | | |
| 121 | | | public Item createItem (SourceFile sf, String message) throws JAXBException |
| 122 | | | { |
| 123 | 0 | | Item result = null; |
| 124 | 0 | | final Matcher match = mPattern.matcher(message); |
| 125 | 0 | | if (match.lookingAt()) |
| 126 | | | { |
| 127 | 0 | | sf.setPos(sf.getPos() + match.end() + 1); |
| 128 | 0 | | result = mOf.createItem(); |
| 129 | 0 | | result.setFindingType(getSymbol()); |
| 130 | 0 | | if (mTextPos != -1) |
| 131 | | | { |
| 132 | 0 | | result.setMessage(match.group(mTextPos)); |
| 133 | | | } |
| 134 | | | else |
| 135 | | | { |
| 136 | 0 | | result.setMessage(match.group()); |
| 137 | | | } |
| 138 | 0 | | if (mLineStart != -1) |
| 139 | | | { |
| 140 | 0 | | result.setLine(Integer.parseInt(match.group(mLineStart))); |
| 141 | | | } |
| 142 | 0 | | if (mLineEnd != -1) |
| 143 | | | { |
| 144 | 0 | | result.setEndLine(Integer.parseInt(match.group(mLineEnd))); |
| 145 | | | } |
| 146 | 0 | | if (mColumnStart != -1) |
| 147 | | | { |
| 148 | 0 | | result.setColumn(Integer.parseInt(match.group(mColumnStart))); |
| 149 | | | } |
| 150 | 0 | | if (mColumnEnd != -1) |
| 151 | | | { |
| 152 | 0 | | result.setEndColumn(Integer.parseInt(match.group(mColumnEnd))); |
| 153 | | | } |
| 154 | 0 | | if (mSourceText != -1) |
| 155 | | | { |
| 156 | 0 | | result.setSourceText(match.group(mSourceText)); |
| 157 | | | } |
| 158 | 0 | | if (mSeverity != null) |
| 159 | | | { |
| 160 | 0 | | result.setSeverity(mSeverity); |
| 161 | | | } |
| 162 | 0 | | if (mFindingDescription.isGlobal()) |
| 163 | | | { |
| 164 | 0 | | result.setGlobal(true); |
| 165 | | | } |
| 166 | | | } |
| 167 | 0 | | return result; |
| 168 | | | } |
| 169 | | | |
| 170 | | | @return |
| 171 | | | public Severity getSeverity () |
| 172 | | | { |
| 173 | 0 | | return mSeverity; |
| 174 | | | } |
| 175 | | | |
| 176 | | (1) | |
| 177 | | | |
| 178 | | | |
| 179 | | | |
| 180 | | | |
| 181 | | | {@link } |
| 182 | | | |
| 183 | | | |
| 184 | | | private int getPriority () |
| 185 | | | { |
| 186 | 0 | | return mPriority; |
| 187 | | | } |
| 188 | | | |
| 189 | | | |
| 190 | | | @return |
| 191 | | | |
| 192 | | | public boolean isSourceColumnByCaret () |
| 193 | | | { |
| 194 | 0 | | return mSourceColumnByCaret; |
| 195 | | | } |
| 196 | | | |
| 197 | | | |
| 198 | | | |
| 199 | | | @return |
| 200 | | | |
| 201 | | | public boolean isGlobal () |
| 202 | | | { |
| 203 | 0 | | return mIsGlobal; |
| 204 | | | } |
| 205 | | | |
| 206 | | | |
| 207 | | | |
| 208 | | | |
| 209 | | | |
| 210 | | | public static void initialize () |
| 211 | | | { |
| 212 | | | |
| 213 | 0 | | } |
| 214 | | | |
| 215 | | | |
| 216 | | | {@link } |
| 217 | | | |
| 218 | 0 | | public static class OrderByPriority |
| 219 | | | implements Comparator<GenericFindingType>, Serializable |
| 220 | | | { |
| 221 | | | private static final long serialVersionUID = 1L; |
| 222 | | | |
| 223 | | | {@inheritDoc} |
| 224 | | | public int compare (GenericFindingType o1, GenericFindingType o2) |
| 225 | | | { |
| 226 | | | final int result; |
| 227 | 0 | | if (o1.getPriority() > o2.getPriority()) |
| 228 | | | { |
| 229 | 0 | | result = -1; |
| 230 | | | } |
| 231 | 0 | | else if (o1.getPriority() < o2.getPriority()) |
| 232 | | | { |
| 233 | 0 | | result = 1; |
| 234 | | | } |
| 235 | | | else |
| 236 | | | { |
| 237 | 0 | | result = o1.getSymbol().compareTo(o2.getSymbol()); |
| 238 | | | } |
| 239 | 0 | | return result; |
| 240 | | | } |
| 241 | | | } |
| 242 | | | |
| 243 | | | } |