use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context in project kie-wb-common by kiegroup.
the class MoveRowsCommandTest method setup.
@Before
public void setup() {
this.context = new Context();
this.uiModel = new DMNGridData();
doReturn(ruleManager).when(handler).getRuleManager();
doReturn(0).when(uiRowNumberColumn).getIndex();
doReturn(1).when(uiNameColumn).getIndex();
doReturn(2).when(uiExpressionEditorColumn).getIndex();
addContextEntry(II1);
addContextEntry(II2);
addUiModelColumn(uiRowNumberColumn);
addUiModelColumn(uiNameColumn);
addUiModelColumn(uiExpressionEditorColumn);
addUiModelRow(0);
addUiModelRow(1);
}
use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context in project liferay-ide by liferay.
the class LiferayTomcatServerBehavior method moveContextToAutoDeployDir.
public IStatus moveContextToAutoDeployDir(IModule module, IPath deployDir, IPath baseDir, IPath autoDeployDir, boolean noPath, boolean serverStopped) {
// $NON-NLS-1$
IPath confDir = baseDir.append("conf");
// $NON-NLS-1$
IPath serverXml = confDir.append("server.xml");
try (InputStream newInputStream = Files.newInputStream(serverXml.toFile().toPath())) {
Factory factory = new Factory();
// $NON-NLS-1$
factory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
Server publishedServer = (Server) factory.loadDocument(newInputStream);
ServerInstance publishedInstance = new ServerInstance(publishedServer, null, null);
IPath contextPath = null;
if (autoDeployDir.isAbsolute()) {
contextPath = autoDeployDir;
} else {
contextPath = baseDir.append(autoDeployDir);
}
File contextDir = contextPath.toFile();
if (!contextDir.exists()) {
contextDir.mkdirs();
}
Context context = publishedInstance.createContext(-1);
// $NON-NLS-1$
context.setReloadable("true");
final String moduleName = module.getName();
final String requiredSuffix = ProjectUtil.getRequiredSuffix(module.getProject());
String contextName = moduleName;
if (!moduleName.endsWith(requiredSuffix)) {
contextName = moduleName + requiredSuffix;
}
// $NON-NLS-1$
context.setSource("org.eclipse.jst.jee.server:" + contextName);
if (// $NON-NLS-1$
Boolean.valueOf(context.getAttributeValue("antiResourceLocking")).booleanValue()) {
// $NON-NLS-1$ //$NON-NLS-2$
context.setAttributeValue("antiResourceLocking", "false");
}
// $NON-NLS-1$
File contextFile = new File(contextDir, contextName + ".xml");
if (!LiferayTomcatUtil.isExtProjectContext(context)) {
// If requested, remove path attribute
if (noPath) {
// $NON-NLS-1$
context.removeAttribute("path");
}
// need to fix the doc base to contain entire path to help autoDeployer for Liferay
context.setDocBase(deployDir.toOSString());
// context.setAttributeValue("antiJARLocking", "true");
// check to see if we need to move from conf folder
// IPath existingContextPath = confDir.append("Catalina/localhost").append(contextFile.getName());
// if (existingContextPath.toFile().exists()) {
// existingContextPath.toFile().delete();
// }
DocumentBuilder builder = XMLUtil.getDocumentBuilder();
Document contextDoc = builder.newDocument();
contextDoc.appendChild(contextDoc.importNode(context.getElementNode(), true));
XMLUtil.save(contextFile.getAbsolutePath(), contextDoc);
}
} catch (Exception e) {
// confDir.toOSString() + ": " + e.getMessage());
return new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorPublishConfiguration, new String[] { e.getLocalizedMessage() }), e);
} finally {
// monitor.done();
}
return Status.OK_STATUS;
}
use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context in project liferay-ide by liferay.
the class LiferayTomcatUtil method loadContextFile.
public static Context loadContextFile(File contextFile) {
Context context = null;
if (contextFile != null && contextFile.exists()) {
try (InputStream fis = Files.newInputStream(contextFile.toPath())) {
Factory factory = new Factory();
// $NON-NLS-1$
factory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
context = (Context) factory.loadDocument(fis);
if (context != null) {
String path = context.getPath();
// If path attribute is not set, derive from file name
if (path == null) {
String fileName = contextFile.getName();
// $NON-NLS-1$
path = fileName.substring(0, fileName.length() - ".xml".length());
if (// $NON-NLS-1$
"ROOT".equals(path))
path = StringPool.EMPTY;
context.setPath(StringPool.FORWARD_SLASH + path);
}
}
} catch (Exception e) {
// may be a spurious xml file in the host dir?
}
}
return context;
}
use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context 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.jst.server.tomcat.core.internal.xml.server40.Context in project webtools.servertools by eclipse.
the class Tomcat85Configuration method modifyWebModule.
/**
* Change a web module.
* @param index int
* @param docBase java.lang.String
* @param path java.lang.String
* @param reloadable boolean
*/
public void modifyWebModule(int index, String docBase, String path, boolean reloadable) {
try {
Context context = serverInstance.getContext(index);
if (context != null) {
context.setPath(path);
context.setDocBase(docBase);
context.setReloadable(reloadable ? "true" : "false");
isServerDirty = true;
WebModule module = new WebModule(path, docBase, null, reloadable);
firePropertyChangeEvent(MODIFY_WEB_MODULE_PROPERTY, new Integer(index), module);
}
} catch (Exception e) {
Trace.trace(Trace.SEVERE, "Error modifying web module " + index, e);
}
}
Aggregations