18
18
import static org .junit .Assert .assertTrue ;
19
19
20
20
import java .util .ArrayList ;
21
- import java .util .Arrays ;
22
21
import java .util .List ;
22
+ import java .util .concurrent .TimeUnit ;
23
+ import java .util .stream .Collectors ;
23
24
24
25
import org .eclipse .core .resources .IProject ;
25
26
import org .eclipse .jdt .core .IClasspathContainer ;
30
31
import org .eclipse .pde .internal .core .PDECore ;
31
32
import org .eclipse .pde .ui .tests .classpathresolver .ClasspathResolverTest ;
32
33
import org .eclipse .pde .ui .tests .util .ProjectUtils ;
34
+ import org .eclipse .swt .widgets .Display ;
33
35
import org .junit .ClassRule ;
34
36
import org .junit .Rule ;
35
37
import org .junit .Test ;
@@ -50,18 +52,37 @@ public class ClasspathContributorTest {
50
52
@ Test
51
53
public void testAdditionalClasspathEntries () throws Exception {
52
54
IProject project = ProjectUtils .importTestProject ("tests/projects/" + ClasspathResolverTest .bundleName );
53
- List <IClasspathEntry > expected = new ArrayList <>(TestClasspathContributor .entries );
54
- expected .addAll (TestClasspathContributor .entries2 );
55
- IJavaProject jProject = JavaCore .create (project );
56
- IClasspathContainer container = JavaCore .getClasspathContainer (PDECore .REQUIRED_PLUGINS_CONTAINER_PATH , jProject );
57
- assertNotNull ("Could not find PDE classpath container" , container );
58
- IClasspathEntry [] classpath = container .getClasspathEntries ();
59
- for (IClasspathEntry element : classpath ) {
60
- if (!isPdeDependency (element )) {
61
- assertTrue ("Unexpected classpath entry found: " + element , expected .remove (element ));
55
+ long deadline = System .currentTimeMillis () + TimeUnit .SECONDS .toMillis (60 );
56
+ while (true ) {
57
+ Display current = Display .getCurrent ();
58
+ if (current != null ) {
59
+ while (current .readAndDispatch ()) {
60
+ Thread .onSpinWait ();
61
+ }
62
+ }
63
+ try {
64
+ List <IClasspathEntry > expected = new ArrayList <>(TestClasspathContributor .entries );
65
+ expected .addAll (TestClasspathContributor .entries2 );
66
+ IJavaProject jProject = JavaCore .create (project );
67
+ IClasspathContainer container = JavaCore .getClasspathContainer (PDECore .REQUIRED_PLUGINS_CONTAINER_PATH ,
68
+ jProject );
69
+ assertNotNull ("Could not find PDE classpath container" , container );
70
+ IClasspathEntry [] classpath = container .getClasspathEntries ();
71
+ for (IClasspathEntry element : classpath ) {
72
+ if (!isPdeDependency (element )) {
73
+ assertTrue ("Unexpected classpath entry found: " + element , expected .remove (element ));
74
+ }
75
+ }
76
+ assertTrue ("Expected classpath entry not found: "
77
+ + expected .stream ().map (String ::valueOf ).collect (Collectors .joining (System .lineSeparator ())),
78
+ expected .isEmpty ());
79
+ break ;
80
+ } catch (AssertionError e ) {
81
+ if (System .currentTimeMillis () > deadline ) {
82
+ throw e ;
83
+ }
62
84
}
63
85
}
64
- assertTrue ("Expected classpath entry not found: " + Arrays .toString (expected .toArray ()), expected .isEmpty ());
65
86
}
66
87
67
88
private boolean isPdeDependency (IClasspathEntry element ) {
0 commit comments