sonar-ndepend-plugin-1.0

16:53:10.508 INFO  jd.cli.Main - Decompiling sonar-ndepend-plugin-1.0.jar
package org.sonar.plugins.ndepend;

import com.google.common.base.Preconditions;
import java.io.File;
import org.sonar.api.BatchExtension;
import org.sonar.api.ServerExtension;
import org.sonar.api.config.Settings;

public class NDependConfiguration
  implements BatchExtension, ServerExtension
{
  private final Settings settings;
  
  public NDependConfiguration(Settings settings)
  {
    this.settings = settings;
  }
  
  public String rules()
  {
    String xml = settings.getString("sonar.cs.ndepend.rules");
    return xml == null ? "" : xml;
  }
  
  public String ruleRunnerPath()
  {
    return checkAbsolutePath("sonar.cs.ndepend.ruleRunnerPath");
  }
  
  public String ndependProjectPath()
  {
    return checkAbsolutePath("sonar.cs.ndepend.projectPath");
  }
  
  public int timeout()
  {
    return settings.getInt("sonar.cs.ndepend.timeoutMinutes");
  }
  
  private String checkAbsolutePath(String property)
  {
    String path = settings.getString(property);
    Preconditions.checkNotNull(path, "The property \"" + property + "\" must be set (to an absolute path).");
    
    File file = new File(path);
    Preconditions.checkArgument(file.isAbsolute(), "The path provided in the property \"" + property + "\" must be an absolute path: " + path);
    Preconditions.checkArgument(file.exists(), "The absolute path provided in the property \"" + property + "\" does not exist: " + path);
    
    return path;
  }
}

/* Location:
 * Qualified Name:     org.sonar.plugins.ndepend.NDependConfiguration
 * Java Class Version: 7 (51.0)
 * JD-Core Version:    0.7.1
 */
package org.sonar.plugins.ndepend;

import java.io.File;
import java.util.concurrent.TimeUnit;
import org.sonar.api.utils.command.Command;
import org.sonar.api.utils.command.CommandException;
import org.sonar.api.utils.command.CommandExecutor;

public class NDependExecutor
{
  public void execute(String executable, String ndependProject, File reportFile, int timeout)
  {
    Command cmd = Command.create(executable).addArgument(ndependProject).addArgument(reportFile.getAbsolutePath());
    
    int exitCode = CommandExecutor.create().execute(cmd, TimeUnit.MINUTES.toMillis(timeout));
    if (exitCode != 0) {
      throw new CommandException(cmd, "NDepend execution failed with exit code: " + exitCode, null);
    }
  }
}

/* Location:
 * Qualified Name:     org.sonar.plugins.ndepend.NDependExecutor
 * Java Class Version: 7 (51.0)
 * JD-Core Version:    0.7.1
 */
package org.sonar.plugins.ndepend;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
import java.util.List;
import org.sonar.api.PropertyType;
import org.sonar.api.SonarPlugin;
import org.sonar.api.config.PropertyDefinition;
import org.sonar.api.config.PropertyDefinition.Builder;

public class NDependPlugin
  extends SonarPlugin
{
  public static final String LANGUAGE_KEY = "cs";
  public static final String REPOSITORY_KEY = "ndepend";
  public static final String REPOSITORY_NAME = "NDepend";
  public static final String RULES_PROPERTY_KEY = "sonar.cs.ndepend.rules";
  public static final String RULE_RUNNER_PATH_PROPERTY_KEY = "sonar.cs.ndepend.ruleRunnerPath";
  public static final String NDEPEND_PROJECT_PATH_PROPERTY_KEY = "sonar.cs.ndepend.projectPath";
  public static final String TIMEOUT_PROPERTY_KEY = "sonar.cs.ndepend.timeoutMinutes";
  private static final String CATEGORY = "NDepend";
  
  public List getExtensions()
  {
    ImmutableList.Builder builder = ImmutableList.builder();
    
    builder.add(new Object[] { NDependConfiguration.class, NDependRulesDefinition.class, NDependSensor.class });
    
    builder.addAll(pluginProperties());
    
    return builder.build();
  }
  
  private static ImmutableList<PropertyDefinition> pluginProperties()
  {
    return ImmutableList.of(PropertyDefinition.builder("sonar.cs.ndepend.rules").name("NDepend rules").description("XML output of NDepend.SonarQube.RuleSetBuilder.exe. Restart the SonarQube server to make changes to this property effective.").category("NDepend").type(PropertyType.TEXT).build(), PropertyDefinition.builder("sonar.cs.ndepend.ruleRunnerPath").name("Path to NDepend.SonarQube.RuleRunner.exe").description("Must be an absolute path. Example: C:/NDepend.SonarQube.RuleRunner.exe").category("NDepend").onQualifiers("TRK", new String[] { "BRC" }).build(), PropertyDefinition.builder("sonar.cs.ndepend.timeoutMinutes").name("NDepend execution timeout").description("Time in minutes after which NDepend's execution should be interrupted if not finished").defaultValue("10").category("NDepend").onQualifiers("TRK", new String[] { "BRC" }).type(PropertyType.INTEGER).build(), PropertyDefinition.builder("sonar.cs.ndepend.projectPath").name("Project file").description("Must be an absolute path. Example: C:/project.ndproj").category("NDepend").onlyOnQualifiers("TRK", new String[] { "BRC" }).build());
  }
}

/* Location:
 * Qualified Name:     org.sonar.plugins.ndepend.NDependPlugin
 * Java Class Version: 7 (51.0)
 * JD-Core Version:    0.7.1
 */
package org.sonar.plugins.ndepend;

class NDependReportParser$ParseErrorException
  extends RuntimeException
{
  private static final long serialVersionUID = 1L;
  
  public NDependReportParser$ParseErrorException(String message)
  {
    super(message);
  }
}

/* Location:
 * Qualified Name:     org.sonar.plugins.ndepend.NDependReportParser.ParseErrorException
 * Java Class Version: 7 (51.0)
 * JD-Core Version:    0.7.1
 */
package org.sonar.plugins.ndepend;

import com.google.common.base.Charsets;
import com.google.common.base.Throwables;
import com.google.common.io.Closeables;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.annotation.Nullable;
import javax.xml.stream.Location;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

class NDependReportParser$Parser
{
  private final NDependReportParserCallback callback;
  private File file;
  private XMLStreamReader stream;
  
  public NDependReportParser$Parser(NDependReportParserCallback callback)
  {
    this.callback = callback;
  }
  
  public void parse(File file)
  {
    this.file = file;
    
    InputStreamReader reader = null;
    XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
    try
    {
      reader = new InputStreamReader(new FileInputStream(file), Charsets.UTF_8);
      stream = xmlFactory.createXMLStreamReader(reader);
      while (stream.hasNext()) {
        if ((stream.next() == 1) && (getAttribute("Name") != null)) {
          handleScope();
        }
      }
    }
    catch (IOException e)
    {
      throw Throwables.propagate(e);
    }
    catch (XMLStreamException e)
    {
      throw Throwables.propagate(e);
    }
    finally
    {
      closeXmlStream();
      Closeables.closeQuietly(reader);
    }
  }
  
  private void handleScope()
    throws XMLStreamException
  {
    String tagName = stream.getLocalName();
    
    String currentFile = getAttribute("File");
    Integer currentLine = getIntAttribute("Line");
    while (stream.hasNext())
    {
      int next = stream.next();
      if ((next == 2) && (tagName.equals(stream.getLocalName()))) {
        break;
      }
      if (next == 1)
      {
        if (getAttribute("Name") != null) {
          handleScope();
        }
        if ((currentFile != null) && (currentLine != null) && ("RuleViolated".equals(stream.getLocalName())))
        {
          String key = getRequiredAttribute("Key");
          callback.onIssue(key, currentFile, currentLine.intValue());
        }
      }
    }
  }
  
  private void closeXmlStream()
  {
    if (stream != null) {
      try
      {
        stream.close();
      }
      catch (XMLStreamException e)
      {
        throw Throwables.propagate(e);
      }
    }
  }
  
  private String getRequiredAttribute(String name)
  {
    String value = getAttribute(name);
    if (value == null) {
      throw parseError("Missing attribute \"" + name + "\" in element <" + stream.getLocalName() + ">");
    }
    return value;
  }
  
  @Nullable
  private Integer getIntAttribute(String name)
  {
    String value = getAttribute(name);
    if (value == null) {
      return null;
    }
    try
    {
      return Integer.valueOf(Integer.parseInt(value));
    }
    catch (NumberFormatException e)
    {
      throw parseError("Expected an integer instead of \"" + value + "\" for the attribute \"" + name + "\"");
    }
  }
  
  @Nullable
  private String getAttribute(String name)
  {
    for (int i = 0; i < stream.getAttributeCount(); i++) {
      if (name.equals(stream.getAttributeLocalName(i))) {
        return stream.getAttributeValue(i);
      }
    }
    return null;
  }
  
  private NDependReportParser.ParseErrorException parseError(String message)
  {
    return new NDependReportParser.ParseErrorException(message + " in " + file.getAbsolutePath() + " at line " + stream.getLocation().getLineNumber());
  }
}

/* Location:
 * Qualified Name:     org.sonar.plugins.ndepend.NDependReportParser.Parser
 * Java Class Version: 7 (51.0)
 * JD-Core Version:    0.7.1
 */
package org.sonar.plugins.ndepend;

import com.google.common.base.Charsets;
import com.google.common.base.Throwables;
import com.google.common.io.Closeables;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.annotation.Nullable;
import javax.xml.stream.Location;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

public class NDependReportParser
{
  private final NDependReportParserCallback callback;
  
  public NDependReportParser(NDependReportParserCallback callback)
  {
    this.callback = callback;
  }
  
  public void parse(File file)
  {
    new Parser(callback).parse(file);
  }
  
  private static class Parser
  {
    private final NDependReportParserCallback callback;
    private File file;
    private XMLStreamReader stream;
    
    public Parser(NDependReportParserCallback callback)
    {
      this.callback = callback;
    }
    
    public void parse(File file)
    {
      this.file = file;
      
      InputStreamReader reader = null;
      XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
      try
      {
        reader = new InputStreamReader(new FileInputStream(file), Charsets.UTF_8);
        stream = xmlFactory.createXMLStreamReader(reader);
        while (stream.hasNext()) {
          if ((stream.next() == 1) && (getAttribute("Name") != null)) {
            handleScope();
          }
        }
      }
      catch (IOException e)
      {
        throw Throwables.propagate(e);
      }
      catch (XMLStreamException e)
      {
        throw Throwables.propagate(e);
      }
      finally
      {
        closeXmlStream();
        Closeables.closeQuietly(reader);
      }
    }
    
    private void handleScope()
      throws XMLStreamException
    {
      String tagName = stream.getLocalName();
      
      String currentFile = getAttribute("File");
      Integer currentLine = getIntAttribute("Line");
      while (stream.hasNext())
      {
        int next = stream.next();
        if ((next == 2) && (tagName.equals(stream.getLocalName()))) {
          break;
        }
        if (next == 1)
        {
          if (getAttribute("Name") != null) {
            handleScope();
          }
          if ((currentFile != null) && (currentLine != null) && ("RuleViolated".equals(stream.getLocalName())))
          {
            String key = getRequiredAttribute("Key");
            callback.onIssue(key, currentFile, currentLine.intValue());
          }
        }
      }
    }
    
    private void closeXmlStream()
    {
      if (stream != null) {
        try
        {
          stream.close();
        }
        catch (XMLStreamException e)
        {
          throw Throwables.propagate(e);
        }
      }
    }
    
    private String getRequiredAttribute(String name)
    {
      String value = getAttribute(name);
      if (value == null) {
        throw parseError("Missing attribute \"" + name + "\" in element <" + stream.getLocalName() + ">");
      }
      return value;
    }
    
    @Nullable
    private Integer getIntAttribute(String name)
    {
      String value = getAttribute(name);
      if (value == null) {
        return null;
      }
      try
      {
        return Integer.valueOf(Integer.parseInt(value));
      }
      catch (NumberFormatException e)
      {
        throw parseError("Expected an integer instead of \"" + value + "\" for the attribute \"" + name + "\"");
      }
    }
    
    @Nullable
    private String getAttribute(String name)
    {
      for (int i = 0; i < stream.getAttributeCount(); i++) {
        if (name.equals(stream.getAttributeLocalName(i))) {
          return stream.getAttributeValue(i);
        }
      }
      return null;
    }
    
    private NDependReportParser.ParseErrorException parseError(String message)
    {
      return new NDependReportParser.ParseErrorException(message + " in " + file.getAbsolutePath() + " at line " + stream.getLocation().getLineNumber());
    }
  }
  
  private static class ParseErrorException
    extends RuntimeException
  {
    private static final long serialVersionUID = 1L;
    
    public ParseErrorException(String message)
    {
      super();
    }
  }
}

/* Location:
 * Qualified Name:     org.sonar.plugins.ndepend.NDependReportParser
 * Java Class Version: 7 (51.0)
 * JD-Core Version:    0.7.1
 */
package org.sonar.plugins.ndepend;

public abstract interface NDependReportParserCallback
{
  public abstract void onIssue(String paramString1, String paramString2, int paramInt);
}

/* Location:
 * Qualified Name:     org.sonar.plugins.ndepend.NDependReportParserCallback
 * Java Class Version: 7 (51.0)
 * JD-Core Version:    0.7.1
 */
package org.sonar.plugins.ndepend;

import com.google.common.base.Throwables;
import com.google.common.io.Closeables;
import java.io.StringReader;
import javax.annotation.Nullable;
import javax.xml.stream.Location;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import org.sonar.api.server.rule.RulesDefinition.NewRepository;
import org.sonar.api.server.rule.RulesDefinition.NewRule;

class NDependRulesDefinition$NDependRulesParser
{
  private final RulesDefinition.NewRepository repository;
  private XMLStreamReader stream;
  
  public NDependRulesDefinition$NDependRulesParser(RulesDefinition.NewRepository repository)
  {
    this.repository = repository;
  }
  
  public void parse(String xml)
  {
    StringReader reader = null;
    XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
    try
    {
      reader = new StringReader(xml);
      stream = xmlFactory.createXMLStreamReader(reader);
      while (stream.hasNext()) {
        if (stream.next() == 1)
        {
          String tagName = stream.getLocalName();
          if ("Rule".equals(tagName)) {
            handleRuleTag();
          }
        }
      }
    }
    catch (XMLStreamException e)
    {
      throw Throwables.propagate(e);
    }
    finally
    {
      closeXmlStream();
      Closeables.closeQuietly(reader);
    }
  }
  
  private void closeXmlStream()
  {
    if (stream != null) {
      try
      {
        stream.close();
      }
      catch (XMLStreamException e)
      {
        throw Throwables.propagate(e);
      }
    }
  }
  
  private void handleRuleTag()
    throws XMLStreamException
  {
    String key = getRequiredAttribute("Key");
    String priority = getRequiredAttribute("Priority");
    String category = getAttribute("Category");
    String name = null;
    String description = null;
    while (stream.hasNext())
    {
      int next = stream.next();
      if ((next == 2) && ("Rule".equals(stream.getLocalName())))
      {
        if (name == null) {
          throw parseError("Missing rule name");
        }
        if (description == null) {
          throw parseError("Missing rule description");
        }
        RulesDefinition.NewRule rule = repository.createRule(key).setName(name).setSeverity(priority).setHtmlDescription(description);
        if (category == null) {
          break;
        }
        rule.addTags(new String[] { category }); break;
      }
      if (next == 1)
      {
        String tagName = stream.getLocalName();
        if ("Name".equals(tagName)) {
          name = stream.getElementText();
        } else if ("Description".equals(tagName)) {
          description = stream.getElementText();
        }
      }
    }
  }
  
  public String getRequiredAttribute(String name)
  {
    String value = getAttribute(name);
    if (value == null) {
      throw parseError("Missing attribute \"" + name + "\" in element <" + stream.getLocalName() + ">");
    }
    return value;
  }
  
  @Nullable
  public String getAttribute(String name)
  {
    for (int i = 0; i < stream.getAttributeCount(); i++) {
      if (name.equals(stream.getAttributeLocalName(i))) {
        return stream.getAttributeValue(i);
      }
    }
    return null;
  }
  
  public NDependRulesDefinition.ParseErrorException parseError(String message)
  {
    return new NDependRulesDefinition.ParseErrorException(message + " at line " + stream.getLocation().getLineNumber());
  }
}

/* Location:
 * Qualified Name:     org.sonar.plugins.ndepend.NDependRulesDefinition.NDependRulesParser
 * Java Class Version: 7 (51.0)
 * JD-Core Version:    0.7.1
 */
package org.sonar.plugins.ndepend;

class NDependRulesDefinition$ParseErrorException
  extends RuntimeException
{
  private static final long serialVersionUID = 1L;
  
  public NDependRulesDefinition$ParseErrorException(String message)
  {
    super(message);
  }
}

/* Location:
 * Qualified Name:     org.sonar.plugins.ndepend.NDependRulesDefinition.ParseErrorException
 * Java Class Version: 7 (51.0)
 * JD-Core Version:    0.7.1
 */
package org.sonar.plugins.ndepend;

import com.google.common.base.Throwables;
import com.google.common.io.Closeables;
import java.io.StringReader;
import javax.annotation.Nullable;
import javax.xml.stream.Location;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.api.server.rule.RulesDefinition.Context;
import org.sonar.api.server.rule.RulesDefinition.NewRepository;
import org.sonar.api.server.rule.RulesDefinition.NewRule;

public class NDependRulesDefinition
  implements RulesDefinition
{
  private static final Logger LOG = LoggerFactory.getLogger(NDependRulesDefinition.class);
  private final NDependConfiguration conf;
  
  public NDependRulesDefinition(NDependConfiguration conf)
  {
    this.conf = conf;
  }
  
  public void define(RulesDefinition.Context context)
  {
    RulesDefinition.NewRepository repository = context.createRepository("ndepend", "cs").setName("NDepend");
    
    String xml = conf.rules();
    if (xml.isEmpty()) {
      LOG.warn("No NDepend rules defined.");
    } else {
      try
      {
        new NDependRulesParser(repository).parse(xml);
      }
      catch (Exception e)
      {
        LOG.error("Error while creating the NDepend rule repository: " + e.getMessage(), e);
      }
    }
    repository.done();
  }
  
  private static class NDependRulesParser
  {
    private final RulesDefinition.NewRepository repository;
    private XMLStreamReader stream;
    
    public NDependRulesParser(RulesDefinition.NewRepository repository)
    {
      this.repository = repository;
    }
    
    public void parse(String xml)
    {
      StringReader reader = null;
      XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
      try
      {
        reader = new StringReader(xml);
        stream = xmlFactory.createXMLStreamReader(reader);
        while (stream.hasNext()) {
          if (stream.next() == 1)
          {
            String tagName = stream.getLocalName();
            if ("Rule".equals(tagName)) {
              handleRuleTag();
            }
          }
        }
      }
      catch (XMLStreamException e)
      {
        throw Throwables.propagate(e);
      }
      finally
      {
        closeXmlStream();
        Closeables.closeQuietly(reader);
      }
    }
    
    private void closeXmlStream()
    {
      if (stream != null) {
        try
        {
          stream.close();
        }
        catch (XMLStreamException e)
        {
          throw Throwables.propagate(e);
        }
      }
    }
    
    private void handleRuleTag()
      throws XMLStreamException
    {
      String key = getRequiredAttribute("Key");
      String priority = getRequiredAttribute("Priority");
      String category = getAttribute("Category");
      String name = null;
      String description = null;
      while (stream.hasNext())
      {
        int next = stream.next();
        if ((next == 2) && ("Rule".equals(stream.getLocalName())))
        {
          if (name == null) {
            throw parseError("Missing rule name");
          }
          if (description == null) {
            throw parseError("Missing rule description");
          }
          RulesDefinition.NewRule rule = repository.createRule(key).setName(name).setSeverity(priority).setHtmlDescription(description);
          if (category == null) {
            break;
          }
          rule.addTags(new String[] { category }); break;
        }
        if (next == 1)
        {
          String tagName = stream.getLocalName();
          if ("Name".equals(tagName)) {
            name = stream.getElementText();
          } else if ("Description".equals(tagName)) {
            description = stream.getElementText();
          }
        }
      }
    }
    
    public String getRequiredAttribute(String name)
    {
      String value = getAttribute(name);
      if (value == null) {
        throw parseError("Missing attribute \"" + name + "\" in element <" + stream.getLocalName() + ">");
      }
      return value;
    }
    
    @Nullable
    public String getAttribute(String name)
    {
      for (int i = 0; i < stream.getAttributeCount(); i++) {
        if (name.equals(stream.getAttributeLocalName(i))) {
          return stream.getAttributeValue(i);
        }
      }
      return null;
    }
    
    public NDependRulesDefinition.ParseErrorException parseError(String message)
    {
      return new NDependRulesDefinition.ParseErrorException(message + " at line " + stream.getLocation().getLineNumber());
    }
  }
  
  private static class ParseErrorException
    extends RuntimeException
  {
    private static final long serialVersionUID = 1L;
    
    public ParseErrorException(String message)
    {
      super();
    }
  }
}

/* Location:
 * Qualified Name:     org.sonar.plugins.ndepend.NDependRulesDefinition
 * Java Class Version: 7 (51.0)
 * JD-Core Version:    0.7.1
 */
package org.sonar.plugins.ndepend;

import org.slf4j.Logger;
import org.sonar.api.batch.fs.FilePredicates;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputFile.Type;
import org.sonar.api.component.ResourcePerspectives;
import org.sonar.api.issue.Issuable;
import org.sonar.api.issue.Issuable.IssueBuilder;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.ActiveRule;
import org.sonar.api.rules.Rule;

class NDependSensor$1
  implements NDependReportParserCallback
{
  NDependSensor$1(NDependSensor paramNDependSensor) {}
  
  public void onIssue(String ruleKey, String file, int line)
  {
    ActiveRule rule = NDependSensor.access$000(this$0).getActiveRule("ndepend", ruleKey);
    if (rule == null)
    {
      logSkippedIssue("the rule is disabled in the current quality profile", ruleKey, file, line);
      return;
    }
    InputFile inputFile = NDependSensor.access$100(this$0).inputFile(NDependSensor.access$100(this$0).predicates().and(NDependSensor.access$100(this$0).predicates().hasAbsolutePath(file), NDependSensor.access$100(this$0).predicates().hasType(InputFile.Type.MAIN)));
    if (inputFile == null)
    {
      logSkippedIssue("the file is not imported in SonarQube", ruleKey, file, line);
      return;
    }
    Issuable issuable = (Issuable)NDependSensor.access$200(this$0).as(Issuable.class, inputFile);
    if (issuable == null)
    {
      logSkippedIssue("no issuable has been found for the file", ruleKey, file, line);
      return;
    }
    Issuable.IssueBuilder builder = issuable.newIssueBuilder();
    builder.ruleKey(RuleKey.of("ndepend", ruleKey));
    builder.line(Integer.valueOf(line));
    builder.message(rule.getRule().getName());
    
    issuable.addIssue(builder.build());
  }
  
  private void logSkippedIssue(String reason, String ruleKey, String file, int line)
  {
    NDependSensor.access$300().debug("Skipping NDepend issue on file " + file + " at line " + line + " on rule " + ruleKey + " because " + reason);
  }
}

/* Location:
 * Qualified Name:     org.sonar.plugins.ndepend.NDependSensor.1
 * Java Class Version: 7 (51.0)
 * JD-Core Version:    0.7.1
 */
package org.sonar.plugins.ndepend;

import com.google.common.annotations.VisibleForTesting;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.batch.fs.FilePredicates;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputFile.Type;
import org.sonar.api.component.ResourcePerspectives;
import org.sonar.api.issue.Issuable;
import org.sonar.api.issue.Issuable.IssueBuilder;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Project;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.ActiveRule;
import org.sonar.api.rules.Rule;

public class NDependSensor
  implements Sensor
{
  private static final Logger LOG = LoggerFactory.getLogger(NDependSensor.class);
  private final NDependConfiguration conf;
  private final FileSystem fs;
  private final RulesProfile profile;
  private final ResourcePerspectives perspectives;
  
  public NDependSensor(NDependConfiguration conf, FileSystem fs, RulesProfile profile, ResourcePerspectives perspectives)
  {
    this.conf = conf;
    this.fs = fs;
    this.profile = profile;
    this.perspectives = perspectives;
  }
  
  public boolean shouldExecuteOnProject(Project project)
  {
    boolean shouldExecute;
    boolean shouldExecute;
    if (!hasFilesToAnalyze())
    {
      shouldExecute = false;
    }
    else
    {
      boolean shouldExecute;
      if (profile.getActiveRulesByRepository("ndepend").isEmpty())
      {
        LOG.info("All NDepend rules are disabled, skipping its execution.");
        shouldExecute = false;
      }
      else
      {
        shouldExecute = true;
      }
    }
    return shouldExecute;
  }
  
  private boolean hasFilesToAnalyze()
  {
    return fs.files(fs.predicates().hasLanguage("cs")).iterator().hasNext();
  }
  
  public void analyse(Project project, SensorContext context)
  {
    analyze(context, new NDependExecutor());
  }
  
  @VisibleForTesting
  void analyze(SensorContext context, NDependExecutor executor)
  {
    File reportFile = new File(fs.workDir(), "ndepend-report.xml");
    executor.execute(conf.ruleRunnerPath(), conf.ndependProjectPath(), reportFile, conf.timeout());
    
    new NDependReportParser(new NDependReportParserCallback()
    {
      public void onIssue(String ruleKey, String file, int line)
      {
        ActiveRule rule = profile.getActiveRule("ndepend", ruleKey);
        if (rule == null)
        {
          logSkippedIssue("the rule is disabled in the current quality profile", ruleKey, file, line);
          return;
        }
        InputFile inputFile = fs.inputFile(fs.predicates().and(fs.predicates().hasAbsolutePath(file), fs.predicates().hasType(InputFile.Type.MAIN)));
        if (inputFile == null)
        {
          logSkippedIssue("the file is not imported in SonarQube", ruleKey, file, line);
          return;
        }
        Issuable issuable = (Issuable)perspectives.as(Issuable.class, inputFile);
        if (issuable == null)
        {
          logSkippedIssue("no issuable has been found for the file", ruleKey, file, line);
          return;
        }
        Issuable.IssueBuilder builder = issuable.newIssueBuilder();
        builder.ruleKey(RuleKey.of("ndepend", ruleKey));
        builder.line(Integer.valueOf(line));
        builder.message(rule.getRule().getName());
        
        issuable.addIssue(builder.build());
      }
      
      private void logSkippedIssue(String reason, String ruleKey, String file, int line)
      {
        NDependSensor.LOG.debug("Skipping NDepend issue on file " + file + " at line " + line + " on rule " + ruleKey + " because " + reason);
      }
    }).parse(reportFile);
  }
}

/* Location:
 * Qualified Name:     org.sonar.plugins.ndepend.NDependSensor
 * Java Class Version: 7 (51.0)
 * JD-Core Version:    0.7.1
 */
package org.sonar.plugins.ndepend;

import javax.annotation.ParametersAreNonnullByDefault;

@ParametersAreNonnullByDefault
abstract interface package-info {}

/* Location:
 * Qualified Name:     org.sonar.plugins.ndepend.package-info
 * Java Class Version: 7 (51.0)
 * JD-Core Version:    0.7.1
 */
1

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd