Package com.github.maven_nar.cpptasks

Examples of com.github.maven_nar.cpptasks.CompilerDef


        // add C++ compiler
        Cpp cpp = getCpp();
        if ( cpp != null )
        {
            CompilerDef cppCompiler = getCpp().getTestCompiler( type, test.getName() );
            if ( cppCompiler != null )
            {
                task.addConfiguredCompiler( cppCompiler );
            }
        }

        // add C compiler
        C c = getC();
        if ( c != null )
        {
            CompilerDef cCompiler = c.getTestCompiler( type, test.getName() );
            if ( cCompiler != null )
            {
                task.addConfiguredCompiler( cCompiler );
            }
        }

        // add Fortran compiler
        Fortran fortran = getFortran();
        if ( fortran != null )
        {
            CompilerDef fortranCompiler = getFortran().getTestCompiler( type, test.getName() );
            if ( fortranCompiler != null )
            {
                task.addConfiguredCompiler( fortranCompiler );
            }
        }
View Full Code Here


     * @return The standard Compiler configuration with 'testOptions' added to the argument list.
     */
    public final CompilerDef getTestCompiler( String type, String output )
        throws MojoFailureException, MojoExecutionException
    {
        CompilerDef compiler = getCompiler(type, output);
        if ( testOptions != null )
        {
            for ( Iterator<String> i = testOptions.iterator(); i.hasNext(); )
            {
                CompilerArgument arg = new CompilerArgument();
                arg.setValue( i.next() );
                compiler.addConfiguredCompilerArg( arg );
            }
        }
        return compiler;
    }
View Full Code Here

        throws MojoFailureException, MojoExecutionException
    {
        String name = getName();
        if (name == null) return null;
       
        CompilerDef compiler = new CompilerDef();
        compiler.setProject( mojo.getAntProject() );
        CompilerEnum compilerName = new CompilerEnum();
        compilerName.setValue( name );
        compiler.setName( compilerName );

        // tool path
        if ( toolPath != null )
        {
            compiler.setToolPath( toolPath );
        }

        // debug, exceptions, rtti, multiThreaded
        compiler.setDebug( debug );
        compiler.setExceptions( exceptions );
        compiler.setRtti( rtti );
        compiler.setMultithreaded( mojo.getOS().equals( "Windows" ) ? true : multiThreaded );

        // optimize
        OptimizationEnum optimization = new OptimizationEnum();
        optimization.setValue( optimize );
        compiler.setOptimize( optimization );

        // add options
        if ( options != null )
        {
            for ( Iterator<String> i = options.iterator(); i.hasNext(); )
            {
                CompilerArgument arg = new CompilerArgument();
                arg.setValue( (String) i.next() );
                compiler.addConfiguredCompilerArg( arg );
            }
        }

        if ( optionSet != null )
        {

            String[] opts = optionSet.split( "\\s" );

            for ( int i = 0; i < opts.length; i++ )
            {

                CompilerArgument arg = new CompilerArgument();

                arg.setValue( opts[i] );
                compiler.addConfiguredCompilerArg( arg );
            }
        }

        compiler.setClearDefaultOptions(clearDefaultOptions);
        if ( !clearDefaultOptions )
        {
            String optionsProperty = NarProperties.getInstance(mojo.getMavenProject()).getProperty( getPrefix() + "options" );
            if ( optionsProperty != null )
            {
                String[] option = optionsProperty.split( " " );
                for ( int i = 0; i < option.length; i++ )
                {
                    CompilerArgument arg = new CompilerArgument();
                    arg.setValue( option[i] );
                    compiler.addConfiguredCompilerArg( arg );
                }
            }
        }

        // add defines
        if ( defines != null )
        {
            DefineSet ds = new DefineSet();
            for ( Iterator<String> i = defines.iterator(); i.hasNext(); )
            {
                DefineArgument define = new DefineArgument();
                String[] pair = i.next().split( "=", 2 );
                define.setName( pair[0] );
                define.setValue( pair.length > 1 ? pair[1] : null );
                ds.addDefine( define );
            }
            compiler.addConfiguredDefineset( ds );
        }

        if ( defineSet != null )
        {

            String[] defList = defineSet.split( "," );
            DefineSet defSet = new DefineSet();

            for ( int i = 0; i < defList.length; i++ )
            {

                String[] pair = defList[i].trim().split( "=", 2 );
                DefineArgument def = new DefineArgument();

                def.setName( pair[0] );
                def.setValue( pair.length > 1 ? pair[1] : null );

                defSet.addDefine( def );
            }

            compiler.addConfiguredDefineset( defSet );
        }

        if ( !clearDefaultDefines )
        {
            DefineSet ds = new DefineSet();
            String defaultDefines = NarProperties.getInstance(mojo.getMavenProject()).getProperty( getPrefix() + "defines" );
            if ( defaultDefines != null )
            {
                ds.setDefine( new CUtil.StringArrayBuilder( defaultDefines ) );
            }
            compiler.addConfiguredDefineset( ds );
        }

        // add undefines
        if ( undefines != null )
        {
            DefineSet us = new DefineSet();
            for ( Iterator<String> i = undefines.iterator(); i.hasNext(); )
            {
                DefineArgument undefine = new DefineArgument();
                String[] pair = i.next().split( "=", 2 );
                undefine.setName( pair[0] );
                undefine.setValue( pair.length > 1 ? pair[1] : null );
                us.addUndefine( undefine );
            }
            compiler.addConfiguredDefineset( us );
        }

        if ( undefineSet != null )
        {

            String[] undefList = undefineSet.split( "," );
            DefineSet undefSet = new DefineSet();

            for ( int i = 0; i < undefList.length; i++ )
            {

                String[] pair = undefList[i].trim().split( "=", 2 );
                DefineArgument undef = new DefineArgument();

                undef.setName( pair[0] );
                undef.setValue( pair.length > 1 ? pair[1] : null );

                undefSet.addUndefine( undef );
            }

            compiler.addConfiguredDefineset( undefSet );
        }

        if ( !clearDefaultUndefines )
        {
            DefineSet us = new DefineSet();
            String defaultUndefines = NarProperties.getInstance(mojo.getMavenProject()).getProperty( getPrefix() + "undefines" );
            if ( defaultUndefines != null )
            {
                us.setUndefine( new CUtil.StringArrayBuilder( defaultUndefines ) );
            }
            compiler.addConfiguredDefineset( us );
        }

        // add include path
        for ( Iterator<IncludePath> i = getIncludePaths( type ).iterator(); i.hasNext(); )
        {
            IncludePath includePath = i.next();
            // Darren Sargent, 30Jan2008 - fail build if invalid include path(s) specified.
                        if ( ! includePath.exists() ) {
                                throw new MojoFailureException("NAR: Include path not found: " + includePath);
                        }
            compiler.createIncludePath().setPath( includePath.getPath() );
        }

        // add system include path (at the end)
        if ( systemIncludePaths != null )
        {
            for ( Iterator<String> i = systemIncludePaths.iterator(); i.hasNext(); )
            {
                String path = i.next();
                compiler.createSysIncludePath().setPath( path );
            }
        }

        // Add default fileset (if exists)
        List<File> srcDirs = getSourceDirectories( type );
        Set<String> includeSet = getIncludes( type );
        Set<String> excludeSet = getExcludes( type );

        // now add all but the current test to the excludes
        for ( Iterator i = mojo.getTests().iterator(); i.hasNext(); )
        {
            Test test = (Test) i.next();
            if ( !test.getName().equals( output ) )
            {
                excludeSet.add( "**/" + test.getName() + ".*" );
            }
        }

        for ( Iterator<File> i = srcDirs.iterator(); i.hasNext(); )
        {
            File srcDir = i.next();
            mojo.getLog().debug( "Checking for existence of " + getLanguage() + " source directory: " + srcDir );
            if ( srcDir.exists() )
            {
                if ( compileOrder != null )
                {
                    compiler.setOrder( Arrays.asList( StringUtils.split( compileOrder, ", " ) ) );
                }

                ConditionalFileSet fileSet = new ConditionalFileSet();
                fileSet.setProject( mojo.getAntProject() );
                fileSet.setIncludes( StringUtils.join( includeSet.iterator(), "," ) );
                fileSet.setExcludes( StringUtils.join( excludeSet.iterator(), "," ) );
                fileSet.setDir( srcDir );
                compiler.addFileset( fileSet );
            }
        }

        return compiler;
    }
View Full Code Here

        // IDL, MC, RC compilations should probably be 'generate source' type actions, seperate from main build.
        // Needs resolution of handling for generate sources.
        // Order is somewhat important here, IDL and MC generate outputs that are (often) included in the RC compilation
        if (getIdl() != null) {
            CompilerDef idl = getIdl().getCompiler( Compiler.MAIN, null );
            if ( idl != null )
            {
                task.addConfiguredCompiler( idl );
            }
        }
        if (getMessage() != null) {
            CompilerDef mc = getMessage().getCompiler( Compiler.MAIN, null );
            if ( mc != null )
            {
                task.addConfiguredCompiler( mc );
            }
        }
        if (getResource() != null) {
            CompilerDef res = getResource().getCompiler( Compiler.MAIN, null );
            if ( res != null )
            {
                task.addConfiguredCompiler( res );
            }
        }
       
        // Darren Sargent Feb 11 2010: Use Compiler.MAIN for "type"...appears the wrong "type" variable was being used
        // since getCompiler() expects "main" or "test", whereas the "type" variable here is "executable", "shared" etc.
        // add C++ compiler
        if (getCpp() != null) {
            CompilerDef cpp = getCpp().getCompiler( Compiler.MAIN, null );
            if ( cpp != null )
            {
                task.addConfiguredCompiler( cpp );
            }
        }

        // add C compiler
        if (getC() != null) {
            CompilerDef c = getC().getCompiler( Compiler.MAIN, null );
            if ( c != null )
            {
                task.addConfiguredCompiler( c );
            }
        }

        // add Fortran compiler
        if (getFortran() != null) {
            CompilerDef fortran = getFortran().getCompiler( Compiler.MAIN, null );
            if ( fortran != null )
            {
                task.addConfiguredCompiler( fortran );
            }
        }
View Full Code Here

   * Creates a new processor.
   *
   * @return new processor
   */
  protected ProcessorDef create() {
    return new CompilerDef();
  }
View Full Code Here

   * "debug" property defined. Return value from getActiveDefines should
   * contain one member
   */
  public void testGetActiveDefines() {
    Project project = new org.apache.tools.ant.Project();
    CompilerDef def = new CompilerDef();
    def.setProject(project);
    DefineSet defset = new DefineSet();
    DefineArgument arg1 = new DefineArgument();
    arg1.setName("DEBUG");
    arg1.setIf("debug");
    defset.addDefine(arg1);
    DefineArgument arg2 = new DefineArgument();
    arg2.setName("NDEBUG");
    arg2.setUnless("debug");
    defset.addDefine(arg2);
    def.addConfiguredDefineset(defset);
    //
    //  Evaluate without "debug" set
    //
    UndefineArgument[] activeArgs = def.getActiveDefines();
    assertEquals(1, activeArgs.length);
    assertEquals("NDEBUG", activeArgs[0].getName());
    //
    //  Set the "debug" property
    //
    project.setProperty("debug", "");
    activeArgs = def.getActiveDefines();
    assertEquals(1, activeArgs.length);
    assertEquals("DEBUG", activeArgs[0].getName());
  }
View Full Code Here

   *
   * and is evaluate for a project without and without "debug" set
   */
  public void testGetActiveIncludePaths() {
    Project project = new org.apache.tools.ant.Project();
    CompilerDef def = new CompilerDef();
    def.setProject(project);
    ConditionalPath path = def.createIncludePath();
    path.setLocation(new File(".."));
    path.setIf("debug");
    //
    //  Evaluate without "debug" set
    //
    String[] includePaths = def.getActiveIncludePaths();
    assertEquals(0, includePaths.length);
    //
    //  Set the "debug" property
    //
    project.setProperty("debug", "");
    includePaths = def.getActiveIncludePaths();
    assertEquals(1, includePaths.length);
  }
View Full Code Here

  /**
   * Tests that setting classname to the Gcc compiler is effective.
   */
  public void testGetGcc() {
    CompilerDef compilerDef = (CompilerDef) create();
    compilerDef.setClassname("com.github.maven_nar.cpptasks.gcc.GccCCompiler");
    Compiler comp = (Compiler) compilerDef.getProcessor();
    assertNotNull(comp);
    assertSame(GccCCompiler.getInstance(), comp);
  }
View Full Code Here

  /**
   * Tests that setting classname to the MSVC compiler is effective.
   */
  public void testGetMSVC() {
    CompilerDef compilerDef = (CompilerDef) create();
    compilerDef
        .setClassname(
      "com.github.maven_nar.cpptasks.msvc.MsvcCCompiler");
    Compiler comp = (Compiler) compilerDef.getProcessor();
    assertNotNull(comp);
    assertSame(MsvcCCompiler.getInstance(), comp);
  }
View Full Code Here

  /**
   * Tests that setting classname to an bogus class name results in a
   * BuildException.
   */
  public void testUnknownClass() {
    CompilerDef compilerDef = (CompilerDef) create();
    try {
      compilerDef
          .setClassname("com.github.maven_nar.cpptasks.bogus.BogusCompiler");
    } catch (BuildException ex) {
      return;
    }
    fail("Exception not thrown");
View Full Code Here

TOP

Related Classes of com.github.maven_nar.cpptasks.CompilerDef

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.