Search in sources :

Example 86 with IPath

use of org.eclipse.core.runtime.IPath in project jop by jop-devel.

the class JavaDownLaunchConfigurationDelegate method getJopizedFile.

/**
     * Returns the location of the JOPized class-file
     * @param configuration
     * @return
     * @throws CoreException
     */
private IPath getJopizedFile(ILaunchConfiguration configuration) throws CoreException {
    IPath outputPath = getAbsoluteProjectOutputPath(configuration);
    IPath jopOutFile = outputPath.append(getMainTypeName(configuration)).addFileExtension("jop");
    return jopOutFile;
}
Also used : IPath(org.eclipse.core.runtime.IPath)

Example 87 with IPath

use of org.eclipse.core.runtime.IPath in project jop by jop-devel.

the class JavaDownLaunchConfigurationDelegate method launch.

@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    if (CommonTab.isLaunchInBackground(configuration)) {
        System.err.println("Launch in background");
    }
    try {
        // JOPize
        int jopizerExitValue = jopize(configuration, mode, launch, monitor);
        IPath jopizedFile = getJopizedFile(configuration);
        if (configuration.getAttribute(IJOPLaunchConfigurationConstants.ATTR_SIMULATE, true)) {
            // configuration.getAttribute("SIMULATE", false)) {
            simulate(configuration, mode, launch, monitor);
        } else {
            JavaDown downloader = new JavaDown();
            boolean usb = useUsbDownload(configuration);
            String portName = configuration.getAttribute(IJOPLaunchConfigurationConstants.ATTR_COM_PORT, "");
            downloader.setCommPortId(portName);
            downloader.useUSB(usb);
            downloader.setJopFile(jopizedFile);
            downloader.run(monitor);
        }
    } catch (Exception e) {
        JOPUtils.abort(e.getLocalizedMessage(), e, 0);
    }
}
Also used : JavaDown(com.jopdesign.jopeclipse.internal.core.JavaDown) IPath(org.eclipse.core.runtime.IPath) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException)

Example 88 with IPath

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

the class AbstractGeneratorComposite method createFileNameBrowseButtons.

private void createFileNameBrowseButtons(Composite parent) {
    new Label(parent, SWT.NONE);
    Composite buttonComposite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    buttonComposite.setLayout(layout);
    GridData gd = new GridData(SWT.END, SWT.CENTER, false, false);
    buttonComposite.setLayoutData(gd);
    buttonComposite.setFont(parent.getFont());
    btnBrowseWorkplace = new Button(buttonComposite, SWT.NONE);
    btnBrowseWorkplace.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IResource chosenFile = chooseFileFromWorkspace();
            if (chosenFile != null) {
                IPath path = chosenFile.getFullPath();
                //$NON-NLS-1$ //$NON-NLS-2$
                txtFileName.setText("${workspace_loc:" + path.toString() + "}");
                javaProjectName = GeneratorLaunchShortcut.getJavaProjectNameFromResource(chosenFile);
            }
        }
    });
    btnBrowseWorkplace.setText(Messages.FILE_PICKER_BROWSE_WORKSPACE);
    btnBrowseFileSystem = new Button(buttonComposite, SWT.NONE);
    btnBrowseFileSystem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            chooseFileFromFileSystem();
        }
    });
    btnBrowseFileSystem.setText(Messages.FILE_PICKER_BROWSE_FILE_SYSTEM);
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) IPath(org.eclipse.core.runtime.IPath) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IResource(org.eclipse.core.resources.IResource)

Example 89 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 90 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)

Aggregations

IPath (org.eclipse.core.runtime.IPath)800 Path (org.eclipse.core.runtime.Path)219 File (java.io.File)161 IFile (org.eclipse.core.resources.IFile)150 CoreException (org.eclipse.core.runtime.CoreException)135 IResource (org.eclipse.core.resources.IResource)112 IOException (java.io.IOException)100 ArrayList (java.util.ArrayList)92 IProject (org.eclipse.core.resources.IProject)85 IFolder (org.eclipse.core.resources.IFolder)80 Test (org.junit.Test)72 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)58 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)55 IStatus (org.eclipse.core.runtime.IStatus)48 InputStream (java.io.InputStream)44 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)42 Status (org.eclipse.core.runtime.Status)36 IJavaProject (org.eclipse.jdt.core.IJavaProject)36 URL (java.net.URL)33 IContainer (org.eclipse.core.resources.IContainer)33