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 (-11 / +111 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-29 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;
29
	private boolean modifyModules = false;
27
30
28
	/**
31
	/**
29
	 * Publisher constructor comment.
32
	 * Publisher constructor comment.
Lines 78-91 Link Here
78
		return delegate;
81
		return delegate;
79
	}
82
	}
80
83
84
	/**
85
	 * Should the original {@link ISchedulingRule} be changed with the new {@link ISchedulingRule}?
86
	 * 
87
	 * @param originalRule
88
	 *            The original {@link ISchedulingRule}
89
	 * @param newRule
90
	 *            The new {@link ISchedulingRule}
91
	 * @return <code>true</code> if the new scheduling rule should be applied; Otherwise <code>false</code>.
92
	 */
93
	private boolean changeSchedulingRule(ISchedulingRule originalRule, ISchedulingRule newRule) {
94
95
		boolean changeRule = false;
96
		if ((originalRule == null) && (newRule == null)) {
97
			// no need to change rules if they're both null
98
			changeRule = false;
99
		}
100
		else if((originalRule == null) && (newRule != null)) {
101
			// there is currently no rule and a new not-null rule wants to be added 
102
			changeRule = true;
103
		}
104
		else if((originalRule != null) && (newRule == null)) {
105
			// there is currently a rule and a new null rule wants to be applied
106
			changeRule = true;
107
		}
108
		else if((originalRule != null) && (newRule != null)) {
109
			// there is currently a rule and a new not-null rule wants to be applied.
110
			changeRule = !originalRule.equals(newRule);
111
		}
112
		return changeRule;
113
	}
114
115
	/**
116
	 * rebuild the cache for the modules involved with this task.
117
	 */
118
	private void rebuildModuleCache() {
119
120
		// reset the publishing cache for the modules that are part of this task.
121
		Server server = (Server) getDelegate().getTaskModel().getObject(TaskModel.TASK_SERVER);
122
		if (server != null) {
123
			// make sure the right server is used.
124
			if(server.isWorkingCopy()) {
125
				IServerWorkingCopy workingCopy = (IServerWorkingCopy)server;
126
				server = (Server) workingCopy.getOriginal();
127
			}
128
			final List moduleList = (List)getDelegate().getTaskModel().getObject(TaskModel.TASK_MODULES);
129
			if (moduleList != null) {
130
				final Iterator moduleIterator = moduleList.iterator();
131
				while (moduleIterator.hasNext()) {
132
					IModule[] module = (IModule[]) moduleIterator.next();
133
					if (module != null) {
134
						Trace.trace(Trace.FINEST, "rebuilding cache for module: " + module[module.length - 1]);
135
						server.getServerPublishInfo().rebuildCache(module);
136
					}
137
				}
138
			}
139
		}
140
	}
141
	
81
	public IStatus execute(int kind, IProgressMonitor monitor, IAdaptable info) throws CoreException {
142
	public IStatus execute(int kind, IProgressMonitor monitor, IAdaptable info) throws CoreException {
143
144
		Trace.trace(Trace.FINEST, "Task.init " + this);
145
		ISchedulingRule delegatePublisherRule = null;
146
		final ISchedulingRule originalPublisherRule = Job.getJobManager().currentRule();
147
		IStatus resultStatus = null;
148
		boolean changeSchedulingRules = false;
82
		try {
149
		try {
83
			Trace.trace(Trace.FINEST, "Task.init " + this);
150
			delegatePublisherRule = getDelegate().getRule();
84
			return getDelegate().execute(kind, monitor, info);
151
			changeSchedulingRules = this.changeSchedulingRule(originalPublisherRule, delegatePublisherRule);
85
		} catch (Exception e) {
152
			Trace.trace(Trace.FINEST, "Change the scheduling rule to execute delegate: " + changeSchedulingRules);
153
			if (changeSchedulingRules) {
154
				Trace.trace(Trace.FINEST, "Ending the current scheduling rule " + originalPublisherRule);
155
				Job.getJobManager().endRule(originalPublisherRule);
156
				Trace.trace(Trace.FINEST, "Beginning the new scheduling rule: " + delegatePublisherRule);
157
				Job.getJobManager().beginRule(delegatePublisherRule, monitor);
158
			}
159
			resultStatus = getDelegate().execute(kind, monitor, info);
160
			this.modifyModules = getDelegate().isModifyModules();
161
			Trace.trace(Trace.FINEST, "The publisher delegate stated that it modified modules: " + this.modifyModules);
162
			if(this.modifyModules) {
163
				this.rebuildModuleCache();
164
			}
165
		}
166
		catch (Exception e) {
86
			Trace.trace(Trace.SEVERE, "Error calling delegate " + toString(), e);
167
			Trace.trace(Trace.SEVERE, "Error calling delegate " + toString(), e);
87
			return new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, "Error in delegate", e); // TODO
168
			resultStatus = new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, "Error in delegate", e); // TODO
88
		}
169
		}
170
		finally {
171
			if (changeSchedulingRules) {
172
				Trace.trace(Trace.FINEST, "Reseting the scheduling rules... ending: " + delegatePublisherRule);
173
				Job.getJobManager().endRule(delegatePublisherRule);
174
				Trace.trace(Trace.FINEST, "Reseting the scheduling rules... beginning: " + originalPublisherRule);
175
				Job.getJobManager().beginRule(originalPublisherRule, monitor);
176
			}
177
		}
178
		return resultStatus;
89
	}
179
	}
90
180
91
	public void setTaskModel(TaskModel taskModel) {
181
	public void setTaskModel(TaskModel taskModel) {
Lines 97-102 Link Here
97
	}
187
	}
98
188
99
	/**
189
	/**
190
	 * Accessor to find out if this publisher modified any modules that are published on the server.
191
	 * 
192
	 * @return <code>true</code> if the publisher modified the contents of any modules that are published on the server.
193
	 */
194
	public boolean isModifyModules() {
195
196
		return this.modifyModules;
197
	}
198
	
199
	/**
100
	 * Return a string representation of this object.
200
	 * Return a string representation of this object.
101
	 * 
201
	 * 
102
	 * @return a string
202
	 * @return a string
(-)servercore/org/eclipse/wst/server/core/internal/ServerPublishInfo.java (+17 lines)
Lines 540-543 Link Here
540
			}
540
			}
541
		}
541
		}
542
	}
542
	}
543
544
	/**
545
	 * Recreates the cache for the specified {@link IModule}.
546
	 * 
547
	 * @param module The {@link IModule}
548
	 */
549
	public void rebuildCache(IModule[] module) {
550
551
		synchronized (modulePublishInfo) {
552
			final String publishInfoKey = this.getKey(module);
553
			ModulePublishInfo mpi = modulePublishInfo.get(publishInfoKey);
554
			if(mpi != null) {
555
				mpi.startCaching(); // clear out the resource list
556
				mpi.fill(module); // rebuild the resource list
557
			}
558
		}
559
	}
543
}
560
}
(-)servercore/org/eclipse/wst/server/core/model/PublisherDelegate.java (-5 / +28 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
	 * Returns the scheduling rule that is required for executing the publisher delegate. The default is the current
96
	 * rule defined on the publishing job.
97
	 * 
98
	 * @return A {@link ISchedulingRule} for the job that defines how this publisher can execute in the publishing job.
99
	 *         A <code>null</code> value may be returned if the publishing job does not have any rule defined.
100
	 * @since 3.2
101
	 */
102
	public ISchedulingRule getRule() {
103
104
		return Job.getJobManager().currentRule();
105
	}
106
107
	/**
108
	 * Accessor to find out if this publisher delegate modified any modules that are published on the server.
109
	 * 
110
	 * @return <code>true</code> if the publisher modified the contents of any modules that are published on the server.
111
	 * @since 3.2
112
	 */
113
	public boolean isModifyModules() {
114
115
		return false;
116
	}
94
}
117
}
(-)servercore/org/eclipse/wst/server/core/model/ServerBehaviourDelegate.java (-30 / +52 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 1144-1161 Link Here
1144
	}
1153
	}
1145
1154
1146
	/**
1155
	/**
1147
	 * Execute publishers.
1156
	 * Execute publishers. If a publisher modified the contents of the module (which is determined by the
1157
	 * {@link PublisherDelegate}) then the delta list is rebuild.
1148
	 * 
1158
	 * 
1149
	 * @param kind the publish kind
1159
	 * @param kind
1150
	 * @param modules the list of modules
1160
	 *            the publish kind
1151
	 * @param deltaKinds the list of delta kind that maps to the list of modules
1161
	 * @param modules
1152
	 * @param monitor a progress monitor, or <code>null</code> if progress
1162
	 *            the list of modules. The contents of this {@link List} may change if the publisher modifies code.
1153
	 *    reporting and cancellation are not desired
1163
	 * @param deltaKinds
1154
	 * @param info the IAdaptable (or <code>null</code>) provided by the
1164
	 *            the list of delta kind that maps to the list of modules. The contents of this {@link List} may change
1155
	 *    caller in order to supply UI information for prompting the
1165
	 *            if the publisher modifies code.
1156
	 *    user if necessary. When this parameter is not <code>null</code>,
1166
	 * @param monitor
1157
	 *    it should minimally contain an adapter for the
1167
	 *            a progress monitor, or <code>null</code> if progress reporting and cancellation are not desired
1158
	 *    org.eclipse.swt.widgets.Shell.class
1168
	 * @param info
1169
	 *            the IAdaptable (or <code>null</code>) provided by the caller in order to supply UI information for
1170
	 *            prompting the user if necessary. When this parameter is not <code>null</code>, it should minimally
1171
	 *            contain an adapter for the org.eclipse.swt.widgets.Shell.class
1159
	 * @throws CoreException
1172
	 * @throws CoreException
1160
	 * @since 1.1
1173
	 * @since 1.1
1161
	 */
1174
	 */
Lines 1176-1187 Link Here
1176
			taskModel.putObject(TaskModel.TASK_DELTA_KINDS, deltaKinds);
1189
			taskModel.putObject(TaskModel.TASK_DELTA_KINDS, deltaKinds);
1177
		}
1190
		}
1178
		
1191
		
1192
		boolean publisherModifiedCode = false;
1179
		for (int i = 0; i < size; i++) {
1193
		for (int i = 0; i < size; i++) {
1180
			Publisher pub = publishers[i];
1194
			Publisher pub = publishers[i];
1181
			monitor.subTask(NLS.bind(Messages.taskPerforming, pub.getName()));
1195
			monitor.subTask(NLS.bind(Messages.taskPerforming, pub.getName()));
1182
			try {
1196
			try {
1183
				pub.setTaskModel(taskModel);
1197
				pub.setTaskModel(taskModel);
1184
				IStatus pubStatus = pub.execute(kind, ProgressUtil.getSubMonitorFor(monitor, 500), info);
1198
				IStatus pubStatus = pub.execute(kind, ProgressUtil.getSubMonitorFor(monitor, 500), info);
1199
				if(!publisherModifiedCode) {
1200
					// If a publisher has modified modules then there is no reason to keep checking other publishers.
1201
					publisherModifiedCode = pub.isModifyModules();
1202
				}
1185
				multi.add(pubStatus);
1203
				multi.add(pubStatus);
1186
			} catch (CoreException ce) {
1204
			} catch (CoreException ce) {
1187
				Trace.trace(Trace.SEVERE, "Publisher failed", ce);
1205
				Trace.trace(Trace.SEVERE, "Publisher failed", ce);
Lines 1192-1197 Link Here
1192
			if (monitor.isCanceled())
1210
			if (monitor.isCanceled())
1193
				return multi;
1211
				return multi;
1194
		}
1212
		}
1213
		if (publisherModifiedCode) {
1214
			// re-create the delta list as at least one publisher has changed the contents of the published modules.
1215
			deltaKinds = this.computeDelta(modules);
1216
		}
1195
		return multi;
1217
		return multi;
1196
	}
1218
	}
1197
1219

Return to bug 319288