|
Lines 12-24
Link Here
|
| 12 |
package org.eclipse.jst.common.project.facet.core.internal; |
12 |
package org.eclipse.jst.common.project.facet.core.internal; |
| 13 |
|
13 |
|
| 14 |
import java.util.Collections; |
14 |
import java.util.Collections; |
|
|
15 |
import java.util.HashMap; |
| 15 |
import java.util.Hashtable; |
16 |
import java.util.Hashtable; |
| 16 |
import java.util.List; |
17 |
import java.util.List; |
|
|
18 |
import java.util.Map; |
| 17 |
|
19 |
|
| 18 |
import org.eclipse.core.resources.IProject; |
20 |
import org.eclipse.core.resources.IProject; |
| 19 |
import org.eclipse.core.resources.IWorkspace; |
21 |
import org.eclipse.core.resources.IWorkspace; |
| 20 |
import org.eclipse.core.resources.IncrementalProjectBuilder; |
22 |
import org.eclipse.core.resources.IncrementalProjectBuilder; |
| 21 |
import org.eclipse.core.resources.ProjectScope; |
|
|
| 22 |
import org.eclipse.core.resources.ResourcesPlugin; |
23 |
import org.eclipse.core.resources.ResourcesPlugin; |
| 23 |
import org.eclipse.core.runtime.CoreException; |
24 |
import org.eclipse.core.runtime.CoreException; |
| 24 |
import org.eclipse.core.runtime.IPath; |
25 |
import org.eclipse.core.runtime.IPath; |
|
Lines 28-47
Link Here
|
| 28 |
import org.eclipse.core.runtime.Status; |
29 |
import org.eclipse.core.runtime.Status; |
| 29 |
import org.eclipse.core.runtime.SubProgressMonitor; |
30 |
import org.eclipse.core.runtime.SubProgressMonitor; |
| 30 |
import org.eclipse.core.runtime.jobs.Job; |
31 |
import org.eclipse.core.runtime.jobs.Job; |
| 31 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
|
|
| 32 |
import org.eclipse.core.runtime.preferences.IScopeContext; |
| 33 |
import org.eclipse.core.runtime.preferences.InstanceScope; |
| 34 |
import org.eclipse.jdt.core.IClasspathEntry; |
32 |
import org.eclipse.jdt.core.IClasspathEntry; |
| 35 |
import org.eclipse.jdt.core.IJavaProject; |
33 |
import org.eclipse.jdt.core.IJavaProject; |
| 36 |
import org.eclipse.jdt.core.JavaCore; |
34 |
import org.eclipse.jdt.core.JavaCore; |
| 37 |
import org.eclipse.jdt.internal.core.JavaProject; |
|
|
| 38 |
import org.eclipse.jdt.launching.IVMInstall; |
35 |
import org.eclipse.jdt.launching.IVMInstall; |
| 39 |
import org.eclipse.jdt.launching.JavaRuntime; |
36 |
import org.eclipse.jdt.launching.JavaRuntime; |
| 40 |
import org.eclipse.jst.common.project.facet.core.ClasspathHelper; |
37 |
import org.eclipse.jst.common.project.facet.core.ClasspathHelper; |
| 41 |
import org.eclipse.jst.common.project.facet.core.JavaFacet; |
38 |
import org.eclipse.jst.common.project.facet.core.JavaFacet; |
| 42 |
import org.eclipse.osgi.util.NLS; |
39 |
import org.eclipse.osgi.util.NLS; |
| 43 |
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; |
40 |
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; |
| 44 |
import org.osgi.service.prefs.BackingStoreException; |
|
|
| 45 |
|
41 |
|
| 46 |
/** |
42 |
/** |
| 47 |
* @author <a href="mailto:konstantin.komissarchik@oracle.com">Konstantin Komissarchik</a> |
43 |
* @author <a href="mailto:konstantin.komissarchik@oracle.com">Konstantin Komissarchik</a> |
|
Lines 49-66
Link Here
|
| 49 |
|
45 |
|
| 50 |
public final class JavaFacetUtil |
46 |
public final class JavaFacetUtil |
| 51 |
{ |
47 |
{ |
| 52 |
public static final String FILE_CLASSPATH = JavaProject.CLASSPATH_FILENAME; |
48 |
public static final String FILE_CLASSPATH = ".classpath"; //$NON-NLS-1$ |
| 53 |
public static final String FILE_JDT_CORE_PREFS = ".settings/org.eclipse.jdt.core.prefs"; //$NON-NLS-1$ |
49 |
public static final String FILE_JDT_CORE_PREFS = ".settings/org.eclipse.jdt.core.prefs"; //$NON-NLS-1$ |
| 54 |
|
50 |
|
|
|
51 |
private static final IPath CPE_PREFIX_FOR_EXEC_ENV |
| 52 |
= new Path( "org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType" ); //$NON-NLS-1$ |
| 53 |
|
| 54 |
private static final Map<IProjectFacetVersion,String> FACET_VER_TO_EXEC_ENV = new HashMap<IProjectFacetVersion,String>(); |
| 55 |
|
| 56 |
static |
| 57 |
{ |
| 58 |
FACET_VER_TO_EXEC_ENV.put( JavaFacet.VERSION_1_3, "J2SE-1.3" ); //$NON-NLS-1$ |
| 59 |
FACET_VER_TO_EXEC_ENV.put( JavaFacet.VERSION_1_4, "J2SE-1.4" ); //$NON-NLS-1$ |
| 60 |
FACET_VER_TO_EXEC_ENV.put( JavaFacet.VERSION_1_5, "J2SE-1.5" ); //$NON-NLS-1$ |
| 61 |
FACET_VER_TO_EXEC_ENV.put( JavaFacet.VERSION_1_6, "JavaSE-1.6" ); //$NON-NLS-1$ |
| 62 |
FACET_VER_TO_EXEC_ENV.put( JavaFacet.VERSION_1_7, "JavaSE-1.7" ); //$NON-NLS-1$ |
| 63 |
} |
| 64 |
|
| 55 |
public static String getCompilerLevel() |
65 |
public static String getCompilerLevel() |
| 56 |
{ |
66 |
{ |
| 57 |
final IScopeContext context = new InstanceScope(); |
67 |
String level = JavaCore.getOption( JavaCore.COMPILER_COMPLIANCE ); |
| 58 |
final IEclipsePreferences prefs = context.getNode( JavaCore.PLUGIN_ID ); |
|
|
| 59 |
String level = prefs.get( JavaCore.COMPILER_COMPLIANCE, null ); |
| 60 |
|
68 |
|
| 61 |
if( level == null ) |
69 |
if( level == null ) |
| 62 |
{ |
70 |
{ |
| 63 |
final Hashtable defaults = JavaCore.getDefaultOptions(); |
71 |
final Hashtable<?,?> defaults = JavaCore.getDefaultOptions(); |
| 64 |
level = (String) defaults.get( JavaCore.COMPILER_COMPLIANCE ); |
72 |
level = (String) defaults.get( JavaCore.COMPILER_COMPLIANCE ); |
| 65 |
} |
73 |
} |
| 66 |
|
74 |
|
|
Lines 69-77
Link Here
|
| 69 |
|
77 |
|
| 70 |
public static String getCompilerLevel( final IProject project ) |
78 |
public static String getCompilerLevel( final IProject project ) |
| 71 |
{ |
79 |
{ |
| 72 |
final IScopeContext context = new ProjectScope( project ); |
80 |
final IJavaProject jproj = JavaCore.create( project ); |
| 73 |
final IEclipsePreferences prefs = context.getNode( JavaCore.PLUGIN_ID ); |
81 |
String level = jproj.getOption( JavaCore.COMPILER_COMPLIANCE, false ); |
| 74 |
String level = prefs.get( JavaCore.COMPILER_COMPLIANCE, null ); |
|
|
| 75 |
|
82 |
|
| 76 |
if( level == null ) |
83 |
if( level == null ) |
| 77 |
{ |
84 |
{ |
|
Lines 87-93
Link Here
|
| 87 |
throws CoreException |
94 |
throws CoreException |
| 88 |
|
95 |
|
| 89 |
{ |
96 |
{ |
| 90 |
setCompilerLevel( project, facetToCompilerLevel( fv ) ); |
97 |
setCompilerLevel( project, fv.getVersionString() ); |
| 91 |
} |
98 |
} |
| 92 |
|
99 |
|
| 93 |
public static void setCompilerLevel( final IProject project, |
100 |
public static void setCompilerLevel( final IProject project, |
|
Lines 96-151
Link Here
|
| 96 |
throws CoreException |
103 |
throws CoreException |
| 97 |
|
104 |
|
| 98 |
{ |
105 |
{ |
| 99 |
final IScopeContext context = new ProjectScope( project ); |
106 |
final IJavaProject jproj = JavaCore.create( project ); |
| 100 |
|
107 |
final Map<?,?> options = jproj.getOptions( false ); |
| 101 |
final IEclipsePreferences prefs |
108 |
JavaCore.setComplianceOptions( level, options ); |
| 102 |
= context.getNode( JavaCore.PLUGIN_ID ); |
109 |
jproj.setOptions( options ); |
| 103 |
|
|
|
| 104 |
if( level.equals( JavaCore.VERSION_1_3 ) ) |
| 105 |
{ |
| 106 |
prefs.put( JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_3 ); |
| 107 |
prefs.put( JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_1 ); |
| 108 |
prefs.put( JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3 ); |
| 109 |
prefs.put( JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.IGNORE ); |
| 110 |
prefs.put( JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.IGNORE ); |
| 111 |
} |
| 112 |
else if( level.equals( JavaCore.VERSION_1_4 ) ) |
| 113 |
{ |
| 114 |
prefs.put( JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4 ); |
| 115 |
prefs.put( JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2 ); |
| 116 |
prefs.put( JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3 ); |
| 117 |
prefs.put( JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.WARNING ); |
| 118 |
prefs.put( JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.WARNING ); |
| 119 |
} |
| 120 |
else if( level.equals( JavaCore.VERSION_1_5 ) ) |
| 121 |
{ |
| 122 |
prefs.put( JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5 ); |
| 123 |
prefs.put( JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5 ); |
| 124 |
prefs.put( JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5 ); |
| 125 |
prefs.put( JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR ); |
| 126 |
prefs.put( JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR ); |
| 127 |
} |
| 128 |
else if( level.equals( JavaCore.VERSION_1_6 ) ) |
| 129 |
{ |
| 130 |
prefs.put( JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_6 ); |
| 131 |
prefs.put( JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_6 ); |
| 132 |
prefs.put( JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6 ); |
| 133 |
prefs.put( JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR ); |
| 134 |
prefs.put( JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR ); |
| 135 |
} |
| 136 |
else |
| 137 |
{ |
| 138 |
throw new IllegalStateException(); |
| 139 |
} |
| 140 |
|
| 141 |
try |
| 142 |
{ |
| 143 |
prefs.flush(); |
| 144 |
} |
| 145 |
catch( BackingStoreException e ) |
| 146 |
{ |
| 147 |
// TODO: Handle this. |
| 148 |
} |
| 149 |
} |
110 |
} |
| 150 |
|
111 |
|
| 151 |
public static void scheduleFullBuild( final IProject project ) |
112 |
public static void scheduleFullBuild( final IProject project ) |
|
Lines 219-232
Link Here
|
| 219 |
|
180 |
|
| 220 |
if( vm != null ) |
181 |
if( vm != null ) |
| 221 |
{ |
182 |
{ |
| 222 |
IPath path = new Path( JavaRuntime.JRE_CONTAINER ); |
183 |
final IPath path = CPE_PREFIX_FOR_EXEC_ENV.append( getCorrespondingExecutionEnvironment( newver ) ); |
| 223 |
path = path.append( vm.getVMInstallType().getId() ); |
184 |
final IClasspathEntry cpe = JavaCore.newContainerEntry( path ); |
| 224 |
path = path.append( vm.getName() ); |
185 |
final List<IClasspathEntry> entries = Collections.singletonList( cpe ); |
| 225 |
|
|
|
| 226 |
final IClasspathEntry cpe |
| 227 |
= JavaCore.newContainerEntry( path ); |
| 228 |
|
| 229 |
final List entries = Collections.singletonList( cpe ); |
| 230 |
|
186 |
|
| 231 |
ClasspathHelper.addClasspathEntries( project, newver, entries ); |
187 |
ClasspathHelper.addClasspathEntries( project, newver, entries ); |
| 232 |
} |
188 |
} |
|
Lines 269-304
Link Here
|
| 269 |
jproj.setRawClasspath( newcp, null ); |
225 |
jproj.setRawClasspath( newcp, null ); |
| 270 |
} |
226 |
} |
| 271 |
|
227 |
|
| 272 |
public static IProjectFacetVersion compilerLevelToFacet( final String ver ) |
228 |
public static String getCorrespondingExecutionEnvironment( final IProjectFacetVersion fv ) |
| 273 |
{ |
229 |
{ |
| 274 |
if( ver.equals( "1.5" ) ) //$NON-NLS-1$ |
230 |
final String res = FACET_VER_TO_EXEC_ENV.get( fv ); |
| 275 |
{ |
231 |
|
| 276 |
return JavaFacet.JAVA_50; |
232 |
if( res == null ) |
| 277 |
} |
|
|
| 278 |
else if( ver.equals( "1.6" ) ) //$NON-NLS-1$ |
| 279 |
{ |
| 280 |
return JavaFacet.JAVA_60; |
| 281 |
} |
| 282 |
else |
| 283 |
{ |
| 284 |
return JavaFacet.FACET.getVersion( ver ); |
| 285 |
} |
| 286 |
} |
| 287 |
|
| 288 |
public static String facetToCompilerLevel( final IProjectFacetVersion fv ) |
| 289 |
{ |
| 290 |
if( fv == JavaFacet.JAVA_50 ) |
| 291 |
{ |
| 292 |
return JavaCore.VERSION_1_5; |
| 293 |
} |
| 294 |
else if( fv == JavaFacet.JAVA_60 ) |
| 295 |
{ |
| 296 |
return JavaCore.VERSION_1_6; |
| 297 |
} |
| 298 |
else |
| 299 |
{ |
233 |
{ |
| 300 |
return fv.getVersionString(); |
234 |
throw new IllegalArgumentException( fv.toString() ); |
| 301 |
} |
235 |
} |
|
|
236 |
|
| 237 |
return res; |
| 302 |
} |
238 |
} |
| 303 |
|
239 |
|
| 304 |
private static final class Resources |
240 |
private static final class Resources |