Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

As you can imagine this means that information from your runtime can be used to set up special stuff in the project, such as adding the runtime's project classpath to the project. OK... lets see all that in action

So now we have a server/runtime that we have added, a type of module and a new project and facet that allows a project to be associated with that facet and thus the runtime/server. OK, the final bit we need to think about is how do we make it so that we can add a project to the server (not just associate it with the runtime and publish the project to that server). Now this is still in development, but I'll put up what we have right now so you get the flavour of it all (smile)

You need to implement three extension points, these basically tell WTP that your project can create a deployable artifact that it is based on a project and that it is associated with the jst.jbi.component module type.

Code Block
xml
xml

<extension point="org.eclipse.wst.server.core.moduleFactories">
		<moduleFactory projects="true"
			class="org.eclipse.jst.jbi.internal.deployables.JBIComponentDeployableFactory"
			id="org.eclipse.jst.jbi.deployables.component">
			<moduleType versions="1.0" types="jst.jbi.component"/>
		</moduleFactory>
	</extension>

	<extension
		point="org.eclipse.wst.server.core.moduleArtifactAdapters">
		<moduleArtifactAdapter
			id="org.eclipse.jst.jbi.component"
			class="org.eclipse.jst.jbt.internal.deployables.JBIComponentDeployableObjectAdapter">
			<enablement>
				<with variable="selection">
					<adapt type="org.eclipse.core.resources.IProject" />
				</with>
			</enablement>
		</moduleArtifactAdapter>
	</extension>

	<extension point="org.eclipse.core.runtime.adapters">
		<factory
			class="org.eclipse.jst.jbi.internal.deployables.JBIComponentDeployableObjectAdapter"
			adaptableType="org.eclipse.core.resources.IProject">
			<adapter
				type="org.eclipse.jst.jbi.internal.deployables.IJBIComponentArtifact" />
		</factory>
	</extension>

Lets start by looking at the JBIComponentDeployableFactory, its job is to determine if a project can be deployed, and to create a module delegate that will actually perform the preparation, remember it is actually the server that does the publishing, our JBIComponentDeployable is passed to the publishing part of the server definition (in our case the generic ant task) to publish to the server.

Code Block
java
java

public class JBIComponentDeployable extends ComponentDeployable {

	public JBIComponentDeployable(IProject project, IVirtualComponent component) {
		super(project);
	}

	public String getContextRoot() {
		Properties props = component.getMetaProperties();
		if (props.containsKey("context-root")) //$NON-NLS-1$
			return props.getProperty("context-root"); //$NON-NLS-1$
		return component.getName();
	}

	public String getURI(IModule module) {
		IVirtualComponent comp = ComponentCore.createComponent(module
				.getProject());
		String aURI = null;
		if (comp != null) {
			if (!comp.isBinary()
					&& isProjectOfType(module.getProject(), "jst.jbi.component")) {
				IVirtualReference ref = component.getReference(comp.getName());
				aURI = ref.getRuntimePath().append(
						comp.getName() + "-installer.jar").toString(); //$NON-NLS-1$
			}
		}

		if (aURI != null && aURI.length() > 1 && aURI.startsWith("/")) //$NON-NLS-1$
			aURI = aURI.substring(1);
		return aURI;
	}

	public String getVersion() {
		IFacetedProject facetedProject = null;
		try {
			facetedProject = ProjectFacetsManager
					.create(component.getProject());
			if (facetedProject != null
					&& ProjectFacetsManager.isProjectFacetDefined("jst.jbi.component")) {
				IProjectFacet projectFacet = ProjectFacetsManager
						.getProjectFacet("jst.jbi.component");
				return facetedProject.getInstalledVersion(projectFacet)
						.getVersionString();
			}
		} catch (Exception e) {
			// Ignore
		}
		return "1.0"; //$NON-NLS-1$
	}
}

Note that this document will continue to discuss how the IProject is converted through the adaptable pattern into a JbiComponent in the next few days. In the meantime I'll leave you with a little demonstration of how a deployable projects looks.