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:com.tsc9526.monalisa.orm.tools.generator.DBGeneratorProcessing.java

License:Open Source License

public DBGeneratorProcessing(ProcessingEnvironment processingEnv, TypeElement typeElement) {
    super();/*from   w  w  w . java 2 s .  co m*/

    this.processingEnv = processingEnv;
    this.typeElement = typeElement;

    DB db = typeElement.getAnnotation(DB.class);
    if (db == null) {
        throw new RuntimeException("TypeElement without @DB: " + typeElement.toString());
    }
    String dbKey = db.key();
    if (dbKey == null || dbKey.length() < 1) {
        dbKey = typeElement.toString();
    }

    boolean inEclipseIDE = false;
    String projectPath = DbProp.CFG_ROOT_PATH;
    if (Helper.inEclipseIDE()) {
        if (processingEnv instanceof org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeBuildProcessingEnvImpl) {
            org.eclipse.jdt.core.IJavaProject project = ((org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeBuildProcessingEnvImpl) processingEnv)
                    .getJavaProject();
            projectPath = project.getProject().getLocation().toString();

            inEclipseIDE = true;

            DbProp.SET_CFG_ROOT_PATH(projectPath);

            plogger.info("Building eclipse project: " + projectPath + " ...");
            plogger.info("Database " + dbKey + ", "
                    + (db.configFile().length() > 0 ? ("Config-file: " + db.configFile()) : (db.url())));
        }
    }

    if (!inEclipseIDE) {
        plogger.info("Building " + dbKey + "(" + (db.configFile().length() > 0 ? db.configFile() : db.url())
                + "): " + new File(DbProp.CFG_ROOT_PATH).getAbsolutePath() + " ...");
    }

    System.setProperty("DB@" + dbKey, projectPath);

    this.dbcfg = DataSourceManager.getInstance().getDBConfig(dbKey, db, true);

    String name = typeElement.getQualifiedName().toString();
    String pkg = name.toLowerCase();
    int p = name.lastIndexOf(".");
    if (p > 0) {
        pkg = name.substring(0, p) + name.substring(p).toLowerCase();
    }

    this.javaPackage = pkg;
    this.resourcePackage = "resources." + pkg;
    this.dbi = typeElement.getQualifiedName().toString();
    this.dbmetadata = new DBMetadata(projectPath, javaPackage, dbcfg);
}

From source file:com.versant.core.jdo.tools.eclipse.RemoveJDONature.java

License:Open Source License

public static void removeJDONature(IJavaProject currentProject) {
    try {/*from   w ww  .j  a  va  2s  .c om*/
        IProject proj = currentProject.getProject();

        Utils.removeJDOGenieNature(proj);
        EnhancerBuilder.removeEnhancerBuilder(currentProject.getProject());

        proj.refreshLocal(IResource.DEPTH_INFINITE, null);
        // as both decorators share the same visibility rules, this will work
    } catch (Exception e) {
        Shell shell = new Shell();
        MessageDialog.openInformation(shell, "Versant OpenAccess Plug-in",
                "Cannot remove JDO nature:\n" + Utils.getStatusMessages(e));
    }
}

From source file:com.versant.core.jdo.tools.eclipse.Utils.java

License:Open Source License

/**
*
*//*from  w ww .  j a v a 2 s.  c  o m*/
public static void addJDONature(IJavaProject currentProject) throws Exception {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    Cursor waitCursor = new Cursor(window.getShell().getDisplay(), SWT.CURSOR_WAIT);
    try {
        window.getShell().setCursor(waitCursor);
        ((ApplicationWindow) window).setStatus("Adding JDO Nature...");
        IProject proj = currentProject.getProject();
        addJDOGenieNature(proj);
        ((ApplicationWindow) window).setStatus("Adding JDO libraries");
        addJDOGenieCPContainer(currentProject);
        addCPVarTo(currentProject);
        ((ApplicationWindow) window).setStatus("Finished adding JDO Nature");

        VOAConfigStruct.storeProp(proj, PROP_REL_PATH, "true");
        proj.refreshLocal(IResource.DEPTH_INFINITE, null);
    } catch (Exception e) {
        Shell shell = new Shell();
        MessageDialog.openInformation(shell, "JDO Ui Plug-in",
                "Cannot add JDO nature:\n" + getStatusMessages(e));
        throw e;
    } finally {
        window.getShell().setCursor(null);
        waitCursor.dispose();
    }
}

From source file:com.windowtester.codegen.util.BuildPathUtil.java

License:Open Source License

public static void addPluginDependency(IJavaProject targetProject, String pluginId) throws CoreException {
    IFile manifest = targetProject.getProject().getFile("META-INF/MANIFEST.MF");
    if (manifest.exists()) {
        updateManifestDependency(manifest.getLocation().toFile(), pluginId);
        manifest.refreshLocal(1, null);//from  ww  w .  j  a  v a  2  s.c o m
    } else {
        IFile plugin = targetProject.getProject().getFile("plugin.xml");
        if (!plugin.exists())
            throw new CoreException(
                    Logger.createLogStatus("No plugin or manifest file found in target project", null, null));
        updatePluginDependnecy(plugin.getLocation().toFile(), pluginId);
        plugin.refreshLocal(1, null);
    }
}

From source file:com.windowtester.codegen.util.BuildPathUtil.java

License:Open Source License

public static IStatus validateDependencies(IJavaProject targetProject, String mainAppProjectName,
        boolean addDefault, boolean isRcpApplication) throws CoreException {
    IProject mainAppProject = ResourcesPlugin.getWorkspace().getRoot().getProject(mainAppProjectName);
    if (!targetProject.getProject().getName().equals(mainAppProjectName) && addDefault) {
        BuildPathUtil.appendProjectBuildPath(targetProject, JavaCore.create(mainAppProject));
    }//www .  java  2s.c  om
    if (!targetProject.getProject().getName().equals(mainAppProjectName) && !addDefault)
        return new Status(IStatus.WARNING, CodeGenPlugin.getPluginId(), IStatus.WARNING,
                "Some required libraries are missing.", null);
    return validateDependencies(targetProject, addDefault, isRcpApplication);
}

From source file:com.windowtester.codegen.util.ProjectUtil.java

License:Open Source License

public static void addDefaultEntries(IJavaProject project, IFolder source, IProgressMonitor monitor)
        throws CoreException {

    IFolder bin = project.getProject().getFolder(new Path("bin"));

    List cpEntries = new ArrayList();
    cpEntries.add(JavaCore.newSourceEntry(source.getFullPath()));
    cpEntries.addAll(Arrays.asList(getDefaultClasspathEntry()));
    IClasspathEntry[] entries = (IClasspathEntry[]) cpEntries.toArray(new IClasspathEntry[cpEntries.size()]);

    if (!source.exists()) {
        source.getLocation().toFile().mkdirs();
    }/*  w w  w.j av a  2s. c  om*/
    if (!bin.exists()) {
        bin.getLocation().toFile().mkdirs();
    }
    project.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
    project.setRawClasspath(entries, bin.getFullPath(), monitor);
}

From source file:com.worldline.awltech.i18ntools.wizard.core.modules.ResourceBundleWrapper.java

License:Open Source License

/**
 * Creates Resource Bundle Wrapper, in specified project.
 * /*www . j  a va 2 s.c o  m*/
 * @param javaProject
 *            : current project
 * @param packageName
 *            : name of the package that will contain the enumeration
 * @param resourceBundleName
 *            : used for enumeration and properties file names.
 * @param prefixMessageByKey 
 */
public ResourceBundleWrapper(final IJavaProject javaProject, final String packageName,
        final String resourceBundleName, boolean prefixMessageByKey) {
    this.javaProject = javaProject;
    this.packageName = packageName;
    this.resourceBundleName = resourceBundleName;
    this.configuration = new RefactoringWizardConfiguration(javaProject.getProject());
    this.prefixMessageByKey = prefixMessageByKey;
}

From source file:com.worldline.awltech.i18ntools.wizard.core.RefactoringJob.java

License:Open Source License

@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {

    // 1. Resolve AST element...
    final ASTParser parser = ASTParser.newParser(AST.JLS4);
    parser.setSource(this.compilationUnit);
    final CompilationUnit astCompilationUnit = (CompilationUnit) parser.createAST(new NullProgressMonitor());
    final ASTNodeFinder nodeFinder = ASTNodeFinder.create(astCompilationUnit, this.offset, this.length);

    // 2. Open GUI to let user put its information
    final IJavaProject javaProject = this.compilationUnit.getJavaProject();
    final RefactoringWizard i18NizeWizard = new RefactoringWizard(javaProject);
    if (!i18NizeWizard.open()) {
        return Status.CANCEL_STATUS;
    }//from w ww  . j  a va 2 s  . c  om

    astCompilationUnit.recordModifications();

    this.resourceBundleName = i18NizeWizard.getResourceBundleName();
    this.enumerationPrefix = i18NizeWizard.getLiteralPrefix();
    this.resourceBundlePackage = i18NizeWizard.getResourceBundlePackage();
    this.prefixMessageByKey = i18NizeWizard.getPrefixMessageByKey();

    // 3. Extract the pattern and arguments from expression

    final ASTExpressionResolver expressionResolver = ASTExpressionResolver.create(nodeFinder);
    final ResourceBundleWrapper resourceBundleWrapper = new ResourceBundleWrapper(javaProject,
            this.resourceBundlePackage, this.resourceBundleName, this.prefixMessageByKey);
    final boolean isModified = resourceBundleWrapper.replaceLiteral(nodeFinder, this.enumerationPrefix,
            expressionResolver);

    if (isModified) {
        RefactoringJob.updateCompilationUnit(astCompilationUnit);
        RefactoringJob.updateCompilationUnit(resourceBundleWrapper.getEnumDomCompilationUnit());
        RefactoringJob.saveCompilationUnit(
                (ICompilationUnit) resourceBundleWrapper.getEnumDomCompilationUnit().getJavaElement());
        RefactoringJob.saveProperties(resourceBundleWrapper.getPropertiesFile(),
                resourceBundleWrapper.getProperties());

        // 4. We refresh the stuff
        javaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
    }
    return Status.OK_STATUS;
}

From source file:dacapo.eclipse.EclipseBuildTests.java

License:Open Source License

/**
 * Start a build on workspace using given options.
 * @param options/*from w w w . j a  v  a 2  s .  co m*/
 * @throws IOException
 * @throws CoreException
 */
private void startBuild(IJavaProject project, Hashtable options, boolean noWarning)
        throws IOException, CoreException {
    if (DEBUG)
        System.out.print("\tstart build...");

    JavaCore.setOptions(options);

    if (project == null) {
        System.out.println("\tBuilding: full workspace");
        env.fullBuild();
    } else {
        System.out.print("\t" + project.toString());
        System.out.print(" opening");
        project.getProject().open(null);
        System.out.print(" cleaning");
        project.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, null);
        System.out.print(" building");
        project.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
        System.out.println();
    }

    if (VERIFY) {
        // Verify markers
        IMarker[] markers = ResourcesPlugin.getWorkspace().getRoot()
                .findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
        List resources = new ArrayList();
        List messages = new ArrayList();
        int warnings = 0;
        for (int i = 0, length = markers.length; i < length; i++) {
            IMarker marker = markers[i];
            switch (((Integer) marker.getAttribute(IMarker.SEVERITY)).intValue()) {
            case IMarker.SEVERITY_ERROR:
                resources.add(marker.getResource().getName());
                messages.add(marker.getAttribute(IMarker.MESSAGE));
                break;
            case IMarker.SEVERITY_WARNING:
                warnings++;
                if (noWarning) {
                    resources.add(marker.getResource().getName());
                    messages.add(marker.getAttribute(IMarker.MESSAGE));
                }
                break;
            }
        }

        // Assert result
        int size = messages.size();
        if (size > 0) {
            StringBuffer debugBuffer = new StringBuffer();
            for (int i = 0; i < size; i++) {
                debugBuffer.append(resources.get(i));
                debugBuffer.append(":\n\t");
                debugBuffer.append(messages.get(i));
                debugBuffer.append('\n');
            }
            System.out.println("Unexpected ERROR marker(s):\n" + debugBuffer.toString());
            System.out.println("--------------------");
        }
    }
    if (DEBUG)
        System.out.println("done");
}

From source file:de.devboost.eclipse.jloop.AbstractLaunchProjectUpdater.java

License:Open Source License

protected void updateProjectClasspath(IJavaProject javaProject, Set<String> requiredProjects)
        throws CoreException, JavaModelException {

    IProject loopSuiteProject = javaProject.getProject();
    IClasspathEntry[] entries = getClasspathEntries(loopSuiteProject, requiredProjects);
    IPath outputLocation = loopSuiteProject.getFullPath().append("/bin");
    IFolder outputFolder = workspaceRoot.getFolder(outputLocation);
    if (!outputFolder.exists()) {
        outputFolder.create(true, true, new NullProgressMonitor());
    }/* w  w  w. j a v a2s.c  o m*/
    IProgressMonitor monitor = new NullProgressMonitor();
    javaProject.setRawClasspath(entries, outputLocation, monitor);
    loopSuiteProject.refreshLocal(IResource.DEPTH_INFINITE, monitor);

    loopSuiteProject.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
}