Search in sources :

Example 96 with IPath

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

the class MyBatisGeneratorClasspathResolver method getGeneratorPath.

public static IPath getGeneratorPath() {
    //$NON-NLS-1$
    Bundle bundle = Platform.getBundle("org.mybatis.generator.core");
    if (bundle == null) {
        return null;
    }
    try {
        //$NON-NLS-1$
        URL devPath = bundle.getEntry("bin/");
        File fullPath;
        if (devPath != null) {
            devPath = FileLocator.toFileURL(devPath);
            fullPath = new File(devPath.toURI());
        } else {
            fullPath = FileLocator.getBundleFile(bundle);
        }
        return new Path(fullPath.getAbsolutePath());
    } catch (IOException e) {
        return null;
    } catch (URISyntaxException e) {
        return null;
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Bundle(org.osgi.framework.Bundle) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URL(java.net.URL)

Example 97 with IPath

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

the class RunGeneratorThread method setClassLoader.

private void setClassLoader() {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IJavaProject javaProject = getJavaProject();
    try {
        if (javaProject != null) {
            List<URL> entries = new ArrayList<URL>();
            IPath path = javaProject.getOutputLocation();
            IResource iResource = root.findMember(path);
            path = iResource.getLocation();
            path = path.addTrailingSeparator();
            entries.add(path.toFile().toURI().toURL());
            IClasspathEntry[] cpEntries = javaProject.getRawClasspath();
            for (IClasspathEntry cpEntry : cpEntries) {
                switch(cpEntry.getEntryKind()) {
                    case IClasspathEntry.CPE_SOURCE:
                        path = cpEntry.getOutputLocation();
                        if (path != null) {
                            iResource = root.findMember(path);
                            path = iResource.getLocation();
                            path = path.addTrailingSeparator();
                            entries.add(path.toFile().toURI().toURL());
                        }
                        break;
                    case IClasspathEntry.CPE_LIBRARY:
                        iResource = root.findMember(cpEntry.getPath());
                        if (iResource == null) {
                            // resource is not in workspace, must be an external JAR
                            path = cpEntry.getPath();
                        } else {
                            path = iResource.getLocation();
                        }
                        entries.add(path.toFile().toURI().toURL());
                        break;
                }
            }
            ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
            URL[] entryArray = new URL[entries.size()];
            entries.toArray(entryArray);
            ClassLoader newCl = new URLClassLoader(entryArray, oldCl);
            Thread.currentThread().setContextClassLoader(newCl);
            oldClassLoader = oldCl;
        }
    } catch (Exception e) {
        // ignore - something too complex is wrong
        ;
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException) InvalidConfigurationException(org.mybatis.generator.exception.InvalidConfigurationException) SQLException(java.sql.SQLException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IOException(java.io.IOException) XMLParserException(org.mybatis.generator.exception.XMLParserException) IJavaProject(org.eclipse.jdt.core.IJavaProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) IResource(org.eclipse.core.resources.IResource)

Example 98 with IPath

use of org.eclipse.core.runtime.IPath in project mechanoid by robotoworks.

the class MechanoidLibsInstaller method installLibs.

protected void installLibs(IJavaProject javaProject, IProgressMonitor monitor) throws URISyntaxException, IOException, CoreException {
    Bundle bundle = Platform.getBundle(ANDROID_LIBS_PLUGIN_RESOURCE_BUNDLE);
    IPath location = javaProject.getProject().getLocation();
    File libsFolder = new File(location.toOSString(), ANDROID_LIBS_DIR_NAME);
    if (!libsFolder.exists()) {
        libsFolder.mkdirs();
    }
    for (String libFileName : LIB_FILE_BUNDLE_PATHS) {
        final URL url = FileLocator.resolve(bundle.getEntry(MECHANOID_LIB_PATH + libFileName));
        File targetFile = new File(libsFolder, libFileName);
        if (targetFile.exists()) {
            targetFile.delete();
        }
        Files.copy(new InputSupplier<InputStream>() {

            @Override
            public InputStream getInput() throws IOException {
                return url.openStream();
            }
        }, targetFile);
    }
    javaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Bundle(org.osgi.framework.Bundle) InputStream(java.io.InputStream) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL)

Example 99 with IPath

use of org.eclipse.core.runtime.IPath in project mechanoid by robotoworks.

the class NewMechanoidElementWizard method performFinish.

@Override
public boolean performFinish() {
    final IPath newFilePath = createNewResourceFilePath();
    onBeforeCreateElementResource();
    WorkspaceModifyDelegatingOperation op = new WorkspaceModifyDelegatingOperation(new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                mNewResource = createElementResource(monitor, newFilePath);
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            } finally {
                monitor.done();
            }
        }
    });
    try {
        getContainer().run(true, true, op);
        selectAndReveal(mNewResource);
        openResource(mNewResource);
    } catch (InvocationTargetException e) {
        Throwable realException = e.getTargetException();
        MessageDialog.openError(getShell(), Messages.NewMechanoidElementWizard_Dialog_CreateResourceError_Title, realException.getMessage());
        return false;
    } catch (InterruptedException e) {
        return false;
    }
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IPath(org.eclipse.core.runtime.IPath) WorkspaceModifyDelegatingOperation(org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PartInitException(org.eclipse.ui.PartInitException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 100 with IPath

use of org.eclipse.core.runtime.IPath in project mechanoid by robotoworks.

the class ContainerBrowserField method onTextChanged.

@Override
protected void onTextChanged(ModifyEvent e) {
    super.onTextChanged(e);
    mSelectedPath = Path.fromPortableString(getTextField().getText());
    if (mSelectedPath.segmentCount() > 0) {
        IPath firstPart = mSelectedPath.uptoSegment(1);
        IContainer container = (IContainer) mWorkspaceRoot.findMember(firstPart);
        if (container != null && container instanceof IProject) {
            mSelectedProject = (IProject) container;
        } else {
            mSelectedProject = null;
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) IContainer(org.eclipse.core.resources.IContainer) IProject(org.eclipse.core.resources.IProject)

Aggregations

IPath (org.eclipse.core.runtime.IPath)500 Path (org.eclipse.core.runtime.Path)128 File (java.io.File)106 IFile (org.eclipse.core.resources.IFile)89 IResource (org.eclipse.core.resources.IResource)80 CoreException (org.eclipse.core.runtime.CoreException)74 ArrayList (java.util.ArrayList)72 IFolder (org.eclipse.core.resources.IFolder)63 IProject (org.eclipse.core.resources.IProject)60 IOException (java.io.IOException)57 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)51 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)40 IStatus (org.eclipse.core.runtime.IStatus)33 IJavaProject (org.eclipse.jdt.core.IJavaProject)33 URL (java.net.URL)26 InputStream (java.io.InputStream)23 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)23 Status (org.eclipse.core.runtime.Status)23 HashSet (java.util.HashSet)22 Test (org.junit.Test)22