Skip to main content
summaryrefslogtreecommitdiffstats
blob: 924e73c8629e416a501cbed483ec21429aca06fe (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
114
115
116
117
118
119
/******************************************************************************
 * Copyright (c) 2010, 2018 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
 *    Carl Anderson - Java 9 support
 *    John Collier - Java 10 support
 ******************************************************************************/

package org.eclipse.jst.common.project.facet.core;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.IVMInstall2;
import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponent;
import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponentType;
import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponentVersion;
import org.eclipse.wst.common.project.facet.core.runtime.RuntimeManager;

/**
 * @author <a href="mailto:konstantin.komissarchik@oracle.com">Konstantin Komissarchik</a>
 */

public final class StandardJreRuntimeComponent 
{
    public static final String TYPE_ID = "standard.jre"; //$NON-NLS-1$
    public static final IRuntimeComponentType TYPE = RuntimeManager.getRuntimeComponentType( TYPE_ID );
    public static final IRuntimeComponentVersion VERSION_1_3 = TYPE.getVersion( "1.3" ); //$NON-NLS-1$
    public static final IRuntimeComponentVersion VERSION_1_4 = TYPE.getVersion( "1.4" ); //$NON-NLS-1$
    public static final IRuntimeComponentVersion VERSION_1_5 = TYPE.getVersion( "1.5" ); //$NON-NLS-1$
    public static final IRuntimeComponentVersion VERSION_1_6 = TYPE.getVersion( "1.6" ); //$NON-NLS-1$
    public static final IRuntimeComponentVersion VERSION_1_7 = TYPE.getVersion( "1.7" ); //$NON-NLS-1$
    public static final IRuntimeComponentVersion VERSION_1_8 = TYPE.getVersion( "1.8" ); //$NON-NLS-1$
    public static final IRuntimeComponentVersion VERSION_9 = TYPE.getVersion( "9" ); //$NON-NLS-1$
    public static final IRuntimeComponentVersion VERSION_10 = TYPE.getVersion( "10" ); //$NON-NLS-1$

    @Deprecated
    public static final IRuntimeComponentVersion VERSION_5_0 = VERSION_1_5;
    
    @Deprecated( )
    public static final IRuntimeComponentVersion VERSION_6_0 = VERSION_1_6;

    public static final String PROP_VM_INSTALL_TYPE = "vm-install-type"; //$NON-NLS-1$
    public static final String PROP_VM_INSTALL_ID = "vm-install-id"; //$NON-NLS-1$
    
    public static IRuntimeComponent create( final IVMInstall vmInstall )
    {
        String jvmver = null;
        
        if( vmInstall instanceof IVMInstall2 )
        {
            final IVMInstall2 vmInstall2 = (IVMInstall2) vmInstall;
            jvmver = vmInstall2.getJavaVersion();
        }
        
        final IRuntimeComponentVersion rcv;
        
        if( jvmver == null ) 
        {
            rcv = StandardJreRuntimeComponent.VERSION_1_7;
        } 
        else if( jvmver.startsWith( "1.3" ) ) //$NON-NLS-1$
        {
            rcv = StandardJreRuntimeComponent.VERSION_1_3;
        }
        else if( jvmver.startsWith( "1.4" ) ) //$NON-NLS-1$
        {
            rcv = StandardJreRuntimeComponent.VERSION_1_4;
        }
        else if( jvmver.startsWith( "1.5" ) ) //$NON-NLS-1$
        {
            rcv = StandardJreRuntimeComponent.VERSION_1_5;
        }
        else if( jvmver.startsWith( "1.6" ) ) //$NON-NLS-1$
        {
            rcv = StandardJreRuntimeComponent.VERSION_1_6;
        }
        else if( jvmver.startsWith( "1.7" ) ) //$NON-NLS-1$
        {
            rcv = StandardJreRuntimeComponent.VERSION_1_7;
        }
        else if( jvmver.startsWith( "1.8" ) ) //$NON-NLS-1$
        {
            rcv = StandardJreRuntimeComponent.VERSION_1_8;
        }
        else if( jvmver.startsWith( "9" ) ) //$NON-NLS-1$
        {
            rcv = StandardJreRuntimeComponent.VERSION_9;
        }
        else if( jvmver.startsWith( "10" ) ) //$NON-NLS-1$
        {
            rcv = StandardJreRuntimeComponent.VERSION_10;
        }
        else 
        {
            rcv = StandardJreRuntimeComponent.VERSION_10;
        }
        
        final Map<String,String> properties = new HashMap<String,String>();
        
        if( vmInstall != null )
        {
            properties.put( StandardJreRuntimeComponent.PROP_VM_INSTALL_TYPE, 
                            vmInstall.getVMInstallType().getId() );
            
            properties.put( StandardJreRuntimeComponent.PROP_VM_INSTALL_ID, 
                            vmInstall.getId() );
        }
        
        return RuntimeManager.createRuntimeComponent( rcv, properties );
    }
    
}

Back to the top