Author: gawor
Date: Thu Jul 12 20:33:57 2012
New Revision: 1360915
URL: http://svn.apache.org/viewvc?rev=1360915&view=rev
Log:
GERONIMODEVTOOLS-796: Update static files without bundle restart - mostly working but still
needs some more work
Modified:
geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviourDelegate.java
geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/IGeronimoServerBehavior.java
Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviourDelegate.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviourDelegate.java?rev=1360915&r1=1360914&r2=1360915&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviourDelegate.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviourDelegate.java
Thu Jul 12 20:33:57 2012
@@ -57,7 +57,6 @@ import org.apache.geronimo.kernel.reposi
import org.apache.geronimo.st.core.GeronimoJMXConnectorFactory;
import org.apache.geronimo.st.core.GeronimoJMXConnectorFactory.JMXConnectorInfo;
import org.apache.geronimo.st.v30.core.commands.DeploymentCommandFactory;
-import org.apache.geronimo.st.v30.core.commands.TargetModuleIdNotFoundException;
import org.apache.geronimo.st.v30.core.internal.DependencyHelper;
import org.apache.geronimo.st.v30.core.internal.Messages;
import org.apache.geronimo.st.v30.core.internal.ServerDelegateHelper;
@@ -66,8 +65,8 @@ import org.apache.geronimo.st.v30.core.o
import org.apache.geronimo.st.v30.core.operations.SharedLibEntryCreationOperation;
import org.apache.geronimo.st.v30.core.operations.SharedLibEntryDataModelProvider;
import org.apache.geronimo.st.v30.core.osgi.AriesHelper;
+import org.apache.geronimo.st.v30.core.osgi.AriesHelper.BundleInfo;
import org.apache.geronimo.st.v30.core.osgi.OSGiModuleHandler;
-import org.apache.geronimo.st.v30.core.osgi.OsgiConstants;
import org.apache.geronimo.system.jmx.KernelDelegate;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
@@ -470,7 +469,7 @@ public class GeronimoServerBehaviourDele
IModule bundleModule = moduleDelta.module[1];
if (moduleDelta.delta == CHANGED && (GeronimoUtils.isWebModule(bundleModule)
|| GeronimoUtils.isBundleModule(bundleModule))) {
// try to do replacement
- status = tryFileReplace(rootModule[0], moduleDelta.module);
+ status = tryFileReplace(moduleDelta.module);
if (status == null) {
// replacement was not possible
replacementPossible = false;
@@ -584,22 +583,11 @@ public class GeronimoServerBehaviourDele
MultiStatus multiStatus = new MultiStatus(Activator.PLUGIN_ID, 0, "", null);
try {
- ExtendedDeploymentManager dm = (ExtendedDeploymentManager) DeploymentCommandFactory.getDeploymentManager(getServer());
- long[] bundleIds = dm.getEBAContentBundleIds(ebaName);
-
- Map<String, Long> bundleMap = new HashMap<String, Long>();
- for (long bundleId : bundleIds) {
- String symbolicName = dm.getEBAContentBundleSymbolicName(ebaName, bundleId);
- if (symbolicName != null) {
- bundleMap.put(symbolicName, bundleId);
- }
- }
-
for (IModule[] bundleModule : bundleModules) {
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
- IStatus status = refreshBundle(ebaModule, bundleModule[1], ebaName, bundleMap);
+ IStatus status = refreshBundle(ebaModule, bundleModule[1], ebaName);
setStatus(bundleModule, status, multiStatus);
}
} catch (Exception e) {
@@ -618,18 +606,20 @@ public class GeronimoServerBehaviourDele
return status;
}
- private IStatus refreshBundle(IModule ebaModule, IModule bundleModule, AbstractName ebaName,
Map<String, Long> bundleMap) {
- Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.refreshBundle",
ebaModule, bundleModule, ebaName, bundleMap);
+ private IStatus refreshBundle(IModule ebaModule, IModule bundleModule, AbstractName ebaName)
{
+ Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.refreshBundle",
ebaModule, bundleModule, ebaName);
+
try {
- String symbolicName = AriesHelper.getSymbolicName(bundleModule);
- Long bundleId = bundleMap.get(symbolicName);
+ ExtendedDeploymentManager dm = (ExtendedDeploymentManager) DeploymentCommandFactory.getDeploymentManager(getServer());
- if (bundleId == null) {
+ BundleInfo bundleInfo = AriesHelper.getBundleInfo(bundleModule.getProject());
+ long bundleId = dm.getEBAContentBundleId(ebaName, bundleInfo.getSymbolicName(),
bundleInfo.getVersion().toString());
+
+ if (bundleId == -1) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.bind(Messages.REFRESH_NO_BUNDLE_FAIL,
new String[] {bundleModule.getProject().getName(), ebaModule.getProject().getName()}));
}
- ExtendedDeploymentManager dm = (ExtendedDeploymentManager) DeploymentCommandFactory.getDeploymentManager(getServer());
/*
* Try class hot swap first and if it fails fallback to regular bundle update.
*/
@@ -654,7 +644,8 @@ public class GeronimoServerBehaviourDele
return false;
}
// ensure only classes have changed
- IModuleResourceDelta[] delta = getPublishedResourceDelta(new IModule[] { ebaModule,
bundleModule });
+ IModule[] module = new IModule[] { ebaModule, bundleModule };
+ IModuleResourceDelta[] delta = getPublishedResourceDelta(module);
IModuleResource[] classResources = DeploymentUtils.getChangedClassResources(delta);
if (classResources == null) {
Trace.tracePoint("Exit ", Activator.traceCore, "GeronimoServerBehaviourDelegate.refreshBundleClasses",
"Non-class resource modifications found");
@@ -667,7 +658,7 @@ public class GeronimoServerBehaviourDele
return false;
}
// get document base for the module if it is expanded
- String documentBase = getServerDelegate().isNoRedeploy() ? getWebModuleDocumentBase(bundleModule)
: null;
+ String documentBase = getServerDelegate().isNoRedeploy() ? getModulePublishLocation(module)
: null;
// see if the classes can be hot swapped - update archive if module is not expanded
if (!dm.hotSwapEBAContent(ebaName, bundleId, changeSetFile, documentBase == null))
{
Trace.tracePoint("Exit ", Activator.traceCore, "GeronimoServerBehaviourDelegate.refreshBundleClasses",
"Bundle class hot swap cannot be preformed");
@@ -1029,23 +1020,37 @@ public class GeronimoServerBehaviourDele
Trace.tracePoint("Exit ", Activator.traceCore, "GeronimoServerBehaviourDelegate.invokeCommand");
}
- private String getWebModuleDocumentBase(IModule webModule) {
- Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.getWebModuleDocumentBase",
webModule);
+ private String getModulePublishLocation(IModule[] module) {
+ Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.getModulePublishLocation",
Arrays.asList(module));
- if (webModule.isExternal()) {
- Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.getWebModuleDocumentBase",
"External module");
+ IModule childModule = module[module.length - 1];
+ if (childModule.isExternal()) {
+ Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.getModulePublishLocation",
"External module");
return null;
}
-
- String contextPath = getServerDelegate().getContextPath(webModule);
- if (contextPath == null) {
- Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.getWebModuleDocumentBase",
"Context path is null");
- return null;
+
+ String publishLocation = null;
+ String contextPath = getServerDelegate().getContextPath(childModule);
+ if (contextPath != null) {
+ // web module
+ publishLocation = getWebModulePublishLocation(childModule, contextPath);
+ } else if (module.length > 1 && GeronimoUtils.isEBAModule(module[0]))
{
+ // bundle module within eba
+ publishLocation = getBundleModulePublishLocation(module);
+ } else {
+ // unsupported module - no publish location
}
+ Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.getModulePublishLocation",
publishLocation);
+ return publishLocation;
+ }
+
+ private String getWebModulePublishLocation(IModule webModule, String contextPath) {
+ Trace.tracePoint("Enter", Activator.traceCore, "GeronimoServerBehaviourDelegate.getWebModulePublishLocation",
webModule, contextPath);
+
String documentBase = getWebModuleDocumentBase(contextPath);
if (documentBase == null) {
- Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.getWebModuleDocumentBase",
"Document base is not set");
+ Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.getWebModulePublishLocation",
"Document base is not set");
return null;
}
@@ -1053,23 +1058,53 @@ public class GeronimoServerBehaviourDele
if (!publishLocation.isAbsolute()) {
publishLocation = getServerResource(IGeronimoServerBehavior.VAR_CATALINA_DIR
+ documentBase).toFile();
}
-
- if (!publishLocation.exists()) {
- Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.getWebModuleDocumentBase",
"Document base does not exist", publishLocation);
+
+ if (publishLocation.isDirectory() ) {
+ Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.getWebModulePublishLocation",
contextPath, documentBase, publishLocation);
+ return publishLocation.getAbsolutePath();
+ } else {
+ Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.getWebModulePublishLocation",
"Invalid publish location", publishLocation);
return null;
}
+ }
+
+ private String getBundleModulePublishLocation(IModule[] module) {
+ Trace.tracePoint("Enter", Activator.traceCore, "GeronimoServerBehaviourDelegate.getBundleModulePublishLocation",
Arrays.asList(module));
- Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.getWebModuleDocumentBase",
contextPath, documentBase, publishLocation);
- return publishLocation.getAbsolutePath();
+ IModule ebaModule = module[0];
+ IModule bundleModule = module[module.length - 1];
+
+ AbstractName ebaName = getApplicationGBeanName(ebaModule);
+ if (ebaName == null) {
+ Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.getBundleModulePublishLocation",
"Unable to get eba name");
+ }
+
+ File publishLocation = null;
+ try {
+ ExtendedDeploymentManager dm = (ExtendedDeploymentManager) DeploymentCommandFactory.getDeploymentManager(getServer());
+
+ BundleInfo bundleInfo = AriesHelper.getBundleInfo(bundleModule.getProject());
+
+ publishLocation = dm.getEBAContentBundlePublishLocation(ebaName, bundleInfo.getSymbolicName(),
bundleInfo.getVersion().toString());
+ } catch (Exception e) {
+ Trace.trace(Trace.WARNING, "Error getting bundle publish location", e, Activator.traceCore);
+ }
+
+ if (publishLocation != null && publishLocation.isDirectory()) {
+ Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.getBundleModulePublishLocation",
publishLocation);
+ return publishLocation.getAbsolutePath();
+ } else {
+ Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.getBundleModulePublishLocation",
"Publish location is not available or is invalid", publishLocation);
+ return null;
+ }
}
private IStatus tryFileReplace(IModule[] module) {
- Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.tryFileReplace",
module.toString());
+ Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.tryFileReplace",
Arrays.asList(module));
- IModule webModule = module[module.length - 1];
- String documentBase = getWebModuleDocumentBase(webModule);
- if (documentBase == null) {
- Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.tryFileReplace",
"Document base is not set or is invalid");
+ String publishLocation = getModulePublishLocation(module);
+ if (publishLocation == null) {
+ Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.tryFileReplace",
"Publish location is not set or is invalid");
return null;
}
@@ -1080,7 +1115,7 @@ public class GeronimoServerBehaviourDele
}
Trace.trace(Trace.INFO, "Modified files: " + modifiedFiles, Activator.logCore);
- IStatus status = findAndReplaceFiles(webModule, modifiedFiles, documentBase);
+ IStatus status = findAndReplaceFiles(module[module.length - 1], modifiedFiles, publishLocation);
Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.tryFileReplace",
status);
return status;
}
@@ -1103,7 +1138,7 @@ public class GeronimoServerBehaviourDele
}
}
return modifiedFiles;
- }
+ }
/*
* This method is used to replace updated files without redeploying the entire module.
@@ -1128,8 +1163,8 @@ public class GeronimoServerBehaviourDele
target.append(moduleFile.getName());
File file = new File(target.toString());
- if(! file.isAbsolute()) {
- file = getServerResource(IGeronimoServerBehavior.VAR_CATALINA_DIR + target.toString()).toFile();
+ if (!file.isAbsolute()) {
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unexpected publish
location", null);
}
switch (deltaModule.getKind()) {
@@ -1188,161 +1223,6 @@ public class GeronimoServerBehaviourDele
return Status.OK_STATUS;
}
-
- private IStatus tryFileReplace(IModule rootModule, IModule[] module) {
- Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.tryFileReplace",
module.toString());
-
- IModule webModule = module[module.length - 1];
- if(GeronimoUtils.isEBAModule(rootModule) && GeronimoUtils.isBundleModule(webModule)){
- List<IModuleResourceDelta> modifiedFiles = findModifiedFiles(module);
- if (modifiedFiles == null) {
- Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.tryFileReplace",
"Some modified files cannot be replaced");
- return null;
- }
-
- IStatus status = findAndReplaceFilesInBundle(rootModule, webModule, modifiedFiles);
-
- return status;
- }
-
-
- String documentBase = getWebModuleDocumentBase(webModule);
- if (documentBase == null ) {
- Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.tryFileReplace",
"Document base is null");
-
- return null;
- }
-
- List<IModuleResourceDelta> modifiedFiles = findModifiedFiles(module);
- if (modifiedFiles == null) {
- Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.tryFileReplace",
"Some modified files cannot be replaced");
- return null;
- }
- Trace.trace(Trace.INFO, "Modified files: " + modifiedFiles, Activator.logCore);
-
- IStatus status = findAndReplaceFiles(webModule, modifiedFiles, documentBase);
- Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.tryFileReplace",
status);
- return status;
- }
-
- private IStatus findAndReplaceFilesInBundle(IModule rootModule, IModule module,
List<IModuleResourceDelta> modifiedFiles) {
-
- Trace.trace(Trace.INFO, "Replacing updated files for " + module.getName() + "
module.", Activator.logCore);
-
- String ch = File.separator;
- byte[] buffer = new byte[10 * 1024];
- int bytesRead;
-
- for (IModuleResourceDelta deltaModule : modifiedFiles) {
- IModuleFile moduleFile = (IModuleFile) deltaModule.getModuleResource();
-
-
- StringBuilder target = new StringBuilder();
- try {
- String rootModuleID = DeploymentUtils.getTargetModuleID(getServer(), rootModule).getModuleID();
- String[] rootNames = rootModuleID.split("/");
- String version = rootNames[rootNames.length-2];
- String parentDir = rootModuleID.substring(0, rootModuleID.indexOf(rootNames[rootNames.length
- 1]));
-
- target.append(ch).append(parentDir.replace("/", ch)).append(AriesHelper.getApplicationBundleInfo(rootModule.getProject()).getSymbolicName()).append("-").append(version).append(OsgiConstants.APPLICATION_EXTENSION).append(ch);
-
-
-
- } catch (TargetModuleIdNotFoundException te) {
- Trace.trace(Trace.ERROR, "Cannot find root module target ID: " + rootModule.getName(),
te, Activator.logCore);
- return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Cannot find root module
target ID " + rootModule.getName(), te);
- } catch (Exception e) {
- Trace.trace(Trace.ERROR, "Cannot get application bundle information: " +
rootModule.getName(), e, Activator.logCore);
- return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Cannot find application
bundle information " + rootModule.getName(), e);
- }
-
-
-
- target.append(AriesHelper.getSymbolicName(module)).append("_").append(AriesHelper.getVersion(module).toString()).append(OsgiConstants.BUNDLE_EXTENSION).append(ch);
- String relativePath = moduleFile.getModuleRelativePath().toOSString();
-
- if (relativePath != null && relativePath.length() != 0) {
- target.append(relativePath);
- target.append(ch);
- }
- target.append(moduleFile.getName());
-
- File file = new File(target.toString());
- if (!file.isAbsolute()) {
- file = getServerResource(IGeronimoServerBehavior.REPOSITORY_DIR + target.toString()).toFile();
- }
-
- switch (deltaModule.getKind()) {
- case IModuleResourceDelta.REMOVED:
- if (file.exists()) {
- file.delete();
- }
- break;
- case IModuleResourceDelta.ADDED:
- case IModuleResourceDelta.CHANGED:
- File parentFile = file.getParentFile();
- if (parentFile != null && !parentFile.exists()) {
- if (!parentFile.mkdirs()) {
- Trace.trace(
- Trace.ERROR,
- "Cannot create target directory: " + parentFile,
- Activator.logCore);
- return new Status(IStatus.ERROR, Activator.PLUGIN_ID,
- "Cannot create target directory", null);
- }
- }
-
- String sourceFile = relativePath;
- InputStream in = null;
- FileOutputStream out = null;
- try {
- IFile srcIFile = (IFile) moduleFile.getAdapter(IFile.class);
- if (srcIFile != null) {
- in = srcIFile.getContents();
- } else {
- File srcFile = (File) moduleFile.getAdapter(File.class);
- in = new FileInputStream(srcFile);
- }
-
- out = new FileOutputStream(file);
-
- while ((bytesRead = in.read(buffer)) > 0) {
- out.write(buffer, 0, bytesRead);
- }
- } catch (FileNotFoundException e) {
- Trace.trace(Trace.ERROR, "Cannot find file to copy: "
- + sourceFile, e, Activator.logCore);
- return new Status(IStatus.ERROR, Activator.PLUGIN_ID,
- "Cannot find file " + sourceFile, e);
- } catch (IOException e) {
- Trace.trace(Trace.ERROR, "Cannot copy file: " + sourceFile,
- e, Activator.logCore);
- return new Status(IStatus.ERROR, Activator.PLUGIN_ID,
- "Cannot copy file " + sourceFile, e);
- } catch (CoreException e) {
- Trace.trace(Trace.ERROR, "Cannot copy file: " + sourceFile,
- e, Activator.logCore);
- return e.getStatus();
- } finally {
- if (in != null) {
- try {
- in.close();
- } catch (IOException ignore) {
- }
- }
- if (out != null) {
- try {
- out.close();
- } catch (IOException ignore) {
- }
- }
- }
- break;
- }
- }
-
- return Status.OK_STATUS;
- }
public Map getServerInstanceProperties() {
return getRuntimeDelegate().getServerInstanceProperties();
Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/IGeronimoServerBehavior.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/IGeronimoServerBehavior.java?rev=1360915&r1=1360914&r2=1360915&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/IGeronimoServerBehavior.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/IGeronimoServerBehavior.java
Thu Jul 12 20:33:57 2012
@@ -27,8 +27,6 @@ import org.eclipse.core.runtime.IPath;
*/
public interface IGeronimoServerBehavior {
public static String VAR_CATALINA_DIR = "var" + File.separator + "catalina" + File.separator;
-
- public static String REPOSITORY_DIR = "repository" + File.separator;
public boolean isFullyStarted();
|