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.github.caofangkun.bazelipse.wizard.BazelProjectSupport.java

License:Open Source License

private static void createClasspath(IPath root, List<String> paths, IJavaProject javaProject)
        throws CoreException {
    String name = root.lastSegment();
    IFolder base = javaProject.getProject().getFolder(name);
    if (!base.isLinked()) {
        base.createLink(root, IResource.NONE, null);
    }// w  w w.  j  a va  2 s  .com
    List<IClasspathEntry> list = new LinkedList<>();
    for (String path : paths) {
        IPath workspacePath = base.getFullPath().append(path);
        list.add(JavaCore.newSourceEntry(workspacePath));
    }
    list.add(JavaCore.newContainerEntry(new Path(BazelClasspathContainer.CONTAINER_NAME)));
    // TODO(dmarting): we should add otherwise. Best way is to get the
    // bootclasspath from Bazel.
    list.add(JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER/"
            + "org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8")));
    IClasspathEntry[] newClasspath = (IClasspathEntry[]) list.toArray(new IClasspathEntry[0]);
    javaProject.setRawClasspath(newClasspath, null);
}

From source file:com.github.ko2ic.plugin.eclipse.taggen.core.service.WorkspaceClassLoader.java

License:Open Source License

private Set<URL> createUrls(IJavaProject javaProject) throws CoreException, MalformedURLException {
    Set<URL> urlList = new HashSet<>();
    IClasspathEntry[] classpathEntries = javaProject.getResolvedClasspath(true);
    for (IClasspathEntry entry : classpathEntries) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath path = entry.getOutputLocation();
            if (path != null) {
                IPath outputPath = javaProject.getOutputLocation().removeFirstSegments(1);
                IPath outputFullPath = javaProject.getProject().getFolder(outputPath).getLocation();
                outputFullPath.append(System.getProperty("line.separator"));
                URL url = outputFullPath.toFile().toURI().toURL();
                urlList.add(url);//from w  ww . jav  a  2 s  .  com
            }
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            URL url = entry.getPath().toFile().toURI().toURL();
            urlList.add(url);
        }
    }
    return urlList;
}

From source file:com.google.appengine.eclipse.core.datatools.SqlConnectionExtensionPopulator.java

License:Open Source License

public static void populateCloudSQLBridgeExtender(IJavaProject javaProject, String cloudSqlJarPath) {
    IProject project = javaProject.getProject();

    if (!GoogleCloudSqlProperties.getGoogleCloudSqlEnabled(project)) {
        return;/*from   www.  ja  va  2  s.c  o m*/
    }

    if (GoogleCloudSqlProperties.getLocalDevMySqlEnabled(project)) {
        if (GoogleCloudSqlProperties.getMySqlIsConfigured(project)) {
            populateCloudSQLBridgeExtender(javaProject, ConnectionType.CONNECTION_TYPE_LOCAL_MYSQL);
        }
    } else {
        if (GoogleCloudSqlProperties.getTestIsConfigured(project)) {
            populateCloudSQLBridgeExtender(javaProject, ConnectionType.CONNECTION_TYPE_TEST, cloudSqlJarPath);
        }
    }

    if (GoogleCloudSqlProperties.getProdIsConfigured(project)) {
        populateCloudSQLBridgeExtender(javaProject, ConnectionType.CONNECTION_TYPE_PROD, cloudSqlJarPath);
    }
}

From source file:com.google.appengine.eclipse.core.datatools.SqlConnectionExtensionPopulator.java

License:Open Source License

private static String getJarPathForType(IJavaProject javaProject, ConnectionType connectionType) {
    switch (connectionType) {
    case CONNECTION_TYPE_LOCAL_MYSQL:
        return GoogleCloudSqlProperties.getMySqlJdbcJar(javaProject.getProject());
    case CONNECTION_TYPE_PROD:
    case CONNECTION_TYPE_TEST:
        return getCloudSqlJarPath(javaProject);
    }/*from  ww w .ja  v a  2 s .  com*/
    return null;
}

From source file:com.google.appengine.eclipse.core.datatools.SqlConnectionExtensionPopulator.java

License:Open Source License

private static SqlConnectionProperties getSqlConnectionPropertiesByType(IJavaProject javaProject,
        ConnectionType connectionType, String jarPath) {
    if (connectionType == ConnectionType.CONNECTION_TYPE_LOCAL_MYSQL) {
        return setLocalMySqlConnectionProperties(javaProject.getProject(), jarPath);
    } else if (connectionType == ConnectionType.CONNECTION_TYPE_PROD) {
        return setProdCloudSqlConnectorsProperties(javaProject, jarPath);
    } else if (connectionType == ConnectionType.CONNECTION_TYPE_TEST) {
        return setTestCloudSqlConnectorsProperties(javaProject, jarPath);
    }/* w  w  w  .j  a va  2 s .  c  om*/
    return null;
}

From source file:com.google.appengine.eclipse.core.datatools.SqlConnectionExtensionPopulator.java

License:Open Source License

private static SqlConnectionProperties setProdCloudSqlConnectorsProperties(IJavaProject javaProject,
        String jarPath) {//from  w ww  .j a v a  2 s . c  o  m
    IProject project = javaProject.getProject();
    SqlConnectionProperties sqlConnectionProperties = new SqlConnectionProperties();

    String username = GoogleCloudSqlProperties.getProdDatabaseUser(project);
    String instanceName = GoogleCloudSqlProperties.getProdInstanceName(project);
    String databaseName = GoogleCloudSqlProperties.getProdDatabaseName(project);
    String password = GoogleCloudSqlProperties.getProdDatabasePassword(project);
    String driverClass = GAE_CLOUD_SQL_DRIVER_CLASS;
    String connectionId = getDisplaybleConnectionId(project.getName(), ConnectionType.CONNECTION_TYPE_PROD);

    sqlConnectionProperties.setUsername(username);
    sqlConnectionProperties.setPassword(password);
    sqlConnectionProperties.setDatabaseName(databaseName);
    sqlConnectionProperties.setJarPath(jarPath);
    sqlConnectionProperties.setDriverClass(driverClass);
    sqlConnectionProperties.setDisplayableConnectionPropertiesId(connectionId);
    sqlConnectionProperties.setInstanceName(instanceName);
    sqlConnectionProperties.setVendor(SqlConnectionProperties.Vendor.GOOGLE);

    return sqlConnectionProperties;
}

From source file:com.google.appengine.eclipse.core.datatools.SqlConnectionExtensionPopulator.java

License:Open Source License

private static SqlConnectionProperties setTestCloudSqlConnectorsProperties(IJavaProject javaProject,
        String jarPath) {/*from w ww.  java  2 s  .  c  om*/
    IProject project = javaProject.getProject();

    SqlConnectionProperties sqlConnectionProperties = new SqlConnectionProperties();

    String username = GoogleCloudSqlProperties.getTestDatabaseUser(project);
    String instanceName = GoogleCloudSqlProperties.getTestInstanceName(project);
    String databaseName = GoogleCloudSqlProperties.getTestDatabaseName(project);
    String password = GoogleCloudSqlProperties.getTestDatabasePassword(project);
    String driverClass = GAE_CLOUD_SQL_DRIVER_CLASS;
    String connectionId = getDisplaybleConnectionId(project.getName(), ConnectionType.CONNECTION_TYPE_TEST);

    sqlConnectionProperties.setUsername(username);
    sqlConnectionProperties.setPassword(password);
    sqlConnectionProperties.setDatabaseName(databaseName);
    sqlConnectionProperties.setJarPath(jarPath);
    sqlConnectionProperties.setDriverClass(driverClass);
    sqlConnectionProperties.setDisplayableConnectionPropertiesId(connectionId);
    sqlConnectionProperties.setInstanceName(instanceName);
    sqlConnectionProperties.setVendor(SqlConnectionProperties.Vendor.GOOGLE);

    return sqlConnectionProperties;
}

From source file:com.google.appengine.eclipse.core.deploy.ui.DeployProjectDialog.java

License:Open Source License

private IJavaProject chooseProject() {
    IJavaProject[] javaProjects;//from ww  w. jav a  2  s  .co m
    try {
        javaProjects = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects();
    } catch (JavaModelException e) {
        AppEngineCorePluginLog.logError(e);
        javaProjects = new IJavaProject[0];
    }

    // Filter the list to only show App Engine projects
    List<IJavaProject> gaeProjects = new ArrayList<IJavaProject>();
    for (IJavaProject javaProject : javaProjects) {
        if (GaeNature.isGaeProject(javaProject.getProject())) {
            gaeProjects.add(javaProject);
        }
    }

    ILabelProvider labelProvider = new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT);
    ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), labelProvider);
    dialog.setTitle("Project Selection");
    dialog.setMessage("Choose a project to deploy");
    dialog.setElements(gaeProjects.toArray(new IJavaProject[0]));
    dialog.setInitialSelections(new Object[] { JavaCore.create(project) });

    dialog.setHelpAvailable(false);
    if (dialog.open() == Window.OK) {
        return (IJavaProject) dialog.getFirstResult();
    }
    return null;
}

From source file:com.google.appengine.eclipse.core.launch.processors.GoogleCloudSqlArgumentProcessor.java

License:Open Source License

public void update(ILaunchConfigurationWorkingCopy launchConfig, IJavaProject javaProject,
        List<String> programArgs, List<String> vmArgs) {
    removeSqlConfigurations(javaProject, vmArgs);

    boolean usingGoogleCloudSql = GoogleCloudSqlProperties.getGoogleCloudSqlEnabled(javaProject.getProject());
    boolean localDevMySqlEnabled = GoogleCloudSqlProperties.getLocalDevMySqlEnabled(javaProject.getProject());
    if (usingGoogleCloudSql && GaeNature.isGaeProject(javaProject.getProject())) {
        if (localDevMySqlEnabled) {
            updateMySqlLaunchCongiguration(launchConfig, javaProject, programArgs, vmArgs);
        } else {//  w w w  . ja  va2 s.  c  o m
            updateGoogleCloudSqlLaunchCongiguration(launchConfig, javaProject, programArgs, vmArgs);
        }
    }
}

From source file:com.google.appengine.eclipse.core.launch.processors.GoogleCloudSqlArgumentProcessor.java

License:Open Source License

private void updateGoogleCloudSqlLaunchCongiguration(ILaunchConfigurationWorkingCopy launchConfig,
        IJavaProject javaProject, List<String> programArgs, List<String> vmArgs) {
    String password = GoogleCloudSqlProperties.getTestDatabasePassword(javaProject.getProject());
    String user = GoogleCloudSqlProperties.getTestDatabaseUser(javaProject.getProject());
    String instance = GoogleCloudSqlProperties.getTestInstanceName(javaProject.getProject());
    String database = GoogleCloudSqlProperties.getTestDatabaseName(javaProject.getProject());
    if (instance.trim().isEmpty()) {
        return;//from   w w w.j  a  v a2s.c o m
    }
    vmArgs.add(0, ARG_RDBMS_SERVER + ARG_RDBMS_SERVER_HOSTED_VALUE);
    vmArgs.add(0, ARG_RDBMS_HOSTED_INSTANCE + "\"" + instance + "\"");
    vmArgs.add(0, ARG_RDBMS_DATABASE + "\"" + database + "\"");
    vmArgs.add(0, ARG_RDBMS_USER + "\"" + user + "\"");
    vmArgs.add(0, ARG_RDBMS_PASSWORD + "\"" + password + "\"");
}