Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.apache.maven.plugin.nar;
  
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
  *
  *  http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
  */
 
 import java.io.File;
 import java.util.List;
 import java.util.Set;
 
 import  org.apache.bcel.classfile.ClassFormatException;
 import  org.apache.bcel.classfile.JavaClass;
 import  org.apache.bcel.classfile.Method;
Sets up the javah configuration

Author(s):
Mark Donszelmann
 
 public class Javah
 {

    
Javah command to run.

Parameter:
default-value="javah"
 
     private String name = "javah";

    
Add boot class paths. By default none.

Parameter:
 
     private List/* <File> */bootClassPaths = new ArrayList();

    
Add class paths. By default the classDirectory directory is included and all dependent classes.

Parameter:
 
     private List/* <File> */classPaths = new ArrayList();

    
The target directory into which to generate the output.

Parameter:
expression="${project.build.directory}/nar/javah-include"
Required:
 
     private File jniDirectory;

    
The class directory to scan for class files with native interfaces.

Parameter:
expression="${project.build.directory}/classes"
Required:
 
     private File classDirectory;

    
The set of files/patterns to include Defaults to "**\/*.class"

Parameter:
 
     private Set includes = new HashSet();

    
A list of exclusion filters.

Parameter:
    private Set excludes = new HashSet();

    
The granularity in milliseconds of the last modification date for testing whether a source needs recompilation

Parameter:
default-value="0"
Required:
    private int staleMillis = 0;

    
The directory to store the timestampfile for the processed aid files. Defaults to jniDirectory.

Parameter:
    private File timestampDirectory;

    
The timestampfile for the processed class files. Defaults to name of javah.

Parameter:
    private File timestampFile;
    private AbstractCompileMojo mojo;
    public Javah()
    {
    }
    public final void setAbstractCompileMojoAbstractCompileMojo mojo )
    {
        this. = mojo;
    }
    protected final List getClassPaths()
        throws MojoExecutionException
    {
        if ( .isEmpty() )
        {
            try
            {
                .addAll.getMavenProject().getCompileClasspathElements() );
            }
            catch ( DependencyResolutionRequiredException e )
            {
                throw new MojoExecutionException"JAVAH, cannot get classpath"e );
            }
        }
        return ;
    }
    protected final File getJniDirectory()
    {
        if (  == null )
        {
             = new File.getMavenProject().getBuild().getDirectory(), "nar/javah-include" );
        }
        return ;
    }
    protected final File getClassDirectory()
    {
        if (  == null )
        {
             = new File.getMavenProject().getBuild().getDirectory(), "classes" );
        }
        return ;
    }
    protected final Set getIncludes()
    {
        if ( .isEmpty() )
        {
            .add"**/*.class" );
        }
        return ;
    }
    protected final File getTimestampDirectory()
    {
        if (  == null )
        {
             = getJniDirectory();
        }
        return ;
    }
    protected final File getTimestampFile()
    {
        if (  == null )
        {
             = new File );
        }
        return ;
    }
    public final void execute()
    {
        getClassDirectory().mkdirs();
        try
        {
            SourceInclusionScanner scanner = new StaleSourceScannergetIncludes(),  );
            if ( getTimestampDirectory().exists() )
            {
                scanner.addSourceMappingnew SingleTargetSourceMapping".class"getTimestampFile().getPath() ) );
            }
            else
            {
                scanner.addSourceMappingnew SuffixMapping".class"".dummy" ) );
            }
            Set classes = scanner.getIncludedSourcesgetClassDirectory(), getTimestampDirectory() );
            if ( !classes.isEmpty() )
            {
                Set files = new HashSet();
                for ( Iterator i = classes.iterator(); i.hasNext(); )
                {
                    String file = ( (Filei.next() ).getPath();
                    JavaClass clazz = NarUtil.getBcelClassfile );
                    Method[] method = clazz.getMethods();
                    for ( int j = 0; j < method.length; j++ )
                    {
                        if ( method[j].isNative() )
                        {
                            files.addclazz.getClassName() );
                        }
                    }
                }
                if ( !files.isEmpty() )
                {
                    getJniDirectory().mkdirs();
                    getTimestampDirectory().mkdirs();
                    String javah = getJavah();
                    
                    .getLog().info"Running " + javah + " compiler on " + files.size() + " classes..." );
                    int result = NarUtil.runCommandjavahgenerateArgsfiles ), nullnull.getLog() );
                    if ( result != 0 )
                    {
                        throw new MojoFailureExceptionjavah + " failed with exit code " + result + " 0x"
                            + Integer.toHexStringresult ) );
                    }
                    FileUtils.fileWritegetTimestampDirectory() + "/" + getTimestampFile(), "" );
                }
            }
        }
        catch ( InclusionScanException e )
        {
            throw new MojoExecutionException"JAVAH: Class scanning failed"e );
        }
        catch ( IOException e )
        {
            throw new MojoExecutionException"JAVAH: IO Exception"e );
        }
        catch ( ClassFormatException e )
        {
            throw new MojoExecutionException"JAVAH: Class could not be inspected"e );
        }
    }
    private String[] generateArgsSet/* <String> */classes )
        throws MojoExecutionException
    {
        List args = new ArrayList();
        if ( !.isEmpty() )
        {
            args.add"-bootclasspath" );
            args.add( StringUtils.join.iterator(), . ) );
        }
        args.add"-classpath" );
        args.add( StringUtils.joingetClassPaths().iterator(), . ) );
        args.add"-d" );
        args.addgetJniDirectory().getPath() );
        if ( .getLog().isDebugEnabled() )
        {
            args.add"-verbose" );
        }
        if ( classes != null )
        {
            for ( Iterator i = classes.iterator(); i.hasNext(); )
            {
                args.addi.next() );
            }
        }
        return (String[]) args.toArraynew String[args.size()] );
    }
    
        String javah = null;
        // try toolchain
        Toolchain toolchain = getToolchain();
        if (toolchain != null) {
            javah = toolchain.findTool"javah" );
        }
        // try java home
        if (javah == null) {
            File javahFile = new File.getJavaHome.getAOL() ), "bin" );
            javah = new FilejavahFile ).getAbsolutePath();
        }
        
        // forget it...
        if (javah == null) {
            throw new MojoExecutionException"NAR: Cannot find 'javah' in Toolchain or on JavaHome" );
        }
        
        return javah;
    }
    
    //TODO remove the part with ToolchainManager lookup once we depend on
    //2.0.9 (have it as prerequisite). Define as regular component field then.
    private Toolchain getToolchain()
    {
        Toolchain toolChain = null;
        ToolchainManager toolchainManager = ((NarJavahMojo)).getToolchainManager();
        
        if ( toolchainManager != null )
        {
            toolChain = toolchainManager.getToolchainFromBuildContext"jdk", ((NarJavahMojo)).getSession() );
        }
        return toolChain;
    }
New to GrepCode? Check out our FAQ X