Author: vyemialyanchyk
Date: 2009-11-23 12:21:03 -0500 (Mon, 23 Nov 2009)
New Revision: 18788
Removed:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConsoleConfigUnloadJarChange.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/DeleteResourceParticipant.java
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/execution/DefaultExecutionContext.java
Log:
http://opensource.atlassian.com/projects/hibernate/browse/HBX-936 - revert changes back,
could be unsafe for core part, cause it change classpath order, should be released in a
better manner
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java 2009-11-23
17:03:30 UTC (rev 18787)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java 2009-11-23
17:21:03 UTC (rev 18788)
@@ -30,15 +30,12 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
-import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -47,11 +44,8 @@
import org.dom4j.DocumentException;
import org.dom4j.Node;
import org.dom4j.io.DOMWriter;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
import org.eclipse.datatools.connectivity.IConnectionProfile;
import org.eclipse.datatools.connectivity.ProfileManager;
-import org.eclipse.jdt.apt.core.internal.JarClassLoader;
import org.eclipse.osgi.util.NLS;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
@@ -77,11 +71,9 @@
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
-@SuppressWarnings("restriction")
public class ConsoleConfiguration implements ExecutionContextHolder {
private ExecutionContext executionContext;
- private ClassLoader classLoader = null;
private Map<String, FakeDelegatingDriver> fakeDrivers = new HashMap<String,
FakeDelegatingDriver>();
@@ -114,20 +106,8 @@
// reseting state
configuration = null;
closeSessionFactory();
- cleanUpClassLoader();
}
- public void cleanUpClassLoader() {
- ClassLoader classLoaderTmp = classLoader;
- while (classLoaderTmp != null) {
- if (classLoaderTmp instanceof JarClassLoader) {
- ((JarClassLoader)classLoaderTmp).close();
- }
- classLoaderTmp = classLoaderTmp.getParent();
- }
- classLoader = null;
- }
-
public void build() {
configuration = buildWith(null, true);
fireConfigurationBuilt();
@@ -257,102 +237,39 @@
}
return customClassPathURLs;
}
-
- public URL[] getCustomClassPathURLs_Jars() {
- URL[] classPathURLs = getCustomClassPathURLs();
- ArrayList<URL> res = new ArrayList<URL>();
- for (int i = 0; i < classPathURLs.length; i++) {
- String fileName = classPathURLs[i].getFile();
- fileName = fileName.toLowerCase();
- if (fileName.endsWith(".jar")) { //$NON-NLS-1$
- res.add(classPathURLs[i]);
- }
- }
- return res.toArray(new URL[0]);
- }
-
- protected URL[] getCustomClassPathURLs_NotJars() {
- URL[] classPathURLs = getCustomClassPathURLs();
- ArrayList<URL> res = new ArrayList<URL>();
- for (int i = 0; i < classPathURLs.length; i++) {
- String fileName = classPathURLs[i].getFile();
- fileName = fileName.toLowerCase();
- if (!fileName.endsWith(".jar")) { //$NON-NLS-1$
- res.add(classPathURLs[i]);
- }
- }
- return res.toArray(new URL[0]);
- }
-
- protected ClassLoader createJarClassLoader() {
- URL[] customClassPathURLs_Jars = getCustomClassPathURLs_Jars();
- List<File> filesTmp = new ArrayList<File>();
- for (int i = 0; i < customClassPathURLs_Jars.length; i++) {
- String filePath = customClassPathURLs_Jars[i].getPath();
- IPath resourcePath = new Path(filePath);
- File resourceFile = resourcePath.toFile();
- //if (resourceFile.exists()) {
- filesTmp.add(resourceFile);
- //}
- }
- final List<File> files = filesTmp;
- JarClassLoader jarClassLoader = AccessController.doPrivileged(new
PrivilegedAction<JarClassLoader>() {
- public JarClassLoader run() {
- return new JarClassLoader(files, getParentClassLoader()) {
- @Override
- public Enumeration<URL> getResources(String name) throws IOException {
- return null;
- }
- };
- }
- });
- return jarClassLoader;
- }
-
- protected ClassLoader createURLClassLoader() {
- final URL[] customClassPathURLs = getCustomClassPathURLs_NotJars();
- URLClassLoader urlClassLoader = AccessController.doPrivileged(new
PrivilegedAction<URLClassLoader>() {
- public URLClassLoader run() {
- return new URLClassLoader(customClassPathURLs, createJarClassLoader()) {
- protected Class<?> findClass(String name) throws ClassNotFoundException {
- try {
- return super.findClass(name);
- } catch (ClassNotFoundException cnfe) {
- throw cnfe;
- }
- }
-
- protected synchronized Class<?> loadClass(String name, boolean resolve) throws
ClassNotFoundException {
- try {
- return super.loadClass(name, resolve);
- } catch (ClassNotFoundException cnfe) {
- throw cnfe;
- }
- }
-
- public Class<?> loadClass(String name) throws ClassNotFoundException {
- try {
- return super.loadClass(name);
- } catch (ClassNotFoundException cnfe) {
- throw cnfe;
- }
- }
- };
- }
- });
- return urlClassLoader;
- }
/**
* @return
*
*/
public Configuration buildWith(final Configuration cfg, final boolean includeMappings)
{
- if (classLoader == null) {
- classLoader = createURLClassLoader();
- }
- executionContext = new DefaultExecutionContext(getName(), classLoader);
+ URL[] customClassPathURLs = getCustomClassPathURLs();
+ executionContext = new DefaultExecutionContext( getName(), new URLClassLoader(
customClassPathURLs, getParentClassLoader() ) {
+ protected Class<?> findClass(String name) throws ClassNotFoundException {
+ try {
+ return super.findClass( name );
+ } catch(ClassNotFoundException cnfe) {
+ throw cnfe;
+ }
+ }
+ protected synchronized Class<?> loadClass(String name, boolean resolve) throws
ClassNotFoundException {
+ try {
+ return super.loadClass( name, resolve );
+ } catch(ClassNotFoundException cnfe) {
+ throw cnfe;
+ }
+ }
+
+ public Class<?> loadClass(String name) throws ClassNotFoundException {
+ try {
+ return super.loadClass( name );
+ } catch(ClassNotFoundException cnfe) {
+ throw cnfe;
+ }
+ }
+ });
+
Configuration result = (Configuration) executionContext.execute(new
ExecutionContext.Command() {
public Object execute() {
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/execution/DefaultExecutionContext.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/execution/DefaultExecutionContext.java 2009-11-23
17:03:30 UTC (rev 18787)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/execution/DefaultExecutionContext.java 2009-11-23
17:21:03 UTC (rev 18788)
@@ -21,6 +21,7 @@
*/
package org.hibernate.console.execution;
+import java.net.URLClassLoader;
import java.util.Map;
import java.util.WeakHashMap;
@@ -30,13 +31,13 @@
public class DefaultExecutionContext implements ExecutionContext {
- final private ClassLoader configurationClassLoader;
+ final private URLClassLoader configurationClassLoader;
private volatile int installs;
private Map<Thread, ClassLoader> previousLoaders = new WeakHashMap<Thread,
ClassLoader>();
final String key;
- public DefaultExecutionContext(String key, ClassLoader loader) {
+ public DefaultExecutionContext(String key, URLClassLoader loader) {
configurationClassLoader = loader;
this.key = key;
}
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml 2009-11-23
17:03:30 UTC (rev 18787)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml 2009-11-23
17:21:03 UTC (rev 18788)
@@ -640,19 +640,6 @@
label="hql editor colors coloring highlighting query"/>
</extension>
<extension
- point="org.eclipse.ltk.core.refactoring.deleteParticipants">
- <deleteParticipant
-
class="org.hibernate.eclipse.launch.core.refactoring.DeleteResourceParticipant"
-
id="org.hibernate.eclipse.launch.core.refactoring.DeleteResourceParticipant"
- name="Console Configuration Resource Delete Participant">
- <enablement>
- <with variable="element">
- <instanceof
value="org.eclipse.core.resources.IResource"/>
- </with>
- </enablement>
- </deleteParticipant>
- </extension>
- <extension
point="org.eclipse.ltk.core.refactoring.renameParticipants">
<renameParticipant
class="org.hibernate.eclipse.launch.core.refactoring.ConsoleConfigurationITypeRenameParticipant"
Deleted:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConsoleConfigUnloadJarChange.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConsoleConfigUnloadJarChange.java 2009-11-23
17:03:30 UTC (rev 18787)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConsoleConfigUnloadJarChange.java 2009-11-23
17:21:03 UTC (rev 18788)
@@ -1,72 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2009 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.hibernate.eclipse.launch.core.refactoring;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.ltk.core.refactoring.Change;
-import org.eclipse.ltk.core.refactoring.RefactoringStatus;
-import org.hibernate.console.ConsoleConfiguration;
-
-/**
- * @author Vitali Yemialyanchyk
- */
-public class ConsoleConfigUnloadJarChange extends Change {
-
- protected ConsoleConfiguration config;
-
- public ConsoleConfigUnloadJarChange(ConsoleConfiguration config) {
- this.config = config;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ltk.core.refactoring.Change#getModifiedElement()
- */
- @Override
- public Object getModifiedElement() {
- return config;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ltk.core.refactoring.Change#getName()
- */
- @Override
- public String getName() {
- return config.getName();
- }
-
- /* (non-Javadoc)
- * @see
org.eclipse.ltk.core.refactoring.Change#initializeValidationData(org.eclipse.core.runtime.IProgressMonitor)
- */
- @Override
- public void initializeValidationData(IProgressMonitor pm) {
- }
-
- /* (non-Javadoc)
- * @see
org.eclipse.ltk.core.refactoring.Change#isValid(org.eclipse.core.runtime.IProgressMonitor)
- */
- @Override
- public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException,
- OperationCanceledException {
- return new RefactoringStatus();
- }
-
- /* (non-Javadoc)
- * @see
org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
- */
- @Override
- public Change perform(IProgressMonitor pm) throws CoreException {
- config.cleanUpClassLoader();
- return null;
- }
-
-}
Deleted:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/DeleteResourceParticipant.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/DeleteResourceParticipant.java 2009-11-23
17:03:30 UTC (rev 18787)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/DeleteResourceParticipant.java 2009-11-23
17:21:03 UTC (rev 18788)
@@ -1,102 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2009 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.hibernate.eclipse.launch.core.refactoring;
-
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.ltk.core.refactoring.Change;
-import org.eclipse.ltk.core.refactoring.RefactoringStatus;
-import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
-import org.eclipse.ltk.core.refactoring.participants.DeleteParticipant;
-import org.hibernate.console.ConsoleConfiguration;
-import org.hibernate.console.KnownConfigurations;
-import org.hibernate.eclipse.console.HibernateConsoleMessages;
-
-/**
- * @author Vitali Yemialyanchyk
- */
-public class DeleteResourceParticipant extends DeleteParticipant {
-
- private String path2Del = null;
-
- /* (non-Javadoc)
- * @see
org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#checkConditions(org.eclipse.core.runtime.IProgressMonitor,
org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext)
- */
- @Override
- public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext
context)
- throws OperationCanceledException {
- return new RefactoringStatus();
- }
-
- @Override
- public Change createPreChange(IProgressMonitor pm) throws CoreException,
OperationCanceledException {
- if (path2Del == null) {
- return null;
- }
- List<Change> changes = new ArrayList<Change>();
- ConsoleConfiguration[] configs =
KnownConfigurations.getInstance().getConfigurations();
- for (int i = 0; i < configs.length; i++) {
- final ConsoleConfiguration config = configs[i];
- final URL[] classPathURLs_Jars = config.getCustomClassPathURLs_Jars();
- for (int j = 0; j < classPathURLs_Jars.length; j++) {
- String path2Jar = classPathURLs_Jars[i].getPath();
- if (path2Jar.startsWith(path2Del)) {
- changes.add(new ConsoleConfigUnloadJarChange(config));
- break;
- }
- }
- }
- return HibernateRefactoringUtil.createChangesFromList(changes, getName());
- }
-
- @Override
- public Change createChange(IProgressMonitor pm) throws CoreException,
OperationCanceledException {
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#getName()
- */
- @Override
- public String getName() {
- return
HibernateConsoleMessages.DeleteResourceParticipant_hibernate_configurations_updates;
- }
-
- /* (non-Javadoc)
- * @see
org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#initialize(java.lang.Object)
- */
- @Override
- protected boolean initialize(Object element) {
- boolean res = false;
- IResource res2Del = (IResource)element;
- String path2Del = res2Del.getLocationURI().getPath();
- ConsoleConfiguration[] configs =
KnownConfigurations.getInstance().getConfigurations();
- for (int i = 0; i < configs.length; i++) {
- final ConsoleConfiguration config = configs[i];
- final URL[] classPathURLs_Jars = config.getCustomClassPathURLs_Jars();
- for (int j = 0; j < classPathURLs_Jars.length; j++) {
- String path2Jar = classPathURLs_Jars[i].getPath();
- if (path2Jar.startsWith(path2Del)) {
- res = true;
- }
- }
- }
- this.path2Del = res ? path2Del : null;
- return res;
- }
-
-}