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;
 
 
Abstract Compiler class

Author(s):
Mark Donszelmann
 
 public abstract class Compiler
 {

    
The name of the compiler. Some choices are: "msvc", "g++", "gcc", "CC", "cc", "icc", "icpc", ... Default is Architecture-OS-Linker specific: FIXME: table missing

Parameter:
expression=""
 
     private String name;

    
Source directory for native files

Parameter:
expression="${basedir}/src/main"
Required:
 
     private File sourceDirectory;

    
Source directory for native test files

Parameter:
expression="${basedir}/src/test"
Required:
 
     private File testSourceDirectory;

    
Include patterns for sources

Parameter:
expression=""
Required:
 
     private Set includes = new HashSet();

    
Exclude patterns for sources

Parameter:
expression=""
Required:
 
     private Set excludes = new HashSet();

    
Compile with debug information.

Parameter:
expression="" default-value="false"
Required:
 
     private boolean debug = false;

    
Enables generation of exception handling code.

Parameter:
expression="" default-value="true"
Required:
    private boolean exceptions = true;

    
Enables run-time type information.

Parameter:
expression="" default-value="true"
Required:
    private boolean rtti = true;

    
Sets optimization. Possible choices are: "none", "size", "minimal", "speed", "full", "aggressive", "extreme", "unsafe".

Parameter:
expression="" default-value="none"
Required:
    private String optimize = "none";

    
Enables or disables generation of multi-threaded code. Default value: false, except on Windows.

Parameter:
expression="" default-value="false"
Required:
    private boolean multiThreaded = false;

    
Defines

Parameter:
expression=""
    private List defines;

    
Defines for the compiler as a comma separated list of name[=value] pairs, where the value is optional. Will work in combination with <defines>.

Parameter:
expression=""
    private String defineSet;

    
Clears default defines

Parameter:
expression="" default-value="false"
Required:
    private boolean clearDefaultDefines;

    
Undefines

Parameter:
expression=""
    private List undefines;

    
Undefines for the compiler as a comma separated list of name[=value] pairs where the value is optional. Will work in combination with <undefines>.

Parameter:
expression=""
    private String undefineSet;

    
Clears default undefines

Parameter:
expression="" default-value="false"
Required:
    private boolean clearDefaultUndefines;

    
Include Paths. Defaults to "${sourceDirectory}/include"

Parameter:
expression=""
    private List includePaths;

    
Test Include Paths. Defaults to "${testSourceDirectory}/include"

Parameter:
expression=""
    private List testIncludePaths;

    
System Include Paths, which are added at the end of all include paths

Parameter:
expression=""
    private List systemIncludePaths;

    
Additional options for the C++ compiler Defaults to Architecture-OS-Linker specific values. FIXME table missing

Parameter:
expression=""
    private List options;

    
Options for the compiler as a whitespace separated list. Will work in combination with <options>.

Parameter:
expression=""
    private String optionSet;

    
Clears default options

Parameter:
expression="" default-value="false"
Required:
    private boolean clearDefaultOptions;

    
Comma separated list of filenames to compile in order

Parameter:
expression=""
    private String compileOrder;
    private AbstractCompileMojo mojo;
    public static final String MAIN = "main";
    public static final String TEST = "test";
    protected Compiler()
    {
    }
    public String getName()
    {
        // adjust default values
        if (  == null )
        {
             = NarProperties.getInstance(.getMavenProject()).getPropertygetPrefix() + "compiler" );
        }
        return ;
    }
    public final void setAbstractCompileMojoAbstractCompileMojo mojo )
    {
        this. = mojo;
    }
    public final List/* <File> */getSourceDirectories()
    {
        return getSourceDirectories"dummy" );
    }
    private List/* <File> */getSourceDirectoriesString type )
    {
        List sourceDirectories = new ArrayList();
        File baseDir = .getMavenProject().getBasedir();
        if ( type.equals ) )
        {
            if (  == null )
            {
                 = new FilebaseDir"/src/test" );
            }
            if ( .exists() )
            {
                sourceDirectories.add );
            }
            for ( Iterator i = .getMavenProject().getTestCompileSourceRoots().iterator(); i.hasNext(); )
            {
                File extraTestSourceDirectory = new File( (Stringi.next() );
                if ( extraTestSourceDirectory.exists() )
                {
                    sourceDirectories.addextraTestSourceDirectory );
                }
            }
        }
        else
        {
            if (  == null )
            {
                 = new FilebaseDir"src/main" );
            }
            if ( .exists() )
            {
                sourceDirectories.add );
            }
            for ( Iterator i = .getMavenProject().getCompileSourceRoots().iterator(); i.hasNext(); )
            {
                File extraSourceDirectory = new File( (Stringi.next() );
                if ( extraSourceDirectory.exists() )
                {
                    sourceDirectories.addextraSourceDirectory );
                }
            }
        }
        if ( .getLog().isDebugEnabled() )
        {
            for ( Iterator i = sourceDirectories.iterator(); i.hasNext(); )
            {
                .getLog().debug"Added to sourceDirectory: " + ( (Filei.next() ).getPath() );
            }
        }
        return sourceDirectories;
    }
    protected final List/* <String> */getIncludePathsString type )
    {
        return createIncludePathstypetype.equals ) ?  :  );
    }
    private List/* <String> */createIncludePathsString typeList paths )
    {
        List includeList = paths;
        if ( includeList == null || ( paths.size() == 0 ) )
        {
            includeList = new ArrayList();
            for ( Iterator i = getSourceDirectoriestype ).iterator(); i.hasNext(); )
            {
		//VR 20100318 only add include directories that exist - we now fail the build fast if an include directory does not exist 
                File includePath = new File( (Filei.next(), "include" );
                if(includePath.isDirectory()) {
                	includeList.addincludePath.getPath() );
                }
            }
        }
        return includeList;
    }
    public final Set getIncludes()
    {
        return getIncludes"main" );
    }
    protected final Set getIncludesString type )
    {
        Set result = new HashSet();
        if ( !type.equals ) && !.isEmpty() )
        {
            result.addAll );
        }
        else
        {
            String defaultIncludes = NarProperties.getInstance(.getMavenProject()).getPropertygetPrefix() + "includes" );
            if ( defaultIncludes != null )
            {
                String[] include = defaultIncludes.split" " );
                for ( int i = 0; i < include.lengthi++ )
                {
                    result.addinclude[i].trim() );
                }
            }
        }
        return result;
    }
    protected final Set getExcludes()
    {
        Set result = new HashSet();
        // add all excludes
        if ( .isEmpty() )
        {
            String defaultExcludes = NarProperties.getInstance(.getMavenProject()).getPropertygetPrefix() + "excludes" );
            if ( defaultExcludes != null )
            {
                String[] exclude = defaultExcludes.split" " );
                for ( int i = 0; i < exclude.lengthi++ )
                {
                    result.addexclude[i].trim() );
                }
            }
        }
        else
        {
            result.addAll );
        }
        return result;
    }
    protected final String getPrefix()
    {
        return .getAOL().getKey() + "." + getLanguage() + ".";
    }
    public final CompilerDef getCompilerString typeString output )
    {
        String name = getName();
        if (name == nullreturn null;
        
        CompilerDef compiler = new CompilerDef();
        compiler.setProject( .getAntProject() );
        CompilerEnum compilerName = new CompilerEnum();
        compilerName.setValuename );
        compiler.setNamecompilerName );
        // debug, exceptions, rtti, multiThreaded
        compiler.setDebug );
        compiler.setExceptions );
        compiler.setRtti );
        compiler.setMultithreaded.getOS().equals"Windows" ) ? true :  );
        // optimize
        OptimizationEnum optimization = new OptimizationEnum();
        optimization.setValue );
        compiler.setOptimizeoptimization );
        // add options
        if (  != null )
        {
            for ( Iterator i = .iterator(); i.hasNext(); )
            {
                CompilerArgument arg = new CompilerArgument();
                arg.setValue( (Stringi.next() );
                compiler.addConfiguredCompilerArgarg );
            }
        }
        if (  != null )
        {
            String[] opts = .split"\\s" );
            for ( int i = 0; i < opts.lengthi++ )
            {
                CompilerArgument arg = new CompilerArgument();
                arg.setValueopts[i] );
                compiler.addConfiguredCompilerArgarg );
            }
        }
        if ( ! )
        {
            String optionsProperty = NarProperties.getInstance(.getMavenProject()).getPropertygetPrefix() + "options" );
            if ( optionsProperty != null )
            {
                String[] option = optionsProperty.split" " );
                for ( int i = 0; i < option.lengthi++ )
                {
                    CompilerArgument arg = new CompilerArgument();
                    arg.setValueoption[i] );
                    compiler.addConfiguredCompilerArgarg );
                }
            }
        }
        // add defines
        if (  != null )
        {
            DefineSet ds = new DefineSet();
            for ( Iterator i = .iterator(); i.hasNext(); )
            {
                DefineArgument define = new DefineArgument();
                String[] pair = ( (Stringi.next() ).split"=", 2 );
                define.setNamepair[0] );
                define.setValuepair.length > 1 ? pair[1] : null );
                ds.addDefinedefine );
            }
            compiler.addConfiguredDefinesetds );
        }
        if (  != null )
        {
            String[] defList = .split"," );
            DefineSet defSet = new DefineSet();
            for ( int i = 0; i < defList.lengthi++ )
            {
                String[] pair = defList[i].trim().split"=", 2 );
                DefineArgument def = new DefineArgument();
                def.setNamepair[0] );
                def.setValuepair.length > 1 ? pair[1] : null );
                defSet.addDefinedef );
            }
            compiler.addConfiguredDefinesetdefSet );
        }
        if ( ! )
        {
            DefineSet ds = new DefineSet();
            String defaultDefines = NarProperties.getInstance(.getMavenProject()).getPropertygetPrefix() + "defines" );
            if ( defaultDefines != null )
            {
                ds.setDefinenew CUtil.StringArrayBuilderdefaultDefines ) );
            }
            compiler.addConfiguredDefinesetds );
        }
        // add undefines
        if (  != null )
        {
            DefineSet us = new DefineSet();
            for ( Iterator i = .iterator(); i.hasNext(); )
            {
                DefineArgument undefine = new DefineArgument();
                String[] pair = ( (Stringi.next() ).split"=", 2 );
                undefine.setNamepair[0] );
                undefine.setValuepair.length > 1 ? pair[1] : null );
                us.addUndefineundefine );
            }
            compiler.addConfiguredDefinesetus );
        }
        if (  != null )
        {
            String[] undefList = .split"," );
            DefineSet undefSet = new DefineSet();
            for ( int i = 0; i < undefList.lengthi++ )
            {
                String[] pair = undefList[i].trim().split"=", 2 );
                DefineArgument undef = new DefineArgument();
                undef.setNamepair[0] );
                undef.setValuepair.length > 1 ? pair[1] : null );
                undefSet.addUndefineundef );
            }
            compiler.addConfiguredDefinesetundefSet );
        }
        if ( ! )
        {
            DefineSet us = new DefineSet();
            String defaultUndefines = NarProperties.getInstance(.getMavenProject()).getPropertygetPrefix() + "undefines" );
            if ( defaultUndefines != null )
            {
                us.setUndefinenew CUtil.StringArrayBuilderdefaultUndefines ) );
            }
            compiler.addConfiguredDefinesetus );
        }
        // add include path
        for ( Iterator i = getIncludePathstype ).iterator(); i.hasNext(); )
        {
            String path = (Stringi.next();
            // Darren Sargent, 30Jan2008 - fail build if invalid include path(s) specified.
			if ( ! new File(path).exists() ) {
				throw new MojoFailureException("NAR: Include path not found: " + path);
			}
            compiler.createIncludePath().setPathpath );
        }
        // add system include path (at the end)
        if (  != null )
        {
            for ( Iterator i = .iterator(); i.hasNext(); )
            {
                String path = (Stringi.next();
                compiler.createSysIncludePath().setPathpath );
            }
        }
        // Add default fileset (if exists)
        List srcDirs = getSourceDirectoriestype );
        Set includeSet = getIncludes();
        Set excludeSet = getExcludes();
        // now add all but the current test to the excludes
        for ( Iterator i = .getTests().iterator(); i.hasNext(); )
        {
            Test test = (Testi.next();
            if ( !test.getName().equalsoutput ) )
            {
                excludeSet.add"**/" + test.getName() + ".*" );
            }
        }
        for ( Iterator i = srcDirs.iterator(); i.hasNext(); )
        {
            File srcDir = (Filei.next();
            .getLog().debug"Checking for existence of " + getLanguage() + " source directory: " + srcDir );
            if ( srcDir.exists() )
            {
                if (  != null )
                {
                    compiler.setOrder( Arrays.asList( StringUtils.split", " ) ) );
                }
                ConditionalFileSet fileSet = new ConditionalFileSet();
                fileSet.setProject( .getAntProject() );
                fileSet.setIncludes( StringUtils.joinincludeSet.iterator(), "," ) );
                fileSet.setExcludes( StringUtils.joinexcludeSet.iterator(), "," ) );
                fileSet.setDirsrcDir );
                compiler.addFilesetfileSet );
            }
        }
        return compiler;
    }
    protected abstract String getLanguage();
    public final void copyIncludeFilesMavenProject mavenProjectFile targetDirectory )
        throws IOException
    {
        for ( Iterator i = getIncludePaths"dummy" ).iterator(); i.hasNext(); )
        {
            File path = new File( (Stringi.next() );
            if ( path.exists() )
            {
                NarUtil.copyDirectoryStructurepathtargetDirectorynull. );
            }
        }
    }
New to GrepCode? Check out our FAQ X