Author: dennyxu
Date: 2008-08-25 22:02:04 -0400 (Mon, 25 Aug 2008)
New Revision: 9888
Added:
workspace/Denny/org.jboss.tools.esb.project/.classpath
workspace/Denny/org.jboss.tools.esb.project/.project
workspace/Denny/org.jboss.tools.esb.project/META-INF/
workspace/Denny/org.jboss.tools.esb.project/META-INF/MANIFEST.MF
workspace/Denny/org.jboss.tools.esb.project/bin/
workspace/Denny/org.jboss.tools.esb.project/build.properties
workspace/Denny/org.jboss.tools.esb.project/plugin.properties
workspace/Denny/org.jboss.tools.esb.project/plugin.xml
workspace/Denny/org.jboss.tools.esb.project/src/
workspace/Denny/org.jboss.tools.esb.project/src/org/
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/JBossWSCorePlugin.java
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/classpath/
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/classpath/JBossRuntime.java
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/classpath/JBossRuntimeClassPathInitializer.java
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/classpath/JBossRuntimeListConverter.java
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/classpath/JBossRuntimeManager.java
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/command/
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/command/JBossClassPathCommand.java
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/command/UninstallJBossClassPathCommand.java
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/facet/
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/facet/IJBossESBFacetDataModelProperties.java
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/facet/JBossESBFacetInstallationConfig.java
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/facet/JBossESBFacetInstallationDelegate.java
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/facet/UnInstallJBossRuntimeDelegate.java
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/messages/
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/messages/JBossFacetCore.properties
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/messages/JBossFacetCoreMessages.java
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/nature/
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/nature/JBossESBProjectNature.java
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/utils/
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/utils/JBossRuntimeCoreUtils.java
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/utils/StatusUtils.java
Log:
esb facet definition
Added: workspace/Denny/org.jboss.tools.esb.project/.classpath
===================================================================
--- workspace/Denny/org.jboss.tools.esb.project/.classpath (rev
0)
+++ workspace/Denny/org.jboss.tools.esb.project/.classpath 2008-08-26 02:02:04 UTC (rev
9888)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: workspace/Denny/org.jboss.tools.esb.project/.project
===================================================================
--- workspace/Denny/org.jboss.tools.esb.project/.project (rev 0)
+++ workspace/Denny/org.jboss.tools.esb.project/.project 2008-08-26 02:02:04 UTC (rev
9888)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.jboss.tools.esb.project</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added: workspace/Denny/org.jboss.tools.esb.project/META-INF/MANIFEST.MF
===================================================================
--- workspace/Denny/org.jboss.tools.esb.project/META-INF/MANIFEST.MF
(rev 0)
+++ workspace/Denny/org.jboss.tools.esb.project/META-INF/MANIFEST.MF 2008-08-26 02:02:04
UTC (rev 9888)
@@ -0,0 +1,32 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %PLUGIN_NAME
+Bundle-SymbolicName: org.jboss.tools.esb.project;singleton:=true
+Bundle-Version: 1.0.0
+Bundle-Localization: plugin
+Bundle-Activator: org.jboss.tools.esb.project.JBossWSCorePlugin
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.wst.common.project.facet.core,
+ org.eclipse.wst.common.frameworks,
+ org.eclipse.core.resources,
+ org.eclipse.jst.ws,
+ org.eclipse.jdt.core,
+ org.eclipse.jdt.launching,
+ org.eclipse.jst.jsf.core,
+ org.eclipse.jst.jsf.ui,
+ org.eclipse.wst.common.modulecore,
+ org.eclipse.jdt.launching,
+ org.eclipse.jst.jsf.core,
+ org.eclipse.jst.jsf.ui,
+ org.eclipse.jdt.launching,
+ org.eclipse.jst.j2ee,
+ org.eclipse.jst.ws.consumption.ui
+Bundle-ActivationPolicy: lazy
+Bundle-Vendor: %PLUGIN_PROVIDER
+Export-Package: org.jboss.tools.esb.project,
+ org.jboss.tools.esb.project.classpath,
+ org.jboss.tools.esb.project.command,
+ org.jboss.tools.esb.project.facet,
+ org.jboss.tools.esb.project.messages,
+ org.jboss.tools.esb.project.utils
Added: workspace/Denny/org.jboss.tools.esb.project/build.properties
===================================================================
--- workspace/Denny/org.jboss.tools.esb.project/build.properties
(rev 0)
+++ workspace/Denny/org.jboss.tools.esb.project/build.properties 2008-08-26 02:02:04 UTC
(rev 9888)
@@ -0,0 +1,6 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ plugin.properties
Added: workspace/Denny/org.jboss.tools.esb.project/plugin.properties
===================================================================
--- workspace/Denny/org.jboss.tools.esb.project/plugin.properties
(rev 0)
+++ workspace/Denny/org.jboss.tools.esb.project/plugin.properties 2008-08-26 02:02:04 UTC
(rev 9888)
@@ -0,0 +1,12 @@
+PLUGIN_NAME=JBossWS Core
+PLUGIN_PROVIDER=Red Hat, Inc.
+
+JBOSSWS_CATOGERY_LABEL=JBoss Web Services
+JBOSSWS_CATOGERY_DISCRIPTION=Enables Web services generation through the JBoss Web
services engine.
+
+JBOSSWS_FACET_CORE_LABEL=JBoss Web Services Core
+JBOSSWS_FACET_CORE_DISCRIPTION=Prepares the project for Web services generation through
the JBoss Web services engine.
+
+
+JBOSSWS_FACET_EXT_LABEL=JBoss Web Services Extensions
+JBOSSWS_FACET_EXT_DISCRIPTION=Prepares the project for additional Web services support
with the JBoss Web services runtime.
\ No newline at end of file
Added: workspace/Denny/org.jboss.tools.esb.project/plugin.xml
===================================================================
--- workspace/Denny/org.jboss.tools.esb.project/plugin.xml (rev
0)
+++ workspace/Denny/org.jboss.tools.esb.project/plugin.xml 2008-08-26 02:02:04 UTC (rev
9888)
@@ -0,0 +1,104 @@
+<plugin>
+ <extension
+ point="org.eclipse.wst.common.project.facet.core.facets">
+ <project-facet
+ id="jboss.esb">
+ <label>
+ JBoss ESB
+ </label>
+ </project-facet>
+ <project-facet-version
+ facet="jboss.esb"
+ version="4.2">
+ <action
+ facet="jboss.esb"
+ type="install"
+ version="4.2">
+ <delegate
+
class="org.jboss.tools.esb.project.facet.JBossESBFacetInstallationDelegate">
+ </delegate>
+ <config-factory
+
class="org.jboss.tools.esb.project.facet.JBossESBFacetInstallationConfig">
+ </config-factory>
+ </action>
+ </project-facet-version>
+ <project-facet-version
+ facet="jboss.esb"
+ version="4.3">
+ <action
+ facet="jboss.esb"
+ id="jboss.esb.install"
+ type="install"
+ version="4.3">
+ <delegate
+
class="org.jboss.tools.esb.project.facet.JBossESBFacetInstallationDelegate">
+ </delegate>
+ <config-factory
+
class="org.jboss.tools.esb.project.facet.JBossESBFacetInstallationConfig">
+ </config-factory>
+ </action>
+ </project-facet-version>
+ <template
+ id="template.jboss.esb">
+ <label>
+ label body text
+ </label>
+ <fixed
+ facet="jboss.esb">
+ </fixed>
+ <fixed
+ facet="jst.java">
+ </fixed>
+ </template>
+ </extension>
+ <extension
+ id="ESBNature"
+ name="JBoss ESB Nature"
+ point="org.eclipse.core.resources.natures">
+ <runtime>
+ <run
+
class="org.jboss.tools.esb.projects.nature.JBossESBProjectNature">
+ </run>
+ </runtime>
+ <requires-nature
+ id="org.eclipse.wst.common.project.facet.core.nature">
+ </requires-nature>
+ </extension>
+ <extension
+ point="org.eclipse.ui.ide.projectNatureImages">
+ <image
+ icon="esbproject.image3"
+ id="org.jboss.esb.project.esbnature.image"
+ natureId="org.jboss.esb.project.esbnature">
+ </image>
+ </extension>
+ <extension
+ point="org.eclipse.wst.server.core.moduleTypes">
+ <moduleType
+ id="jboss.esb"
+ name="JBoss ESB Module">
+ </moduleType>
+ </extension>
+ <extension
+ point="org.eclipse.wst.common.project.facet.core.runtimes">
+ <supported>
+ <facet
+ id="jboss.esb"
+ version="4.2,4.3">
+ </facet>
+ <runtime-component
+ id="org.jboss.ide.eclipse.as.runtime.component"
+ version="4.2">
+ </runtime-component>
+ </supported>
+ </extension>
+ <extension
+ point="org.eclipse.jdt.core.classpathContainerInitializer">
+ <classpathContainerInitializer
+
class="org.jboss.tools.esb.project.classpath.JBossRuntimeClassPathInitializer"
+ id="JBoss_ESB_Runtime">
+ </classpathContainerInitializer>
+ </extension>
+
+
+</plugin>
Added:
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/JBossWSCorePlugin.java
===================================================================
---
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/JBossWSCorePlugin.java
(rev 0)
+++
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/JBossWSCorePlugin.java 2008-08-26
02:02:04 UTC (rev 9888)
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+
+package org.jboss.tools.esb.project;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class JBossWSCorePlugin extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.jboss.tools.ws.core";
+
+ // The shared instance
+ private static JBossWSCorePlugin plugin;
+
+ /**
+ * The constructor
+ */
+ public JBossWSCorePlugin() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static JBossWSCorePlugin getDefault() {
+ return plugin;
+ }
+
+}
Added:
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/classpath/JBossRuntime.java
===================================================================
---
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/classpath/JBossRuntime.java
(rev 0)
+++
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/classpath/JBossRuntime.java 2008-08-26
02:02:04 UTC (rev 9888)
@@ -0,0 +1,123 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.esb.project.classpath;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Grid Qian
+ */
+public class JBossRuntime {
+
+ String name = null;
+
+ String homeDir = null;
+
+ String version = null;
+
+ boolean defaultRt = false;
+
+ List<String> libraries;
+
+ private boolean userConfigClasspath;
+
+ /**
+ * Default constructor
+ */
+ public JBossRuntime() {
+ libraries = new ArrayList<String>();
+ }
+
+ /**
+ * Get JBossWSRuntime name
+ *
+ * @return name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Get path to home directory
+ *
+ * @return home directory path as string
+ */
+ public String getHomeDir() {
+ return homeDir;
+ }
+
+ /**
+ * Set JBossWSRuntime name
+ *
+ * @param name
+ * new JBossWSRuntime name
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Set home directory
+ *
+ * @param homeDir
+ * new JBossWSRuntime's home directory
+ */
+ public void setHomeDir(String homeDir) {
+ this.homeDir = homeDir;
+ }
+
+ /**
+ * Mark runtime as default
+ *
+ * @param b
+ * new value for default property
+ */
+ public void setDefault(boolean b) {
+ this.defaultRt = b;
+ }
+
+ /**
+ * Get default flag
+ *
+ * @return default property
+ */
+ public boolean isDefault() {
+ return defaultRt;
+ }
+
+ public List<String> getLibraries(){
+
+ return this.libraries;
+ }
+
+ public void setLibraries(List<String> libraries){
+ this.libraries = libraries;
+ }
+
+ public boolean isUserConfigClasspath(){
+ return this.userConfigClasspath;
+ }
+
+ public void setUserConfigClasspath(boolean userConfigClasspath){
+ this.userConfigClasspath = userConfigClasspath;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+}
Added:
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/classpath/JBossRuntimeClassPathInitializer.java
===================================================================
---
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/classpath/JBossRuntimeClassPathInitializer.java
(rev 0)
+++
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/classpath/JBossRuntimeClassPathInitializer.java 2008-08-26
02:02:04 UTC (rev 9888)
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.esb.project.classpath;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.ClasspathContainerInitializer;
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.launching.JavaRuntime;
+import org.jboss.tools.esb.project.messages.JBossFacetCoreMessages;
+
+/**
+ * @author Grid Qian
+ */
+public class JBossRuntimeClassPathInitializer extends
+ ClasspathContainerInitializer {
+
+ public JBossRuntimeClassPathInitializer() {
+ }
+
+ private String segment;
+
+ @Override
+ public void initialize(IPath containerPath, IJavaProject project)
+ throws CoreException {
+
+ if (containerPath.segment(0).equals(
+ JBossFacetCoreMessages.JBossWS_Runtime_Lib)) {
+ JBossWSRuntimeClasspathContainer container = new JBossWSRuntimeClasspathContainer(
+ containerPath);
+ segment = containerPath.segment(1);
+ JavaCore.setClasspathContainer(containerPath,
+ new IJavaProject[] { project },
+ new IClasspathContainer[] { container }, null);
+ }
+ }
+
+ public IClasspathEntry[] getEntries(IPath path) {
+ return new JBossWSRuntimeClasspathContainer(path).getClasspathEntries();
+ }
+
+ public class JBossWSRuntimeClasspathContainer implements
+ IClasspathContainer {
+ private IPath path;
+ private IClasspathEntry[] entries = null;
+
+ public JBossWSRuntimeClasspathContainer(IPath path) {
+ this.path = path;
+ }
+
+ public String getDescription() {
+ return JBossFacetCoreMessages.JBossWS_Runtime;
+ }
+
+ public int getKind() {
+ return IClasspathContainer.K_APPLICATION;
+ }
+
+ public IPath getPath() {
+ return path;
+ }
+
+ public IClasspathEntry[] getClasspathEntries() {
+ if (entries == null) {
+ ArrayList<IClasspathEntry> entryList = new ArrayList<IClasspathEntry>();
+ JBossRuntime jbws = JBossRuntimeManager.getInstance()
+ .findRuntimeByName(segment);
+ if (jbws != null) {
+
+ List<String> jars =
JBossRuntimeManager.getInstance().getAllRuntimeJars(jbws);
+ for (String jar : jars) {
+ entryList.add(getEntry(new Path(jar)));
+ }
+ entries = entryList.toArray(new IClasspathEntry[entryList.size()]);
+ if (entries == null)
+ return new IClasspathEntry[0];
+ }
+ }
+ return entries;
+ }
+
+ protected IClasspathEntry getEntry(IPath path) {
+ return JavaRuntime.newArchiveRuntimeClasspathEntry(path)
+ .getClasspathEntry();
+ }
+
+ public void removeEntry(String jarName) {
+ if (entries == null) {
+ return;
+ }
+ IClasspathEntry[] newEntries = new IClasspathEntry[entries.length - 1];
+ int i = 0;
+ for (IClasspathEntry entry : entries) {
+ if (!entry.toString().contains(jarName)) {
+ newEntries[i++] = entry;
+ }
+ }
+ entries = newEntries;
+ }
+
+ }
+
+ public boolean filterJars(String jarName, ArrayList<IClasspathEntry> list) {
+ for (IClasspathEntry entry : list) {
+ if (entry.getPath().lastSegment().equals(jarName)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+}
Added:
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/classpath/JBossRuntimeListConverter.java
===================================================================
---
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/classpath/JBossRuntimeListConverter.java
(rev 0)
+++
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/classpath/JBossRuntimeListConverter.java 2008-08-26
02:02:04 UTC (rev 9888)
@@ -0,0 +1,141 @@
+package org.jboss.tools.esb.project.classpath;
+
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+
+/**
+ *
+ * @author Grid Qian
+ *
+ */
+public class JBossRuntimeListConverter {
+
+ /*
+ * Constants definitions
+ */
+ private static final String REGEXP_ESCAPE = "\\";
+ private static final String COMMA = ",";
+ private static final String LIBRARY_SEPARATOR = ";";
+ private static final String EMPTY_STRING = "";
+ private static final String FIELD_SEPARATOR = "|";
+ private static final String DEFAULT = "default";
+ private static final String HOME_DIR = "homeDir";
+ private static final String VERSION = "version";
+ private static final String NAME = "name";
+ private static final String USER_CONFIG_CLASSPATH = "userConfig";
+ private static final String LIBRARY = "libraries";
+
+ /**
+ * Load String to JBossWSRuntime map from String
+ * @param input
+ * String representation of map
+ * @return
+ * Map<String, JBossWSRuntime> loaded from string
+ * TODO - switch to XML?
+ * TODO - write converter from old serialization format to XML?
+ * TODO - handle errors in string format
+ */
+ public Map<String, JBossRuntime> getMap(String input) {
+
+ Map<String, JBossRuntime> result = new HashMap<String, JBossRuntime>();
+ if (input == null || EMPTY_STRING.equals(input.trim())) {
+ return result;
+ }
+ StringTokenizer runtimes = new StringTokenizer(input, COMMA);
+ while (runtimes.hasMoreTokens()) {
+ String runtime = runtimes.nextToken();
+ String[] map = runtime.split(REGEXP_ESCAPE + FIELD_SEPARATOR);
+ JBossRuntime rt = new JBossRuntime();
+ final int step = 2;
+ for (int i = 0; i < map.length; i += step) {
+ String name = map[i];
+ String value = i + 1 < map.length ? map[i + 1] : EMPTY_STRING;
+ if (NAME.equals(name)) {
+ rt.setName(value);
+ } else if (HOME_DIR.equals(name)) {
+ rt.setHomeDir(value);
+ } else if (VERSION.equals(name)) {
+ rt.setVersion(value);
+ } else if (DEFAULT.equals(name)) {
+ rt.setDefault(Boolean.parseBoolean(value));
+ }else if(USER_CONFIG_CLASSPATH.equals(name)){
+ rt.setUserConfigClasspath(Boolean.parseBoolean(value));
+ }else if(LIBRARY.equals(name)){
+ if(value != null && !EMPTY_STRING.equals(value)){
+ rt.setLibraries(getLibrariesFromString(value));
+ }
+ }
+
+ }
+ result.put(rt.getName(), rt);
+ }
+
+ return result;
+ }
+
+ private List<String> getLibrariesFromString(String strLibraries){
+ List<String> libraries = new ArrayList<String>();
+ StringTokenizer st = new StringTokenizer(strLibraries, LIBRARY_SEPARATOR);
+ while(st.hasMoreTokens()){
+ String library = st.nextToken();
+ if(!libraries.contains(library)){
+ libraries.add(library);
+ }
+ }
+ return libraries;
+
+ }
+
+ private String convertListToString(List<String> libraries){
+ String strLib = "";
+ for(String library: libraries){
+ if("".equals(strLib)){
+ strLib = library;
+ }else{
+ strLib = strLib + LIBRARY_SEPARATOR + library;
+ }
+ }
+ return strLib;
+ }
+
+ /**
+ * Convert map String to JBossWSRUntime to string representation
+ * @param runtimeMap
+ * Map<String, JBossWSRuntime> - map of String to JBossWS Runtime to
convert
+ * in String
+ * @return
+ * String representation of String to JBossWS Runtime map
+ */
+ public String getString(Map<String, JBossRuntime> runtimeMap) {
+ StringBuffer buffer = new StringBuffer();
+ JBossRuntime[] runtimes = runtimeMap.values().toArray(
+ new JBossRuntime[runtimeMap.size()]);
+ for (int i = 0; i < runtimes.length; i++) {
+ buffer.append(NAME).append(FIELD_SEPARATOR);
+ buffer.append(runtimes[i].getName());
+ buffer.append(FIELD_SEPARATOR).append(VERSION).append(
+ FIELD_SEPARATOR);
+ buffer.append(runtimes[i].getVersion());
+ buffer.append(FIELD_SEPARATOR).append(HOME_DIR).append(
+ FIELD_SEPARATOR);
+ buffer.append(runtimes[i].getHomeDir());
+ buffer.append(FIELD_SEPARATOR).append(DEFAULT).append(
+ FIELD_SEPARATOR);
+ buffer.append(runtimes[i].isDefault());
+ buffer.append(FIELD_SEPARATOR).append(USER_CONFIG_CLASSPATH).append(FIELD_SEPARATOR);
+ buffer.append(runtimes[i].isUserConfigClasspath());
+ buffer.append(FIELD_SEPARATOR).append(LIBRARY).append(FIELD_SEPARATOR);
+ buffer.append(convertListToString(runtimes[i].getLibraries()));
+ if (i != runtimes.length - 1) {
+ buffer.append(COMMA);
+ }
+ }
+ return buffer.toString();
+ }
+ }
+
Added:
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/classpath/JBossRuntimeManager.java
===================================================================
---
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/classpath/JBossRuntimeManager.java
(rev 0)
+++
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/classpath/JBossRuntimeManager.java 2008-08-26
02:02:04 UTC (rev 9888)
@@ -0,0 +1,359 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.esb.project.classpath;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.jface.preference.IPersistentPreferenceStore;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.IProjectFacet;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+import org.jboss.tools.esb.project.JBossWSCorePlugin;
+import org.jboss.tools.esb.project.facet.IJBossESBFacetDataModelProperties;
+import org.jboss.tools.esb.project.messages.JBossFacetCoreMessages;
+
+/**
+ * @author Grid Qian
+ */
+public class JBossRuntimeManager {
+
+ private static JBossRuntimeListConverter converter = new JBossRuntimeListConverter();
+
+ private Map<String, JBossRuntime> runtimes = new HashMap<String,
JBossRuntime>();
+
+ /**
+ * Private constructor
+ */
+ private JBossRuntimeManager() {
+ load();
+ }
+
+ /**
+ * This class make Java Runtime responsible for solving synchronization
+ * problems during initialization if there is any
+ *
+ */
+ static class JBossRuntimeManagerHolder {
+ private static final JBossRuntimeManager INSTANCE = new JBossRuntimeManager();
+ }
+
+ /**
+ * Return JBossWSRuntimeManaher instance
+ *
+ * @return JBossWSRuntimeManager instance
+ */
+ public static JBossRuntimeManager getInstance() {
+ return JBossRuntimeManagerHolder.INSTANCE;
+ }
+
+ /**
+ * Return Array of configured JBossWSRuntimes
+ *
+ * @return JBossWSRuntime[]
+ */
+ public JBossRuntime[] getRuntimes() {
+ Collection<JBossRuntime> c = runtimes.values();
+ return c.toArray(new JBossRuntime[runtimes.size()]);
+ }
+
+ /**
+ * Add new JBossWSRuntime
+ *
+ * @param runtime
+ * JBossWSRuntime
+ */
+ public void addRuntime(JBossRuntime runtime) {
+ if (runtimes.size() == 0) {
+ runtime.setDefault(true);
+ }
+
+ JBossRuntime oldDefaultRuntime = getDefaultRuntime();
+ if (oldDefaultRuntime != null && runtime.isDefault()) {
+ oldDefaultRuntime.setDefault(false);
+ }
+ runtimes.put(runtime.getName(), runtime);
+ save();
+ }
+
+ /**
+ * Add new JBossWSRuntime with given parameters
+ *
+ * @param name
+ * String - runtime name
+ * @param path
+ * String - runtime home folder
+ * @param version
+ * String - string representation of version number
+ * @param defaultRt
+ * boolean - default flag
+ */
+ public void addRuntime(String name, String path, String version,
+ boolean defaultRt) {
+ JBossRuntime jbossWSRt = new JBossRuntime();
+ jbossWSRt.setHomeDir(path);
+ jbossWSRt.setName(name);
+ jbossWSRt.setVersion(version);
+ jbossWSRt.setDefault(defaultRt);
+ addRuntime(jbossWSRt);
+ }
+
+ /**
+ * Return JBossWSRuntime by given name
+ *
+ * @param name
+ * String - JBossWSRuntime name
+ * @return JBossWSRuntime - found JBossWSRuntime instance or null
+ */
+ public JBossRuntime findRuntimeByName(String name) {
+ for (JBossRuntime jbossWSRuntime : runtimes.values()) {
+ if (jbossWSRuntime.getName().equals(name)) {
+ return jbossWSRuntime;
+ }
+ }
+ return null;
+ }
+
+ public List<String> getAllRuntimeJars(JBossRuntime rt){
+ List<String> jarList = new ArrayList<String>();
+ if (rt != null) {
+ if (rt.isUserConfigClasspath()) {
+ jarList.addAll(rt.getLibraries());
+
+ } else {
+ IPath wsPath = new Path(rt.getHomeDir());
+ if (wsPath != null) {
+ IPath libPath = wsPath
+ .append(JBossFacetCoreMessages.Dir_Lib);
+ List<File> libs = getJarsOfFolder(libPath.toFile());
+ libPath = wsPath
+ .append(JBossFacetCoreMessages.Dir_Client);
+ List<File> clientJars = getJarsOfFolder(libPath.toFile());
+
+ jarList = mergeTwoList(libs, clientJars);
+ }
+ }
+
+ }
+ return jarList;
+ }
+
+
+
+ private List<File> getJarsOfFolder(File folder){
+ List<File> jars = new ArrayList<File>();
+ if(folder.isDirectory()){
+ for(File file: folder.listFiles()){
+ if(file.isFile() && (file.getName().endsWith(".jar") ||
file.getName().endsWith(".zip"))){
+ jars.add(file);
+ }else if (folder.isDirectory()){
+ jars.addAll(getJarsOfFolder(file));
+ }
+ }
+ }
+
+ return jars;
+ }
+
+ // if two folders have the same jar file, one of them will be ignored.
+ private List<String> mergeTwoList(List<File> jarList1, List<File>
jarList2){
+ List<String> rtList = new ArrayList<String>();
+ List<String> distinctFileNames = new ArrayList<String>();
+
+ for(File jarFile: jarList1){
+ distinctFileNames.add(jarFile.getName());
+ rtList.add(jarFile.getAbsolutePath());
+ }
+ for(File jarFile: jarList2){
+ if(!distinctFileNames.contains(jarFile.getName())){
+ rtList.add(jarFile.getAbsolutePath());
+ }
+ }
+
+ return rtList;
+
+ }
+
+ /**
+ * Remove given JBossWSRuntime from manager
+ *
+ * @param rt
+ * JBossWSRuntime
+ */
+ public void removeRuntime(JBossRuntime rt) {
+ runtimes.remove(rt.getName());
+ }
+
+ /**
+ * Save preference value and force save changes to disk
+ */
+ public void save() {
+ JBossWSCorePlugin.getDefault().getPreferenceStore().setValue(
+ JBossFacetCoreMessages.WS_Location, converter.getString(runtimes));
+ IPreferenceStore store = JBossWSCorePlugin.getDefault()
+ .getPreferenceStore();
+ if (store instanceof IPersistentPreferenceStore) {
+ try {
+ ((IPersistentPreferenceStore) store).save();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * Marks this runtime as default. Marks other runtimes with the same version
+ * as not default.
+ *
+ * @param runtime
+ */
+ public void setDefaultRuntime(JBossRuntime runtime) {
+ JBossRuntime[] runtimes = getRuntimes();
+ for (int i = 0; i < runtimes.length; i++) {
+ runtimes[i].setDefault(false);
+ }
+ runtime.setDefault(true);
+ }
+
+ /**
+ * Return first default JBossWSRuntime
+ *
+ * @return JBossWSRuntime
+ */
+ public JBossRuntime getDefaultRuntime() {
+ for (JBossRuntime rt : runtimes.values()) {
+ if (rt.isDefault()) {
+ return rt;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return list of available JBossWSRuntime names
+ *
+ * @return List<String>
+ */
+ public List<String> getRuntimeNames() {
+ JBossRuntime[] rts = getRuntimes();
+ List<String> result = new ArrayList<String>();
+ for (JBossRuntime jbossWSRuntime : rts) {
+ result.add(jbossWSRuntime.getName());
+ }
+ return result;
+ }
+
+ /**
+ * Return a list of all runtime names
+ *
+ * @return List of all runtime names
+ */
+ public List<String> getAllRuntimeNames() {
+ JBossRuntime[] rts = getRuntimes();
+ List<String> result = new ArrayList<String>();
+ for (JBossRuntime jbossWSRuntime : rts) {
+ result.add(jbossWSRuntime.getName());
+ }
+ return result;
+ }
+
+ /**
+ * TBD
+ *
+ * @param oldName
+ * old runtime name
+ * @param newName
+ * new runtime name
+ */
+ public void changeRuntimeName(String oldName, String newName) {
+ JBossRuntime o = findRuntimeByName(oldName);
+ if (o == null) {
+ return;
+ }
+ o.setName(newName);
+ onRuntimeNameChanged(oldName, newName);
+ }
+
+ private void onRuntimeNameChanged(String oldName, String newName) {
+ IProjectFacet facet = ProjectFacetsManager
+ .getProjectFacet("jbossws.core");
+ Set<IFacetedProject> facetedProjects = null;
+ try {
+ facetedProjects = ProjectFacetsManager.getFacetedProjects(facet);
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ for (IFacetedProject facetedProject : facetedProjects) {
+ QualifiedName qRuntimeName =
IJBossESBFacetDataModelProperties.PERSISTENCE_PROPERTY_QNAME_RUNTIME_NAME;
+ String name = null;
+ try {
+ name = facetedProject.getProject().getPersistentProperty(
+ qRuntimeName);
+ if (name != null && name.equals(oldName)) {
+ facetedProject.getProject().setPersistentProperty(
+ qRuntimeName, newName);
+ }
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+ }
+
+ public static boolean isRuntimeUsed(String name) {
+ IProjectFacet facet = ProjectFacetsManager
+ .getProjectFacet("jbossws.core");
+ Set<IFacetedProject> facetedProjects = null;
+ try {
+ facetedProjects = ProjectFacetsManager.getFacetedProjects(facet);
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ for (IFacetedProject facetedProject : facetedProjects) {
+ QualifiedName qRuntimeName =
IJBossESBFacetDataModelProperties.PERSISTENCE_PROPERTY_QNAME_RUNTIME_NAME;
+ try {
+ if (name.equals(facetedProject.getProject()
+ .getPersistentProperty(qRuntimeName))) {
+ return true;
+ }
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+ return false;
+ }
+
+ public void load() {
+ IPreferenceStore ps = JBossWSCorePlugin.getDefault()
+ .getPreferenceStore();
+
+ String runtimeListString = ps
+ .getString(JBossFacetCoreMessages.WS_Location);
+
+ runtimes = converter.getMap(runtimeListString);
+ }
+
+}
\ No newline at end of file
Added:
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/command/JBossClassPathCommand.java
===================================================================
---
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/command/JBossClassPathCommand.java
(rev 0)
+++
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/command/JBossClassPathCommand.java 2008-08-26
02:02:04 UTC (rev 9888)
@@ -0,0 +1,151 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.esb.project.command;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.core.IClasspathAttribute;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jst.j2ee.classpathdep.ClasspathDependencyUtil;
+import org.eclipse.jst.j2ee.classpathdep.IClasspathDependencyConstants;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.jboss.tools.esb.project.facet.IJBossESBFacetDataModelProperties;
+import org.jboss.tools.esb.project.messages.JBossFacetCoreMessages;
+import org.jboss.tools.esb.project.utils.StatusUtils;
+
+/**
+ * @author Grid Qian
+ */
+public class JBossClassPathCommand extends AbstractDataModelOperation {
+
+ IProject project;
+ private IDataModel model;
+
+ public JBossClassPathCommand(IProject project, IDataModel model) {
+ this.project = project;
+ this.model = model;
+ }
+
+ public IStatus execute(IProgressMonitor monitor, IAdaptable info)
+ throws ExecutionException {
+ return executeOverride(monitor);
+ }
+
+ public IStatus executeOverride(IProgressMonitor monitor) {
+ IStatus status = Status.OK_STATUS;
+ try {
+ boolean isServerSupplied = model
+ .getBooleanProperty(IJBossESBFacetDataModelProperties.RUNTIME_IS_SERVER_SUPPLIED);
+ if (isServerSupplied) {
+ project
+ .setPersistentProperty(
+ IJBossESBFacetDataModelProperties.PERSISTENCE_PROPERTY_SERVER_SUPPLIED_RUNTIME,
+ IJBossESBFacetDataModelProperties.DEFAULT_VALUE_IS_SERVER_SUPPLIED);
+ } else {
+ // store runtime name and runtime location to the project
+
+ String runtimeName = model
+ .getStringProperty(IJBossESBFacetDataModelProperties.RUNTIME_ID);
+ String runtimeLocation = model
+ .getStringProperty(IJBossESBFacetDataModelProperties.RUNTIME_HOME);
+ project
+ .setPersistentProperty(
+ IJBossESBFacetDataModelProperties.PERSISTENCE_PROPERTY_QNAME_RUNTIME_NAME,
+ runtimeName);
+ project
+ .setPersistentProperty(
+ IJBossESBFacetDataModelProperties.PERSISTENCE_PROPERTY_RNTIME_LOCATION,
+ runtimeLocation);
+ boolean isDeployed = model
+ .getBooleanProperty(IJBossESBFacetDataModelProperties.RUNTIME_DEPLOY);
+
+ status = addClassPath(project, runtimeName, isDeployed);
+ }
+
+ } catch (CoreException e) {
+ status = StatusUtils.errorStatus(
+ JBossFacetCoreMessages.Error_Add_Facet_JBossWS, e);
+ }
+ return status;
+ }
+
+ public IStatus addClassPath(IProject project, String segment,
+ boolean isDeployed) {
+ IStatus status = Status.OK_STATUS;
+ try {
+
+ IClasspathEntry newClasspath;
+ IJavaProject javaProject = JavaCore.create(project);
+
+ if (isDeployed) {
+ IClasspathAttribute depAttrib = JavaCore
+ .newClasspathAttribute(
+ IClasspathDependencyConstants.CLASSPATH_COMPONENT_DEPENDENCY,
+ ClasspathDependencyUtil.getDefaultRuntimePath(
+ true).toString());
+ newClasspath = JavaCore.newContainerEntry(new Path(
+ JBossFacetCoreMessages.JBossWS_Runtime_Lib)
+ .append(segment), null,
+ new IClasspathAttribute[] { depAttrib }, true);
+ } else {
+ newClasspath = JavaCore.newContainerEntry(new Path(
+ JBossFacetCoreMessages.JBossWS_Runtime_Lib)
+ .append(segment));
+ }
+
+ IClasspathEntry[] oldClasspathEntries = javaProject
+ .readRawClasspath();
+
+ boolean isFolderInClassPathAlready = false;
+ for (int i = 0; i < oldClasspathEntries.length
+ && !isFolderInClassPathAlready; i++) {
+ if (oldClasspathEntries[i].getPath().equals(
+ newClasspath.getPath())) {
+ isFolderInClassPathAlready = true;
+ break;
+ }
+ }
+
+ if (!isFolderInClassPathAlready) {
+
+ IClasspathEntry[] newClasspathEntries = new
IClasspathEntry[oldClasspathEntries.length + 1];
+ for (int i = 0; i < oldClasspathEntries.length; i++) {
+ newClasspathEntries[i] = oldClasspathEntries[i];
+ }
+ newClasspathEntries[oldClasspathEntries.length] = newClasspath;
+
+ javaProject.setRawClasspath(newClasspathEntries,
+ new NullProgressMonitor());
+ }
+ } catch (JavaModelException e) {
+ status = StatusUtils.errorStatus(NLS.bind(
+ JBossFacetCoreMessages.Error_Copy, new String[] { e
+ .getLocalizedMessage() }), e);
+ return status;
+ }
+
+ return status;
+ }
+
+}
\ No newline at end of file
Added:
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/command/UninstallJBossClassPathCommand.java
===================================================================
---
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/command/UninstallJBossClassPathCommand.java
(rev 0)
+++
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/command/UninstallJBossClassPathCommand.java 2008-08-26
02:02:04 UTC (rev 9888)
@@ -0,0 +1,102 @@
+package org.jboss.tools.esb.project.command;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.jboss.tools.esb.project.facet.IJBossESBFacetDataModelProperties;
+import org.jboss.tools.esb.project.messages.JBossFacetCoreMessages;
+import org.jboss.tools.esb.project.utils.StatusUtils;
+
+public class UninstallJBossClassPathCommand {
+ IProject project;
+
+ public UninstallJBossClassPathCommand(IProject project, IDataModel model) {
+ this.project = project;
+ }
+
+ public IStatus execute(IProgressMonitor monitor, IAdaptable info)
+ throws ExecutionException {
+ return executeOverride(monitor);
+ }
+
+ public IStatus executeOverride(IProgressMonitor monitor) {
+ IStatus status = Status.OK_STATUS;
+ try {
+ boolean isServerSupplied = Boolean
+ .getBoolean(project
+ .getPersistentProperty(IJBossESBFacetDataModelProperties.PERSISTENCE_PROPERTY_SERVER_SUPPLIED_RUNTIME));
+ if (isServerSupplied) {
+// project
+// .getPersistentProperties()
+// .remove(
+// IJBossWSFacetDataModelProperties.PERSISTENCE_PROPERTY_SERVER_SUPPLIED_RUNTIME);
+ } else {
+// project
+// .getPersistentProperties()
+// .remove(
+// IJBossWSFacetDataModelProperties.PERSISTENCE_PROPERTY_QNAME_RUNTIME_NAME);
+// project
+// .getPersistentProperties()
+// .remove(
+// IJBossWSFacetDataModelProperties.PERSISTENCE_PROPERTY_RNTIME_LOCATION);
+ String runtimeName = project
+ .getPersistentProperty(IJBossESBFacetDataModelProperties.PERSISTENCE_PROPERTY_QNAME_RUNTIME_NAME);
+
+ status = removeClassPath(project, runtimeName);
+ }
+
+ } catch (CoreException e) {
+ status = StatusUtils.errorStatus(
+ JBossFacetCoreMessages.Error_Remove_Facet_JBossWS, e);
+ }
+ return status;
+ }
+
+ public IStatus removeClassPath(IProject project, String segment) {
+ IStatus status = Status.OK_STATUS;
+ try {
+ IJavaProject javaProject = JavaCore.create(project);
+ IClasspathEntry[] oldClasspathEntries = javaProject
+ .readRawClasspath();
+
+ boolean isFolderInClassPathAlready = false;
+ List<IClasspathEntry> classpathEntries = new
ArrayList<IClasspathEntry>();
+ for (int i = 0; i < oldClasspathEntries.length
+ && !isFolderInClassPathAlready; i++) {
+ if (!oldClasspathEntries[i].getPath().equals(
+ new Path(JBossFacetCoreMessages.JBossWS_Runtime_Lib)
+ .append(segment))) {
+ classpathEntries.add(oldClasspathEntries[i]);
+ }
+ }
+ if (classpathEntries.size() < oldClasspathEntries.length) {
+ javaProject.setRawClasspath(classpathEntries
+ .toArray(new IClasspathEntry[classpathEntries.size()]),
+ new NullProgressMonitor());
+ }
+ } catch (JavaModelException e) {
+ status = StatusUtils.errorStatus(NLS.bind(
+ JBossFacetCoreMessages.Error_Remove_Facet_JBossWS,
+ new String[] { e.getLocalizedMessage() }), e);
+ return status;
+ }
+
+ return status;
+ }
+
+}
Added:
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/facet/IJBossESBFacetDataModelProperties.java
===================================================================
---
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/facet/IJBossESBFacetDataModelProperties.java
(rev 0)
+++
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/facet/IJBossESBFacetDataModelProperties.java 2008-08-26
02:02:04 UTC (rev 9888)
@@ -0,0 +1,37 @@
+package org.jboss.tools.esb.project.facet;
+
+import org.eclipse.core.runtime.QualifiedName;
+import
org.eclipse.wst.common.componentcore.datamodel.properties.IFacetProjectCreationDataModelProperties;
+
+public interface IJBossESBFacetDataModelProperties extends
IFacetProjectCreationDataModelProperties {
+
+ public static final String USER_DEFINED_LOCATION =
"IProjectCreationPropertiesNew.USER_DEFINED_LOCATION"; //$NON-NLS-1$
+ public static final String DEFAULT_LOCATION =
"IProjectCreationPropertiesNew.DEFAULT_LOCATION"; //$NON-NLS-1$
+ public static final String USE_DEFAULT_LOCATION =
"IProjectCreationPropertiesNew.USE_DEFAULT_LOCATION"; //$NON-NLS-1$
+ public static final String PROJECT_LOCATION =
"IProjectCreationPropertiesNew.PROJECT_LOCATION";
+
+ public static final String ESB_CONTENT_FOLDER =
"JBoss.Project.Content_Folder";
+ public static final String ESB_SRC_FOLDER = "JBoss.Project.Src_Folder";
+
+ public static final QualifiedName QNAME_ESB_CONTENT_FOLDER = new
QualifiedName("jboss", ESB_CONTENT_FOLDER);
+ public static final QualifiedName QNAME_ESB_SRC_FOLDER = new
QualifiedName("jboss", ESB_SRC_FOLDER);
+
+
+
+ public static final String JBOSS_WS_FACET_ID = "jboss.esb";
+ public static final String RUNTIME_DEPLOY = "jboss.deploy";
+ public static final String QUALIFIEDNAME_IDENTIFIER = "jboss.tools";
+ public static final String RUNTIME_IS_SERVER_SUPPLIED =
"jboss.is.server.supplied";
+ public static final String RUNTIME_ID = "jboss.runtime_id";
+
+ public static final String PERSISTENT_PROPERTY_IS_SERVER_SUPPLIED_RUNTIME =
"is.server.supplied.runtime";
+ public static final String RUNTIME_HOME = "jboss.runtime.home";
+ public static final String DEFAULT_VALUE_IS_SERVER_SUPPLIED = "1";
+ static QualifiedName PERSISTENCE_PROPERTY_QNAME_RUNTIME_NAME = new
QualifiedName(QUALIFIEDNAME_IDENTIFIER,
+ RUNTIME_ID);
+ static QualifiedName PERSISTENCE_PROPERTY_RNTIME_LOCATION = new
QualifiedName(QUALIFIEDNAME_IDENTIFIER,
+ RUNTIME_HOME);
+ static QualifiedName PERSISTENCE_PROPERTY_SERVER_SUPPLIED_RUNTIME = new QualifiedName(
+ QUALIFIEDNAME_IDENTIFIER,
+ PERSISTENT_PROPERTY_IS_SERVER_SUPPLIED_RUNTIME);
+}
Added:
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/facet/JBossESBFacetInstallationConfig.java
===================================================================
---
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/facet/JBossESBFacetInstallationConfig.java
(rev 0)
+++
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/facet/JBossESBFacetInstallationConfig.java 2008-08-26
02:02:04 UTC (rev 9888)
@@ -0,0 +1,67 @@
+package org.jboss.tools.esb.project.facet;
+
+import java.util.Set;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.wst.common.componentcore.datamodel.FacetInstallDataModelProvider;
+import
org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties;
+import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
+import org.eclipse.wst.common.project.facet.core.IActionConfigFactory;
+import org.jboss.tools.esb.project.utils.StatusUtils;
+
+public class JBossESBFacetInstallationConfig extends
+ FacetInstallDataModelProvider implements
+ IJBossESBFacetDataModelProperties, IActionConfigFactory{
+
+ public Object create() {
+ // TODO Auto-generated method stub
+ return DataModelFactory.createDataModel(this);
+
+ }
+
+ public Object getDefaultProperty(String propertyName) {
+ if (IFacetDataModelProperties.FACET_ID.equals(propertyName)) {
+
+ return "jboss.esb";
+ }
+ else if(IJBossESBFacetDataModelProperties.ESB_CONTENT_FOLDER.equals(propertyName)){
+ return "esbcontent";
+ }
+ else if(IJBossESBFacetDataModelProperties.ESB_SRC_FOLDER.equals(propertyName)){
+ return "src";
+ }
+ else if(propertyName.equals(RUNTIME_DEPLOY)){
+ return false;
+ }else if(propertyName.equals(RUNTIME_ID)){
+ return "";
+ }else if(propertyName.equals(FACET_ID)){
+ return IJBossESBFacetDataModelProperties.JBOSS_WS_FACET_ID;
+ }
+ return super.getDefaultProperty(propertyName);
+ }
+
+ @Override
+ public Set getPropertyNames() {
+ Set names = super.getPropertyNames();
+ names.add(IJBossESBFacetDataModelProperties.ESB_CONTENT_FOLDER);
+ names.add(IJBossESBFacetDataModelProperties.ESB_SRC_FOLDER);
+ names.add(RUNTIME_DEPLOY);
+ names.add(RUNTIME_ID);
+ names.add(RUNTIME_IS_SERVER_SUPPLIED);
+ names.add(RUNTIME_HOME);
+ return names;
+ }
+
+ @Override
+ public IStatus validate(String name) {
+ boolean serverSupplied = getBooleanProperty(RUNTIME_IS_SERVER_SUPPLIED);
+ String runtimeName = getStringProperty(RUNTIME_ID);
+ if (!serverSupplied
+ && (runtimeName == null || runtimeName.equals(""))) {
+ return StatusUtils.errorStatus("");
+ }
+ return super.validate(name);
+ }
+
+
+}
Added:
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/facet/JBossESBFacetInstallationDelegate.java
===================================================================
---
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/facet/JBossESBFacetInstallationDelegate.java
(rev 0)
+++
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/facet/JBossESBFacetInstallationDelegate.java 2008-08-26
02:02:04 UTC (rev 9888)
@@ -0,0 +1,97 @@
+package org.jboss.tools.esb.project.facet;
+
+import java.io.ByteArrayInputStream;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jst.ws.internal.common.ResourceUtils;
+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.jboss.tools.esb.project.command.JBossClassPathCommand;
+import org.jboss.tools.esb.project.messages.JBossFacetCoreMessages;
+
+public class JBossESBFacetInstallationDelegate implements IDelegate {
+
+
+ private IDataModel model;
+ public static final String ESB_NATURE =
"org.jboss.tools.esb.project.ESBNature";
+
+ public void execute(IProject project, IProjectFacetVersion fv,
+ Object config, IProgressMonitor monitor) throws CoreException {
+ model = (IDataModel)config;
+
+ createProjectStructure(project);
+
+ addESBNature(project);
+
+ monitor.beginTask(JBossFacetCoreMessages.Progress_Install_JBossWS_Runtime,
+ 2);
+
+ JBossClassPathCommand command = new JBossClassPathCommand(project,
+ model);
+ IStatus status = command.executeOverride(monitor);
+ if(!status.equals(Status.OK_STATUS)){
+ throw new CoreException(status);
+ }
+ monitor.worked(1);
+ monitor.done();
+
+
+
+ //String prjName =
model.getStringProperty(IFacetDataModelProperties.FACET_PROJECT_NAME);
+ //IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(prjName);
+
+
+ }
+
+ private IFile createJBossESBXML(IFolder folder) throws CoreException{
+ StringBuffer emptyESB = new StringBuffer();
+ emptyESB.append("<?xml version = \"1.0\" encoding =
\"UTF-8\"?>");
+ emptyESB.append("\n");
+ emptyESB.append("<jbossesb
xmlns=\"http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/et...
parameterReloadSecs=\"5\">");
+ emptyESB.append("\n");
+ emptyESB.append("</jbossesb>");
+ IFile esbfile = folder.getFile("jboss-esb.xml");
+ esbfile.create(new ByteArrayInputStream(emptyESB.toString().getBytes()), true, null);
+
+ return esbfile;
+ }
+
+
+
+
+ private void createProjectStructure(IProject project) throws CoreException{
+ IFile esbFile = null;
+ String strContentFolder =
model.getStringProperty(IJBossESBFacetDataModelProperties.ESB_CONTENT_FOLDER);
+ project.setPersistentProperty(IJBossESBFacetDataModelProperties.QNAME_ESB_CONTENT_FOLDER,
strContentFolder);
+ IFolder esbContent = project.getFolder(strContentFolder);
+ if(!esbContent.exists()) {
+ esbContent.create(true, true, null);
+ }
+
+ esbContent.getFolder("lib").create(true, true, null);
+ esbContent.getFolder("META-INF").create(true, true, null);
+ esbFile = createJBossESBXML(esbContent.getFolder("META-INF"));
+
+ project.refreshLocal(IResource.DEPTH_ZERO, null);
+ }
+
+ private static void addESBNature(IProject project) throws CoreException{
+ IProjectDescription desc = project.getDescription();
+ final String[] current = desc.getNatureIds();
+ final String[] replacement = new String[ current.length + 1 ];
+ System.arraycopy( current, 0, replacement, 1, current.length );
+ replacement[ 0 ] = ESB_NATURE;
+ desc.setNatureIds( replacement );
+ project.setDescription( desc, null );
+
+ }
+}
Added:
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/facet/UnInstallJBossRuntimeDelegate.java
===================================================================
---
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/facet/UnInstallJBossRuntimeDelegate.java
(rev 0)
+++
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/facet/UnInstallJBossRuntimeDelegate.java 2008-08-26
02:02:04 UTC (rev 9888)
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.esb.project.facet;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+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.jboss.tools.esb.project.command.UninstallJBossClassPathCommand;
+import org.jboss.tools.esb.project.messages.JBossFacetCoreMessages;
+
+/**
+ * @author Grid Qian
+ */
+public class UnInstallJBossRuntimeDelegate implements IDelegate {
+
+ public void execute(IProject project, IProjectFacetVersion arg1,
+ Object arg2, IProgressMonitor monitor) throws CoreException {
+ monitor.beginTask(
+ JBossFacetCoreMessages.Progress_UnInstall_JBossWS_Runtime, 2);
+
+ IDataModel model = (IDataModel) arg2;
+
+ UninstallJBossClassPathCommand command = new UninstallJBossClassPathCommand(
+ project, model);
+ command.executeOverride(monitor);
+ monitor.worked(1);
+ monitor.done();
+ }
+
+}
Added:
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/messages/JBossFacetCore.properties
===================================================================
---
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/messages/JBossFacetCore.properties
(rev 0)
+++
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/messages/JBossFacetCore.properties 2008-08-26
02:02:04 UTC (rev 9888)
@@ -0,0 +1,15 @@
+Progress_Install_JBossWS_Runtime=JBoss ESB Runtime
+Progress_UnInstall_JBossWS_Runtime=Uninstall JBoss ESB Runtime
+Dir_Lib=lib
+Dir_Client=client
+Dir_Web_Inf=WEB-INF
+Dir_Web_Content=WebContent
+Error_Copy=Exception while copy runtime jars
+WS_Location=jbossesbruntimelocation
+JBossWS_Runtime_Lib=JBoss_ESB_Runtime
+JBossWS_Runtime=JBoss ESB Runtime
+JBossAS=JBOSS
+Error_WS_Location=The JBoss ESB Runtime Location is NULL
+Error_WS_Classpath=A error comes up when create JBoss ESB runtime Classpath
+Error_Add_Facet_JBossWS=Exception while install JBoss ESB facet
+Error_Remove_Facet_JBossWS=Exception while uninstall JBoss ESB facet
Added:
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/messages/JBossFacetCoreMessages.java
===================================================================
---
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/messages/JBossFacetCoreMessages.java
(rev 0)
+++
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/messages/JBossFacetCoreMessages.java 2008-08-26
02:02:04 UTC (rev 9888)
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.esb.project.messages;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * @author Grid Qian
+ */
+public class JBossFacetCoreMessages {
+
+ private static final String BUNDLE_NAME =
"org.jboss.tools.esb.project.messages.JBossFacetCore"; //$NON-NLS-1$
+
+ private JBossFacetCoreMessages() {
+ // Do not instantiate
+ }
+
+ public static String Progress_Install_JBossWS_Runtime;
+ public static String Progress_UnInstall_JBossWS_Runtime;
+ public static String Dir_Lib;
+ public static String Dir_Client;
+ public static String Dir_Web_Inf;
+ public static String Dir_Web_Content;
+ public static String Error_Copy;
+ public static String WS_Location;
+ public static String JBossWS_Runtime_Lib;
+ public static String JBossWS_Runtime;
+ public static String JBossAS;
+ public static String Error_WS_Location;
+ public static String Error_WS_Classpath;
+ public static String Error_Add_Facet_JBossWS;
+ public static String Error_Remove_Facet_JBossWS;
+
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, JBossFacetCoreMessages.class);
+ }
+}
\ No newline at end of file
Added:
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/nature/JBossESBProjectNature.java
===================================================================
---
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/nature/JBossESBProjectNature.java
(rev 0)
+++
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/nature/JBossESBProjectNature.java 2008-08-26
02:02:04 UTC (rev 9888)
@@ -0,0 +1,28 @@
+package org.jboss.tools.esb.project.nature;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectNature;
+import org.eclipse.core.runtime.CoreException;
+
+public class JBossESBProjectNature implements IProjectNature {
+
+ IProject project;
+ public void configure() throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void deconfigure() throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public IProject getProject() {
+ return project;
+ }
+
+ public void setProject(IProject project) {
+ this.project = project;
+ }
+
+}
Added:
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/utils/JBossRuntimeCoreUtils.java
===================================================================
---
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/utils/JBossRuntimeCoreUtils.java
(rev 0)
+++
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/utils/JBossRuntimeCoreUtils.java 2008-08-26
02:02:04 UTC (rev 9888)
@@ -0,0 +1,218 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.esb.project.utils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.esb.project.messages.JBossFacetCoreMessages;
+
+/**
+ * @author Grid Qian
+ */
+public class JBossRuntimeCoreUtils {
+
+/* public static IPath pathToWebProjectContainer(String project) {
+ IPath projectRoot = getProjectRoot(project);
+ IPath currentDynamicWebProjectDir = J2EEUtils
+ .getWebContentPath(getProjectName(project));
+ IPath currentDynamicWebProjectDirWithoutProjectRoot = J2EEUtils
+ .getWebContentPath(getProjectName(project))
+ .removeFirstSegments(1).makeAbsolute();
+ if (projectRoot.toOSString().contains(getWorkspace().toOSString())) {
+ return getWorkspace().append(currentDynamicWebProjectDir);
+ } else {
+ return projectRoot
+ .append(currentDynamicWebProjectDirWithoutProjectRoot);
+ }
+
+ }*/
+
+ public static IPath getProjectRoot(String project) {
+ String projectString = replaceEscapecharactors(project.toString());
+ return ResourcesPlugin.getWorkspace().getRoot().getProject(
+ getProjectNameFromFramewokNameString(projectString))
+ .getLocation();
+ }
+
+ // Fix for the windows build not working
+ private static String replaceEscapecharactors(String vulnarableString) {
+ if (vulnarableString.indexOf("/") != -1) {
+ vulnarableString = vulnarableString.replace('/', File.separator
+ .charAt(0));
+ }
+ return vulnarableString;
+ }
+
+ private static String getProjectNameFromFramewokNameString(
+ String frameworkProjectString) {
+ if (frameworkProjectString.indexOf(getSplitCharactor()) == -1) {
+ return frameworkProjectString;
+ } else {
+ return frameworkProjectString.split(getSplitCharactors())[1];
+ }
+ }
+
+ private static String getSplitCharactor() {
+ // Windows check (because from inside wtp in return I received a hard
+ // coded path)
+ if (File.separatorChar == '\\') {
+ return "\\";
+ } else {
+ return File.separator;
+ }
+ }
+
+ private static String getSplitCharactors() {
+ // Windows check (because from inside wtp in return I received a hard
+ // coded path)
+ if (File.separatorChar == '\\') {
+ return "\\" + File.separator;
+ } else {
+ return File.separator;
+ }
+ }
+
+ public static IPath getWorkspace() {
+ return ResourcesPlugin.getWorkspace().getRoot().getLocation();
+ }
+
+ public static IWorkspaceRoot getWorkspaceRoot() {
+ return ResourcesPlugin.getWorkspace().getRoot();
+ }
+
+ public static IProject getProjectName(String project) {
+ String projectString = replaceEscapecharactors(project.toString());
+ return ResourcesPlugin.getWorkspace().getRoot().getProject(
+ getProjectNameFromFramewokNameString(projectString));
+ }
+
+ public static IStatus copy(IPath sourcePath, IPath targetPath) {
+
+ IStatus status = Status.OK_STATUS;
+ File sourceDir = sourcePath.toFile();
+ File[] children = sourceDir.listFiles();
+
+ FileInputStream finStream = null;
+ for (int i = 0; i < children.length; i++) {
+ if (children[i].isFile()) {
+ try {
+ finStream = new FileInputStream(children[i]);
+ } catch (FileNotFoundException e) {
+ status = StatusUtils.errorStatus(NLS.bind(
+ JBossFacetCoreMessages.Error_Copy, new String[] { e
+ .getLocalizedMessage() }), e);
+ }
+ try {
+ makeFile(getWorkspaceRoot().getContainerForLocation(
+ targetPath), children[i].getName(), finStream);
+ } catch (CoreException e) {
+ status = StatusUtils.errorStatus(NLS.bind(
+ JBossFacetCoreMessages.Error_Copy, new String[] { e
+ .getLocalizedMessage() }), e);
+ }
+ } else {
+ try {
+ IFolder temp = makeFolder(getWorkspaceRoot()
+ .getContainerForLocation(targetPath), children[i]
+ .getName());
+ copy(sourcePath.append(children[i].getName()), temp
+ .getLocation());
+ } catch (CoreException e) {
+ status = StatusUtils.errorStatus(NLS.bind(
+ JBossFacetCoreMessages.Error_Copy, new String[] { e
+ .getLocalizedMessage() }), e);
+ }
+ }
+ }
+ return status;
+ }
+
+ private static IFolder makeFolder(IContainer parent, String folderName)
+ throws CoreException {
+ IResource child = parent.findMember(folderName);
+ if (child == null) {
+ IFolder folder = parent.getFolder(new Path(folderName));
+ try {
+ folder.create(true, true, null);
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return folder;
+ } else {
+ if (child.getType() == IResource.FOLDER) {
+ return (IFolder) child;
+ } else {
+ throw new CoreException(new Status(IStatus.ERROR,
+ "ResourceUtils", 0, NLS.bind("ERROR",//
EnvironmentMessages.MSG_ERROR_RESOURCE_NOT_FOLDER,
+ new Object[] { parent.getFullPath().append(
+ folderName).toString() }), null));
+ }
+ }
+
+ }
+
+ private static IFile makeFile(IContainer parent, String fileName,
+ InputStream inputStream) throws CoreException {
+ IResource child = parent.findMember(fileName);
+
+ if (child != null) {
+ if (child.getType() == IResource.FILE) {
+
+ // We have permission to overwrite so check if file is read-only
+ if (child.getResourceAttributes() != null
+ && child.getResourceAttributes().isReadOnly()) {
+ IFile[] files = new IFile[1];
+ files[0] = (IFile) child;
+ }
+
+ // Change the contents of the existing file.
+ IFile file = parent.getFile(new Path(fileName));
+ file.setContents(inputStream, true, true, null);
+
+ return file;
+
+ } else {
+ throw new CoreException(new Status(IStatus.ERROR,
+ "ResourceUtils", 0, NLS.bind("ERROR",
+ new Object[] { parent.getFullPath().append(
+ fileName) }), null));
+ }
+ } else {
+ // Create a new file.
+ IFile file = parent.getFile(new Path(fileName));
+ file.create(inputStream, true, null);
+
+ return file;
+ }
+ }
+
+
+
+
+}
Added:
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/utils/StatusUtils.java
===================================================================
---
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/utils/StatusUtils.java
(rev 0)
+++
workspace/Denny/org.jboss.tools.esb.project/src/org/jboss/tools/esb/project/utils/StatusUtils.java 2008-08-26
02:02:04 UTC (rev 9888)
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.esb.project.utils;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.Status;
+
+public class StatusUtils
+{
+ public static IStatus errorStatus( String errorMessage )
+ {
+ return new Status( IStatus.ERROR, "id", 0, errorMessage, null );
+ }
+
+ public static IStatus errorStatus( Throwable exc )
+ {
+ String message = exc.getMessage();
+
+ return new Status( IStatus.ERROR, "id", 0, message == null ? "" :
message, exc );
+ }
+
+ public static IStatus errorStatus( String message, Throwable exc )
+ {
+ return new Status( IStatus.ERROR, "id", 0, message, exc );
+ }
+
+ public static MultiStatus multiStatus( String message, IStatus[] children, Throwable
exc )
+ {
+ return new MultiStatus( "id", 0, children, message, exc );
+ }
+
+ public static MultiStatus multiStatus( String message, IStatus[] children )
+ {
+ return new MultiStatus( "id", 0, children, message, null );
+ }
+
+ public static IStatus warningStatus( String warningMessage )
+ {
+ return new Status( IStatus.WARNING, "id", 0, warningMessage, null );
+ }
+
+ public static IStatus warningStatus( String warningMessage, Throwable exc )
+ {
+ return new Status( IStatus.WARNING, "id", 0, warningMessage, exc );
+ }
+
+ public static IStatus infoStatus( String infoMessage )
+ {
+ return new Status( IStatus.INFO, "id", 0, infoMessage, null );
+ }
+}
\ No newline at end of file