Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c1656529ecf6262454b27ecfabdde991e375ff5d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
 * Copyright (c) 2013 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.emf.cdo.releng.internal.setup;

import org.eclipse.emf.cdo.releng.internal.setup.ui.ErrorDialog;
import org.eclipse.emf.cdo.releng.setup.SetupConstants;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IStartup;
import org.eclipse.ui.plugin.AbstractUIPlugin;

import org.osgi.framework.BundleContext;

/**
 * @author Eike Stepper
 */
public class Activator extends AbstractUIPlugin
{
  public static final String PLUGIN_ID = "org.eclipse.emf.cdo.releng.setup";

  public static final String CDO_URL = "http://download.eclipse.org/modeling/emf/cdo/updates/integration";

  private static Activator plugin;

  private static BundleContext bundleContext;

  public Activator()
  {
  }

  @Override
  public void start(BundleContext context) throws Exception
  {
    super.start(context);
    bundleContext = context;
    plugin = this;

    if (SetupConstants.SETUP_IDE && !SetupConstants.SETUP_SKIP)
    {
      Display.getDefault().asyncExec(new Runnable()
      {
        public void run()
        {
          try
          {
            // IDEHelper.waitForIDE();

            SetupTaskPerformer setupTaskPerformer = new SetupTaskPerformer(false);
            setupTaskPerformer.perform();
          }
          catch (Throwable ex)
          {
            log(ex);
            ErrorDialog.open(ex);
          }
        }
      });
    }
  }

  @Override
  public void stop(BundleContext context) throws Exception
  {
    plugin = null;
    super.stop(context);
  }

  public static void log(String message)
  {
    log(message, IStatus.INFO);
  }

  protected static void log(String message, int severity)
  {
    plugin.getLog().log(new Status(severity, PLUGIN_ID, message));
  }

  public static void log(IStatus status)
  {
    plugin.getLog().log(status);
  }

  public static String log(Throwable t)
  {
    IStatus status = getStatus(t);
    log(status);
    return status.getMessage();
  }

  public static IStatus getStatus(Throwable t)
  {
    if (t instanceof CoreException)
    {
      CoreException coreException = (CoreException)t;
      return coreException.getStatus();
    }

    String msg = t.getLocalizedMessage();
    if (msg == null || msg.length() == 0)
    {
      msg = t.getClass().getName();
    }

    return new Status(IStatus.ERROR, PLUGIN_ID, msg, t);
  }

  public static BundleContext getBundleContext()
  {
    return bundleContext;
  }

  public static Activator getDefault()
  {
    return plugin;
  }

  /**
   * @author Eike Stepper
   */
  public static final class EarlyStartup implements IStartup
  {
    public void earlyStartup()
    {
    }
  }

  // /**
  // * @author Eike Stepper
  // */
  // public static final class IDEHelper
  // {
  // public static void waitForIDE()
  // {
  // PlatformUI.getWorkbench().addWorkbenchListener();
  // }
  // }
}

Back to the top