Package com.github.maven_nar.cpptasks

Examples of com.github.maven_nar.cpptasks.LinkerDef


        if (jniIncludeDir.exists()) {
          task.createIncludePath().setPath(jniIncludeDir.getPath());
        }

        // add linker
        LinkerDef linkerDefinition =
            getLinker().getTestLinker( this, antProject, getOS(), getAOL().getKey() + ".linker.", type );
        task.addConfiguredLinker( linkerDefinition );

        File includeDir =
            getLayout().getIncludeDirectory( getTargetDirectory(), getMavenProject().getArtifactId(),
                                             getMavenProject().getVersion() );

        File libDir =
            getLayout().getLibDirectory( getTargetDirectory(), getMavenProject().getArtifactId(),
                                         getMavenProject().getVersion(), getAOL().toString(), test.getLink() );

        // copy shared library
        // FIXME why do we do this ?
        /*
         * Removed in alpha-10 if (test.getLink().equals(Library.SHARED)) { try { // defaults are Unix String libPrefix
         * = NarUtil.getDefaults().getProperty( getAOLKey() + "shared.prefix", "lib"); String libExt =
         * NarUtil.getDefaults().getProperty( getAOLKey() + "shared.extension", "so"); File copyDir = new
         * File(getTargetDirectory(), (getOS().equals( "Windows") ? "bin" : "lib") + "/" + getAOL() + "/" +
         * test.getLink()); FileUtils.copyFileToDirectory(new File(libDir, libPrefix + libName + "." + libExt),
         * copyDir); if (!getOS().equals(OS.WINDOWS)) { libDir = copyDir; } } catch (IOException e) { throw new
         * MojoExecutionException( "NAR: Could not copy shared library", e); } }
         */
        // FIXME what about copying the other shared libs?

        // add include of this package
        if ( includeDir.exists() )
        {
            task.createIncludePath().setLocation( includeDir );
        }

        // add library of this package
        if ( libDir.exists() )
        {
            LibrarySet libSet = new LibrarySet();
            libSet.setProject( antProject );
            String libs = getNarInfo().getLibs( getAOL() );
            getLog().debug( "Searching for parent to link with " + libs );
            libSet.setLibs( new CUtil.StringArrayBuilder( libs ) );
            LibraryTypeEnum libType = new LibraryTypeEnum();
            libType.setValue( test.getLink() );
            libSet.setType( libType );
            libSet.setDir( libDir );
            task.addLibset( libSet );
        }

        // add dependency libraries
        List depLibOrder = getDependencyLibOrder();

        // reorder the libraries that come from the nar dependencies
        // to comply with the order specified by the user
        if ( ( depLibOrder != null ) && !depLibOrder.isEmpty() )
        {

            List tmp = new LinkedList();

            for ( Iterator i = depLibOrder.iterator(); i.hasNext(); )
            {

                String depToOrderName = (String) i.next();

                for ( Iterator j = depLibs.iterator(); j.hasNext(); )
                {

                    NarArtifact dep = (NarArtifact) j.next();
                    String depName = dep.getGroupId() + ":" + dep.getArtifactId();

                    if ( depName.equals( depToOrderName ) )
                    {

                        tmp.add( dep );
                        j.remove();
                    }
                }
            }

            tmp.addAll( depLibs );
            depLibs = tmp;
        }

        for ( Iterator i = depLibs.iterator(); i.hasNext(); )
        {
            NarArtifact dependency = (NarArtifact) i.next();

            // FIXME no handling of "local"

            // FIXME, no way to override this at this stage
            String binding = dependency.getNarInfo().getBinding( getAOL(), Library.NONE );
            getLog().debug( "Using Binding: " + binding );
            AOL aol = getAOL();
            aol = dependency.getNarInfo().getAOL( getAOL() );
            getLog().debug( "Using Library AOL: " + aol.toString() );

            if ( !binding.equals( Library.JNI ) && !binding.equals( Library.NONE ) && !binding.equals( Library.EXECUTABLE) )
            {
                // check if it exists in the normal unpack directory
                File dir =
                    getLayout().getLibDirectory( getUnpackDirectory(), dependency.getArtifactId(),
                                                  dependency.getBaseVersion(), aol.toString(), binding );
                getLog().debug( "Looking for Library Directory: " + dir );
                if ( !dir.exists() )
                {
                    getLog().debug( "Library Directory " + dir + " does NOT exist." );

                    // otherwise try the test unpack directory
                    dir = getLayout().getLibDirectory( getTestUnpackDirectory(), dependency.getArtifactId(),
                                                        dependency.getBaseVersion(), aol.toString(), binding );
                    getLog().debug( "Looking for Library Directory: " + dir );
                }
                if ( dir.exists() )
                {
                    LibrarySet libSet = new LibrarySet();
                    libSet.setProject( antProject );

                    // FIXME, no way to override
                    String libs = dependency.getNarInfo().getLibs( getAOL() );
                    if ( ( libs != null ) && !libs.equals( "" ) )
                    {
                        getLog().debug( "Using LIBS = " + libs );
                        libSet.setLibs( new CUtil.StringArrayBuilder( libs ) );
                        libSet.setDir( dir );
                        task.addLibset( libSet );
                    }
                }
                else
                {
                    getLog().debug( "Library Directory " + dir + " does NOT exist." );
                }

                // FIXME, look again at this, for multiple dependencies we may need to remove duplicates
                String options = dependency.getNarInfo().getOptions( getAOL() );
                if ( ( options != null ) && !options.equals( "" ) )
                {
                    getLog().debug( "Using OPTIONS = " + options );
                    LinkerArgument arg = new LinkerArgument();
                    arg.setValue( options );
                    linkerDefinition.addConfiguredLinkerArg( arg );
                }

                String sysLibs = dependency.getNarInfo().getSysLibs( getAOL() );
                if ( ( sysLibs != null ) && !sysLibs.equals( "" ) )
                {
View Full Code Here


     */
    public final LinkerDef getTestLinker( AbstractCompileMojo mojo, Project antProject, String os, String prefix,
                                          String type )
        throws MojoFailureException, MojoExecutionException
    {
        LinkerDef linker = getLinker(mojo, antProject, os, prefix, type);
        if ( testOptions != null )
        {
            for ( Iterator i = testOptions.iterator(); i.hasNext(); )
            {
                LinkerArgument arg = new LinkerArgument();
                arg.setValue( (String) i.next() );
                linker.addConfiguredLinkerArg( arg );
            }
        }
        return linker;
    }
View Full Code Here

        if ( name == null )
        {
            throw new MojoFailureException( "NAR: Please specify a <Name> as part of <Linker>" );
        }

        LinkerDef linker = new LinkerDef();
        linker.setProject( antProject );
        LinkerEnum linkerEnum = new LinkerEnum();
        linkerEnum.setValue( name );
        linker.setName( linkerEnum );

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

        // incremental, map
        linker.setIncremental( incremental );
        linker.setMap( map );

        // Add definitions (Window only)
        if ( os.equals( OS.WINDOWS ) && getName( null, null ).equals( "msvc" ) && ( type.equals( Library.SHARED ) || type.equals( Library.JNI ) ) )
        {
            Set defs = new HashSet();
            try
            {
                if ( mojo.getC() != null )
                {
                    List cSrcDirs = mojo.getC().getSourceDirectories();
                    for ( Iterator i = cSrcDirs.iterator(); i.hasNext(); )
                    {
                        File dir = (File) i.next();
                        if ( dir.exists() )
                        {
                            defs.addAll( FileUtils.getFiles( dir, "**/*.def", null ) );
                        }
                    }
                }
            }
            catch ( IOException e )
            {
            }
            try
            {
                if ( mojo.getCpp() != null )
                {
                    List cppSrcDirs = mojo.getCpp().getSourceDirectories();
                    for ( Iterator i = cppSrcDirs.iterator(); i.hasNext(); )
                    {
                        File dir = (File) i.next();
                        if ( dir.exists() )
                        {
                            defs.addAll( FileUtils.getFiles( dir, "**/*.def", null ) );
                        }
                    }
                }
            }
            catch ( IOException e )
            {
            }
            try
            {
                if ( mojo.getFortran() != null )
                {
                    List fortranSrcDirs = mojo.getFortran().getSourceDirectories();
                    for ( Iterator i = fortranSrcDirs.iterator(); i.hasNext(); )
                    {
                        File dir = (File) i.next();
                        if ( dir.exists() )
                        {
                            defs.addAll( FileUtils.getFiles( dir, "**/*.def", null ) );
                        }
                    }
                }
            }
            catch ( IOException e )
            {
            }

            for ( Iterator i = defs.iterator(); i.hasNext(); )
            {
                LinkerArgument arg = new LinkerArgument();
                arg.setValue( "/def:" + i.next() );
                linker.addConfiguredLinkerArg( arg );
            }
        }

        // FIXME, this should be done in CPPTasks at some point, and may not be necessary, but was for VS 2010 beta 2
        if ( os.equals( OS.WINDOWS ) && getName( null, null ).equals( "msvc" ) && !getVersion().startsWith( "6." ) )
        {
            LinkerArgument arg = new LinkerArgument();
            arg.setValue( "/MANIFEST" );
            linker.addConfiguredLinkerArg( arg );
        }

        // Add options to linker
        if ( options != null )
        {
            for ( Iterator i = options.iterator(); i.hasNext(); )
            {
                LinkerArgument arg = new LinkerArgument();
                arg.setValue( (String) i.next() );
                linker.addConfiguredLinkerArg( arg );
            }
        }

        if ( optionSet != null )
        {

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

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

                LinkerArgument arg = new LinkerArgument();

                arg.setValue( opts[i] );
                linker.addConfiguredLinkerArg( arg );
            }
        }

        if ( !clearDefaultOptions )
        {
            String option = NarProperties.getInstance(mojo.getMavenProject()).getProperty( prefix + "options" );
            if ( option != null )
            {
                String[] opt = option.split( " " );
                for ( int i = 0; i < opt.length; i++ )
                {
                    LinkerArgument arg = new LinkerArgument();
                    arg.setValue( opt[i] );
                    linker.addConfiguredLinkerArg( arg );
                }
            }
        }

        // record the preference for nar dependency library link order
        if ( narDependencyLibOrder != null )
        {

            List libOrder = new LinkedList();

            String[] lib = narDependencyLibOrder.split( "," );

            for ( int i = 0; i < lib.length; i++ )
            {
                libOrder.add( lib[i].trim() );
            }

            mojo.setDependencyLibOrder( libOrder );
        }

        // Add Libraries to linker
        if ( ( libs != null ) || ( libSet != null ) )
        {

            if ( libs != null )
            {

                for ( Iterator i = libs.iterator(); i.hasNext(); )
                {

                    Lib lib = (Lib) i.next();
                    lib.addLibSet( mojo, linker, antProject );
                }
            }

            if ( libSet != null )
            {
                addLibraries( libSet, linker, antProject, false );
            }
        }
        else
        {

            String libsList = NarProperties.getInstance(mojo.getMavenProject()).getProperty( prefix + "libs" );

            addLibraries( libsList, linker, antProject, false );
        }

        // Add System Libraries to linker
        if ( ( sysLibs != null ) || ( sysLibSet != null ) )
        {

            if ( sysLibs != null )
            {

                for ( Iterator i = sysLibs.iterator(); i.hasNext(); )
                {

                    SysLib sysLib = (SysLib) i.next();
                    linker.addSyslibset( sysLib.getSysLibSet( antProject ) );
                }
            }

            if ( sysLibSet != null )
            {
View Full Code Here

                }
            }
        }

        // add linker
        LinkerDef linkerDefinition =
            getLinker().getLinker( this, antProject, getOS(), getAOL().getKey() + ".linker.", type );
        task.addConfiguredLinker(linkerDefinition);

        // add dependency libraries
        // FIXME: what about PLUGIN and STATIC, depending on STATIC, should we
        // not add all libraries, see NARPLUGIN-96
        if ( type.equals( Library.SHARED ) || type.equals( Library.JNI ) || type.equals( Library.EXECUTABLE ) )
        {

            List depLibOrder = getDependencyLibOrder();
            List depLibs = dependencies;

            // reorder the libraries that come from the nar dependencies
            // to comply with the order specified by the user
            if ( ( depLibOrder != null ) && !depLibOrder.isEmpty() )
            {
                List tmp = new LinkedList();

                for ( Iterator i = depLibOrder.iterator(); i.hasNext(); )
                {
                    String depToOrderName = (String) i.next();

                    for ( Iterator j = depLibs.iterator(); j.hasNext(); )
                    {
                        NarArtifact dep = (NarArtifact) j.next();
                        String depName = dep.getGroupId() + ":" + dep.getArtifactId();

                        if (depName.equals(depToOrderName))
                        {
                            tmp.add(dep);
                            j.remove();
                        }
                    }
                }

                tmp.addAll(depLibs);
                depLibs = tmp;
            }

            for ( Iterator i = depLibs.iterator(); i.hasNext(); )
            {
                NarArtifact dependency = (NarArtifact) i.next();

                // FIXME no handling of "local"

                // FIXME, no way to override this at this stage
                String binding = dependency.getNarInfo().getBinding( getAOL(), Library.NONE );
                getLog().debug("Using Binding: " + binding);
                AOL aol = getAOL();
                aol = dependency.getNarInfo().getAOL(getAOL());
                getLog().debug("Using Library AOL: " + aol.toString());

                if ( !binding.equals( Library.JNI ) && !binding.equals( Library.NONE ) && !binding.equals( Library.EXECUTABLE) )
                {
                    File unpackDirectory = getUnpackDirectory();

                    File dir =
                        getLayout().getLibDirectory( unpackDirectory, dependency.getArtifactId(),
                                                     dependency.getBaseVersion(), aol.toString(), binding );

                    getLog().debug("Looking for Library Directory: " + dir);
                    if ( dir.exists() )
                    {
                        LibrarySet libSet = new LibrarySet();
                        libSet.setProject(antProject);

                        // FIXME, no way to override
                        String libs = dependency.getNarInfo().getLibs(getAOL());
                        if ( ( libs != null ) && !libs.equals( "" ) )
                        {
                            getLog().debug("Using LIBS = " + libs);
                            libSet.setLibs(new CUtil.StringArrayBuilder(libs));
                            libSet.setDir(dir);
                            task.addLibset(libSet);
                        }
                    }
                    else
                    {
                        getLog().debug( "Library Directory " + dir + " does NOT exist." );
                    }

                    // FIXME, look again at this, for multiple dependencies we may need to remove duplicates
                    String options = dependency.getNarInfo().getOptions( getAOL() );
                    if ( ( options != null ) && !options.equals( "" ) )
                    {
                        getLog().debug("Using OPTIONS = " + options);
                        LinkerArgument arg = new LinkerArgument();
                        arg.setValue(options);
                        linkerDefinition.addConfiguredLinkerArg(arg);
                    }

                    String sysLibs = dependency.getNarInfo().getSysLibs( getAOL() );
                    if ( ( sysLibs != null ) && !sysLibs.equals( "" ) )
                    {
View Full Code Here

        }
      }
    }

    // add linker
    LinkerDef linkerDefinition = getLinker().getLinker(this, antProject,
        getOS(), getAOL().getKey() + ".linker.", type);
    task.addConfiguredLinker(linkerDefinition);

    // add dependency libraries
    // FIXME: what about PLUGIN and STATIC, depending on STATIC, should we
    // not add all libraries, see NARPLUGIN-96
    if (type.equals(Library.SHARED) || type.equals(Library.JNI)
        || type.equals(Library.EXECUTABLE)) {

      List depLibOrder = getDependencyLibOrder();
      List depLibs = dependencies;

      // reorder the libraries that come from the nar dependencies
      // to comply with the order specified by the user
      if ((depLibOrder != null) && !depLibOrder.isEmpty()) {

        List tmp = new LinkedList();

        for (Iterator i = depLibOrder.iterator(); i.hasNext();) {

          String depToOrderName = (String) i.next();

          for (Iterator j = depLibs.iterator(); j.hasNext();) {

            NarArtifact dep = (NarArtifact) j.next();
            String depName = dep.getGroupId() + ":"
                + dep.getArtifactId();

            if (depName.equals(depToOrderName)) {

              tmp.add(dep);
              j.remove();
            }
          }
        }

        tmp.addAll(depLibs);
        depLibs = tmp;
      }

      for (Iterator i = depLibs.iterator(); i.hasNext();) {

        NarArtifact dependency = (NarArtifact) i.next();

        // FIXME no handling of "local"

        // FIXME, no way to override this at this stage
        String binding = dependency.getNarInfo().getBinding(getAOL(),
            Library.STATIC);
        getLog().debug("Using Binding: " + binding);
        AOL aol = getAOL();
        aol = dependency.getNarInfo().getAOL(getAOL());
        getLog().debug("Using Library AOL: " + aol.toString());

                if ( !binding.equals( Library.JNI ) && !binding.equals( Library.NONE ) && !binding.equals( Library.EXECUTABLE) )
                {
                    File unpackDirectory = getUnpackDirectory();
                    File dir =
                        getLayout().getLibDirectory( unpackDirectory, dependency.getArtifactId(),
                                                     dependency.getBaseVersion(), aol.toString(), binding );
          getLog().debug("Looking for Library Directory: " + dir);
          if (dir.exists()) {
            LibrarySet libSet = new LibrarySet();
            libSet.setProject(antProject);

            // FIXME, no way to override
            String libs = dependency.getNarInfo().getLibs(getAOL());
            if ((libs != null) && !libs.equals("")) {
              getLog().debug("Using LIBS = " + libs);
              libSet.setLibs(new CUtil.StringArrayBuilder(libs));
              libSet.setDir(dir);
              task.addLibset(libSet);
            }
          } else {
            getLog()
                .debug(
                    "Library Directory " + dir
                        + " does NOT exist.");
          }

          // FIXME, look again at this, for multiple dependencies we
          // may need to remove duplicates
          String options = dependency.getNarInfo().getOptions(
              getAOL());
          if ((options != null) && !options.equals("")) {
            getLog().debug("Using OPTIONS = " + options);
            LinkerArgument arg = new LinkerArgument();
            arg.setValue(options);
            linkerDefinition.addConfiguredLinkerArg(arg);
          }

          String sysLibs = dependency.getNarInfo().getSysLibs(
              getAOL());
View Full Code Here

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

  /**
   * Test if setting the classname attribute to the name of the GCC linker
   * results in the singleton GCC linker.
   */
  public void testGetGcc() {
    LinkerDef linkerDef = (LinkerDef) create();
    linkerDef.setClassname("com.github.maven_nar.cpptasks.gcc.GccLinker");
    Linker comp = (Linker) linkerDef.getProcessor();
    assertNotNull(comp);
    assertSame(GccLinker.getInstance(), comp);
  }
View Full Code Here

  /**
   * Test if setting the classname attribute to the name of the MSVC linker
   * results in the singleton MSVC linker.
   */
  public void testGetMSVC() {
    LinkerDef linkerDef = (LinkerDef) create();
    linkerDef
        .setClassname("com.github.maven_nar.cpptasks.msvc.MsvcLinker");
    Linker comp = (Linker) linkerDef.getProcessor();
    assertNotNull(comp);
    assertSame(MsvcLinker.getInstance(), comp);
  }
View Full Code Here

   * Tests if setting the classname attribute to an bogus classname results in
   * a BuildException.
   *
   */
  public void testUnknownClass() {
    LinkerDef linkerDef = (LinkerDef) create();
    try {
      linkerDef
          .setClassname("com.github.maven_nar.cpptasks.bogus.BogusLinker");
    } catch (BuildException ex) {
      return;
    }
    fail("should have thrown exception");
View Full Code Here

   * Tests if setting the classname to the name of a class that doesn't
   * support Linker throws a BuildException.
   *
   */
  public void testWrongType() {
    LinkerDef linkerDef = (LinkerDef) create();
    try {
      linkerDef.setClassname("com.github.maven_nar.cpptasks.CCTask");
    } catch (ClassCastException ex) {
      return;
    }
    fail("should have thrown exception");
  }
View Full Code Here

TOP

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

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.