Search in sources :

Example 1 with IManagedBuildInfo

use of org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo in project arduino-eclipse-plugin by Sloeber.

the class Helpers method setDirtyFlag.

/**
 * Set the project to force a rebuild. This method is called after the arduino
 * settings have been updated. Note the only way I found I could get this to
 * work is by deleting the build folder Still then the "indexer needs to recheck
 * his includes from the language provider which still is not working
 *
 * @param project
 */
public static void setDirtyFlag(IProject project, ICConfigurationDescription cfgDescription) {
    IManagedBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(project);
    if (buildInfo == null) {
        // Project is not a managed build project
        return;
    }
    IFolder buildFolder = project.getFolder(cfgDescription.getName());
    if (buildFolder.exists()) {
        try {
            buildFolder.delete(true, null);
        } catch (CoreException e) {
            Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, Messages.Helpers_delete_folder_failed + cfgDescription.getName(), e));
        }
    }
// List<ILanguageSettingsProvider> providers;
// if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) {
// providers = new ArrayList<>(
// ((ILanguageSettingsProvidersKeeper)
// cfgDescription).getLanguageSettingProviders());
// for (ILanguageSettingsProvider provider : providers) {
// if ((provider instanceof AbstractBuiltinSpecsDetector)) { //
// basically
// // check
// // for
// // working
// // copy
// // clear and reset isExecuted flag
// ((AbstractBuiltinSpecsDetector) provider).clear();
// }
// }
// }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IManagedBuildInfo(org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo) CoreException(org.eclipse.core.runtime.CoreException) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with IManagedBuildInfo

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

the class DisassembleCFileHandler method execute.

// public static void pipeStream(InputStream input, OutputStream output)
// throws IOException {
// 
// byte buffer[] = new byte[1024];
// int numRead = 0;
// 
// while (input.available() > 0) {
// numRead = input.read(buffer);
// output.write(buffer, 0, numRead);
// }
// output.flush();
// }
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    String os = System.getProperty("os.name");
    boolean isLinux = (os != null) && os.toUpperCase().contains("LINUX");
    Object source = HandlerUtil.getCurrentSelection(event);
    // System.err.println("Event source = "+source.toString()+"\n class = "+source.getClass().toString());
    if (!(source instanceof TreeSelection)) {
        // System.err.println("Source is not an instance of TreeSelection");
        return null;
    }
    TreeSelection selection = (TreeSelection) source;
    if (!(selection.getFirstElement() instanceof IBinary)) {
        // System.err.println("Selection.getFirstElement() is not an instance of org.eclipse.cdt.core.model.IBinary");
        return null;
    }
    IBinary binary = (IBinary) selection.getFirstElement();
    IResource resource = binary.getUnderlyingResource();
    IPath resourcePath = resource.getLocation();
    IPath dissassemblyPath = resourcePath.removeFileExtension().addFileExtension("lis");
    // Get Environment (path etc)
    CoreModel cdtCoreModel = org.eclipse.cdt.core.model.CoreModel.getDefault();
    ICProjectDescription cProjectDescription = cdtCoreModel.getProjectDescription(resource.getProject());
    ICConfigurationDescription cConfigurationDescription = cProjectDescription.getActiveConfiguration();
    IContributedEnvironment contributedEnvironment = CCorePlugin.getDefault().getBuildEnvironmentManager().getContributedEnvironment();
    IEnvironmentVariable[] environmentVariablesArray = contributedEnvironment.getVariables(cConfigurationDescription);
    HashMap<String, String> environmentMap = new HashMap<String, String>();
    for (IEnvironmentVariable ev : environmentVariablesArray) {
        String name = ev.getName();
        if ((!isLinux) && name.equals("PATH")) {
            name = "Path";
        }
        // System.err.println("Adding Environment variable: "+name+" => "+ev.getValue());
        environmentMap.put(name, ev.getValue());
    }
    // String resourceName = resource.getName();
    // System.err.println("resourceName = "+resourceName);
    IManagedBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(resource);
    IConfiguration configuration = buildInfo.getDefaultConfiguration();
    // System.err.println("configuration = "+configuration);
    // Find lister tool in configuration
    ITool[] toolArray = configuration.getTools();
    ITool tool = null;
    for (ITool t : toolArray) {
        Pattern p = Pattern.compile("net\\.sourceforge\\.usbdm\\.cdt\\..*\\.toolchain\\.lister\\..*");
        if (p.matcher(t.getId()).matches()) {
            tool = configuration.getTool(t.getId());
            break;
        }
    }
    if (tool == null) {
        return null;
    }
    // System.err.println("tool.getName = "+tool.getName());
    // System.err.println("tool.getToolCommand = "+tool.getToolCommand());
    // Get command line generator
    IManagedCommandLineGenerator commandLineGenerator = tool.getCommandLineGenerator();
    // Get command line
    try {
        String[] inputs = { resourcePath.lastSegment() };
        IManagedCommandLineInfo commandLineInfo = commandLineGenerator.generateCommandLineInfo(tool, tool.getToolCommand(), tool.getToolCommandFlags(resourcePath, dissassemblyPath), "", ">", dissassemblyPath.lastSegment(), inputs, "${COMMAND} ${INPUTS} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT}");
        // System.err.println("cl.toString() = "+commandLineInfo.toString());
        // System.err.println("cl.getCommandLine() = "+commandLineInfo.getCommandLine());
        String[] commandArray = null;
        if (isLinux) {
            // Construct command (Use cmd for PATH changes!)
            ArrayList<String> command = new ArrayList<String>(20);
            command.add("/bin/sh");
            command.add("-c");
            command.add(commandLineInfo.getCommandLine());
            commandArray = (String[]) command.toArray(new String[command.size()]);
        } else {
            // Construct command (Use cmd for PATH changes!)
            ArrayList<String> command = new ArrayList<String>(20);
            command.add("cmd.exe");
            command.add("/C");
            command.add(commandLineInfo.getCommandLine());
            commandArray = (String[]) command.toArray(new String[command.size()]);
        }
        // Run command
        // System.err.println("Running...");
        ProcessBuilder pb = new ProcessBuilder(commandArray);
        pb.environment().putAll(environmentMap);
        File commandFile = findExecutableOnPath(pb.environment().get("PATH"), commandLineInfo.getCommandName());
        if (commandFile != null) {
        // System.err.println("commandFile.toPath() = "+ commandFile.toPath());
        // System.err.println("pwd = "+ resourcePath.removeLastSegments(1).toFile());
        }
        // System.err.println("=================== Environment variables ===================");
        // for (String envName : pb.environment().keySet()) {
        // System.err.println("Environment variable: "+envName+" => "+pb.environment().get(envName));
        // }
        // System.err.println("=================== End of Environment variables ===================");
        pb.redirectInput(Redirect.INHERIT);
        pb.redirectError(Redirect.INHERIT);
        pb.redirectOutput(Redirect.INHERIT);
        pb.directory(resourcePath.removeLastSegments(1).toFile());
        // System.err.println("WD =" + pb.directory());
        Process p = pb.start();
        // System.err.println("Waiting...");
        p.waitFor();
    // System.err.println("Exit value = " + p.waitFor());
    } catch (IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (BuildException e) {
        e.printStackTrace();
    }
    try {
        // Refresh parent directory so file is visible
        resource.getParent().refreshLocal(1, null);
    } catch (CoreException e) {
        e.printStackTrace();
    }
    try {
        // Open disassembled file in editor
        IPath asmPath = resource.getFullPath().removeFileExtension().addFileExtension("lis");
        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        IDE.openEditor(page, ResourcesPlugin.getWorkspace().getRoot().getFile(asmPath));
    } catch (PartInitException e) {
        e.printStackTrace();
    }
    // System.err.println("Completed");
    return null;
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TreeSelection(org.eclipse.jface.viewers.TreeSelection) PartInitException(org.eclipse.ui.PartInitException) Pattern(java.util.regex.Pattern) IPath(org.eclipse.core.runtime.IPath) IManagedCommandLineGenerator(org.eclipse.cdt.managedbuilder.core.IManagedCommandLineGenerator) IBinary(org.eclipse.cdt.core.model.IBinary) IOException(java.io.IOException) ITool(org.eclipse.cdt.managedbuilder.core.ITool) IContributedEnvironment(org.eclipse.cdt.core.envvar.IContributedEnvironment) IManagedBuildInfo(org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo) CoreException(org.eclipse.core.runtime.CoreException) IManagedCommandLineInfo(org.eclipse.cdt.managedbuilder.core.IManagedCommandLineInfo) CoreModel(org.eclipse.cdt.core.model.CoreModel) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEnvironmentVariable(org.eclipse.cdt.core.envvar.IEnvironmentVariable) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription) BuildException(org.eclipse.cdt.managedbuilder.core.BuildException) IConfiguration(org.eclipse.cdt.managedbuilder.core.IConfiguration) File(java.io.File) IResource(org.eclipse.core.resources.IResource)

Example 3 with IManagedBuildInfo

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

the class ProjectUtilities method changeExcludedItem.

private static void changeExcludedItem(IProject project, String targetPath, boolean isFolder, boolean excluded, IProgressMonitor progressMonitor) throws CoreException, BuildException {
    IPath path = project.getFolder(targetPath).getProjectRelativePath();
    System.err.println(String.format("changeExcludedItem(target=%s, isfolder=%s, exclude=%s)", path.toString(), Boolean.toString(isFolder), Boolean.toString(excluded)));
    // ICProjectDescription projectDescription = CoreModel.getDefault().getProjectDescription(project, true);
    // ICConfigurationDescription configDecriptions[] = projectDescription.getConfigurations();
    // for (ICConfigurationDescription configDescription : configDecriptions) {
    // // Exclude in each configuration
    // System.err.println(String.format("Excluding in configuration %s", configDescription.toString()));
    // ICSourceEntry[] sourceEntries         = configDescription.getSourceEntries();
    // ICSourceEntry[] modifiedSourceEntries = CDataUtil.setExcludedIfPossible(path, isFolder, excluded, sourceEntries);
    // configDescription.setSourceEntries(modifiedSourceEntries);
    // }
    // CoreModel.getDefault().setProjectDescription(project, projectDescription);
    IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
    IConfiguration[] configurations = info.getManagedProject().getConfigurations();
    for (IConfiguration configuration : configurations) {
        // Exclude in each configuration
        System.err.println(String.format("Excluding in configuration %s", configuration.toString()));
        ICSourceEntry[] sourceEntries = configuration.getSourceEntries();
        ICSourceEntry[] modifiedSourceEntries = CDataUtil.setExcludedIfPossible(path, isFolder, excluded, sourceEntries);
        configuration.setSourceEntries(modifiedSourceEntries);
    }
}
Also used : IManagedBuildInfo(org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo) IPath(org.eclipse.core.runtime.IPath) ICSourceEntry(org.eclipse.cdt.core.settings.model.ICSourceEntry) IConfiguration(org.eclipse.cdt.managedbuilder.core.IConfiguration)

Example 4 with IManagedBuildInfo

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

the class UsbdmSetCrossCommand method process.

@Override
public void process(TemplateCore template, ProcessArgument[] args, String processId, IProgressMonitor monitor) throws ProcessFailureException {
    String projectName = null;
    String crossCommandPath = null;
    String crossCommandPrefix = null;
    for (ProcessArgument arg : args) {
        if (arg.getName().equals("projectName")) {
            // Name of project to get handle
            projectName = arg.getSimpleValue();
        } else if (arg.getName().equals("crossCommandPath")) {
            // Cross Command path
            crossCommandPath = arg.getSimpleValue();
        } else if (arg.getName().equals("crossCommandPrefix")) {
            // Cross Command prefix
            crossCommandPrefix = arg.getSimpleValue();
        } else {
            // $NON-NLS-1$
            throw new ProcessFailureException("UsbdmSetCrossCommand.process() - Unexpected argument \'" + arg.getName() + "\'");
        }
    }
    if ((projectName == null) || (crossCommandPath == null) || (crossCommandPrefix == null)) {
        // $NON-NLS-1$
        throw new ProcessFailureException("UsbdmSetCrossCommand.process() - Missing arguments");
    }
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    if (!project.exists()) {
        return;
    }
    IManagedBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(project);
    if (buildInfo == null) {
        return;
    }
// IConfiguration[] configs = buildInfo.getManagedProject().getConfigurations();
// for (IConfiguration config : configs) {
// IToolChain toolchain = config.getToolChain();
// IOption option;
// System.err.println("UsbdmSetCrossCommand.process()");
// option = toolchain.getOptionBySuperClassId(UsbdmConstants.USBDM_GCC_PREFIX_OPTION_KEY); //$NON-NLS-1$
// System.err.println("UsbdmSetCrossCommand.process() UsbdmConstants.USBDM_GCC_PREFIX_OPTION_KEY => "+option);
// ManagedBuildManager.setOption(config, toolchain, option, crossCommandPrefix);
// option = toolchain.getOptionBySuperClassId(UsbdmConstants.USBDM_GCC_PATH_OPTION_KEY); //$NON-NLS-1$
// System.err.println("UsbdmSetCrossCommand.process() UsbdmConstants.USBDM_GCC_PATH_OPTION_KEY => "+option);
// ManagedBuildManager.setOption(config, toolchain, option, crossCommandPath);
// ICfgScannerConfigBuilderInfo2Set cbi = CfgScannerConfigProfileManager.getCfgScannerConfigBuildInfo(config);
// Map<CfgInfoContext, IScannerConfigBuilderInfo2> map = cbi.getInfoMap();
// for (CfgInfoContext cfgInfoContext : map.keySet()) {
// IScannerConfigBuilderInfo2 bi = map.get(cfgInfoContext);
// String providerId = "specsFile"; //$NON-NLS-1$
// String runCommand = bi.getProviderRunCommand(providerId);
// runCommand = crossCommandPrefix + runCommand;
// bi.setProviderRunCommand(providerId, runCommand);
// try {
// bi.save();
// } catch (CoreException e) {
// System.err.println("Exception in SetCrossCommand.process()"+e.toString());
// }
// 
// // Clear the path info that was captured at project creation time
// 
// DiscoveredPathInfo pathInfo = new DiscoveredPathInfo(project);
// InfoContext infoContext = cfgInfoContext.toInfoContext();
// 
// // 1. Remove scanner info from .metadata/.plugins/org.eclipse.cdt.make.core/Project.sc
// DiscoveredScannerInfoStore dsiStore = DiscoveredScannerInfoStore.getInstance();
// try {
// dsiStore.saveDiscoveredScannerInfoToState(project, infoContext, pathInfo);
// } catch (CoreException e) {
// e.printStackTrace();
// }
// 
// // 2. Remove scanner info from CfgDiscoveredPathManager cache and from the Tool
// CfgDiscoveredPathManager cdpManager = CfgDiscoveredPathManager.getInstance();
// cdpManager.removeDiscoveredInfo(project, cfgInfoContext);
// 
// // 3. Remove scanner info from SI collector
// IScannerConfigBuilderInfo2 buildInfo2 = map.get(cfgInfoContext);
// if (buildInfo2!=null) {
// ScannerConfigProfileManager scpManager = ScannerConfigProfileManager.getInstance();
// String selectedProfileId = buildInfo2.getSelectedProfileId();
// SCProfileInstance profileInstance = scpManager.getSCProfileInstance(project, infoContext, selectedProfileId);
// 
// IScannerInfoCollector collector = profileInstance.getScannerInfoCollector();
// if (collector instanceof IScannerInfoCollectorCleaner) {
// ((IScannerInfoCollectorCleaner) collector).deleteAll(project);
// }
// buildInfo2 = null;
// }
// }
// }
// ManagedBuildManager.saveBuildInfo(project, true);
// 
// for (IConfiguration config : configs) {
// ScannerConfigBuilder.build(config, ScannerConfigBuilder.PERFORM_CORE_UPDATE, new NullProgressMonitor());
// }
}
Also used : IManagedBuildInfo(org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo) ProcessFailureException(org.eclipse.cdt.core.templateengine.process.ProcessFailureException) ProcessArgument(org.eclipse.cdt.core.templateengine.process.ProcessArgument) IProject(org.eclipse.core.resources.IProject)

Example 5 with IManagedBuildInfo

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

the class UsbdmGCCSpecsRunSIProvider method getToolPrefix.

/**
 * @param project       The project to look in for options
 * @return              The prefix for the build tools
 */
private String getToolPrefix(IProject project) {
    IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
    if (info == null) {
        return "";
    }
    IConfiguration cfg = info.getDefaultConfiguration();
    // System.err.println("UsbdmGCCSpecsRunSIProvider.initialize() Found IConfiguration = " + cfg.getName());
    IToolChain toolChain = cfg.getToolChain();
    // System.err.println("UsbdmGCCSpecsRunSIProvider.initialize() Found toolChain = " + toolChain.getName());
    // Find selected build tool (either ARM or Coldfire)
    IOption buildToolOption = toolChain.getOptionBySuperClassId(UsbdmConstants.ARM_BUILDTOOLS_OPTIONS);
    if (buildToolOption == null) {
        buildToolOption = toolChain.getOptionBySuperClassId(UsbdmConstants.COLDFIRE_BUILDTOOLS_OPTIONS);
    }
    if (buildToolOption == null) {
        return "";
    }
    // Get build path variable
    ToolInformationData toolData = ToolInformationData.getToolInformationTable().get(buildToolOption.getValue().toString());
    if (toolData == null) {
        return "";
    }
    String toolPrefixVariableId = toolData.getPrefixVariableName();
    if (toolPrefixVariableId == null) {
        return "";
    }
    UsbdmSharedSettings settings = UsbdmSharedSettings.getSharedSettings();
    String toolPrefix = null;
    if (settings != null) {
        toolPrefix = settings.get(toolPrefixVariableId);
    }
    if (toolPrefix == null) {
        toolPrefix = "Tool Prefix not set";
        return "";
    }
    // System.err.println("UsbdmGCCSpecsRunSIProvider.initialize() Found tool prefix = " + toolPrefix);
    return toolPrefix;
}
Also used : UsbdmSharedSettings(net.sourceforge.usbdm.constants.UsbdmSharedSettings) IManagedBuildInfo(org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo) ToolInformationData(net.sourceforge.usbdm.constants.ToolInformationData) IToolChain(org.eclipse.cdt.managedbuilder.core.IToolChain) IOption(org.eclipse.cdt.managedbuilder.core.IOption) IConfiguration(org.eclipse.cdt.managedbuilder.core.IConfiguration)

Aggregations

IManagedBuildInfo (org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo)8 IConfiguration (org.eclipse.cdt.managedbuilder.core.IConfiguration)6 IToolChain (org.eclipse.cdt.managedbuilder.core.IToolChain)3 CoreException (org.eclipse.core.runtime.CoreException)3 ToolInformationData (net.sourceforge.usbdm.constants.ToolInformationData)2 UsbdmSharedSettings (net.sourceforge.usbdm.constants.UsbdmSharedSettings)2 ICProjectDescription (org.eclipse.cdt.core.settings.model.ICProjectDescription)2 BuildException (org.eclipse.cdt.managedbuilder.core.BuildException)2 IOption (org.eclipse.cdt.managedbuilder.core.IOption)2 ITool (org.eclipse.cdt.managedbuilder.core.ITool)2 IPath (org.eclipse.core.runtime.IPath)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Pattern (java.util.regex.Pattern)1 IContributedEnvironment (org.eclipse.cdt.core.envvar.IContributedEnvironment)1 IEnvironmentVariable (org.eclipse.cdt.core.envvar.IEnvironmentVariable)1