[jbosstools-dev] Re: Deploying a .ds (or any resource)
Max Rydahl Andersen
max.andersen at redhat.com
Wed Aug 8 20:16:12 EDT 2007
>> Here is some example code I've thrown together. The code below should
>> work, except that the publisher is *not* yet ready to handle it.
>> However, the APIs will work.
I tried to do this code and on the way found a couple of NPE's (i've
committed fixes to that)
>> // get a path somehow. you can also use resource. Look at
>> SingleDeployableFactory's static methods
>> IPath p = new Path("/abc/1.txt");
>>
>> // mark this path or resource deployable.
>> SingleDeployableFactory.makeDeployable(p);
>>
>> // get the actual module object from the factory
>> IModule module =
>> SingleDeployableFactory.findModule(p);
until this point works..(had to use a job to make sure the resource
actually exists when running)
>> IServer s = someServer //
>> wherever you get your server from
How do I get the Server/Runtime associated with a given project/wizard ?
without this i'm stumped ;(
here is an eclipse patch that just misses the server finding.
Index:
/home/max/work/os/jbosstools/trunk/seam/plugins/org.jboss.tools.seam.core/META-INF/MANIFEST.MF
===================================================================
---
/home/max/work/os/jbosstools/trunk/seam/plugins/org.jboss.tools.seam.core/META-INF/MANIFEST.MF
(revision 2988)
+++
/home/max/work/os/jbosstools/trunk/seam/plugins/org.jboss.tools.seam.core/META-INF/MANIFEST.MF
(working copy)
@@ -33,7 +33,9 @@
org.eclipse.datatools.connectivity.db.generic.ui,
org.eclipse.datatools.connectivity.ui,
org.eclipse.datatools.connectivity.ui.dse,
- org.eclipse.jst.common.project.facet.core
+ org.eclipse.jst.common.project.facet.core,
+ org.jboss.ide.eclipse.as.core,
+ org.eclipse.wst.server.core
Provide-Package: org.jboss.tools.seam.core,
org.jboss.tools.seam.internal.core,
org.jboss.tools.seam.internal.core.scanner,
Index:
/home/max/work/os/jbosstools/trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/SeamFacetInstallDelegete.java
===================================================================
---
/home/max/work/os/jbosstools/trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/SeamFacetInstallDelegete.java
(revision 2988)
+++
/home/max/work/os/jbosstools/trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/SeamFacetInstallDelegete.java
(working copy)
@@ -20,6 +20,7 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
@@ -33,6 +34,11 @@
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
import org.eclipse.wst.common.project.facet.core.IDelegate;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.model.ServerBehaviourDelegate;
+import
org.jboss.ide.eclipse.as.core.server.stripped.DeployableServerBehavior;
+import
org.jboss.ide.eclipse.as.core.singledeployable.SingleDeployableFactory;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.SeamCorePlugin;
@@ -172,7 +178,7 @@
WebArtifactEdit edit =
WebArtifactEdit.getWebArtifactEditForRead(project);
IVirtualComponent com = ComponentCore.createComponent(project);
IVirtualFolder webRootFolder = com.getRootFolder().getFolder(new
Path("/"));
- IVirtualFolder srcRootFolder = com.getRootFolder().getFolder(new
Path("/WEB-INF/classes"));
+ final IVirtualFolder srcRootFolder =
com.getRootFolder().getFolder(new Path("/WEB-INF/classes"));
IContainer folder = webRootFolder.getUnderlyingFolder();
edit.dispose();
model.setProperty(ISeamFacetDataModelProperties.SEAM_PROJECT_NAME,
project.getName());
@@ -296,6 +302,44 @@
if(model.getProperty(ISeamFacetDataModelProperties.JDBC_DRIVER_JAR_PATH)!=null)
AntCopyUtils.copyFiles((String[])model.getProperty(ISeamFacetDataModelProperties.JDBC_DRIVER_JAR_PATH),
webLibFolder);
+ Job create = new Job("Deploying datasource to server") {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+
+ IServer s = (IServer) project.getAdapter(IServer.class);
+
+ if(s==null) {
+ return new Status(Status.WARNING, SeamCorePlugin.PLUGIN_ID, "No
server selected to deploy datasource to");
+ }
+
+ // convert it to a DeployableServer instance
+ DeployableServerBehavior deployer =
(DeployableServerBehavior) s.loadAdapter(DeployableServerBehavior.class,
null);
+
+ // if its not null, the adaptation worked.
+ if( deployer == null ) {
+ return new Status(Status.WARNING,
SeamCorePlugin.PLUGIN_ID, "Server did not support deploy of datasource.");
+ }
+
+ IContainer underlyingFolder =
srcRootFolder.getUnderlyingFolder();
+
+ IPath projectPath = new
Path("/"+underlyingFolder.getProject().getName());
+ IPath projectRelativePath = underlyingFolder.getProjectRelativePath();
+
+ IPath append =
projectPath.append(projectRelativePath).append(project.getName()+"-ds.xml");
+
+ if(SingleDeployableFactory.makeDeployable(append)) {
+
+ IModule module = SingleDeployableFactory.findModule(append);
+
+ // custom API to deploy / publish only one module.
+ return deployer.publishOneModule(IServer.PUBLISH_FULL, new
IModule[] { module}, ServerBehaviourDelegate.ADDED, monitor);
+ } else {
+ return new Status(Status.WARNING, SeamCorePlugin.PLUGIN_ID,
"Could not deploy datasource " + append);
+ }
+ }
+ };
+ create.setRule(ResourcesPlugin.getWorkspace().getRoot());
+ create.schedule();
} else {
More information about the jbosstools-dev
mailing list