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 |