Example usage for org.eclipse.jdt.core IJavaProject getProject

List of usage examples for org.eclipse.jdt.core IJavaProject getProject

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaProject getProject.

Prototype

IProject getProject();

Source Link

Document

Returns the IProject on which this IJavaProject was created.

Usage

From source file:cn.ieclipse.pde.signer.handler.SignHandler.java

License:Apache License

public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    ISelection sel = window.getSelectionService().getSelection();
    if (sel instanceof IStructuredSelection) {
        Object obj = ((IStructuredSelection) sel).getFirstElement();
        if (obj instanceof IProject) {
            IProject prj = (IProject) obj;
            openProject(prj, null);//from w  w w.  j a v  a2 s  .c o m
        } else if (obj instanceof IFile) {
            IResource resource = (IResource) obj;
            String file = resource.getLocation().toOSString();
            if (file != null) {
                if (file.endsWith(Const.EXT_JAR)) {
                    openJar(file);
                } else if (file.endsWith(Const.EXT_APK)) {
                    openAndroid(file);
                } else {
                    openJar(null);
                }
            } else {
                openJar(null);
            }
        } else if (obj instanceof IJavaProject) {
            IJavaProject jprj = (IJavaProject) obj;
            IProject prj = jprj.getProject();
            openProject(prj, jprj);
        } else {
            openJar(null);
        }
    }
    return null;
}

From source file:com.aliyun.odps.eclipse.create.wizard.NewUDFWizard.java

License:Apache License

private void doFinish(IProgressMonitor monitor) throws CoreException {
    String udfName = this.page.getTypeName();
    String testClassName = "Test" + udfName;
    String classPath = this.page.getPackageText();
    String udtfClassPath = classPath;
    String testClassPath = "test." + classPath;
    if (classPath.equals("")) {
        testClassPath = "";
    }//w  w  w  .  jav  a 2s.  com

    IJavaProject myjavapro = this.page.getJavaProject();
    IProject myproject = myjavapro.getProject();

    String content = NewWizardUtils.getContent(myproject, testClassName, udfName, udtfClassPath, testClassPath,
            TESTUDFMODEL);
    NewWizardUtils.createClass(myjavapro, testClassName, testClassPath, monitor, content);
    content = NewWizardUtils.getContent(myproject, testClassName, udfName, udtfClassPath, testClassPath,
            TESTUDFBASEMODEL);
    NewWizardUtils.createTestBase(myjavapro, testClassPath, monitor, content, TESTUDFBASE);
    NewWizardUtils.createDataFile(myproject, testClassName, "udf_test", monitor);
}

From source file:com.aliyun.odps.eclipse.create.wizard.NewUDTFWizard.java

License:Apache License

private void doFinish(IProgressMonitor monitor) throws CoreException {
    String udtfName = this.page.getTypeName();
    String testClassName = "Test" + udtfName;
    String classPath = this.page.getPackageText();
    String udtfClassPath = classPath;
    String testClassPath = "test." + classPath;
    if (classPath.equals("")) {
        testClassPath = "";
    }/*from w  w w.  j av a 2 s . com*/

    IJavaProject myjavapro = this.page.getJavaProject();
    IProject myproject = myjavapro.getProject();

    String content = NewWizardUtils.getContent(myproject, testClassName, udtfName, udtfClassPath, classPath,
            UDTFCLASS);
    NewWizardUtils.createClass(myjavapro, udtfName, classPath, monitor, content);

    content = NewWizardUtils.getContent(myproject, testClassName, udtfName, udtfClassPath, testClassPath,
            TESTUDTFMODEL);
    NewWizardUtils.createClass(myjavapro, testClassName, testClassPath, monitor, content);
    content = NewWizardUtils.getContent(myproject, testClassName, udtfName, udtfClassPath, testClassPath,
            TESTUDTFBASEMODEL);
    NewWizardUtils.createTestBase(myjavapro, testClassPath, monitor, content, TESTUDTFBASE);
    NewWizardUtils.createDataFile(myproject, testClassName, "udtf_test", monitor);
}

From source file:com.aliyun.odps.eclipse.create.wizard.ProjectNature.java

License:Apache License

/**
 * Configures an Eclipse project as a Map/Reduce project by adding the Hadoop libraries to a
 * project's classpath.//from ww  w  .jav a2s  .  co  m
 */
public void configure() throws CoreException {
    String path = project.getPersistentProperty(new QualifiedName(Activator.PLUGIN_ID, "ODPS.runtime.path"));

    File dir = new File(path);
    final ArrayList<File> coreJars = new ArrayList<File>();
    dir.listFiles(new FileFilter() {
        public boolean accept(File pathname) {
            String fileName = pathname.getName();

            // get the hadoop core jar without touching test or examples
            // older version of hadoop don't use the word "core" -- eyhung
            if ((fileName.indexOf("hadoop") != -1) && (fileName.endsWith("jar"))
                    && (fileName.indexOf("test") == -1) && (fileName.indexOf("examples") == -1)) {
                coreJars.add(pathname);
            }

            return false; // we don't care what this returns
        }
    });
    File dir2 = new File(path + File.separatorChar + "lib");
    if (dir2.exists() && dir2.isDirectory()) {
        dir2.listFiles(new FileFilter() {
            public boolean accept(File pathname) {
                if ((!pathname.isDirectory()) && (pathname.getName().endsWith("jar"))) {
                    coreJars.add(pathname);
                }

                return false; // we don't care what this returns
            }
        });
    }

    // Add Hadoop libraries onto classpath
    IJavaProject javaProject = JavaCore.create(getProject());
    // Bundle bundle = Activator.getDefault().getBundle();

    try {
        IClasspathEntry[] currentCp = javaProject.getRawClasspath();
        IClasspathEntry[] newCp = new IClasspathEntry[currentCp.length + coreJars.size() + 1];
        System.arraycopy(currentCp, 0, newCp, 0, currentCp.length);

        final Iterator<File> i = coreJars.iterator();
        int count = 0;
        while (i.hasNext()) {
            // for (int i = 0; i < s_coreJarNames.length; i++) {

            final File f = (File) i.next();
            // URL url = FileLocator.toFileURL(FileLocator.find(bundle, new
            // Path("lib/" + s_coreJarNames[i]), null));
            URL url = f.toURI().toURL();
            log.finer("hadoop library url.getPath() = " + url.getPath());

            newCp[newCp.length - 2 - count] = JavaCore.newLibraryEntry(new Path(url.getPath()), null, null);
            count++;
        }

        // add examples to class-path
        IPath sourceFolderPath = new Path(javaProject.getProject().getName()).makeAbsolute();
        IPath exampleSrc = sourceFolderPath.append(new Path(CONST.EXAMPLE_SRC_PATH));
        IPath exampleClasses = sourceFolderPath.append(new Path(CONST.EXAMPLE_BIN));
        IClasspathEntry exampleSrcEntry = JavaCore.newSourceEntry(exampleSrc, new IPath[] {}, exampleClasses);
        newCp[newCp.length - 1] = exampleSrcEntry;

        javaProject.setRawClasspath(newCp, new NullProgressMonitor());
    } catch (Exception e) {
        log.log(Level.SEVERE, "IOException generated in " + this.getClass().getCanonicalName(), e);
    }
}

From source file:com.amashchenko.eclipse.strutsclipse.StrutsXmlHyperlinkDetector.java

License:Apache License

private List<IHyperlink> createResultLocationLinks(final IDocument document, final String elementValue,
        final IRegion elementRegion, final String typeAttrValue, final String namespaceParamValue) {
    final List<IHyperlink> links = new ArrayList<IHyperlink>();

    // assume that default is dispatcher for now, TODO improve
    // that/*from ww  w. ja  v  a2  s.com*/
    if (typeAttrValue == null || StrutsXmlConstants.DISPATCHER_RESULT.equals(typeAttrValue)
            || StrutsXmlConstants.FREEMARKER_RESULT.equals(typeAttrValue)) {
        IProject project = ProjectUtil.getCurrentProject(document);
        if (project != null && project.exists()) {
            IVirtualComponent rootComponent = ComponentCore.createComponent(project);
            final IVirtualFolder rootFolder = rootComponent.getRootFolder();
            IPath path = rootFolder.getProjectRelativePath().append(elementValue);

            IFile file = project.getFile(path);
            if (file.exists()) {
                links.add(new FileHyperlink(elementRegion, file));
            }
        }
    } else if (StrutsXmlConstants.REDIRECT_ACTION_RESULT.equals(typeAttrValue)) {
        Set<String> namespaces = new HashSet<String>();

        // if there is a namespaceParamValue then used it, else get
        // namespace from parent package
        String namespace = namespaceParamValue;
        if (namespace == null) {
            TagRegion packageTagRegion = strutsXmlParser.getParentTagRegion(document, elementRegion.getOffset(),
                    StrutsXmlConstants.PACKAGE_TAG);
            if (packageTagRegion != null) {
                namespace = packageTagRegion.getAttrValue(StrutsXmlConstants.NAMESPACE_ATTR, "");
            } else {
                namespace = "";
            }

            // if namespace came NOT from namespaceParamValue then add
            // special namespaces
            namespaces.add("");
            namespaces.add("/");
        }

        namespaces.add(namespace);

        IRegion region = strutsXmlParser.getActionRegion(document, namespaces, elementValue);
        if (region != null) {
            ITextFileBuffer textFileBuffer = FileBuffers.getTextFileBufferManager().getTextFileBuffer(document);
            if (textFileBuffer != null) {
                IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(textFileBuffer.getLocation());
                if (file.exists()) {
                    links.add(new FileHyperlink(elementRegion, file, region));
                }
            }
        }
    } else if (StrutsXmlConstants.TILES_RESULT.equals(typeAttrValue)) {
        try {
            final IDocumentProvider provider = new TextFileDocumentProvider();
            final IJavaProject javaProject = ProjectUtil.getCurrentJavaProject(document);
            if (javaProject != null && javaProject.exists()) {
                final IProject project = javaProject.getProject();
                final String outputFolder = javaProject.getOutputLocation()
                        .makeRelativeTo(project.getFullPath()).segment(0);
                project.accept(new IResourceVisitor() {
                    @Override
                    public boolean visit(IResource resource) throws CoreException {
                        // don't visit output folder
                        if (resource.getType() == IResource.FOLDER
                                && resource.getProjectRelativePath().segment(0).equals(outputFolder)) {
                            return false;
                        }
                        if (resource.isAccessible() && resource.getType() == IResource.FILE
                                && "xml".equalsIgnoreCase(resource.getFileExtension()) && resource.getName()
                                        .toLowerCase(Locale.ROOT).contains(StrutsXmlConstants.TILES_RESULT)) {
                            provider.connect(resource);
                            IDocument document = provider.getDocument(resource);
                            provider.disconnect(resource);

                            IRegion region = tilesXmlParser.getDefinitionRegion(document, elementValue);
                            if (region != null) {
                                IFile file = project.getFile(resource.getProjectRelativePath());
                                if (file.exists()) {
                                    links.add(new FileHyperlink(elementRegion, file, region));
                                }
                            }
                        }
                        return true;
                    }
                });
            }
        } catch (CoreException e) {
            e.printStackTrace();
        }
    }
    return links;
}

From source file:com.amazonaws.eclipse.android.sdk.classpath.AndroidSdkClasspathContainerInitializer.java

License:Open Source License

@Override
public void initialize(IPath containerPath, IJavaProject javaProject) throws CoreException {
    try {/*  www .  j  av  a  2  s . com*/
        SdkProjectMetadata sdkProjectMetadataFile = new SdkProjectMetadata(javaProject.getProject());
        File sdkInstallRoot = sdkProjectMetadataFile.getSdkInstallRootForProject();

        if (sdkInstallRoot == null)
            throw new Exception("No SDK install directory specified");

        AndroidSdkInstall sdkInstall = new AndroidSdkInstallFactory().createSdkInstallFromDisk(sdkInstallRoot);

        if (sdkInstall.isValidSdkInstall() == false)
            throw new Exception("Invalid SDK install directory specified: " + sdkInstall.getRootDirectory());

        copySdkJarToProject(javaProject.getProject(), sdkInstall);

        AndroidSdkClasspathContainer classpathContainer = new AndroidSdkClasspathContainer(sdkInstall,
                javaProject.getProject());
        JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { javaProject },
                new IClasspathContainer[] { classpathContainer }, null);
    } catch (Exception e) {
        AndroidSdkInstall defaultSdkInstall = AndroidSdkManager.getInstance().getDefaultSdkInstall();
        if (defaultSdkInstall == null)
            throw new CoreException(new Status(IStatus.ERROR, JavaSdkPlugin.PLUGIN_ID, "No SDKs available"));

        AndroidSdkClasspathContainer classpathContainer = new AndroidSdkClasspathContainer(defaultSdkInstall,
                javaProject.getProject());
        JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { javaProject },
                new IClasspathContainer[] { classpathContainer }, null);
        try {
            defaultSdkInstall.writeMetadataToProject(javaProject);
        } catch (IOException ioe) {
            StatusManager.getManager().handle(
                    new Status(Status.WARNING, JavaSdkPlugin.PLUGIN_ID, ioe.getMessage(), ioe),
                    StatusManager.LOG);
        }

        String message = "Unable to initialize previous AWS SDK for Android classpath entries - defaulting to latest version";
        Status status = new Status(Status.WARNING, JavaSdkPlugin.PLUGIN_ID, message, e);
        StatusManager.getManager().handle(status, StatusManager.LOG);
    }
}

From source file:com.amazonaws.eclipse.android.sdk.classpath.AwsAndroidSdkClasspathUtils.java

License:Open Source License

public static void addAwsAndroidSdkToProjectClasspath(IJavaProject javaProject, AbstractSdkInstall sdkInstall) {
    try {//from   ww w .ja va 2s. c o  m
        AndroidSdkClasspathContainer classpathContainer = new AndroidSdkClasspathContainer(sdkInstall,
                javaProject.getProject());

        IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
        List<IClasspathEntry> newList = new ArrayList<IClasspathEntry>();
        for (IClasspathEntry entry : rawClasspath) {
            if (entry.getPath().equals(classpathContainer.getPath()) == false) {
                newList.add(entry);
            }
        }

        newList.add(JavaCore.newContainerEntry(classpathContainer.getPath()));

        javaProject.setRawClasspath(newList.toArray(new IClasspathEntry[newList.size()]), null);
    } catch (JavaModelException e) {
        String message = "Unable to add AWS SDK for Android to the project's classpath";
        IStatus status = new Status(IStatus.ERROR, AndroidSDKPlugin.PLUGIN_ID, message, e);
        StatusManager.getManager().handle(status, StatusManager.LOG);
    }
}

From source file:com.amazonaws.eclipse.lambda.project.listener.LambdaProjectChangeTracker.java

License:Open Source License

public boolean isProjectDirty(IJavaProject project) {
    return isProjectDirty(project.getProject());
}

From source file:com.amazonaws.eclipse.lambda.project.listener.LambdaProjectChangeTracker.java

License:Open Source License

private void markProjectAsDirty(IJavaProject project) {
    markProjectAsDirty(project.getProject());
}

From source file:com.amazonaws.eclipse.lambda.project.wizard.NewLambdaJavaFunctionProjectWizard.java

License:Open Source License

@Override
protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException {

    trackNewProjectAttributes(dataModel);

    pageTwo.performFinish(monitor);/*  w ww .  j av a 2 s  .c o  m*/

    monitor.setTaskName("Configuring AWS Lambda Java project");

    IJavaProject javaProject = pageTwo.getJavaProject();
    final IProject project = javaProject.getProject();

    Display.getDefault().syncExec(new Runnable() {

        public void run() {

            File readmeFile = null;

            try {
                savePreferences(dataModel, LambdaPlugin.getDefault().getPreferenceStore());

                addSourceToProject(project, dataModel);

                if (dataModel.isShowReadmeFile()) {
                    readmeFile = addReadmeFileToProject(project, dataModel.collectHandlerTestTemplateData());
                }

                refreshProject(project);

            } catch (Exception e) {
                trackProjectCreationFailed();
                StatusManager.getManager().handle(new Status(IStatus.ERROR, LambdaPlugin.PLUGIN_ID,
                        "Failed to create new Lambda project", e), StatusManager.SHOW);
                return;
            }

            trackProjectCreationSucceeded();

            try {
                IFile handlerClass = findHandlerClassFile(project, dataModel);
                selectAndReveal(handlerClass); // show in explorer
                openHandlerClassEditor(handlerClass); // show in editor
            } catch (Exception e) {
                LambdaPlugin.getDefault().warn("Failed to open the handler class", e);
            }

            if (readmeFile != null) {
                try {
                    BrowserUtil.openInternalBrowserAsEditor(readmeFile.toURI().toURL());
                } catch (Exception e) {
                    LambdaPlugin.getDefault().warn("Failed to open README.html for the new Lambda project", e);
                }
            }
        }
    });
}