Search in sources :

Example 11 with BuildException

use of org.eclipse.cdt.managedbuilder.core.BuildException in project usbdm-eclipse-plugins by podonoghue.

the class GccCommandLineGenerator method addFlags.

private String[] addFlags(ITool tool, String[] flags) {
    IToolChain toolChain = getToolChain(tool);
    // Create list of new flags
    ArrayList<String> newFlags = new ArrayList<String>();
    if (toolChain != null) {
        for (String newFlag : optionKeys) {
            // $NON-NLS-1$
            IOption option = toolChain.getOptionBySuperClassId(newFlag);
            if (option == null) {
                // System.err.println("GccCommandLineGenerator.addFlags() - option("+newFlag+"): not found");
                continue;
            }
            try {
                String command = option.getCommand();
                if (command == null) {
                    command = "";
                }
                String value = null;
                if (option.getValueType() == IOption.ENUMERATED) {
                    String enumId = option.getSelectedEnum();
                    value = option.getEnumCommand(enumId);
                } else if (option.getValueType() == IOption.STRING) {
                    value = option.getStringValue();
                } else if (option.getValueType() == IOption.BOOLEAN) {
                    boolean booleanValue = option.getBooleanValue();
                    if (!booleanValue) {
                        command = option.getCommandFalse();
                    }
                    option.getDefaultValue();
                } else {
                    System.err.println("GccCommandLineGenerator.addFlags() - option(" + newFlag + "): Unexpected option type");
                    continue;
                }
                if (value == null) {
                    value = "";
                }
                if ((command.isEmpty()) && (value.isEmpty())) {
                    // System.err.println("GccCommandLineGenerator.addFlags() - option("+newFlag+"): Command && value ==> null/empty");
                    continue;
                }
                String flag = "";
                if (command.contains("{value}")) {
                    flag = command.replace("{value}", value);
                } else {
                    flag = command + value;
                }
                // System.err.println("GccCommandLineGenerator.addFlags() - option("+newFlag+") ==> \'"+flag+"\'");
                newFlags.add(flag);
            } catch (BuildException e) {
                e.printStackTrace();
            }
        }
    }
    // Create combined list of newFlags + flags as array
    if (flags == null) {
        flags = new String[0];
    }
    String[] allFlags = new String[newFlags.size() + flags.length];
    int index = 0;
    StringBuffer allFlagsBuffer = new StringBuffer();
    boolean firstFlag = false;
    for (String flag : newFlags) {
        allFlags[index] = flag;
        if (!firstFlag) {
            allFlagsBuffer.append(" ");
        }
        allFlagsBuffer.append(flag);
        index++;
    }
    for (String flag : flags) {
        allFlags[index++] = flag;
    }
    // String flag = UsbdmSharedSettings.getSharedSettings().get(UsbdmSharedConstants.USBDM_COMPILER_FLAGS_VAR);
    return allFlags;
}
Also used : IToolChain(org.eclipse.cdt.managedbuilder.core.IToolChain) ArrayList(java.util.ArrayList) IOption(org.eclipse.cdt.managedbuilder.core.IOption) BuildException(org.eclipse.cdt.managedbuilder.core.BuildException)

Example 12 with BuildException

use of org.eclipse.cdt.managedbuilder.core.BuildException in project m2e-nar by maven-nar.

the class CProjectConfigurator method getCdtProject.

private ICProjectDescription getCdtProject(IProject project, IToolChain tc, String artefactType, IProgressMonitor monitor) throws CoreException {
    try {
        ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
        if (!project.hasNature(CCProjectNature.CC_NATURE_ID)) {
            MavenNarPlugin.getDefault().log("Configuring project with " + tc.getUniqueRealName() + " tool chain");
            // Add the C++ Nature
            CCorePlugin.getDefault().convertProjectToNewCC(project, ManagedBuildManager.CFG_DATA_PROVIDER_ID, monitor);
            ICProjectDescription des = mngr.createProjectDescription(project, false, false);
            IManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
            List<IConfiguration> cfgs = getCfgs(tc, artefactType);
            if (cfgs.isEmpty()) {
                throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Cannot find any configurations"));
            }
            IConfiguration cf = cfgs.get(0);
            IManagedProject mProj = ManagedBuildManager.createManagedProject(project, cf.getProjectType());
            info.setManagedProject(mProj);
            return des;
        } else {
            ICProjectDescription des = mngr.getProjectDescription(project, true);
            return des;
        }
    } catch (BuildException e) {
        throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Cannot create CDT managed project", e));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IManagedProject(org.eclipse.cdt.managedbuilder.core.IManagedProject) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) IManagedBuildInfo(org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo) CoreException(org.eclipse.core.runtime.CoreException) ICProjectDescriptionManager(org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager) BuildException(org.eclipse.cdt.managedbuilder.core.BuildException) IConfiguration(org.eclipse.cdt.managedbuilder.core.IConfiguration)

Example 13 with BuildException

use of org.eclipse.cdt.managedbuilder.core.BuildException in project m2e-nar by maven-nar.

the class OptionSetter method setOption.

public void setOption(final String optionId, final String value) throws CoreException {
    try {
        for (final ITool tool : config.getToolsBySuperClassId(toolId)) {
            final IOption option = tool.getOptionBySuperClassId(optionId);
            config.setOption(tool, option, value);
        }
    } catch (BuildException e) {
        throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Couldn't set " + optionId + " option", e));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) IOption(org.eclipse.cdt.managedbuilder.core.IOption) BuildException(org.eclipse.cdt.managedbuilder.core.BuildException) ITool(org.eclipse.cdt.managedbuilder.core.ITool)

Example 14 with BuildException

use of org.eclipse.cdt.managedbuilder.core.BuildException in project m2e-nar by maven-nar.

the class OptionSetter method setOption.

public void setOption(final String optionId, final String[] values) throws CoreException {
    try {
        for (final ITool tool : config.getToolsBySuperClassId(toolId)) {
            final IOption option = tool.getOptionBySuperClassId(optionId);
            config.setOption(tool, option, values);
        }
    } catch (BuildException e) {
        throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Couldn't set " + optionId + " option", e));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) IOption(org.eclipse.cdt.managedbuilder.core.IOption) BuildException(org.eclipse.cdt.managedbuilder.core.BuildException) ITool(org.eclipse.cdt.managedbuilder.core.ITool)

Aggregations

BuildException (org.eclipse.cdt.managedbuilder.core.BuildException)14 IOption (org.eclipse.cdt.managedbuilder.core.IOption)10 ArrayList (java.util.ArrayList)8 ITool (org.eclipse.cdt.managedbuilder.core.ITool)7 IPath (org.eclipse.core.runtime.IPath)7 CoreException (org.eclipse.core.runtime.CoreException)6 IStatus (org.eclipse.core.runtime.IStatus)6 Status (org.eclipse.core.runtime.Status)6 BuildMacroException (org.eclipse.cdt.managedbuilder.macros.BuildMacroException)5 IConfiguration (org.eclipse.cdt.managedbuilder.core.IConfiguration)4 List (java.util.List)3 Vector (java.util.Vector)3 IManagedCommandLineGenerator (org.eclipse.cdt.managedbuilder.core.IManagedCommandLineGenerator)3 IManagedCommandLineInfo (org.eclipse.cdt.managedbuilder.core.IManagedCommandLineInfo)3 FileContextData (org.eclipse.cdt.managedbuilder.internal.macros.FileContextData)3 IResource (org.eclipse.core.resources.IResource)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 ICProjectDescription (org.eclipse.cdt.core.settings.model.ICProjectDescription)2 IInputType (org.eclipse.cdt.managedbuilder.core.IInputType)2