1 11 package org.eclipse.jdt.internal.ui.text.correction; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.core.runtime.Assert; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.core.runtime.IStatus; 20 import org.eclipse.core.runtime.Status; 21 22 import org.eclipse.debug.core.DebugPlugin; 23 import org.eclipse.debug.core.ILaunchConfiguration; 24 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 25 import org.eclipse.debug.core.ILaunchManager; 26 import org.eclipse.debug.core.model.ILaunchConfigurationDelegate; 27 28 import org.eclipse.debug.ui.IDebugUIConstants; 29 30 import org.eclipse.jdt.core.IJavaProject; 31 32 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; 33 import org.eclipse.jdt.launching.IRuntimeClasspathEntry; 34 35 import org.eclipse.jdt.internal.ui.JavaPlugin; 36 37 42 public final class SerialVersionComputationHelper { 43 44 45 private static final String LAUNCH_CONFIG_TYPE= "org.eclipse.jdt.ui.serial.support"; 47 48 private static final String SERIAL_SUPPORT_CLASS= "org.eclipse.jdt.internal.ui.text.correction.SerialVersionComputer"; 50 66 public static long[] computeSerialIDs(final IRuntimeClasspathEntry[] classPath, final IJavaProject project, final String [] classNames, final IProgressMonitor monitor) throws CoreException { 67 Assert.isNotNull(classPath); 68 Assert.isNotNull(project); 69 Assert.isNotNull(classNames); 70 Assert.isNotNull(monitor); 71 long[] result= {}; 72 final ILaunchConfigurationWorkingCopy copy= DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(LAUNCH_CONFIG_TYPE).newInstance(null, LAUNCH_CONFIG_TYPE + System.currentTimeMillis()); 73 copy.setAttribute(IDebugUIConstants.ATTR_PRIVATE, true); 74 copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false); 75 copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, SERIAL_SUPPORT_CLASS); 76 final StringBuffer buffer= new StringBuffer (); 77 for (int index= 0; index < classNames.length; index++) { 78 buffer.append(classNames[index]); 79 buffer.append(' '); 80 } 81 copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, buffer.toString()); 82 copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, project.getElementName()); 83 final List mementos= new ArrayList (classPath.length); 84 IRuntimeClasspathEntry entry= null; 85 for (int index= 0; index < classPath.length; index++) { 86 entry= classPath[index]; 87 mementos.add(entry.getMemento()); 88 } 89 copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, mementos); 90 final ILaunchConfiguration configuration= copy.doSave(); 91 try { 92 final ILaunchConfigurationDelegate delegate= configuration.getType().getDelegate(ILaunchManager.RUN_MODE); 93 if (delegate instanceof SerialVersionLaunchConfigurationDelegate) { 94 final SerialVersionLaunchConfigurationDelegate extension= (SerialVersionLaunchConfigurationDelegate) delegate; 95 configuration.launch(ILaunchManager.RUN_MODE, monitor, true, false); 96 result= extension.getSerialVersionIDs(); 97 final String message= extension.getErrorMessage(); 98 if (message != null) 99 throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, message, null)); 100 } else 101 throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, CorrectionMessages.SerialVersionHashProposal_wrong_launch_delegate, null)); 102 } finally { 103 configuration.delete(); 104 } 105 return result; 106 } 107 108 111 private SerialVersionComputationHelper() { 112 } 114 } 115 | Popular Tags |