diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2011-01-19 22:36:38 +0100 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2011-01-19 22:49:50 +0100 |
commit | 5b4a5f39b3081312c37e9cf436aee6b04f8995d0 (patch) | |
tree | cf27e668a8fedaf91b131f3053b58f29fd822580 | |
parent | 1fbdcfbd155563691ded8f80d4fe2d03f754c897 (diff) | |
download | sonarqube-5b4a5f39b3081312c37e9cf436aee6b04f8995d0.tar.gz sonarqube-5b4a5f39b3081312c37e9cf436aee6b04f8995d0.zip |
create the module sonar-java-api dedicated to Java support
-rw-r--r-- | plugins/sonar-squid-java-plugin/pom.xml | 5 | ||||
-rw-r--r-- | pom.xml | 35 | ||||
-rw-r--r-- | sonar-java-api/pom.xml | 29 | ||||
-rw-r--r-- | sonar-java-api/src/main/java/org/sonar/java/api/JavaClass.java | 96 | ||||
-rw-r--r-- | sonar-java-api/src/main/java/org/sonar/java/api/JavaUtils.java | 43 | ||||
-rw-r--r-- | sonar-java-api/src/test/java/org/sonar/java/api/JavaClassTest.java | 51 | ||||
-rw-r--r-- | sonar-java-api/src/test/java/org/sonar/java/api/JavaUtilsTest.java | 39 |
7 files changed, 274 insertions, 24 deletions
diff --git a/plugins/sonar-squid-java-plugin/pom.xml b/plugins/sonar-squid-java-plugin/pom.xml index c5054b67cb1..70cb1d91ee2 100644 --- a/plugins/sonar-squid-java-plugin/pom.xml +++ b/plugins/sonar-squid-java-plugin/pom.xml @@ -16,6 +16,11 @@ <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> <scope>provided</scope> </dependency> @@ -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> @@ -415,6 +397,11 @@ mmmm </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> <version>${project.version}</version> </dependency> diff --git a/sonar-java-api/pom.xml b/sonar-java-api/pom.xml new file mode 100644 index 00000000000..26577b644b9 --- /dev/null +++ b/sonar-java-api/pom.xml @@ -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> diff --git a/sonar-java-api/src/main/java/org/sonar/java/api/JavaClass.java b/sonar-java-api/src/main/java/org/sonar/java/api/JavaClass.java new file mode 100644 index 00000000000..4a2b9d7086b --- /dev/null +++ b/sonar-java-api/src/main/java/org/sonar/java/api/JavaClass.java @@ -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); + } +} diff --git a/sonar-java-api/src/main/java/org/sonar/java/api/JavaUtils.java b/sonar-java-api/src/main/java/org/sonar/java/api/JavaUtils.java new file mode 100644 index 00000000000..a1925501b5d --- /dev/null +++ b/sonar-java-api/src/main/java/org/sonar/java/api/JavaUtils.java @@ -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(); + } +}
\ No newline at end of file diff --git a/sonar-java-api/src/test/java/org/sonar/java/api/JavaClassTest.java b/sonar-java-api/src/test/java/org/sonar/java/api/JavaClassTest.java new file mode 100644 index 00000000000..576d7d28c41 --- /dev/null +++ b/sonar-java-api/src/test/java/org/sonar/java/api/JavaClassTest.java @@ -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")); + } +} diff --git a/sonar-java-api/src/test/java/org/sonar/java/api/JavaUtilsTest.java b/sonar-java-api/src/test/java/org/sonar/java/api/JavaUtilsTest.java new file mode 100644 index 00000000000..f98853e5306 --- /dev/null +++ b/sonar-java-api/src/test/java/org/sonar/java/api/JavaUtilsTest.java @@ -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")); + } +} |