All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.plugins.xml.checks.XmlFile Maven / Gradle / Ivy

There is a newer version: 2.12.0.5749
Show newest version
/*
 * SonarQube XML Plugin
 * Copyright (C) 2010-2016 SonarSource SA
 * mailto:contact AT sonarsource DOT com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package org.sonar.plugins.xml.checks;

import com.google.common.io.Files;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;

import java.io.File;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Checks and analyzes report measurements, issues and other findings in WebSourceCode.
 *
 * @author Matthijs Galesloot
 */
public class XmlFile {

  private static final Logger LOG = LoggerFactory.getLogger(XmlFile.class);
  private static final String XML_PROLOG_START_TAG = "
   *   
  • lineDeltaForIssue *
  • file */ private void processCharBeforePrologInFile(FileSystem fileSystem, int lineDelta) { try { String content = Files.toString(inputFile.file(), fileSystem.encoding()); File tempFile = new File(fileSystem.workDir(), inputFile.file().getName()); int index = content.indexOf(XML_PROLOG_START_TAG); Files.write(content.substring(index), tempFile, fileSystem.encoding()); noCharBeforePrologFile = tempFile; if (index != -1) { characterDeltaForHighlight += index; } if (lineDelta > 1) { lineDeltaForIssue = lineDelta - 1; } } catch (IOException e) { LOG.warn("Unable to analyse file {}", inputFile.absolutePath(), e); } } public InputFile getInputFile() { return inputFile; } public int getLineDelta() { return lineDeltaForIssue; } public int getOffsetDelta() { return characterDeltaForHighlight; } public File getIOFile() { return noCharBeforePrologFile != null ? noCharBeforePrologFile : inputFile.file(); } public int getPrologLine() { return lineDeltaForIssue + 1; } public boolean hasCharsBeforeProlog() { return hasCharsBeforeProlog; } }




  • © 2015 - 2025 Weber Informatics LLC | Privacy Policy