Example usage for org.eclipse.jdt.core JavaCore setClasspathVariable

List of usage examples for org.eclipse.jdt.core JavaCore setClasspathVariable

Introduction

In this page you can find the example usage for org.eclipse.jdt.core JavaCore setClasspathVariable.

Prototype

public static void setClasspathVariable(String variableName, IPath path) throws JavaModelException 

Source Link

Document

Sets the value of the given classpath variable.

Usage

From source file:webx.studio.projectcreation.ui.ProjectCreationWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    if (_DEBUG)/*from  w  ww  . j  a  va2 s  .c om*/
        time = System.currentTimeMillis();
    final NameRule nameRule = new NameRule(projectInfomationWizardPage.getProjectGroupId(),
            projectInfomationWizardPage.getProjectName());
    final Model parentModel = projectInfomationWizardPage.getModel(nameRule);
    projectStructureWizardPage.updateModel(parentModel, nameRule);
    final IPath location = Path.fromOSString(projectInfomationWizardPage.getPathValue());

    final JejuProject webxProject = new JejuProject(nameRule.getProjectName());
    webxProject.setWebxVersion(projectInfomationWizardPage.getWebxVersion());
    final WebxStructureModel webxStructureModel = projectStructureWizardPage.getWebxStructureModel();
    final String settingFilePath = projectInfomationWizardPage.getSeetingFilePath();
    final String antxPropertiesPath = projectInfomationWizardPage.getAntxPropertiesPath();
    final String autoconfigCharset = projectInfomationWizardPage.getAutoconfigCharset();
    webxProject.setSettingFile(StringUtils.trimToEmpty(settingFilePath));
    webxProject.setAntxPropertiesFile(StringUtils.trimToEmpty(antxPropertiesPath));
    webxProject.setAutoconfigCharset(StringUtils.trimToEmpty(autoconfigCharset));
    webxProject.setWebRoot(getWebRoot(location, nameRule));
    WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
        protected void execute(IProgressMonitor monitor) throws CoreException {
            IOConsole mc = getIOConsole();
            IOConsoleOutputStream consoleStream = mc.newOutputStream();

            System.setIn(mc.getInputStream());
            System.setErr(new PrintStream(consoleStream));
            System.setOut(new PrintStream(consoleStream));
            try {
                if (_DEBUG) {
                    time = System.currentTimeMillis();
                }
                monitor.beginTask("Create a Jeju project[ " + nameRule.getProjectName() + " ]", 20);
                List<IProject> projects = ProjectHelper.createProject(location, parentModel, webxStructureModel,
                        nameRule, new SubProgressMonitor(monitor, 10));
                if (_DEBUG) {
                    System.out.println("Creating eclipse project costs "
                            + (System.currentTimeMillis() - time) / 1000 + " second.");
                    time = System.currentTimeMillis();
                }

                if (JavaCore.getClasspathVariable(ProjectCreationConstants.M2_REPO_KEY) == null) {
                    JavaCore.setClasspathVariable(ProjectCreationConstants.M2_REPO_KEY,
                            new Path(MavenHelper.getLocalRepository()));
                }
                File parentPomFile = new File(location.toFile(), nameRule.getProjectName() + "/pom.xml");
                MavenHelper.generateEclipse(parentPomFile.getParent(), settingFilePath,
                        new SubProgressMonitor(monitor, 10));
                if (_DEBUG)
                    System.out.println("Running maven command costs "
                            + (System.currentTimeMillis() - time) / 1000 + " second.");
                for (IProject project : projects) {
                    webxProject.getProjectNames().add(project.getName());
                }
                Job job = new Job("Save Metadata") {

                    protected IStatus run(IProgressMonitor monitor) {
                        JejuProjectCore.addWebXProject(webxProject);
                        return Status.OK_STATUS;
                    }

                };
                job.schedule();
            } catch (Exception e) {
                throw new CoreException(
                        new Status(IStatus.ERROR, ProjectCreationPlugin.PLUGIN_ID, -1, e.getMessage(), e));
            } finally {
                System.setIn(System.in);
                System.setErr(System.err);
                System.setOut(System.out);
                try {
                    // mc.getInputStream().close();
                    consoleStream.close();
                } catch (Exception e) {
                    ProjectCreationPlugin.logThrowable(e);
                }
            }
        }
    };

    try {
        getContainer().run(true, true, op);
        UIUtil.refreshPackageExplorer();
    } catch (InterruptedException e) {
        return false;
    } catch (InvocationTargetException e) {
        e.printStackTrace();

        Throwable t = e.getTargetException();
        if (t instanceof CoreException) {
            CoreException ce = (CoreException) t;
            Throwable tmpt = ce.getStatus().getException();
            String errMessage = null;
            if (tmpt instanceof MavenExecuteException) {
                errMessage = "Maven command execute failed!";
            }
            ErrorDialog.openError(getShell(),
                    NLS.bind("Failed to create project \"{0}\"", nameRule.getProjectName()), errMessage,
                    ((CoreException) t).getStatus());
        } else {
            MessageDialog.openError(getShell(), "Creation Problems",
                    NLS.bind("Internal error: {0}", t.getMessage()));
        }
        ProjectCreationPlugin.logThrowable(t);
        return false;
    }
    return true;

}