/** * Create {@code MakeTarget} from basic data elements available during copy/paste or drag/drop * operations. The other data will be set to default. * * @param name - name of make target being created. * @param targetStr - build target. * @param command - make command. ("make" by default). * @param container - container where to place the target. * @return newly created {@link IMakeTarget}. * @throws CoreException if there was a problem creating new make target. */ public static IMakeTarget createMakeTarget( String name, String targetStr, String command, IContainer container) throws CoreException { IMakeTargetManager makeTargetManager = MakeCorePlugin.getDefault().getTargetManager(); IProject project = container.getProject(); String[] ids = makeTargetManager.getTargetBuilders(project); String builderId = ids[0]; // IMakeTarget attributes IMakeTarget newMakeTarget = makeTargetManager.createTarget(project, name, builderId); if (targetStr != null) { newMakeTarget.setBuildAttribute(IMakeTarget.BUILD_TARGET, targetStr); } // IMakeCommonBuildInfo attributes String projectBuildCommand = getProjectBuildCommand(project); if (command != null && command.length() > 0 && !command.equals(projectBuildCommand)) { newMakeTarget.setBuildAttribute(IMakeCommonBuildInfo.BUILD_COMMAND, command); newMakeTarget.setUseDefaultBuildCmd(false); } else { newMakeTarget.setBuildAttribute(IMakeCommonBuildInfo.BUILD_COMMAND, projectBuildCommand); newMakeTarget.setUseDefaultBuildCmd(true); } return newMakeTarget; }
/** * Populate destination make target with data from source make target. * * @param source - source make target. * @param destination - destination make target. * @throws CoreException if there is a problem populating the target. * <p>See MakeTarget */ private static void copyTargetData(IMakeTarget source, IMakeTarget destination) throws CoreException { // IMakeTarget attributes // destination.project and destination.targetBuilderID are not changed destination.setRunAllBuilders(source.runAllBuilders()); destination.setAppendProjectEnvironment(source.appendProjectEnvironment()); destination.setBuildAttribute( IMakeTarget.BUILD_TARGET, source.getBuildAttribute(IMakeTarget.BUILD_TARGET, "")); // $NON-NLS-1$ // IMakeCommonBuildInfo attributes // Ignore IMakeCommonBuildInfo.BUILD_LOCATION in order not to pick // location of another project (or another folder) if (!source.isDefaultBuildCmd()) { destination.setBuildAttribute( IMakeCommonBuildInfo.BUILD_COMMAND, source.getBuildAttribute(IMakeCommonBuildInfo.BUILD_COMMAND, DEFAULT_BUILD_COMMAND)); destination.setBuildAttribute( IMakeCommonBuildInfo.BUILD_ARGUMENTS, source.getBuildAttribute(IMakeCommonBuildInfo.BUILD_ARGUMENTS, "")); // $NON-NLS-1$ } destination.setStopOnError(source.isStopOnError()); destination.setUseDefaultBuildCmd(source.isDefaultBuildCmd()); destination.setEnvironment(source.getEnvironment()); destination.setAppendEnvironment(source.appendEnvironment()); // setErrorParsers() is not supported in MakeTarget yet }
/** * Creating a copy of IMakeTarget in a different project. * * @param name - name of new target. * @param makeTarget - make target. * @param project - project where to assign the make target. * @return newly created make target. * @throws CoreException if there is a problem with creating or copying the target. */ private static IMakeTarget cloneTarget(String name, IMakeTarget makeTarget, IProject project) throws CoreException { IMakeTargetManager makeTargetManager = MakeCorePlugin.getDefault().getTargetManager(); String[] ids = makeTargetManager.getTargetBuilders(project); String builderId = ids[0]; IMakeTarget newMakeTarget = makeTargetManager.createTarget(project, name, builderId); copyTargetData(makeTarget, newMakeTarget); if (makeTarget .getName() .equals(makeTarget.getBuildAttribute(IMakeTarget.BUILD_TARGET, ""))) { // $NON-NLS-1$ newMakeTarget.setBuildAttribute(IMakeTarget.BUILD_TARGET, name); } return newMakeTarget; }
@Override public boolean visit(IResourceProxy proxy) throws CoreException { try { if (proxy.getType() != IResource.FOLDER && proxy.getType() != IResource.PROJECT) { return false; } IContainer container = (IContainer) proxy.requestResource(); monitor.subTask(container.getProjectRelativePath().toString()); QualifiedName qName = new QualifiedName("org.eclipse.cdt.make", "goals"); // $NON-NLS-1$ //$NON-NLS-2$ String goal = container.getPersistentProperty(qName); if (goal != null) { goal = goal.trim(); IMakeTargetManager manager = MakeCorePlugin.getDefault().getTargetManager(); String[] builder = manager.getTargetBuilders(container.getProject()); IMakeTarget target = manager.createTarget(container.getProject(), goal, builder[0]); target.setBuildAttribute(IMakeTarget.BUILD_TARGET, goal); manager.addTarget(container, target); container.setPersistentProperty(qName, null); } return true; } finally { if (--nextProgress <= 0) { // we have exhausted the current increment, so report progress monitor.worked(1); worked++; if (worked >= halfWay) { // we have passed the current halfway point, so double the // increment and reset the halfway point. currentIncrement *= 2; halfWay += (TOTAL_WORK - halfWay) / 2; } // reset the progress counter to another full increment nextProgress = currentIncrement; } } }