parent
5d6f5888d2
commit
56b0ccda79
@ -0,0 +1,4 @@
|
|||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
target
|
@ -0,0 +1,168 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
||||||
|
http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<name>deors.plugins.sonarqube.idemetadata</name>
|
||||||
|
<groupId>deors.plugins</groupId>
|
||||||
|
<artifactId>deors.plugins.sonarqube.idemetadata</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
<packaging>sonar-plugin</packaging>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<sonarqube.version>5.1</sonarqube.version>
|
||||||
|
<json.version>1.0</json.version>
|
||||||
|
<slf4j.version>1.7.5</slf4j.version>
|
||||||
|
<log4j.version>1.2.16</log4j.version>
|
||||||
|
<xstream.version>1.4.3</xstream.version>
|
||||||
|
|
||||||
|
<junit.version>4.12</junit.version>
|
||||||
|
|
||||||
|
<jacoco.version>0.7.5.201505241946</jacoco.version>
|
||||||
|
<jacoco.path>${settings.localRepository}/org/jacoco/org.jacoco.agent/${jacoco.version}/org.jacoco.agent-${jacoco.version}-runtime.jar</jacoco.path>
|
||||||
|
<jacoco.utReport>${project.build.directory}/jacoco.exec</jacoco.utReport>
|
||||||
|
<jacoco.itReport>${project.build.directory}/jacoco.itest</jacoco.itReport>
|
||||||
|
<jacoco.utAgentConfig>-javaagent:${jacoco.path}=destfile=${jacoco.utReport}</jacoco.utAgentConfig>
|
||||||
|
<jacoco.itAgentConfig>-javaagent:${jacoco.path}=destfile=${jacoco.itReport}</jacoco.itAgentConfig>
|
||||||
|
|
||||||
|
<jacoco-listeners.version>3.5</jacoco-listeners.version>
|
||||||
|
|
||||||
|
<sonar.jacoco.itReportPath>${jacoco.itReport}</sonar.jacoco.itReportPath>
|
||||||
|
<sonar.squid.analyse.property.accessors>false</sonar.squid.analyse.property.accessors>
|
||||||
|
<sonar.findbugs.excludesFilters>${project.basedir}/findbugs-filter.xml</sonar.findbugs.excludesFilters>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.3</version>
|
||||||
|
<configuration>
|
||||||
|
<source>${java.version}</source>
|
||||||
|
<target>${java.version}</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.18.1</version>
|
||||||
|
<configuration>
|
||||||
|
<argLine>${jacoco.utAgentConfig}</argLine>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/it/*TestCase.java</exclude>
|
||||||
|
</excludes>
|
||||||
|
<properties>
|
||||||
|
<property>
|
||||||
|
<name>listener</name>
|
||||||
|
<value>org.sonar.java.jacoco.JUnitListener</value>
|
||||||
|
</property>
|
||||||
|
</properties>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-failsafe-plugin</artifactId>
|
||||||
|
<version>2.18.1</version>
|
||||||
|
<configuration>
|
||||||
|
<argLine>${jacoco.itAgentConfig}</argLine>
|
||||||
|
<includes>
|
||||||
|
<include>**/it/*TestCase.java</include>
|
||||||
|
</includes>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>integration-test</id>
|
||||||
|
<phase>integration-test</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>integration-test</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.sonar</groupId>
|
||||||
|
<artifactId>sonar-packaging-maven-plugin</artifactId>
|
||||||
|
<version>1.13</version>
|
||||||
|
<extensions>true</extensions>
|
||||||
|
<configuration>
|
||||||
|
<pluginKey>idemetadata</pluginKey>
|
||||||
|
<pluginClass>deors.plugins.sonarqube.idemetadata.IDEMetadataPlugin</pluginClass>
|
||||||
|
<pluginName>SonarQube IDE Metadata plugin</pluginName>
|
||||||
|
<pluginDescription>Gathers and displays information from IDE metadata files, including project type (based on natures/facets) and dependencies.</pluginDescription>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.sonar</groupId>
|
||||||
|
<artifactId>sonar-plugin-api</artifactId>
|
||||||
|
<version>${sonarqube.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish</groupId>
|
||||||
|
<artifactId>javax.json</artifactId>
|
||||||
|
<version>${json.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<version>${slf4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>log4j</groupId>
|
||||||
|
<artifactId>log4j</artifactId>
|
||||||
|
<version>${log4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-log4j12</artifactId>
|
||||||
|
<version>${slf4j.version}</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- <dependency>
|
||||||
|
<groupId>com.thoughtworks.xstream</groupId>
|
||||||
|
<artifactId>xstream</artifactId>
|
||||||
|
<version>${xstream.version}</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency> -->
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.sonar</groupId>
|
||||||
|
<artifactId>sonar-testing-harness</artifactId>
|
||||||
|
<version>${sonarqube.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>${junit.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jacoco</groupId>
|
||||||
|
<artifactId>org.jacoco.agent</artifactId>
|
||||||
|
<version>${jacoco.version}</version>
|
||||||
|
<classifier>runtime</classifier>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.sonarsource.java</groupId>
|
||||||
|
<artifactId>sonar-jacoco-listeners</artifactId>
|
||||||
|
<version>${jacoco-listeners.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,28 @@
|
|||||||
|
deors.plugins.sonarqube.idemetadata
|
||||||
|
===================================
|
||||||
|
|
||||||
|
SonarQube IDE Metadata plugin gathers and displays information from IDE metadata files,
|
||||||
|
including project type (based on natures/facets) and dependencies.
|
||||||
|
|
||||||
|
Introduction
|
||||||
|
------------
|
||||||
|
|
||||||
|
This is an example of a simple SonarQube plug-in that declares a few metrics at the
|
||||||
|
project level containing information extracted from IDE Metadata configuration files
|
||||||
|
(currently only Eclipse IDE is supported but other extractors can be easily created).
|
||||||
|
|
||||||
|
To install this plug-in, follow these steps:
|
||||||
|
|
||||||
|
A) Create the plug-in binary with this command:
|
||||||
|
|
||||||
|
mvn clean package
|
||||||
|
|
||||||
|
B) Copy the file to your SonarQube installation:
|
||||||
|
|
||||||
|
copy target/deors.plugins.sonarqube.idemetadata-1.0.jar $SONARQUBE_HOME/extensions/plugins
|
||||||
|
|
||||||
|
C) Restart SonarQube
|
||||||
|
|
||||||
|
D) Add the widget to a dashboard
|
||||||
|
|
||||||
|
E) Analyse a project and enjoy!
|
@ -0,0 +1,57 @@
|
|||||||
|
package deors.plugins.sonarqube.idemetadata;
|
||||||
|
|
||||||
|
import org.sonar.api.web.AbstractRubyTemplate;
|
||||||
|
import org.sonar.api.web.Description;
|
||||||
|
import org.sonar.api.web.RubyRailsWidget;
|
||||||
|
import org.sonar.api.web.UserRole;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IDE Metadata plugin widget definition.
|
||||||
|
*
|
||||||
|
* @author jorge.hidalgo
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
@UserRole(UserRole.USER)
|
||||||
|
@Description("Shows IDE metadata configuration for the project, including project type, language support and configured frameworks")
|
||||||
|
public class IDEMetadataDashboardWidget
|
||||||
|
extends AbstractRubyTemplate
|
||||||
|
implements RubyRailsWidget {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
public IDEMetadataDashboardWidget() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the widget id.
|
||||||
|
*
|
||||||
|
* @return the widget id
|
||||||
|
*/
|
||||||
|
public String getId() {
|
||||||
|
return "idemetadata";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the widget title.
|
||||||
|
*
|
||||||
|
* @return the widget title
|
||||||
|
*/
|
||||||
|
public String getTitle() {
|
||||||
|
return "IDE Metadata";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the path to the widget Ruby file.
|
||||||
|
*
|
||||||
|
* @return the path to the widget Ruby file
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected String getTemplatePath() {
|
||||||
|
String templatePath = "/deors/plugins/sonarqube/idemetadata/idemetadata_widget.html.erb";
|
||||||
|
// uncomment next line to enable change reloading during development
|
||||||
|
//templatePath = "c:/projects/deors.plugins/deors.plugins.sonarqube.idemetadata/src/main/resources" + templatePath;
|
||||||
|
return templatePath;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,257 @@
|
|||||||
|
package deors.plugins.sonarqube.idemetadata;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.sonar.api.measures.CoreMetrics;
|
||||||
|
import org.sonar.api.measures.Metric;
|
||||||
|
import org.sonar.api.measures.Metrics;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IDE Metadata plugin metrics definition.
|
||||||
|
*
|
||||||
|
* @author jorge.hidalgo
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
public class IDEMetadataMetrics implements Metrics {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The project name (as configured in the IDE).
|
||||||
|
*/
|
||||||
|
public static final Metric IDE_PRJ_NAME =
|
||||||
|
new Metric.Builder(
|
||||||
|
"ide_prj_name",
|
||||||
|
"Project name in IDE",
|
||||||
|
Metric.ValueType.STRING)
|
||||||
|
.setDescription("The project name (as configured in the IDE)")
|
||||||
|
.setQualitative(false)
|
||||||
|
.setDomain(CoreMetrics.DOMAIN_GENERAL)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the project is configured as Java in the IDE.
|
||||||
|
*/
|
||||||
|
public static final Metric IDE_IS_JAVA =
|
||||||
|
new Metric.Builder(
|
||||||
|
"ide_is_java",
|
||||||
|
"Java project",
|
||||||
|
Metric.ValueType.BOOL)
|
||||||
|
.setDescription("Whether the project is configured as Java in the IDE")
|
||||||
|
.setQualitative(false)
|
||||||
|
.setDomain(CoreMetrics.DOMAIN_GENERAL)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the project is configured as EAR in the IDE.
|
||||||
|
*/
|
||||||
|
public static final Metric IDE_IS_EAR =
|
||||||
|
new Metric.Builder(
|
||||||
|
"ide_is_ear",
|
||||||
|
"Enterprise Application project",
|
||||||
|
Metric.ValueType.BOOL)
|
||||||
|
.setDescription("Whether the project is configured as EAR in the IDE")
|
||||||
|
.setQualitative(false)
|
||||||
|
.setDomain(CoreMetrics.DOMAIN_GENERAL)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the project is configured as EJB in the IDE.
|
||||||
|
*/
|
||||||
|
public static final Metric IDE_IS_EJB =
|
||||||
|
new Metric.Builder(
|
||||||
|
"ide_is_ejb",
|
||||||
|
"Enterprise JavaBeans project",
|
||||||
|
Metric.ValueType.BOOL)
|
||||||
|
.setDescription("Whether the project is configured as EJB in the IDE")
|
||||||
|
.setQualitative(false)
|
||||||
|
.setDomain(CoreMetrics.DOMAIN_GENERAL)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the project is configured as Web in the IDE.
|
||||||
|
*/
|
||||||
|
public static final Metric IDE_IS_WEB =
|
||||||
|
new Metric.Builder(
|
||||||
|
"ide_is_web",
|
||||||
|
"Web Application project",
|
||||||
|
Metric.ValueType.BOOL)
|
||||||
|
.setDescription("Whether the project is configured as Web in the IDE")
|
||||||
|
.setQualitative(false)
|
||||||
|
.setDomain(CoreMetrics.DOMAIN_GENERAL)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the project is configured as GWT in the IDE.
|
||||||
|
*/
|
||||||
|
public static final Metric IDE_IS_GWT =
|
||||||
|
new Metric.Builder(
|
||||||
|
"ide_is_gwt",
|
||||||
|
"Google Web Toolkit project",
|
||||||
|
Metric.ValueType.BOOL)
|
||||||
|
.setDescription("Whether the project is configured as GWT in the IDE")
|
||||||
|
.setQualitative(false)
|
||||||
|
.setDomain(CoreMetrics.DOMAIN_GENERAL)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the project is configured as GAE in the IDE.
|
||||||
|
*/
|
||||||
|
public static final Metric IDE_IS_GAE =
|
||||||
|
new Metric.Builder(
|
||||||
|
"ide_is_gae",
|
||||||
|
"Google App Engine project",
|
||||||
|
Metric.ValueType.BOOL)
|
||||||
|
.setDescription("Whether the project is configured as GAE in the IDE")
|
||||||
|
.setQualitative(false)
|
||||||
|
.setDomain(CoreMetrics.DOMAIN_GENERAL)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the project is configured as Groovy in the IDE.
|
||||||
|
*/
|
||||||
|
public static final Metric IDE_IS_GROOVY =
|
||||||
|
new Metric.Builder(
|
||||||
|
"ide_is_groovy",
|
||||||
|
"Groovy project",
|
||||||
|
Metric.ValueType.BOOL)
|
||||||
|
.setDescription("Whether the project is configured as Groovy in the IDE")
|
||||||
|
.setQualitative(false)
|
||||||
|
.setDomain(CoreMetrics.DOMAIN_GENERAL)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the project is configured as Grails in the IDE.
|
||||||
|
*/
|
||||||
|
public static final Metric IDE_IS_GRAILS =
|
||||||
|
new Metric.Builder(
|
||||||
|
"ide_is_grails",
|
||||||
|
"Grails project",
|
||||||
|
Metric.ValueType.BOOL)
|
||||||
|
.setDescription("Whether the project is configured as Grails in the IDE")
|
||||||
|
.setQualitative(false)
|
||||||
|
.setDomain(CoreMetrics.DOMAIN_GENERAL)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the project is configured as PDE in the IDE.
|
||||||
|
*/
|
||||||
|
public static final Metric IDE_IS_PDE =
|
||||||
|
new Metric.Builder(
|
||||||
|
"ide_is_pde",
|
||||||
|
"Eclipse Plugin Development project",
|
||||||
|
Metric.ValueType.BOOL)
|
||||||
|
.setDescription("Whether the project is configured as PDE in the IDE")
|
||||||
|
.setQualitative(false)
|
||||||
|
.setDomain(CoreMetrics.DOMAIN_GENERAL)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the project is configured as JET in the IDE.
|
||||||
|
*/
|
||||||
|
public static final Metric IDE_IS_JET =
|
||||||
|
new Metric.Builder(
|
||||||
|
"ide_is_jet",
|
||||||
|
"Java Emitter Templates project",
|
||||||
|
Metric.ValueType.BOOL)
|
||||||
|
.setDescription("Whether the project is configured as JET in the IDE")
|
||||||
|
.setQualitative(false)
|
||||||
|
.setDomain(CoreMetrics.DOMAIN_GENERAL)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The list of declared dependencies for the project.
|
||||||
|
*/
|
||||||
|
public static final Metric IDE_DEPENDENCIES =
|
||||||
|
new Metric.Builder(
|
||||||
|
"ide_dependencies",
|
||||||
|
"List of declared dependencies",
|
||||||
|
Metric.ValueType.STRING)
|
||||||
|
.setDescription("The list of declared dependencies for the project")
|
||||||
|
.setQualitative(false)
|
||||||
|
.setDomain(CoreMetrics.DOMAIN_GENERAL)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The list of configured classpath entries for the project.
|
||||||
|
*/
|
||||||
|
public static final Metric IDE_CLASSPATH =
|
||||||
|
new Metric.Builder(
|
||||||
|
"ide_classpath",
|
||||||
|
"List of configured classpath entries",
|
||||||
|
Metric.ValueType.STRING)
|
||||||
|
.setDescription("The list of configured classpath entries for the project")
|
||||||
|
.setQualitative(false)
|
||||||
|
.setDomain(CoreMetrics.DOMAIN_GENERAL)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
/*add code for our project*/
|
||||||
|
|
||||||
|
public static final Metric IDE_FILE_NUMBER =
|
||||||
|
new Metric.Builder(
|
||||||
|
"ide_classpath",
|
||||||
|
"Number of project files",
|
||||||
|
Metric.ValueType.STRING)
|
||||||
|
.setDescription("Number of project files")
|
||||||
|
.setQualitative(false)
|
||||||
|
.setDomain(CoreMetrics.DOMAIN_GENERAL)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
public static final Metric IDE_CLASS_NUMBER =
|
||||||
|
new Metric.Builder(
|
||||||
|
"ide_classpath",
|
||||||
|
"Number of classes that is created in the project",
|
||||||
|
Metric.ValueType.STRING)
|
||||||
|
.setDescription("Number of classes that is created in the project")
|
||||||
|
.setQualitative(false)
|
||||||
|
.setDomain(CoreMetrics.DOMAIN_GENERAL)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
public static final Metric WA_IS_NAMEPBM =
|
||||||
|
new Metric.Builder(
|
||||||
|
"ide_classpath",
|
||||||
|
"List of problem that named badly",
|
||||||
|
Metric.ValueType.STRING)
|
||||||
|
.setDescription("List of problem that named badly for the showed information")
|
||||||
|
.setQualitative(false)
|
||||||
|
.setDomain(CoreMetrics.DOMAIN_GENERAL)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
public static final Metric WA_IS_COMMENTARY =
|
||||||
|
new Metric.Builder(
|
||||||
|
"ide_classpath",
|
||||||
|
"Problem caused by less or too much commentary of code",
|
||||||
|
Metric.ValueType.STRING)
|
||||||
|
.setDescription("Problem caused by less or too much commentary of code for the showed information")
|
||||||
|
.setQualitative(false)
|
||||||
|
.setDomain(CoreMetrics.DOMAIN_GENERAL)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
public static final Metric WA_IS_THREAT =
|
||||||
|
new Metric.Builder(
|
||||||
|
"ide_classpath",
|
||||||
|
"Potential threat caused by Bad programming style",
|
||||||
|
Metric.ValueType.STRING)
|
||||||
|
.setDescription("Problem caused by less or too much commentary of code for the showed information")
|
||||||
|
.setQualitative(false)
|
||||||
|
.setDomain(CoreMetrics.DOMAIN_GENERAL)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
public IDEMetadataMetrics() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the plugin metrics.
|
||||||
|
*
|
||||||
|
* @return the list of this plugin metrics
|
||||||
|
*/
|
||||||
|
public List<Metric> getMetrics() {
|
||||||
|
return Arrays.asList(
|
||||||
|
IDE_PRJ_NAME, IDE_IS_JAVA, IDE_IS_EAR, IDE_IS_EJB, IDE_IS_WEB,
|
||||||
|
IDE_IS_GWT, IDE_IS_GAE, IDE_IS_GROOVY, IDE_IS_GRAILS,
|
||||||
|
IDE_IS_PDE, IDE_IS_JET, IDE_DEPENDENCIES, IDE_CLASSPATH);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package deors.plugins.sonarqube.idemetadata;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.sonar.api.Extension;
|
||||||
|
import org.sonar.api.SonarPlugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IDE Metadata plugin definition.
|
||||||
|
*
|
||||||
|
* @author jorge.hidalgo
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
public class IDEMetadataPlugin extends SonarPlugin {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
public IDEMetadataPlugin() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the plugin extensions: metrics, sensor and dashboard widget.
|
||||||
|
*
|
||||||
|
* @return the list of extensions for this plugin
|
||||||
|
*/
|
||||||
|
public List<Class<? extends Extension>> getExtensions() {
|
||||||
|
return Arrays.asList(
|
||||||
|
IDEMetadataMetrics.class,
|
||||||
|
IDEMetadataSensor.class,
|
||||||
|
IDEMetadataDashboardWidget.class);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,176 @@
|
|||||||
|
package deors.plugins.sonarqube.idemetadata;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
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.FileSystem;
|
||||||
|
import org.sonar.api.measures.Measure;
|
||||||
|
import org.sonar.api.resources.Project;
|
||||||
|
|
||||||
|
import deors.plugins.sonarqube.idemetadata.analyzers.AnalyzerException;
|
||||||
|
import deors.plugins.sonarqube.idemetadata.analyzers.EclipseAnalyzer;
|
||||||
|
import deors.plugins.sonarqube.idemetadata.model.ProjectInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IDE Metadata plugin sensor. It analyses project directory in search for
|
||||||
|
* IDE metadata configuration files and extracts relevant information.
|
||||||
|
*
|
||||||
|
* @author jorge.hidalgo
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
public class IDEMetadataSensor implements Sensor {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The file system object for the project being analysed.
|
||||||
|
*/
|
||||||
|
private final FileSystem fileSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The logger object for the sensor.
|
||||||
|
*/
|
||||||
|
private final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that sets the file system object for the
|
||||||
|
* project being analysed.
|
||||||
|
*
|
||||||
|
* @param fileSystem the project file system
|
||||||
|
*/
|
||||||
|
public IDEMetadataSensor(FileSystem fileSystem) {
|
||||||
|
this.fileSystem = fileSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the sensor should run or not for the given project.
|
||||||
|
*
|
||||||
|
* @param project the project being analysed
|
||||||
|
* @return always true
|
||||||
|
*/
|
||||||
|
public boolean shouldExecuteOnProject(Project project) {
|
||||||
|
// this sensor is executed on any type of project
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Analyses project directory in search for IDE metadata configuration files
|
||||||
|
* and extracts relevant information.
|
||||||
|
*
|
||||||
|
* @param project the project being analysed
|
||||||
|
* @param sensorContext the sensor context
|
||||||
|
*/
|
||||||
|
public void analyse(Project project, SensorContext sensorContext) {
|
||||||
|
|
||||||
|
File rootDir = fileSystem.baseDir();
|
||||||
|
|
||||||
|
log.info("Analysing project root in search for IDE Metadata files: " + rootDir.getAbsolutePath());
|
||||||
|
|
||||||
|
EclipseAnalyzer analyzer = new EclipseAnalyzer(rootDir);
|
||||||
|
ProjectInfo projectInfo;
|
||||||
|
|
||||||
|
try {
|
||||||
|
projectInfo = analyzer.analyze();
|
||||||
|
|
||||||
|
log.info("Analysis done");
|
||||||
|
log.debug("this is what we've found: " + projectInfo);
|
||||||
|
|
||||||
|
saveMainInfo(sensorContext, projectInfo);
|
||||||
|
saveDependencies(sensorContext, projectInfo);
|
||||||
|
saveClasspath(sensorContext, projectInfo);
|
||||||
|
|
||||||
|
} catch (AnalyzerException ae) {
|
||||||
|
log.error("Error while running EclipseAnalyzer", ae);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves measures corresponding to main project information.
|
||||||
|
*
|
||||||
|
* @param sensorContext the sensor context
|
||||||
|
* @param projectInfo the project information bean
|
||||||
|
*/
|
||||||
|
private void saveMainInfo(SensorContext sensorContext, ProjectInfo projectInfo) {
|
||||||
|
|
||||||
|
log.debug("saving measures for main project information");
|
||||||
|
|
||||||
|
Measure measure;
|
||||||
|
|
||||||
|
measure = new Measure(IDEMetadataMetrics.IDE_PRJ_NAME, projectInfo.getProjectName());
|
||||||
|
sensorContext.saveMeasure(measure);
|
||||||
|
|
||||||
|
measure = new Measure(IDEMetadataMetrics.IDE_IS_JAVA, projectInfo.isJavaProject() ? 1d : 0d);
|
||||||
|
sensorContext.saveMeasure(measure);
|
||||||
|
|
||||||
|
measure = new Measure(IDEMetadataMetrics.IDE_IS_EAR, projectInfo.isEarProject() ? 1d : 0d);
|
||||||
|
sensorContext.saveMeasure(measure);
|
||||||
|
|
||||||
|
measure = new Measure(IDEMetadataMetrics.IDE_IS_EJB, projectInfo.isEjbProject() ? 1d : 0d);
|
||||||
|
sensorContext.saveMeasure(measure);
|
||||||
|
|
||||||
|
measure = new Measure(IDEMetadataMetrics.IDE_IS_WEB, projectInfo.isWebProject() ? 1d : 0d);
|
||||||
|
sensorContext.saveMeasure(measure);
|
||||||
|
|
||||||
|
measure = new Measure(IDEMetadataMetrics.IDE_IS_GWT, projectInfo.isGwtProject() ? 1d : 0d);
|
||||||
|
sensorContext.saveMeasure(measure);
|
||||||
|
|
||||||
|
measure = new Measure(IDEMetadataMetrics.IDE_IS_GAE, projectInfo.isGaeProject() ? 1d : 0d);
|
||||||
|
sensorContext.saveMeasure(measure);
|
||||||
|
|
||||||
|
measure = new Measure(IDEMetadataMetrics.IDE_IS_GROOVY, projectInfo.isGroovyProject() ? 1d : 0d);
|
||||||
|
sensorContext.saveMeasure(measure);
|
||||||
|
|
||||||
|
measure = new Measure(IDEMetadataMetrics.IDE_IS_GRAILS, projectInfo.isGrailsProject() ? 1d : 0d);
|
||||||
|
sensorContext.saveMeasure(measure);
|
||||||
|
|
||||||
|
measure = new Measure(IDEMetadataMetrics.IDE_IS_PDE, projectInfo.isPdeProject() ? 1d : 0d);
|
||||||
|
sensorContext.saveMeasure(measure);
|
||||||
|
|
||||||
|
measure = new Measure(IDEMetadataMetrics.IDE_IS_JET, projectInfo.isJetProject() ? 1d : 0d);
|
||||||
|
sensorContext.saveMeasure(measure);
|
||||||
|
|
||||||
|
log.debug("measures saved");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves measures corresponding to project dependencies information.
|
||||||
|
*
|
||||||
|
* @param sensorContext the sensor context
|
||||||
|
* @param projectInfo the project information bean
|
||||||
|
*/
|
||||||
|
private void saveDependencies(SensorContext sensorContext, ProjectInfo projectInfo) {
|
||||||
|
|
||||||
|
log.debug("saving measure for project dependencies");
|
||||||
|
|
||||||
|
sensorContext.saveMeasure(new Measure(
|
||||||
|
IDEMetadataMetrics.IDE_DEPENDENCIES, projectInfo.getProjectDependencies().toString()));
|
||||||
|
|
||||||
|
log.debug("measure saved");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves measures corresponding to project classpath information.
|
||||||
|
*
|
||||||
|
* @param sensorContext the sensor context
|
||||||
|
* @param projectInfo the project information bean
|
||||||
|
*/
|
||||||
|
private void saveClasspath(SensorContext sensorContext, ProjectInfo projectInfo) {
|
||||||
|
|
||||||
|
log.debug("saving measure for project classpath");
|
||||||
|
|
||||||
|
sensorContext.saveMeasure(new Measure(
|
||||||
|
IDEMetadataMetrics.IDE_CLASSPATH, projectInfo.getProjectClasspath().toString()));
|
||||||
|
|
||||||
|
log.debug("measure saved");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of the sensor as it will be used in logs during analysis.
|
||||||
|
*
|
||||||
|
* @return the name of the sensor
|
||||||
|
*/
|
||||||
|
public String toString() {
|
||||||
|
return "IDEMetadataSensor";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
package deors.plugins.sonarqube.idemetadata.analyzers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Analyzer Exception type.
|
||||||
|
*
|
||||||
|
* @author jorge.hidalgo
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
public class AnalyzerException extends Exception {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialization id.
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = -1644223223242751568L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
public AnalyzerException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception constructor from a given message.
|
||||||
|
*
|
||||||
|
* @param message the exception message
|
||||||
|
*/
|
||||||
|
public AnalyzerException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception constructor from a given root cause.
|
||||||
|
*
|
||||||
|
* @param rootCause the exception root cause
|
||||||
|
*/
|
||||||
|
public AnalyzerException(Throwable rootCause) {
|
||||||
|
super(rootCause);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception constructor from a given message and root cause.
|
||||||
|
*
|
||||||
|
* @param message the exception message
|
||||||
|
* @param rootCause the exception root cause
|
||||||
|
*/
|
||||||
|
public AnalyzerException(String message, Throwable rootCause) {
|
||||||
|
super(message, rootCause);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,297 @@
|
|||||||
|
package deors.plugins.sonarqube.idemetadata.analyzers;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.xpath.XPath;
|
||||||
|
import javax.xml.xpath.XPathConstants;
|
||||||
|
import javax.xml.xpath.XPathExpression;
|
||||||
|
import javax.xml.xpath.XPathExpressionException;
|
||||||
|
import javax.xml.xpath.XPathFactory;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
import deors.plugins.sonarqube.idemetadata.model.ProjectInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Eclipse IDE Metadata Analyzer.
|
||||||
|
*
|
||||||
|
* This tool searches for project and classpath metadata generated by Eclipse IDE
|
||||||
|
* and derived IDE's and extracts the project basic information and dependencies.
|
||||||
|
* The tool detects Java, Web, EJB, EAR, Google Web Toolkit, Google App Engine,
|
||||||
|
* Groovy, Grails, Eclipse PDE and Eclipse JET projects.
|
||||||
|
*
|
||||||
|
* @author jorge.hidalgo
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
public class EclipseAnalyzer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The project root directory.
|
||||||
|
*/
|
||||||
|
private final File rootDir;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bean with analysis results.
|
||||||
|
*/
|
||||||
|
private ProjectInfo projectInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* XPath expression used to parse Eclipse project files.
|
||||||
|
*/
|
||||||
|
private static final String XPATH_PROJECT_NAME = "/projectDescription/name/text()"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* XPath expression used to parse Eclipse project files.
|
||||||
|
*/
|
||||||
|
private static final String XPATH_PROJECT_DEPENDENCIES = "/projectDescription/projects/project/text()"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* XPath expression used to parse Eclipse project files.
|
||||||
|
*/
|
||||||
|
private static final String XPATH_PROJECT_NATURES = "/projectDescription/natures/nature/text()"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* XPath expression used to parse Eclipse facet config files.
|
||||||
|
*/
|
||||||
|
private static final String XPATH_FACET_FIXED = "/faceted-project/fixed/@facet"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* XPath expression used to parse Eclipse facet config files.
|
||||||
|
*/
|
||||||
|
private static final String XPATH_FACET_INSTALLED = "/faceted-project/installed/@facet"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* XPath expression used to parse Eclipse classpath files.
|
||||||
|
*/
|
||||||
|
private static final String XPATH_CLASSPATH_LIB = "/classpath/classpathentry[@kind='lib']/@path"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* XPath expression used to parse Eclipse classpath files.
|
||||||
|
*/
|
||||||
|
private static final String XPATH_CLASSPATH_SRC = "/classpath/classpathentry[@kind='src']/@path"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Eclipse project file name.
|
||||||
|
*/
|
||||||
|
private static final String PROJECT_FILE = ".project"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Eclipse classpath file name.
|
||||||
|
*/
|
||||||
|
private static final String CLASSPATH_FILE = ".classpath"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The WST facet configuration file name.
|
||||||
|
*/
|
||||||
|
private static final String FACET_CONFIG_FILE = ".settings\\org.eclipse.wst.common.project.facet.core.xml"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The logger.
|
||||||
|
*/
|
||||||
|
private final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Analyzer constructor.
|
||||||
|
*
|
||||||
|
* @param rootDir the project root directory
|
||||||
|
*/
|
||||||
|
public EclipseAnalyzer(final File rootDir) {
|
||||||
|
super();
|
||||||
|
this.rootDir = rootDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Analyzes the metadata files.
|
||||||
|
*
|
||||||
|
* @return the project information extracted from metadata files
|
||||||
|
* @throws AnalyzerException any error occurred while analyzing the metadata
|
||||||
|
* files, typically a parsing error in XML files
|
||||||
|
*/
|
||||||
|
public ProjectInfo analyze()
|
||||||
|
throws AnalyzerException {
|
||||||
|
|
||||||
|
projectInfo = new ProjectInfo();
|
||||||
|
|
||||||
|
analyzeProjectFile();
|
||||||
|
analyzeFacetsFile();
|
||||||
|
analyzeClasspathFile();
|
||||||
|
|
||||||
|
return projectInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Analyzes the .project file.
|
||||||
|
*
|
||||||
|
* @throws AnalyzerException any error occurred while analyzing the metadata
|
||||||
|
* files, typically a parsing error in XML files
|
||||||
|
*/
|
||||||
|
private void analyzeProjectFile()
|
||||||
|
throws AnalyzerException {
|
||||||
|
|
||||||
|
List<String> projectDependencies = new ArrayList<>();
|
||||||
|
List<String> projectNatures = new ArrayList<>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// parses .project file
|
||||||
|
File projectFile = new File(rootDir, PROJECT_FILE);
|
||||||
|
if (!projectFile.exists()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
|
factory.setNamespaceAware(true);
|
||||||
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
|
XPathFactory xpathFactory = XPathFactory.newInstance();
|
||||||
|
XPath xpath = xpathFactory.newXPath();
|
||||||
|
|
||||||
|
Document projectDocument = builder.parse(projectFile);
|
||||||
|
|
||||||
|
// gets project name
|
||||||
|
XPathExpression xpathProjectName = xpath.compile(XPATH_PROJECT_NAME);
|
||||||
|
NodeList projectNameNodes = (NodeList) xpathProjectName.evaluate(projectDocument, XPathConstants.NODESET);
|
||||||
|
String projectName = projectNameNodes.item(0).getNodeValue();
|
||||||
|
|
||||||
|
log.debug("project name = " + projectName);
|
||||||
|
|
||||||
|
// gets project dependencies
|
||||||
|
XPathExpression xpathProjectDependencies = xpath.compile(XPATH_PROJECT_DEPENDENCIES);
|
||||||
|
NodeList projectDependenciesNodes = (NodeList) xpathProjectDependencies.evaluate(projectDocument, XPathConstants.NODESET);
|
||||||
|
for (int i = 0, n = projectDependenciesNodes.getLength(); i < n; i++) {
|
||||||
|
String supplier = projectDependenciesNodes.item(i).getNodeValue();
|
||||||
|
projectDependencies.add(supplier);
|
||||||
|
}
|
||||||
|
|
||||||
|
// gets project natures
|
||||||
|
XPathExpression xpathProjectNatures = xpath.compile(XPATH_PROJECT_NATURES);
|
||||||
|
NodeList projectNaturesNodes = (NodeList) xpathProjectNatures.evaluate(projectDocument, XPathConstants.NODESET);
|
||||||
|
for (int i = 0, n = projectNaturesNodes.getLength(); i < n; i++) {
|
||||||
|
projectNatures.add(projectNaturesNodes.item(i).getNodeValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
projectInfo.setProjectName(projectName);
|
||||||
|
projectInfo.setProjectDependencies(projectDependencies);
|
||||||
|
projectInfo.setProjectNatures(projectNatures);
|
||||||
|
|
||||||
|
} catch (ParserConfigurationException |
|
||||||
|
SAXException |
|
||||||
|
XPathExpressionException |
|
||||||
|
IOException ex) {
|
||||||
|
log.error("error parsing project file", ex);
|
||||||
|
throw new AnalyzerException("error parsing project file", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Analyzes the facet configuration file.
|
||||||
|
*
|
||||||
|
* @throws AnalyzerException any error occurred while analyzing the metadata
|
||||||
|
* files, typically a parsing error in XML files
|
||||||
|
*/
|
||||||
|
private void analyzeFacetsFile()
|
||||||
|
throws AnalyzerException {
|
||||||
|
|
||||||
|
List<String> projectFacets = new ArrayList<>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// for faceted projects, parses facet config file
|
||||||
|
File facetConfigFile = new File(rootDir, FACET_CONFIG_FILE);
|
||||||
|
if (!facetConfigFile.exists()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
|
factory.setNamespaceAware(true);
|
||||||
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
|
XPathFactory xpathFactory = XPathFactory.newInstance();
|
||||||
|
XPath xpath = xpathFactory.newXPath();
|
||||||
|
|
||||||
|
Document facetConfigDocument = builder.parse(facetConfigFile);
|
||||||
|
|
||||||
|
// get fixed facets
|
||||||
|
XPathExpression xpathFixedFacetEntry = xpath.compile(XPATH_FACET_FIXED);
|
||||||
|
NodeList fixedFacetEntryNodes = (NodeList) xpathFixedFacetEntry.evaluate(facetConfigDocument, XPathConstants.NODESET);
|
||||||
|
for (int i = 0, n = fixedFacetEntryNodes.getLength(); i < n; i++) {
|
||||||
|
projectFacets.add(fixedFacetEntryNodes.item(i).getNodeValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
// get installed facets
|
||||||
|
XPathExpression xpathInstalledFacetEntry = xpath.compile(XPATH_FACET_INSTALLED);
|
||||||
|
NodeList installedFacetEntryNodes = (NodeList) xpathInstalledFacetEntry.evaluate(facetConfigDocument, XPathConstants.NODESET);
|
||||||
|
for (int i = 0, n = installedFacetEntryNodes.getLength(); i < n; i++) {
|
||||||
|
projectFacets.add(installedFacetEntryNodes.item(i).getNodeValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
projectInfo.setProjectFacets(projectFacets);
|
||||||
|
|
||||||
|
} catch (ParserConfigurationException |
|
||||||
|
SAXException |
|
||||||
|
XPathExpressionException |
|
||||||
|
IOException ex) {
|
||||||
|
log.error("error parsing project file", ex);
|
||||||
|
throw new AnalyzerException("error parsing project file", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Analyze the classpath file.
|
||||||
|
*
|
||||||
|
* @throws AnalyzerException any error occurred while analyzing the metadata
|
||||||
|
* files, typically a parsing error in XML files
|
||||||
|
*/
|
||||||
|
private void analyzeClasspathFile()
|
||||||
|
throws AnalyzerException {
|
||||||
|
|
||||||
|
List<String> projectClasspath = new ArrayList<>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// parses .classpath file
|
||||||
|
File classpathFile = new File(rootDir, CLASSPATH_FILE);
|
||||||
|
if (!classpathFile.exists()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
|
factory.setNamespaceAware(true);
|
||||||
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
|
XPathFactory xpathFactory = XPathFactory.newInstance();
|
||||||
|
XPath xpath = xpathFactory.newXPath();
|
||||||
|
|
||||||
|
Document classpathDocument = builder.parse(classpathFile);
|
||||||
|
|
||||||
|
// get libraries in classpath
|
||||||
|
XPathExpression xpathClasspathLibEntry = xpath.compile(XPATH_CLASSPATH_LIB);
|
||||||
|
NodeList classpathLibEntryNodes = (NodeList) xpathClasspathLibEntry.evaluate(classpathDocument, XPathConstants.NODESET);
|
||||||
|
for (int i = 0, n = classpathLibEntryNodes.getLength(); i < n; i++) {
|
||||||
|
String libName = classpathLibEntryNodes.item(i).getNodeValue();
|
||||||
|
projectClasspath.add(libName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get source folders in classpath
|
||||||
|
XPathExpression xpathClasspathSrcEntry = xpath.compile(XPATH_CLASSPATH_SRC);
|
||||||
|
NodeList classpathSrcEntryNodes = (NodeList) xpathClasspathSrcEntry.evaluate(classpathDocument, XPathConstants.NODESET);
|
||||||
|
for (int i = 0, n = classpathSrcEntryNodes.getLength(); i < n; i++) {
|
||||||
|
String srcName = classpathSrcEntryNodes.item(i).getNodeValue();
|
||||||
|
projectClasspath.add(srcName);
|
||||||
|
}
|
||||||
|
|
||||||
|
projectInfo.setProjectClasspath(projectClasspath);
|
||||||
|
|
||||||
|
} catch (ParserConfigurationException |
|
||||||
|
SAXException |
|
||||||
|
XPathExpressionException |
|
||||||
|
IOException ex) {
|
||||||
|
log.error("error parsing project file", ex);
|
||||||
|
throw new AnalyzerException("error parsing project file", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* Sonar IDE Metadata plugin analyzers package. Contains analyzers
|
||||||
|
* for different IDE metadata (currently only Eclipse is supported).
|
||||||
|
*
|
||||||
|
* @author jorge.hidalgo
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
package deors.plugins.sonarqube.idemetadata.analyzers;
|
@ -0,0 +1,595 @@
|
|||||||
|
package deors.plugins.sonarqube.idemetadata.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.json.Json;
|
||||||
|
import javax.json.JsonArrayBuilder;
|
||||||
|
import javax.json.JsonObjectBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The project information bean.
|
||||||
|
*
|
||||||
|
* @author jorge.hidalgo
|
||||||
|
* @version 1.2
|
||||||
|
*/
|
||||||
|
public class ProjectInfo {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An EAR nature identifier.
|
||||||
|
*/
|
||||||
|
static final String IBM_ETOOLS_EAR_NATURE = "com.ibm.etools.j2ee.EAR13Nature"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An EJB nature identifier.
|
||||||
|
*/
|
||||||
|
static final String IBM_ETOOLS_EJB_NATURE = "com.ibm.etools.j2ee.EJB2_0Nature"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Java nature identifier.
|
||||||
|
*/
|
||||||
|
static final String IBM_ETOOLS_JAVA_NATURE = "com.ibm.etools.ctc.javaprojectnature"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Web nature identifier.
|
||||||
|
*/
|
||||||
|
static final String IBM_ETOOLS_WEB_NATURE = "com.ibm.etools.j2ee.WebNature"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An EJB nature identifier.
|
||||||
|
*/
|
||||||
|
static final String IBM_WTP_EJB_NATURE = "com.ibm.wtp.ejb.EJBNature"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Web nature identifier.
|
||||||
|
*/
|
||||||
|
static final String IBM_WTP_WEB_NATURE = "com.ibm.wtp.web.WebNature"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Java nature identifier.
|
||||||
|
*/
|
||||||
|
static final String JAVA_NATURE = "org.eclipse.jdt.core.javanature"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Faceted project nature identifier.
|
||||||
|
*/
|
||||||
|
static final String FACET_NATURE = "org.eclipse.wst.common.project.facet.core.nature"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Google Web Toolkit nature identifier.
|
||||||
|
*/
|
||||||
|
static final String GWT_NATURE = "com.google.gwt.eclipse.core.gwtNature"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Google App Engine nature identifier.
|
||||||
|
*/
|
||||||
|
static final String GAE_NATURE = "com.google.appengine.eclipse.core.gaeNature"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Groovy nature identifier.
|
||||||
|
*/
|
||||||
|
static final String GROOVY_NATURE = "org.eclipse.jdt.groovy.core.groovyNature"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Grails nature identifier.
|
||||||
|
*/
|
||||||
|
static final String GRAILS_NATURE = "com.springsource.sts.grails.core.nature"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An Eclipse plug-in nature identifier.
|
||||||
|
*/
|
||||||
|
static final String PDE_NATURE = "org.eclipse.pde.PluginNature"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A JET nature identifier.
|
||||||
|
*/
|
||||||
|
static final String JET_NATURE = "org.eclipse.jet.jet2Nature"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Web facet identifier.
|
||||||
|
*/
|
||||||
|
static final String WEB_FACET = "jst.web"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An EJB facet identifier.
|
||||||
|
*/
|
||||||
|
static final String EJB_FACET = "jst.ejb"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An EAR facet identifier.
|
||||||
|
*/
|
||||||
|
static final String EAR_FACET = "jst.ear"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Grails facet identifier.
|
||||||
|
*/
|
||||||
|
static final String GRAILS_FACET = "grails.app"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The project classpath list.
|
||||||
|
*/
|
||||||
|
private List<String> projectClasspath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The project dependencies list.
|
||||||
|
*/
|
||||||
|
private List<String> projectDependencies;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The project name.
|
||||||
|
*/
|
||||||
|
private String projectName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The project natures list.
|
||||||
|
*/
|
||||||
|
private List<String> projectNatures;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The project facets list.
|
||||||
|
*/
|
||||||
|
private List<String> projectFacets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
public ProjectInfo() {
|
||||||
|
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.projectName = "DEFAULT"; //$NON-NLS-1$
|
||||||
|
this.projectClasspath = new ArrayList<>();
|
||||||
|
this.projectDependencies = new ArrayList<>();
|
||||||
|
this.projectNatures = new ArrayList<>();
|
||||||
|
this.projectFacets = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that sets the project name.
|
||||||
|
*
|
||||||
|
* @param projectName the project name
|
||||||
|
*/
|
||||||
|
public ProjectInfo(String projectName) {
|
||||||
|
|
||||||
|
this();
|
||||||
|
|
||||||
|
this.projectName = projectName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a project classpath entry.
|
||||||
|
*
|
||||||
|
* @param classpathEntry the classpath entry
|
||||||
|
*/
|
||||||
|
public void addProjectClasspathEntry(String classpathEntry) {
|
||||||
|
|
||||||
|
projectClasspath.add(classpathEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a project dependency.
|
||||||
|
*
|
||||||
|
* @param dependencyName the dependency name
|
||||||
|
*/
|
||||||
|
public void addProjectDependency(String dependencyName) {
|
||||||
|
|
||||||
|
projectDependencies.add(dependencyName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a project nature.
|
||||||
|
*
|
||||||
|
* @param natureName the nature name
|
||||||
|
*/
|
||||||
|
public void addProjectNature(String natureName) {
|
||||||
|
|
||||||
|
projectNatures.add(natureName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a project facet.
|
||||||
|
*
|
||||||
|
* @param facetName the facet name
|
||||||
|
*/
|
||||||
|
public void addProjectFacet(String facetName) {
|
||||||
|
|
||||||
|
projectFacets.add(facetName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compares equality between this object and the given object.
|
||||||
|
*
|
||||||
|
* @param target the object to compare with
|
||||||
|
*
|
||||||
|
* @return whether this object and the given object are equal
|
||||||
|
*/
|
||||||
|
public boolean equals(Object target) {
|
||||||
|
|
||||||
|
if (target == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(target instanceof ProjectInfo)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProjectInfo casted = (ProjectInfo) target;
|
||||||
|
|
||||||
|
return projectName.equals(casted.projectName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the hash code of this object. It is calculated using
|
||||||
|
* the AND logical operator over property values.
|
||||||
|
*
|
||||||
|
* @return the hash code
|
||||||
|
*/
|
||||||
|
public int hashCode() {
|
||||||
|
|
||||||
|
return projectName.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of the property <code>projectClasspath</code>.
|
||||||
|
*
|
||||||
|
* @return the value of the property
|
||||||
|
*/
|
||||||
|
public List<String> getProjectClasspath() {
|
||||||
|
|
||||||
|
return projectClasspath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of the property <code>projectDependencies</code>.
|
||||||
|
*
|
||||||
|
* @return the value of the property
|
||||||
|
*/
|
||||||
|
public List<String> getProjectDependencies() {
|
||||||
|
|
||||||
|
return projectDependencies;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of the property <code>projectName</code>.
|
||||||
|
*
|
||||||
|
* @return the value of the property
|
||||||
|
*/
|
||||||
|
public String getProjectName() {
|
||||||
|
|
||||||
|
return projectName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of the property <code>projectNatures</code>.
|
||||||
|
*
|
||||||
|
* @return the value of the property
|
||||||
|
*/
|
||||||
|
public List<String> getProjectNatures() {
|
||||||
|
|
||||||
|
return projectNatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of the property <code>projectFacets</code>.
|
||||||
|
*
|
||||||
|
* @return the value of the property
|
||||||
|
*/
|
||||||
|
public List<String> getProjectFacets() {
|
||||||
|
|
||||||
|
return projectFacets;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the project has a Java nature.
|
||||||
|
*
|
||||||
|
* @return the Java nature flag
|
||||||
|
*/
|
||||||
|
public boolean isJavaProject() {
|
||||||
|
|
||||||
|
for (String nature : projectNatures) {
|
||||||
|
if (JAVA_NATURE.equals(nature)
|
||||||
|
|| IBM_ETOOLS_JAVA_NATURE.equals(nature)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the project has an EAR nature.
|
||||||
|
*
|
||||||
|
* @return the EAR nature flag
|
||||||
|
*/
|
||||||
|
public boolean isEarProject() {
|
||||||
|
|
||||||
|
for (String nature : projectNatures) {
|
||||||
|
if (IBM_ETOOLS_EAR_NATURE.equals(nature)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isFacetedProject()) {
|
||||||
|
for (String facet : projectFacets) {
|
||||||
|
if (EAR_FACET.equals(facet)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the project has an EJB nature.
|
||||||
|
*
|
||||||
|
* @return the EJB nature flag
|
||||||
|
*/
|
||||||
|
public boolean isEjbProject() {
|
||||||
|
|
||||||
|
for (String nature : projectNatures) {
|
||||||
|
if (IBM_ETOOLS_EJB_NATURE.equals(nature)
|
||||||
|
|| IBM_WTP_EJB_NATURE.equals(nature)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isFacetedProject()) {
|
||||||
|
for (String facet : projectFacets) {
|
||||||
|
if (EJB_FACET.equals(facet)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the project has a Web nature.
|
||||||
|
*
|
||||||
|
* @return the Web nature flag
|
||||||
|
*/
|
||||||
|
public boolean isWebProject() {
|
||||||
|
|
||||||
|
for (String nature : projectNatures) {
|
||||||
|
if (IBM_ETOOLS_WEB_NATURE.equals(nature)
|
||||||
|
|| IBM_WTP_WEB_NATURE.equals(nature)
|
||||||
|
|| GWT_NATURE.equals(nature)
|
||||||
|
|| GRAILS_NATURE.equals(nature)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isFacetedProject()) {
|
||||||
|
for (String facet : projectFacets) {
|
||||||
|
if (WEB_FACET.equals(facet)
|
||||||
|
|| GRAILS_FACET.equals(facet)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the project has a Faceted project nature.
|
||||||
|
*
|
||||||
|
* @return the Faceted project nature flag
|
||||||
|
*/
|
||||||
|
public boolean isFacetedProject() {
|
||||||
|
|
||||||
|
for (String nature : projectNatures) {
|
||||||
|
if (FACET_NATURE.equals(nature)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the project has a GWT nature.
|
||||||
|
*
|
||||||
|
* @return the GWT nature flag
|
||||||
|
*/
|
||||||
|
public boolean isGwtProject() {
|
||||||
|
|
||||||
|
for (String nature : projectNatures) {
|
||||||
|
if (GWT_NATURE.equals(nature)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the project has a GAE nature.
|
||||||
|
*
|
||||||
|
* @return the GAE nature flag
|
||||||
|
*/
|
||||||
|
public boolean isGaeProject() {
|
||||||
|
|
||||||
|
for (String nature : projectNatures) {
|
||||||
|
if (GAE_NATURE.equals(nature)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the project has a Groovy nature.
|
||||||
|
*
|
||||||
|
* @return the Groovy nature flag
|
||||||
|
*/
|
||||||
|
public boolean isGroovyProject() {
|
||||||
|
|
||||||
|
for (String nature : projectNatures) {
|
||||||
|
if (GROOVY_NATURE.equals(nature)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the project has a Grails nature.
|
||||||
|
*
|
||||||
|
* @return the Grails nature flag
|
||||||
|
*/
|
||||||
|
public boolean isGrailsProject() {
|
||||||
|
|
||||||
|
for (String nature : projectNatures) {
|
||||||
|
if (GRAILS_NATURE.equals(nature)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isFacetedProject()) {
|
||||||
|
for (String facet : projectFacets) {
|
||||||
|
if (GRAILS_FACET.equals(facet)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the project has an Eclipse plug-in nature.
|
||||||
|
*
|
||||||
|
* @return the Eclipse plug-in nature flag
|
||||||
|
*/
|
||||||
|
public boolean isPdeProject() {
|
||||||
|
|
||||||
|
for (String nature : projectNatures) {
|
||||||
|
if (PDE_NATURE.equals(nature)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the project has a JET nature.
|
||||||
|
*
|
||||||
|
* @return the GraiJETls nature flag
|
||||||
|
*/
|
||||||
|
public boolean isJetProject() {
|
||||||
|
|
||||||
|
for (String nature : projectNatures) {
|
||||||
|
if (JET_NATURE.equals(nature)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the value of the property <code>projectClasspath</code>.
|
||||||
|
*
|
||||||
|
* @param projectClasspath the new value for the property
|
||||||
|
*/
|
||||||
|
public void setProjectClasspath(List<String> projectClasspath) {
|
||||||
|
|
||||||
|
this.projectClasspath = projectClasspath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the value of the property <code>projectDependencies</code>.
|
||||||
|
*
|
||||||
|
* @param projectDependencies the new value for the property
|
||||||
|
*/
|
||||||
|
public void setProjectDependencies(List<String> projectDependencies) {
|
||||||
|
|
||||||
|
this.projectDependencies = projectDependencies;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the value of the property <code>projectName</code>.
|
||||||
|
*
|
||||||
|
* @param projectName the new value for the property
|
||||||
|
*/
|
||||||
|
public void setProjectName(String projectName) {
|
||||||
|
|
||||||
|
this.projectName = projectName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the value of the property <code>projectNatures</code>.
|
||||||
|
*
|
||||||
|
* @param projectNatures the new value for the property
|
||||||
|
*/
|
||||||
|
public void setProjectNatures(List<String> projectNatures) {
|
||||||
|
|
||||||
|
this.projectNatures = projectNatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the value of the property <code>projectFacets</code>.
|
||||||
|
*
|
||||||
|
* @param projectFacets the new value for the property
|
||||||
|
*/
|
||||||
|
public void setProjectFacets(List<String> projectFacets) {
|
||||||
|
|
||||||
|
this.projectFacets = projectFacets;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a JSON representation of this object.
|
||||||
|
*
|
||||||
|
* @return the JSON representation
|
||||||
|
*/
|
||||||
|
public String toJson() {
|
||||||
|
|
||||||
|
JsonObjectBuilder jsb = Json.createObjectBuilder()
|
||||||
|
.add("name", getProjectName()); //$NON-NLS-1$
|
||||||
|
|
||||||
|
if (!projectDependencies.isEmpty()) {
|
||||||
|
JsonArrayBuilder jab = Json.createArrayBuilder();
|
||||||
|
for (String dep : projectDependencies) {
|
||||||
|
jab.add(dep);
|
||||||
|
}
|
||||||
|
jsb.add("dependencies", jab); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
jsb.add("isJava", isJavaProject()); //$NON-NLS-1$
|
||||||
|
jsb.add("isEar", isEarProject()); //$NON-NLS-1$
|
||||||
|
jsb.add("isEjb", isEjbProject()); //$NON-NLS-1$
|
||||||
|
jsb.add("isWeb", isWebProject()); //$NON-NLS-1$
|
||||||
|
jsb.add("isGwt", isGwtProject()); //$NON-NLS-1$
|
||||||
|
jsb.add("isGae", isGaeProject()); //$NON-NLS-1$
|
||||||
|
jsb.add("isGroovy", isGroovyProject()); //$NON-NLS-1$
|
||||||
|
jsb.add("isGrails", isGrailsProject()); //$NON-NLS-1$
|
||||||
|
jsb.add("isPde", isPdeProject()); //$NON-NLS-1$
|
||||||
|
jsb.add("isJet", isJetProject()); //$NON-NLS-1$
|
||||||
|
|
||||||
|
return jsb.build().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a string representation of this object.
|
||||||
|
*
|
||||||
|
* @return the string representation
|
||||||
|
*/
|
||||||
|
public String toString() {
|
||||||
|
|
||||||
|
return projectName
|
||||||
|
+ " dependencies " //$NON-NLS-1$
|
||||||
|
+ projectDependencies
|
||||||
|
+ " natures " //$NON-NLS-1$
|
||||||
|
+ projectNatures
|
||||||
|
+ " facets " //$NON-NLS-1$
|
||||||
|
+ projectFacets
|
||||||
|
+ " classpath " //$NON-NLS-1$
|
||||||
|
+ projectClasspath;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
/**
|
||||||
|
* Contains model beans for IDE Metadata plugin.
|
||||||
|
*
|
||||||
|
* @author jorge.hidalgo
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
package deors.plugins.sonarqube.idemetadata.model;
|
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* Sonar IDE Metadata plugin root package. Contains plugin definition,
|
||||||
|
* metrics definition, sensor and dashboard widget.
|
||||||
|
*
|
||||||
|
* @author jorge.hidalgo
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
package deors.plugins.sonarqube.idemetadata;
|
@ -0,0 +1 @@
|
|||||||
|
rebel.xml
|
@ -0,0 +1,157 @@
|
|||||||
|
<%
|
||||||
|
def check_image(metric_or_measure)
|
||||||
|
html = ''
|
||||||
|
|
||||||
|
if metric_or_measure.is_a? ProjectMeasure
|
||||||
|
m = metric_or_measure
|
||||||
|
elsif @snapshot
|
||||||
|
m = @snapshot.measure(metric_or_measure)
|
||||||
|
end
|
||||||
|
|
||||||
|
if m.nil?
|
||||||
|
return ''
|
||||||
|
end
|
||||||
|
|
||||||
|
if m && m.metric
|
||||||
|
if m.value == 1
|
||||||
|
html = image_tag(url_for_static(:plugin => 'idemetadata', :path => 'check-round-yes-small.png'), :size => '16x16', :style => 'vertical-align:middle')
|
||||||
|
elsif
|
||||||
|
html = image_tag(url_for_static(:plugin => 'idemetadata', :path => 'check-round-no-small.png'), :size => '16x16', :style => 'vertical-align:middle')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
html
|
||||||
|
end
|
||||||
|
|
||||||
|
def remove_brackets(metric_or_measure)
|
||||||
|
out = ''
|
||||||
|
|
||||||
|
if metric_or_measure.is_a? ProjectMeasure
|
||||||
|
m = metric_or_measure
|
||||||
|
elsif @snapshot
|
||||||
|
m = @snapshot.measure(metric_or_measure)
|
||||||
|
end
|
||||||
|
|
||||||
|
if m.nil?
|
||||||
|
return ''
|
||||||
|
end
|
||||||
|
|
||||||
|
if m && m.metric
|
||||||
|
out = m.data[1..-2]
|
||||||
|
end
|
||||||
|
|
||||||
|
out
|
||||||
|
end
|
||||||
|
%>
|
||||||
|
<div class="dashbox">
|
||||||
|
<h3>Project name (as configured in the IDE):</h3>
|
||||||
|
<p>
|
||||||
|
<span class="big">
|
||||||
|
<%= format_measure('ide_prj_name') %>
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="dashbox">
|
||||||
|
<table class="width100">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td style="width=60%; vertical-align:top; padding:0 30px 0 0;">
|
||||||
|
<h3>Project type and active frameworks:</h3>
|
||||||
|
<table>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<%= check_image('ide_is_java') -%>
|
||||||
|
<span style="vertical-align:middle">Java VM</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<%= check_image('ide_is_ear') -%>
|
||||||
|
<span style="vertical-align:middle">Java Enterprise Application (EAR)</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<%= check_image('ide_is_ejb') -%>
|
||||||
|
<span style="vertical-align:middle">Enterprise JavaBeans (EJB)</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<%= check_image('ide_is_web') -%>
|
||||||
|
<span style="vertical-align:middle">Web</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<%= check_image('ide_is_gwt') -%>
|
||||||
|
<span style="vertical-align:middle">Google Web Toolkit</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<%= check_image('ide_is_gae') -%>
|
||||||
|
<span style="vertical-align:middle">Google App Engine</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<%= check_image('ide_is_groovy') -%>
|
||||||
|
<span style="vertical-align:middle">Groovy</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<%= check_image('ide_is_grails') -%>
|
||||||
|
<span style="vertical-align:middle">Grails</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<%= check_image('ide_is_pde') -%>
|
||||||
|
<span style="vertical-align:middle">Eclipse Plug-in</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<%= check_image('ide_is_jet') -%>
|
||||||
|
<span style="vertical-align:middle">Eclipse JET code generator</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
<td style="width=40%; vertical-align:top">
|
||||||
|
<h3>Declared dependencies:</h3>
|
||||||
|
<table>
|
||||||
|
<tbody>
|
||||||
|
<% remove_brackets('ide_dependencies').split(/, /).each do |it| %>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<%= image_tag('bullet_black.png', :style => 'vertical-align:middle') -%>
|
||||||
|
<span style="vertical-align:middle"><%= it -%></span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<br/>
|
||||||
|
<h3>Configured source folders:</h3>
|
||||||
|
<table>
|
||||||
|
<tbody>
|
||||||
|
<% remove_brackets('ide_classpath').split(/, /).each do |it| %>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<%= image_tag('bullet_black.png', :style => 'vertical-align:middle') -%>
|
||||||
|
<span style="vertical-align:middle"><%= it -%></span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
After Width: | Height: | Size: 8.1 KiB |
After Width: | Height: | Size: 7.5 KiB |
@ -0,0 +1,20 @@
|
|||||||
|
package deors.plugins.sonarqube.idemetadata;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class IDEMetadataMetricsTest {
|
||||||
|
|
||||||
|
public IDEMetadataMetricsTest() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMetricsDefinition() {
|
||||||
|
|
||||||
|
IDEMetadataMetrics metrics = new IDEMetadataMetrics();
|
||||||
|
|
||||||
|
assertEquals("plug-in should have 13 metrics defined", 13, metrics.getMetrics().size());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package deors.plugins.sonarqube.idemetadata;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class IDEMetadataPluginTest {
|
||||||
|
|
||||||
|
public IDEMetadataPluginTest() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPluginDefinition() {
|
||||||
|
|
||||||
|
IDEMetadataPlugin plugin = new IDEMetadataPlugin();
|
||||||
|
|
||||||
|
assertEquals("plug-in should have 3 extensions defined", 3, plugin.getExtensions().size());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,105 @@
|
|||||||
|
package deors.plugins.sonarqube.idemetadata.analyzers;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import deors.plugins.sonarqube.idemetadata.model.ProjectInfo;
|
||||||
|
|
||||||
|
|
||||||
|
public class EclipseAnalyzerTest {
|
||||||
|
public EclipseAnalyzerTest() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMissingProject() throws AnalyzerException {
|
||||||
|
|
||||||
|
EclipseAnalyzer ea = new EclipseAnalyzer(new File("missing-dir"));
|
||||||
|
|
||||||
|
ProjectInfo projectInfo = ea.analyze();
|
||||||
|
|
||||||
|
assertFalse("project should not be Java", projectInfo.isJavaProject());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUnfacetedJavaProject() throws URISyntaxException, AnalyzerException {
|
||||||
|
|
||||||
|
URL settingsUrl = this.getClass().getResource("/project1");
|
||||||
|
File settingsDir = new File(settingsUrl.toURI());
|
||||||
|
|
||||||
|
EclipseAnalyzer ea = new EclipseAnalyzer(settingsDir);
|
||||||
|
|
||||||
|
ProjectInfo projectInfo = ea.analyze();
|
||||||
|
|
||||||
|
assertFalse("project should not be faceted", projectInfo.isFacetedProject());
|
||||||
|
assertTrue("project should be Java", projectInfo.isJavaProject());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFacetedJavaWebProject() throws URISyntaxException, AnalyzerException {
|
||||||
|
|
||||||
|
URL settingsUrl = this.getClass().getResource("/project2");
|
||||||
|
File settingsDir = new File(settingsUrl.toURI());
|
||||||
|
|
||||||
|
EclipseAnalyzer ea = new EclipseAnalyzer(settingsDir);
|
||||||
|
|
||||||
|
ProjectInfo projectInfo = ea.analyze();
|
||||||
|
|
||||||
|
assertTrue("project should be faceted", projectInfo.isFacetedProject());
|
||||||
|
assertTrue("project should be Java", projectInfo.isJavaProject());
|
||||||
|
assertTrue("project should be Web", projectInfo.isWebProject());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testProjectWithDependencies() throws URISyntaxException, AnalyzerException {
|
||||||
|
|
||||||
|
URL settingsUrl = this.getClass().getResource("/project3");
|
||||||
|
File settingsDir = new File(settingsUrl.toURI());
|
||||||
|
|
||||||
|
EclipseAnalyzer ea = new EclipseAnalyzer(settingsDir);
|
||||||
|
|
||||||
|
ProjectInfo projectInfo = ea.analyze();
|
||||||
|
|
||||||
|
assertFalse("project should have dependencies", projectInfo.getProjectDependencies().isEmpty());
|
||||||
|
assertFalse("project should depend on classpath libraries", projectInfo.getProjectClasspath().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = AnalyzerException.class)
|
||||||
|
public void testProjectWithBadFiles1() throws URISyntaxException, AnalyzerException {
|
||||||
|
|
||||||
|
URL settingsUrl = this.getClass().getResource("/badproject1");
|
||||||
|
File settingsDir = new File(settingsUrl.toURI());
|
||||||
|
|
||||||
|
EclipseAnalyzer ea = new EclipseAnalyzer(settingsDir);
|
||||||
|
|
||||||
|
ea.analyze();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = AnalyzerException.class)
|
||||||
|
public void testProjectWithBadFiles2() throws URISyntaxException, AnalyzerException {
|
||||||
|
|
||||||
|
URL settingsUrl = this.getClass().getResource("/badproject2");
|
||||||
|
File settingsDir = new File(settingsUrl.toURI());
|
||||||
|
|
||||||
|
EclipseAnalyzer ea = new EclipseAnalyzer(settingsDir);
|
||||||
|
|
||||||
|
ea.analyze();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = AnalyzerException.class)
|
||||||
|
public void testProjectWithBadFiles3() throws URISyntaxException, AnalyzerException {
|
||||||
|
|
||||||
|
URL settingsUrl = this.getClass().getResource("/badproject3");
|
||||||
|
File settingsDir = new File(settingsUrl.toURI());
|
||||||
|
|
||||||
|
EclipseAnalyzer ea = new EclipseAnalyzer(settingsDir);
|
||||||
|
|
||||||
|
ea.analyze();
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Loading…
Reference in new issue