Skip to content

Commit

Permalink
Move utility method ResourceTest#setBuildOrder() to only consumers ec…
Browse files Browse the repository at this point in the history
…lipse-platform#903

The method ResourceTest#setBuildOrder() has two consuming paths in the
inheritance hierarchy, one concrete test class and one abstract test
class that is lower in the type hierarchy. This change pushes down the
utility method to clean up the REsourceTest inheritance hierarchy.

Contributes to
eclipse-platform#903
  • Loading branch information
HeikoKlare committed Dec 4, 2023
1 parent bf5a19d commit 2b13542
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
package org.eclipse.core.tests.internal.builders;

import java.util.Map;
import org.eclipse.core.resources.*;
import java.util.stream.Stream;
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceDescription;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.tests.resources.ResourceTest;

Expand Down Expand Up @@ -65,4 +71,14 @@ protected void dirty(IFile file) throws CoreException {
file.setContents(getRandomContents(), true, true, getMonitor());
}

/**
* Sets the workspace build order to just contain the given projects.
*/
protected void setBuildOrder(IProject... projects) throws CoreException {
IWorkspace workspace = getWorkspace();
IWorkspaceDescription desc = workspace.getDescription();
desc.setBuildOrder(Stream.of(projects).map(IProject::getName).toArray(String[]::new));
workspace.setDescription(desc);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Stream;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileInfo;
import org.eclipse.core.filesystem.IFileStore;
Expand Down Expand Up @@ -940,16 +939,6 @@ protected void setAutoBuilding(boolean enabled) throws CoreException {
waitForBuild();
}

/**
* Sets the workspace build order to just contain the given projects.
*/
protected void setBuildOrder(IProject... projects) throws CoreException {
IWorkspace workspace = getWorkspace();
IWorkspaceDescription desc = workspace.getDescription();
desc.setBuildOrder(Stream.of(projects).map(IProject::getName).toArray(String[]::new));
workspace.setDescription(desc);
}

/**
* Blocks the calling thread until autobuild completes.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceDescription;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
Expand Down Expand Up @@ -66,7 +67,10 @@ public void test1() throws CoreException {
unsortedFile1.setContents(new ByteArrayInputStream(new byte[] { 1, 4, 3 }), true, true, null);
unsortedFile2.setContents(new ByteArrayInputStream(new byte[] { 1, 4, 3 }), true, true, null);

setBuildOrder(project1, project2);
// set build order
IWorkspaceDescription desc = workspace.getDescription();
desc.setBuildOrder(new String[] { project1.getName(), project2.getName() });
workspace.setDescription(desc);
setAutoBuilding(false);

// configure builder for project1
Expand Down

0 comments on commit 2b13542

Please sign in to comment.