View | Details | Raw Unified | Return to bug 319288 | Differences between
and this patch

Collapse All | Expand All

(-)servercore/org/eclipse/wst/server/core/internal/Publisher.java (-12 / +101 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
2
 * Copyright (c) 2008, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-21 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.wst.server.core.internal;
11
package org.eclipse.wst.server.core.internal;
12
12
13
import org.eclipse.core.runtime.CoreException;
13
import java.util.Iterator;
14
import org.eclipse.core.runtime.IAdaptable;
14
import java.util.List;
15
import org.eclipse.core.runtime.IConfigurationElement;
15
16
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.*;
17
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.jobs.ISchedulingRule;
18
import org.eclipse.core.runtime.Status;
18
import org.eclipse.core.runtime.jobs.Job;
19
import org.eclipse.wst.server.core.IModule;
20
import org.eclipse.wst.server.core.IServerWorkingCopy;
19
import org.eclipse.wst.server.core.TaskModel;
21
import org.eclipse.wst.server.core.TaskModel;
20
import org.eclipse.wst.server.core.model.PublisherDelegate;
22
import org.eclipse.wst.server.core.model.PublisherDelegate;
21
/**
23
/**
Lines 24-30 Link Here
24
public class Publisher {
26
public class Publisher {
25
	private IConfigurationElement element;
27
	private IConfigurationElement element;
26
	private PublisherDelegate delegate;
28
	private PublisherDelegate delegate;
27
29
	
28
	/**
30
	/**
29
	 * Publisher constructor comment.
31
	 * Publisher constructor comment.
30
	 * 
32
	 * 
Lines 78-91 Link Here
78
		return delegate;
80
		return delegate;
79
	}
81
	}
80
82
83
	/**
84
	 * Should the original {@link ISchedulingRule} be changed with the new {@link ISchedulingRule}?
85
	 * 
86
	 * @param originalRule
87
	 *            The original {@link ISchedulingRule}
88
	 * @param newRule
89
	 *            The new {@link ISchedulingRule}
90
	 * @return <code>true</code> if the new scheduling rule should be applied; Otherwise <code>false</code>.
91
	 */
92
	private boolean changeSchedulingRule(ISchedulingRule originalRule, ISchedulingRule newRule) {
93
94
		boolean changeRule = false;
95
		if ((originalRule == null) && (newRule == null)) {
96
			// no need to change rules if they're both null
97
			changeRule = false;
98
		}
99
		else if((originalRule == null) && (newRule != null)) {
100
			// there is currently no rule and a new not-null rule wants to be added 
101
			changeRule = true;
102
		}
103
		else if((originalRule != null) && (newRule == null)) {
104
			// there is currently a rule and a new null rule wants to be applied
105
			changeRule = true;
106
		}
107
		else if((originalRule != null) && (newRule != null)) {
108
			// there is currently a rule and a new not-null rule wants to be applied.
109
			changeRule = !originalRule.equals(newRule);
110
		}
111
		return changeRule;
112
	}
113
114
	/**
115
	 * rebuild the cache for the modules involved with this task.
116
	 */
117
	private void rebuildModuleCache() {
118
119
		// reset the publishing cache for the modules that are part of this task.
120
		Server server = (Server) getDelegate().getTaskModel().getObject(TaskModel.TASK_SERVER);
121
		if (server != null) {
122
			// make sure the right server is used.
123
			if(server.isWorkingCopy()) {
124
				IServerWorkingCopy workingCopy = (IServerWorkingCopy)server;
125
				server = (Server) workingCopy.getOriginal();
126
			}
127
			final List moduleList = (List)getDelegate().getTaskModel().getObject(TaskModel.TASK_MODULES);
128
			if (moduleList != null) {
129
				final Iterator moduleIterator = moduleList.iterator();
130
				while (moduleIterator.hasNext()) {
131
					IModule[] module = (IModule[]) moduleIterator.next();
132
					if (module != null) {
133
						Trace.trace(Trace.FINEST, "rebuilding cache for module: " + module[module.length - 1]);
134
						server.getServerPublishInfo().rebuildCache(module);
135
					}
136
				}
137
			}
138
		}
139
	}
140
	
81
	public IStatus execute(int kind, IProgressMonitor monitor, IAdaptable info) throws CoreException {
141
	public IStatus execute(int kind, IProgressMonitor monitor, IAdaptable info) throws CoreException {
142
143
		Trace.trace(Trace.FINEST, "Task.init " + this);
144
		ISchedulingRule delegatePublisherRule = null;
145
		final ISchedulingRule originalPublisherRule = Job.getJobManager().currentRule();
146
		IStatus resultStatus = null;
147
		boolean changeSchedulingRules = false;
82
		try {
148
		try {
83
			Trace.trace(Trace.FINEST, "Task.init " + this);
149
			delegatePublisherRule = getDelegate().getRule();
84
			return getDelegate().execute(kind, monitor, info);
150
			changeSchedulingRules = this.changeSchedulingRule(originalPublisherRule, delegatePublisherRule);
85
		} catch (Exception e) {
151
			Trace.trace(Trace.FINEST, "Change the scheduling rule to execute delegate: " + changeSchedulingRules);
152
			if (changeSchedulingRules) {
153
				Trace.trace(Trace.FINEST, "Ending the current scheduling rule " + originalPublisherRule);
154
				Job.getJobManager().endRule(originalPublisherRule);
155
				Trace.trace(Trace.FINEST, "Beginning the new scheduling rule: " + delegatePublisherRule);
156
				Job.getJobManager().beginRule(delegatePublisherRule, monitor);
157
			}
158
			resultStatus = getDelegate().execute(kind, monitor, info);
159
			boolean delegateModifiedModules = getDelegate().isModifyModules();
160
			Trace.trace(Trace.FINEST, "The delegate stated that it modified modules: " + delegateModifiedModules);
161
			if(delegateModifiedModules) {
162
				this.rebuildModuleCache();
163
			}
164
		}
165
		catch (Exception e) {
86
			Trace.trace(Trace.SEVERE, "Error calling delegate " + toString(), e);
166
			Trace.trace(Trace.SEVERE, "Error calling delegate " + toString(), e);
87
			return new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, "Error in delegate", e); // TODO
167
			resultStatus = new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, "Error in delegate", e); // TODO
168
		}
169
		finally {
170
			if (changeSchedulingRules) {
171
				Trace.trace(Trace.FINEST, "Reseting the scheduling rules... ending: " + delegatePublisherRule);
172
				Job.getJobManager().endRule(delegatePublisherRule);
173
				Trace.trace(Trace.FINEST, "Reseting the scheduling rules... beginning: " + originalPublisherRule);
174
				Job.getJobManager().beginRule(originalPublisherRule, monitor);
175
			}
88
		}
176
		}
177
		return resultStatus;
89
	}
178
	}
90
179
91
	public void setTaskModel(TaskModel taskModel) {
180
	public void setTaskModel(TaskModel taskModel) {
(-)servercore/org/eclipse/wst/server/core/internal/ServerPublishInfo.java (+30 lines)
Lines 540-543 Link Here
540
			}
540
			}
541
		}
541
		}
542
	}
542
	}
543
544
	/**
545
	 * Clears all caches of current module resources and deltas.
546
	 */
547
	public void clearCache(IModule[] module) {
548
		synchronized (modulePublishInfo) {
549
			final String publishInfoKey = this.getKey(module);
550
			ModulePublishInfo mpi = modulePublishInfo.get(publishInfoKey);
551
			if (mpi != null) {
552
				mpi.clearCache();
553
			}
554
		}
555
	}
556
557
	/**
558
	 * Recreates the cache for the specified {@link IModule}.
559
	 * 
560
	 * @param module The {@link IModule}
561
	 */
562
	public void rebuildCache(IModule[] module) {
563
564
		synchronized (modulePublishInfo) {
565
			final String publishInfoKey = this.getKey(module);
566
			ModulePublishInfo mpi = modulePublishInfo.get(publishInfoKey);
567
			if(mpi != null) {
568
				mpi.startCaching(); // clear out the resource list
569
				mpi.fill(module); // rebuild the resource list
570
			}
571
		}
572
	}
543
}
573
}
(-)servercore/org/eclipse/wst/server/core/model/PublisherDelegate.java (-5 / +21 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
2
 * Copyright (c) 2008, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-19 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.wst.server.core.model;
11
package org.eclipse.wst.server.core.model;
12
12
13
import org.eclipse.core.runtime.CoreException;
13
import org.eclipse.core.runtime.*;
14
import org.eclipse.core.runtime.IAdaptable;
14
import org.eclipse.core.runtime.jobs.ISchedulingRule;
15
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.core.runtime.jobs.Job;
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.wst.server.core.TaskModel;
16
import org.eclipse.wst.server.core.TaskModel;
18
/**
17
/**
19
 * An operation that will be executed during publishing. 
18
 * An operation that will be executed during publishing. 
Lines 91-94 Link Here
91
	 * @throws CoreException if there was an error while executing the task
90
	 * @throws CoreException if there was an error while executing the task
92
	 */
91
	 */
93
	public abstract IStatus execute(int kind, IProgressMonitor monitor, IAdaptable info) throws CoreException;
92
	public abstract IStatus execute(int kind, IProgressMonitor monitor, IAdaptable info) throws CoreException;
93
	
94
	/**
95
	 * TODO
96
	 * @return
97
	 */
98
	public ISchedulingRule getRule() {
99
100
		return Job.getJobManager().currentRule();
101
	}
102
103
	/**
104
	 * 
105
	 */
106
	public boolean isModifyModules() {
107
108
		return false;
109
	}
94
}
110
}
(-)servercore/org/eclipse/wst/server/core/model/ServerBehaviourDelegate.java (-19 / +31 lines)
Lines 863-868 Link Here
863
			multi.addAll(tempMulti);
863
			multi.addAll(tempMulti);
864
	}*/
864
	}*/
865
865
866
	private List<Integer> computeDelta(final List<IModule[]> moduleList) {
867
868
		final List<Integer> deltaKindList = new ArrayList<Integer>();
869
		final Iterator<IModule[]> iterator = moduleList.iterator();
870
		while (iterator.hasNext()) {
871
			IModule[] module = iterator.next();
872
			if (hasBeenPublished(module)) {
873
				IModule m = module[module.length - 1];
874
				if ((m.getProject() != null && !m.getProject().isAccessible())
875
						|| getPublishedResourceDelta(module).length == 0) {
876
					deltaKindList.add(new Integer(ServerBehaviourDelegate.NO_CHANGE));
877
				}
878
				else {
879
					deltaKindList.add(new Integer(ServerBehaviourDelegate.CHANGED));
880
				}
881
			}
882
			else {
883
				deltaKindList.add(new Integer(ServerBehaviourDelegate.ADDED));
884
			}
885
		}
886
		this.addRemovedModules(moduleList, null);
887
		while (deltaKindList.size() < moduleList.size()) {
888
			deltaKindList.add(new Integer(ServerBehaviourDelegate.REMOVED));
889
		}
890
		return deltaKindList;
891
	}
892
	
866
	/**
893
	/**
867
	 * Publish to the server.
894
	 * Publish to the server.
868
	 * 
895
	 * 
Lines 878-902 Link Here
878
			return new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, Messages.errorPublishNoRuntime, null);
905
			return new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, Messages.errorPublishNoRuntime, null);
879
		
906
		
880
		final List<IModule[]> moduleList = getAllModules();
907
		final List<IModule[]> moduleList = getAllModules();
881
		final List<Integer> deltaKindList = new ArrayList<Integer>();
908
		List<Integer> deltaKindList = this.computeDelta(moduleList);
882
		
883
		Iterator iterator = moduleList.iterator();
884
		while (iterator.hasNext()) {
885
			IModule[] module = (IModule[]) iterator.next();
886
			if (hasBeenPublished(module)) {
887
				IModule m = module[module.length - 1];
888
				if ((m.getProject() != null && !m.getProject().isAccessible())
889
						|| getPublishedResourceDelta(module).length == 0)
890
					deltaKindList.add(new Integer(ServerBehaviourDelegate.NO_CHANGE));
891
				else
892
					deltaKindList.add(new Integer(ServerBehaviourDelegate.CHANGED));
893
			} else
894
				deltaKindList.add(new Integer(ServerBehaviourDelegate.ADDED));
895
		}
896
		
897
		addRemovedModules(moduleList, null);
898
		while (deltaKindList.size() < moduleList.size())
899
			deltaKindList.add(new Integer(ServerBehaviourDelegate.REMOVED));
900
		
909
		
901
		PublishOperation[] tasks = getTasks(kind, moduleList, deltaKindList);
910
		PublishOperation[] tasks = getTasks(kind, moduleList, deltaKindList);
902
		int size = 2000 + 3500 * moduleList.size() + 500 * tasks.length;
911
		int size = 2000 + 3500 * moduleList.size() + 500 * tasks.length;
Lines 926-931 Link Here
926
			if (taskStatus != null && !taskStatus.isOK())
935
			if (taskStatus != null && !taskStatus.isOK())
927
				tempMulti.addAll(taskStatus);
936
				tempMulti.addAll(taskStatus);
928
			
937
			
938
			// re-create the delta list as the publishers may have changed it.
939
			deltaKindList = this.computeDelta(moduleList);
940
			
929
			if (monitor.isCanceled())
941
			if (monitor.isCanceled())
930
				return Status.CANCEL_STATUS;
942
				return Status.CANCEL_STATUS;
931
			
943
			

Return to bug 319288