Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 251d93aca80756d41348396c074f3dc0a79b74d8 (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
/***************************************************************************************************
 * Copyright (c) 2003, 2004 IBM Corporation and others. 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: IBM Corporation - initial API and implementation
 **************************************************************************************************/
package org.eclipse.jst.j2ee.internal.wizard;


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.eclipse.core.resources.IProject;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jst.j2ee.internal.earcreation.EAREditModel;
import org.eclipse.jst.j2ee.internal.earcreation.EARNatureRuntime;
import org.eclipse.jst.j2ee.internal.validation.UIEarValidator;
import org.eclipse.wst.common.frameworks.internal.ui.RunnableWithProgressWrapper;
import org.eclipse.wst.validation.internal.operations.OneValidatorOperation;
import org.eclipse.wst.validation.internal.operations.ValidatorManager;

public class EARValidationHelper {

	/**
	 * Constructor for EARValidationHelper.
	 */
	private EARValidationHelper() {
		super();
	}

	/**
	 * Return a list of runnable validation operations for all EAR projects which have auto validate
	 * enabled, and are impacted by the list of projects; If the ear project itself is in the list,
	 * then it is skipped.
	 */
	public static IRunnableWithProgress[] getEARValidationOperations(List modifiedProjects) {
		List earProjects = EARNatureRuntime.getAllEARProjectsInWorkbench();
		List result = new ArrayList(earProjects.size());
		for (int i = 0; i < earProjects.size(); i++) {
			IProject earProj = (IProject) earProjects.get(i);
			if (willEARProjectNeedValidation(earProj, modifiedProjects)) {
				result.add(createValidationRunnable(earProj));
			}
		}
		return (IRunnableWithProgress[]) result.toArray(new IRunnableWithProgress[result.size()]);
	}

	/**
	 * Return a list of runnable validation operations for all EAR projects which have auto validate
	 * enabled, and are impacted by the j2ee project
	 */
	public static IRunnableWithProgress[] getEARValidationOperations(IProject modifiedJ2EEProject) {
		return getEARValidationOperations(Collections.singletonList(modifiedJ2EEProject));
	}

	public static boolean isEARValidationAutoEnabled(IProject earProj) {
		return ValidatorManager.getManager().isAutoValidate(earProj) && ValidatorManager.getManager().isEnabled(earProj, UIEarValidator.VALIDATOR_ID);
	}

	private static boolean willEARProjectNeedValidation(IProject earProj, List modifiedProjects) {
		if (modifiedProjects.contains(earProj) || !isEARValidationAutoEnabled(earProj))
			return false;
		Object accessorKey = new Object();
		EARNatureRuntime runtime = EARNatureRuntime.getRuntime(earProj);
		EAREditModel editModel = runtime.getEarEditModelForRead(accessorKey);
		try {
			for (int i = 0; i < modifiedProjects.size(); i++) {
				if (editModel.hasMappingToProject((IProject) modifiedProjects.get(i)))
					return true;
			}
		} finally {
			if (editModel != null)
				editModel.releaseAccess(accessorKey);
		}
		return false;
	}

	/**
	 * Creates a new IRunnableWithProgress which runs a one validator operation on the EAR project
	 */
	public static IRunnableWithProgress createValidationRunnable(IProject earProj) {
		OneValidatorOperation op = new OneValidatorOperation(earProj, UIEarValidator.VALIDATOR_ID, true, false);

		return new RunnableWithProgressWrapper(op);
	}

}

Back to the top