You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ga...@apache.org on 2011/07/09 03:38:20 UTC
svn commit: r1144570 - in
/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core:
./ osgi/
Author: gawor
Date: Sat Jul 9 01:38:19 2011
New Revision: 1144570
URL: http://svn.apache.org/viewvc?rev=1144570&view=rev
Log:
GERONIMODEVTOOLS-759: Don't persist bundle id mappings. Patch from Yi Xiao
Added:
geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGIBundleCache.java (with props)
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/GeronimoUtils.java
geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/ModuleArtifactMapper.java
geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGIBundleHelper.java
geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OsgiConstants.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=1144570&r1=1144569&r2=1144570&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 Sat Jul 9 01:38:19 2011
@@ -59,6 +59,7 @@ 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.OSGIBundleCache;
import org.apache.geronimo.st.v30.core.osgi.OSGIBundleHelper;
import org.apache.geronimo.st.v30.core.osgi.OsgiConstants;
import org.eclipse.core.commands.ExecutionException;
@@ -703,16 +704,20 @@ abstract public class GeronimoServerBeha
protected void removeObsoleteOSGIBundles() throws CoreException {
try {
- Map<String, String[]> bundleMap = ModuleArtifactMapper.getInstance().getServerBundlesMap(getServer());
- synchronized(bundleMap) {
- Iterator<Map.Entry<String, String[]>> bundleIter = bundleMap.entrySet().iterator();
- while(bundleIter.hasNext()) {
- Map.Entry<String, String[]> bundleEntry = bundleIter.next();
- if("true".equals(bundleEntry.getValue()[3])) {
- long bundleId = Long.parseLong(bundleEntry.getValue()[2]);
+ Set<OSGIBundleCache.BundleInfo> bundles = OSGIBundleHelper.getSpecificServerBundles(getServer());
+ synchronized(bundles) {
+ Iterator<OSGIBundleCache.BundleInfo> iter = bundles.iterator();
+ while(iter.hasNext()) {
+ OSGIBundleCache.BundleInfo bif = iter.next();
+ if(bif.isDirty()) {
+ long bundleId = OSGIBundleHelper.getOSGIBundleIdFromServer(getServer(), bif);
+ if(bundleId == -1) {
+ iter.remove();
+ continue;
+ }
IStatus status = this.removeOSGIBundleById(bundleId);
if(status.isOK()) {
- bundleIter.remove();
+ iter.remove();
}
}
}
@@ -884,6 +889,7 @@ abstract public class GeronimoServerBeha
protected void invokeCommand(int deltaKind, IModule module, IProgressMonitor monitor) throws CoreException {
Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.invokeCommand", deltaKindToString(deltaKind), module.getName());
ClassLoader old = Thread.currentThread().getContextClassLoader();
+ System.out.println("haha");
try {
ClassLoader cl = getContextClassLoader();
if (cl != null)
@@ -926,36 +932,23 @@ abstract public class GeronimoServerBeha
*/
protected void doAdded(IModule module, String configId, IProgressMonitor monitor) throws Exception {
Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.doAdded", module.getName(), configId);
- if(OSGIBundleHelper.isBundle(module)) {
- configId = ModuleArtifactMapper.getInstance().resolveBundleByModule(getServer(), module);
- } else {
- configId = getLastKnowConfigurationId(module, configId);
- }
-
IStatus status;
TargetModuleID[] ids;
- if (configId == null) {
- if(OSGIBundleHelper.isBundle(module)) {/* If the module is the OSGI bundle */
- Map<String, String[]> bundlesMap = ModuleArtifactMapper.getInstance().getServerBundlesMap(getServer());
- if(bundlesMap != null) {
- synchronized (bundlesMap) {
- Object[] ret = this.distributeOSGIBundles(module);
- status = (IStatus) ret[0];
- if(status.isOK()) {
- /* Add the bundle info into the ModuleArtifactMapper's bundle cache */
- Long bundleId = (Long) ret[1];
- OSGIBundleHelper.addBundleToPublishedMap(getServer(), module, bundleId);
- /* end here */
- setModuleState(new IModule [] { module }, IServer.STATE_STARTED);
- } else {
- doFail(status, Messages.DISTRIBUTE_FAIL);
- }
- }
- }
-
- } else {
- Map<String, String> artifactsMap = ModuleArtifactMapper.getInstance().getServerArtifactsMap(getServer());
+ if(OSGIBundleHelper.isBundle(module)) {
+ status = this.distributeOSGIBundles(module);
+ if(status.isOK()) {
+ /* Add the bundle info into the ModuleArtifactMapper's bundle cache */
+ OSGIBundleHelper.addBundleToCache(getServer(), module);
+ /* end here */
+ setModuleState(new IModule [] { module }, IServer.STATE_STARTED);
+ } else {
+ doFail(status, Messages.DISTRIBUTE_FAIL);
+ }
+ } else {
+ configId = getLastKnowConfigurationId(module, configId);
+ if (configId == null) {
+ Map<String, String> artifactsMap = ModuleArtifactMapper.getInstance().getServerArtifactsMap(getServer());
if (artifactsMap != null) {
synchronized (artifactsMap) {
status = distribute(module, monitor);
@@ -980,12 +973,12 @@ abstract public class GeronimoServerBeha
} else {
setModuleState(new IModule [] { module }, IServer.STATE_STARTED);
}
- }
- } else {
- //either (1) a configuration with the same module id exists already on the server
- //or (2) the module now has a different configId and the configuration on the server using
- //the old id as specified in the project-configId map should be uninstalled.
- doChanged(module, configId, monitor);
+ } else {
+ //either (1) a configuration with the same module id exists already on the server
+ //or (2) the module now has a different configId and the configuration on the server using
+ //the old id as specified in the project-configId map should be uninstalled.
+ doChanged(module, configId, monitor);
+ }
}
Trace.tracePoint("Exit ", Activator.traceCore, "GeronimoServerBehaviourDelegate.doAdded");
@@ -998,16 +991,15 @@ abstract public class GeronimoServerBeha
protected void doChanged(IModule module, String configId, IProgressMonitor monitor) throws Exception {
Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.doChanged", module.getName(), configId);
IStatus status = null;
- Object[] ret = null;
if(OSGIBundleHelper.isBundle(module)) {
- boolean isPublished = OSGIBundleHelper.checkBundleInPublishedMap(getServer(), module);
+ boolean isPublished = OSGIBundleHelper.checkBundleInCache(getServer(), module);
+// int state = DeploymentUtils.getModuleState(getServer(), module);
if(isPublished) status = doOSGIBundleRedeploy(module);
else {
- ret = this.distributeOSGIBundles(module);
- status = (IStatus) ret[0];
+ status = this.distributeOSGIBundles(module);
}
if(status.isOK()) {
- if(! isPublished) OSGIBundleHelper.addBundleToPublishedMap(getServer(), module, (Long) ret[1]);
+ if(! isPublished) OSGIBundleHelper.addBundleToCache(getServer(), module);
setModuleState(new IModule [] { module }, IServer.STATE_STARTED);
} else {
doFail(status, Messages.REDEPLOY_FAIL);
@@ -1192,9 +1184,9 @@ abstract public class GeronimoServerBeha
IStatus status = null;
if(OSGIBundleHelper.isBundle(module)) {/* If the module is a OSGI bundle */
// must consider the situation of the project name or bundle name or both have been changed, not done yet!!!
- status= this.removeOSGIBundle(module);
+ status = this.removeOSGIBundle(module);
if(status.isOK()) {
- OSGIBundleHelper.removeBundleFromPublishedMap(getServer(), module);
+ OSGIBundleHelper.removeBundleFromCache(getServer(), module);
} else {
doFail(status, Messages.DISTRIBUTE_FAIL);
}
@@ -1268,27 +1260,20 @@ abstract public class GeronimoServerBeha
protected IStatus doOSGIBundleRedeploy(IModule module) throws Exception {
IStatus status = Status.CANCEL_STATUS;
- Map<String, String[]> bundlesMap = ModuleArtifactMapper.getInstance().getServerBundlesMap(getServer());
- if(bundlesMap != null) {
- synchronized (bundlesMap) {
- status = this.removeOSGIBundle(module);
- if(status.isOK()) {
- OSGIBundleHelper.removeBundleFromPublishedMap(getServer(), module);/* remove the bundle from cache */
- /* install the bundle as a new one */
- Object[] ret = this.distributeOSGIBundles(module);
- status = (IStatus) ret[0];
- if(status.isOK()) {
- /* Add the bundle info into the ModuleArtifactMapper's bundle cache */
- Long bundleId = (Long) ret[1];
- OSGIBundleHelper.addBundleToPublishedMap(getServer(), module, bundleId);
- /* end here */
- }
- }
+ status = this.removeOSGIBundle(module);
+ if(status.isOK()) {
+ OSGIBundleHelper.removeBundleFromCache(getServer(), module);/* remove the bundle from cache */
+ /* install the bundle as a new one */
+ status = this.distributeOSGIBundles(module);
+ if(status.isOK()) {
+ /* Add the bundle info into the ModuleArtifactMapper's bundle cache */
+ OSGIBundleHelper.addBundleToCache(getServer(), module);
+ /* end here */
}
- }
+ }
return status;
}
- protected Object[] distributeOSGIBundles(IModule module) throws Exception {
+ protected IStatus distributeOSGIBundles(IModule module) throws Exception {
RemoteDeploymentManager rDm = (RemoteDeploymentManager)DeploymentCommandFactory.getDeploymentManager(this.getServer());
try {
/* Get target file */
@@ -1298,23 +1283,23 @@ abstract public class GeronimoServerBeha
Messages.bind(Messages.moduleExportError, module.getProject().getName())));
}
/* end here */
-
- long bundleId = rDm.recordInstall(f, OsgiConstants.BUNDLE_IS_INPLACE, OsgiConstants.BUNDLE_DEFAULT_START_LEVLE);
+ long bundleId = rDm.recordInstall(f, null, OsgiConstants.BUNDLE_DEFAULT_START_LEVLE);
boolean ss = this._startBundle(bundleId);
if(ss) {
- return new Object[] {Status.OK_STATUS, new Long(bundleId)};
+ return Status.OK_STATUS;
} else {
Trace.trace(Trace.ERROR, "The Bundle: " + module.getName() + " could not be installed", null, Activator.logCore);
- return new Object[] {Status.CANCEL_STATUS};
+ return Status.CANCEL_STATUS;
}
} catch (IOException e) {
Trace.trace(Trace.ERROR, "The Bundle: " + module.getName() + " could not be installed", e, Activator.logCore);
- return new Object[] {Status.CANCEL_STATUS};
+ return Status.CANCEL_STATUS;
}
}
protected IStatus removeOSGIBundle(IModule module) throws Exception {
try {
- long bundleId = ModuleArtifactMapper.getInstance().getBundleId(getServer(), module);
+ long bundleId = OSGIBundleHelper.getOSGIBundleIdFromServer(getServer(), module);
+ if(bundleId == -1) return Status.OK_STATUS;// indicate the bundle has been removed from server
return this.removeOSGIBundleById(bundleId);
} catch (Exception e) {
Trace.trace(Trace.ERROR, "The Bundle: " + module.getName() + " could not be unInstalled", e, Activator.logCore);
@@ -1322,6 +1307,7 @@ abstract public class GeronimoServerBeha
}
}
+
protected IStatus removeOSGIBundleById(long bundleId) throws Exception {
try {
boolean isSuccess = this._unInstallBundle(bundleId);
@@ -1586,7 +1572,6 @@ abstract public class GeronimoServerBeha
try {
jmxConnector = JMXConnectorFactory.connect(address, map);
} catch (SecurityException se) {
- //FIXME once GERONIMO-3467 JIRA is fixed
Thread.sleep(10000);
jmxConnector = JMXConnectorFactory.connect(address, map);
}
@@ -1655,7 +1640,7 @@ abstract public class GeronimoServerBeha
Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.startModule", Arrays.asList(module));
try {
if(OSGIBundleHelper.isBundle(module[0])) {
- boolean isIn = OSGIBundleHelper.checkBundleInPublishedMap(getServer(), module[0]);
+ boolean isIn = OSGIBundleHelper.checkBundleInCache(getServer(), module[0]);
int state = DeploymentUtils.getModuleState(getServer(), module[0]);
if(isIn && (state == IServer.STATE_STOPPED)) startOSGIBundle(module[0]);
else throw new Exception(Messages.START_FAIL);
@@ -1671,7 +1656,7 @@ abstract public class GeronimoServerBeha
protected void startOSGIBundle(IModule module) throws Exception {
- long bundleId = OSGIBundleHelper.getOSGIBundleId(getServer(), module);
+ long bundleId = OSGIBundleHelper.getOSGIBundleIdFromServer(getServer(), module);
if(bundleId == -1) throw new Exception("can not start bundle");
boolean ss = this._startBundle(bundleId);
if(ss) {
@@ -1681,7 +1666,7 @@ abstract public class GeronimoServerBeha
}
}
protected void stopOSGIBundle(IModule module) throws Exception {
- long bundleId = OSGIBundleHelper.getOSGIBundleId(getServer(), module);
+ long bundleId = OSGIBundleHelper.getOSGIBundleIdFromServer(getServer(), module);
if(bundleId == -1) throw new Exception("can not stop bundle");
boolean ss = this._stopBundle(bundleId);
if(ss) {
@@ -1695,7 +1680,7 @@ abstract public class GeronimoServerBeha
Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.stopModule", Arrays.asList(module));
try {
if(OSGIBundleHelper.isBundle(module[0])) {
- boolean isIn = OSGIBundleHelper.checkBundleInPublishedMap(getServer(), module[0]);
+ boolean isIn = OSGIBundleHelper.checkBundleInCache(getServer(), module[0]);
int state = DeploymentUtils.getModuleState(getServer(), module[0]);
if(! isIn || state == IServer.STATE_UNKNOWN) doFail(Status.CANCEL_STATUS, Messages.DISTRIBUTE_FAIL);
else {
@@ -1717,7 +1702,7 @@ abstract public class GeronimoServerBeha
Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.restartModule", Arrays.asList(module));
try {
if(OSGIBundleHelper.isBundle(module[0])) {
- boolean isIn = OSGIBundleHelper.checkBundleInPublishedMap(getServer(), module[0]);
+ boolean isIn = OSGIBundleHelper.checkBundleInCache(getServer(), module[0]);
int state = DeploymentUtils.getModuleState(getServer(), module[0]);
if(isIn && (state == IServer.STATE_STARTED)) {
this.stopOSGIBundle(module[0]);
@@ -1779,18 +1764,17 @@ abstract public class GeronimoServerBeha
return false;
}
}
- private boolean _unInstallBundle(long bundleId) {
+ private boolean _unInstallBundle(long bundleId) throws CoreException {
+ RemoteDeploymentManager rDm = (RemoteDeploymentManager)DeploymentCommandFactory.getDeploymentManager(this.getServer());
try {
- MBeanServerConnection connection = getServerConnection();
- connection.invoke(getFramework(), "uninstallBundle",
- new Object[] { bundleId }, new String[] { long.class.getName() });
+ rDm.eraseUninstall(bundleId);
return true;
} catch(Exception e) {
- Trace.trace(Trace.INFO, "Could not uninstall bundle", Activator.traceCore);
+ Trace.trace(Trace.INFO, e.getMessage(), Activator.traceCore);
return false;
}
}
- protected ObjectName getFramework() throws Exception {
+ public ObjectName getFramework() throws Exception {
try {
MBeanServerConnection connection = getServerConnection();
Set<ObjectName> objectNameSet =
Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoUtils.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/GeronimoUtils.java?rev=1144570&r1=1144569&r2=1144570&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoUtils.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoUtils.java Sat Jul 9 01:38:19 2011
@@ -32,6 +32,7 @@ import org.apache.geronimo.jee.web.WebAp
import org.apache.geronimo.st.v30.core.internal.Trace;
import org.apache.geronimo.st.v30.core.jaxb.JAXBUtils;
import org.apache.geronimo.st.v30.core.osgi.AriesHelper;
+import org.apache.geronimo.st.v30.core.osgi.OSGIBundleHelper;
import org.apache.geronimo.st.v30.core.osgi.OsgiConstants;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -202,11 +203,11 @@ public class GeronimoUtils {
if (AriesHelper.isAriesInstalled()) {
try {
if (isEBAModule(module)) {
- Class ariesUtilsClass = Class.forName("com.ibm.etools.aries.internal.core.utils.AriesUtils");
+ Class<?> ariesUtilsClass = Class.forName("com.ibm.etools.aries.internal.core.utils.AriesUtils");
Method method = ariesUtilsClass.getMethod("getApplicationManifest", IProject.class);
Object object = method.invoke(null, module.getProject());
- Class appManifestClass = Class.forName("com.ibm.etools.aries.core.models.ApplicationManifest");
+ Class<?> appManifestClass = Class.forName("com.ibm.etools.aries.core.models.ApplicationManifest");
method = appManifestClass.getMethod("getApplicationSymbolicName");
String artifactID = (String) method.invoke(object);
@@ -222,22 +223,7 @@ public class GeronimoUtils {
}
}
if(isBundleModule(module)) {
- Class<?> ariesUtilsClass = Class.forName("com.ibm.etools.aries.internal.core.utils.AriesUtils");
- Method method = ariesUtilsClass.getMethod("getBlueprintBundleManifest", IProject.class);
- Object object = method.invoke(null, module.getProject());
-
- Class<?> bundleManifest = Class.forName("com.ibm.etools.aries.core.models.BundleManifest");
- method = bundleManifest.getMethod("getBundleSymbolicName");
- String bundleSymName = (String) method.invoke(object);
-
- method = bundleManifest.getMethod("getBundleVersion");
- String versionStr = (String) method.invoke(object);
- Version version = Version.parseVersion(versionStr);
- String newVersionStr = getVersion(version);
-
- if (bundleSymName != null && version != null) {
- return bundleSymName + ":" + newVersionStr;
- }
+ return OSGIBundleHelper.getBundleSymbolicNameAndVersionString(module.getProject());
}
} catch (Exception e) {
}
Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/ModuleArtifactMapper.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/ModuleArtifactMapper.java?rev=1144570&r1=1144569&r2=1144570&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/ModuleArtifactMapper.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/ModuleArtifactMapper.java Sat Jul 9 01:38:19 2011
@@ -18,11 +18,9 @@ package org.apache.geronimo.st.v30.core;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
-import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
-import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInput;
@@ -31,18 +29,7 @@ import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
-
-import org.apache.geronimo.st.v30.core.internal.Trace;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IResourceChangeEvent;
-import org.eclipse.core.resources.IResourceChangeListener;
-import org.eclipse.core.resources.IResourceDelta;
-import org.eclipse.core.resources.IResourceDeltaVisitor;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
@@ -57,18 +44,13 @@ public class ModuleArtifactMapper {
private static ModuleArtifactMapper instance = new ModuleArtifactMapper();
private static final String FILE_NAME = "servermodule.info";
- private static final String BUNDLE_FILE_NAME = "serverbundle.info";
private ServerEntries serverArtifactEntries = null;
- private ServerBundleEntries serverBundleEntries = null;
private ModuleArtifactMapper() {
if (serverArtifactEntries == null) {
serverArtifactEntries = new ServerEntries();
}
- if(serverBundleEntries == null) {
- serverBundleEntries = new ServerBundleEntries();
- }
load();
}
@@ -97,87 +79,6 @@ public class ModuleArtifactMapper {
}
}
- synchronized public void addBundleEntry(IServer server, IModule module, String symName, String version, long bundleId) {
- Map<String, String[]> bundleEntries = getServerBundlesMap(server);
- if (bundleEntries != null && module != null) {
- bundleEntries.put(module.getProject().getName(), new String[] {symName, version, new Long(bundleId).toString(), "false"});
- }
- }
- synchronized public String resolveBundleByModule(IServer server, IModule module) {// return the bundle symbolic name
- if(module != null && module.getProject() != null) {
- Map<String, String[]> bundleEntries = this.serverBundleEntries.get(server.getRuntime().getLocation().toFile());
- if (bundleEntries != null) {
- String[] vs = bundleEntries.get(module.getProject().getName());
- return vs == null ? null : vs[0];
- }
- }
- return null;
- }
- synchronized public String resolveBundleBySymbolicName(IServer server, String symName, String version) {// return the project name
- if(symName == null || version == null) return null;
- Map<String, String[]> bundleEntries = this.serverBundleEntries.get(server.getRuntime().getLocation().toFile());
- if (bundleEntries != null) {
- Iterator<Map.Entry<String, String[]>> iter = bundleEntries.entrySet().iterator();
- while(iter.hasNext()) {
- Map.Entry<String, String[]> entry = iter.next();
- if(symName.equals(entry.getValue()[0]) && version.equals(entry.getValue()[1])) return entry.getKey();
- }
- }
- return null;
- }
- synchronized public boolean checkBundleDirty(IServer server, IModule module) {
- boolean isDirty = false;
- if(module != null && module.getProject() != null) {
- Map<String, String[]> bundleEntries = this.serverBundleEntries.get(server.getRuntime().getLocation().toFile());
- if (bundleEntries != null) {
- String[] vs = bundleEntries.get(module.getProject().getName());
- if(vs == null) isDirty = false;
- else isDirty = Boolean.parseBoolean(vs[3]);
- }
- }
- return isDirty;
- }
- @SuppressWarnings("finally")
- synchronized public String resolveBundleById(IServer server, int bundleId) {// return the project name
- String pName = null;
- try {
- String idStr = new Integer(bundleId).toString();
- Map<String, String[]> bundleEntries = this.serverBundleEntries.get(server.getRuntime().getLocation().toFile());
- if (bundleEntries != null) {
- Iterator<Map.Entry<String, String[]>> iter = bundleEntries.entrySet().iterator();
- while(iter.hasNext()) {
- Map.Entry<String, String[]> entry = iter.next();
- if(idStr.equals(entry.getValue()[2])) return entry.getKey();
- }
- }
- } catch(Exception e) {
- Trace.trace(Trace.ERROR, e.getMessage(), e, Activator.logCore);
- } finally {
- return pName;
- }
- }
- synchronized public void removeBundle(IServer server, IModule module) {
- if(module != null && module.getProject() != null) {
- Map<String, String[]> bundleEntries = this.serverBundleEntries.get(server.getRuntime().getLocation().toFile());
- if(bundleEntries != null) {
- bundleEntries.remove(module.getProject().getName());
- }
- }
- }
-
- public long getBundleId(IServer server, IModule module) {
- int id = -1;
- if(module != null && module.getProject() != null) {
- String projectName = module.getProject().getName();
- Map<String, String[]> bundleEntries = this.serverBundleEntries.get(server.getRuntime().getLocation().toFile());
- if (bundleEntries != null) {
- String[] strs = bundleEntries.get(projectName);
- if(strs != null) return new Long(strs[2]);
- }
- }
- return id;
- }
-
synchronized public String resolveArtifact(IServer server, IModule module) {
if (module != null) {
Map<String, String> artifactEntries = getServerArtifactsMap(server);
@@ -202,20 +103,7 @@ public class ModuleArtifactMapper {
return artifactEntries;
}
- synchronized public Map<String, String[]> getServerBundlesMap(IServer server) {
- if (!SocketUtil.isLocalhost(server.getHost())) {
- return null;
- }
-
- File runtimeLoc = server.getRuntime().getLocation().toFile();
- Map<String, String[]> bundleEntries = serverBundleEntries.get(runtimeLoc);
- if (bundleEntries == null) {
- bundleEntries = new HashMap<String, String[]>();
- serverBundleEntries.put(runtimeLoc, bundleEntries);
- }
-
- return bundleEntries;
- }
+
private void save(IServerEntries entries, String fileName) {
ObjectOutput output = null;
try {
@@ -239,7 +127,6 @@ public class ModuleArtifactMapper {
synchronized public void save() {
save(serverArtifactEntries, FILE_NAME);
- save(serverBundleEntries, BUNDLE_FILE_NAME);
}
private void load(IServerEntries entries, String fileName) {
@@ -266,8 +153,6 @@ public class ModuleArtifactMapper {
}
synchronized private void load() {
load(serverArtifactEntries, FILE_NAME);
- load(serverBundleEntries, BUNDLE_FILE_NAME);
- addListener();
}
@@ -353,177 +238,4 @@ public class ModuleArtifactMapper {
}
}
- protected class ServerBundleEntries extends HashMap<File, Map<String, String[]>> implements IServerEntries{
- static final long serialVersionUID = 0;
-
- public void loadXML (String xml) {
- if (xml == null || xml.length() == 0)
- return;
-
- String projectName, bundleSymName, bundleVersion, bundleId, removed;
- int fileEndPos, nomapStartPos, mapStartPos, mapEndPos, stringStartPos, stringEndPos;
- int fileStartPos = xml.indexOf("<file>", 0);
- Map<String, String[]> artifactEntries;
- while (fileStartPos > -1) {
- fileEndPos = xml.indexOf("</file>", fileStartPos);
- File runtimeLoc = new File(xml.substring(fileStartPos + 6, fileEndPos));
-
- nomapStartPos = xml.indexOf("<map/>", fileEndPos);
- mapStartPos = xml.indexOf("<map>", fileEndPos);
- artifactEntries = new HashMap<String, String[]>();
- // have projects on the server
- if ((nomapStartPos == -1) || (nomapStartPos > mapStartPos)) {
- mapEndPos = xml.indexOf("</map>", mapStartPos);
- stringStartPos = xml.indexOf("<string>", mapStartPos);
- while ((stringStartPos > -1) && (stringStartPos < mapEndPos)) {
- stringEndPos = xml.indexOf("</string>", stringStartPos);
- projectName = xml.substring(stringStartPos + 8, stringEndPos);// load project name
- stringStartPos = xml.indexOf("<string>", stringEndPos);
- stringEndPos = xml.indexOf("</string>", stringStartPos);
- bundleSymName = xml.substring(stringStartPos + 8, stringEndPos);// load bundle symbolic name
- stringStartPos = xml.indexOf("<string>", stringEndPos);
- stringEndPos = xml.indexOf("</string>", stringStartPos);
- bundleVersion = xml.substring(stringStartPos + 8, stringEndPos);// load bundle version
- stringStartPos = xml.indexOf("<string>", stringEndPos);
- stringEndPos = xml.indexOf("</string>", stringStartPos);
- bundleId = xml.substring(stringStartPos + 8, stringEndPos);// load bundle id
- stringStartPos = xml.indexOf("<string>", stringEndPos);
- stringEndPos = xml.indexOf("</string>", stringStartPos);
- removed = xml.substring(stringStartPos + 8, stringEndPos);// load bundle removed
-
- artifactEntries.put(projectName, new String []{bundleSymName, bundleVersion, bundleId, removed});
- stringStartPos = xml.indexOf("<string>", stringEndPos);
-
- }
- }
- // if no projects on the server, it is ok to put an empty HashMap
- this.put (runtimeLoc, artifactEntries);
-
- fileStartPos = xml.indexOf("<file>", fileEndPos);
- }
- }
-
- public String toXML () {
- String xmlString = "";
- if (!isEmpty()) {
- xmlString = "<map>\n <entry>\n";
-
- Object[] serverKeySet = keySet().toArray();
- for (int i = 0; i < serverKeySet.length; i++) {
- xmlString += " <file>" + serverKeySet[i] + "</file>\n";
- Map<String, String[]> projectMap = (Map<String, String[]>)get(serverKeySet[i]);
- if (projectMap == null || projectMap.size() == 0) {
- xmlString += " <map/>\n";
- }
- else {
- xmlString += " <map>\n";
- Object[] projectKeySet = projectMap.keySet().toArray();
- for (int j = 0; j < projectKeySet.length; j++)
- {
- xmlString += " <entry>\n";
- xmlString += " <string>" + (String)projectKeySet[j] + "</string>\n";
- xmlString += " <string>" + (String)projectMap.get(projectKeySet[j])[0] + "</string>\n";
- xmlString += " <string>" + (String)projectMap.get(projectKeySet[j])[1] + "</string>\n";
- xmlString += " <string>" + (String)projectMap.get(projectKeySet[j])[2] + "</string>\n";
- xmlString += " <string>" + (String)projectMap.get(projectKeySet[j])[3] + "</string>\n";
- xmlString += " </entry>\n";
- }
- xmlString += " </map>\n";
- }
- }
- xmlString += " </entry>\n</map>";
- }
- return xmlString;
- }
- }
- // private methods
- private void addListener() {
- ResourcesPlugin.getWorkspace().addResourceChangeListener(new IResourceChangeListener() {
- @Override
- public void resourceChanged(IResourceChangeEvent event) {
- if(event.getType() == IResourceChangeEvent.POST_CHANGE) {// just listen to the project's change event
- try {
- event.getDelta().accept(new IResourceDeltaVisitor() {
-
- @Override
- public boolean visit(IResourceDelta delta) throws CoreException {
- if(delta.getKind() == IResourceDelta.REMOVED) {
- return processResourceRemoved(delta.getResource());
- } else if(delta.getKind() == IResourceDelta.CHANGED) {
- return processResourceChanged(delta.getResource());
- }
- return false;
- }
-
- private boolean processResourceRemoved(IResource res) {
- try {
- if(res instanceof IProject) {
- IProject p = (IProject) res;
- String projectName = p.getName();
-
- Iterator<Map.Entry<File, Map<String, String[]>>> iter = serverBundleEntries.entrySet().iterator();
- while(iter.hasNext()) {
- Map.Entry<File, Map<String, String[]>> serverEntry = iter.next();
- Map<String, String[]> bundleMap = serverEntry.getValue();
- String[] value = bundleMap.get(projectName);
- if(value != null) {
- value[3] = "true";// set removed flag to true
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return true;
- }
-
- private boolean processResourceChanged(IResource res) {
- try {
- if(res.getFullPath().toString().endsWith(".MF")) {// the project's menifest file is changed
- BufferedReader br = new BufferedReader(new FileReader(res.getLocation().toFile()));
- String projectName = res.getFullPath().toString().split("/")[1];
- String fc = br.readLine();
- String symbolicName = null, version = null;
- boolean bss = false, bvs = false;
- while(fc != null && (! bss || ! bvs)) {
- if(fc.startsWith("Bundle-SymbolicName")) {
- int index = fc.indexOf(":");
- symbolicName = fc.substring(index+1).trim();bss = true;
- } else if (fc.startsWith("Bundle-Version")) {
- int index = fc.indexOf(":");
- version = fc.substring(index+1).trim();bvs = true;
- }
- fc = br.readLine();
- }
- Iterator<Map.Entry<File, Map<String, String[]>>> iter = serverBundleEntries.entrySet().iterator();
- while(iter.hasNext()) {
- Map.Entry<File, Map<String, String[]>> serverEntry = iter.next();
- Map<String, String[]> bundleMap = serverEntry.getValue();
-
- String[] value = bundleMap.get(projectName);
- if(value != null) {
- if(value[0].equals(symbolicName) && value[1].equals(version)) break;
- value[0] = symbolicName; value[1] = version;
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return true;
- }
-
- });
- } catch (CoreException e) {
- e.printStackTrace();
- }
- }
-
- }
- }, IResourceChangeEvent.POST_CHANGE);
-
- }
-
-
-
}
Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGIBundleCache.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/osgi/OSGIBundleCache.java?rev=1144570&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGIBundleCache.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGIBundleCache.java Sat Jul 9 01:38:19 2011
@@ -0,0 +1,281 @@
+package org.apache.geronimo.st.v30.core.osgi;
+
+import java.io.File;
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.geronimo.st.v30.core.Activator;
+import org.apache.geronimo.st.v30.core.internal.Trace;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceDeltaVisitor;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.util.SocketUtil;
+
+@SuppressWarnings("serial")
+public class OSGIBundleCache extends HashMap<File, Set<OSGIBundleCache.BundleInfo>> {
+ private static OSGIBundleCache instance = new OSGIBundleCache();
+
+ private OSGIBundleCache(){
+ addProjectListener();
+ };
+
+ public synchronized static OSGIBundleCache getInstance() {
+ if(instance == null) instance = new OSGIBundleCache();
+ return instance;
+ }
+ /**
+ * Add bundle info into the cache
+ * @param server
+ * @param module
+ * @param symName
+ * @param version
+ * @param id
+ */
+ public synchronized void addBundleEntry(IServer server, IModule module, String symName, String version) {
+ Set<BundleInfo> bundles = this.getServerBundles(server);
+ if(module != null && module.getProject() != null) {
+ BundleInfo bInfo = new BundleInfo(module.getProject().getName(), symName, version, false);
+ bundles.add(bInfo);
+ }
+ }
+ /**
+ * Remove the bundle info from the cache
+ * @param server
+ * @param module
+ */
+ public synchronized void removeBundleEntry(IServer server, IModule module) {
+ if(module != null && module.getProject() != null) {
+ Set<BundleInfo> bundles = this.getServerBundles(server);
+ BundleInfo bi = this.getBundleByArrtibutesFromSet(bundles, new String[] {"bundleProjectName"}, new Object[] {module.getProject().getName()});
+ if(bi != null) bundles.remove(bi);
+ }
+ }
+ /**
+ * Get bundle info by module info
+ * @param server
+ * @param module
+ * @return
+ */
+ public synchronized BundleInfo getBundleByModule(IServer server, IModule module) {
+ if(module != null && module.getProject() != null) {
+ Set<BundleInfo> bundles = this.getServerBundles(server);
+ return this.getBundleByArrtibutesFromSet(bundles, new String[]{"bundleProjectName"}, new Object[] {module.getProject().getName()});
+ }
+ return null;
+ }
+ /**
+ * Get bundle info by bundle symbolic name and version
+ * @param server
+ * @param symName
+ * @param version
+ * @return
+ */
+ public synchronized BundleInfo getBundleBySymblicNameAndVersion(IServer server, String symName, String version) {
+ Set<BundleInfo> bundles = this.getServerBundles(server);
+ return this.getBundleByArrtibutesFromSet(bundles, new String[]{"bundleSymbolicName", "bundleVersion"},
+ new Object[] {symName, version});
+ }
+ /**
+ * Get bundle info by bundle id
+ * @param server
+ * @param bundleId
+ * @return
+ */
+ public synchronized BundleInfo getBundleById(IServer server, long bundleId) {
+ Set<BundleInfo> bundles = this.getServerBundles(server);
+ return this.getBundleByArrtibutesFromSet(bundles, new String[]{"bundleId"}, new Object[] {bundleId});
+ }
+
+ public synchronized Set<BundleInfo> getServerBundles(IServer server) {
+ if (server == null || !SocketUtil.isLocalhost(server.getHost())) {
+ return null;
+ }
+
+ File runtimeLoc = server.getRuntime().getLocation().toFile();
+ Set<BundleInfo> retSet = this.get(runtimeLoc);
+ if(retSet == null) {
+ retSet = new HashSet<BundleInfo>();
+ this.put(runtimeLoc, retSet);
+ }
+ return retSet;
+ }
+
+ /**
+ *
+ * @param bundles
+ * @param fieldNames
+ * @param values
+ * @return
+ */
+ private BundleInfo getBundleByArrtibutesFromSet(Set<BundleInfo> bundles, String[] fieldNames, Object[] values) {
+ Iterator<BundleInfo> iter = bundles.iterator();
+ try {
+ while(iter.hasNext()) {
+ BundleInfo b = iter.next();
+ boolean fullMatched = true;
+ boolean partialMatched = false;
+ boolean isCompared = false;
+ for(int i=0; i<fieldNames.length; ++i) {
+ isCompared = true;
+ partialMatched = false;
+ Field f = b.getClass().getDeclaredField(fieldNames[i]);
+ f.setAccessible(true);
+ if(f.get(b).equals(values[i])) {
+ partialMatched = true;
+ }
+ fullMatched &= partialMatched;
+ }
+ if(isCompared && fullMatched) return b;
+ }
+ } catch(SecurityException e) {
+ Trace.trace(Trace.ERROR, e.getMessage(), e, Activator.logOsgi);
+ } catch(NoSuchFieldException e) {
+ Trace.trace(Trace.ERROR, e.getMessage(), e, Activator.logOsgi);
+ } catch (IllegalArgumentException e) {
+ Trace.trace(Trace.ERROR, e.getMessage(), e, Activator.logOsgi);
+ } catch (IllegalAccessException e) {
+ Trace.trace(Trace.ERROR, e.getMessage(), e, Activator.logOsgi);
+ }
+ return null;
+ }
+
+ private void addProjectListener() {
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(new IResourceChangeListener() {
+ @Override
+ public void resourceChanged(IResourceChangeEvent event) {
+ if(event.getType() == IResourceChangeEvent.POST_CHANGE) {// just listen to the project's change event
+ try {
+ event.getDelta().accept(new IResourceDeltaVisitor() {
+
+ @Override
+ public boolean visit(IResourceDelta delta) throws CoreException {
+ if(delta.getKind() == IResourceDelta.REMOVED) {
+ return processResourceRemoved(delta.getResource());
+ }
+ else if(delta.getKind() == IResourceDelta.CHANGED) {
+ return true;
+ }
+ return false;
+ }
+
+ private boolean processResourceRemoved(IResource res) {
+ try {
+ if(res instanceof IProject) {
+ IProject p = (IProject) res;
+ String projectName = p.getName();
+ Iterator<Map.Entry<File, Set<BundleInfo>>> iter = OSGIBundleCache.this.entrySet().iterator();
+ while(iter.hasNext()) {
+ Map.Entry<File, Set<BundleInfo>> serverEntry = iter.next();
+ BundleInfo bInfo = OSGIBundleCache.this.getBundleByArrtibutesFromSet(serverEntry.getValue(), new String[] {"bundleProjectName"},
+ new Object[] {projectName});
+ if(bInfo != null) bInfo.setDirty(true);
+
+
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return true;
+ }
+
+ });
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+
+ }
+ }, IResourceChangeEvent.POST_CHANGE);
+ }
+
+ public static class BundleInfo {
+ private String bundleProjectName;
+ private String bundleSymbolicName;
+ private String bundleVersion;
+ private boolean isDirty;
+
+ public BundleInfo(String bundleProjectName, String bundleSymbolicName, String bundleVersion,
+ boolean isDirty) {
+ super();
+ this.bundleProjectName = bundleProjectName;
+ this.bundleSymbolicName = bundleSymbolicName;
+ this.bundleVersion = bundleVersion;
+ this.isDirty = isDirty;
+ }
+
+ public String getBundleProjectName() {
+ return bundleProjectName;
+ }
+ public void setBundleProjectName(String bundleProjectName) {
+ this.bundleProjectName = bundleProjectName;
+ }
+ public String getBundleSymbolicName() {
+ return bundleSymbolicName;
+ }
+ public void setBundleSymbolicName(String bundleSymbolicName) {
+ this.bundleSymbolicName = bundleSymbolicName;
+ }
+ public String getBundleVersion() {
+ return bundleVersion;
+ }
+ public void setBundleVersion(String bundleVersion) {
+ this.bundleVersion = bundleVersion;
+ }
+ public boolean isDirty() {
+ return isDirty;
+ }
+ public void setDirty(boolean isDirty) {
+ this.isDirty = isDirty;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((bundleProjectName == null) ? 0 : bundleProjectName.hashCode());
+ result = prime * result + ((bundleSymbolicName == null) ? 0 : bundleSymbolicName.hashCode());
+ result = prime * result + ((bundleVersion == null) ? 0 : bundleVersion.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ BundleInfo other = (BundleInfo) obj;
+ if (bundleProjectName == null) {
+ if (other.bundleProjectName != null)
+ return false;
+ } else if (!bundleProjectName.equals(other.bundleProjectName))
+ return false;
+ if (bundleSymbolicName == null) {
+ if (other.bundleSymbolicName != null)
+ return false;
+ } else if (!bundleSymbolicName.equals(other.bundleSymbolicName))
+ return false;
+ if (bundleVersion == null) {
+ if (other.bundleVersion != null)
+ return false;
+ } else if (!bundleVersion.equals(other.bundleVersion))
+ return false;
+ return true;
+ }
+
+ }
+}
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGIBundleCache.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGIBundleCache.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGIBundleCache.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGIBundleHelper.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/osgi/OSGIBundleHelper.java?rev=1144570&r1=1144569&r2=1144570&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGIBundleHelper.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGIBundleHelper.java Sat Jul 9 01:38:19 2011
@@ -17,51 +17,63 @@
package org.apache.geronimo.st.v30.core.osgi;
import java.lang.reflect.Method;
+import java.util.Set;
+
+import org.apache.geronimo.deployment.plugin.jmx.RemoteDeploymentManager;
import org.apache.geronimo.st.v30.core.GeronimoUtils;
-import org.apache.geronimo.st.v30.core.ModuleArtifactMapper;
-import org.apache.geronimo.st.v30.core.internal.Messages;
+import org.apache.geronimo.st.v30.core.commands.DeploymentCommandFactory;
import org.eclipse.core.resources.IProject;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
import org.osgi.framework.Version;
public class OSGIBundleHelper {
- public static void addBundleToPublishedMap(IServer server, IModule module, long bundleId) throws Exception {
- if(! GeronimoUtils.isBundleModule(module)) return;
+
+ public static void addBundleToCache(IServer server, IModule module) throws Exception {
+ if(! isBundle(module)) return;
try {
String[] strArray = getBundleSymbolicNameAndVersion(module.getProject());
- ModuleArtifactMapper.getInstance().addBundleEntry(server, module, strArray[0], strArray[1], bundleId);
+ OSGIBundleCache.getInstance().addBundleEntry(server, module, strArray[0], strArray[1]);
} catch (Exception e) {
throw e;
}
}
- public static boolean checkBundleInPublishedMap(IServer server, IModule module) {
- String symName = ModuleArtifactMapper.getInstance().resolveBundleByModule(server, module);
- return symName == null ? false : true;
+
+ public static boolean checkBundleInCache(IServer server, IModule module) {
+ OSGIBundleCache.BundleInfo bundle = OSGIBundleCache.getInstance().getBundleByModule(server, module);
+ return bundle == null ? false : true;
}
- public static void removeBundleFromPublishedMap(IServer server, IModule module) {
- ModuleArtifactMapper.getInstance().removeBundle(server, module);
+ public static void removeBundleFromCache(IServer server, IModule module) {
+ OSGIBundleCache.getInstance().removeBundleEntry(server, module);
}
- public static boolean isBundle(IModule module) {
- return GeronimoUtils.isBundleModule(module);
+ public static boolean isBundle(IModule module) throws Exception {
+ if(module != null && module.getProject() != null) {
+ return isBundle(module.getProject());
+ }
+ return false;
}
+
public static boolean isBundle(IProject project) throws Exception {
boolean ret = false;
if(AriesHelper.isAriesInstalled()) {
Class<?> ariesUtilsClass = Class.forName("com.ibm.etools.aries.internal.core.utils.AriesUtils");
Method method = ariesUtilsClass.getMethod("isOSGIBundle", IProject.class);
ret = (Boolean) method.invoke(null, project);
- } else {
- throw new Exception(Messages.OSGI_ARIES_NOT_INSTALLED);
}
return ret;
}
+ public static Set<OSGIBundleCache.BundleInfo> getSpecificServerBundles(IServer server) {
+ return OSGIBundleCache.getInstance().getServerBundles(server);
+ }
+
public static boolean checkBundleDirty(IServer server, IModule module) {
- return ModuleArtifactMapper.getInstance().checkBundleDirty(server, module);
+ OSGIBundleCache.BundleInfo bInfo = OSGIBundleCache.getInstance().getBundleByModule(server, module);
+ if(bInfo == null) return false;
+ return bInfo.isDirty();
}
public static String[] getBundleSymbolicNameAndVersion(IProject project) throws Exception {
@@ -92,9 +104,21 @@ public class OSGIBundleHelper {
}
- public static long getOSGIBundleId(IServer server, IModule module) {
- return ModuleArtifactMapper.getInstance().getBundleId(server, module);
+ public static long getOSGIBundleIdFromServer(IServer server, IModule module) throws Exception {
+ if(module != null && module.getProject() != null) {
+ RemoteDeploymentManager rDm = (RemoteDeploymentManager)DeploymentCommandFactory.getDeploymentManager(server);
+ OSGIBundleCache.BundleInfo bif = OSGIBundleCache.getInstance().getBundleByModule(server, module);
+
+ return rDm.getBundleId(bif.getBundleSymbolicName(), bif.getBundleVersion());
+ }
+ return -1;
}
+
+ public static long getOSGIBundleIdFromServer(IServer server, OSGIBundleCache.BundleInfo bundleInfo) throws Exception {
+ RemoteDeploymentManager rDm = (RemoteDeploymentManager)DeploymentCommandFactory.getDeploymentManager(server);
+ return rDm.getBundleId(bundleInfo.getBundleSymbolicName(), bundleInfo.getBundleVersion());
+ }
+
public static String getBundleSymbolicNameAndVersionString(IProject project) throws Exception {
String[] strs = getBundleSymbolicNameAndVersion(project);
return strs[0] + ":" + strs[1];
Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OsgiConstants.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/osgi/OsgiConstants.java?rev=1144570&r1=1144569&r2=1144570&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OsgiConstants.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OsgiConstants.java Sat Jul 9 01:38:19 2011
@@ -27,7 +27,6 @@ public final class OsgiConstants {
public final static String BUNDLE_GROUP = "recorded-bundles";
public final static String BUNDLE_EXTENSION = ".jar";
public final static String BUNDLE_DATAMODEL_PROVIDER_ID = "osgi.bundle.datamodelprovider";
- public final static boolean BUNDLE_IS_INPLACE = false;
public final static int BUNDLE_DEFAULT_START_LEVLE = 60;
public final static String FRAGMENT_BUNDLE = "osgi.fragment";