Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added test for lint mojo. Too much logic without test

  • Loading branch information...
commit 6fd24854620f443f4142c88bc5132af67c7e240f 1 parent 6e39686
@stephanenicolas stephanenicolas authored
View
11 .checkstyle
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="true">
+ <local-check-config name="maven_checks" location="/Users/stephanenicolas/git/maven-android-plugin/src/conf/maven_checks.xml" type="external" description="">
+ <property name="checkstyle.cache.file" value=".checkstyle-cache"/>
+ <additional-data name="protect-config-file" value="false"/>
+ </local-check-config>
+ <fileset name="all" enabled="true" check-config-name="maven_checks" local="true">
+ <file-match-pattern match-pattern="." include-pattern="true"/>
+ </fileset>
+</fileset-config>
View
4 src/conf/maven_checks.xml
@@ -163,8 +163,8 @@ Android Maven Plugin uses the APL v2 but with copyright mentions -->
<!-- Checks for common coding problems -->
<!-- See http://checkstyle.sf.net/config_coding.html -->
- <!-- module name="AvoidInlineConditionals"/ -->
- <module name="DoubleCheckedLocking"/>
+ <!-- module name="AvoidInlineConditionals"/
+ <module name="DoubleCheckedLocking"/> -->
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="HiddenField">
View
60 src/main/java/com/jayway/maven/plugins/android/standalonemojos/LintMojo.java
@@ -26,6 +26,7 @@
* @goal lint
* @requiresProject false
*/
+@SuppressWarnings( "unused" )
public class LintMojo extends AbstractAndroidMojo
{
@@ -142,7 +143,7 @@
*/
private String lintConfig;
- @PullParameter( defaultValue = "null" )
+ @PullParameter( defaultValueGetterMethod = "getConfig" )
private String parsedConfig;
// ---------------
@@ -234,7 +235,7 @@
* Create a simple HTML report. If the filename is a directory (or a new filename without an extension), lint will
* create a separate report for each scanned project. Defaults to ${project.build.directory}/lint-simple-html/.
*
- * @parameter expression="${android.lint.simpleHtml}"
+ * @parameter expression="${android.lint.simpleHtmlOutputPath}"
* @see com.jayway.maven.plugins.android.configuration.Lint#simpleHtml
*/
private String lintSimpleHtmlOutputPath;
@@ -250,15 +251,15 @@
*/
private Boolean lintEnableXml;
- @PullParameter( defaultValue = "false" )
+ @PullParameter( defaultValue = "true" )
private Boolean parsedEnableXml;
/**
* Create an XML report. If the filename is a directory (or a new filename without an extension), lint will create a
* separate report for each scanned project. Defaults to ${project.build.directory}/lint.xml.
*
- * @parameter expression="${android.lint.xml}"
- * @see com.jayway.maven.plugins.android.configuration.Lint#xml
+ * @parameter expression="${android.lint.xmlOutputPath}"
+ * @see com.jayway.maven.plugins.android.configuration.Lint#xmlOutputPath
*/
private String lintXmlOutputPath;
@@ -308,10 +309,6 @@
@PullParameter( defaultValueGetterMethod = "getLibraries" )
private String parsedLibraries;
- private File htmlPath;
- private File simpleHtmlPath;
- private File xmlPath;
-
/**
* Execute the mojo by parsing the config and actually doing the lint.
*
@@ -460,13 +457,23 @@ public void execute() throws MojoExecutionException, MojoFailureException
}
// used via PullParameter annotation - do not remove
+ private String getConfig()
+ {
+ if ( parsedConfig == null )
+ {
+ return new File( project.getBuild().getDirectory(), "lint.xml" ).getAbsolutePath();
+ }
+ return parsedConfig;
+ }
+
+ // used via PullParameter annotation - do not remove
private String getHtmlOutputPath()
{
if ( parsedHtmlOutputPath == null )
{
- htmlPath = new File( project.getBuild().getDirectory(), "lint-html" );
+ return new File( project.getBuild().getDirectory(), "lint-html" ).getAbsolutePath();
}
- return htmlPath.getAbsolutePath();
+ return parsedHtmlOutputPath;
}
// used via PullParameter annotation - do not remove
@@ -474,19 +481,21 @@ private String getSimpleHtmlOutputPath()
{
if ( parsedSimpleHtmlOutputPath == null )
{
- simpleHtmlPath = new File( project.getBuild().getDirectory(), "lint-simple-html" );
+ return new File( project.getBuild().getDirectory(), "lint-simple-html" ).getAbsolutePath();
}
- return simpleHtmlPath.getAbsolutePath();
+ return parsedSimpleHtmlOutputPath;
}
// used via PullParameter annotation - do not remove
private String getXmlOutputPath()
{
+ getLog().debug( "get parsed xml output path:" + parsedXmlOutputPath );
+
if ( parsedXmlOutputPath == null )
{
- xmlPath = new File( project.getBuild().getDirectory(), "lint.xml" );
+ return new File( project.getBuild().getDirectory(), "lint.xml" ).getAbsolutePath();
}
- return xmlPath.getAbsolutePath();
+ return parsedXmlOutputPath;
}
// used via PullParameter annotation - do not remove
@@ -515,18 +524,21 @@ private String getLibraries()
{
StringBuilder defaultClasspathBuilder = new StringBuilder();
Set< Artifact > artifacts = project.getDependencyArtifacts();
- for ( Artifact artifact : artifacts )
+ if ( artifacts != null )
{
- if ( !Artifact.SCOPE_PROVIDED.equals( artifact.getScope() ) && artifact.isResolved() )
+ for ( Artifact artifact : artifacts )
{
- defaultClasspathBuilder.append( artifact.getFile().getPath() );
- defaultClasspathBuilder.append( File.pathSeparator );
+ if ( !Artifact.SCOPE_PROVIDED.equals( artifact.getScope() ) && artifact.isResolved() )
+ {
+ defaultClasspathBuilder.append( artifact.getFile().getPath() );
+ defaultClasspathBuilder.append( File.pathSeparator );
+ }
+ }
+ if ( defaultClasspathBuilder.length() > 0 )
+ {
+ defaultClasspathBuilder.deleteCharAt( defaultClasspathBuilder.length() - 1 );
+ parsedLibraries = defaultClasspathBuilder.toString();
}
- }
- if ( defaultClasspathBuilder.length() > 0 )
- {
- defaultClasspathBuilder.deleteCharAt( defaultClasspathBuilder.length() - 1 );
- parsedLibraries = defaultClasspathBuilder.toString();
}
}
return parsedLibraries;
View
56 src/test/java/com/jayway/maven/plugins/android/standalonemojos/LintMojoTest.java
@@ -0,0 +1,56 @@
+package com.jayway.maven.plugins.android.standalonemojos;
+
+import java.io.File;
+
+import org.apache.maven.project.MavenProject;
+import org.powermock.reflect.Whitebox;
+
+import com.jayway.maven.plugins.android.AbstractAndroidMojoTestCase;
+import com.jayway.maven.plugins.android.config.ConfigHandler;
+
+public class LintMojoTest extends AbstractAndroidMojoTestCase< LintMojo >
+{
+ @Override
+ public String getPluginGoalName()
+ {
+ return "lint";
+ }
+
+ public void testDefaultLintConfig() throws Exception
+ {
+ LintMojo mojo = createMojo( "lint-config-project1" );
+ final ConfigHandler cfh = new ConfigHandler( mojo );
+ cfh.parseConfiguration();
+ MavenProject project = Whitebox.getInternalState( mojo, "project" );
+
+ Boolean lintSkip = Whitebox.getInternalState( mojo, "parsedSkip" );
+ Boolean lintFailOnError = Whitebox.getInternalState( mojo, "parsedFailOnError" );
+ Boolean lintIgnoreWarnings = Whitebox.getInternalState( mojo, "parsedIgnoreWarnings" );
+ Boolean lintWarnAll = Whitebox.getInternalState( mojo, "parsedWarnAll" );
+ Boolean lintWarningsAsErrors = Whitebox.getInternalState( mojo, "parsedWarningsAsErrors" );
+ String lintConfig = Whitebox.getInternalState( mojo, "parsedConfig" );
+
+ // TODO finish all default settings tests
+ Boolean lintEnableXml = Whitebox.getInternalState( mojo, "parsedEnableXml" );
+ Boolean lintEnableHtml = Whitebox.getInternalState( mojo, "parsedEnableHtml" );
+ Boolean lintEnableSimpleHtml = Whitebox.getInternalState( mojo, "parsedEnableSimpleHtml" );
+
+ assertTrue( "lint skip parameter should be false", lintSkip );
+ assertFalse( "lint failOnError parameter should be false", lintFailOnError );
+ assertFalse( "lint ignoreWarning parameter should be false", lintFailOnError );
+ assertFalse( "lint warnAll parameter should be false", lintFailOnError );
+ assertFalse( "lint warningsAsErrors parameter should be false", lintFailOnError );
+ assertNotNull( "lint config parameter should be false", lintConfig );
+ File lintConfigFile = new File( project.getBuild().getDirectory(), "lint.xml" );
+ assertEquals( "lint config parameter should point to lint.xml", lintConfig, lintConfigFile.getAbsolutePath() );
+
+ assertTrue( "lint enableXml parameter should be true", lintEnableXml );
+ assertFalse( "lint enableHtml parameter should be false", lintEnableHtml );
+ assertFalse( "lint enableSimplHtml parameter should be false", lintEnableSimpleHtml );
+ }
+
+ // TODO add test where all default values are overridden
+
+ // TODO test the mojo logic with a mock executor and check parameters
+
+}
View
17 src/test/resources/lint-config-project1/plugin-config.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0"?>
+<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>
+ <groupId>com.jayway.maven.plugins.android.tests</groupId>
+ <artifactId>lint-config-project1</artifactId>
+ <version>15.4.3.1011</version>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>android-maven-plugin</artifactId>
+ <!-- no lint config -->
+ <configuration/>
+ </plugin>
+ </plugins>
+ </build>
+</project>
View
20 src/test/resources/lint-configuration-2/plugin-config.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0"?>
+<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>
+ <groupId>com.jayway.maven.plugins.android.tests</groupId>
+ <artifactId>lint-config-project1</artifactId>
+ <version>15.4.3.1011</version>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>android-maven-plugin</artifactId>
+ <configuration>
+ <lint>
+ <skip>false</skip>
+ </lint>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Please sign in to comment.
Something went wrong with that request. Please try again.