/** * Converts the {@link VertexOrder vertex order} into the appropriate {@link ProjectBuildConfigOrder build * configuration order}. * * @param order * the order to convert. * @return the converted vertex order as a build configuration order. The returning configuration can be consumed by * the Eclipse build framework. */ private static ProjectBuildConfigOrder vertexOrderToProjectBuildConfigOrder(final VertexOrder order) { final IBuildConfiguration[] buildConfigs = new IBuildConfiguration[order.vertexes.length]; System.arraycopy(order.vertexes, 0, buildConfigs, 0, order.vertexes.length); final IBuildConfiguration[][] knots = new IBuildConfiguration[order.knots.length][]; for (int i = 0; i < order.knots.length; i++) { knots[i] = new IBuildConfiguration[order.knots[i].length]; System.arraycopy(order.knots[i], 0, knots[i], 0, order.knots[i].length); } return new ProjectBuildConfigOrder(buildConfigs, order.hasCycles, knots); }
@Override public int compare(final IBuildConfiguration px, final IBuildConfiguration py) { int cmp = py.getProject().getName().compareTo(px.getProject().getName()); if (cmp == 0) { cmp = py.getName().compareTo(px.getName()); } return cmp; }
/** * Like {@link #getActiveBuildConfig()} but doesn't check accessibility. Project must be accessible. * * @see #getActiveBuildConfig() */ /* default */ IBuildConfiguration unsafeGetActiveBuildConfig() { String configName = internalGetDescription().getActiveBuildConfig(); try { if (configName != null) return getBuildConfig(configName); } catch (CoreException e) { // Build configuration doesn't exist; treat the first as active. } return internalGetBuildConfigs(false)[0]; }
/** * Creates a new job with the already ordered configurations to builder. * * @param configs * the configurations to build. * */ public RebuildWorkspaceProjectsJob(final IBuildConfiguration[] configs) { super("Building workspace"); checkState(Platform.isRunning(), "This job requires a running platform"); this.configs = checkNotNull(configs, "configs"); setSystem(false); setUser(true); setRule(BUILD_RULE); }
/** * Schedules a build with the given projects. Does nothing if the {@link Platform platform} is not running, or the * iterable of projects is empty. * * @param toUpdate * an iterable of projects to build. */ public void scheduleBuildIfNecessary(final Iterable<IProject> toUpdate) { if (Platform.isRunning() && !Iterables.isEmpty(toUpdate)) { final Workspace workspace = (Workspace) ResourcesPlugin.getWorkspace(); final IBuildConfiguration[] projectsToReBuild = from(asList(workspace.getBuildOrder())) .filter(config -> Iterables.contains(toUpdate, config.getProject())) .toArray(IBuildConfiguration.class); if (!Arrays2.isEmpty(projectsToReBuild)) { new RebuildWorkspaceProjectsJob(projectsToReBuild).schedule(); } } }
@Override public IBuildConfiguration[] internalGetReferencedBuildConfigs(final String configName, final boolean includeMissing) { final IBuildConfiguration[] filteredConfigs = from(referencedBuildConfigs) .filter(config -> !includeMissing ? config.getProject().exists() : true) .toArray(IBuildConfiguration.class); return filteredConfigs; }
private void refreshAndFullBuild(IProgressMonitor monitor) throws InvocationTargetException { List<IProject> projects = Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects()); boolean isAutoBuildEnabled = isAutoBuildEnabled(); try { if (isAutoBuildEnabled) { enableAutoBuild(false); } // refresh all projects one by one for (IProject project : projects) { if (project.isOpen()) { project.refreshLocal(IResource.DEPTH_INFINITE, null); } } // do a full build ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.CLEAN_BUILD, monitor); IBuildConfiguration[] platformBuildConfig = { ResourcesPlugin.getWorkspace().newBuildConfig("platform","platform-build")}; // build the platform first since other projects depend on it ResourcesPlugin.getWorkspace().build(platformBuildConfig, IncrementalProjectBuilder.FULL_BUILD, true, monitor); ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, monitor); } catch (CoreException e) { Activator.logError("Failed to synchronize with the platform", e); throw new InvocationTargetException(e); } if (isAutoBuildEnabled) { enableAutoBuild(true); } }
@Override public void build( IBuildConfiguration[] iBuildConfigurations, int i, boolean b, IProgressMonitor iProgressMonitor) throws CoreException { throw new UnsupportedOperationException(); }
protected boolean isFirstProjectOfKind() throws CoreException { for (IBuildConfiguration buildConfig : getContext().getAllReferencedBuildConfigs()) { if(buildConfig.getProject().hasNature(LangCore.NATURE_ID)) { return false; } } return true; }
protected boolean isLastProjectOfKind() throws CoreException { for (IBuildConfiguration buildConfig : getContext().getAllReferencingBuildConfigs()) { if(buildConfig.getProject().hasNature(LangCore.NATURE_ID)) { return false; } } return true; }
@Override public IBuildConfiguration getActiveBuildConfig() throws CoreException { return new BuildConfiguration(this); }
private void doPerformOperation(final IBuildConfiguration[] configs, final BuildOperation operation, final IProgressMonitor monitor) { if (Arrays2.isEmpty(configs)) { return; } final ISchedulingRule rule = getRule(); try { Job.getJobManager().beginRule(rule, monitor); final List<ExternalProject> projects = transform(configs, config -> (ExternalProject) config.getProject()); final List<IBuildConfiguration> buildOrder = newArrayList(getBuildOrder(projects)); if (BuildOperation.CLEAN.equals(operation)) { Collections.reverse(buildOrder); } // Remove external projects that have the workspace counterpart if it is a build operation. if (BuildOperation.BUILD.equals(operation)) { for (final Iterator<IBuildConfiguration> itr = buildOrder.iterator(); itr.hasNext(); /**/) { if (hasWorkspaceCounterpart(itr.next())) { itr.remove(); } } } checkState(buildOrder.size() == configs.length, "Inconsistency between build configuration and the ordered projects:" + "\n\tInput was: " + getProjectNames(configs) + "\n\tOrdered was: " + getProjectNames(buildOrder)); ensureDynamicDependenciesSetForWorkspaceProjects(); final String prefix = Strings.toFirstUpper(operation.toString().toLowerCase()); final String projectNames = getProjectNames(buildOrder); LOGGER.info(prefix + "ing external libraries: " + projectNames); final SubMonitor subMonitor = SubMonitor.convert(monitor, buildOrder.size()); for (final IBuildConfiguration configuration : buildOrder) { final IProject project = configuration.getProject(); LOGGER.info(prefix + "ing external library: " + project.getName()); operation.run(this, project, subMonitor.newChild(1)); } } finally { Job.getJobManager().endRule(rule); } }
/** * Returns with {@code true} if the external project is accessible in the workspace as well. */ private boolean hasWorkspaceCounterpart(IBuildConfiguration config) { final URI uri = URI.createPlatformResourceURI(config.getProject().getName(), true); final IN4JSProject n4Project = core.findProject(uri).orNull(); return null != n4Project && n4Project.exists() && !n4Project.isExternal(); }
private String getProjectNames(final Iterable<IBuildConfiguration> buildOrder) { return Iterables.toString(from(buildOrder).transform(c -> c.getProject().getName())); }
private String getProjectNames(final IBuildConfiguration[] buildOrder) { return Iterables.toString(transform(buildOrder, c -> c.getProject().getName())); }
private IBuildConfiguration getBuildConfiguration(final IProject project) { return TO_CONFIG_FUNC.apply(project); }
@Override public void build( IBuildConfiguration iBuildConfiguration, int i, IProgressMonitor iProgressMonitor) throws CoreException { throw new UnsupportedOperationException(); }
@Override public IBuildConfiguration getActiveBuildConfig() throws CoreException { throw new UnsupportedOperationException(); }
@Override public IBuildConfiguration getBuildConfig(String s) throws CoreException { throw new UnsupportedOperationException(); }
@Override public IBuildConfiguration[] getBuildConfigs() throws CoreException { throw new UnsupportedOperationException(); }
@Override public IBuildConfiguration[] getReferencedBuildConfigs(String s, boolean b) throws CoreException { throw new UnsupportedOperationException(); }
@Override public IBuildConfiguration newBuildConfig(String s, String s1) { throw new UnsupportedOperationException(); }
/** * {@inheritDoc} */ @Override public void build(final IBuildConfiguration config, final int kind, final IProgressMonitor monitor) throws CoreException { resource().build(config, kind, monitor); }
/** * {@inheritDoc} */ @Override public IBuildConfiguration getActiveBuildConfig() throws CoreException { return resource().getActiveBuildConfig(); }
/** * {@inheritDoc} */ @Override public IBuildConfiguration getBuildConfig(final String configName) throws CoreException { return resource().getBuildConfig(configName); }
/** * {@inheritDoc} */ @Override public IBuildConfiguration[] getBuildConfigs() throws CoreException { return resource().getBuildConfigs(); }
/** * {@inheritDoc} */ @Override public IBuildConfiguration[] getReferencedBuildConfigs(final String configName, final boolean includeMissing) throws CoreException { return resource().getReferencedBuildConfigs(configName, includeMissing); }
@Override public void build(IBuildConfiguration config, int kind, IProgressMonitor monitor) throws CoreException { throw new RuntimeException("Not implemented"); }
@Override public IBuildConfiguration getActiveBuildConfig() throws CoreException { throw new RuntimeException("Not implemented"); }
@Override public IBuildConfiguration getBuildConfig(String configName) throws CoreException { throw new RuntimeException("Not implemented"); }
@Override public IBuildConfiguration[] getBuildConfigs() throws CoreException { throw new RuntimeException("Not implemented"); }
@Override public IBuildConfiguration[] getReferencedBuildConfigs(String configName, boolean includeMissing) throws CoreException { throw new RuntimeException("Not implemented"); }
/** * Computes the build order among specified projects given as the argument. * * @param projects * the projects. * @return the build order as an array of build configuration instances. */ public static IBuildConfiguration[] getBuildOrder(final Iterable<ExternalProject> projects) { return vertexOrderToProjectBuildConfigOrder(computeActiveBuildConfigOrder(projects)).buildConfigurations; }
/** * Performs a full build on the given project. Same as {@link #build(IProject)} but a monitor can be provided for * the running process. * * @param project * the project to build. * @param monitor * the monitor for the full build operation. */ public void build(final IProject project, final IProgressMonitor monitor) { build(new IBuildConfiguration[] { new BuildConfiguration(project) }, monitor); }
/** * Full builds the projects given as an array of build configuration. * <p> * For information on locking see {@link #getRule()}. * * @param buildConfigs * the build configurations representing the projects to be built. * @param monitor * the monitor for the progress. Must not be {@code null}. * * @throws IllegalArgumentException * if a scheduling rule is in effect that does not contain the rule returned by {@link #getRule()}. For * more info, see {@link #getRule() here}. */ public void build(final IBuildConfiguration[] buildConfigs, final IProgressMonitor monitor) { doPerformOperation(buildConfigs, BuildOperation.BUILD, monitor); }
/** * Cleans the given project. Same as {@link #clean(IProject)} but additional {@link IProgressMonitor monitor} can be * provided for the operation. * * @param project * the project that has to be cleaned (without rebuilding it). * @param monitor * monitor for the clean process. */ public void clean(final IProject project, final IProgressMonitor monitor) { clean(new IBuildConfiguration[] { getBuildConfiguration(project) }, monitor); }
/** * Performs a clean (without rebuild) on the projects given as an array of build configuration. The clean order is * identical with the order of the elements in the {@code buildOrder} argument. * <p> * For information on locking see {@link #getRule()}. * * @param buildConfigs * the build configurations representing the the projects to be cleaned. * @param monitor * the monitor for the progress. Must not be {@code null}. * * @throws IllegalArgumentException * if a scheduling rule is in effect that does not contain the rule returned by {@link #getRule()}. For * more info, see {@link #getRule() here}. */ public void clean(final IBuildConfiguration[] buildConfigs, final IProgressMonitor monitor) { doPerformOperation(buildConfigs, BuildOperation.CLEAN, monitor); }
/** * Attach the argument as a referenced build configuration to the project. * * @param config * the configuration to attach. * @return {@link Set#add(Object)}. */ boolean add(final IBuildConfiguration config) { return referencedBuildConfigs.add(config); }