create the module sonar-java-api dedicated to Java support

This commit is contained in:
simonbrandhof 2011-01-19 22:36:38 +01:00
parent 1fbdcfbd15
commit 5b4a5f39b3
7 changed files with 274 additions and 24 deletions

View File

@ -14,6 +14,11 @@
<description>Squid analyzer for Java.</description>
<dependencies>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-java-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-plugin-api</artifactId>

35
pom.xml
View File

@ -13,20 +13,21 @@
<!-- public artifacts to be deployed to central repository -->
<module>archetypes/sonar-basic-plugin</module>
<module>archetypes/sonar-gwt-plugin</module>
<module>sonar-core</module>
<module>sonar-deprecated</module>
<module>sonar-batch</module>
<module>sonar-maven-plugin</module>
<module>sonar-maven3-plugin</module>
<module>sonar-channel</module>
<module>sonar-check-api</module>
<module>sonar-colorizer</module>
<module>sonar-core</module>
<module>sonar-deprecated</module>
<module>sonar-duplications</module>
<module>sonar-graph</module>
<module>sonar-gwt-api</module>
<module>sonar-java-api</module>
<module>sonar-maven-plugin</module>
<module>sonar-maven3-plugin</module>
<module>sonar-plugin-api</module>
<module>sonar-testing-harness</module>
<module>sonar-squid</module>
<module>sonar-testing-harness</module>
<module>sonar-ws-client</module>
<module>plugins/sonar-core-gwt</module>
<module>plugins/sonar-core-plugin</module>
@ -314,22 +315,6 @@
</archive>
</configuration>
</plugin>
<!-- <plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<outputDirectory>${project.reporting.outputDirectory}/${project.version}/clover</outputDirectory>
<generateHistorical>false</generateHistorical>
<generateXml>false</generateXml>
<license><![CDATA[opmOXvoSTwRurJtdPUPnnqXUoPxgewBKvhvFsQghghMpHN
mi2KCHwAl26X>gPZJcsdXAvR2KEZT5o>pDZqs>VNq7CbJD
OomqxtmMpmQQorqpnOqWVrrrQONpmONrNRUVuWTtSWSoop
qqnmqmUUnooqqonommmmmUUnooqqonommmmmUUJlkXoUUn
mmmm
]]></license>
</configuration>
</plugin>-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
@ -342,8 +327,6 @@ mmmm
<reportOutputDirectory>${project.reporting.outputDirectory}/${project.version}/apidocs</reportOutputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
@ -353,7 +336,6 @@ mmmm
<javadocDir>${project.reporting.outputDirectory}/${project.version}/apidocs</javadocDir>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
@ -413,6 +395,11 @@ mmmm
<artifactId>sonar-gwt-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-java-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-plugin-api</artifactId>

29
sonar-java-api/pom.xml Normal file
View File

@ -0,0 +1,29 @@
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar</artifactId>
<version>2.6-SNAPSHOT</version>
</parent>
<artifactId>sonar-java-api</artifactId>
<name>Sonar :: Java API</name>
<dependencies>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-plugin-api</artifactId>
</dependency>
<!-- unit tests -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,96 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* Sonar is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* Sonar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.java.api;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.resources.*;
/**
* @since 2.6
*/
public final class JavaClass extends Resource {
private String name;
private JavaClass(String name) {
this.name = name;
setKey(name);
}
public String getPackageName() {
return StringUtils.substringBeforeLast(name, JavaUtils.PACKAGE_SEPARATOR);
}
public String getClassName() {
return StringUtils.substringAfterLast(name, JavaUtils.PACKAGE_SEPARATOR);
}
@Override
public String getName() {
return getClassName();
}
@Override
public String getLongName() {
return name;
}
@Override
public String getDescription() {
return null;
}
@Override
public Language getLanguage() {
return Java.INSTANCE;
}
@Override
public String getScope() {
return ResourceScopes.TYPE;
}
@Override
public String getQualifier() {
return ResourceQualifiers.CLASS;
}
@Override
public Resource getParent() {
return null;
}
@Override
public boolean matchFilePattern(String antPattern) {
return false;
}
public static JavaClass create(String name) {
return new JavaClass(name);
}
public static JavaClass create(String packageName, String className) {
if (StringUtils.isBlank(packageName)) {
return new JavaClass(className);
}
String name = new StringBuilder().append(packageName).append(JavaUtils.PACKAGE_SEPARATOR).append(className).toString();
return new JavaClass(name);
}
}

View File

@ -0,0 +1,43 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* Sonar is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* Sonar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.java.api;
import org.apache.commons.lang.StringUtils;
public final class JavaUtils {
public static final String PACKAGE_SEPARATOR = ".";
private JavaUtils() {
// only static methods
}
public static String abbreviatePackage(String packageName) {
String[] parts = StringUtils.split(packageName, PACKAGE_SEPARATOR);
StringBuilder sb = new StringBuilder();
if (parts.length>=1) {
sb.append(parts[0]);
}
for (int index=1 ; index<parts.length ; index++) {
sb.append(PACKAGE_SEPARATOR).append(parts[index].charAt(0));
}
return sb.toString();
}
}

View File

@ -0,0 +1,51 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* Sonar is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* Sonar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.java.api;
import org.junit.Test;
import org.sonar.api.resources.Java;
import org.sonar.api.resources.Language;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
public class JavaClassTest {
@Test
public void shouldCreateJavaClassFromName() {
JavaClass javaClass = JavaClass.create("org.foo.Bar");
assertThat(javaClass.getClassName(), is("Bar"));
assertThat(javaClass.getKey(), is("org.foo.Bar"));
assertThat(javaClass.getLanguage(), is((Language)Java.INSTANCE));
assertThat(javaClass.getName(), is("Bar"));
assertThat(javaClass.getLongName(), is("org.foo.Bar"));
}
@Test
public void shouldCreateJavaClassFromPackageAndClassname() {
JavaClass javaClass = JavaClass.create("org.foo", "Bar");
assertThat(javaClass.getClassName(), is("Bar"));
assertThat(javaClass.getKey(), is("org.foo.Bar"));
assertThat(javaClass.getLanguage(), is((Language)Java.INSTANCE));
assertThat(javaClass.getName(), is("Bar"));
assertThat(javaClass.getLongName(), is("org.foo.Bar"));
}
}

View File

@ -0,0 +1,39 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* Sonar is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* Sonar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.java.api;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
public class JavaUtilsTest {
@Test
public void shouldAbbreviatePackage() {
assertThat(JavaUtils.abbreviatePackage(""), is(""));
assertThat(JavaUtils.abbreviatePackage("com"), is("com"));
assertThat(JavaUtils.abbreviatePackage("com.foo"), is("com.f"));
assertThat(JavaUtils.abbreviatePackage("com.foo.bar.buz"), is("com.f.b.b"));
assertThat(JavaUtils.abbreviatePackage("..."), is(""));
assertThat(JavaUtils.abbreviatePackage("com.foo."), is("com.f"));
assertThat(JavaUtils.abbreviatePackage("com.foo..bar"), is("com.f.b"));
}
}