Author: Grid.Qian
Date: 2009-04-24 03:45:00 -0400 (Fri, 24 Apr 2009)
New Revision: 14879
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/AbstractGenerateCodeCommand.java
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/Java2WSCommand.java
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/WSDL2JavaCommand.java
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/utils/JBossWSCreationUtils.java
Log:
JBIDE-4208: WS client generation: generated code is placed under "src" folder
regardless of real source folder of Eclipse (3.4.2) project
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/AbstractGenerateCodeCommand.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/AbstractGenerateCodeCommand.java 2009-04-24
03:14:36 UTC (rev 14878)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/AbstractGenerateCodeCommand.java 2009-04-24
07:45:00 UTC (rev 14879)
@@ -49,17 +49,14 @@
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(
model.getWebProjectName());
- String projectRoot = JBossWSCreationUtils.getProjectRoot(
- model.getWebProjectName()).toOSString();
- IJavaProject javaProject = JavaCore.create(project);
try {
String runtimeLocation = JBossWSCreationUtils
.getJBossWSRuntimeLocation(project);
String commandLocation = runtimeLocation + Path.SEPARATOR + "bin";
IPath path = new Path(commandLocation);
-
+
List<String> command = new ArrayList<String>();
-
+
if (System.getProperty("os.name").toLowerCase().indexOf("win")
>= 0) {
command.add("cmd.exe");
command.add("/c");
@@ -79,18 +76,11 @@
new String[] { path.toOSString() }));
}
- command.add("-k");
addCommandlineArgs(command);
- if(model.getWsdlURI() != null){
- command.add(model.getWsdlURI());
- }
+ addCommonArgs(command, project);
- command.add("-o");
- StringBuffer opDir = new StringBuffer();
- opDir.append(projectRoot).append(Path.SEPARATOR).append(javaProject.getOutputLocation().removeFirstSegments(1).toOSString());
- command.add(opDir.toString());
-
- Process proc = DebugPlugin.exec(command.toArray(new String[command.size()]), new
File(commandLocation));
+ Process proc = DebugPlugin.exec(command.toArray(new String[command
+ .size()]), new File(commandLocation));
StringBuffer errorResult = new StringBuffer();
StringBuffer inputResult = new StringBuffer();
@@ -105,7 +95,8 @@
String resultInput = inputResult.toString();
if (resultInput != null && resultInput.indexOf("[ERROR]") >= 0)
{
JBossWSCreationCore.getDefault().logError(resultInput);
- IStatus errorStatus = StatusUtils.warningStatus(resultInput);
+ IStatus errorStatus = StatusUtils
+ .warningStatus(resultInput);
status = StatusUtils
.warningStatus(
JBossWSCreationCoreMessages.Error_Message_Failed_To_Generate_Code,
@@ -132,6 +123,28 @@
return status;
}
+ private void addCommonArgs(List<String> command, IProject project) throws
Exception {
+ String projectRoot = JBossWSCreationUtils.getProjectRoot(
+ model.getWebProjectName()).toOSString();
+ IJavaProject javaProject = JavaCore.create(project);
+
+ command.add("-k");
+
+ command.add("-s");
+ command.add(JBossWSCreationUtils.getJavaProjectSrcLocation(project));
+
+ command.add("-o");
+ StringBuffer opDir = new StringBuffer();
+ opDir.append(projectRoot).append(Path.SEPARATOR).append(
+ javaProject.getOutputLocation().removeFirstSegments(1)
+ .toOSString());
+ command.add(opDir.toString());
+ if (model.getWsdlURI() != null) {
+ command.add(model.getWsdlURI());
+ }
+
+ }
+
private void convertInputStreamToString(final StringBuffer result,
final InputStream input) {
@@ -169,7 +182,8 @@
}
}
- abstract protected void addCommandlineArgs(List<String> command) throws
Exception;
+ abstract protected void addCommandlineArgs(List<String> command)
+ throws Exception;
abstract protected String getCommandLineFileName_linux();
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/Java2WSCommand.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/Java2WSCommand.java 2009-04-24
03:14:36 UTC (rev 14878)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/Java2WSCommand.java 2009-04-24
07:45:00 UTC (rev 14879)
@@ -56,10 +56,7 @@
IProject iProject = ResourcesPlugin.getWorkspace().getRoot()
.getProject(projectName);
-
- command.add("-s");
- command.add(projectRoot + Path.SEPARATOR + "src");
-
+
if (model.isGenWSDL()) {
command.add("-w");
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/WSDL2JavaCommand.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/WSDL2JavaCommand.java 2009-04-24
03:14:36 UTC (rev 14878)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/WSDL2JavaCommand.java 2009-04-24
07:45:00 UTC (rev 14879)
@@ -3,9 +3,7 @@
import java.io.File;
import java.util.List;
-import org.eclipse.core.runtime.Path;
import org.jboss.tools.ws.creation.core.data.ServiceModel;
-import org.jboss.tools.ws.creation.core.utils.JBossWSCreationUtils;
public class WSDL2JavaCommand extends AbstractGenerateCodeCommand{
@@ -29,12 +27,7 @@
@Override
protected void addCommandlineArgs(List<String> command) {
- String project = model.getWebProjectName();
- String projectRoot = JBossWSCreationUtils.getProjectRoot(project).toOSString();
- command.add("-s");
- command.add(projectRoot + Path.SEPARATOR + "src");
-
if(model.getCustomPackage() != null &&
!"".equals(model.getCustomPackage())){
command.add("-p");
command.add(model.getCustomPackage());
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/utils/JBossWSCreationUtils.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/utils/JBossWSCreationUtils.java 2009-04-24
03:14:36 UTC (rev 14878)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/utils/JBossWSCreationUtils.java 2009-04-24
07:45:00 UTC (rev 14879)
@@ -4,7 +4,7 @@
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
-* This is free software; you can redistribute it and/or modify it
+ * This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
@@ -23,14 +23,18 @@
import java.io.File;
import java.text.Collator;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import java.util.Locale;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
+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.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaModel;
@@ -53,156 +57,156 @@
import org.jboss.tools.ws.creation.core.messages.JBossWSCreationCoreMessages;
public class JBossWSCreationUtils {
-
- static final String javaKeyWords[] =
- {
- "abstract", "assert", "boolean",
"break", "byte", "case",
- "catch", "char", "class", "const",
"continue",
- "default", "do", "double", "else",
"extends",
- "false", "final", "finally", "float",
"for",
- "goto", "if", "implements", "import",
"instanceof",
- "int", "interface", "long", "native",
"new",
- "null", "package", "private",
"protected", "public",
- "return", "short", "static",
"strictfp", "super",
- "switch", "synchronized", "this",
"throw", "throws",
- "transient", "true", "try", "void",
"volatile",
- "while"
- };
-
- public static boolean isJavaKeyword(String keyword) {
- if (hasUpperCase(keyword)) {
- return false;
- }
- return (Arrays.binarySearch(javaKeyWords, keyword,
Collator.getInstance(Locale.ENGLISH)) >= 0);
- }
- private static boolean hasUpperCase(String nodeName) {
- if (nodeName == null) {
- return false;
- }
- for (int i = 0; i < nodeName.length(); i++) {
- if (Character.isUpperCase(nodeName.charAt(i))) {
- return true;
- }
- }
- return false;
- }
-
- public static IPath getWorkspace(){
+ static final String javaKeyWords[] = { "abstract", "assert",
"boolean",
+ "break", "byte", "case", "catch",
"char", "class", "const",
+ "continue", "default", "do", "double",
"else", "extends", "false",
+ "final", "finally", "float", "for",
"goto", "if", "implements",
+ "import", "instanceof", "int", "interface",
"long", "native",
+ "new", "null", "package", "private",
"protected", "public",
+ "return", "short", "static", "strictfp",
"super", "switch",
+ "synchronized", "this", "throw", "throws",
"transient", "true",
+ "try", "void", "volatile", "while" };
+
+ public static boolean isJavaKeyword(String keyword) {
+ if (hasUpperCase(keyword)) {
+ return false;
+ }
+ return (Arrays.binarySearch(javaKeyWords, keyword, Collator
+ .getInstance(Locale.ENGLISH)) >= 0);
+ }
+
+ private static boolean hasUpperCase(String nodeName) {
+ if (nodeName == null) {
+ return false;
+ }
+ for (int i = 0; i < nodeName.length(); i++) {
+ if (Character.isUpperCase(nodeName.charAt(i))) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static IPath getWorkspace() {
return ResourcesPlugin.getWorkspace().getRoot().getLocation();
}
-
- public static IProject getProjectByName(String project){
+
+ public static IProject getProjectByName(String project) {
String projectString = replaceEscapecharactors(project);
return ResourcesPlugin.getWorkspace().getRoot().getProject(
getProjectNameFromFramewokNameString(projectString));
}
-
- public static IPath getProjectRoot(String project){
+
+ public static IPath getProjectRoot(String project) {
String projectString = replaceEscapecharactors(project);
return ResourcesPlugin.getWorkspace().getRoot().getProject(
- getProjectNameFromFramewokNameString(projectString)).getLocation();
+ getProjectNameFromFramewokNameString(projectString))
+ .getLocation();
}
- public static String pathToWebProjectContainer(String project) {
+ public static String pathToWebProjectContainer(String project) {
IPath projectRoot = getProjectRoot(project);
- IPath currentDynamicWebProjectDir = J2EEUtils.getWebContentPath(
- getProjectByName(project));
- IPath currentDynamicWebProjectDirWithoutProjectRoot = J2EEUtils.getWebContentPath(
- getProjectByName(project)).removeFirstSegments(1).makeAbsolute();
- if(projectRoot.toOSString().contains(getWorkspace().toOSString())){
- return getWorkspace()
- .append(currentDynamicWebProjectDir).toOSString();
- }else{
- return projectRoot
- .append(currentDynamicWebProjectDirWithoutProjectRoot).toOSString();
+ IPath currentDynamicWebProjectDir = J2EEUtils
+ .getWebContentPath(getProjectByName(project));
+ IPath currentDynamicWebProjectDirWithoutProjectRoot = J2EEUtils
+ .getWebContentPath(getProjectByName(project))
+ .removeFirstSegments(1).makeAbsolute();
+ if (projectRoot.toOSString().contains(getWorkspace().toOSString())) {
+ return getWorkspace().append(currentDynamicWebProjectDir)
+ .toOSString();
+ } else {
+ return projectRoot.append(
+ currentDynamicWebProjectDirWithoutProjectRoot).toOSString();
}
-
+
}
-
- public static String pathToWebProjectContainerWEBINF(String project) {
+
+ public static String pathToWebProjectContainerWEBINF(String project) {
IPath projectRoot = getProjectRoot(project);
- IPath webContainerWEBINFDir = J2EEUtils.getWebInfPath(
- getProjectByName(project));
- IPath webContainerWEBINFDirWithoutProjectRoot = J2EEUtils.getWebInfPath(
- getProjectByName(project)).removeFirstSegments(1).makeAbsolute();
- if(projectRoot.toOSString().contains(getWorkspace().toOSString())){
- return getWorkspace()
- .append(webContainerWEBINFDir).toOSString();
- }else{
- return projectRoot
- .append(webContainerWEBINFDirWithoutProjectRoot).toOSString();
+ IPath webContainerWEBINFDir = J2EEUtils
+ .getWebInfPath(getProjectByName(project));
+ IPath webContainerWEBINFDirWithoutProjectRoot = J2EEUtils
+ .getWebInfPath(getProjectByName(project))
+ .removeFirstSegments(1).makeAbsolute();
+ if (projectRoot.toOSString().contains(getWorkspace().toOSString())) {
+ return getWorkspace().append(webContainerWEBINFDir).toOSString();
+ } else {
+ return projectRoot.append(webContainerWEBINFDirWithoutProjectRoot)
+ .toOSString();
}
}
-
-
- private static String replaceEscapecharactors(String vulnarableString){
- if (vulnarableString.indexOf("/")!=-1){
- vulnarableString = vulnarableString.replace('/', File.separator.charAt(0));
+
+ 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){
+
+ private static String getProjectNameFromFramewokNameString(
+ String frameworkProjectString) {
+ if (frameworkProjectString.indexOf(getSplitCharactor()) == -1) {
return frameworkProjectString;
- }else{
+ } 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{
+
+ 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 == '\\'){
+
+ 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{
+ } else {
return File.separator;
}
}
-
- public static String classNameFromQualifiedName(String qualifiedCalssName){
- //This was done due to not splitting with . Strange
- qualifiedCalssName = qualifiedCalssName.replace('.', ':');
- String[] parts = qualifiedCalssName.split(":");
- if (parts.length == 0){
- return "";
- }
- return parts[parts.length-1];
- }
-
+
+ public static String classNameFromQualifiedName(String qualifiedCalssName) {
+ // This was done due to not splitting with . Strange
+ qualifiedCalssName = qualifiedCalssName.replace('.', ':');
+ String[] parts = qualifiedCalssName.split(":");
+ if (parts.length == 0) {
+ return "";
+ }
+ return parts[parts.length - 1];
+ }
+
// JDT utils
/**
* get JavaProject object from project name
*/
- public static IJavaProject getJavaProjectByName(String projectName) throws
JavaModelException {
+ public static IJavaProject getJavaProjectByName(String projectName)
+ throws JavaModelException {
- IJavaModel model = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
- model.open(null);
+ IJavaModel model = JavaCore.create(ResourcesPlugin.getWorkspace()
+ .getRoot());
+ model.open(null);
- IJavaProject[] projects = model.getJavaProjects();
+ IJavaProject[] projects = model.getJavaProjects();
- for (IJavaProject proj : projects) {
- if (proj.getProject().getName().equals(projectName)) {
- return proj;
- }
- }
+ for (IJavaProject proj : projects) {
+ if (proj.getProject().getName().equals(projectName)) {
+ return proj;
+ }
+ }
- return null;
- }
-
- public static ICompilationUnit findUnitByFileName(IJavaElement javaElem,
+ return null;
+ }
+
+ public static ICompilationUnit findUnitByFileName(IJavaElement javaElem,
String filePath) throws Exception {
ICompilationUnit unit = null;
@@ -252,26 +256,30 @@
return null;
}
-
- /**
- * get Java compilation unit by file path
- * @param javaFile the java sour file to look
- * @return ICompilationUnit, JDK compilation unit for this java file.
- */
- public static ICompilationUnit getJavaUnitFromFile(IFile javaFile) {
- try {
- IJavaProject project =
getJavaProjectByName(javaFile.getProject().getName());
- if (project == null) {
- return null;
- }
+ /**
+ * get Java compilation unit by file path
+ *
+ * @param javaFile
+ * the java sour file to look
+ * @return ICompilationUnit, JDK compilation unit for this java file.
+ */
+ public static ICompilationUnit getJavaUnitFromFile(IFile javaFile) {
+ try {
+ IJavaProject project = getJavaProjectByName(javaFile.getProject()
+ .getName());
- return findUnitByFileName(project, javaFile.getFullPath().toString());
- } catch (Exception e) {
- return null;
- }
- }
-
+ if (project == null) {
+ return null;
+ }
+
+ return findUnitByFileName(project, javaFile.getFullPath()
+ .toString());
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
public static boolean validateJBossWSLocation() {
String location = JBossWSCorePlugin.getDefault().getPreferenceStore()
.getString(JBossWSCoreMessages.WS_Location);
@@ -280,7 +288,7 @@
}
return true;
}
-
+
public static String getJBossWSRuntimeLocation(IProject project)
throws CoreException {
@@ -319,11 +327,12 @@
runtimeTypeName = "";
}
if (runtimeTypeName.toUpperCase().indexOf("JBOSS") >= 0) {
- String runtimeLocation = serverRuntime.getLocation().toOSString();
- if(runtimeLocation.endsWith("bin")){
+ String runtimeLocation = serverRuntime.getLocation()
+ .toOSString();
+ if (runtimeLocation.endsWith("bin")) {
return serverRuntime.getLocation().removeLastSegments(1)
- .toOSString();
- }else{
+ .toOSString();
+ } else {
return runtimeLocation;
}
}
@@ -347,23 +356,57 @@
return "";
}
-
- public static IRuntime
getRuntime(org.eclipse.wst.common.project.facet.core.runtime.IRuntime runtime) {
+
+ public static IRuntime getRuntime(
+ org.eclipse.wst.common.project.facet.core.runtime.IRuntime runtime) {
if (runtime == null)
throw new IllegalArgumentException();
-
+
String id = runtime.getProperty("id");
if (id == null)
return null;
-
- org.eclipse.wst.server.core.IRuntime[] runtimes = ServerCore.getRuntimes();
+
+ org.eclipse.wst.server.core.IRuntime[] runtimes = ServerCore
+ .getRuntimes();
int size = runtimes.length;
for (int i = 0; i < size; i++) {
if (id.equals(runtimes[i].getId()))
return runtimes[i];
}
-
+
return null;
}
-
+
+ public static String getJavaProjectSrcLocation(IProject project) throws
JavaModelException {
+ IResource[] rs = getJavaSourceRoots(project);
+ String src = "";
+ if (rs == null || rs.length == 0)
+ return src;
+ for (int i = 0; i < rs.length; i++) {
+ IPath p = rs[i].getLocation();
+ if (p != null) {
+ src = p.toOSString();
+ }
+ }
+ return src;
+ }
+
+ public static IResource[] getJavaSourceRoots(IProject project) throws JavaModelException
{
+ IJavaProject javaProject = JavaCore.create(project);
+ if (javaProject == null)
+ return null;
+ List<IResource> resources = new ArrayList<IResource>();
+ IClasspathEntry[] es = javaProject.getResolvedClasspath(true);
+ for (int i = 0; i < es.length; i++) {
+ if (es[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
+ IResource findMember = ResourcesPlugin.getWorkspace().getRoot()
+ .findMember(es[i].getPath());
+ if (findMember != null && findMember.exists()) {
+ resources.add(findMember);
+ }
+ }
+ }
+ return resources.toArray(new IResource[resources.size()]);
+ }
+
}