|
Removed
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2009 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.jst.j2ee.project; |
| 12 |
|
| 13 |
import java.util.Collections; |
| 14 |
import java.util.Iterator; |
| 15 |
import java.util.List; |
| 16 |
|
| 17 |
import org.eclipse.core.resources.IContainer; |
| 18 |
import org.eclipse.core.resources.IFolder; |
| 19 |
import org.eclipse.core.resources.IProject; |
| 20 |
import org.eclipse.core.resources.IResource; |
| 21 |
import org.eclipse.core.runtime.CoreException; |
| 22 |
import org.eclipse.core.runtime.IPath; |
| 23 |
import org.eclipse.core.runtime.IStatus; |
| 24 |
import org.eclipse.core.runtime.MultiStatus; |
| 25 |
import org.eclipse.core.runtime.Path; |
| 26 |
import org.eclipse.core.runtime.Status; |
| 27 |
import org.eclipse.jst.common.jdt.internal.javalite.JavaLiteUtilities; |
| 28 |
import org.eclipse.jst.j2ee.internal.J2EEConstants; |
| 29 |
import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin; |
| 30 |
import org.eclipse.jst.j2ee.internal.project.SingleRootStatus; |
| 31 |
import org.eclipse.wst.common.componentcore.internal.ComponentResource; |
| 32 |
import org.eclipse.wst.common.componentcore.internal.Property; |
| 33 |
import org.eclipse.wst.common.componentcore.internal.StructureEdit; |
| 34 |
import org.eclipse.wst.common.componentcore.internal.WorkbenchComponent; |
| 35 |
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; |
| 36 |
import org.eclipse.wst.common.componentcore.resources.IVirtualReference; |
| 37 |
|
| 38 |
public class SingleRootUtil { |
| 39 |
|
| 40 |
|
| 41 |
/** |
| 42 |
* Used to return immediately after the first error code is found. |
| 43 |
*/ |
| 44 |
public static final int INCLUDE_FIRST_ERROR = 0x08; |
| 45 |
/** |
| 46 |
* Used to capture all status codes (error, warning, info) |
| 47 |
*/ |
| 48 |
public static final int INCLUDE_ALL = 0x07; |
| 49 |
/** |
| 50 |
* Used to capture all error and warning status codes only. |
| 51 |
*/ |
| 52 |
public static final int INCLUDE_ERRORS_AND_WARNINGS = 0x06; |
| 53 |
/** |
| 54 |
* Used to capture all error status codes only. |
| 55 |
*/ |
| 56 |
public static final int INCLUDE_ERRORS = 0x04; |
| 57 |
|
| 58 |
private static final int WARNINGS = 0x02; |
| 59 |
private static final int INFO = 0x01; |
| 60 |
private static final int CANCEL = 0x0; |
| 61 |
private static final int GET_SINGLE_ROOT_CONTAINER = 0x09; |
| 62 |
private static String USE_SINGLE_ROOT_PROPERTY = "useSingleRoot"; //$NON-NLS-1$ |
| 63 |
private IVirtualComponent aComponent; |
| 64 |
private List<IContainer> cachedSourceContainers; |
| 65 |
private IContainer[] cachedOutputContainers; |
| 66 |
private MultiStatus wrapperStatus; |
| 67 |
private int VALIDATE_FLAG; |
| 68 |
|
| 69 |
public SingleRootUtil(IVirtualComponent component) { |
| 70 |
this.aComponent = component; |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Returns true if this module has a simple structure based on a |
| 75 |
* single-root folder, and false otherwise. |
| 76 |
* |
| 77 |
* In a single-root structure, all files that are contained within the root folder |
| 78 |
* are part of the module, and are already in the correct module structure. No |
| 79 |
* module resources exist outside of this single folder. |
| 80 |
* |
| 81 |
* @return true if this module has a single-root structure, and |
| 82 |
* false otherwise |
| 83 |
*/ |
| 84 |
public boolean isSingleRoot() { |
| 85 |
return validateSingleRoot(INCLUDE_FIRST_ERROR).getSeverity() != IStatus.ERROR; |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Will attempt to return the IContainer that counts as the "single-root". |
| 90 |
* If this module does not qualify as a "single-root" module, this |
| 91 |
* method will return null. Otherwise it will return an IContainer |
| 92 |
* that may be used as the single-root container. |
| 93 |
* |
| 94 |
* @return IContainer representing single-root container |
| 95 |
*/ |
| 96 |
public IContainer getSingleRoot() { |
| 97 |
IStatus status = validateSingleRoot(GET_SINGLE_ROOT_CONTAINER); |
| 98 |
if (status.getSeverity() == IStatus.INFO) { |
| 99 |
IStatus[] children = ((MultiStatus) status).getChildren(); |
| 100 |
ISingleRootStatus rootStatus = (ISingleRootStatus) children[0]; |
| 101 |
return rootStatus.getSingleRoot(); |
| 102 |
} |
| 103 |
return null; |
| 104 |
} |
| 105 |
|
| 106 |
/** |
| 107 |
* Validates whether the component module has a single-root structure. |
| 108 |
* An IStatus with a severity of OK is returned for a valid single-root |
| 109 |
* structure. A MultiStatus containing children of type ISingleRootStatus |
| 110 |
* is returned if any status codes were captured during the validation. |
| 111 |
* A MultiStatus with a severity of INFO or WARNING is returned for a valid |
| 112 |
* single-root structure containing status codes with no severities of ERROR. |
| 113 |
* A MultiStatus with a severity of ERROR means the component does not have a |
| 114 |
* valid single-root structure. |
| 115 |
* |
| 116 |
* @param flag - indicates the status codes (by severity) to capture during |
| 117 |
* the validation. The INLCUDE_ALL flag will also capture the |
| 118 |
* single-root container if a single-root structure was found. |
| 119 |
* Valid flags are: |
| 120 |
* INCLUDE_ALL |
| 121 |
* INCLUDE_ERRORS_AND_WARNINGS |
| 122 |
* INCLUDE_ERRORS |
| 123 |
* INCLUDE_FIRST_ERROR |
| 124 |
* |
| 125 |
* @return IStatus |
| 126 |
*/ |
| 127 |
public IStatus validateSingleRoot(int flag) { |
| 128 |
VALIDATE_FLAG = flag; |
| 129 |
wrapperStatus = null; |
| 130 |
StructureEdit edit = null; |
| 131 |
try { |
| 132 |
edit = StructureEdit.getStructureEditForRead(getProject()); |
| 133 |
if (edit == null || edit.getComponent() == null) { |
| 134 |
reportStatus(ISingleRootStatus.NO_COMPONENT_FOUND); |
| 135 |
return getStatus(); |
| 136 |
} |
| 137 |
|
| 138 |
// 229650 - check to see if the property 'useSingleRoot' is defined. |
| 139 |
Boolean useSingleRoot = getUseSingleRootProperty(edit); |
| 140 |
if (useSingleRoot != null) { |
| 141 |
//check if it was set to false |
| 142 |
if (!useSingleRoot.booleanValue()) { |
| 143 |
reportStatus(ISingleRootStatus.EXPLICITLY_DISABLED); |
| 144 |
} |
| 145 |
else { |
| 146 |
reportStatus(ISingleRootStatus.SINGLE_ROOT_FORCED, aComponent.getRootFolder().getUnderlyingFolder()); |
| 147 |
} |
| 148 |
return getStatus(); |
| 149 |
} |
| 150 |
|
| 151 |
if (JavaEEProjectUtilities.isEARProject(getProject())) { |
| 152 |
// Always return false for EARs so that members for EAR are always calculated and j2ee modules are filtered out |
| 153 |
reportStatus(ISingleRootStatus.EAR_PROJECT_FOUND); |
| 154 |
return getStatus(); |
| 155 |
} |
| 156 |
|
| 157 |
// if there are any consumed references, this is not single-root |
| 158 |
if (hasConsumableReferences(aComponent)) { |
| 159 |
reportStatus(ISingleRootStatus.CONSUMABLE_REFERENCES_FOUND); |
| 160 |
if (VALIDATE_FLAG == CANCEL) |
| 161 |
return getStatus(); |
| 162 |
} |
| 163 |
|
| 164 |
// if there are any linked resources then this is not a single-root module |
| 165 |
if (rootFoldersHaveLinkedContent()) { |
| 166 |
reportStatus(ISingleRootStatus.LINKED_RESOURCES_FOUND); |
| 167 |
if (VALIDATE_FLAG == CANCEL) |
| 168 |
return getStatus(); |
| 169 |
} |
| 170 |
|
| 171 |
List resourceMaps = edit.getComponent().getResources(); |
| 172 |
|
| 173 |
// If the list is empty, return false |
| 174 |
if (resourceMaps.size() < 1) { |
| 175 |
reportStatus(ISingleRootStatus.NO_RESOURCE_MAPS_FOUND); |
| 176 |
return getStatus(); |
| 177 |
} |
| 178 |
|
| 179 |
if (resourceMaps.size() == 1) { |
| 180 |
ComponentResource mapping = (ComponentResource)resourceMaps.get(0); |
| 181 |
if (isRootMapping(mapping)) { |
| 182 |
IResource sourceResource = getProject().findMember(mapping.getSourcePath()); |
| 183 |
if (sourceResource != null && sourceResource.exists()) { |
| 184 |
if (sourceResource instanceof IContainer && !isSourceContainer((IContainer) sourceResource)) { |
| 185 |
reportStatus(ISingleRootStatus.SINGLE_ROOT_CONTAINER_FOUND, (IContainer) sourceResource); |
| 186 |
return getStatus(); |
| 187 |
} |
| 188 |
} |
| 189 |
} |
| 190 |
} |
| 191 |
|
| 192 |
if (JavaEEProjectUtilities.isDynamicWebProject(getProject())) { |
| 193 |
//validate web projects for single root |
| 194 |
validateWebProject(resourceMaps); |
| 195 |
} else { |
| 196 |
validateProject(resourceMaps); |
| 197 |
} |
| 198 |
//return the current status |
| 199 |
return getStatus(); |
| 200 |
} finally { |
| 201 |
cachedOutputContainers = null; |
| 202 |
cachedSourceContainers = null; |
| 203 |
if (edit != null) |
| 204 |
edit.dispose(); |
| 205 |
} |
| 206 |
} |
| 207 |
|
| 208 |
protected Boolean getUseSingleRootProperty(StructureEdit edit) { |
| 209 |
WorkbenchComponent wbComp = edit.getComponent(); |
| 210 |
final List componentProperties = wbComp.getProperties(); |
| 211 |
if (componentProperties != null) { |
| 212 |
final Iterator componentPropertiesIterator = componentProperties.iterator(); |
| 213 |
while (componentPropertiesIterator.hasNext()) { |
| 214 |
Property wbProperty = (Property) componentPropertiesIterator.next(); |
| 215 |
if (USE_SINGLE_ROOT_PROPERTY.equals(wbProperty.getName())) { |
| 216 |
return Boolean.valueOf(wbProperty.getValue()); |
| 217 |
} |
| 218 |
} |
| 219 |
} |
| 220 |
return null; |
| 221 |
} |
| 222 |
|
| 223 |
protected boolean hasConsumableReferences(IVirtualComponent vc) { |
| 224 |
IVirtualReference[] refComponents = vc.getReferences(); |
| 225 |
for (int i = 0; i < refComponents.length; i++) { |
| 226 |
IVirtualReference reference = refComponents[i]; |
| 227 |
if (reference != null && reference.getDependencyType()==IVirtualReference.DEPENDENCY_TYPE_CONSUMES) { |
| 228 |
return true; |
| 229 |
} |
| 230 |
} |
| 231 |
return false; |
| 232 |
} |
| 233 |
|
| 234 |
private void validateProject(List resourceMaps) { |
| 235 |
// Ensure there are only source folder component resource mappings to the root content folder |
| 236 |
if (isRootResourceMapping(resourceMaps)) { |
| 237 |
IContainer[] javaOutputFolders = getJavaOutputFolders(); |
| 238 |
// Verify only one java outputfolder |
| 239 |
if (javaOutputFolders.length == 1) { |
| 240 |
// By the time we get here we know: for any folders defined as source in the |
| 241 |
// .component file that they are also java source folders. |
| 242 |
if (!isSourceContainer(javaOutputFolders[0])) { |
| 243 |
// The single output folder is NOT a source folder so this is single-rooted. Since the |
| 244 |
// output folder (something like classes or bin) is not a source folder, JDT copies all files |
| 245 |
// (including non Java files) to this folder, so every resource needed at runtime is located |
| 246 |
// in a single directory. |
| 247 |
reportStatus(ISingleRootStatus.SINGLE_ROOT_CONTAINER_FOUND, javaOutputFolders[0]); |
| 248 |
return; |
| 249 |
} |
| 250 |
// Verify the java output folder is the same as one of the content roots |
| 251 |
IPath javaOutputPath = getJavaOutputFolders()[0].getProjectRelativePath(); |
| 252 |
IContainer[] rootFolders = aComponent.getRootFolder().getUnderlyingFolders(); |
| 253 |
for (int i=0; i < rootFolders.length; i++) { |
| 254 |
IPath compRootPath = rootFolders[i].getProjectRelativePath(); |
| 255 |
if (javaOutputPath.equals(compRootPath)) { |
| 256 |
reportStatus(ISingleRootStatus.SINGLE_ROOT_CONTAINER_FOUND, aComponent.getRootFolder().getUnderlyingFolder()); |
| 257 |
return; |
| 258 |
} |
| 259 |
} |
| 260 |
reportStatus(ISingleRootStatus.JAVA_OUTPUT_NOT_A_CONTENT_ROOT); |
| 261 |
} |
| 262 |
else { |
| 263 |
reportStatus(ISingleRootStatus.JAVA_OUTPUT_GREATER_THAN_1); |
| 264 |
} |
| 265 |
} |
| 266 |
} |
| 267 |
|
| 268 |
private void validateWebProject(List resourceMaps) { |
| 269 |
// Ensure there are only basic component resource mappings -- one for the content folder |
| 270 |
// and any for src folders mapped to WEB-INF/classes |
| 271 |
if (hasDefaultWebResourceMappings(resourceMaps)) { |
| 272 |
IContainer[] javaOutputFolders = getJavaOutputFolders(); |
| 273 |
// Verify only one java output folder |
| 274 |
if (javaOutputFolders.length == 1) { |
| 275 |
// Verify the java output folder is to <content root>/WEB-INF/classes |
| 276 |
IPath javaOutputPath = getJavaOutputFolders()[0].getProjectRelativePath(); |
| 277 |
IContainer rootContainer = aComponent.getRootFolder().getUnderlyingFolder(); |
| 278 |
IPath compRootPath = rootContainer.getProjectRelativePath(); |
| 279 |
if (compRootPath.append(J2EEConstants.WEB_INF_CLASSES).equals(javaOutputPath)) { |
| 280 |
reportStatus(ISingleRootStatus.SINGLE_ROOT_CONTAINER_FOUND, rootContainer); |
| 281 |
return; |
| 282 |
} |
| 283 |
reportStatus(ISingleRootStatus.JAVA_OUTPUT_NOT_WEBINF_CLASSES); |
| 284 |
} |
| 285 |
else { |
| 286 |
reportStatus(ISingleRootStatus.JAVA_OUTPUT_GREATER_THAN_1); |
| 287 |
} |
| 288 |
} |
| 289 |
} |
| 290 |
|
| 291 |
public IContainer[] getJavaOutputFolders() { |
| 292 |
if (cachedOutputContainers == null) |
| 293 |
cachedOutputContainers = getJavaOutputFolders(aComponent); |
| 294 |
return cachedOutputContainers; |
| 295 |
} |
| 296 |
|
| 297 |
public IContainer[] getJavaOutputFolders(IVirtualComponent component) { |
| 298 |
if (component == null) |
| 299 |
return new IContainer[0]; |
| 300 |
|
| 301 |
List<IContainer> l = JavaLiteUtilities.getJavaOutputContainers(component); |
| 302 |
return l.toArray(new IContainer[l.size()]); |
| 303 |
} |
| 304 |
|
| 305 |
/** |
| 306 |
* Checks if the path argument is to a source container for the project. |
| 307 |
* |
| 308 |
* @param a workspace relative full path |
| 309 |
* @return is path a source container? |
| 310 |
*/ |
| 311 |
private boolean isSourceContainer(IContainer sourceContainer) { |
| 312 |
if (cachedSourceContainers == null) { |
| 313 |
cachedSourceContainers = getSourceContainers(aComponent); |
| 314 |
} |
| 315 |
return cachedSourceContainers.contains(sourceContainer); |
| 316 |
} |
| 317 |
|
| 318 |
public List<IContainer> getSourceContainers(IVirtualComponent component) { |
| 319 |
if (component == null) |
| 320 |
Collections.emptyList(); |
| 321 |
|
| 322 |
return JavaLiteUtilities.getJavaSourceContainers(component); |
| 323 |
} |
| 324 |
|
| 325 |
/* |
| 326 |
* This method returns true if the root folders of this component have any linked resources (folder or file); |
| 327 |
* Otherwise false is returned. |
| 328 |
*/ |
| 329 |
private boolean rootFoldersHaveLinkedContent() { |
| 330 |
if (this.aComponent != null) { |
| 331 |
final IContainer[] rootFolders = this.aComponent.getRootFolder().getUnderlyingFolders(); |
| 332 |
for (int i = 0; i < rootFolders.length; i++) { |
| 333 |
try { |
| 334 |
boolean hasLinkedContent = this.hasLinkedContent(rootFolders[i]); |
| 335 |
if (hasLinkedContent) { |
| 336 |
return true; |
| 337 |
} |
| 338 |
} |
| 339 |
catch (CoreException coreEx) { |
| 340 |
J2EEPlugin.logError(coreEx); |
| 341 |
} |
| 342 |
} |
| 343 |
} |
| 344 |
return false; |
| 345 |
} |
| 346 |
|
| 347 |
/* |
| 348 |
* If the resource to check is a file then this method will return true if the file is linked. If the resource to |
| 349 |
* check is a folder then this method will return true if it, any of its sub directories, or any file contained |
| 350 |
* with-in this directory of any of it's sub directories are linked. Otherwise false is returned. |
| 351 |
*/ |
| 352 |
private boolean hasLinkedContent(final IResource resourceToCheck) throws CoreException { |
| 353 |
if ((resourceToCheck != null) && resourceToCheck.isAccessible()) { |
| 354 |
// skip non-accessible files |
| 355 |
if (resourceToCheck.isLinked()) { |
| 356 |
return true; |
| 357 |
} |
| 358 |
switch (resourceToCheck.getType()) { |
| 359 |
case IResource.FOLDER: |
| 360 |
// recursively check sub directory contents |
| 361 |
final IResource[] subDirContents = ((IFolder) resourceToCheck).members(); |
| 362 |
for (int i = 0; i < subDirContents.length; i++) { |
| 363 |
if (hasLinkedContent(subDirContents[i])) { |
| 364 |
return true; |
| 365 |
} |
| 366 |
} |
| 367 |
break; |
| 368 |
case IResource.FILE: |
| 369 |
return resourceToCheck.isLinked(); |
| 370 |
default: |
| 371 |
// skip as we only care about files and folders |
| 372 |
break; |
| 373 |
} |
| 374 |
} |
| 375 |
return false; |
| 376 |
} |
| 377 |
|
| 378 |
/** |
| 379 |
* Ensure that any component resource mappings are for source folders and |
| 380 |
* that they map to the root content folder |
| 381 |
* |
| 382 |
* @param resourceMaps |
| 383 |
* @return boolean |
| 384 |
*/ |
| 385 |
private boolean isRootResourceMapping(List resourceMaps) { |
| 386 |
for (int i=0; i < resourceMaps.size(); i++) { |
| 387 |
ComponentResource resourceMap = (ComponentResource) resourceMaps.get(i); |
| 388 |
// Verify it maps to "/" for the content root |
| 389 |
if (!isRootMapping(resourceMap)) { |
| 390 |
reportStatus(ISingleRootStatus.RUNTIME_PATH_NOT_ROOT, resourceMap.getRuntimePath()); |
| 391 |
if (VALIDATE_FLAG == CANCEL) return false; |
| 392 |
} |
| 393 |
|
| 394 |
// verify it is also a src container |
| 395 |
IPath sourcePath = resourceMap.getSourcePath(); |
| 396 |
IResource sourceResource = getProject().findMember(sourcePath); |
| 397 |
if (sourceResource != null && sourceResource.exists()) { |
| 398 |
if (sourceResource instanceof IContainer && !isSourceContainer((IContainer) sourceResource)) { |
| 399 |
reportStatus(ISingleRootStatus.SOURCE_NOT_JAVA_CONTAINER, sourcePath); |
| 400 |
} |
| 401 |
} |
| 402 |
else { |
| 403 |
reportStatus(ISingleRootStatus.SOURCE_PATH_NOT_FOUND, sourcePath); |
| 404 |
} |
| 405 |
if (VALIDATE_FLAG == CANCEL) return false; |
| 406 |
} |
| 407 |
return true; |
| 408 |
} |
| 409 |
|
| 410 |
private boolean isRootMapping(ComponentResource map) { |
| 411 |
// Verify it maps to "/" for the content root |
| 412 |
if (map.getRuntimePath().equals(Path.ROOT)) |
| 413 |
return true; |
| 414 |
return false; |
| 415 |
} |
| 416 |
|
| 417 |
/** |
| 418 |
* Ensure the default web setup is correct with one resource map and any number of java |
| 419 |
* resource maps to WEB-INF/classes |
| 420 |
* |
| 421 |
* @param resourceMaps |
| 422 |
* @return boolean |
| 423 |
*/ |
| 424 |
private boolean hasDefaultWebResourceMappings(List resourceMaps) { |
| 425 |
int rootValidMaps = 0; |
| 426 |
|
| 427 |
IPath webInfClasses = new Path(J2EEConstants.WEB_INF_CLASSES).makeAbsolute(); |
| 428 |
for (int i = 0; i < resourceMaps.size(); i++) { |
| 429 |
ComponentResource resourceMap = (ComponentResource) resourceMaps.get(i); |
| 430 |
IPath sourcePath = resourceMap.getSourcePath(); |
| 431 |
IPath runtimePath = resourceMap.getRuntimePath(); |
| 432 |
IResource sourceResource = getProject().findMember(sourcePath); |
| 433 |
|
| 434 |
// Verify if the map is for the content root |
| 435 |
if (isRootMapping(resourceMap)) { |
| 436 |
rootValidMaps++; |
| 437 |
} |
| 438 |
// Verify if the map is for a java src folder and is mapped to "WEB-INF/classes" |
| 439 |
else if (runtimePath.equals(webInfClasses)) { |
| 440 |
if (sourceResource != null && sourceResource.exists()) { |
| 441 |
if (sourceResource instanceof IContainer && !isSourceContainer((IContainer) sourceResource)) { |
| 442 |
reportStatus(ISingleRootStatus.SOURCE_NOT_JAVA_CONTAINER, sourcePath); |
| 443 |
} |
| 444 |
} |
| 445 |
else { |
| 446 |
reportStatus(ISingleRootStatus.SOURCE_PATH_NOT_FOUND, sourcePath); |
| 447 |
} |
| 448 |
} |
| 449 |
else { |
| 450 |
reportStatus(ISingleRootStatus.RUNTIME_PATH_NOT_ROOT_OR_WEBINF_CLASSES, runtimePath); |
| 451 |
} |
| 452 |
if (VALIDATE_FLAG == CANCEL) return false; |
| 453 |
} |
| 454 |
// Make sure only one of the maps is the content root, and that at least one is for the java folder |
| 455 |
if (rootValidMaps != 1) { |
| 456 |
if (rootValidMaps < 1) { |
| 457 |
reportStatus(ISingleRootStatus.ONE_CONTENT_ROOT_REQUIRED); |
| 458 |
} |
| 459 |
else if (rootValidMaps > 1) { |
| 460 |
reportStatus(ISingleRootStatus.ONLY_1_CONTENT_ROOT_ALLOWED); |
| 461 |
} |
| 462 |
} |
| 463 |
return VALIDATE_FLAG == CANCEL ? false : true; |
| 464 |
} |
| 465 |
|
| 466 |
private IProject getProject() { |
| 467 |
return aComponent.getProject(); |
| 468 |
} |
| 469 |
|
| 470 |
public void reportStatus(int code) { |
| 471 |
reportStatus(code, null, null); |
| 472 |
} |
| 473 |
|
| 474 |
public void reportStatus(int code, IContainer container) { |
| 475 |
reportStatus(code, null, container); |
| 476 |
} |
| 477 |
|
| 478 |
public void reportStatus(int code, IPath path) { |
| 479 |
reportStatus(code, path, null); |
| 480 |
} |
| 481 |
|
| 482 |
public void reportStatus(int code, IPath path, IContainer container) { |
| 483 |
ISingleRootStatus status = new SingleRootStatus(code, path, container); |
| 484 |
if (status.getSeverity() == IStatus.ERROR) { |
| 485 |
if ((VALIDATE_FLAG & INCLUDE_FIRST_ERROR) != 0) { |
| 486 |
VALIDATE_FLAG = CANCEL; |
| 487 |
addStatus(status); |
| 488 |
} |
| 489 |
else if ((VALIDATE_FLAG & INCLUDE_ERRORS) != 0) { |
| 490 |
addStatus(status); |
| 491 |
} |
| 492 |
} |
| 493 |
else if (status.getSeverity() == IStatus.WARNING && (VALIDATE_FLAG & WARNINGS) != 0) { |
| 494 |
addStatus(status); |
| 495 |
} |
| 496 |
else if (status.getSeverity() == IStatus.INFO && (VALIDATE_FLAG & INFO) != 0) { |
| 497 |
addStatus(status); |
| 498 |
} |
| 499 |
} |
| 500 |
|
| 501 |
public IStatus getStatus() { |
| 502 |
if (wrapperStatus != null) { |
| 503 |
return wrapperStatus; |
| 504 |
} |
| 505 |
return Status.OK_STATUS; |
| 506 |
} |
| 507 |
|
| 508 |
private void addStatus(ISingleRootStatus status) { |
| 509 |
if (wrapperStatus == null) { |
| 510 |
wrapperStatus = new MultiStatus(J2EEPlugin.PLUGIN_ID, 0, new IStatus[] { status }, null, null); |
| 511 |
} |
| 512 |
else { |
| 513 |
wrapperStatus.add(status); |
| 514 |
} |
| 515 |
} |
| 516 |
|
| 517 |
} |