<description>Squid analyzer for Java</description> | <description>Squid analyzer for Java</description> | ||||
<dependencies> | <dependencies> | ||||
<dependency> | |||||
<groupId>org.codehaus.sonar</groupId> | |||||
<artifactId>sonar-deprecated</artifactId> | |||||
</dependency> | |||||
<dependency> | <dependency> | ||||
<groupId>org.codehaus.sonar</groupId> | <groupId>org.codehaus.sonar</groupId> | ||||
<artifactId>sonar-squid</artifactId> | <artifactId>sonar-squid</artifactId> |
<?xml version="1.0" encoding="UTF-8"?> | <?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"> | |||||
<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> | <modelVersion>4.0.0</modelVersion> | ||||
<parent> | <parent> | ||||
<groupId>org.codehaus.sonar</groupId> | <groupId>org.codehaus.sonar</groupId> | ||||
<groupId>${project.groupId}</groupId> | <groupId>${project.groupId}</groupId> | ||||
<artifactId>sonar-plugin-api</artifactId> | <artifactId>sonar-plugin-api</artifactId> | ||||
</dependency> | </dependency> | ||||
<dependency> | |||||
<groupId>xmlunit</groupId> | |||||
<artifactId>xmlunit</artifactId> | |||||
<scope>test</scope> | |||||
</dependency> | |||||
<dependency> | <dependency> | ||||
<groupId>junit</groupId> | <groupId>junit</groupId> | ||||
<artifactId>junit</artifactId> | <artifactId>junit</artifactId> | ||||
<artifactId>dbunit</artifactId> | <artifactId>dbunit</artifactId> | ||||
<scope>test</scope> | <scope>test</scope> | ||||
</dependency> | </dependency> | ||||
<dependency> | |||||
<groupId>ch.qos.logback</groupId> | |||||
<artifactId>logback-classic</artifactId> | |||||
<scope>test</scope> | |||||
</dependency> | |||||
</dependencies> | </dependencies> | ||||
</project> | </project> |
import java.util.Map; | import java.util.Map; | ||||
/** | /** | ||||
* @since 2.1 | |||||
* @since 2.1 (experimental) | |||||
* @deprecated since 2.3 | |||||
*/ | */ | ||||
@Deprecated | |||||
public class AnnotationCheckerFactory<CHECKER> extends CheckerFactory<CHECKER> { | public class AnnotationCheckerFactory<CHECKER> extends CheckerFactory<CHECKER> { | ||||
private CheckProfile profile; | private CheckProfile profile; |
import java.util.Map; | import java.util.Map; | ||||
/** | /** | ||||
* @since 2.1 | |||||
* @since 2.1 (experimental) | |||||
* @deprecated since 2.3 | |||||
*/ | */ | ||||
@Deprecated | |||||
public abstract class CheckerFactory<CHECKER> { | public abstract class CheckerFactory<CHECKER> { | ||||
public abstract Map<Check, CHECKER> create(); | public abstract Map<Check, CHECKER> create(); | ||||
} | } |
import java.util.Locale; | import java.util.Locale; | ||||
import java.util.Map; | import java.util.Map; | ||||
/** | |||||
* @since 2.1 (experimental) | |||||
* @deprecated since 2.3 | |||||
*/ | |||||
@Deprecated | |||||
public class MessageDispatcher { | public class MessageDispatcher { | ||||
private Map<Check, Object> checkersByCheck; | private Map<Check, Object> checkersByCheck; |
*/ | */ | ||||
package org.sonar.api.checks.checkers; | package org.sonar.api.checks.checkers; | ||||
/** | |||||
* @since 2.1 (experimental) | |||||
* @deprecated since 2.3 | |||||
*/ | |||||
@Deprecated | |||||
public class UnvalidCheckerException extends RuntimeException { | public class UnvalidCheckerException extends RuntimeException { | ||||
public UnvalidCheckerException() { | public UnvalidCheckerException() { | ||||
} | } |
import java.util.HashMap; | import java.util.HashMap; | ||||
import java.util.Map; | import java.util.Map; | ||||
/** | |||||
* @since 2.1 (experimental) | |||||
* @deprecated since 2.3 | |||||
*/ | |||||
@Deprecated | |||||
public final class AnnotationCheckProfileFactory { | public final class AnnotationCheckProfileFactory { | ||||
private AnnotationCheckProfileFactory() { | private AnnotationCheckProfileFactory() { |
import java.util.Map; | import java.util.Map; | ||||
/** | /** | ||||
* EXPERIMENTAL - will be used in version 2.2 | |||||
* @since 2.1 (experimental) | |||||
* @deprecated since 2.3 | |||||
*/ | */ | ||||
@Deprecated | |||||
public class Check { | public class Check { | ||||
private String repositoryKey; | private String repositoryKey; |
import java.util.Collection; | import java.util.Collection; | ||||
import java.util.List; | import java.util.List; | ||||
/** | |||||
* @since 2.1 (experimental) | |||||
* @deprecated since 2.3 | |||||
*/ | |||||
@Deprecated | |||||
public class CheckProfile implements BatchExtension, ServerExtension { | public class CheckProfile implements BatchExtension, ServerExtension { | ||||
private String name; | private String name; |
import java.util.Collection; | import java.util.Collection; | ||||
/** | /** | ||||
* EXPERIMENTAL - will be used in version 2.2 | |||||
* @since 2.1 (experimental) | |||||
* @deprecated since 2.3 | |||||
*/ | */ | ||||
@Deprecated | |||||
public abstract class CheckProfileProvider implements ServerExtension { | public abstract class CheckProfileProvider implements ServerExtension { | ||||
public abstract Collection<CheckProfile> provide(); | public abstract Collection<CheckProfile> provide(); |
import java.util.Map; | import java.util.Map; | ||||
/** | /** | ||||
* EXPERIMENTAL - will be used in version 2.3 | |||||
* @since 2.1 (experimental) | |||||
* @deprecated since 2.3 | |||||
*/ | */ | ||||
@Deprecated | |||||
public final class CheckProfileXmlMarshaller { | public final class CheckProfileXmlMarshaller { | ||||
public static void toXml(CheckProfile profile, Writer writer) { | public static void toXml(CheckProfile profile, Writer writer) { |
import java.util.List; | import java.util.List; | ||||
/** | /** | ||||
* Load templates from class annotations (see the library sonar-check-api) | |||||
* @since 2.1 (experimental) | |||||
* @deprecated since 2.3 | |||||
*/ | */ | ||||
@Deprecated | |||||
public class AnnotationCheckTemplateFactory { | public class AnnotationCheckTemplateFactory { | ||||
private static final Logger LOG = LoggerFactory.getLogger(AnnotationCheckTemplateFactory.class); | private static final Logger LOG = LoggerFactory.getLogger(AnnotationCheckTemplateFactory.class); |
import java.util.ResourceBundle; | import java.util.ResourceBundle; | ||||
/** | /** | ||||
* Internationalized check template. Translations are loaded from resource bundles (properties files in the classpath) | |||||
* | |||||
* @since 2.1 | |||||
* @since 2.1 (experimental) | |||||
* @deprecated since 2.3 | |||||
*/ | */ | ||||
@Deprecated | |||||
public class BundleCheckTemplate extends CheckTemplate { | public class BundleCheckTemplate extends CheckTemplate { | ||||
private static final Logger LOG = LoggerFactory.getLogger(BundleCheckTemplate.class); | private static final Logger LOG = LoggerFactory.getLogger(BundleCheckTemplate.class); | ||||
import java.util.Locale; | import java.util.Locale; | ||||
/** | |||||
* @since 2.1 (experimental) | |||||
* @deprecated since 2.3 | |||||
*/ | |||||
@Deprecated | |||||
public class BundleCheckTemplateProperty extends CheckTemplateProperty { | public class BundleCheckTemplateProperty extends CheckTemplateProperty { | ||||
private BundleCheckTemplate check; | private BundleCheckTemplate check; |
import java.util.Locale; | import java.util.Locale; | ||||
/** | /** | ||||
* EXPERIMENTAL - will be used in version 2.2 | |||||
* | |||||
* @since 2.1 | |||||
* @since 2.1 (experimental) | |||||
* @deprecated since 2.3 | |||||
*/ | */ | ||||
@Deprecated | |||||
public abstract class CheckTemplate { | public abstract class CheckTemplate { | ||||
protected String key; | protected String key; |
import java.util.Collection; | import java.util.Collection; | ||||
/** | /** | ||||
* EXPERIMENTAL - will be used in version 2.2 | |||||
* @since 2.1 | |||||
* @since 2.1 (experimental) | |||||
* @deprecated since 2.3 | |||||
*/ | */ | ||||
@Deprecated | |||||
public abstract class CheckTemplateFactory { | public abstract class CheckTemplateFactory { | ||||
public abstract Collection<CheckTemplate> create(); | public abstract Collection<CheckTemplate> create(); |
import java.util.Locale; | import java.util.Locale; | ||||
/** | /** | ||||
* EXPERIMENTAL - will be used in version 2.2 | |||||
* | |||||
* @since 2.1 | |||||
* @since 2.1 (experimental) | |||||
* @deprecated since 2.3 | |||||
*/ | */ | ||||
@Deprecated | |||||
public abstract class CheckTemplateProperty implements Comparable<CheckTemplateProperty> { | public abstract class CheckTemplateProperty implements Comparable<CheckTemplateProperty> { | ||||
protected String key; | protected String key; |
import java.util.Map; | import java.util.Map; | ||||
/** | /** | ||||
* @since 2.1 | |||||
* @since 2.1 (experimental) | |||||
* @deprecated since 2.3 | |||||
*/ | */ | ||||
@Deprecated | |||||
public class CheckTemplateRepositories implements ServerExtension { | public class CheckTemplateRepositories implements ServerExtension { | ||||
private Map<String, CheckTemplateRepository> repositoriesByKey = new HashMap<String, CheckTemplateRepository>(); | private Map<String, CheckTemplateRepository> repositoriesByKey = new HashMap<String, CheckTemplateRepository>(); |
import java.util.*; | import java.util.*; | ||||
/** | /** | ||||
* EXPERIMENTAL - will be used in version 2.3 | |||||
* | |||||
* @since 2.1 | |||||
* @since 2.1 (experimental) | |||||
* @deprecated since 2.3 | |||||
*/ | */ | ||||
@Deprecated | |||||
public class CheckTemplateRepository implements RulesRepository { | public class CheckTemplateRepository implements RulesRepository { | ||||
private String key; | private String key; |
/* | |||||
* 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.api.checks.checkers; | package org.sonar.api.checks.checkers; | ||||
import org.junit.Before; | import org.junit.Before; | ||||
Map map = new HashMap(); | Map map = new HashMap(); | ||||
map.put("max", "300"); | map.put("max", "300"); | ||||
when(check.getProperties()).thenReturn(map); | when(check.getProperties()).thenReturn(map); | ||||
factory.instantiate(check, CheckWithUnsupportedPropertyType.class); | factory.instantiate(check, CheckWithUnsupportedPropertyType.class); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
@Check(isoCategory = IsoCategory.Efficiency, priority = Priority.CRITICAL) | |||||
class CheckerWithoutProperties { | |||||
} | |||||
@Check(isoCategory = IsoCategory.Efficiency, priority = Priority.CRITICAL) | |||||
class CheckerWithStringProperty { | |||||
@CheckProperty(key = "maiximum") | |||||
private String max; | |||||
public String getMax() { | |||||
return max; | |||||
} | |||||
} | |||||
@Check(isoCategory = IsoCategory.Efficiency, priority = Priority.CRITICAL) | |||||
class CheckerWithPrimitiveProperties { | |||||
@CheckProperty(description = "Maximum threshold") | |||||
private int max = 50; | |||||
@CheckProperty | |||||
private boolean active; | |||||
public int getMax() { | |||||
return max; | |||||
} | |||||
public boolean isActive() { | |||||
return active; | |||||
} | |||||
} | |||||
@Check(isoCategory = IsoCategory.Efficiency, priority = Priority.CRITICAL) | |||||
class CheckerWithIntegerProperty { | |||||
@CheckProperty | |||||
private Integer max; | |||||
public Integer getMax() { | |||||
return max; | |||||
} | |||||
} | |||||
@Check(isoCategory = IsoCategory.Efficiency, priority = Priority.CRITICAL) | |||||
class CheckWithUnsupportedPropertyType { | |||||
@CheckProperty | |||||
private StringBuilder max = null; | |||||
} | |||||
@Check(isoCategory = IsoCategory.Efficiency, priority = Priority.CRITICAL) | @Check(isoCategory = IsoCategory.Efficiency, priority = Priority.CRITICAL) | ||||
class CheckWithOverridenPropertyKey{ | class CheckWithOverridenPropertyKey{ | ||||
package org.sonar.api.checks.checkers; | |||||
import org.sonar.check.Check; | |||||
import org.sonar.check.CheckProperty; | |||||
import org.sonar.check.IsoCategory; | |||||
import org.sonar.check.Priority; | |||||
/** | |||||
* Created by IntelliJ IDEA. | |||||
* User: simonbrandhof | |||||
* Date: Sep 14, 2010 | |||||
* Time: 11:20:57 AM | |||||
* To change this template use File | Settings | File Templates. | |||||
*/ | |||||
@Check(isoCategory = IsoCategory.Efficiency, priority = Priority.CRITICAL) | |||||
class CheckWithUnsupportedPropertyType { | |||||
@CheckProperty | |||||
private StringBuilder max = null; | |||||
} |
package org.sonar.api.checks.checkers; | |||||
import org.sonar.check.Check; | |||||
import org.sonar.check.CheckProperty; | |||||
import org.sonar.check.IsoCategory; | |||||
import org.sonar.check.Priority; | |||||
@Check(isoCategory = IsoCategory.Efficiency, priority = Priority.CRITICAL) | |||||
class CheckerWithIntegerProperty { | |||||
@CheckProperty | |||||
private Integer max; | |||||
public Integer getMax() { | |||||
return max; | |||||
} | |||||
} |
package org.sonar.api.checks.checkers; | |||||
import org.sonar.check.Check; | |||||
import org.sonar.check.CheckProperty; | |||||
import org.sonar.check.IsoCategory; | |||||
import org.sonar.check.Priority; | |||||
/** | |||||
* Created by IntelliJ IDEA. | |||||
* User: simonbrandhof | |||||
* Date: Sep 14, 2010 | |||||
* Time: 11:20:57 AM | |||||
* To change this template use File | Settings | File Templates. | |||||
*/ | |||||
@Check(isoCategory = IsoCategory.Efficiency, priority = Priority.CRITICAL) | |||||
class CheckerWithPrimitiveProperties { | |||||
@CheckProperty(description = "Maximum threshold") | |||||
private int max = 50; | |||||
@CheckProperty | |||||
private boolean active; | |||||
public int getMax() { | |||||
return max; | |||||
} | |||||
public boolean isActive() { | |||||
return active; | |||||
} | |||||
} |
package org.sonar.api.checks.checkers; | |||||
import org.sonar.check.Check; | |||||
import org.sonar.check.CheckProperty; | |||||
import org.sonar.check.IsoCategory; | |||||
import org.sonar.check.Priority; | |||||
/** | |||||
* Created by IntelliJ IDEA. | |||||
* User: simonbrandhof | |||||
* Date: Sep 14, 2010 | |||||
* Time: 11:20:57 AM | |||||
* To change this template use File | Settings | File Templates. | |||||
*/ | |||||
@Check(isoCategory = IsoCategory.Efficiency, priority = Priority.CRITICAL) | |||||
class CheckerWithStringProperty { | |||||
@CheckProperty(key = "maiximum") | |||||
private String max; | |||||
public String getMax() { | |||||
return max; | |||||
} | |||||
} |
/* | |||||
* 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.api.checks.checkers; | |||||
import org.sonar.check.Check; | |||||
import org.sonar.check.IsoCategory; | |||||
import org.sonar.check.Priority; | |||||
@Check(isoCategory = IsoCategory.Efficiency, priority = Priority.CRITICAL) | |||||
class CheckerWithoutProperties { | |||||
} |
/* | |||||
* 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.api.checks.profiles; | package org.sonar.api.checks.profiles; | ||||
import org.hamcrest.BaseMatcher; | import org.hamcrest.BaseMatcher; | ||||
import org.hamcrest.Description; | import org.hamcrest.Description; | ||||
import org.junit.Test; | import org.junit.Test; | ||||
import org.sonar.check.BelongsToProfile; | |||||
import org.sonar.check.BelongsToProfiles; | |||||
import org.sonar.check.IsoCategory; | |||||
import org.sonar.check.Priority; | import org.sonar.check.Priority; | ||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import static org.junit.Assert.assertThat; | import static org.junit.Assert.assertThat; | ||||
import static org.junit.internal.matchers.IsCollectionContaining.hasItem; | import static org.junit.internal.matchers.IsCollectionContaining.hasItem; | ||||
/** | |||||
* Created by IntelliJ IDEA. | |||||
* User: simonbrandhof | |||||
* Date: Sep 14, 2010 | |||||
* Time: 11:02:28 AM | |||||
* To change this template use File | Settings | File Templates. | |||||
*/ | |||||
public class AnnotationCheckProfileFactoryTest { | public class AnnotationCheckProfileFactoryTest { | ||||
@Test | @Test | ||||
} | } | ||||
} | } | ||||
@org.sonar.check.Check(priority = Priority.BLOCKER, isoCategory = IsoCategory.Maintainability) | |||||
@BelongsToProfile(title = "profile one", priority = Priority.MINOR) | |||||
class FakeCheckOne { | |||||
} | |||||
@org.sonar.check.Check(priority = Priority.BLOCKER, isoCategory = IsoCategory.Maintainability) | |||||
@BelongsToProfiles({ | |||||
@BelongsToProfile(title = "profile two", priority = Priority.INFO), | |||||
@BelongsToProfile(title = "profile one", priority = Priority.MINOR) | |||||
}) | |||||
class FakeCheckTwo { | |||||
} | |||||
class CheckProfileMatcher extends BaseMatcher<CheckProfile> { | class CheckProfileMatcher extends BaseMatcher<CheckProfile> { | ||||
private String name; | private String name; | ||||
private int numberOfChecks; | private int numberOfChecks; |
package org.sonar.api.checks.profiles; | |||||
import org.sonar.check.BelongsToProfile; | |||||
import org.sonar.check.IsoCategory; | |||||
import org.sonar.check.Priority; | |||||
/** | |||||
* Created by IntelliJ IDEA. | |||||
* User: simonbrandhof | |||||
* Date: Sep 14, 2010 | |||||
* Time: 11:02:28 AM | |||||
* To change this template use File | Settings | File Templates. | |||||
*/ | |||||
@org.sonar.check.Check(priority = Priority.BLOCKER, isoCategory = IsoCategory.Maintainability) | |||||
@BelongsToProfile(title = "profile one", priority = Priority.MINOR) | |||||
class FakeCheckOne { | |||||
} |
package org.sonar.api.checks.profiles; | |||||
import org.sonar.check.BelongsToProfile; | |||||
import org.sonar.check.BelongsToProfiles; | |||||
import org.sonar.check.IsoCategory; | |||||
import org.sonar.check.Priority; | |||||
/** | |||||
* Created by IntelliJ IDEA. | |||||
* User: simonbrandhof | |||||
* Date: Sep 14, 2010 | |||||
* Time: 11:02:28 AM | |||||
* To change this template use File | Settings | File Templates. | |||||
*/ | |||||
@org.sonar.check.Check(priority = Priority.BLOCKER, isoCategory = IsoCategory.Maintainability) | |||||
@BelongsToProfiles({ | |||||
@BelongsToProfile(title = "profile two", priority = Priority.INFO), | |||||
@BelongsToProfile(title = "profile one", priority = Priority.MINOR) | |||||
}) | |||||
class FakeCheckTwo { | |||||
} |
ProfileImporter importer = getProfileImporter(importerKey); | ProfileImporter importer = getProfileImporter(importerKey); | ||||
RulesProfile profile = importer.importProfile(new StringReader(profileDefinition), messages); | RulesProfile profile = importer.importProfile(new StringReader(profileDefinition), messages); | ||||
if (!messages.hasErrors()) { | if (!messages.hasErrors()) { | ||||
profile.setName(profileName); | |||||
profile.setLanguage(language); | |||||
DatabaseSession session = sessionFactory.getSession(); | DatabaseSession session = sessionFactory.getSession(); | ||||
session.saveWithoutFlush(profile); | session.saveWithoutFlush(profile); | ||||
session.commit(); | session.commit(); |