3 * Copyright 2000-2009 JetBrains s.r.o.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package com
.intellij
.openapi
.application
.impl
;
19 import com
.intellij
.openapi
.application
.ApplicationNamesInfo
;
20 import com
.intellij
.openapi
.application
.PathManager
;
21 import com
.intellij
.openapi
.application
.ex
.ApplicationInfoEx
;
22 import com
.intellij
.openapi
.components
.ApplicationComponent
;
23 import com
.intellij
.openapi
.diagnostic
.Logger
;
24 import com
.intellij
.openapi
.util
.*;
25 import org
.jdom
.Document
;
26 import org
.jdom
.Element
;
27 import org
.jetbrains
.annotations
.NonNls
;
28 import org
.jetbrains
.annotations
.NotNull
;
32 import java
.util
.ArrayList
;
33 import java
.util
.Calendar
;
34 import java
.util
.GregorianCalendar
;
35 import java
.util
.List
;
37 public class ApplicationInfoImpl
extends ApplicationInfoEx
implements JDOMExternalizable
, ApplicationComponent
{
39 private static final Logger LOG
= Logger
.getInstance("#com.intellij.openapi.application.impl.ApplicationInfoImpl");
41 @NonNls private static final String BUILD_STUB
= "__BUILD_NUMBER__";
42 private String myCodeName
= null;
43 private String myMajorVersion
= null;
44 private String myMinorVersion
= null;
45 private String myBuildNumber
= null;
46 private String myLogoUrl
= null;
47 private Color myLogoTextColor
= new Color(0, 35, 135); // idea blue
48 private String myAboutLogoUrl
= null;
49 @NonNls private String myIconUrl
= "/icon.png";
50 @NonNls private String mySmallIconUrl
= "/icon_small.png";
51 @NonNls private String myOpaqueIconUrl
= "/icon.png";
52 @NonNls private String myToolWindowIconUrl
= "/general/toolWindowProject.png";
53 private Calendar myBuildDate
= null;
54 private String myPackageCode
= null;
55 private boolean myShowLicensee
= true;
56 private String myWelcomeScreenCaptionUrl
;
57 private String myWelcomeScreenDeveloperSloganUrl
;
58 private UpdateUrls myUpdateUrls
;
59 private String myDocumentationUrl
;
60 private String mySupportUrl
;
61 private String myEAPFeedbackUrl
;
62 private String myReleaseFeedbackUrl
;
63 private String myPluginManagerUrl
;
64 private String myPluginsListUrl
;
65 private String myPluginsDownloadUrl
;
66 private String myDefaultUpdateChannel
;
67 private String myWhatsNewUrl
;
68 private boolean myEAP
;
69 @NonNls private String myHelpFileName
= "ideahelp.jar";
70 @NonNls private String myHelpRootName
= "idea";
71 @NonNls private String myWebHelpUrl
= "http://www.jetbrains.com/idea/webhelp/";
72 private List
<PluginChooserPage
> myPluginChooserPages
= new ArrayList
<PluginChooserPage
>();
74 @NonNls private static final String IDEA_PATH
= "/idea/";
75 @NonNls private static final String ELEMENT_VERSION
= "version";
76 @NonNls private static final String ATTRIBUTE_MAJOR
= "major";
77 @NonNls private static final String ATTRIBUTE_MINOR
= "minor";
78 @NonNls private static final String ATTRIBUTE_CODENAME
= "codename";
79 @NonNls private static final String ELEMENT_BUILD
= "build";
80 @NonNls private static final String ATTRIBUTE_NUMBER
= "number";
81 @NonNls private static final String ATTRIBUTE_DATE
= "date";
82 @NonNls private static final String ELEMENT_LOGO
= "logo";
83 @NonNls private static final String ATTRIBUTE_URL
= "url";
84 @NonNls private static final String ATTRIBUTE_TEXTCOLOR
= "textcolor";
85 @NonNls private static final String ELEMENT_ABOUT
= "about";
86 @NonNls private static final String ELEMENT_ICON
= "icon";
87 @NonNls private static final String ATTRIBUTE_SIZE32
= "size32";
88 @NonNls private static final String ATTRIBUTE_SIZE16
= "size16";
89 @NonNls private static final String ATTRIBUTE_SIZE12
= "size12";
90 @NonNls private static final String ATTRIBUTE_SIZE32OPAQUE
= "size32opaque";
91 @NonNls private static final String ELEMENT_PACKAGE
= "package";
92 @NonNls private static final String ATTRIBUTE_CODE
= "code";
93 @NonNls private static final String ELEMENT_LICENSEE
= "licensee";
94 @NonNls private static final String ATTRIBUTE_SHOW
= "show";
95 @NonNls private static final String WELCOME_SCREEN_ELEMENT_NAME
= "welcome-screen";
96 @NonNls private static final String CAPTION_URL_ATTR
= "caption-url";
97 @NonNls private static final String SLOGAN_URL_ATTR
= "slogan-url";
98 @NonNls private static final String UPDATE_URLS_ELEMENT_NAME
= "update-urls";
99 @NonNls private static final String XML_EXTENSION
= ".xml";
100 @NonNls private static final String ATTRIBUTE_EAP
= "eap";
101 @NonNls private static final String HELP_ELEMENT_NAME
= "help";
102 @NonNls private static final String ATTRIBUTE_HELP_FILE
= "file";
103 @NonNls private static final String ATTRIBUTE_HELP_ROOT
= "root";
104 @NonNls private static final String PLUGINS_PAGE_ELEMENT_NAME
= "plugins-page";
105 @NonNls private static final String ELEMENT_DOCUMENTATION
= "documentation";
106 @NonNls private static final String ELEMENT_SUPPORT
= "support";
107 @NonNls private static final String ELEMENT_FEEDBACK
= "feedback";
108 @NonNls private static final String ATTRIBUTE_RELEASE_URL
= "release-url";
109 @NonNls private static final String ATTRIBUTE_EAP_URL
= "eap-url";
110 @NonNls private static final String ELEMENT_PLUGINS
= "plugins";
111 @NonNls private static final String ATTRIBUTE_LIST_URL
= "list-url";
112 @NonNls private static final String ATTRIBUTE_DOWNLOAD_URL
= "download-url";
113 @NonNls private static final String ATTRIBUTE_WEBHELP_URL
= "webhelp-url";
114 @NonNls private static final String ELEMENT_WHATSNEW
= "whatsnew";
115 private static final String DEFAULT_PLUGINS_HOST
= "http://plugins.intellij.net";
117 public void initComponent() { }
119 public void disposeComponent() {
122 public Calendar
getBuildDate() {
127 public BuildNumber
getBuild() {
128 return BuildNumber
.fromString(myBuildNumber
);
131 public String
getMajorVersion() {
132 return myMajorVersion
;
135 public String
getMinorVersion() {
136 return myMinorVersion
;
139 public String
getVersionName() {
140 final String fullName
= ApplicationNamesInfo
.getInstance().getFullProductName();
142 return fullName
+ " (" + myCodeName
+ ")";
148 public String
getHelpURL() {
149 return "jar:file:///" + getHelpJarPath() + "!/" + myHelpRootName
;
153 private String
getHelpJarPath() {
154 return PathManager
.getHomePath() + File
.separator
+ "help" + File
.separator
+ myHelpFileName
;
157 public String
getLogoUrl() {
161 public Color
getLogoTextColor() {
162 return myLogoTextColor
;
165 public String
getAboutLogoUrl() {
166 return myAboutLogoUrl
;
169 public String
getIconUrl() {
173 public String
getSmallIconUrl() {
174 return mySmallIconUrl
;
177 public String
getOpaqueIconUrl() {
178 return myOpaqueIconUrl
;
181 public String
getToolWindowIconUrl() {
182 return myToolWindowIconUrl
;
185 public String
getPackageCode() {
186 return myPackageCode
;
189 public String
getWelcomeScreenCaptionUrl() {
190 return myWelcomeScreenCaptionUrl
;
193 public String
getWelcomeScreenDeveloperSloganUrl() {
194 return myWelcomeScreenDeveloperSloganUrl
;
197 public boolean isEAP() {
201 public String
getDefaultUpdateChannel() {
202 return myDefaultUpdateChannel
;
205 public UpdateUrls
getUpdateUrls() {
209 public String
getDocumentationUrl() {
210 return myDocumentationUrl
;
213 public String
getSupportUrl() {
217 public String
getEAPFeedbackUrl() {
218 return myEAPFeedbackUrl
;
221 public String
getReleaseFeedbackUrl() {
222 return myReleaseFeedbackUrl
;
226 public String
getPluginManagerUrl() {
227 return myPluginManagerUrl
;
230 public String
getPluginsListUrl() {
231 return myPluginsListUrl
;
234 public String
getPluginsDownloadUrl() {
235 return myPluginsDownloadUrl
;
238 public String
getWebHelpUrl() {
242 public String
getWhatsNewUrl() {
243 return myWhatsNewUrl
;
246 public String
getFullApplicationName() {
247 @NonNls StringBuilder buffer
= new StringBuilder();
248 buffer
.append(getVersionName());
250 if (getMajorVersion() != null && !isEAP()) {
251 buffer
.append(getMajorVersion());
253 if (getMinorVersion() != null && getMinorVersion().length() > 0){
255 buffer
.append(getMinorVersion());
259 buffer
.append(getBuild().asString());
261 return buffer
.toString();
264 public boolean showLicenseeInfo() {
265 return myShowLicensee
;
268 private static ApplicationInfoImpl ourShadowInstance
;
270 public static ApplicationInfoEx
getShadowInstance() {
271 if (ourShadowInstance
== null) {
272 ourShadowInstance
= new ApplicationInfoImpl();
274 Document doc
= JDOMUtil
.loadDocument(ApplicationInfoImpl
.class.getResourceAsStream(IDEA_PATH
+
275 ApplicationNamesInfo
.getComponentName() +
277 ourShadowInstance
.readExternal(doc
.getRootElement());
279 catch (Exception e
) {
283 return ourShadowInstance
;
286 public void readExternal(Element parentNode
) throws InvalidDataException
{
287 Element versionElement
= parentNode
.getChild(ELEMENT_VERSION
);
288 if (versionElement
!= null) {
289 myMajorVersion
= versionElement
.getAttributeValue(ATTRIBUTE_MAJOR
);
290 myMinorVersion
= versionElement
.getAttributeValue(ATTRIBUTE_MINOR
);
291 myCodeName
= versionElement
.getAttributeValue(ATTRIBUTE_CODENAME
);
292 myEAP
= Boolean
.parseBoolean(versionElement
.getAttributeValue(ATTRIBUTE_EAP
));
293 myDefaultUpdateChannel
= versionElement
.getAttributeValue("update-channel");
296 Element buildElement
= parentNode
.getChild(ELEMENT_BUILD
);
297 if (buildElement
!= null) {
298 myBuildNumber
= buildElement
.getAttributeValue(ATTRIBUTE_NUMBER
);
299 String dateString
= buildElement
.getAttributeValue(ATTRIBUTE_DATE
);
300 if (dateString
.equals("__BUILD_DATE__")) {
301 myBuildDate
= new GregorianCalendar();
308 year
= Integer
.parseInt(dateString
.substring(0, 4));
309 month
= Integer
.parseInt(dateString
.substring(4, 6));
310 day
= Integer
.parseInt(dateString
.substring(6, 8));
312 catch (Exception ex
) {
318 myBuildDate
= new GregorianCalendar(year
, month
, day
);
322 Thread currentThread
= Thread
.currentThread();
323 currentThread
.setName(currentThread
.getName() + " " + myMajorVersion
+ "." + myMinorVersion
+ "#" + myBuildNumber
+ ", eap:"+myEAP
);
325 Element logoElement
= parentNode
.getChild(ELEMENT_LOGO
);
326 if (logoElement
!= null) {
327 myLogoUrl
= logoElement
.getAttributeValue(ATTRIBUTE_URL
);
328 final int rgb
= Integer
.parseInt(logoElement
.getAttributeValue(ATTRIBUTE_TEXTCOLOR
), 16);
329 myLogoTextColor
= new Color(rgb
);
332 Element aboutLogoElement
= parentNode
.getChild(ELEMENT_ABOUT
);
333 if (aboutLogoElement
!= null) {
334 myAboutLogoUrl
= aboutLogoElement
.getAttributeValue(ATTRIBUTE_URL
);
337 Element iconElement
= parentNode
.getChild(ELEMENT_ICON
);
338 if (iconElement
!= null) {
339 myIconUrl
= iconElement
.getAttributeValue(ATTRIBUTE_SIZE32
);
340 mySmallIconUrl
= iconElement
.getAttributeValue(ATTRIBUTE_SIZE16
);
341 myOpaqueIconUrl
= iconElement
.getAttributeValue(ATTRIBUTE_SIZE32OPAQUE
);
342 final String toolWindowIcon
= iconElement
.getAttributeValue(ATTRIBUTE_SIZE12
);
343 if (toolWindowIcon
!= null) {
344 myToolWindowIconUrl
= toolWindowIcon
;
348 Element packageElement
= parentNode
.getChild(ELEMENT_PACKAGE
);
349 if (packageElement
!= null) {
350 myPackageCode
= packageElement
.getAttributeValue(ATTRIBUTE_CODE
);
353 Element showLicensee
= parentNode
.getChild(ELEMENT_LICENSEE
);
354 if (showLicensee
!= null) {
355 myShowLicensee
= Boolean
.valueOf(showLicensee
.getAttributeValue(ATTRIBUTE_SHOW
)).booleanValue();
358 Element welcomeScreen
= parentNode
.getChild(WELCOME_SCREEN_ELEMENT_NAME
);
359 if (welcomeScreen
!= null) {
360 myWelcomeScreenCaptionUrl
= welcomeScreen
.getAttributeValue(CAPTION_URL_ATTR
);
361 myWelcomeScreenDeveloperSloganUrl
= welcomeScreen
.getAttributeValue(SLOGAN_URL_ATTR
);
364 Element helpElement
= parentNode
.getChild(HELP_ELEMENT_NAME
);
365 if (helpElement
!= null) {
366 myHelpFileName
= helpElement
.getAttributeValue(ATTRIBUTE_HELP_FILE
);
367 myHelpRootName
= helpElement
.getAttributeValue(ATTRIBUTE_HELP_ROOT
);
368 final String webHelpUrl
= helpElement
.getAttributeValue(ATTRIBUTE_WEBHELP_URL
);
369 if (webHelpUrl
!= null) {
370 myWebHelpUrl
= webHelpUrl
;
374 Element updateUrls
= parentNode
.getChild(UPDATE_URLS_ELEMENT_NAME
);
375 myUpdateUrls
= new UpdateUrlsImpl(updateUrls
);
377 Element documentationElement
= parentNode
.getChild(ELEMENT_DOCUMENTATION
);
378 if (documentationElement
!= null) {
379 myDocumentationUrl
= documentationElement
.getAttributeValue(ATTRIBUTE_URL
);
382 Element supportElement
= parentNode
.getChild(ELEMENT_SUPPORT
);
383 if (supportElement
!= null) {
384 mySupportUrl
= supportElement
.getAttributeValue(ATTRIBUTE_URL
);
387 Element feedbackElement
= parentNode
.getChild(ELEMENT_FEEDBACK
);
388 if (feedbackElement
!= null) {
389 myEAPFeedbackUrl
= feedbackElement
.getAttributeValue(ATTRIBUTE_EAP_URL
);
390 myReleaseFeedbackUrl
= feedbackElement
.getAttributeValue(ATTRIBUTE_RELEASE_URL
);
393 Element whatsnewElement
= parentNode
.getChild(ELEMENT_WHATSNEW
);
394 if (whatsnewElement
!= null) {
395 myWhatsNewUrl
= whatsnewElement
.getAttributeValue(ATTRIBUTE_URL
);
398 myPluginsListUrl
= DEFAULT_PLUGINS_HOST
+ "/plugins/list/";
399 myPluginsDownloadUrl
= DEFAULT_PLUGINS_HOST
+ "/pluginManager";
401 Element pluginsElement
= parentNode
.getChild(ELEMENT_PLUGINS
);
402 if (pluginsElement
!= null) {
403 myPluginManagerUrl
= pluginsElement
.getAttributeValue(ATTRIBUTE_URL
);
404 final String listUrl
= pluginsElement
.getAttributeValue(ATTRIBUTE_LIST_URL
);
405 if (listUrl
!= null) {
406 myPluginsListUrl
= listUrl
;
408 final String downloadUrl
= pluginsElement
.getAttributeValue(ATTRIBUTE_DOWNLOAD_URL
);
409 if (downloadUrl
!= null) {
410 myPluginsDownloadUrl
= downloadUrl
;
414 myPluginManagerUrl
= DEFAULT_PLUGINS_HOST
;
417 final String pluginsHost
= System
.getProperty("idea.plugins.host");
418 if (pluginsHost
!= null) {
419 myPluginsListUrl
= myPluginsListUrl
.replace(DEFAULT_PLUGINS_HOST
, pluginsHost
);
420 myPluginsDownloadUrl
= myPluginsDownloadUrl
.replace(DEFAULT_PLUGINS_HOST
, pluginsHost
);
423 myPluginChooserPages
= new ArrayList
<PluginChooserPage
>();
424 final List children
= parentNode
.getChildren(PLUGINS_PAGE_ELEMENT_NAME
);
425 for(Object child
: children
) {
426 myPluginChooserPages
.add(new PluginChooserPageImpl((Element
) child
));
430 public List
<PluginChooserPage
> getPluginChooserPages() {
431 return myPluginChooserPages
;
434 public void writeExternal(Element element
) throws WriteExternalException
{
435 throw new WriteExternalException();
440 public String
getComponentName() {
441 return ApplicationNamesInfo
.getComponentName();
444 private static class UpdateUrlsImpl
implements UpdateUrls
{
445 private String myCheckingUrl
;
446 private String myPatchesUrl
;
448 private UpdateUrlsImpl(Element element
) {
449 if (element
!= null) {
450 myCheckingUrl
= element
.getAttributeValue("check");
451 myPatchesUrl
= element
.getAttributeValue("patches");
455 public String
getCheckingUrl() {
456 return myCheckingUrl
;
459 public String
getPatchesUrl() {
464 private static class PluginChooserPageImpl
implements PluginChooserPage
{
465 private final String myTitle
;
466 private final String myCategory
;
467 private final String myDependentPlugin
;
469 private PluginChooserPageImpl(Element e
) {
470 myTitle
= e
.getAttributeValue("title");
471 myCategory
= e
.getAttributeValue("category");
472 myDependentPlugin
= e
.getAttributeValue("depends");
475 public String
getTitle() {
479 public String
getCategory() {
483 public String
getDependentPlugin() {
484 return myDependentPlugin
;