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) { |