use of org.eclipse.wst.server.core.model.IModuleResourceDelta in project sling by apache.
the class SlingLaunchpadBehaviour method publishContentModule.
private void publishContentModule(int kind, int deltaKind, IModule[] module, IProgressMonitor monitor) throws CoreException, SerializationException, IOException {
Logger logger = Activator.getDefault().getPluginLogger();
Repository repository = ServerUtil.getConnectedRepository(getServer(), monitor);
if (repository == null) {
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable to find a repository for server " + getServer()));
}
Batcher batcher = Activator.getDefault().getBatcherFactory().createBatcher();
// TODO it would be more efficient to have a module -> filter mapping
// it would be simpler to implement this in SlingContentModuleAdapter, but
// the behaviour for resources being filtered out is deletion, and that
// would be an incorrect ( or at least suprising ) behaviour at development time
List<IModuleResource> addedOrUpdatedResources = new ArrayList<>();
IModuleResource[] allResources = getResources(module);
Set<IPath> handledPaths = new HashSet<>();
switch(deltaKind) {
case ServerBehaviourDelegate.CHANGED:
for (IModuleResourceDelta resourceDelta : getPublishedResourceDelta(module)) {
StringBuilder deltaTrace = new StringBuilder();
deltaTrace.append("- processing delta kind ");
switch(resourceDelta.getKind()) {
case IModuleResourceDelta.ADDED:
deltaTrace.append("ADDED ");
break;
case IModuleResourceDelta.CHANGED:
deltaTrace.append("CHANGED ");
break;
case IModuleResourceDelta.NO_CHANGE:
deltaTrace.append("NO_CHANGE ");
break;
case IModuleResourceDelta.REMOVED:
deltaTrace.append("REMOVED ");
break;
default:
deltaTrace.append("UNKNOWN - ").append(resourceDelta.getKind());
}
deltaTrace.append("for resource ").append(resourceDelta.getModuleResource());
logger.trace(deltaTrace.toString());
switch(resourceDelta.getKind()) {
case IModuleResourceDelta.ADDED:
case IModuleResourceDelta.CHANGED:
case // TODO is this needed?
IModuleResourceDelta.NO_CHANGE:
Command<?> command = addFileCommand(repository, resourceDelta.getModuleResource());
if (command != null) {
ensureParentIsPublished(resourceDelta.getModuleResource(), repository, allResources, handledPaths, batcher);
addedOrUpdatedResources.add(resourceDelta.getModuleResource());
}
enqueue(batcher, command);
break;
case IModuleResourceDelta.REMOVED:
enqueue(batcher, removeFileCommand(repository, resourceDelta.getModuleResource()));
break;
}
}
break;
case ServerBehaviourDelegate.ADDED:
case // TODO is this correct ?
ServerBehaviourDelegate.NO_CHANGE:
for (IModuleResource resource : getResources(module)) {
Command<?> command = addFileCommand(repository, resource);
enqueue(batcher, command);
if (command != null) {
addedOrUpdatedResources.add(resource);
}
}
break;
case ServerBehaviourDelegate.REMOVED:
for (IModuleResource resource : getResources(module)) {
enqueue(batcher, removeFileCommand(repository, resource));
}
break;
}
// reorder the child nodes at the end, when all create/update/deletes have been processed
for (IModuleResource resource : addedOrUpdatedResources) {
enqueue(batcher, reorderChildNodesCommand(repository, resource));
}
execute(batcher);
// set state to published
super.publishModule(kind, deltaKind, module, monitor);
setModulePublishState(module, IServer.PUBLISH_STATE_NONE);
// setServerPublishState(IServer.PUBLISH_STATE_NONE);
}
use of org.eclipse.wst.server.core.model.IModuleResourceDelta in project liferay-ide by liferay.
the class LiferayPublishOperation method publishDir.
private void publishDir(IModule module2, List status, IProgressMonitor monitor) throws CoreException {
final IPath path = server.getModuleDeployDirectory(module2);
// Remove if requested or if previously published and are now serving without publishing
if (kind == IServer.PUBLISH_CLEAN || deltaKind == ServerBehaviourDelegate.REMOVED || server.getTomcatServer().isServeModulesWithoutPublish()) {
File f = path.toFile();
if (f.exists()) {
try {
IPath baseDir = server.getRuntimeBaseDirectory();
// $NON-NLS-1$ //$NON-NLS-2$
IPath serverXml = baseDir.append("conf").append("server.xml");
ServerInstance oldInstance = TomcatVersionHelper.getCatalinaServerInstance(serverXml, null, null);
// $NON-NLS-1$
IPath contextDir = oldInstance.getContextXmlDirectory(baseDir.append("conf"));
// $NON-NLS-1$
String contextFileName = path.lastSegment() + ".xml";
File contextFile = contextDir.append(contextFileName).toFile();
if (contextFile.exists()) {
contextFile.delete();
}
File autoDeployDir = baseDir.append(server.getLiferayTomcatServer().getAutoDeployDirectory()).toFile();
File autoDeployFile = new File(autoDeployDir, contextFileName);
if (autoDeployFile.exists()) {
autoDeployFile.delete();
}
} catch (Exception e) {
// $NON-NLS-1$
LiferayTomcatPlugin.logError("Could not delete context xml file.", e);
}
IStatus[] stat = PublishHelper.deleteDirectory(f, monitor);
addArrayToList(status, stat);
}
if (deltaKind == ServerBehaviourDelegate.REMOVED || server.getTomcatServer().isServeModulesWithoutPublish())
return;
}
IPath baseDir = server.getTomcatServer().getRuntimeBaseDirectory();
IPath autoDeployDir = new Path(server.getLiferayTomcatServer().getAutoDeployDirectory());
boolean serverStopped = server.getServer().getServerState() == IServer.STATE_STOPPED;
if (kind == IServer.PUBLISH_CLEAN || kind == IServer.PUBLISH_FULL) {
IModuleResource[] mr = server.getResources(module);
IStatus[] stat = helper.publishFull(mr, path, monitor);
addArrayToList(status, stat);
clearWebXmlDescriptors(module2.getProject(), path, monitor);
server.moveContextToAutoDeployDir(module2, path, baseDir, autoDeployDir, true, serverStopped);
return;
}
IModuleResourceDelta[] delta = server.getPublishedResourceDelta(module);
// check if we have a anti*Locking directory temp files and copy the resources out there as well
File[] antiDirs = new File[0];
try {
File tempDir = // $NON-NLS-1$
server.getLiferayTomcatServer().getTomcatRuntime().getRuntime().getLocation().append("temp").toFile();
antiDirs = tempDir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(path.lastSegment());
}
});
} catch (Exception e) {
}
int size = delta.length;
for (int i = 0; i < size; i++) {
IStatus[] stat = helper.publishDelta(delta[i], path, monitor);
for (File antiDir : antiDirs) {
if (antiDir.exists()) {
try {
helper.publishDelta(delta[i], new Path(antiDir.getCanonicalPath()), monitor);
} catch (Exception e) {
// best effort
}
}
}
addArrayToList(status, stat);
}
// check to see if we need to re-invoke the liferay plugin deployer
String[] paths = new String[] { // $NON-NLS-1$ //$NON-NLS-2$
WEB_XML_PATH, // $NON-NLS-1$ //$NON-NLS-2$
"WEB-INF/portlet.xml", // $NON-NLS-1$ //$NON-NLS-2$
"WEB-INF/liferay-portlet.xml", // $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
"WEB-INF/liferay-display.xml", // $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
"WEB-INF/liferay-look-and-feel.xml", // $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
"WEB-INF/liferay-hook.xml", // $NON-NLS-1$//$NON-NLS-2$
"WEB-INF/liferay-layout-templates.xml", // $NON-NLS-1$//$NON-NLS-2$
"WEB-INF/liferay-plugin-package.properties", "WEB-INF/liferay-plugin-package.xml", // $NON-NLS-1$ //$NON-NLS-2$
"WEB-INF/server-config.wsdd" };
for (IModuleResourceDelta del : delta) {
if (ComponentUtil.containsMember(del, paths) || isHookProjectDelta(del)) {
clearWebXmlDescriptors(module2.getProject(), path, monitor);
server.moveContextToAutoDeployDir(module2, path, baseDir, autoDeployDir, true, serverStopped);
break;
}
}
}
use of org.eclipse.wst.server.core.model.IModuleResourceDelta in project liferay-ide by liferay.
the class LiferayPublishOperation method publishArchiveModule.
private void publishArchiveModule(String jarURI, Properties p, List status, IProgressMonitor monitor) {
IPath path = server.getModuleDeployDirectory(module[0]);
boolean moving = false;
// Get URI used for previous publish, if known
String oldURI = (String) p.get(module[1].getId());
if (oldURI != null) {
// If old URI found, detect if jar is moving or changing its name
if (jarURI != null) {
moving = !oldURI.equals(jarURI);
}
}
// If we don't have a jar URI, make a guess so we have one if we need it
if (jarURI == null) {
// $NON-NLS-1$
jarURI = "WEB-INF/lib/" + module[1].getName();
}
IPath jarPath = path.append(jarURI);
// Make our best determination of the path to the old jar
IPath oldJarPath = jarPath;
if (oldURI != null) {
oldJarPath = path.append(oldURI);
}
// Establish the destination directory
path = jarPath.removeLastSegments(1);
// Remove if requested or if previously published and are now serving without publishing
if (moving || kind == IServer.PUBLISH_CLEAN || deltaKind == ServerBehaviourDelegate.REMOVED || server.getTomcatServer().isServeModulesWithoutPublish()) {
File file = oldJarPath.toFile();
if (file.exists()) {
file.delete();
}
p.remove(module[1].getId());
if (deltaKind == ServerBehaviourDelegate.REMOVED || server.getTomcatServer().isServeModulesWithoutPublish())
return;
}
if (!moving && kind != IServer.PUBLISH_CLEAN && kind != IServer.PUBLISH_FULL) {
// avoid changes if no changes to module since last publish
IModuleResourceDelta[] delta = server.getPublishedResourceDelta(module);
if (ListUtil.isEmpty(delta))
return;
}
// make directory if it doesn't exist
if (!path.toFile().exists())
path.toFile().mkdirs();
IModuleResource[] mr = server.getResources(module);
IStatus[] stat = helper.publishToPath(mr, jarPath, monitor);
addArrayToList(status, stat);
p.put(module[1].getId(), jarURI);
}
use of org.eclipse.wst.server.core.model.IModuleResourceDelta in project liferay-ide by liferay.
the class PortalPublishTask method getTasks.
@SuppressWarnings("rawtypes")
public PublishOperation[] getTasks(IServer server, int kind, List modules, List kindList) {
List<BundlePublishOperation> tasks = new ArrayList<BundlePublishOperation>();
PortalServerBehavior serverBehavior = (PortalServerBehavior) server.loadAdapter(PortalServerBehavior.class, null);
if (ListUtil.isNotEmpty(modules)) {
final int size = modules.size();
for (int i = 0; i < size; i++) {
IModule[] module = (IModule[]) modules.get(i);
Integer deltaKind = (Integer) kindList.get(i);
boolean needClean = false;
IModuleResourceDelta[] deltas = ((Server) server).getPublishedResourceDelta(module);
for (IModuleResourceDelta delta : deltas) {
final IModuleResource resource = delta.getModuleResource();
final IFile resourceFile = (IFile) resource.getAdapter(IFile.class);
if (resourceFile != null && resourceFile.getName().equals("bnd.bnd")) {
needClean = true;
break;
}
}
switch(kind) {
case IServer.PUBLISH_FULL:
case IServer.PUBLISH_INCREMENTAL:
case IServer.PUBLISH_AUTO:
final IProject project = module[0].getProject();
switch(deltaKind) {
case ServerBehaviourDelegate.ADDED:
addOperation(BundlePublishFullAddCleanBuild.class, tasks, server, module);
break;
case ServerBehaviourDelegate.CHANGED:
if (needClean) {
addOperation(BundlePublishFullAddCleanBuild.class, tasks, server, module);
} else {
addOperation(BundlePublishFullAdd.class, tasks, server, module);
}
break;
case ServerBehaviourDelegate.REMOVED:
addOperation(BundlePublishFullRemove.class, tasks, server, module);
break;
case ServerBehaviourDelegate.NO_CHANGE:
final IBundleProject bundleProject = LiferayCore.create(IBundleProject.class, project);
if (bundleProject != null) {
try {
if (isUserRedeploy(serverBehavior, module[0]) || !isDeployed(server, serverBehavior, bundleProject.getSymbolicName())) {
addOperation(BundlePublishFullAddCleanBuild.class, tasks, server, module);
}
} catch (CoreException e) {
LiferayServerCore.logError("Unable to get bsn for project " + project.getName(), e);
}
}
break;
default:
break;
}
break;
default:
break;
}
}
}
return tasks.toArray(new PublishOperation[0]);
}
use of org.eclipse.wst.server.core.model.IModuleResourceDelta in project liferay-ide by liferay.
the class RemoteServerBehavior method publishModuleDelta.
protected int publishModuleDelta(IModule[] module, IProgressMonitor monitor) throws CoreException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
IProject moduleProject = module[0].getProject();
IModuleResourceDelta[] delta = getPublishedResourceDelta(module);
if (shouldPublishModuleFull(delta)) {
return publishModuleFull(module, CHANGED, monitor);
}
final String appName = ComponentUtilities.getServerContextRoot(moduleProject);
// $NON-NLS-1$ //$NON-NLS-2$
monitor.subTask("Creating partial " + moduleProject.getName() + " update archive...");
final ILiferayProject liferayProject = LiferayCore.create(moduleProject);
final IRemoteServerPublisher publisher = liferayProject.adapt(IRemoteServerPublisher.class);
if (publisher == null) {
setModuleStatus(module, null);
throw new CoreException(LiferayServerCore.error(Msgs.publishingModuleProject));
}
final IPath warPath = publisher.publishModuleDelta(appName + ".war", delta, "liferay", true);
monitor.worked(25);
if (monitor != null && monitor.isCanceled()) {
return IServer.PUBLISH_STATE_UNKNOWN;
}
monitor.subTask(Msgs.gettingLiferayConnection);
IServerManagerConnection connection = getServerManagerConnection();
monitor.subTask(NLS.bind(Msgs.updatingModuleProject, moduleProject.getName()));
Object error = null;
try {
error = connection.updateApplication(appName, warPath.toOSString(), monitor);
} catch (APIException e) {
error = e.getMessage();
}
monitor.worked(90);
if (error != null) {
throw new CoreException(LiferayServerCore.error(error.toString()));
}
monitor.done();
return IServer.PUBLISH_STATE_NONE;
}
Aggregations