Index: src/java/org/apache/ivyde/eclipse/cpcontainer/IvydeContainerPage.java =================================================================== --- src/java/org/apache/ivyde/eclipse/cpcontainer/IvydeContainerPage.java (revision 607532) +++ src/java/org/apache/ivyde/eclipse/cpcontainer/IvydeContainerPage.java (working copy) @@ -18,11 +18,12 @@ import org.apache.ivyde.eclipse.IvyPlugin; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; import org.eclipse.jdt.core.IClasspathEntry; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.internal.ui.wizards.TypedElementSelectionValidator; import org.eclipse.jdt.ui.wizards.IClasspathContainerPage; import org.eclipse.jdt.ui.wizards.IClasspathContainerPageExtension; import org.eclipse.jdt.ui.wizards.NewElementWizardPage; @@ -49,6 +50,7 @@ import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; +import org.eclipse.ui.dialogs.ISelectionStatusValidator; import org.eclipse.ui.model.WorkbenchContentProvider; import org.eclipse.ui.model.WorkbenchLabelProvider; import org.eclipse.ui.views.navigator.ResourceSorter; @@ -162,9 +164,24 @@ btn.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { ElementTreeSelectionDialog dialog= new ElementTreeSelectionDialog(Display.getDefault().getActiveShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider()); - Class[] acceptedClasses= new Class[] { IFile.class }; - TypedElementSelectionValidator validator= new TypedElementSelectionValidator(acceptedClasses, true); - dialog.setValidator(validator); + dialog.setValidator(new ISelectionStatusValidator() { + private IStatus errorStatus = new Status(IStatus.ERROR, IvyPlugin.ID, ""); //$NON-NLS-1$ + private IStatus OKStatus = new Status(IStatus.OK, IvyPlugin.ID, ""); //$NON-NLS-1$ + + public IStatus validate(Object[] selection) { + if (selection.length == 0) { + return errorStatus; + } + for (int i = 0; i < selection.length; i++) { + Object o = selection[i]; + if (!(o instanceof IFile)) { + return errorStatus; + } + } + return OKStatus; + } + + }); dialog.setTitle("choose ivy file"); dialog.setMessage("choose the ivy file to use to resolve dependencies"); dialog.setInput(_project.getProject()); Index: src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathUtil.java =================================================================== --- src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathUtil.java (revision 607532) +++ src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathUtil.java (working copy) @@ -2,15 +2,15 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Iterator; import java.util.List; import org.apache.ivyde.eclipse.IvyPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; -import org.eclipse.jdt.core.IClasspathContainer; import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; @@ -21,94 +21,116 @@ import org.eclipse.ui.PlatformUI; public class IvyClasspathUtil { - /** - * Adds an IvyDE classpath container to the list of existing classpath entries in the - * given project. - * - * @param project - * the project to which the cp container should be added - * @param projectRelativePath - * the path relative to the project of the module descriptor file - * to use for the classpath container - * @param confs - * the configurations to use in the classpath container. - */ - public static void addCPContainer( - IJavaProject project, IPath projectRelativePath, String confs) { - try { - IClasspathEntry newEntry = JavaCore.newContainerEntry( - new Path(IvyClasspathContainer.IVY_CLASSPATH_CONTAINER_ID) - .append(projectRelativePath) - .append(confs)); - - IClasspathEntry[] entries= project.getRawClasspath(); - - List newEntries = new ArrayList(Arrays.asList(entries)); - newEntries.add(newEntry); - entries = (IClasspathEntry[]) newEntries - .toArray(new IClasspathEntry[newEntries.size()]); - - project.setRawClasspath(entries, project.getOutputLocation(), null); - } catch (CoreException e) { - IvyPlugin.getDefault().log(e); - } - } - - public static void refreshContainer() { + + /** + * Adds an Ivy classpath container to the list of existing classpath + * entries in the given project. + * + * @param project + * the project to which the classpath container should be added + * @param projectRelativePath + * the path relative to the project of the module descriptor file + * to use for the classpath container + * @param confs + * the configurations to use in the classpath container. + */ + public static void addCPContainer(IJavaProject project, IPath projectRelativePath, String confs) { + try { + IClasspathEntry newEntry = JavaCore.newContainerEntry(new Path( + IvyClasspathContainer.IVY_CLASSPATH_CONTAINER_ID).append(projectRelativePath).append(confs)); + + IClasspathEntry[] entries = project.getRawClasspath(); + + List newEntries = new ArrayList(Arrays.asList(entries)); + newEntries.add(newEntry); + entries = (IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]); + + project.setRawClasspath(entries, project.getOutputLocation(), null); + } catch (CoreException e) { + IvyPlugin.log(e); + } + } + + /** + * Get the current selection in the Java package view + * + * @return the selection, null if unsuccessful + */ + public static IStructuredSelection getSelectionInJavaPackageView() { IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if(activeWorkbenchWindow != null) { + if (activeWorkbenchWindow == null) { + return null; + } ISelection sel = activeWorkbenchWindow.getSelectionService().getSelection(); - if(!(sel instanceof IStructuredSelection)) { - sel = activeWorkbenchWindow.getSelectionService().getSelection("org.eclipse.jdt.ui.PackageExplorer"); + IStructuredSelection selection; + if (sel instanceof IStructuredSelection) { + selection = (IStructuredSelection) sel; + } else { + sel = activeWorkbenchWindow.getSelectionService().getSelection("org.eclipse.jdt.ui.PackageExplorer"); + if (sel instanceof IStructuredSelection) { + selection = (IStructuredSelection) sel; + } else { + return null; } - if (sel instanceof IStructuredSelection) { - IStructuredSelection s = (IStructuredSelection)sel; - try { - IClasspathContainer fContainer= getClassPathContainer(s.getFirstElement()); - if (fContainer instanceof IvyClasspathContainer) { - IvyClasspathContainer ivycp = (IvyClasspathContainer)fContainer; - ivycp.refresh(); + } + return selection; + } + + /** + * Get the Ivy classpath container from the selection in the Java package view + * + * @param selection the selection + * @return + * @throws JavaModelException + */ + public static IvyClasspathContainer getIvyClasspathContainer(IStructuredSelection selection) throws JavaModelException { + if (selection == null) { + return null; + } + for (Iterator it = selection.iterator(); it.hasNext();) { + Object element = it.next(); + IvyClasspathContainer cp = null; + if (element instanceof IvyClasspathContainer) { + return (IvyClasspathContainer) element; + } + if (element instanceof IJavaProject) { + return getIvyClassPathContainer((IJavaProject) element); + } + if (element instanceof IAdaptable) { + cp = (IvyClasspathContainer) ((IAdaptable) element).getAdapter(IvyClasspathContainer.class); + if (cp == null) { + IJavaProject p = (IJavaProject) ((IAdaptable) element).getAdapter(IJavaProject.class); + if (p != null) { + cp = getIvyClassPathContainer(p); } - } catch (JavaModelException e) { - e.printStackTrace(); } } + if (cp != null) { + return cp; + } + if (element instanceof ClassPathContainer) { + // we shouldn't check against internal JDT API but there are not adaptable to useful class + return getIvyClassPathContainer(((ClassPathContainer) element).getJavaProject()); + } } + return null; } - public static void refreshContainer(IJavaProject project) { - IvyClasspathContainer ivycp; - try { - ivycp = (IvyClasspathContainer)getIvyClassPathContainer(project); - if(ivycp != null) { - ivycp.refresh(); - } - } catch (JavaModelException e) { - } - } - - private static IClasspathContainer getClassPathContainer(Object o) throws JavaModelException { - if (o instanceof ClassPathContainer) { - ClassPathContainer cp = (ClassPathContainer) o; - IJavaProject project = cp.getJavaProject(); - return JavaCore.getClasspathContainer(cp.getClasspathEntry().getPath(), project); + + /** + * Search the Ivy classpath container within the specified Java project + * + * @param javaProject the project to search into + * @return the Ivy classpath container if found, otherwise return null + * @throws JavaModelException + */ + public static IvyClasspathContainer getIvyClassPathContainer(IJavaProject javaProject) throws JavaModelException { + IClasspathEntry[] cpe = javaProject.getRawClasspath(); + for (int i = 0; i < cpe.length; i++) { + IClasspathEntry entry = cpe[i]; + if (IvyClasspathContainer.isIvyClasspathContainer(entry.getPath())) { + return (IvyClasspathContainer) JavaCore.getClasspathContainer(entry.getPath(), javaProject); + } } - if (o instanceof IJavaProject) { - return getIvyClassPathContainer((IJavaProject) o); - } - if (o instanceof IJavaElement) { - return getClassPathContainer(((IJavaElement) o).getParent()); - } return null; } - - public static IvyClasspathContainer getIvyClassPathContainer(IJavaProject javaProject) throws JavaModelException { - IClasspathEntry[] cpe = javaProject.getRawClasspath(); - for (int i = 0; i < cpe.length; i++) { - IClasspathEntry entry = cpe[i]; - if (IvyClasspathContainer.isIvyClasspathContainer(entry.getPath())) { - return (IvyClasspathContainer) JavaCore.getClasspathContainer(entry.getPath(), javaProject); - } - } - return null; - } } Index: src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainer.java =================================================================== --- src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainer.java (revision 607532) +++ src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainer.java (working copy) @@ -8,7 +8,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashSet; @@ -16,7 +15,8 @@ import java.util.Map; import org.apache.ivy.Ivy; -import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.cache.RepositoryCacheManager; +import org.apache.ivy.core.cache.ResolutionCacheManager; import org.apache.ivy.core.event.IvyEvent; import org.apache.ivy.core.event.IvyListener; import org.apache.ivy.core.event.download.EndArtifactDownloadEvent; @@ -45,14 +45,13 @@ import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jdt.core.IAccessRule; import org.eclipse.jdt.core.IClasspathAttribute; import org.eclipse.jdt.core.IClasspathContainer; import org.eclipse.jdt.core.IClasspathEntry; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.internal.core.ClasspathAttribute; -import org.eclipse.jdt.internal.core.ClasspathEntry; import org.eclipse.jdt.internal.core.JavaModelManager; import org.eclipse.swt.widgets.Display; @@ -68,15 +67,17 @@ private IProgressMonitor _monitor; private IProgressMonitor _dlmonitor; private Ivy _ivy; - private CacheManager _cacheMgr; + private ResolutionCacheManager resolutionCacheManager; private boolean _usePreviousResolveIfExist; private int _workPerArtifact = 100; private boolean _notify; + private RepositoryCacheManager repoCacheManager; public IvyResolveJob(Ivy ivy, boolean usePreviousResolveIfExist, boolean notify) { super("Resolve "+_javaProject.getProject().getName()+"/"+_ivyXmlPath+" dependencies"); _ivy = ivy; - _cacheMgr = CacheManager.getInstance(_ivy.getSettings()); + resolutionCacheManager = _ivy.getSettings().getResolutionCacheManager(); + repoCacheManager = _ivy.getSettings().getDefaultRepositoryCacheManager(); _usePreviousResolveIfExist = usePreviousResolveIfExist; _notify = notify; } @@ -184,7 +185,7 @@ // we check if all required configurations have been // resolved for (int i = 0; i < confs.length; i++) { - File report = _cacheMgr.getConfigurationResolveReportInCache(ResolveOptions + File report = resolutionCacheManager.getConfigurationResolveReportInCache(ResolveOptions .getDefaultResolveId(md), confs[i]); boolean resolved = false; if (report.exists()) { @@ -311,13 +312,13 @@ for (Iterator iter = all.iterator(); iter.hasNext();) { Artifact artifact = (Artifact)iter.next(); if (IvyPlugin.accept(_javaProject, artifact)) { - Path classpathArtifact = new Path(_cacheMgr.getArchiveFileInCache(artifact).getAbsolutePath()); + Path classpathArtifact = getPathFromCahe(artifact); Path sourcesArtifact = getSourcesArtifactPath(artifact, all); Path javadocArtifact = getJavadocArtifactPath(artifact, all); paths.add(JavaCore.newLibraryEntry(classpathArtifact, getSourceAttachment(classpathArtifact, sourcesArtifact), getSourceAttachmentRoot(classpathArtifact, sourcesArtifact), - ClasspathEntry.NO_ACCESS_RULES, + new IAccessRule[0], getExtraAttribute(classpathArtifact, javadocArtifact), false)); } @@ -327,7 +328,12 @@ return classpathEntries; } - private Path getSourcesArtifactPath(Artifact artifact, Collection all) { + private Path getPathFromCahe(Artifact artifact) { + return new Path(_ivy.getSettings().getDefaultRepositoryCacheBasedir() + File.separator + + repoCacheManager.getArchivePathInCache(artifact)); + } + + private Path getSourcesArtifactPath(Artifact artifact, Collection all) { _monitor.subTask("searching sources for "+artifact); for (Iterator iter = all.iterator(); iter.hasNext();) { Artifact a = (Artifact)iter.next(); @@ -335,7 +341,7 @@ a.getId().getRevision().equals(artifact.getId().getRevision()) && IvyPlugin.isSources(_javaProject, a)) { - return new Path(_cacheMgr.getArchiveFileInCache(a).getAbsolutePath()); + return getPathFromCahe(a); } } if (IvyPlugin.shouldTestNonDeclaredSources(_javaProject)) { @@ -354,7 +360,7 @@ a.getId().equals(artifact.getId()) && IvyPlugin.isJavadoc(_javaProject, a)) { - return new Path(_cacheMgr.getArchiveFileInCache(a).getAbsolutePath()); + return getPathFromCahe(a); } } if (IvyPlugin.shouldTestNonDeclaredSources(_javaProject)) { @@ -383,7 +389,7 @@ // a badly saved artifact origin // we could go back to _cacheMgr.getArchiveFileInCache(metaArtifact) // when IVY-430 is resolved - File metaArtifactFile = _cacheMgr.getArchiveFileInCache(metaArtifact, null); + File metaArtifactFile = getPathFromCahe(metaArtifact).toFile(); File attempt = new File(metaArtifactFile.getAbsolutePath()+".notfound"); if (metaArtifactFile.exists()) { return new Path(metaArtifactFile.getAbsolutePath()); @@ -391,7 +397,7 @@ return null; } else { Message.info("checking "+metaType+" for "+artifact); - _ivy.getResolveEngine().download(metaArtifact, _cacheMgr, false); + _ivy.getResolveEngine().download(metaArtifact, false); if (metaArtifactFile.exists()) { return new Path(metaArtifactFile.getAbsolutePath()); } else { @@ -442,7 +448,7 @@ } if (url != null) { - result.add(new ClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, url + result.add(JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, url .toExternalForm())); } return (IClasspathAttribute[]) result.toArray(new IClasspathAttribute[result.size()]); @@ -692,7 +698,7 @@ URL ivyURL = _ivyXmlFile.toURL(); ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance().parseDescriptor(ivy.getSettings(), ivyURL, false); String resolveId = ResolveOptions.getDefaultResolveId(md); - return CacheManager.getInstance(ivy.getSettings()) + return ivy.getSettings().getResolutionCacheManager() .getConfigurationResolveReportInCache( resolveId, md.getConfigurationsNames()[0]).toURL(); Index: src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathInitializer.java =================================================================== --- src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathInitializer.java (revision 607532) +++ src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathInitializer.java (working copy) @@ -1,6 +1,7 @@ package org.apache.ivyde.eclipse.cpcontainer; +import org.apache.ivy.util.Message; import org.apache.ivyde.eclipse.IvyPlugin; import org.apache.ivyde.eclipse.cpcontainer.fragmentinfo.IPackageFragmentExtraInfo; import org.eclipse.core.runtime.CoreException; @@ -89,7 +90,16 @@ //force refresh of ivy classpath entry in ui thread Display.getDefault().asyncExec(new Runnable() { public void run() { - IvyClasspathUtil.refreshContainer(project); + IvyClasspathContainer ivycp; + try { + ivycp = IvyClasspathUtil.getIvyClassPathContainer(project); + } catch (JavaModelException e) { + Message.error(e.getMessage()); + return; + } + if (ivycp != null) { + ivycp.refresh(); + } } }); } Index: src/java/org/apache/ivyde/eclipse/IvyPlugin.java =================================================================== --- src/java/org/apache/ivyde/eclipse/IvyPlugin.java (revision 607532) +++ src/java/org/apache/ivyde/eclipse/IvyPlugin.java (working copy) @@ -15,7 +15,6 @@ import java.util.Set; import org.apache.ivy.Ivy; -import org.apache.ivy.core.IvyContext; import org.apache.ivy.core.module.descriptor.Artifact; import org.apache.ivy.util.Message; import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathContainer; @@ -25,14 +24,16 @@ import org.apache.ivyde.eclipse.ui.preferences.PreferenceConstants; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ProjectScope; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.IScopeContext; +import org.eclipse.jdt.core.IJavaModel; import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.internal.core.JavaModelManager; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.util.IPropertyChangeListener; @@ -59,9 +60,10 @@ //Resource bundle. private ResourceBundle resourceBundle; private IvyConsole console; - - - /** + + private IJavaModel javaModel; + + /** * The constructor. */ public IvyPlugin() { @@ -93,6 +95,7 @@ } } }); + javaModel = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); log(IStatus.INFO, "IvyDE plugin started", null); } @@ -209,7 +212,7 @@ public static void ivyConfPathChanged() { try { - IJavaProject[] projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects(); + IJavaProject[] projects = plugin.javaModel.getJavaProjects(); String defaultConfURL = getIvyconfURL(); for (int i = 0; i < projects.length; i++) { if (getStrictIvyconfURL(projects[i]) == null) { @@ -222,7 +225,7 @@ public static void typesChanged(String typesCode) { try { - IJavaProject[] projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects(); + IJavaProject[] projects = plugin.javaModel.getJavaProjects(); String defaultConfURL = getIvyconfURL(); for (int i = 0; i < projects.length; i++) { if ("[inherited]".equals(getTypesString(projects[i], typesCode))) { Index: src/java/org/apache/ivyde/eclipse/ui/actions/CreateContainerAction.java =================================================================== --- src/java/org/apache/ivyde/eclipse/ui/actions/CreateContainerAction.java (revision 607532) +++ src/java/org/apache/ivyde/eclipse/ui/actions/CreateContainerAction.java (working copy) @@ -1,30 +1,13 @@ package org.apache.ivyde.eclipse.ui.actions; -import java.util.ArrayList; -import java.util.List; - -import org.apache.ivyde.eclipse.IvyPlugin; -import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathContainer; import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathUtil; import org.eclipse.core.resources.IFile; -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.SubProgressMonitor; -import org.eclipse.jdt.core.IClasspathContainer; -import org.eclipse.jdt.core.IClasspathEntry; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.internal.corext.buildpath.ClasspathModifier; -import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer; -import org.eclipse.jdt.internal.ui.wizards.buildpaths.CPListElement; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; import org.eclipse.ui.PlatformUI; Index: src/java/org/apache/ivyde/eclipse/ui/actions/ResolveAllAction.java =================================================================== --- src/java/org/apache/ivyde/eclipse/ui/actions/ResolveAllAction.java (revision 607532) +++ src/java/org/apache/ivyde/eclipse/ui/actions/ResolveAllAction.java (working copy) @@ -34,7 +34,7 @@ protected IStatus run(IProgressMonitor monitor) { Collection containers = IvyPlugin.getDefault().getAllContainers(); monitor.beginTask("Resolve all dependencies", containers.size()); - for (Iterator iter = IvyPlugin.getDefault().getAllContainers().iterator(); iter.hasNext();) { + for (Iterator iter = containers.iterator(); iter.hasNext();) { if (monitor.isCanceled()) { return Status.CANCEL_STATUS; } Index: src/java/org/apache/ivyde/eclipse/ui/actions/OpenIvyFileAction.java =================================================================== --- src/java/org/apache/ivyde/eclipse/ui/actions/OpenIvyFileAction.java (revision 607532) +++ src/java/org/apache/ivyde/eclipse/ui/actions/OpenIvyFileAction.java (working copy) @@ -6,31 +6,24 @@ */ package org.apache.ivyde.eclipse.ui.actions; -import java.io.File; - +import org.apache.ivy.util.Message; import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathContainer; +import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathUtil; import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jdt.core.IClasspathContainer; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaCore; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility; -import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer; import org.eclipse.jface.action.IAction; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IEditorRegistry; +import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.ide.IDE; -import org.eclipse.ui.internal.WorkbenchPage; -import org.eclipse.ui.internal.ide.DialogUtil; -import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; import org.eclipse.ui.part.FileEditorInput; @@ -49,38 +42,43 @@ * @see IWorkbenchWindowActionDelegate#run */ public void run(IAction action) { - ISelection sel = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection(); - if (sel instanceof IStructuredSelection) { - IStructuredSelection s = (IStructuredSelection)sel; - Object o = s.getFirstElement(); - if (o instanceof ClassPathContainer) { - IPath path = ((ClassPathContainer)o).getClasspathEntry().getPath(); - IJavaProject project = ((ClassPathContainer)o).getJavaProject(); + IvyClasspathContainer cp; + try { + cp = IvyClasspathUtil.getIvyClasspathContainer(IvyClasspathUtil.getSelectionInJavaPackageView()); + } catch (JavaModelException e) { + Message.error(e.getMessage()); + return; + } + if (cp != null) { + IFile file = cp.getIvyFile(); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + if (file != null) { try { - IClasspathContainer fContainer= JavaCore.getClasspathContainer(path, project); - if (fContainer instanceof IvyClasspathContainer) { - IvyClasspathContainer ivycp = (IvyClasspathContainer)fContainer; - - IFile file = ivycp.getIvyFile(); - IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - if (file != null) { - try { - String editorId = "org.apache.ivyde.editors.IvyEditor"; - page.openEditor(new FileEditorInput(file), editorId, true); - // only remember the default editor if the open succeeds - IDE.setDefaultEditor(file, editorId); - } catch (PartInitException e) { - DialogUtil.openError(page.getWorkbenchWindow().getShell(), - IDEWorkbenchMessages.OpenWithMenu_dialogTitle, - e.getMessage(), e); - } - } + String editorId = "org.apache.ivyde.editors.IvyEditor"; + page.openEditor(new FileEditorInput(file), editorId, true); + // only remember the default editor if the open succeeds + IDE.setDefaultEditor(file, editorId); + } catch (PartInitException e) { + Shell parent = page.getWorkbenchWindow().getShell(); + String title = "Problems Opening Editor"; + String message = e.getMessage(); + // Check for a nested CoreException + CoreException nestedException = null; + IStatus status = e.getStatus(); + if (status != null && status.getException() instanceof CoreException) { + nestedException = (CoreException) status.getException(); } - } catch (Exception e) { - // TODO : log exc - System.err.println(e.getMessage()); + if (nestedException != null) { + // Open an error dialog and include the extra + // status information from the nested CoreException + ErrorDialog.openError(parent, title, message, nestedException + .getStatus()); + } else { + // Open a regular error dialog since there is no + // extra information to display + MessageDialog.openError(parent, title, message); + } } - } } } Index: src/java/org/apache/ivyde/eclipse/ui/actions/RefreshAction.java =================================================================== --- src/java/org/apache/ivyde/eclipse/ui/actions/RefreshAction.java (revision 607532) +++ src/java/org/apache/ivyde/eclipse/ui/actions/RefreshAction.java (working copy) @@ -1,20 +1,13 @@ package org.apache.ivyde.eclipse.ui.actions; +import org.apache.ivy.util.Message; import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathContainer; import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathUtil; -import org.eclipse.core.runtime.IPath; -import org.eclipse.jdt.core.IClasspathContainer; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; -import org.eclipse.ui.PlatformUI; -import org.eclipse.jface.dialogs.MessageDialog; public class RefreshAction implements IWorkbenchWindowActionDelegate { @@ -32,10 +25,18 @@ * @see IWorkbenchWindowActionDelegate#run */ public void run(IAction action) { - IvyClasspathUtil.refreshContainer(); + IvyClasspathContainer cp; + try { + cp = IvyClasspathUtil.getIvyClasspathContainer(IvyClasspathUtil.getSelectionInJavaPackageView()); + } catch (JavaModelException e) { + Message.error(e.getMessage()); + return; + } + if (cp != null) { + cp.refresh(); + } } - /** * Selection in the workbench has been changed. We * can change the state of the 'real' action here Index: src/java/org/apache/ivyde/eclipse/ui/actions/ResolveAction.java =================================================================== --- src/java/org/apache/ivyde/eclipse/ui/actions/ResolveAction.java (revision 607532) +++ src/java/org/apache/ivyde/eclipse/ui/actions/ResolveAction.java (working copy) @@ -1,19 +1,13 @@ package org.apache.ivyde.eclipse.ui.actions; +import org.apache.ivy.util.Message; import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathContainer; -import org.eclipse.core.runtime.IPath; -import org.eclipse.jdt.core.IClasspathContainer; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaCore; +import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathUtil; import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; -import org.eclipse.ui.PlatformUI; -import org.eclipse.jface.dialogs.MessageDialog; public class ResolveAction implements IWorkbenchWindowActionDelegate { @@ -31,24 +25,16 @@ * @see IWorkbenchWindowActionDelegate#run */ public void run(IAction action) { - ISelection sel = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection(); - if (sel instanceof IStructuredSelection) { - IStructuredSelection s = (IStructuredSelection)sel; - Object o = s.getFirstElement(); - if (o instanceof ClassPathContainer) { - IPath path = ((ClassPathContainer)o).getClasspathEntry().getPath(); - IJavaProject project = ((ClassPathContainer)o).getJavaProject(); - try { - IClasspathContainer fContainer= JavaCore.getClasspathContainer(path, project); - if (fContainer instanceof IvyClasspathContainer) { - IvyClasspathContainer ivycp = (IvyClasspathContainer)fContainer; - ivycp.resolve(); - } - } catch (JavaModelException e) { - } - - } + IvyClasspathContainer cp; + try { + cp = IvyClasspathUtil.getIvyClasspathContainer(IvyClasspathUtil.getSelectionInJavaPackageView()); + } catch (JavaModelException e) { + Message.error(e.getMessage()); + return; } + if (cp != null) { + cp.resolve(); + } } /** Index: src/java/org/apache/ivyde/eclipse/ui/views/ReportView.java =================================================================== --- src/java/org/apache/ivyde/eclipse/ui/views/ReportView.java (revision 607532) +++ src/java/org/apache/ivyde/eclipse/ui/views/ReportView.java (working copy) @@ -4,12 +4,8 @@ import org.apache.ivy.util.Message; import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathContainer; -import org.eclipse.core.runtime.IPath; -import org.eclipse.jdt.core.IClasspathContainer; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaCore; +import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathUtil; import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.swt.SWT; @@ -38,29 +34,24 @@ public void selectionChanged(IWorkbenchPart part, ISelection sel) { if (sel instanceof IStructuredSelection) { - IStructuredSelection s = (IStructuredSelection)sel; - Object o = s.getFirstElement(); - if (o instanceof ClassPathContainer) { - IPath path = ((ClassPathContainer)o).getClasspathEntry().getPath(); - IJavaProject project = ((ClassPathContainer)o).getJavaProject(); - try { - IClasspathContainer fContainer= JavaCore.getClasspathContainer(path, project); - if (fContainer instanceof IvyClasspathContainer) { - _browser.setUrl(""); - IvyClasspathContainer ivycp = (IvyClasspathContainer)fContainer; - URL report = ivycp.getReportUrl(); - if (report != null) { - if (!_browser.setUrl(report.toExternalForm())) { - _browser.setUrl(""); - Message.warn("impossible to set report view url to "+report.toExternalForm()); - } - } + IvyClasspathContainer ivycp; + try { + ivycp = IvyClasspathUtil.getIvyClasspathContainer((IStructuredSelection) sel); + } catch (JavaModelException e) { + Message.error(e.getMessage()); + return; + } + if (ivycp != null) { + _browser.setUrl(""); + URL report = ivycp.getReportUrl(); + if (report != null) { + if (!_browser.setUrl(report.toExternalForm())) { + _browser.setUrl(""); + Message.warn("impossible to set report view url to " + report.toExternalForm()); } - } catch (JavaModelException e) { } - } } - } + } } Index: build.properties =================================================================== --- build.properties (revision 607532) +++ build.properties (working copy) @@ -7,7 +7,7 @@ ivy.minimum.javaversion=1.4 debug.mode=on -ivy.install.version=2.0.0-alpha2-incubating +ivy.install.version=2.0.0-beta1 source.ivyde-eclipse.jar = src/java/ output.ivyde-eclipse.jar = bin/ Index: build.xml =================================================================== --- build.xml (revision 607532) +++ build.xml (working copy) @@ -2,7 +2,7 @@ - + -