Android Open Source - masa Lint Mojo






From Project

Back to project page masa.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUC...

If you think the Android project masa listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.jvending.masa.plugin.lint;
//from   w ww. j a  va 2 s.  c o  m
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.jvending.masa.CommandExecutor;
import org.jvending.masa.ExecutionException;
import org.jvending.masa.MasaUtil;

/**
 *
 * @goal verify
 * 
 * @phase process-sources
 */
public class LintMojo
    extends AbstractMojo
{

    /**
     * The maven project.
     * 
     * @parameter expression="${project}"
     */
    public MavenProject project;

    /**
     * @parameter expression="${session}
     */
    public MavenSession session;

    /**
     * @parameter
     */
    public File config;

    /**
     * @parameter
     */
    public String disable;

    /**
     * @parameter
     */
    public String enable;

    /**
     * @parameter
     */
    public String check;

    /**
     * @parameter default-value="false"
     */
    public boolean disableConfigFile;

    /**
     * @parameter default-value="true"
     */
    public boolean generateHtml;

    /**
     * @parameter default-value="false"
     */
    public boolean generateXml;

    /**
     * @parameter default-value="false"
     */
    public boolean noWarn;

    /**
     * @parameter default-value="true"
     */
    public boolean quiet;

    /**
     * @parameter default-value="false"
     */
    public boolean noLines;

    /**
     * @parameter default-value="false"
     */
    public boolean fullPath;

    private File target;

    public void execute()
        throws MojoExecutionException
    {

        if ( !generateHtml && !generateXml )
        {
            throw new MojoExecutionException(
                                              "Must specify generateXml and/or generateHtml parameters as true. Check your plugin configuration." );
        }

        target = new File( project.getBuild().getDirectory(), "lint" );
        if ( !target.exists() )
        {
            target.mkdirs();
        }

        /*
        try
        {
            copyResourceFilesToTargetDir();
            copySourceFilesToTargetDir();
        }
        catch ( IOException e )
        {
            throw new MojoExecutionException( "Failed to copy source files to target directory.", e );
        }
*/
        if ( generateHtml )
        {
            List<String> commands = new ArrayList<String>();
            commands.add( "--html" );
            commands.add( new File( target, "index.html" ).getAbsolutePath() );
            executeLint( commands );
        }

        if ( generateXml )
        {
            List<String> commands = new ArrayList<String>();
            commands.add( "--xml" );
            commands.add( new File( target, "lint-report.xml" ).getAbsolutePath() );
            executeLint( commands );
        }
    }

    private void executeLint( Collection<String> args )
        throws MojoExecutionException
    {
        CommandExecutor executor = CommandExecutor.Factory.createDefaultCommmandExecutor();
        executor.setLogger( getLog() );

        List<String> commands = new ArrayList<String>();

        if ( getLintFile().exists() && !disableConfigFile )
        {
            commands.add( "--config" );
            commands.add( getLintFile().getAbsolutePath() );
        }

        if ( noLines )
        {
            commands.add( "--nolines" );
        }

        if ( quiet )
        {
            commands.add( "--quiet" );
        }

        if ( noWarn )
        {
            commands.add( "--nowarn" );
        }

        if ( fullPath )
        {
            commands.add( "--fullpath" );
        }

        if ( disable != null )
        {
            commands.add( "--disable" );
            commands.add( disable );
        }

        if ( enable != null )
        {
            commands.add( "--enable" );
            commands.add( enable );
        }

        if ( check != null )
        {
            commands.add( "--check" );
            commands.add( check );
        }

        commands.addAll( args );
        commands.add( project.getBasedir().getAbsolutePath() );
        
        //commands.add( target.getAbsolutePath() );

        String lintCommand = MasaUtil.getToolnameWithPath( session, project, "lint" );
        getLog().info( lintCommand + ":" + commands.toString() );
        try
        {
            executor.executeCommand( lintCommand, commands, project.getBasedir(), false );
        }
        catch ( ExecutionException e )
        {
            throw new MojoExecutionException( "", e );
        }
    }

    private File getLintFile()
    {
        return ( config != null && config.exists() ) ? config : new File( project.getBasedir(), "lint.xml" );
    }

    private void copyResourceFilesToTargetDir()
        throws IOException
    {
        for ( Resource res : (List<Resource>) project.getResources() )
        {
            File resDir = new File( res.getDirectory() );
            FileUtils.copyDirectory( resDir, new File( target, resDir.getName() ) );
        }
        
        File manifest = new File(project.getBasedir(), "AndroidManifest.xml");
        FileUtils.copyFileToDirectory( manifest, target );
    }

    private void copySourceFilesToTargetDir()
        throws IOException
    {
        for ( String src : (List<String>) project.getCompileSourceRoots() )
        {
            File srcDir = new File( src );
            FileUtils.copyDirectory( srcDir, new File( target, srcDir.getName() ) );
        }
        
        File srcDir = new File( project.getBuild().getDirectory(), "classes" );
        FileUtils.copyDirectoryStructure( srcDir, new File( target, "classes" ) );
       
        srcDir = new File( project.getBuild().getDirectory(), "gen-mvn" );
        FileUtils.copyDirectoryStructure( srcDir, new File( target, "classes" ) );        
    }
}




Java Source Code List

org.apache.maven.plugin.surefire.report.AndroidReportConfiguration.java
org.apache.maven.plugin.surefire.report.AndroidXmlReporter.java
org.apache.maven.surefire.android.TestRunnerCoreProvider.java
org.apache.maven.surefire.android.reporting.AndroidReportEntry.java
org.jvending.masa.ApkInstaller.java
org.jvending.masa.ApplicationRequirements.java
org.jvending.masa.CommandExecutor.java
org.jvending.masa.ExecutionException.java
org.jvending.masa.MasaUtil.java
org.jvending.masa.ddmlib.AdbConnector.java
org.jvending.masa.ddmlib.ConnectionException.java
org.jvending.masa.plugin.aapt.AaptCompilerMojo.java
org.jvending.masa.plugin.aapt.AaptPackagerMojo.java
org.jvending.masa.plugin.aapt.LibraryPackagerMojo.java
org.jvending.masa.plugin.aapt.LibraryResourceProcessorMojo.java
org.jvending.masa.plugin.adb.DeviceInstallerMojo.java
org.jvending.masa.plugin.adb.DevicePullerMojo.java
org.jvending.masa.plugin.adb.DevicePusherMojo.java
org.jvending.masa.plugin.aidl.AidlGeneratorMojo.java
org.jvending.masa.plugin.apkbuilder.ApkBuilderMojo.java
org.jvending.masa.plugin.apkbuilder.ApkVerifierMojo.java
org.jvending.masa.plugin.apkbuilder.KeystoreInfo.java
org.jvending.masa.plugin.apkbuilder.NativeLibraries.java
org.jvending.masa.plugin.apkbuilder.PrivateKeyInfo.java
org.jvending.masa.plugin.apkbuilder.X509Cert.java
org.jvending.masa.plugin.dx.DxMojo.java
org.jvending.masa.plugin.jarsigner.JarSignerMojo.java
org.jvending.masa.plugin.lint.LintMojo.java
org.jvending.masa.plugin.localization.CopyResourcesMojo.java
org.jvending.masa.plugin.platformtest.ApkInstallerMojo.java
org.jvending.masa.plugin.platformtest.PlatformTesterMojo.java
org.jvending.masa.plugin.proguard.ProguardMojo.java
org.jvending.masa.plugin.zipalign.ZipAlignMojo.java
org.jvending.masa.plugins.toolchains.Capability.java
org.jvending.masa.plugins.toolchains.Matcher.java
org.jvending.masa.plugins.toolchains.ToolchainMojo.java
org.jvending.masa.plugins.toolchains.Toolchains.java
org.maven.reslinks.plugin.ResourceLinkerMojo.java
${package}.App.java