KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > ClasspathValidation


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.core;
12
13 import org.eclipse.core.resources.IProject;
14 import org.eclipse.core.runtime.IPath;
15 import org.eclipse.jdt.core.IClasspathEntry;
16 import org.eclipse.jdt.core.IJavaModelStatus;
17 import org.eclipse.jdt.core.IJavaModelStatusConstants;
18 import org.eclipse.jdt.core.JavaModelException;
19 import org.eclipse.jdt.internal.core.builder.JavaBuilder;
20
21 /*
22  * Validates the raw classpath format and the resolved classpath of this project,
23  * updating markers if necessary.
24  */

25 public class ClasspathValidation {
26     
27     private JavaProject project;
28     
29     public ClasspathValidation(JavaProject project) {
30         this.project = project;
31     }
32     
33     public void validate() {
34         JavaModelManager.PerProjectInfo perProjectInfo;
35         try {
36             perProjectInfo = this.project.getPerProjectInfo();
37         } catch (JavaModelException e) {
38             // project doesn't exist
39
IProject resource = this.project.getProject();
40             if (resource.isAccessible()) {
41                 this.project.flushClasspathProblemMarkers(true/*flush cycle markers*/, true/*flush classpath format markers*/);
42                     
43                 // remove problems and tasks created by the builder
44
JavaBuilder.removeProblemsAndTasksFor(resource);
45             }
46             return;
47         }
48         
49         // use synchronized block to ensure consistency
50
IClasspathEntry[] rawClasspath;
51         IPath outputLocation;
52         IJavaModelStatus status;
53         synchronized (perProjectInfo) {
54             rawClasspath = perProjectInfo.rawClasspath;
55             outputLocation = perProjectInfo.outputLocation;
56             status = perProjectInfo.rawClasspathStatus; // status has been set during POST_CHANGE
57
}
58         
59         // update classpath format problems
60
this.project.flushClasspathProblemMarkers(false/*cycle*/, true/*format*/);
61         if (!status.isOK())
62             this.project.createClasspathProblemMarker(status);
63         
64         // update resolved classpath problems
65
this.project.flushClasspathProblemMarkers(false/*cycle*/, false/*format*/);
66         
67         if (rawClasspath != JavaProject.INVALID_CLASSPATH && outputLocation != null) {
68             for (int i = 0; i < rawClasspath.length; i++) {
69                 status = ClasspathEntry.validateClasspathEntry(this.project, rawClasspath[i], false/*src attach*/, true /*recurse in container*/);
70                 if (!status.isOK()) {
71                     if (status.getCode() == IJavaModelStatusConstants.INVALID_CLASSPATH && ((ClasspathEntry) rawClasspath[i]).isOptional())
72                         continue; // ignore this entry
73
this.project.createClasspathProblemMarker(status);
74                 }
75              }
76             status = ClasspathEntry.validateClasspath(this.project, rawClasspath, outputLocation);
77             if (!status.isOK())
78                 this.project.createClasspathProblemMarker(status);
79          }
80     }
81
82 }
83
Popular Tags