Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 653d5c105657beba3b6c5a7f756761b3dd8becb5 (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
/******************************************************************************
 * Copyright (c) 2008 Oracle
 * 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 implementation and ongoing maintenance
 ******************************************************************************/

package org.eclipse.jst.jsf.core.internal.project.facet;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jst.common.project.facet.core.libprov.ILibraryProvider;
import org.eclipse.jst.common.project.facet.core.libprov.LegacyLibraryProviderDetector;
import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderFramework;
import org.eclipse.jst.jsf.core.internal.JSFCorePlugin;
import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryRegistryUtil;
import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibrary;
import org.eclipse.jst.jsf.core.jsflibraryconfiguration.JSFLibraryConfigurationHelper;
import org.eclipse.wst.common.project.facet.core.IProjectFacet;

/**
 * @author <a href="mailto:konstantin.komissarchik@oracle.com">Konstantin Komissarchik</a>
 */
@SuppressWarnings("deprecation")
public final class LegacyJSFLibraryProviderDetector

    extends LegacyLibraryProviderDetector
    
{
    private static final String LEGACY_JSF_LIBRARY_PROVIDER_ID 
        = "legacy-jsf-library-provider"; //$NON-NLS-1$

    @Override
    public ILibraryProvider detect( final IProject project,
                                    final IProjectFacet facet )
    {
        try
        {
            final IJavaProject jproj = JavaCore.create( project );
            
            for( IClasspathEntry cpe : jproj.getRawClasspath() )
            {
                if( detect( cpe ) )
                {
                    return LibraryProviderFramework.getProvider( LEGACY_JSF_LIBRARY_PROVIDER_ID );
                }
            }
        }
        catch( Exception e )
        {
            JSFCorePlugin.log( e, e.getMessage() );
        }

        return null;
    }
    
    /**
     * @param cpe
     * @return true if the classpath entry is detected
     */
    public static boolean detect( final IClasspathEntry cpe )
    {
        if( cpe.getEntryKind() == IClasspathEntry.CPE_CONTAINER )
        {
            final IPath path = cpe.getPath();
            
            if( isJSFLibraryContainer( path ) ) 
            {
                String libId = path.lastSegment();
                JSFLibrary ref = JSFLibraryRegistryUtil.getInstance().getJSFLibraryRegistry().getJSFLibraryByID(libId);
                
                if( ref != null && ref.isImplementation() )
                {
                    return true;
                }
            }
        }
        
        return false;
    }
    
    private static boolean isJSFLibraryContainer(IPath path) {
        return path != null && path.segmentCount() == 2 && JSFLibraryConfigurationHelper.JSF_LIBRARY_CP_CONTAINER_ID.equals(path.segment(0));
    }
    
}

Back to the top