Skip to main content
summaryrefslogtreecommitdiffstats
blob: c4161f49b9a9a3e3bd5658e9a835d969cd11fefe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/******************************************************************************
 * Copyright (c) 2006 BEA Systems, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Konstantin Komissarchik - initial API and implementation
 ******************************************************************************/

package org.eclipse.jst.common.jdt.internal.classpath;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jem.util.logger.proxy.Logger;

/**
 * @author <a href="mailto:kosta@bea.com">Konstantin Komissarchik</a>
 */

public final class ClasspathUtil
{
    private ClasspathUtil() {}
    
    public static Set getResolvedClasspath( final IJavaProject jproj,
                                            final IPath entryToIgnore )
    {
        return getResolvedClasspath( jproj, Collections.singleton( entryToIgnore ) );
    }
    
    public static Set getResolvedClasspath( final IJavaProject jproj,
                                            final Set entriesToIgnore )
    {
        final Set resolved = new HashSet();
        
        try 
        {
            final IClasspathEntry[] entries = jproj.getRawClasspath();
            
            for( int i = 0; i < entries.length; i++ )
            {
                IClasspathEntry entry = entries[ i ];
                
                if( entriesToIgnore.contains( entry.getPath() ) )
                {
                    continue;
                }
                
                switch( entry.getEntryKind() )
                {
                    case IClasspathEntry.CPE_LIBRARY:
                    case IClasspathEntry.CPE_PROJECT:
                    {
                        resolved.add( entry.getPath() );
                        break;
                    }
                    case IClasspathEntry.CPE_VARIABLE:
                    {
                        entry = JavaCore.getResolvedClasspathEntry( entry );
                        
                        if( entry != null )
                        {
                            resolved.add( entry.getPath() );
                        }
                        
                        break;
                    }
                    case IClasspathEntry.CPE_CONTAINER:
                    {
                        final IClasspathContainer container;
                        
                        try
                        {
                            container = JavaCore.getClasspathContainer( entry.getPath(), jproj );
                        }
                        catch( JavaModelException e )
                        {
                            Logger.getLogger().logError( e );
                            continue;
                        }
                        
                        if( container != null ) 
                        {
	                        final IClasspathEntry[] containerEntries
	                            = container.getClasspathEntries();
	
	                        for( int j = 0; j < containerEntries.length; j++ )
	                        {
	                            resolved.add( containerEntries[ j ].getPath() );
	                        }
                        }
                    }
                }
            }
        } 
        catch( JavaModelException e ) 
        {
            Logger.getLogger().logError( e );
        }
        
        return resolved;
    }

}

Back to the top