Search in sources :

Example 91 with CoreException

use of org.eclipse.core.runtime.CoreException in project generator by mybatis.

the class ConfigurationComposite method isValid.

public boolean isValid() {
    try {
        String fileName = txtFileName.getText();
        String fullPath = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(fileName);
        File file = new File(fullPath);
        if (file.exists()) {
            ConfigVerifyer cv = new ConfigVerifyer(file);
            if (cv.isConfigurationFile()) {
                configurationTab.setErrorMessage(null);
                return true;
            } else {
                configurationTab.setErrorMessage(Messages.CONFIGURATION_TAB_INVALID_MESSAGE);
                return false;
            }
        } else {
            configurationTab.setErrorMessage(Messages.FILE_PICKER_FILE_DOESNT_EXIST);
            return false;
        }
    } catch (CoreException e) {
        return false;
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ConfigVerifyer(org.mybatis.generator.eclipse.ui.content.ConfigVerifyer) File(java.io.File) IFile(org.eclipse.core.resources.IFile)

Example 92 with CoreException

use of org.eclipse.core.runtime.CoreException in project generator by mybatis.

the class RunGeneratorAction method handleException.

private void handleException(Exception exception, Shell shell) {
    IStatus status;
    Throwable exceptionToHandle;
    if (exception instanceof InvocationTargetException) {
        exceptionToHandle = ((InvocationTargetException) exception).getCause();
    } else {
        exceptionToHandle = exception;
    }
    if (exceptionToHandle instanceof InterruptedException) {
        status = new Status(IStatus.CANCEL, Activator.PLUGIN_ID, IStatus.CANCEL, "Cancelled by User", exceptionToHandle);
    } else if (exceptionToHandle instanceof CoreException) {
        status = ((CoreException) exceptionToHandle).getStatus();
    } else {
        String message = "Unexpected error while running MyBatis Generator.";
        status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, message, exceptionToHandle);
        Activator.getDefault().getLog().log(status);
    }
    ErrorDialog.openError(shell, "MyBatis Generator", "Generation Failed", status, IStatus.ERROR | IStatus.CANCEL);
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 93 with CoreException

use of org.eclipse.core.runtime.CoreException in project generator by mybatis.

the class RunGeneratorThread method getJavaProject.

private IJavaProject getJavaProject() {
    IJavaProject answer = null;
    IProject project = inputFile.getProject();
    try {
        if (project.hasNature(JavaCore.NATURE_ID)) {
            answer = JavaCore.create(project);
        }
    } catch (CoreException e) {
        // ignore - something is wrong
        ;
    }
    return answer;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) IProject(org.eclipse.core.resources.IProject)

Example 94 with CoreException

use of org.eclipse.core.runtime.CoreException in project generator by mybatis.

the class EclipseShellCallback method getSpecificSourceFolder.

private IPackageFragmentRoot getSpecificSourceFolder(IJavaProject javaProject, String targetProject) throws ShellException {
    try {
        Path path = new Path("/" + targetProject);
        IPackageFragmentRoot pfr = javaProject.findPackageFragmentRoot(path);
        if (pfr == null) {
            StringBuffer sb = new StringBuffer();
            sb.append("Cannot find source folder ");
            sb.append(targetProject);
            throw new ShellException(sb.toString());
        }
        return pfr;
    } catch (CoreException e) {
        throw new ShellException(e.getStatus().getMessage(), e);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) CoreException(org.eclipse.core.runtime.CoreException) ShellException(org.mybatis.generator.exception.ShellException) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 95 with CoreException

use of org.eclipse.core.runtime.CoreException in project generator by mybatis.

the class EclipseShellCallback method getJavaProject.

private IJavaProject getJavaProject(String javaProjectName) throws ShellException {
    IJavaProject javaProject = projects.get(javaProjectName);
    if (javaProject == null) {
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        IProject project = root.getProject(javaProjectName);
        if (project.exists()) {
            boolean isJavaProject;
            try {
                isJavaProject = project.hasNature(JavaCore.NATURE_ID);
            } catch (CoreException e) {
                throw new ShellException(e.getStatus().getMessage(), e);
            }
            if (isJavaProject) {
                javaProject = JavaCore.create(project);
            } else {
                StringBuffer sb = new StringBuffer();
                sb.append("Project ");
                sb.append(javaProjectName);
                sb.append(" is not a Java project");
                throw new ShellException(sb.toString());
            }
        } else {
            StringBuffer sb = new StringBuffer();
            sb.append("Project ");
            sb.append(javaProjectName);
            sb.append(" does not exist");
            throw new ShellException(sb.toString());
        }
        projects.put(javaProjectName, javaProject);
    }
    return javaProject;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) ShellException(org.mybatis.generator.exception.ShellException) IProject(org.eclipse.core.resources.IProject)

Aggregations

CoreException (org.eclipse.core.runtime.CoreException)987 IStatus (org.eclipse.core.runtime.IStatus)264 Status (org.eclipse.core.runtime.Status)240 IFile (org.eclipse.core.resources.IFile)176 IOException (java.io.IOException)174 IProject (org.eclipse.core.resources.IProject)133 IResource (org.eclipse.core.resources.IResource)132 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)128 IPath (org.eclipse.core.runtime.IPath)126 ArrayList (java.util.ArrayList)125 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)100 File (java.io.File)95 InvocationTargetException (java.lang.reflect.InvocationTargetException)95 InputStream (java.io.InputStream)76 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)67 Path (org.eclipse.core.runtime.Path)61 ByteArrayInputStream (java.io.ByteArrayInputStream)54 IWorkspace (org.eclipse.core.resources.IWorkspace)53 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)52 IFileStore (org.eclipse.core.filesystem.IFileStore)51