Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
   *
   * The contents of this file are subject to the terms of either the GNU
   * General Public License Version 2 only ("GPL") or the Common
   * Development and Distribution License("CDDL") (collectively, the
   * "License"). You may not use this file except in compliance with the
  * License. You can obtain a copy of the License at
  * http://www.netbeans.org/cddl-gplv2.html
  * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  * specific language governing permissions and limitations under the
  * License.  When distributing the software, include this License Header
  * Notice in each file and include the License file at
  * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
  * particular file as subject to the "Classpath" exception as provided
  * by Sun in the GPL Version 2 section of the License file that
  * accompanied this code. If applicable, add the following below the
  * License Header, with the fields enclosed by brackets [] replaced by
  * your own identifying information:
  * "Portions Copyrighted [year] [name of copyright owner]"
  *
  * Contributor(s):
  *
  * The Original Software is NetBeans. The Initial Developer of the Original
  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
  * Microsystems, Inc. All Rights Reserved.
  *
  * If you wish your version of this file to be governed by only the CDDL
  * or only the GPL Version 2, indicate your decision by adding
  * "[Contributor] elects to include this software in this distribution
  * under the [CDDL or GPL Version 2] license." If you do not indicate a
  * single choice of license, a recipient has the option to distribute
  * your version of this file under either the CDDL, the GPL Version 2 or
  * to extend the choice of license to its licensees as provided above.
  * However, if you add GPL Version 2 code and therefore, elected the GPL
  * Version 2 license, then the option applies only if the new code is
  * made subject to such option by the copyright holder.
  */
 package org.netbeans.modules.cnd.makeproject.api.configurations;
 
 
 public class LinkerConfiguration implements AllOptionsProvider {
 
     private StringConfiguration output;
     private BooleanConfiguration stripOption;
     private BooleanConfiguration picOption;
     private StringConfiguration tool;
 
     // Constructors
     public LinkerConfiguration(MakeConfiguration makeConfiguration) {
         this. = makeConfiguration;
          = new StringConfiguration(null""); // NOI18N
          = new VectorConfiguration<String>(null);
          = new VectorConfiguration<String>(null);
          = new LinkerStripConfiguration(nullfalse); // NOI18N
          = new BooleanConfiguration(nulltrue"""-Kpic"); // NOI18N
          = new BooleanConfiguration(nulltrue"""-norunpath"); // NOI18N
          = new BooleanConfiguration(nulltrue);
          = new OptionsConfiguration();
          = new OptionsConfiguration();
          = new LibrariesConfiguration();
          = new StringConfiguration(null""); // NOI18N
     }
 
         String pd = "${BUILD_SUBPROJECTS} ${OBJECTFILES}"// NOI18N
         return pd;
     }
    // MakeConfiguration
    public void setMakeConfiguration(MakeConfiguration makeConfiguration) {
        this. = makeConfiguration;
    }
        return ;
    }
    // Output
    public void setOutput(StringConfiguration output) {
        this. = output;
    }
    public StringConfiguration getOutput() {
        return ;
    }
    // Additional Libraries
        return ;
    }
    public void setAdditionalLibs(VectorConfiguration<StringadditionalLibs) {
        this. = additionalLibs;
    }
    // Dynamic Search
        return ;
    }
    public void setDynamicSearch(VectorConfiguration<StringdynamicSearch) {
        this. = dynamicSearch;
    }
    // Strip
    public void setStripOption(BooleanConfiguration stripOption) {
        this. = stripOption;
    }
        return ;
    }
    // Kpic
    public void setPICOption(BooleanConfiguration picOption) {
        this. = picOption;
    }
        return ;
    }
    // Norunpath
    public void setNorunpathOption(BooleanConfiguration norunpathOption) {
        this. = norunpathOption;
    }
        return ;
    }
    // Name Assign
    public void setNameassignOption(BooleanConfiguration nameassignOption) {
        this. = nameassignOption;
    }
        return ;
    }
    // CommandLine
        return ;
    }
    public void setCommandLineConfiguration(OptionsConfiguration commandLineConfiguration) {
        this. = commandLineConfiguration;
    }
    // Additional Dependencies
        return ;
    }
    public void setAdditionalDependencies(OptionsConfiguration additionalDependencies) {
        this. = additionalDependencies;
    }
    // LibrariesConfiguration
        return ;
    }
    public void setLibrariesConfiguration(LibrariesConfiguration librariesConfiguration) {
        this. = librariesConfiguration;
    }
    // Tool
    public void setTool(StringConfiguration tool) {
        this. = tool;
    }
    public StringConfiguration getTool() {
        return ;
    }
    // Clone and assign
    public void assign(LinkerConfiguration conf) {
        // LinkerConfiguration
        //setMakeConfiguration(conf.getMakeConfiguration()); // MakeConfiguration should not be assigned
        getOutput().assign(conf.getOutput());
        getAdditionalLibs().assign(conf.getAdditionalLibs());
        getDynamicSearch().assign(conf.getDynamicSearch());
        getStripOption().assign(conf.getStripOption());
        getPICOption().assign(conf.getPICOption());
        getTool().assign(conf.getTool());
    }
    @Override
    public LinkerConfiguration clone() {
        // LinkerConfiguration
        clone.setOutput(getOutput().clone());
        clone.setAdditionalLibs(getAdditionalLibs().clone());
        clone.setDynamicSearch(getDynamicSearch().clone());
        clone.setStripOption(getStripOption().clone());
        clone.setPICOption(getPICOption().clone());
        clone.setNorunpathOption(getNorunpathOption().clone());
        clone.setTool(getTool().clone());
        return clone;
    }
    public String getOptions() {
        String options = getCommandLineConfiguration().getValue() + " "// NOI18N
        options += getBasicOptions() + " "// NOI18N
        return CppUtils.reformatWhitespaces(options);
    }
    public String getBasicOptions() {
        String options = ""// NOI18N
            String libName = getOutputValue();
            int sep = libName.lastIndexOf('/');
            if (sep >= 0 && libName.length() > 1) {
                libName = libName.substring(sep + 1);
            }
            // FIXUP: should be move to Platform...
            if (cs != null) {
                options += cs.getCompilerFlavor().getToolchainDescriptor().getLinker().getDynamicLibraryBasicFlag();
                if (cs.isGnuCompiler() && getMakeConfiguration().getDevelopmentHost().getBuildPlatform() == .) {
                    options += libName + " "// NOI18N
                }
            }
        }
        if (cs != null) {
            options += cs.getCompilerFlavor().getToolchainDescriptor().getLinker().getOutputFileFlag() + getOutputValue() + " "// NOI18N
        } else {
            options += "-o " + getOutputValue() + " "// NOI18N
        }
        options += getStripOption().getOption() + " "// NOI18N
            // FIXUP: should move to Platform
            if (cs != null) {
                if (getPICOption().getValue()) {
                    options += getPICOption(cs);
                }
                if (cs.isSunCompiler()) {
                    options += getNorunpathOption().getOption() + " "// NOI18N
                    options += getNameassignOption(getNameassignOption().getValue()) + " "// NOI18N
                }
            }
        }
        return CppUtils.reformatWhitespaces(options);
    }
    public String getPICOption(CompilerSet cs) {
        if (linker != null) {
            return linker.getPICFlag();
        }
        return null;
    }
    public String getLibraryItems() {
        LinkerDescriptor linker = cs == null ? null : cs.getCompilerFlavor().getToolchainDescriptor().getLinker();
        if (linker == null) {
            return ""// NOI18N
        }
        String options = ""// NOI18N
        OptionToString staticSearchVisitor = new OptionToString(cslinker.getLibrarySearchFlag());
        options += getAdditionalLibs().toString(staticSearchVisitor) + " "// NOI18N
        OptionToString dynamicSearchVisitor = new OptionToString(cslinker.getDynamicLibrarySearchFlag());
        options += getDynamicSearch().toString(dynamicSearchVisitor) + " "// NOI18N
        LibraryToString libVisitor = new LibraryToString(getMakeConfiguration());
        options += getLibrariesConfiguration().toString(libVisitor) + " "// NOI18N
        return CppUtils.reformatWhitespaces(options);
    }
    // Interface OptionsProvider
    public String getAllOptions(BasicCompiler compiler) {
        String options = getBasicOptions() + " "// NOI18N
        options += getLibraryItems() + " "// NOI18N
        return CppUtils.reformatWhitespaces(options);
    }
    // Sheet
    public Sheet getGeneralSheet(Project projectMakeConfigurationDescriptor configurationDescriptorMakeConfiguration confboolean isQtMode) {
        Sheet sheet = new Sheet();
        CompilerSet compilerSet = conf.getCompilerSet().getCompilerSet();
        String linkDriver = null;
        String[] texts = null;
        if (compilerSet != null) {
            if (conf.hasCPPFiles(configurationDescriptor)) {
                BasicCompiler ccCompiler = (BasicCompilercompilerSet.getTool(.);
                linkDriver = ccCompiler.getName();
            } else {
                BasicCompiler cCompiler = (BasicCompilercompilerSet.getTool(.);
                linkDriver = cCompiler.getName();
            }
        }
        Sheet.Set set1 = new Sheet.Set();
        set1.setName("General"); // NOI18N
        set1.setDisplayName(getString("GeneralTxt"));
        set1.setShortDescription(getString("GeneralHint"));
        if (!isQtMode) {
            set1.put(new OutputNodeProp(getOutput(), getOutputDefault(), "Output"getString("OutputTxt"), getString("OutputHint"))); // NOI18N
            set1.put(new VectorNodeProp(getAdditionalLibs(), nullgetMakeConfiguration().getBaseDir(), new String[]{"AdditionalLibraryDirectories"getString("AdditionalLibraryDirectoriesTxt"), getString("AdditionalLibraryDirectoriesHint")}, truenew HelpCtx("AddtlLibraryDirectories"))); // NOI18N
        }
        set1.put(new VectorNodeProp(getDynamicSearch(), nullgetMakeConfiguration().getBaseDir(), new String[]{"RuntimeSearchDirectories"getString("RuntimeSearchDirectoriesTxt"), getString("RuntimeSearchDirectoriesHint")}, falsenew HelpCtx("RuntimeSearchDirectories"))); // NOI18N
        sheet.put(set1);
        if (!isQtMode) {
            Sheet.Set set2 = new Sheet.Set();
            set2.setName("Options"); // NOI18N
            set2.setDisplayName(getString("OptionsTxt"));
            set2.setShortDescription(getString("OptionsHint"));
            set2.put(new BooleanNodeProp(getStripOption(), true"StripSymbols"getString("StripSymbolsTxt"), getString("StripSymbolsHint"))); // NOI18N
            if (conf.getConfigurationType().getValue() == .) {
                set2.put(new BooleanNodeProp(getPICOption(), true"PositionIndependantCode"getString("PositionIndependantCodeTxt"), getString("PositionIndependantCodeHint"))); // NOI18N
                if (compilerSet != null && compilerSet.isSunCompiler()) {
                    set2.put(new BooleanNodeProp(getNorunpathOption(), true"NoRunPath"getString("NoRunPathTxt"), getString("NoRunPathHint"))); // NOI18N
                    set2.put(new BooleanNodeProp(getNameassignOption(), true"AssignName"getString("AssignNameTxt"), getString("AssignNameHint"))); // NOI18N
                }
            }
            sheet.put(set2);
            Sheet.Set set3 = new Sheet.Set();
            texts = new String[]{getString("AdditionalDependenciesTxt1"), getString("AdditionalDependenciesHint"), getString("AdditionalDependenciesTxt2"), getString("InheritedValuesTxt")};
            set3.setName("Input"); // NOI18N
            set3.setDisplayName(getString("InputTxt"));
            set3.setShortDescription(getString("InputHint"));
            set3.put(new OptionsNodeProp(getAdditionalDependencies(), nullnew AdditionalDependenciesOptions(), null","texts)); // NOI18N
            sheet.put(set3);
            Sheet.Set set4 = new Sheet.Set();
            set4.setName("Tool"); // NOI18N
            set4.setDisplayName(getString("ToolTxt1"));
            set4.setShortDescription(getString("ToolHint1"));
            if (linkDriver != null) {
                set4.put(new StringNodeProp(getTool(), linkDriver"Tool"getString("ToolTxt1"), getString("ToolHint1"))); // NOI18N
            }
            sheet.put(set4);
        }
        texts = new String[]{getString("LibrariesTxt1"), getString("LibrariesHint"), getString("LibrariesTxt2"), getString("AllOptionsTxt2")};
        Sheet.Set set5 = new Sheet.Set();
        set5.setName("Libraries"); // NOI18N
        set5.setDisplayName(getString("LibrariesTxt1"));
        set5.setShortDescription(getString("LibrariesHint"));
        set5.put(new LibrariesNodeProp(getLibrariesConfiguration(), projectconfgetMakeConfiguration().getBaseDir(), texts));
        sheet.put(set5);
        if (!isQtMode) {
            texts = new String[]{getString("AdditionalOptionsTxt1"), getString("AdditionalOptionsHint"), getString("AdditionalOptionsTxt2"), getString("AllOptionsTxt")}; // NOI18N
            Sheet.Set set6 = new Sheet.Set();
            set6.setName("CommandLine"); // NOI18N
            set6.setDisplayName(getString("CommandLineTxt"));
            set6.setShortDescription(getString("CommandLineHint"));
            set6.put(new OptionsNodeProp(getCommandLineConfiguration(), nullthisnullnulltexts));
            sheet.put(set6);
        }
        return sheet;
    }
        public String getAllOptions(BasicCompiler compiler) {
            String options = ""// NOI18N
            options += .getPreDefined();
            return CppUtils.reformatWhitespaces(options);
        }
    }
    private String getNameassignOption(boolean val) {
        if (val) {
            return "-h " + IpeUtils.getBaseName(getOutputValue()); // NOI18N
        } else {
            return ""// NOI18N
        }
    }
    public String getOutputValue() {
        if (getOutput().getModified()) {
            return getOutput().getValue();
        } else {
            return getOutputDefault();
        }
    }
    private String getOutputDefault() {
        String outputName = IpeUtils.getBaseName(getMakeConfiguration().getBaseDir());
        switch (getMakeConfiguration().getConfigurationType().getValue()) {
            case .:
                outputName = outputName.toLowerCase();
                break;
            case .:
                outputName = Platforms.getPlatform(getMakeConfiguration().getDevelopmentHost().getBuildPlatform()).getLibraryName(outputName);
                break;
        }
        outputName = ConfigurationSupport.makeNameLegal(outputName);
        return "${CND_DISTDIR}" + "/" + "${CND_CONF}" + "/" + "${CND_PLATFORM}" + "/" + outputName// NOI18N
    }
    public String getOutputDefault27() {
        String outputName = IpeUtils.getBaseName(getMakeConfiguration().getBaseDir());
            outputName = outputName.toLowerCase();
            outputName = "lib" + outputName + ".so"// NOI18N
        }
        return . + "/" + getMakeConfiguration().getName() + "/" + outputName// NOI18N
    }
    private static class OutputNodeProp extends StringNodeProp {
        public OutputNodeProp(StringConfiguration stringConfigurationString defString txt1String txt2String txt3) {
            super(stringConfigurationdeftxt1txt2txt3);
        }
        @Override
        public void setValue(String v) {
            if (IpeUtils.hasMakeSpecialCharacters(v)) {
                DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(getString("SPECIAL_CHARATERS_ERROR"), .));
                return;
            }
            super.setValue(v);
        }
    }
    private class LinkerStripConfiguration extends BooleanConfiguration {
        public LinkerStripConfiguration(BooleanConfiguration masterboolean def) {
            super(masterdef);
        }
        @Override
        public String getOption() {
            if (getValue()) {
                String option;
                if (getMakeConfiguration().getDevelopmentHost().getBuildPlatform() == .) {
                    option = "-Wl,-S "// NOI18N
                } else {
                    option = "-s ";  // NOI18N
                }
                return option;
            } else {
                return ""// NOI18N
            }
        }
        // Clone and Assign
        @Override
        public void assign(BooleanConfiguration conf) {
            setDirty(getDirty() || getValue() != conf.getValue());
            setValue(conf.getValue());
            setModified(conf.getValue());
        }
        @Override
        public LinkerStripConfiguration clone() {
            LinkerStripConfiguration clone = new LinkerStripConfiguration(getMaster(), getDefault());
            clone.setValue(getValue());
            clone.setModified(getModified());
            return clone;
        }
    }

    
Look up i18n strings here
    private static String getString(String s) {
        return NbBundle.getMessage(LinkerConfiguration.classs);
    }
    public static class LibraryToString implements VectorConfiguration.ToString<LibraryItem> {
        private final MakeConfiguration conf;
        public LibraryToString(MakeConfiguration conf) {
            this. = conf;
        }
        public String toString(LibraryItem item) {
            return item.getOption();
        }
    }
New to GrepCode? Check out our FAQ X