PMD: откат на движок 6.55.0 (maven-pmd-plugin 3.21.2), закрытый набор из 26 правил; нарушения починены кодом
PR checks / web (pull_request) Successful in 39s
PR checks / java (pull_request) Successful in 3m4s
Main: tests, deploy, autotests / java (push) Successful in 9s
Main: tests, deploy, autotests / web (push) Successful in 43s
Main: tests, deploy, autotests / images-app (push) Successful in 1m13s
Main: tests, deploy, autotests / images-web (push) Successful in 30s
Main: tests, deploy, autotests / deploy (push) Successful in 1m35s
Main: tests, deploy, autotests / autotests (push) Successful in 45s
Main: tests, deploy, autotests / rollback (push) Has been skipped
PR checks / web (pull_request) Successful in 39s
PR checks / java (pull_request) Successful in 3m4s
Main: tests, deploy, autotests / java (push) Successful in 9s
Main: tests, deploy, autotests / web (push) Successful in 43s
Main: tests, deploy, autotests / images-app (push) Successful in 1m13s
Main: tests, deploy, autotests / images-web (push) Successful in 30s
Main: tests, deploy, autotests / deploy (push) Successful in 1m35s
Main: tests, deploy, autotests / autotests (push) Successful in 45s
Main: tests, deploy, autotests / rollback (push) Has been skipped
This commit was merged in pull request #107.
This commit is contained in:
@@ -66,6 +66,15 @@ public final class WordPdfValidator {
|
||||
/** Элемент-контейнер body, внутри которого sectPr — межсекционный разрыв. */
|
||||
private static final String BODY_ELEMENT = "body";
|
||||
|
||||
/** Кэш-элемент <Pages> в docProps/app.xml. */
|
||||
private static final String PAGES_ELEMENT = "Pages";
|
||||
|
||||
/** Элемент sectPr — секция документа (межсекционный разрыв). */
|
||||
private static final String SECTION_PROPERTIES = "sectPr";
|
||||
|
||||
/** Элемент w:br — разрыв строки/страницы. */
|
||||
private static final String BREAK_ELEMENT = "br";
|
||||
|
||||
/** Кэш Word <Pages>. */
|
||||
private static final String APP_PART = "docProps/app.xml";
|
||||
|
||||
@@ -563,7 +572,7 @@ public final class WordPdfValidator {
|
||||
XMLStreamReader xr = newSecureReader().createXMLStreamReader(in);
|
||||
while (xr.hasNext()) {
|
||||
if (xr.next() == XMLStreamReader.START_ELEMENT
|
||||
&& "Pages".equals(xr.getLocalName())) {
|
||||
&& PAGES_ELEMENT.equals(xr.getLocalName())) {
|
||||
String text = xr.getElementText().trim();
|
||||
return Math.max(0, Integer.parseInt(text));
|
||||
}
|
||||
@@ -652,7 +661,7 @@ public final class WordPdfValidator {
|
||||
// различает финальную и межсекционные)
|
||||
}
|
||||
case "type" -> {
|
||||
if (inBodySectPr && "sectPr".equals(parent)) {
|
||||
if (inBodySectPr && SECTION_PROPERTIES.equals(parent)) {
|
||||
sectTypeVal = attrLocal(xr, "val");
|
||||
}
|
||||
}
|
||||
@@ -660,7 +669,7 @@ public final class WordPdfValidator {
|
||||
}
|
||||
}
|
||||
} else if (ev == XMLStreamReader.END_ELEMENT) {
|
||||
if ("sectPr".equals(xr.getLocalName()) && inBodySectPr) {
|
||||
if (SECTION_PROPERTIES.equals(xr.getLocalName()) && inBodySectPr) {
|
||||
if (pendingNewPageSection) {
|
||||
bodyDirectSectPr++;
|
||||
}
|
||||
@@ -693,7 +702,7 @@ public final class WordPdfValidator {
|
||||
XMLStreamReader xr = newSecureReader().createXMLStreamReader(in);
|
||||
while (xr.hasNext()) {
|
||||
if (xr.next() == XMLStreamReader.START_ELEMENT
|
||||
&& "br".equals(xr.getLocalName()) && isPageBreak(xr)) {
|
||||
&& BREAK_ELEMENT.equals(xr.getLocalName()) && isPageBreak(xr)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +72,10 @@ final class HiddenTextNormalizer {
|
||||
/** Закрывающий слэш самозакрывающегося тега. */
|
||||
private static final char SELF_CLOSE = '/';
|
||||
|
||||
/** Части, которые рерайт пропускает: ранов там нет, а vanish в styles — входные данные. */
|
||||
private static final String STYLES_PART = "word/styles.xml";
|
||||
private static final String NUMBERING_PART = "word/numbering.xml";
|
||||
|
||||
/** Открывающий/закрывающий тег рана; {@code <w:rPr>}/{@code <w:rStyle>} и прочее не матчатся по границе имени. */
|
||||
private static final Pattern RUN_TOKEN = Pattern.compile("<w:r(?=[ >/])|</w:r>");
|
||||
|
||||
@@ -110,7 +114,7 @@ final class HiddenTextNormalizer {
|
||||
static byte[] normalize(byte[] docx) throws IOException {
|
||||
Set<String> vanishStyles = Set.of();
|
||||
try (ZipFile zf = new ZipFile(new SeekableInMemoryByteChannel(docx))) {
|
||||
ZipArchiveEntry styles = zf.getEntry("word/styles.xml");
|
||||
ZipArchiveEntry styles = zf.getEntry(STYLES_PART);
|
||||
if (styles != null) {
|
||||
vanishStyles = vanishStyles(new String(
|
||||
zf.getInputStream(styles).readAllBytes(), StandardCharsets.UTF_8));
|
||||
@@ -152,7 +156,7 @@ final class HiddenTextNormalizer {
|
||||
* @return новая строка либо null, если менять нечего
|
||||
*/
|
||||
static String rewritePart(String name, String xml, Set<String> vanishStyleIds) {
|
||||
if ("word/styles.xml".equals(name) || "word/numbering.xml".equals(name)) {
|
||||
if (STYLES_PART.equals(name) || NUMBERING_PART.equals(name)) {
|
||||
return null;
|
||||
}
|
||||
return rewrite(vanishStyleIds, xml);
|
||||
|
||||
@@ -75,6 +75,9 @@ public final class OleObjectNormalizer {
|
||||
/** Сегмент «наверх» в относительном Target rels. */
|
||||
private static final String PARENT_DIR = "..";
|
||||
|
||||
/** Сегмент «текущий каталог» в относительном Target rels. */
|
||||
private static final String CURRENT_DIR = ".";
|
||||
|
||||
private static final Pattern DEFAULT_TYPE = Pattern.compile(
|
||||
"<Default\\b[^>]*\\bExtension=\"([^\"]*)\"[^>]*\\bContentType=\"([^\"]*)\"[^>]*/>"
|
||||
+ "|<Default\\b[^>]*\\bContentType=\"([^\"]*)\"[^>]*\\bExtension=\"([^\"]*)\"[^>]*/>");
|
||||
@@ -373,7 +376,7 @@ public final class OleObjectNormalizer {
|
||||
}
|
||||
}
|
||||
for (String s : target.split("/")) {
|
||||
if (s.isEmpty() || ".".equals(s)) {
|
||||
if (s.isEmpty() || CURRENT_DIR.equals(s)) {
|
||||
continue;
|
||||
}
|
||||
if (PARENT_DIR.equals(s)) {
|
||||
|
||||
@@ -52,6 +52,10 @@ final class ChartRenderer {
|
||||
/** Порог «значение целое» при форматировании подписей. */
|
||||
private static final double INTEGER_EPSILON = 1e-9;
|
||||
|
||||
/** Позиции легенды (ECMA-376 §21.2.2.144 ST_LegendPos): снизу/сверху. */
|
||||
private static final String LEGEND_BOTTOM = "b";
|
||||
private static final String LEGEND_TOP = "t";
|
||||
|
||||
/**
|
||||
* Верхняя граница числа делений: {@code c:majorUnit} (ECMA-376 §21.2.2.103) —
|
||||
* double без нижней границы; Word пишет «круглые» значения, а враждебный docx —
|
||||
@@ -110,12 +114,12 @@ final class ChartRenderer {
|
||||
// дорисовывается поверх после художника. Регрессия — ChartRendererTest#overlayLegend_drawnOverPlot.
|
||||
double legendH = legend == null || spec.legendOverlay ? 0 : legend.height;
|
||||
Rectangle2D box0 = box;
|
||||
if (legend != null && !spec.legendOverlay && "b".equals(spec.legendPos)) {
|
||||
if (legend != null && !spec.legendOverlay && LEGEND_BOTTOM.equals(spec.legendPos)) {
|
||||
legend.draw(g, box.getX(), box.getY() + box.getHeight() - legendH,
|
||||
box.getWidth());
|
||||
box = new Rectangle2D.Double(box.getX(), box.getY(),
|
||||
box.getWidth(), box.getHeight() - legendH);
|
||||
} else if (legend != null && !spec.legendOverlay && "t".equals(spec.legendPos)) {
|
||||
} else if (legend != null && !spec.legendOverlay && LEGEND_TOP.equals(spec.legendPos)) {
|
||||
legend.draw(g, box.getX(), box.getY(), box.getWidth());
|
||||
box = new Rectangle2D.Double(box.getX(), box.getY() + legendH,
|
||||
box.getWidth(), box.getHeight() - legendH);
|
||||
@@ -144,7 +148,7 @@ final class ChartRenderer {
|
||||
default -> LOG.warn("тип графика {} не поддерживается — пустой PNG", spec.type);
|
||||
}
|
||||
if (legend != null && spec.legendOverlay) {
|
||||
double y = "t".equals(spec.legendPos)
|
||||
double y = LEGEND_TOP.equals(spec.legendPos)
|
||||
? box0.getY() : box0.getY() + box0.getHeight() - legend.height;
|
||||
legend.draw(g, box0.getX(), y, box0.getWidth());
|
||||
}
|
||||
|
||||
@@ -57,6 +57,8 @@ final class DrawMlText {
|
||||
|
||||
/** Значения выравнивания DrawingML (a:pPr/@algn, a:bodyPr/@anchor). */
|
||||
private static final String ALIGN_CTR = "ctr";
|
||||
private static final String ALIGN_RIGHT = "r";
|
||||
private static final String ALIGN_FAR = "far";
|
||||
private static final String VALIGN_BOTTOM = "b";
|
||||
|
||||
/** Длина строки, дальше которую рез не идёт (прогресс гарантирован 1 символом). */
|
||||
@@ -241,7 +243,7 @@ final class DrawMlText {
|
||||
String align = line.align() != null ? line.align() : defAlign;
|
||||
if (ALIGN_CTR.equals(align)) {
|
||||
x += (box.getWidth() - line.width()) / 2.0;
|
||||
} else if ("r".equals(align) || "far".equals(align)) {
|
||||
} else if (ALIGN_RIGHT.equals(align) || ALIGN_FAR.equals(align)) {
|
||||
x += box.getWidth() - line.width();
|
||||
}
|
||||
fontFor(line.style()).draw(g, line.text(), x, y + line.ascent(),
|
||||
|
||||
+15
-10
@@ -402,19 +402,24 @@ final class Surface3dPainter {
|
||||
|
||||
private static List<double[]> clipHalf(List<double[]> poly, double bound, boolean keepAbove) {
|
||||
List<double[]> out = new ArrayList<>();
|
||||
for (int i = 0; i < poly.size(); i++) {
|
||||
double[] cur = poly.get(i);
|
||||
double[] nxt = poly.get((i + 1) % poly.size());
|
||||
if (poly.isEmpty()) {
|
||||
return out;
|
||||
}
|
||||
// Рёбра (prev → cur) по кругу от замыкающего: то же множество рёбер, что у
|
||||
// индексного (i, (i+1)%n); foreach — ForLoopCanBeForeach.
|
||||
double[] prev = poly.get(poly.size() - 1);
|
||||
for (double[] cur : poly) {
|
||||
boolean inPrev = keepAbove ? prev[2] >= bound : prev[2] <= bound;
|
||||
boolean inCur = keepAbove ? cur[2] >= bound : cur[2] <= bound;
|
||||
boolean inNxt = keepAbove ? nxt[2] >= bound : nxt[2] <= bound;
|
||||
if (inCur) {
|
||||
out.add(cur);
|
||||
if (inPrev) {
|
||||
out.add(prev);
|
||||
}
|
||||
if (inCur != inNxt && Math.abs(nxt[2] - cur[2]) > 1e-12) {
|
||||
double t = (bound - cur[2]) / (nxt[2] - cur[2]);
|
||||
out.add(new double[]{cur[0] + t * (nxt[0] - cur[0]),
|
||||
cur[1] + t * (nxt[1] - cur[1]), bound});
|
||||
if (inPrev != inCur && Math.abs(cur[2] - prev[2]) > 1e-12) {
|
||||
double t = (bound - prev[2]) / (cur[2] - prev[2]);
|
||||
out.add(new double[]{prev[0] + t * (cur[0] - prev[0]),
|
||||
prev[1] + t * (cur[1] - prev[1]), bound});
|
||||
}
|
||||
prev = cur;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -256,6 +256,8 @@ public final class DocToDocx {
|
||||
private static final char QUOTE = '"';
|
||||
/** Переключатель якорной ссылки Word. */
|
||||
private static final String ANCHOR_SWITCH = "\\l";
|
||||
/** Токен поля HYPERLINK в начале инструкции. */
|
||||
private static final String HYPERLINK_FIELD = "HYPERLINK";
|
||||
|
||||
private final PieceTable pieces;
|
||||
private final ChpxIndex chpx;
|
||||
@@ -950,7 +952,7 @@ public final class DocToDocx {
|
||||
while (end < s.length() && !Character.isWhitespace(s.charAt(end))) {
|
||||
end++;
|
||||
}
|
||||
if (!"HYPERLINK".equalsIgnoreCase(s.substring(0, end))) {
|
||||
if (!HYPERLINK_FIELD.equalsIgnoreCase(s.substring(0, end))) {
|
||||
return null;
|
||||
}
|
||||
int p = end;
|
||||
|
||||
@@ -86,8 +86,12 @@ final class Tables {
|
||||
int[] centers() {
|
||||
int[] c = new int[colWidths.length + 1];
|
||||
c[0] = indent;
|
||||
for (int i = 0; i < colWidths.length; i++) {
|
||||
c[i + 1] = c[i] + colWidths[i];
|
||||
int i = 1;
|
||||
// foreach: индексный for по компоненту рекорда валит ForLoopCanBeForeach
|
||||
// на PMD 6.55.0 (ClassCastException в VariableNameDeclaration.isArray)
|
||||
for (int w : colWidths) {
|
||||
c[i] = c[i - 1] + w;
|
||||
i++;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
+8
-4
@@ -47,6 +47,10 @@ class PresetGeometryTest {
|
||||
private static final int DEPTH_BLOCK = 2;
|
||||
private static final int DEPTH_SECTION = 3;
|
||||
|
||||
private static final String GUIDE_ELEMENT = "gd";
|
||||
private static final String PATH_LIST_SECTION = "pathLst";
|
||||
private static final String POINT_ELEMENT = "pt";
|
||||
|
||||
@Test
|
||||
void tableMatchesEcmaXml() throws Exception {
|
||||
Map<String, PresetGeometry.Preset> fromXml = parseEcmaXml();
|
||||
@@ -196,14 +200,14 @@ class PresetGeometryTest {
|
||||
case "avLst", "gdLst", "pathLst" -> ln;
|
||||
default -> null;
|
||||
};
|
||||
} else if (block != null && "gd".equals(ln) && section != null) {
|
||||
} else if (block != null && GUIDE_ELEMENT.equals(ln) && section != null) {
|
||||
String entry = r.getAttributeValue(null, "name") + " "
|
||||
+ r.getAttributeValue(null, "fmla");
|
||||
switch (section) {
|
||||
case "avLst" -> av.add(entry);
|
||||
default -> gd.add(entry);
|
||||
}
|
||||
} else if (block != null && "pathLst".equals(section)) {
|
||||
} else if (block != null && PATH_LIST_SECTION.equals(section)) {
|
||||
switch (ln) {
|
||||
case "moveTo", "lnTo" -> {
|
||||
String[] pt = readPt(r);
|
||||
@@ -241,7 +245,7 @@ class PresetGeometryTest {
|
||||
private static String[] readPt(XMLStreamReader r) throws Exception {
|
||||
while (r.hasNext()) {
|
||||
if (r.next() == XMLStreamConstants.START_ELEMENT
|
||||
&& "pt".equals(r.getLocalName())) {
|
||||
&& POINT_ELEMENT.equals(r.getLocalName())) {
|
||||
String[] attrs = {
|
||||
r.getAttributeValue(null, "x"),
|
||||
r.getAttributeValue(null, "y"),
|
||||
@@ -249,7 +253,7 @@ class PresetGeometryTest {
|
||||
boolean closed = false;
|
||||
while (!closed) {
|
||||
closed = r.next() == XMLStreamConstants.END_ELEMENT
|
||||
&& "pt".equals(r.getLocalName());
|
||||
&& POINT_ELEMENT.equals(r.getLocalName());
|
||||
}
|
||||
return attrs;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user