diff options
Diffstat (limited to 'plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project')
10 files changed, 0 insertions, 2415 deletions
diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/Assert.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/Assert.java deleted file mode 100644 index 265ae9ab1..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/Assert.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.j2ee.internal.project; - -/** - * <code>Assert</code> is useful for for embedding runtime sanity checks - * in code. - * The predicate methods all test a condition and throw some - * type of unchecked exception if the condition does not hold. - * <p> - * Assertion failure exceptions, like most runtime exceptions, are - * thrown when something is misbehaving. Assertion failures are invariably - * unspecified behavior; consequently, clients should never rely on - * these being thrown (and certainly should not being catching them - * specifically). - * </p> - */ -public final class Assert { - /* This class is not intended to be instantiated. */ - private Assert() { - // not allowed - } - - /** Asserts that an argument is legal. If the given boolean is - * not <code>true</code>, an <code>IllegalArgumentException</code> - * is thrown. - * - * @param expression the outcode of the check - * @return <code>true</code> if the check passes (does not return - * if the check fails) - * @exception IllegalArgumentException if the legality test failed - */ - public static boolean isLegal(boolean expression) { - return isLegal(expression, ""); //$NON-NLS-1$ - } - - /** Asserts that an argument is legal. If the given boolean is - * not <code>true</code>, an <code>IllegalArgumentException</code> - * is thrown. - * The given message is included in that exception, to aid debugging. - * - * @param expression the outcode of the check - * @param message the message to include in the exception - * @return <code>true</code> if the check passes (does not return - * if the check fails) - * @exception IllegalArgumentException if the legality test failed - */ - public static boolean isLegal(boolean expression, String message) { - if (!expression) - throw new IllegalArgumentException(message); - return expression; - } - - /** Asserts that the given object is not <code>null</code>. If this - * is not the case, some kind of unchecked exception is thrown. - * - * @param object the value to test - * @exception IllegalArgumentException if the object is <code>null</code> - */ - public static void isNotNull(Object object) { - isNotNull(object, ""); //$NON-NLS-1$ - } - - /** Asserts that the given object is not <code>null</code>. If this - * is not the case, some kind of unchecked exception is thrown. - * The given message is included in that exception, to aid debugging. - * - * @param object the value to test - * @param message the message to include in the exception - * @exception IllegalArgumentException if the object is <code>null</code> - */ - public static void isNotNull(Object object, String message) { - if (object == null) - throw new AssertionFailedException("null argument:" + message); //$NON-NLS-1$ - } - - /** Asserts that the given boolean is <code>true</code>. If this - * is not the case, some kind of unchecked exception is thrown. - * - * @param expression the outcode of the check - * @return <code>true</code> if the check passes (does not return - * if the check fails) - */ - public static boolean isTrue(boolean expression) { - return isTrue(expression, ""); //$NON-NLS-1$ - } - - /** Asserts that the given boolean is <code>true</code>. If this - * is not the case, some kind of unchecked exception is thrown. - * The given message is included in that exception, to aid debugging. - * - * @param expression the outcode of the check - * @param message the message to include in the exception - * @return <code>true</code> if the check passes (does not return - * if the check fails) - */ - public static boolean isTrue(boolean expression, String message) { - if (!expression) - throw new AssertionFailedException("assertion failed: " + message); //$NON-NLS-1$ - return expression; - } -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/AssertionFailedException.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/AssertionFailedException.java deleted file mode 100644 index 91c64d906..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/AssertionFailedException.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.j2ee.internal.project; - -/** - * <code>AssertionFailedException</code> is a runtime exception thrown - * by some of the methods in <code>Assert</code>. - * <p> - * This class is not declared public to prevent some misuses; programs that catch - * or otherwise depend on assertion failures are susceptible to unexpected - * breakage when assertions in the code are added or removed. - * </p> - */ -/* package */ -class AssertionFailedException extends RuntimeException { - /** - * All serializable objects should have a stable serialVersionUID - */ - private static final long serialVersionUID = 1L; - - /** Constructs a new exception with the given message. - */ - public AssertionFailedException(String detail) { - super(detail); - } -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/IJ2EEProjectTypes.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/IJ2EEProjectTypes.java deleted file mode 100644 index 684f12120..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/IJ2EEProjectTypes.java +++ /dev/null @@ -1,23 +0,0 @@ -/*************************************************************************************************** - * Copyright (c) 2003, 2004 IBM Corporation and others. All rights reserved. This program and the - * accompanying materials are 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: IBM Corporation - initial API and implementation - **************************************************************************************************/ -package org.eclipse.jst.j2ee.internal.project; - - -public interface IJ2EEProjectTypes { - int SOURCE = 1; - int BINARY = 2; - int DEFAULT = 3; - int UTIL = 4; - int EJB_CLIENT = 5; - int MODULE = 6; - int EJB_MODULE = 7; - int WEB_MODULE = 8; - int JCA_MODULE = 9; - int APPCLIENT_MODULE = 10; -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/J2EECreationResourceHandler.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/J2EECreationResourceHandler.java deleted file mode 100644 index 8974bd53a..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/J2EECreationResourceHandler.java +++ /dev/null @@ -1,162 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.j2ee.internal.project; - - -import org.eclipse.osgi.util.NLS; - -public class J2EECreationResourceHandler extends NLS { - private static final String BUNDLE_NAME = "j2eecreation";//$NON-NLS-1$ - - private J2EECreationResourceHandler() { - // Do not instantiate - } - - public static String EJBReferenceDataModel_UI_12; - public static String MIGRATE_J2EE_SPEC_UI_; - public static String EJBReferenceDataModel_UI_11; - public static String EJBReferenceDataModel_UI_10; - public static String REQUIRED_CLIENT_VIEW_TITLE; - public static String MIGRATION_COMPLETE; - public static String NOT_NEEDED_DEPLOYMENT_DESC_MIG; - public static String MIGRATION_WARNINGS_REPORT_UI_; - public static String BACKEND_MIGRATION_FAILED; - public static String REUSE_DELETED_CLIENT_VIEW_NAME_UI_; - public static String EJB_PROJECTS_UI_; - public static String NOT_NEEDED_BACKEND_MIG; - public static String MIGRATION_NOT_POSSIBLE_REPORT; - public static String PROJECT_MUST_BE_SELECTED_UI_; - public static String JAR_11_IMPORT_20_UI_; - public static String WEBCONTENT_FOLDER_RENAME_SKIPPED; - public static String CONFIRM_MIGRATE_PROJECT_STRUCTURE; - public static String WEBPROJECT_VERSION_MIGRATE_FAILED; - public static String JdkJarFileDoesNotExist_UI; - public static String Local_cannot_be_empty_UI_; - public static String LOCAL_CLIENT_NOT_NEEDED; - public static String REMOTE_CLIENT_VIEWS_NOT_EXIST_UI_; - public static String MIGRATING_PROJECT_STRUCTURES_UI_; - public static String ResourceEnvironmentReferenceDataModel_2; - public static String J2EE_1_2_ONLY_HAVE_REMOTE; - public static String OPEN_EDITORS_TITLE; - public static String EJB_MUST_BE_SELECTED_UI_; - public static String FAILED_MIGRATING_IMPORTED_CLASSES; - public static String OPEN_J2EE_MIGRATION_WIZARD_UI_; - public static String LOCAL_CLIENT_VIEWS_EXIST_UI_; - public static String DELETING_REMOTE_CLIENT_VIEWS_UI_; - public static String EJB_UI_; - public static String CONFIRM_CLIENT_VIEW_REQUIRED; - public static String MIGRATION_NOT_NEEDED; - public static String ADDING_LOCAL_CLIENT_VIEWS_UI_; - public static String WEB_UI_; - public static String DeleteModuleOperation_UI_0; - public static String Home_cannot_be_empty_UI_; - public static String WEBCONTENT_LIBPATH_UPDATE_FAILED; - public static String REMOTE_CLIENT_DELETE_SUCCESS_UI_; - public static String ServerTargetDataModel_UI_9; - public static String LOCAL_CLIENT_ADD_FAILED_UI_; - public static String ServerTargetDataModel_UI_8; - public static String OLD_PROJECT_STRUCTURE_UI_; - public static String ServerTargetDataModel_UI_7; - public static String INFORM_PROPER_SELECTION; - public static String MIGRATE_MODULE_PROJECTS_UI_; - public static String COMPLETED_LOCAL_CLIENT_CREATE; - public static String IMPORTED_CLASSES_FILE_DELETED; - public static String ADD_LOCAL_CLIENT_VIEWS_BAN_UI_; - public static String USE_REMOTE_FOR_DIFFERENT_EAR; - public static String APP_PROJECT_ERROR_EXC_; - public static String InvalidCharsError; - public static String ENTERPRISE_APPLICATIONS_UI_; - public static String ResourceReferenceDataModel_UI_1; - public static String ResourceReferenceDataModel_UI_0; - public static String DELETE_REM_CLIENT_VIEWS_UI_; - public static String Errors_occurred_renaming_module_dependencies_UI_; - public static String MIGRATION_ERRORS_REPORT_UI_; - public static String J2EE_VERSION_FAILED_UI_; - public static String COMPLETED_DEPLOY_DELETE; - public static String PROJECT_REFERENCES_UPDATED; - public static String TARGET_ALSO_EXIST_IN_SAME_EAR; - public static String WEBCONTENT_FOLDER_RENAME_FAILED; - public static String MIGRATE_UI_; - public static String Creating__UI_; - public static String Error_creating_an_EAR_proj_UI_; - public static String ReferenceDataModel_UI_6; - public static String ReferenceDataModel_UI_5; - public static String ReferenceDataModel_UI_3; - public static String ENTERPRISE_BEANS_BAN_UI_; - public static String ADD_LOCAL_CLIENT_VIEWS_CHECK_UI_; - public static String Can_not_rename_module_dependency_from_project_UI_; - public static String PROJECT_STRUCTURE_SUCCESS_UI_; - public static String SOURCE_FOLDER_RENAME_SKIPPED; - public static String UNKNOWN_UI_; - public static String WIZ_BAN_DESC_UI_; - public static String COMPLETED_CMP20_CODEGEN; - public static String PROJECT_NOT_NEED_MIGRATION_UI_; - public static String SELECT_EJB_CLIENT_VIEWS_UI_; - public static String Creating_Java_Project_UI_; - public static String REMOTE_CLIENT_DELETE_FAILED_UI_; - public static String FILES_OUT_OF_SYNC; - public static String MIGRATE_CMP_BEANS_UI_; - public static String Remote_cannot_be_empty_UI_; - public static String Errors_occurred_deleting_module_dependencies_UI_; - public static String Can_not_remove_module_dependency_from_project_UI_; - public static String INVALID_SELECTION_TITLE; - public static String ABS_PATHS_APP_EXT_REMOVED; - public static String Local_home_cannot_be_empty_UI_; - public static String USE_LOCAL_FOR_DIFFERENT_EAR; - public static String ENTERPRISE_APP_PROJECTS_UI_; - public static String MIGRATE_J2EE_PROJECTS_UI_; - public static String MIGRATION_SUCCESS_REPORT_UI_; - public static String FAILED_DEPLOY_DELETE; - public static String J2EE_VERSION_NOT_NEED_MIGRATION_UI_; - public static String MIGRATING_J2EE_VERSION_UI_; - public static String APPLICATION_CLIENTS_UI_; - public static String ServiceReferenceDataModel_ERROR_8; - public static String PROJECT_STRUCTURE_FAILED_UI_; - public static String LOCAL_CLIENT_ADD_SUCCESS_UI_; - public static String COMPONENT_ALREADYINEAR; - public static String COMPLETED_BACKEND_MIG; - public static String MIGRATE_EJB_SPEC_UI_; - public static String RenameModuleOperation_UI_0; - public static String CMP_11_IMPORT_20_UI_; - public static String J2EE_PROJECT_MIGRATION_TITLE_UI_; - public static String APP_CLIENT_ONLY_HAVE_REMOTE; - public static String MIGRATION_NOT_NEEDED_REPORT; - public static String LOCAL_CLIENT_VIEW_SCHEME_UI_; - public static String BINARY_MIGRATION_FAILED; - public static String ENTERPRISE_APPLICATION_UI_; - public static String INFORM_OPEN_EDITORS; - public static String EXTRACTED_IMPORTED_CLASSES; - public static String J2EE_VERSION_SUCCESS_UI_; - public static String SUFFIX_EXAMPLE_UI_; - public static String CONFIRMATION_TITLE; - public static String MIGRATION_ERRORS; - public static String APPLICATION_CLIENT_UI_; - public static String SPECIFY_SUFFIX_UI_; - public static String CONFIRM_MIGRATE_J2EE_13; - public static String PortComponentReferenceDataModel_ERROR_4; - public static String FAILED_LOCAL_CLIENT_CREATE; - public static String MessageDestReferenceDataModel_9; - public static String APPLICATION_CLIENT_PROJECTS_UI_; - public static String MessageDestReferenceDataModel_8; - public static String SOURCE_FOLDER_RENAME_FAILED; - public static String MessageDestReferenceDataModel_7; - public static String ENTERPRISE_BEANS_LIST_UI_; - public static String PROJECT_CLASSPATH_UPDATED; - public static String VERSION_NOT_SUPPORTED; - - static { - NLS.initializeMessages(BUNDLE_NAME, J2EECreationResourceHandler.class); - } - - public static String getString(String key, Object[] args) { - return NLS.bind(key, args); - } -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/J2EEJavaProjectInfo.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/J2EEJavaProjectInfo.java deleted file mode 100644 index bdbacddfe..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/J2EEJavaProjectInfo.java +++ /dev/null @@ -1,481 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.j2ee.internal.project; - - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -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.jem.internal.plugin.JavaProjectInfo; -import org.eclipse.wst.server.core.IRuntime; - -/** - * This class stores the info required for creating a new J2EE project; not all info will apply to - * all kinds of projects - */ -public class J2EEJavaProjectInfo extends JavaProjectInfo { - protected static final String SRCROOT_VAR = "JRE_SRCROOT"; //$NON-NLS-1$ - protected IProject project; - protected String jdkRTJarPath; - protected String projectName; - protected IPath projectLocation; - protected String javaOutputPath; - protected IClasspathEntry[] classpathEntries; - protected boolean shouldInitializeDefaultClasspath = true; - protected String natureId; - protected IRuntime serverTarget; - protected int moduleVersion; - - /** - * EJBProjectInfo constructor comment. - */ - public J2EEJavaProjectInfo() { - super(); - } - - /** - * EJBProjectInfo constructor comment. - */ - public J2EEJavaProjectInfo(IProject project) { - super(); - setProject(project); - } - - public IClasspathEntry[] calculateServerClasspathEntries() throws JavaModelException { - IJavaProject javaProject = getJavaProject(); - if (javaProject == null) - return null; - if (getProject().exists()) { - //We don't need to remove a server target anyomre as it need to be there - //ServerTargetManager.removeServerTarget(getProject(),null); - IClasspathEntry[] ces = javaProject.getRawClasspath(); - if (ces.length > 0) - addToClasspathEntries(ces); - } - addServerJdkRuntimeToClasspathEntries(); - addServerJarsToClasspathEntries(); - return classpathEntries; - } - - /** - * Sets up the default classpath for this project - */ - protected void addDefaultToClasspathEntries() { - addToClasspathEntries(computeDefaultJavaClasspath()); - } - - /** - * Set the corresponding jsp and servlet levels. Creation date: (11/09/00 10:05:24 AM) - */ - public void setJ2EEVersion(int newVersion) { - } - - - /** - * add the source folder to classpath dir (IClasspathEntry.CPE_SOURCE) - */ - public void addJavaSourceToClasspathEntries() { - IPath sourceClassPath = new Path(getFullSourcePath()); - addToClasspathEntries(new IClasspathEntry[]{JavaCore.newSourceEntry(sourceClassPath)}); - } - - public boolean addJdkJarToClasspathEntries(String jdkJarFullPathName) { - - IJavaProject javaProject = getJavaProject(); - if (javaProject == null) - return false; - - IClasspathEntry[] entry = new IClasspathEntry[1]; - Path path = new Path(jdkJarFullPathName); - if (!path.toFile().exists()) { - org.eclipse.jem.util.logger.proxy.Logger.getLogger().logError(J2EECreationResourceHandler.getString(J2EECreationResourceHandler.JdkJarFileDoesNotExist_UI, new Object[]{jdkJarFullPathName})); - return false; - } - - entry[0] = JavaCore.newLibraryEntry(path, null, null); - addToClasspathEntries(entry); - - return true; - } - - /** - * add rt.jar form the server.jdk plugin - */ - public void addServerJdkRuntimeToClasspathEntries() { - addToClasspathEntries(getServerJDKClasspathEntries()); - } - - public IClasspathEntry[] getServerJDKClasspathEntries() { - List list = new ArrayList(4); - //TODO This class should be deleted. - // if (isJ2EE13() - // || !org.eclipse.jst.j2ee.internal.internal.plugin.J2EEPlugin.hasDevelopmentRole()) { - // list.add(JavaCore.newVariableEntry(new - // Path(IEJBNatureConstants.SERVERJDK_50_PLUGINDIR_VARIABLE + "/jre/lib/rt.jar"), - // //$NON-NLS-1$ - // new Path(IEJBNatureConstants.SERVERJDK_50_PLUGINDIR_VARIABLE + "/src.jar"), //$NON-NLS-1$ - // new Path(IEJBNatureConstants.SERVERJDK_SRCROOT_VARIABLE))); //$NON-NLS-1$ - // } else { - // list.add(JavaCore.newVariableEntry(new - // Path(IEJBNatureConstants.SERVERJDK_PLUGINDIR_VARIABLE + "/jre/lib/rt.jar"), //$NON-NLS-1$ - // new Path(IEJBNatureConstants.SERVERJDK_PLUGINDIR_VARIABLE + "/src.jar"), //$NON-NLS-1$ - // new Path(IEJBNatureConstants.SERVERJDK_SRCROOT_VARIABLE))); //$NON-NLS-1$ - // } - return (IClasspathEntry[]) list.toArray(new IClasspathEntry[list.size()]); - } - - /** - * Adds entries to the class path for this project - */ - public void addToClasspathEntries(IClasspathEntry[] entries) { - - java.util.List list = new ArrayList(10); - // add the existing ones if any - if (classpathEntries != null) - list.addAll(Arrays.asList(classpathEntries)); - - // add the new ones - list.addAll(Arrays.asList(entries)); - - // convert - classpathEntries = new IClasspathEntry[list.size()]; - classpathEntries = (IClasspathEntry[]) list.toArray(classpathEntries); - - } - - public boolean addVariableJarToClasspathEntries(String fullPath) { - - IJavaProject javaProject = getJavaProject(); - if (javaProject == null) - return false; - - IClasspathEntry[] entry = new IClasspathEntry[1]; - entry[0] = JavaCore.newVariableEntry(new Path(fullPath), null, null); - addToClasspathEntries(entry); - return true; - } - - public boolean addVariableJarToClasspathEntriesWithAttachments(String fullPath, String srcPath, String srcRoot) { - - IJavaProject javaProject = getJavaProject(); - if (javaProject == null) - return false; - - IClasspathEntry[] entry = new IClasspathEntry[1]; - entry[0] = JavaCore.newVariableEntry(new Path(fullPath), new Path(srcPath), new Path(srcRoot)); - addToClasspathEntries(entry); - return true; - } - - /** - * Return the default classpath for projects of this kind; subclasses should override for - * setting up new projects - */ - protected IClasspathEntry[] computeDefaultJavaClasspath() { - IJavaProject javaProject = getJavaProject(); - if (javaProject == null) - return null; - addJavaSourceToClasspathEntries(); - if (serverTarget == null) { - addServerJdkRuntimeToClasspathEntries(); - addServerJarsToClasspathEntries(); - } - return classpathEntries; - } - - /** - * Sublcasses have to overide this method to set the server jars - */ - public void addServerJarsToClasspathEntries() { - - } - - /** - * Creates a project handle with a specified path. The project resource should <b>not </b> be - * created concretely here; - */ - public IProject createProjectHandle(IPath projectPath) { - return getWorkspace().getRoot().getProject(projectPath.segment(0)); - } - - public IClasspathEntry[] getClasspathEntries() { - if (classpathEntries == null) - initializeClasspathEntries(); - return classpathEntries; - } - - /** - * Insert the method's description here. Creation date: (11/09/00 10:05:24 AM) - * - * @return java.lang.String - */ - public java.lang.String getDefaultContextRoot() { - return null; - } - - /** - * Subclasses should override as necessary - */ - protected String getDefaultJavaOutputPath() { - return DEFAULT_JAVA_OUTPUT_PATH; - } - - /** - * Insert the method's description here. Creation date: (11/09/00 10:05:24 AM) - * - * @return java.lang.String - */ - public java.lang.String getDefaultUri() { - return projectName.replace(' ', '_') + ".jar"; //$NON-NLS-1$ - } - - /** - * Get the java output folder for the receiver, in the form of /project/ <output folder> - * - * @return java.lang.String - */ - public String getFullJavaOutputPath() { - return Path.ROOT.append(getProjectPath()).append(getJavaOutputPath()).toString(); - } - - /** - * Get the module path folder for the receiver in the form of /project/modulepath - * - * @return java.lang.String - */ - protected String getFullSourcePath() { - return Path.ROOT.append(getProjectPath()).append(getSourcePath()).toString(); - } - - /** - * Returns the project relative path of the java build destination - */ - public java.lang.String getJavaOutputPath() { - if (javaOutputPath == null) - javaOutputPath = getDefaultJavaOutputPath(); - return javaOutputPath; - } - - /** - * @param i - */ - public void setModuleVersion(int version) { - moduleVersion = version; - } - - public IJavaProject getJavaProject() { - // needed to get an IJavaProject to create classpaths from. - IProject aProject = getProject(); - if (aProject == null) - aProject = getWorkspace().getRoot().getProject(getProjectName()); - - return JavaCore.create(aProject); - } - - /** - * Return the absolute path of the default jdk rt.jar to use for this project - */ - public java.lang.String getJdkRTJarPath() { - return jdkRTJarPath; - } - - /** - * Return the project being created; checks the workspace for an existing project - */ - public IProject getProject() { - if (project == null) { - IProject aProject = getWorkspace().getRoot().getProject(getProjectName()); - if (aProject.exists()) - project = aProject; - } - return project; - } - - /** - * Return the location of the project in the file system. - * - * @return org.eclipse.core.runtime.IPath - */ - public IPath getProjectLocation() { - return projectLocation; - } - - /** - * Insert the method's description here. Creation date: (11/09/00 10:05:24 AM) - * - * @return java.lang.String - */ - public java.lang.String getProjectName() { - if (projectName == null && project != null) - projectName = project.getName(); - return projectName; - } - - public IPath getProjectPath() { - return new Path(getProjectName()); - } - - public IWorkspace getWorkspace() { - return org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin.getWorkspace(); - } - - /** - * Lazy initialization - useGetClasspathEntries - */ - protected void initializeClasspathEntries() { - if (shouldInitializeDefaultClasspath()) - computeDefaultJavaClasspath(); - else - classpathEntries = new IClasspathEntry[0]; - } - - /** - * Answer false by default - * - * @deprecated - Use getModuleVersion() with J2EEVersionConstants - */ - protected boolean isJ2EE13() { - return false; - } - - public IProject primGetProject() { - return project; - } - - public void removeClasspathEntry(IClasspathEntry entry) { - if (entry == null) - return; - - List list = new ArrayList(Arrays.asList(getClasspathEntries())); - list.remove(entry); - classpathEntries = (IClasspathEntry[]) list.toArray(new IClasspathEntry[list.size()]); - } - - /** - * Insert the method's description here. Creation date: (11/10/00 10:09:58 AM) - * - * @param newClassPathEntries - * org.eclipse.jdt.core.api.IClasspathEntry - */ - public void setClasspathEntries(IClasspathEntry[] newClasspathEntries) { - classpathEntries = newClasspathEntries; - } - - public void setJavaOutputPath(String path) { - javaOutputPath = path; - } - - public void setJdkRTJarPath(String path) { - jdkRTJarPath = path; - } - - public void setProject(IProject aProject) { - project = aProject; - } - - /** - * Set the location in the file system that the project is to be created. - * - * @param newProjectLocation - * IPath - */ - public void setProjectLocation(IPath newProjectLocation) { - projectLocation = newProjectLocation; - } - - /** - * Insert the method's description here. Creation date: (11/09/00 10:05:24 AM) - * - * @param newProjectName - * java.lang.String - */ - public void setProjectName(java.lang.String newProjectName) { - if (projectName != newProjectName) - setClasspathEntries(null); - projectName = newProjectName; - } - - public void setShouldInitializeDefaultClasspath(boolean value) { - shouldInitializeDefaultClasspath = value; - } - - public boolean shouldInitializeDefaultClasspath() { - return shouldInitializeDefaultClasspath; - } - - /** - * Gets the natureId. - * - * @return Returns a String - */ - public String getNatureId() { - if (natureId == null) - return getDefaultNatureId(); - return natureId; - } - - /** - * returns the correct nature id string based on the J2EE spec level being used - */ - public String getDefaultNatureId() { - return null; - } - - /** - * Sets the natureId. - * - * @param natureId - * The natureId to set - */ - public void setNatureId(String natureId) { - this.natureId = natureId; - } - - /** - * Get the correct WAS classpath variable based on the J2EE version. - */ - protected String getWASPluginVariable() { - //TODO This class needs to be deleted. - // if (isJ2EE13() - // || !org.eclipse.jst.j2ee.internal.internal.plugin.J2EEPlugin.hasDevelopmentRole()) - // return IEJBNatureConstants.WAS_50_PLUGINDIR_VARIABLE; - // else - // return IEJBNatureConstants.WAS_PLUGINDIR_VARIABLE; - return ""; //$NON-NLS-1$ - } - - public int getModuleVersion() { - return moduleVersion; - } - - /** - * @return - */ - public IRuntime getServerTarget() { - return serverTarget; - } - - /** - * @param target - */ - public void setServerTarget(IRuntime target) { - serverTarget = target; - } -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/J2EEProjectUtilities.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/J2EEProjectUtilities.java deleted file mode 100644 index bdf87db3f..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/J2EEProjectUtilities.java +++ /dev/null @@ -1,904 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.j2ee.internal.project; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.resources.ICommand; -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.IProjectDescription; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.emf.common.util.URI; -import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jem.java.JavaClass; -import org.eclipse.jem.java.JavaRefFactory; -import org.eclipse.jem.util.emf.workbench.ProjectUtilities; -import org.eclipse.jem.util.emf.workbench.WorkbenchByteArrayOutputStream; -import org.eclipse.jem.util.logger.proxy.Logger; -import org.eclipse.jem.util.plugin.JEMUtilPlugin; -import org.eclipse.jem.workbench.utility.JemProjectUtilities; -import org.eclipse.jst.j2ee.commonarchivecore.internal.Archive; -import org.eclipse.jst.j2ee.commonarchivecore.internal.EARFile; -import org.eclipse.jst.j2ee.commonarchivecore.internal.EJBJarFile; -import org.eclipse.jst.j2ee.commonarchivecore.internal.File; -import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.DeploymentDescriptorLoadException; -import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.OpenFailureException; -import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveManifest; -import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveManifestImpl; -import org.eclipse.jst.j2ee.commonarchivecore.internal.impl.CommonarchiveFactoryImpl; -import org.eclipse.jst.j2ee.commonarchivecore.internal.util.ArchiveUtil; -import org.eclipse.jst.j2ee.ejb.EJBJar; -import org.eclipse.jst.j2ee.ejb.EnterpriseBean; -import org.eclipse.jst.j2ee.internal.J2EEConstants; -import org.eclipse.jst.j2ee.internal.archive.operations.JavaComponentLoadStrategyImpl; -import org.eclipse.jst.j2ee.internal.common.classpath.J2EEComponentClasspathUpdater; -import org.eclipse.jst.j2ee.internal.componentcore.AppClientBinaryComponentHelper; -import org.eclipse.jst.j2ee.internal.componentcore.EJBBinaryComponentHelper; -import org.eclipse.jst.j2ee.internal.componentcore.JCABinaryComponentHelper; -import org.eclipse.jst.j2ee.internal.componentcore.WebBinaryComponentHelper; -import org.eclipse.jst.j2ee.internal.moduleextension.EarModuleManager; -import org.eclipse.jst.j2ee.project.facet.IJavaProjectMigrationDataModelProperties; -import org.eclipse.jst.j2ee.project.facet.JavaProjectMigrationDataModelProvider; -import org.eclipse.jst.j2ee.project.facet.JavaProjectMigrationOperation; -import org.eclipse.jst.server.core.FacetUtil; -import org.eclipse.wst.common.componentcore.ComponentCore; -import org.eclipse.wst.common.componentcore.internal.impl.ModuleURIUtil; -import org.eclipse.wst.common.componentcore.internal.util.ComponentUtilities; -import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualFolder; -import org.eclipse.wst.common.componentcore.resources.IVirtualResource; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -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.eclipse.wst.server.core.IRuntime; - -public class J2EEProjectUtilities extends ProjectUtilities { - - public static final String ENTERPRISE_APPLICATION = IModuleConstants.JST_EAR_MODULE; - - public static final String APPLICATION_CLIENT = IModuleConstants.JST_APPCLIENT_MODULE; - - public static final String EJB = IModuleConstants.JST_EJB_MODULE; - - public static final String DYNAMIC_WEB = IModuleConstants.JST_WEB_MODULE; - - public static final String UTILITY = IModuleConstants.JST_UTILITY_MODULE; - - public static final String JCA = IModuleConstants.JST_CONNECTOR_MODULE; - - public static final String STATIC_WEB = IModuleConstants.WST_WEB_MODULE; - - /** - * Return the absolute path of a loose archive in a J2EE application or WAR file - */ - public static IPath getRuntimeLocation(IProject aProject) { - if (JemProjectUtilities.isBinaryProject(aProject)) - return getBinaryProjectJARLocation(aProject); - return JemProjectUtilities.getJavaProjectOutputAbsoluteLocation(aProject); - } - - public static IPath getBinaryProjectJARLocation(IProject aProject) { - List sources = JemProjectUtilities.getLocalJARPathsFromClasspath(aProject); - if (!sources.isEmpty()) { - IPath path = (IPath) sources.get(0); - return aProject.getFile(path).getLocation(); - } - return null; - } - - public static Archive getClientJAR(EJBJarFile file, EARFile earFile) { - EJBJar jar = null; - try { - jar = file.getDeploymentDescriptor(); - } catch (DeploymentDescriptorLoadException exc) { - return null; - } - if (jar == null) - return null; - String clientJAR = jar.getEjbClientJar(); - if (clientJAR == null || clientJAR.length() == 0) - return null; - String normalized = ArchiveUtil.deriveEARRelativeURI(clientJAR, file.getURI()); - if (normalized != null) { - try { - File aFile = earFile.getFile(normalized); - if (aFile.isArchive() && !aFile.isModuleFile()) - return (Archive) aFile; - } catch (FileNotFoundException nothingThere) { - } - } - return null; - // TODO - release the DD here to free up space - } - - /** - * Append one IClasspathEntry to the build path of the passed project. If a classpath entry - * having the same path as the parameter already exists, then does nothing. - */ - public static void appendJavaClassPath(IProject p, IClasspathEntry newEntry) throws JavaModelException { - IJavaProject javaProject = JemProjectUtilities.getJavaProject(p); - if (javaProject == null) - return; - IClasspathEntry[] classpath = javaProject.getRawClasspath(); - List newPathList = new ArrayList(classpath.length); - for (int i = 0; i < classpath.length; i++) { - IClasspathEntry entry = classpath[i]; - // fix dup class path entry for .JETEmitter project - // Skip the entry to be added if it already exists - if (Platform.getOS().equals(Platform.OS_WIN32)) { - if (!entry.getPath().toString().equalsIgnoreCase(newEntry.getPath().toString())) - newPathList.add(entry); - else - return; - } else { - if (!entry.getPath().equals(newEntry.getPath())) - newPathList.add(entry); - else - return; - } - } - newPathList.add(newEntry); - IClasspathEntry[] newClasspath = (IClasspathEntry[]) newPathList.toArray(new IClasspathEntry[newPathList.size()]); - javaProject.setRawClasspath(newClasspath, new NullProgressMonitor()); - } - - public static Archive asArchiveFromBinary(String jarUri, IProject aProject) throws OpenFailureException { - IPath path = getBinaryProjectJARLocation(aProject); - if (path != null) { - String location = path.toOSString(); - Archive anArchive = CommonarchiveFactoryImpl.getActiveFactory().primOpenArchive(location); - anArchive.setURI(jarUri); - return anArchive; - } - return null; - } - - public static ArchiveManifest readManifest(IFile aFile) { - InputStream in = null; - try { - if (aFile == null || !aFile.exists()) - return null; - in = aFile.getContents(); - return new ArchiveManifestImpl(in); - } catch (Exception ex) { - org.eclipse.jem.util.logger.proxy.Logger.getLogger().logError(ex); - return null; - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException weTried) { - } - } - } - } - - public static ArchiveManifest readManifest(IProject p) { - InputStream in = null; - try { - IFile aFile = getManifestFile(p); - if (aFile == null || !aFile.exists()) - return null; - in = aFile.getContents(); - return new ArchiveManifestImpl(in); - } catch (Exception ex) { - org.eclipse.jem.util.logger.proxy.Logger.getLogger().logError(ex); - return null; - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException weTried) { - } - } - } - } - - /** - * Equavalent to calling getManifestFile(project, true) - * - * @param p - * @return - */ - public static IFile getManifestFile(IProject project) { - return getManifestFile(project, true); - } - - /** - * Returns the IFile handle to the J2EE manifest file for the specified - * project. If createIfNecessary is true, the MANIFEST.MF file will be - * created if it does not already exist. - * - * @param p - * @param createIfNecessary - * @return - */ - public static IFile getManifestFile(IProject p, boolean createIfNecessary) { - IVirtualComponent component = ComponentCore.createComponent(p); - try { - IFile file = ComponentUtilities.findFile(component, new Path(J2EEConstants.MANIFEST_URI)); - if (createIfNecessary && file == null) { - IVirtualFolder virtualFolder = component.getRootFolder(); - file = virtualFolder.getUnderlyingFolder().getFile(new Path(J2EEConstants.MANIFEST_URI)); - - try { - ManifestFileCreationAction.createManifestFile(file, p); - } catch (CoreException e) { - Logger.getLogger().log(e); - } catch (IOException e) { - Logger.getLogger().log(e); - } - } - return file; - } catch (CoreException ce) { - Logger.getLogger().log(ce); - } - return null; - } - - public static void writeManifest(IProject aProject, ArchiveManifest manifest) throws java.io.IOException { - writeManifest(aProject, getManifestFile(aProject), manifest); - } - - public static void writeManifest(IFile aFile, ArchiveManifest manifest) throws java.io.IOException { - writeManifest(aFile.getProject(), aFile, manifest); - } - - private static void writeManifest(IProject aProject, IFile aFile, ArchiveManifest manifest) throws java.io.IOException { - if (aFile != null) { - OutputStream out = new WorkbenchByteArrayOutputStream(aFile); - manifest.writeSplittingClasspath(out); - out.close(); - J2EEComponentClasspathUpdater.getInstance().queueUpdateModule(aProject); - } - } - - /** - * Keys are the EJB JAR files and the values are the respective client JARs; includes only key - * value pairs for which EJB Client JARs are defined and exist. - * - * @author schacher - */ - public static Map collectEJBClientJARs(EARFile earFile) { - if (earFile == null) - return Collections.EMPTY_MAP; - Map ejbClientJARs = null; - List ejbJARFiles = earFile.getEJBJarFiles(); - Archive clientJAR = null; - for (int i = 0; i < ejbJARFiles.size(); i++) { - EJBJarFile ejbJarFile = (EJBJarFile) ejbJARFiles.get(i); - clientJAR = getClientJAR(ejbJarFile, earFile); - if (clientJAR != null) { - if (ejbClientJARs == null) - ejbClientJARs = new HashMap(); - ejbClientJARs.put(ejbJarFile, clientJAR); - } - } - return ejbClientJARs == null ? Collections.EMPTY_MAP : ejbClientJARs; - } - - public static String computeRelativeText(String referencingURI, String referencedURI, EnterpriseBean bean) { - if (bean == null) - return null; - - String beanName = bean.getName(); - if (beanName == null) - return null; - - String relativeUri = computeRelativeText(referencingURI, referencedURI); - if (relativeUri == null) - return beanName; - return relativeUri + "#" + beanName; //$NON-NLS-1$ - } - - public static String computeRelativeText(String referencingURI, String referencedURI) { - if (referencingURI == null || referencedURI == null) - return null; - IPath pPre = new Path(referencingURI); - IPath pDep = new Path(referencedURI); - if (pPre.getDevice() != null || pDep.getDevice() != null) - return null; - pPre = pPre.makeRelative(); - pDep = pDep.makeRelative(); // referenced Archive path URI - - while (pPre.segmentCount() > 1 && pDep.segmentCount() > 1 && pPre.segment(0).equals(pDep.segment(0))) { - pPre = pPre.removeFirstSegments(1); - pDep = pDep.removeFirstSegments(1); - } - - IPath result = null; - StringBuffer buf = new StringBuffer(); - String segment = null; - do { - segment = pDep.lastSegment(); - pPre = pPre.removeLastSegments(1); - pDep = pDep.removeLastSegments(1); - if (segment != null) { - if (result == null) - result = new Path(segment); - else - result = new Path(segment).append(result); - } - if (!pPre.equals(pDep) && !pPre.isEmpty()) - buf.append("../"); //$NON-NLS-1$ - } while (!pPre.equals(pDep)); - - if (result != null) - buf.append(result.makeRelative().toString()); - - return buf.toString(); - } - - public static IProject getEJBProjectFromEJBClientProject(IProject ejbClientProject) { - try { - if (null != ejbClientProject && ejbClientProject.hasNature(JavaCore.NATURE_ID)) { - IProject[] allProjects = getAllProjects(); - for (int i = 0; i < allProjects.length; i++) { - if (null != EarModuleManager.getEJBModuleExtension().getEJBJar(allProjects[i])) { - if (ejbClientProject == EarModuleManager.getEJBModuleExtension().getDefinedEJBClientJARProject(allProjects[i])) { - return allProjects[i]; - } - } - } - } - } catch (CoreException e) { - } - return null; - } - - public static EnterpriseBean getEnterpriseBean(ICompilationUnit cu) { - IProject proj = cu.getJavaProject().getProject(); - EJBJar jar = EarModuleManager.getEJBModuleExtension().getEJBJar(proj); - if (null == jar) { - jar = EarModuleManager.getEJBModuleExtension().getEJBJar(getEJBProjectFromEJBClientProject(proj)); - } - if (jar != null) { - int index = cu.getElementName().indexOf('.'); - String className = cu.getElementName(); - if (index > 0) - className = className.substring(0, index); - JavaClass javaClass = (JavaClass) JavaRefFactory.eINSTANCE.reflectType(cu.getParent().getElementName(), className, jar.eResource().getResourceSet()); - return jar.getEnterpriseBeanWithReference(javaClass); - } - return null; - } - - public static IContainer getSourceFolderOrFirst(IProject p, String defaultSourceName) { - try { - IPath sourcePath = getSourcePathOrFirst(p, defaultSourceName); - if (sourcePath == null) - return null; - else if (sourcePath.isEmpty()) - return p; - else - return p.getFolder(sourcePath); - } catch (IllegalArgumentException ex) { - return null; - } - } - - public static void removeBuilders(IProject project, List builderids) throws CoreException { - IProjectDescription desc = project.getDescription(); - ICommand[] oldSpec = desc.getBuildSpec(); - int oldLength = oldSpec.length; - if (oldLength == 0) - return; - int remaining = 0; - // null out all commands that match the builder to remove - for (int i = 0; i < oldSpec.length; i++) { - if (builderids.contains(oldSpec[i].getBuilderName())) - oldSpec[i] = null; - else - remaining++; - } - // check if any were actually removed - if (remaining == oldSpec.length) - return; - ICommand[] newSpec = new ICommand[remaining]; - for (int i = 0, newIndex = 0; i < oldLength; i++) { - if (oldSpec[i] != null) - newSpec[newIndex++] = oldSpec[i]; - } - desc.setBuildSpec(newSpec); - project.setDescription(desc, IResource.NONE, null); - } - - public static IPath getSourcePathOrFirst(IProject p, String defaultSourceName) { - IJavaProject javaProj = JemProjectUtilities.getJavaProject(p); - if (javaProj == null) - return null; - IClasspathEntry[] cp = null; - try { - cp = javaProj.getRawClasspath(); - } catch (JavaModelException ex) { - JEMUtilPlugin.getLogger().logError(ex); - return null; - } - IClasspathEntry firstSource = null; - IPath defaultSourcePath = null; - if (defaultSourceName != null) - defaultSourcePath = createPath(p, defaultSourceName); - boolean found = false; - for (int i = 0; i < cp.length; i++) { - if (cp[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { - // check if it contains /META-INF/MANIFEST.MF - IPath sourceFolderPath = cp[i].getPath().removeFirstSegments(1); - IFolder sourceFolder = p.getFolder(sourceFolderPath); - if (isSourceFolderAnInputContainer(sourceFolder)) { - found = true; - if (firstSource == null) { - firstSource = cp[i]; - if (defaultSourcePath == null) - break; - } - if (cp[i].getPath().equals(defaultSourcePath)) - return defaultSourcePath.removeFirstSegments(1); - } - } - } - if (!found) { - for (int i = 0; i < cp.length; i++) { - if (cp[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { - if (firstSource == null) { - firstSource = cp[i]; - if (defaultSourcePath == null) - break; - } - if (cp[i].getPath().equals(defaultSourcePath)) - return defaultSourcePath.removeFirstSegments(1); - } - } - } - if (firstSource == null) - return null; - if (firstSource.getPath().segment(0).equals(p.getName())) - return firstSource.getPath().removeFirstSegments(1); - return null; - } - - public static boolean isSourceFolderAnInputContainer(IFolder sourceFolder) { - IContainer parent = sourceFolder; - while (true) { - parent = parent.getParent(); - if (parent == null) - return false; - if (parent instanceof IProject) - break; - } - IProject project = (IProject) parent; - try { - if (!project.isAccessible()) - return false; - if (isEJBProject(project)) { - return sourceFolder.findMember(J2EEConstants.EJBJAR_DD_URI) != null; - } else if (isApplicationClientProject(project)) { - return sourceFolder.findMember(J2EEConstants.APP_CLIENT_DD_URI) != null; - } else if (isDynamicWebProject(project)) { - return sourceFolder.findMember(J2EEConstants.WEBAPP_DD_URI) != null; - } else if (isJCAProject(project)) { - return sourceFolder.findMember(J2EEConstants.RAR_DD_URI) != null; - } - } catch (Exception e) { - e.printStackTrace(); - } - return false; - } - - public static Archive asArchive(String jarUri, IProject project, boolean exportSource) throws OpenFailureException { - JavaComponentLoadStrategyImpl strat = new JavaComponentLoadStrategyImpl(ComponentCore.createComponent(project)); - strat.setExportSource(exportSource); - return CommonarchiveFactoryImpl.getActiveFactory().primOpenArchive(strat, jarUri); - } - - public static boolean isProjectOfType(IProject project, String typeID) { - IFacetedProject facetedProject = null; - try { - facetedProject = ProjectFacetsManager.create(project); - } catch (CoreException e) { - return false; - } - - if (facetedProject != null && ProjectFacetsManager.isProjectFacetDefined(typeID)) { - IProjectFacet projectFacet = ProjectFacetsManager.getProjectFacet(typeID); - return projectFacet != null && facetedProject.hasProjectFacet(projectFacet); - } - return false; - } - - private static boolean isProjectOfType(IFacetedProject facetedProject, String typeID) { - - if (facetedProject != null && ProjectFacetsManager.isProjectFacetDefined(typeID)) { - IProjectFacet projectFacet = ProjectFacetsManager.getProjectFacet(typeID); - return projectFacet != null && facetedProject.hasProjectFacet(projectFacet); - } - return false; - } - - private static boolean isEARProject(IFacetedProject project) { - return isProjectOfType(project, ENTERPRISE_APPLICATION); - } - - private static boolean isDynamicWebProject(IFacetedProject project) { - return isProjectOfType(project, DYNAMIC_WEB); - } - - private static boolean isStaticWebProject(IFacetedProject project) { - return isProjectOfType(project, STATIC_WEB); - } - - private static boolean isEJBProject(IFacetedProject project) { - return isProjectOfType(project, EJB); - } - - private static boolean isJCAProject(IFacetedProject project) { - return isProjectOfType(project, JCA); - } - - private static boolean isApplicationClientProject(IFacetedProject project) { - return isProjectOfType(project, APPLICATION_CLIENT); - } - - private static boolean isUtilityProject(IFacetedProject project) { - return isProjectOfType(project, UTILITY); - } - - public static boolean isEARProject(IProject project) { - return isProjectOfType(project, ENTERPRISE_APPLICATION); - } - - public static boolean isDynamicWebComponent(IVirtualComponent component) { - if (component.isBinary()) { - return WebBinaryComponentHelper.handlesComponent(component); - } - return isProjectOfType(component.getProject(), DYNAMIC_WEB); - } - - public static boolean isDynamicWebProject(IProject project) { - return isProjectOfType(project, DYNAMIC_WEB); - } - - public static boolean isStaticWebProject(IProject project) { - return isProjectOfType(project, STATIC_WEB); - } - - public static boolean isEJBComponent(IVirtualComponent component) { - if (component.isBinary()) { - return EJBBinaryComponentHelper.handlesComponent(component); - } - return isProjectOfType(component.getProject(), EJB); - } - - public static boolean isEJBProject(IProject project) { - return isProjectOfType(project, EJB); - } - - public static boolean isJCAComponent(IVirtualComponent component) { - if (component.isBinary()) { - return JCABinaryComponentHelper.handlesComponent(component); - } - return isProjectOfType(component.getProject(), JCA); - } - - public static boolean isJCAProject(IProject project) { - return isProjectOfType(project, JCA); - } - - public static boolean isApplicationClientComponent(IVirtualComponent component) { - if (component.isBinary()) { - return AppClientBinaryComponentHelper.handlesComponent(component); - } - return isProjectOfType(component.getProject(), APPLICATION_CLIENT); - } - - public static boolean isApplicationClientProject(IProject project) { - return isProjectOfType(project, APPLICATION_CLIENT); - } - - public static boolean isUtilityProject(IProject project) { - return isProjectOfType(project, UTILITY); - } - - public static boolean isStandaloneProject(IProject project) { - return getReferencingEARProjects(project).length == 0; - } - - - - public static IProject[] getReferencingEARProjects(IProject project) { - if(project != null && isEARProject(project)){ - return new IProject[] {project}; - } - - List result = new ArrayList(); - IVirtualComponent component = ComponentCore.createComponent(project); - if (component != null) { - IVirtualComponent[] refComponents = component.getReferencingComponents(); - for (int i = 0; i < refComponents.length; i++) { - if (isEARProject(refComponents[i].getProject())) - result.add(refComponents[i].getProject()); - } - } - return (IProject[]) result.toArray(new IProject[result.size()]); - } - - /** - * Return all projects in workspace of the specified type - * - * @param type - - * use one of the static strings on this class as a type - * @return IProject[] - */ - public static IProject[] getAllProjectsInWorkspaceOfType(String type) { - IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); - List result = new ArrayList(); - for (int i = 0; i < projects.length; i++) { - if (isProjectOfType(projects[i], type)) - result.add(projects[i]); - } - return (IProject[]) result.toArray(new IProject[result.size()]); - } - - public static String getJ2EEComponentType(IVirtualComponent component) { - if (null != component) { - if (component.isBinary()) { - if (isApplicationClientComponent(component)) - return APPLICATION_CLIENT; - else if (isDynamicWebComponent(component)) - return DYNAMIC_WEB; - else if (isEJBComponent(component)) - return EJB; - else if (isJCAComponent(component)) - return JCA; - else - return UTILITY; - } - return getJ2EEProjectType(component.getProject()); - } - return ""; //$NON-NLS-1$ - } - - public static String getJ2EEProjectType(IProject project) { - if (null != project && project.isAccessible()) { - IFacetedProject facetedProject = null; - try { - facetedProject = ProjectFacetsManager.create(project); - } catch (CoreException e) { - return ""; //$NON-NLS-1$ - } - if (isApplicationClientProject(facetedProject)) - return APPLICATION_CLIENT; - else if (isDynamicWebProject(facetedProject)) - return DYNAMIC_WEB; - else if (isEJBProject(facetedProject)) - return EJB; - else if (isEARProject(facetedProject)) - return ENTERPRISE_APPLICATION; - else if (isJCAProject(facetedProject)) - return JCA; - else if (isStaticWebProject(facetedProject)) - return STATIC_WEB; - else if (isUtilityProject(facetedProject)) - return UTILITY; - } - return ""; //$NON-NLS-1$ - } - - public static IRuntime getServerRuntime(IProject project) throws CoreException { - if (project == null) - return null; - IFacetedProject facetedProject = ProjectFacetsManager.create(project); - if (facetedProject == null) - return null; - org.eclipse.wst.common.project.facet.core.runtime.IRuntime runtime = facetedProject.getRuntime(); - if (runtime == null) - return null; - return FacetUtil.getRuntime(runtime); - } - - public static String getJ2EEProjectVersion(IProject project) { - String type = getJ2EEProjectType(project); - IFacetedProject facetedProject = null; - IProjectFacet facet = null; - try { - facetedProject = ProjectFacetsManager.create(project); - facet = ProjectFacetsManager.getProjectFacet(type); - } catch (Exception e) { - // Not Faceted project or not J2EE Project - } - if (facet != null && facetedProject.hasProjectFacet(facet)) - return facetedProject.getInstalledVersion(facet).getVersionString(); - return null; - } - - public static JavaProjectMigrationOperation createFlexJavaProjectForProjectOperation(IProject project) { - IDataModel model = DataModelFactory.createDataModel(new JavaProjectMigrationDataModelProvider()); - model.setProperty(IJavaProjectMigrationDataModelProperties.PROJECT_NAME, project.getName()); - return new JavaProjectMigrationOperation(model); - } - - /** - * Retrieve all the source containers for a given virtual workbench component - * - * @param vc - * @return the array of IPackageFragmentRoots - */ - public static IPackageFragmentRoot[] getSourceContainers(IProject project) { - IJavaProject jProject = JemProjectUtilities.getJavaProject(project); - if (jProject == null) - return new IPackageFragmentRoot[0]; - List list = new ArrayList(); - IVirtualComponent vc = ComponentCore.createComponent(project); - IPackageFragmentRoot[] roots; - try { - roots = jProject.getPackageFragmentRoots(); - for (int i = 0; i < roots.length; i++) { - if (roots[i].getKind() != IPackageFragmentRoot.K_SOURCE) - continue; - IResource resource = roots[i].getResource(); - if (null != resource) { - IVirtualResource[] vResources = ComponentCore.createResources(resource); - boolean found = false; - for (int j = 0; !found && j < vResources.length; j++) { - if (vResources[j].getComponent().equals(vc)) { - if (!list.contains(roots[i])) - list.add(roots[i]); - found = true; - } - } - } - } - } catch (JavaModelException e) { - Logger.getLogger().logError(e); - } - return (IPackageFragmentRoot[]) list.toArray(new IPackageFragmentRoot[list.size()]); - } - - /** - * Retrieve all the output containers for a given virtual component. - * - * @param vc - * @return array of IContainers for the output folders - */ - public static IContainer[] getOutputContainers(IProject project) { - List result = new ArrayList(); - try { - if (!project.hasNature(JavaCore.NATURE_ID)) - return new IContainer[] {}; - } catch (Exception e) { - } - IPackageFragmentRoot[] sourceContainers = getSourceContainers(project); - for (int i = 0; i < sourceContainers.length; i++) { - IContainer outputFolder = getOutputContainer(project, sourceContainers[i]); - if (outputFolder != null && !result.contains(outputFolder)) - result.add(outputFolder); - } - return (IContainer[]) result.toArray(new IContainer[result.size()]); - } - - public static IContainer getOutputContainer(IProject project, IPackageFragmentRoot sourceContainer) { - try { - IJavaProject jProject = JavaCore.create(project); - IPath outputPath = sourceContainer.getRawClasspathEntry().getOutputLocation(); - if (outputPath == null) { - if (jProject.getOutputLocation().segmentCount() == 1) - return project; - return project.getFolder(jProject.getOutputLocation().removeFirstSegments(1)); - } - return project.getFolder(outputPath.removeFirstSegments(1)); - } catch (Exception e) { - } - return null; - } - - /** - * - * @param name - * @return - * @description the passed name should have either lib or var as its first segment e.g. - * lib/D:/foo/foo.jar or var/<CLASSPATHVAR>/foo.jar - */ - public static IPath getResolvedPathForArchiveComponent(String name) { - - URI uri = URI.createURI(name); - - String resourceType = uri.segment(0); - URI contenturi = ModuleURIUtil.trimToRelativePath(uri, 1); - String contentName = contenturi.toString(); - - if (resourceType.equals("lib")) { //$NON-NLS-1$ - // module:/classpath/lib/D:/foo/foo.jar - return Path.fromOSString(contentName); - - } else if (resourceType.equals("var")) { //$NON-NLS-1$ - - // module:/classpath/var/<CLASSPATHVAR>/foo.jar - String classpathVar = contenturi.segment(0); - URI remainingPathuri = ModuleURIUtil.trimToRelativePath(contenturi, 1); - String remainingPath = remainingPathuri.toString(); - - String[] classpathvars = JavaCore.getClasspathVariableNames(); - boolean found = false; - for (int i = 0; i < classpathvars.length; i++) { - if (classpathVar.equals(classpathvars[i])) { - found = true; - break; - } - } - if (found) { - IPath path = JavaCore.getClasspathVariable(classpathVar); - URI finaluri = URI.createURI(path.toOSString() + IPath.SEPARATOR + remainingPath); - return Path.fromOSString(finaluri.toString()); - } - } - return null; - } - - public static List getAllJavaNonFlexProjects() throws CoreException { - List nonFlexJavaProjects = new ArrayList(); - IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); - for (int i = 0; i < projects.length; i++) { - if (projects[i].isAccessible() && projects[i].hasNature(JavaCore.NATURE_ID) && !projects[i].hasNature(IModuleConstants.MODULE_NATURE_ID)) { - nonFlexJavaProjects.add(projects[i]); - } - } - return nonFlexJavaProjects; - } - - /** - * This method will retrieve the context root for the associated workbench module which is used - * by the server at runtime. This method is not yet completed as the context root has to be - * abstracted and added to the workbenchModule model. This API will not change though. Returns - * null for now. - * - * @return String value of the context root for runtime of the associated module - */ - public static String getServerContextRoot(IProject project) { - return ComponentUtilities.getServerContextRoot(project); - } - - /** - * This method will set the context root on the associated workbench module with the given - * string value passed in. This context root is used by the server at runtime. This method is - * not yet completed as the context root still needs to be abstracted and added to the workbench - * module model. This API will not change though. Does nothing as of now. - * - * @param contextRoot - * string - */ - public static void setServerContextRoot(IProject project, String contextRoot) { - ComponentUtilities.setServerContextRoot(project, contextRoot); - } -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/ManifestFileCreationAction.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/ManifestFileCreationAction.java deleted file mode 100644 index 78e2cddfa..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/ManifestFileCreationAction.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.j2ee.internal.project; - -import java.io.IOException; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jem.util.emf.workbench.WorkbenchByteArrayOutputStream; - -public class ManifestFileCreationAction { - - public static final String MANIFEST_HEADER = "Manifest-Version: 1.0\r\nClass-Path: \r\n\r\n"; //$NON-NLS-1$ - - /** - * Constructor for ManifestFileCreationAction. - */ - public ManifestFileCreationAction() { - super(); - } - - public static void createManifestFile(IFile file, IProject aJ2EEProject) throws CoreException, IOException { - try { - WorkbenchByteArrayOutputStream out = new WorkbenchByteArrayOutputStream(file); - out.write(MANIFEST_HEADER.getBytes()); - out.close(); - - } catch (IOException ioe) { - throw ioe; - } - } -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/ProjectSupportResourceHandler.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/ProjectSupportResourceHandler.java deleted file mode 100644 index 66416f0c2..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/ProjectSupportResourceHandler.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.j2ee.internal.project; - -import org.eclipse.osgi.util.NLS; - -public class ProjectSupportResourceHandler extends NLS { - private static final String BUNDLE_NAME = "projectsupport";//$NON-NLS-1$ - - private ProjectSupportResourceHandler() { - // Do not instantiate - } - - public static String Folder_name_cannot_be_the_same_as_Java_source_folder_5; - public static String Target_Update_Op; - public static String Operation_failed_due_to_SA_ERROR_; - public static String Creating_Web_Project____UI_; - public static String Could_not_rename_____2; - public static String A_web_project_must_be_open_and_must_exist_for_properties_to_be_edited_30; - public static String Operation_failed_due_to_IO_ERROR_; - public static String Cannot_clone_TaglibInfo_1_EXC_; - public static String Syntax_Error_in_the_links_UI_; - public static String Sync_WLP_Op; - public static String Generated_by_Web_Tooling_23; - public static String _1concat_EXC_; - public static String File_Serving_Enabler_7; - public static String Auto_Generated___File_Enabler_9; - public static String Not_a_web_project_29; - public static String Names_cannot_begin_or_end_with_whitespace_5; - public static String The_character_is_invalid_in_a_context_root; - public static String Folder_name_cannot_be_the_same_as_Java_class_folder_6; - public static String The_path_for_the_links_sta_EXC_; - public static String Operation_failed_due_to_Ja_ERROR_; - public static String Folder_name_cannot_be_empty_2; - public static String Error_importing_Module_Fil_EXC_; - public static String Operation_failed_due_to_Co_ERROR_; - public static String Folder_names_cannot_be_equal_4; - public static String Could_not_read_TLD_15; - public static String Folder_name_is_not_valid; - public static String Invalid_Servlet_Level_set_on_WebNature_3_EXC_; - public static String Context_Root_cannot_be_empty_2; - public static String Error_while_saving_links_s_EXC_; - public static String Sychronize_Class_Path_UI_; - public static String UNABLE_TO_LOAD_MODULE_ERROR_; - public static String Catalog_Lib_Directory__UI_; - public static String Update_ClassPath__UI_; - public static String Set_ClassPath__UI_; - public static String Names_cannot_contain_whitespace_; - - - static { - NLS.initializeMessages(BUNDLE_NAME, ProjectSupportResourceHandler.class); - } - - public static String getString(String key, Object[] args) { - return NLS.bind(key, args); - } -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/WTPJETEmitter.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/WTPJETEmitter.java deleted file mode 100644 index 87bec50ac..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/WTPJETEmitter.java +++ /dev/null @@ -1,594 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Mar 17, 2004 - * - * To change the template for this generated file go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -package org.eclipse.jst.j2ee.internal.project; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.Method; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.StringTokenizer; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IncrementalProjectBuilder; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.emf.codegen.CodeGenPlugin; -import org.eclipse.emf.codegen.jet.JETCompiler; -import org.eclipse.emf.codegen.jet.JETEmitter; -import org.eclipse.emf.codegen.jet.JETException; -import org.eclipse.jdt.core.IClasspathAttribute; -import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.core.IJavaModel; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.launching.JavaRuntime; -import org.eclipse.jem.util.logger.proxy.Logger; -import org.eclipse.jst.j2ee.internal.plugin.J2EEPluginResourceHandler; -import org.eclipse.osgi.util.ManifestElement; -import org.osgi.framework.Bundle; -import org.osgi.framework.Constants; - -/** - * @author schacher, mdelder - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -public class WTPJETEmitter extends JETEmitter { - - public static final String PROJECT_NAME = ".JETEmitters"; //$NON-NLS-1$ - private Map variables; - - private boolean intelligentLinkingEnabled = false; - - private JETCompiler jetCompiler; - - /** - * @param templateURI - */ - public WTPJETEmitter(String templateURI) { - super(templateURI); - } - - /** - * @param templateURIPath - * @param relativeTemplateURI - */ - public WTPJETEmitter(String[] templateURIPath, String relativeTemplateURI) { - super(templateURIPath, relativeTemplateURI); - } - - /** - * @param templateURI - * @param classLoader - */ - public WTPJETEmitter(String templateURI, ClassLoader classLoader) { - super(templateURI, classLoader); - try { - initialize(new NullProgressMonitor()); - } catch (JETException e) { - e.printStackTrace(); - } - } - - /** - * @param templateURIPath - * @param relativeTemplateURI - * @param classLoader - */ - public WTPJETEmitter(String[] templateURIPath, String relativeTemplateURI, ClassLoader classLoader) { - super(templateURIPath, relativeTemplateURI, classLoader); - } - - /** - * @param templateURIPath - * @param relativeTemplateURI - * @param classLoader - * @param encoding - */ - public WTPJETEmitter(String[] templateURIPath, String relativeTemplateURI, ClassLoader classLoader, String encoding) { - super(templateURIPath, relativeTemplateURI, classLoader, encoding); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.emf.codegen.jet.JETEmitter#initialize(org.eclipse.core.runtime.IProgressMonitor) - */ - public void initialize(IProgressMonitor progressMonitor) throws JETException { - - progressMonitor.beginTask("", 10); //$NON-NLS-1$ - progressMonitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_GeneratingJETEmitterFor_message", new Object[]{templateURI})); //$NON-NLS-1$ - - try { - // This ensures that the JRE variables are initialized. - try { - JavaRuntime.getDefaultVMInstall(); - } catch (Throwable throwable) { - // This is kind of nasty to come here. - URL jreURL = Platform.find(Platform.getBundle("org.eclipse.emf.codegen"),new Path("plugin.xml")); //$NON-NLS-1$ //$NON-NLS-2$ - IPath jrePath = new Path(Platform.asLocalURL(jreURL).getFile()); - jrePath = jrePath.removeLastSegments(1).append(new Path("../../jre/lib/rt.jar")); //$NON-NLS-1$ - if (!jrePath.equals(JavaCore.getClasspathVariable(JavaRuntime.JRELIB_VARIABLE))) { - JavaCore.setClasspathVariable(JavaRuntime.JRELIB_VARIABLE, jrePath, null); - } - } - - /* - * final JETCompiler jetCompiler = templateURIPath == null ? new - * MyJETCompiler(templateURI, encoding) : - */ - - getJetCompiler(); - - progressMonitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_JETParsing_message", new Object[]{jetCompiler.getResolvedTemplateURI()})); //$NON-NLS-1$ - jetCompiler.parse(); - progressMonitor.worked(1); - - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - jetCompiler.generate(outputStream); - final InputStream contents = new ByteArrayInputStream(outputStream.toByteArray()); - - final IWorkspace workspace = ResourcesPlugin.getWorkspace(); - IJavaModel javaModel = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); - if (!javaModel.isOpen()) { - javaModel.open(new SubProgressMonitor(progressMonitor, 1)); - } else { - progressMonitor.worked(1); - } - - final IProject project = workspace.getRoot().getProject(getProjectName()); - progressMonitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_JETPreparingProject_message", new Object[]{project.getName()})); //$NON-NLS-1$ - - IJavaProject javaProject; - if (!project.exists()) { - javaProject = createJavaProject(progressMonitor, workspace, project); - - initializeJavaProject(progressMonitor, project, javaProject); - - javaProject.close(); - } else { - project.open(new SubProgressMonitor(progressMonitor, 5)); - javaProject = JavaCore.create(project); - List rawClassPath = Arrays.asList(javaProject.getRawClasspath()); - for (int i=0; i<rawClassPath.size(); i++) { - IClasspathEntry entry = (IClasspathEntry) rawClassPath.get(i); - if (entry.getEntryKind()==IClasspathEntry.CPE_LIBRARY) - classpathEntries.add(entry); - } - } - - IPackageFragmentRoot sourcePackageFragmentRoot = openJavaProjectIfNecessary(progressMonitor, project, javaProject); - - String packageName = jetCompiler.getSkeleton().getPackageName(); - StringTokenizer stringTokenizer = new StringTokenizer(packageName, "."); //$NON-NLS-1$ - IProgressMonitor subProgressMonitor = new SubProgressMonitor(progressMonitor, 1); - subProgressMonitor.beginTask("", stringTokenizer.countTokens() + 4); //$NON-NLS-1$ - subProgressMonitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_CreateTargetFile_message")); //$NON-NLS-1$ - IContainer sourceContainer = (IContainer) sourcePackageFragmentRoot.getCorrespondingResource(); - while (stringTokenizer.hasMoreElements()) { - String folderName = stringTokenizer.nextToken(); - sourceContainer = sourceContainer.getFolder(new Path(folderName)); - if (!sourceContainer.exists()) { - ((IFolder) sourceContainer).create(false, true, new SubProgressMonitor(subProgressMonitor, 1)); - } - } - IFile targetFile = sourceContainer.getFile(new Path(jetCompiler.getSkeleton().getClassName() + ".java")); //$NON-NLS-1$ - if (!targetFile.exists()) { - subProgressMonitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_JETCreating_message", new Object[]{targetFile.getFullPath()})); //$NON-NLS-1$ - targetFile.create(contents, true, new SubProgressMonitor(subProgressMonitor, 1)); - } else { - subProgressMonitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_JETUpdating_message", new Object[]{targetFile.getFullPath()})); //$NON-NLS-1$ - targetFile.setContents(contents, true, true, new SubProgressMonitor(subProgressMonitor, 1)); - } - - boolean errors = performBuild(project, subProgressMonitor, targetFile); - - if (!errors) { - loadClass(workspace, project, javaProject, packageName, subProgressMonitor); - } - - subProgressMonitor.done(); - } catch (CoreException exception) { - throw new JETException(exception); - } catch (Exception exception) { - throw new JETException(exception); - } finally { - progressMonitor.done(); - } - - } - - /** - * @param progressMonitor - * @param project - * @param javaProject - * @return - * @throws JavaModelException - */ - protected IPackageFragmentRoot openJavaProjectIfNecessary(IProgressMonitor progressMonitor, final IProject project, IJavaProject javaProject) throws JavaModelException { - progressMonitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_JETOpeningJavaProject_message", new Object[]{project.getName()})); //$NON-NLS-1$ - javaProject.open(new SubProgressMonitor(progressMonitor, 1)); - - IPackageFragmentRoot[] packageFragmentRoots = javaProject.getPackageFragmentRoots(); - IPackageFragmentRoot sourcePackageFragmentRoot = null; - for (int j = 0; j < packageFragmentRoots.length; ++j) { - IPackageFragmentRoot packageFragmentRoot = packageFragmentRoots[j]; - if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_SOURCE) { - sourcePackageFragmentRoot = packageFragmentRoot; - break; - } - } - return sourcePackageFragmentRoot; - } - - /** - * @param progressMonitor - * @param project - * @param javaProject - * @throws CoreException - * @throws JavaModelException - */ - protected void initializeJavaProject(IProgressMonitor progressMonitor, final IProject project, IJavaProject javaProject) throws CoreException, JavaModelException { - progressMonitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_JETInitializingProject_message", new Object[]{project.getName()})); //$NON-NLS-1$ - IClasspathEntry classpathEntry = JavaCore.newSourceEntry(new Path("/" + project.getName() + "/src")); //$NON-NLS-1$ //$NON-NLS-2$ - - //IClasspathEntry jreClasspathEntry = JavaCore.newVariableEntry(new Path(JavaRuntime.JRELIB_VARIABLE), new Path(JavaRuntime.JRESRC_VARIABLE), new Path(JavaRuntime.JRESRCROOT_VARIABLE)); - IClasspathEntry jreClasspathEntry = JavaRuntime.getDefaultJREContainerEntry(); - - List classpath = new ArrayList(); - classpath.add(classpathEntry); - classpath.add(jreClasspathEntry); - classpath.addAll(classpathEntries); - - IFolder sourceFolder = project.getFolder(new Path("src")); //$NON-NLS-1$ - if (!sourceFolder.exists()) { - sourceFolder.create(false, true, new SubProgressMonitor(progressMonitor, 1)); - } - IFolder runtimeFolder = project.getFolder(new Path("runtime")); //$NON-NLS-1$ - if (!runtimeFolder.exists()) { - runtimeFolder.create(false, true, new SubProgressMonitor(progressMonitor, 1)); - } - - IClasspathEntry[] classpathEntryArray = (IClasspathEntry[]) classpath.toArray(new IClasspathEntry[classpath.size()]); - - javaProject.setRawClasspath(classpathEntryArray, new SubProgressMonitor(progressMonitor, 1)); - - javaProject.setOutputLocation(new Path("/" + project.getName() + "/runtime"), new SubProgressMonitor(progressMonitor, 1)); //$NON-NLS-1$ //$NON-NLS-2$ - - // appended from previous implementation - createClasspathEntries(project); - } - - /** - * @param progressMonitor - * @param workspace - * @param project - * @return - * @throws CoreException - */ - private IJavaProject createJavaProject(IProgressMonitor progressMonitor, final IWorkspace workspace, final IProject project) throws CoreException { - IJavaProject javaProject; - progressMonitor.subTask("JET creating project " + project.getName()); //$NON-NLS-1$ - project.create(new SubProgressMonitor(progressMonitor, 1)); - progressMonitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_JETCreatingProject_message", new Object[]{project.getName()})); //$NON-NLS-1$ - IProjectDescription description = workspace.newProjectDescription(project.getName()); - description.setNatureIds(new String[]{JavaCore.NATURE_ID}); - description.setLocation(null); - project.open(new SubProgressMonitor(progressMonitor, 1)); - project.setDescription(description, new SubProgressMonitor(progressMonitor, 1)); - - javaProject = JavaCore.create(project); - return javaProject; - } - - /** - * @param workspace - * @param project - * @param javaProject - * @param packageName - * @param subProgressMonitor - * @throws JavaModelException - * @throws MalformedURLException - * @throws ClassNotFoundException - * @throws SecurityException - */ - protected void loadClass(final IWorkspace workspace, final IProject project, IJavaProject javaProject, String packageName, IProgressMonitor subProgressMonitor) throws JavaModelException, MalformedURLException, ClassNotFoundException, SecurityException { - //IContainer targetContainer = - // workspace.getRoot().getFolder(javaProject.getOutputLocation()); - - subProgressMonitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_JETLoadingClass_message", new Object[]{jetCompiler.getSkeleton().getClassName() + ".class"})); //$NON-NLS-1$ //$NON-NLS-2$ - - // Construct a proper URL for relative lookup. - // - URL url = new File(project.getLocation() + "/" + javaProject.getOutputLocation().removeFirstSegments(1) + "/").toURL(); //$NON-NLS-1$ //$NON-NLS-2$ - URLClassLoader theClassLoader = new URLClassLoader(new URL[]{url}, classLoader); - Class theClass = theClassLoader.loadClass((packageName.length() == 0 ? "" : packageName + ".") + jetCompiler.getSkeleton().getClassName()); //$NON-NLS-1$ //$NON-NLS-2$ - String methodName = jetCompiler.getSkeleton().getMethodName(); - Method[] methods = theClass.getDeclaredMethods(); - for (int i = 0; i < methods.length; ++i) { - if (methods[i].getName().equals(methodName)) { - setMethod(methods[i]); - break; - } - } - } - - /** - * @param project - * @param subProgressMonitor - * @param targetFile - * @return - * @throws CoreException - */ - protected boolean performBuild(final IProject project, IProgressMonitor subProgressMonitor, IFile targetFile) throws CoreException { - subProgressMonitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_JETBuilding_message", new Object[]{project.getName()})); //$NON-NLS-1$ - project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new SubProgressMonitor(subProgressMonitor, 1)); - - IMarker[] markers = targetFile.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE); - boolean errors = false; - for (int i = 0; i < markers.length; ++i) { - IMarker marker = markers[i]; - if (marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO) == IMarker.SEVERITY_ERROR) { - errors = true; - subProgressMonitor.subTask(marker.getAttribute(IMarker.MESSAGE) + " : " + (CodeGenPlugin.getPlugin().getString("jet.mark.file.line", new Object[]{targetFile.getLocation(), marker.getAttribute(IMarker.LINE_NUMBER)}))); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - return errors; - } - - /** - * Create the correct classpath entries for the given project - * - * @param project - */ - protected void createClasspathEntries(IProject project) { - Assert.isNotNull(project, "A valid project is required in order to append to a classpath"); //$NON-NLS-1$ - String variableName = null; - String pluginId = null; - for (Iterator variablesKeyIterator = getVariables().keySet().iterator(); variablesKeyIterator.hasNext();) { - variableName = (String) variablesKeyIterator.next(); - pluginId = (String) getVariables().get(variableName); - if (hasOutputDirectory(pluginId)) - addLinkedFolderAsLibrary(project, variableName, pluginId); - else - addRuntimeJarsAsLibrary(project, pluginId); - } - } - - /** - * @param pluginId - * @return - */ - protected boolean hasOutputDirectory(String pluginId) { - Bundle bundle = Platform.getBundle(pluginId); - URL outputDirectory = Platform.find(bundle,new Path("bin")); //$NON-NLS-1$ - if (outputDirectory == null) - return false; - URL installLocation = null; - try { - installLocation = Platform.asLocalURL(outputDirectory); - } catch (IOException e) { - Logger.getLogger().logWarning(J2EEPluginResourceHandler.getString("Install_Location_Error_", new Object[]{installLocation}) + e); //$NON-NLS-1$ - } - File outputDirectoryFile = new File(installLocation.getPath());// new File(location); - return outputDirectoryFile.canRead() && outputDirectoryFile.isDirectory() && outputDirectoryFile.listFiles().length > 0; - } - - /** - * @param project - * @param variableName - * @param pluginId - */ - protected void addRuntimeJarsAsLibrary(IProject project, String pluginId) { - ManifestElement[] elements = null; - Bundle bundle = Platform.getBundle(pluginId); - try { - String requires = (String) bundle.getHeaders().get(Constants.BUNDLE_CLASSPATH); - elements = ManifestElement.parseHeader(Constants.BUNDLE_CLASSPATH, requires); - } catch (Exception e) { - Logger.getLogger().logError(e); - elements = new ManifestElement[0]; - } - IPath runtimeLibFullPath = null; - URL fullurl = null; - if (elements == null) { - if (bundle.getLocation().endsWith(".jar")) //$NON-NLS-1$ - runtimeLibFullPath = getJarredPluginPath(bundle); - appendToClassPath(runtimeLibFullPath,project); - return; - } - for (int i = 0; i < elements.length; i++) { - String value = elements[i].getValue(); - if (".".equals(value)) //$NON-NLS-1$ - value = "/"; //$NON-NLS-1$ - fullurl = Platform.getBundle(pluginId).getEntry(value); - // fix the problem with leading slash that caused dup classpath entries - if (fullurl==null) continue; - try { - runtimeLibFullPath = new Path(Platform.asLocalURL(fullurl).getPath()); - } catch (Exception e) { - Logger.getLogger().logError(e); - } - //TODO handle jar'ed plugins, this is a hack for now, need to find proper bundle API - if (bundle.getLocation().endsWith(".jar")) //$NON-NLS-1$ - runtimeLibFullPath = getJarredPluginPath(bundle); - if (!"jar".equals(runtimeLibFullPath.getFileExtension()) && !"zip".equals(runtimeLibFullPath.getFileExtension())) //$NON-NLS-1$ //$NON-NLS-2$ - continue; - appendToClassPath(runtimeLibFullPath,project); - } - } - - private void appendToClassPath(IPath runtimeLibFullPath, IProject project) { - IClasspathEntry entry = null; - entry = JavaCore.newLibraryEntry(runtimeLibFullPath, null,null,null,new IClasspathAttribute[]{},false); - try { - if (!classpathEntries.contains(entry)) - classpathEntries.add(entry); - //J2EEProjectUtilities.appendJavaClassPath(project, entry); - } catch (Exception e) { - Logger.getLogger().logError("Problem appending \"" + entry.getPath() + "\" to classpath of Project \"" + project.getName() + "\"."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - Logger.getLogger().logError(e); - } - } - - private IPath getJarredPluginPath(Bundle bundle) { - Path runtimeLibFullPath = null; - String jarPluginLocation = bundle.getLocation().substring(7); - Path jarPluginPath = new Path(jarPluginLocation); - // handle case where jars are installed outside of eclipse installation - if (jarPluginPath.isAbsolute()) - runtimeLibFullPath = jarPluginPath; - // handle normal case where all plugins under eclipse install - else { - String installPath = Platform.getInstallLocation().getURL().getPath(); - runtimeLibFullPath = new Path(installPath+"/"+jarPluginLocation); //$NON-NLS-1$ - } - return runtimeLibFullPath; - } - - /** - * @param progressMonitor - */ - protected void updateProgress(IProgressMonitor progressMonitor, String key) { - progressMonitor.subTask(getMessage(key)); - } - - /** - * @param progressMonitor - */ - protected void updateProgress(IProgressMonitor progressMonitor, String key, Object[] args) { - progressMonitor.subTask(getMessage(key, args)); - } - - protected String getMessage(String key) { - return CodeGenPlugin.getPlugin().getString(key); - } - - protected String getMessage(String key, Object[] args) { - return CodeGenPlugin.getPlugin().getString(key, args); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.emf.codegen.jet.JETEmitter#addVariable(java.lang.String, java.lang.String) - */ - public void addVariable(String variableName, String pluginID) throws JETException { - if (!isIntelligentLinkingEnabled()) - super.addVariable(variableName, pluginID); - else { - getVariables().put(variableName, pluginID); - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - IProject project = workspace.getRoot().getProject(getProjectName()); - if (project != null && project.exists()) - createClasspathEntries(project); - } - - } - - /** - * @return - */ - private boolean isIntelligentLinkingEnabled() { - return intelligentLinkingEnabled; - } - - /** - * @return - */ - private Map getVariables() { - if (variables == null) - variables = new HashMap(); - return variables; - } - - protected void addLinkedFolderAsLibrary(IProject project, String variableName, String pluginID) { - try { - URL outputDirectory = Platform.find(Platform.getBundle(pluginID),new Path("bin")); //$NON-NLS-1$ -// IPluginDescriptor pluginDescriptor = Platform.getPlugin(pluginID).getDescriptor(); -// URL outputDirectory = pluginDescriptor.find(new Path("bin")); //$NON-NLS-1$ - String pathString = Platform.asLocalURL(outputDirectory).getPath(); - if (pathString.endsWith("/")) //$NON-NLS-1$ - pathString = pathString.substring(0, pathString.length() - 1); - if (pathString.startsWith("/")) //$NON-NLS-1$ - pathString = pathString.substring(1, pathString.length()); - IPath path = new Path(pathString).makeAbsolute(); - - String binDirectoryVariable = variableName + "_BIN"; //$NON-NLS-1$ - IFolder linkedDirectory = project.getFolder(binDirectoryVariable); - if (!linkedDirectory.exists()) { - linkedDirectory.createLink(path, IResource.ALLOW_MISSING_LOCAL, null); - linkedDirectory.setDerived(true); - project.refreshLocal(IResource.DEPTH_INFINITE, null); - } - IClasspathEntry entry = JavaCore.newLibraryEntry(linkedDirectory.getFullPath(), null,null,null,new IClasspathAttribute[]{},false); - - if (!classpathEntries.contains(entry)) - classpathEntries.add(entry); - //J2EEProjectUtilities.appendJavaClassPath(project, entry); - - } catch (Exception e) { - Logger.getLogger().logError(e); - } - } - - /** - * @param intelligentLinkingEnabled - * The intelligentLinkingEnabled to set. - */ - public void setIntelligentLinkingEnabled(boolean intelligentLinkingEnabled) { - this.intelligentLinkingEnabled = intelligentLinkingEnabled; - } - - protected JETCompiler getJetCompiler() { - try { - if (jetCompiler == null) { - jetCompiler = templateURIPath == null ? new MyJETCompiler(templateURI, encoding) : new MyJETCompiler(templateURIPath, templateURI, encoding); - } - } catch (JETException e) { - Logger.getLogger().logError(e); - } - return jetCompiler; - } -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/test.jpage b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/test.jpage deleted file mode 100644 index e69de29bb..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/test.jpage +++ /dev/null |