Author: snjeza
Date: 2010-04-04 19:10:03 -0400 (Sun, 04 Apr 2010)
New Revision: 21261
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/MANIFEST.MF
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/WTPRuntimeFix.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/PortletRuntimeComponentProvider.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5950 Need additional runtime checks for ESB &
BPEL project examples
Modified: trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/MANIFEST.MF
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/MANIFEST.MF 2010-04-04
22:40:47 UTC (rev 21260)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/MANIFEST.MF 2010-04-04
23:10:03 UTC (rev 21261)
@@ -28,7 +28,8 @@
org.jboss.tools.common,
org.eclipse.equinox.p2.ui,
org.eclipse.equinox.p2.ui.sdk,
- org.eclipse.equinox.p2.metadata
+ org.eclipse.equinox.p2.metadata,
+ org.jboss.tools.portlet.core
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
Export-Package: org.jboss.tools.project.examples,
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/WTPRuntimeFix.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/WTPRuntimeFix.java 2010-04-04
22:40:47 UTC (rev 21260)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/WTPRuntimeFix.java 2010-04-04
23:10:03 UTC (rev 21261)
@@ -1,10 +1,17 @@
package org.jboss.tools.project.examples.fixes;
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.ArrayList;
+import java.util.List;
import java.util.StringTokenizer;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
@@ -12,6 +19,10 @@
import org.eclipse.wst.server.core.IRuntime;
import org.eclipse.wst.server.core.IRuntimeType;
import org.eclipse.wst.server.core.ServerCore;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerConstants;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
+import org.jboss.tools.portlet.core.IPortletConstants;
+import org.jboss.tools.portlet.core.internal.PortletRuntimeComponentProvider;
import org.jboss.tools.project.examples.Messages;
import org.jboss.tools.project.examples.ProjectExamplesActivator;
import org.jboss.tools.project.examples.model.Project;
@@ -19,6 +30,13 @@
public class WTPRuntimeFix implements ProjectExamplesFix {
+ private static final String BPEL = "bpel";
+ private static final String JBOSSESB_SAR = "jbossesb.sar";
+ private static final String JBOSSESB_ESB = "jbossesb.esb";
+ private static final String ESB = "esb";
+ private static final String PORTLET = "portlet";
+ private static final String REQUIRED_COMPONENTS = "required-components";
+
public boolean canFix(Project project, ProjectFix fix) {
if (!ProjectFix.WTP_RUNTIME.equals(fix.getType())) {
return false;
@@ -77,19 +95,90 @@
IRuntime[] runtimes = ServerCore.getRuntimes();
if (runtimes.length > 0
&& ProjectFix.ANY.equals(allowedType)) {
- return runtimes[0];
+ return isComponentPresent(fix, runtimes[0]);
}
for (int i = 0; i < runtimes.length; i++) {
IRuntime runtime = runtimes[i];
IRuntimeType runtimeType = runtime.getRuntimeType();
if (runtimeType.getId().equals(allowedType)) {
- return runtime;
+ return isComponentPresent(fix, runtime);
}
}
}
return null;
}
+ private IRuntime isComponentPresent(ProjectFix fix, IRuntime runtime) {
+ String required_components = fix.getProperties().get(REQUIRED_COMPONENTS);
+ List<String> components = tokenize(required_components);
+ if (components == null) {
+ return runtime;
+ }
+ File location = null;
+ if (runtime != null && runtime.getLocation() != null) {
+ location = runtime.getLocation().toFile();
+ } else {
+ return null;
+ }
+ for (String component:components) {
+ if (PORTLET.equals(component)) {
+ if (!PortletRuntimeComponentProvider.isPortalPresent(location, runtime,
PortletRuntimeComponentProvider.IS_PORTLET_RUNTIME)) {
+ return null;
+ }
+ }
+ if (ESB.equals(component)) {
+ if (!isEsbPresent(location, runtime)) {
+ return null;
+ }
+ }
+ if (BPEL.equals(component)) {
+ if (!isBpelPresent(location, runtime)) {
+ return null;
+ }
+ }
+ return runtime;
+ }
+ return null;
+ }
+
+ private boolean isBpelPresent(File location, IRuntime runtime) {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ private List<String> tokenize(String requiredComponents) {
+ StringTokenizer tokenizer = new StringTokenizer(requiredComponents, ",");
+ List<String> components = new ArrayList<String>();
+ while (tokenizer.hasMoreTokens()) {
+ components.add(tokenizer.nextToken().trim());
+ }
+ return components;
+ }
+
+ public static boolean isEsbPresent(final File location,
+ IRuntime runtime) {
+ IJBossServerRuntime jbossRuntime =
(IJBossServerRuntime)runtime.loadAdapter(IJBossServerRuntime.class, new
NullProgressMonitor());
+ if (jbossRuntime != null) {
+ IPath jbossLocation = runtime.getLocation();
+ IPath configPath =
jbossLocation.append(IJBossServerConstants.SERVER).append(jbossRuntime.getJBossConfiguration());
+ File configFile = configPath.toFile();
+ return exists(configFile, JBOSSESB_ESB) && exists(configFile, JBOSSESB_SAR);
+ }
+ return false;
+ }
+
+ private static boolean exists(final File location,String esbDir) {
+ if (Platform.getOS().equals(Platform.OS_WIN32)) {
+ esbDir = esbDir.replace("/", "\\"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ File deployFile = new File(location,IJBossServerConstants.DEPLOY);
+ if (!deployFile.exists() && !deployFile.isDirectory()) {
+ return false;
+ }
+ File file = new File(deployFile,esbDir);
+ return file.exists();
+ }
+
private static IRuntime getRuntime(
org.eclipse.wst.common.project.facet.core.runtime.IRuntime runtime) {
if (runtime == null)
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java 2010-04-04
22:40:47 UTC (rev 21260)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java 2010-04-04
23:10:03 UTC (rev 21261)
@@ -295,11 +295,9 @@
includedProjects, ","); //$NON-NLS-1$
List<String> projectList = new ArrayList<String>();
while (tokenizer.hasMoreTokens()) {
- projectList.add(tokenizer
- .nextToken());
+ projectList.add(tokenizer.nextToken().trim());
}
- project
- .setIncludedProjects(projectList);
+ project.setIncludedProjects(projectList);
}
}
if (nodeName.equals("welcome")) { //$NON-NLS-1$
Modified:
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/PortletRuntimeComponentProvider.java
===================================================================
---
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/PortletRuntimeComponentProvider.java 2010-04-04
22:40:47 UTC (rev 21260)
+++
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/PortletRuntimeComponentProvider.java 2010-04-04
23:10:03 UTC (rev 21261)
@@ -23,7 +23,7 @@
public class PortletRuntimeComponentProvider extends
RuntimeFacetComponentProviderDelegate {
- private static final String IS_PORTLET_RUNTIME = "isPortletRuntime";
//$NON-NLS-1$
+ public static final String IS_PORTLET_RUNTIME = "isPortletRuntime";
//$NON-NLS-1$
private static final IRuntimeComponentType PORTAL_TYPE = RuntimeManager
.getRuntimeComponentType("org.jboss.tools.portlet.core.runtime.component");
//$NON-NLS-1$