|
9 | 9 | import consulo.content.bundle.SdkModificator; |
10 | 10 | import consulo.google.gwt.base.icon.GwtIconGroup; |
11 | 11 | import consulo.gwt.base.module.extension.path.GwtSdkUtil; |
12 | | -import consulo.ui.image.Image; |
| 12 | +import consulo.localize.LocalizeValue; |
13 | 13 | import consulo.util.lang.Comparing; |
14 | 14 | import consulo.virtualFileSystem.VirtualFile; |
15 | 15 | import consulo.virtualFileSystem.archive.ArchiveVfsUtil; |
16 | | - |
17 | 16 | import jakarta.annotation.Nonnull; |
18 | 17 | import jakarta.annotation.Nullable; |
| 18 | + |
19 | 19 | import java.io.File; |
20 | 20 | import java.io.IOException; |
21 | 21 | import java.nio.charset.StandardCharsets; |
|
26 | 26 | * @since 09.07.13. |
27 | 27 | */ |
28 | 28 | @ExtensionImpl |
29 | | -public class GoogleGwtSdkType extends GwtSdkBaseType |
30 | | -{ |
31 | | - private static final String LINE_START = "Google Web Toolkit "; |
32 | | - private static final String LINE_START2 = "GWT "; |
33 | | - |
34 | | - public GoogleGwtSdkType() |
35 | | - { |
36 | | - super("GOOGLE_GWT_SDK"); |
37 | | - } |
38 | | - |
39 | | - @Override |
40 | | - @Nonnull |
41 | | - public GwtVersion getVersion(Sdk sdk) |
42 | | - { |
43 | | - return GwtSdkUtil.detectVersion(sdk); |
44 | | - } |
45 | | - |
46 | | - @Nullable |
47 | | - public String getDevJarPath(Sdk sdk) |
48 | | - { |
49 | | - return GwtSdkUtil.getDevJarPath(sdk.getHomePath()); |
50 | | - } |
51 | | - |
52 | | - @Nullable |
53 | | - public String getUserJarPath(Sdk sdk) |
54 | | - { |
55 | | - return GwtSdkUtil.getUserJarPath(sdk.getHomePath()); |
56 | | - } |
57 | | - |
58 | | - @Nullable |
59 | | - @Override |
60 | | - public Image getIcon() |
61 | | - { |
62 | | - return GwtIconGroup.gwt(); |
63 | | - } |
64 | | - |
65 | | - @Override |
66 | | - public boolean isValidSdkHome(String s) |
67 | | - { |
68 | | - File file = new File(s, "gwt-dev.jar"); |
69 | | - return file.exists(); |
70 | | - } |
71 | | - |
72 | | - @Nullable |
73 | | - @Override |
74 | | - public String getVersionString(String s) |
75 | | - { |
76 | | - File file = new File(s, "about.txt"); |
77 | | - if(!file.exists()) |
78 | | - { |
79 | | - return "0.0"; |
80 | | - } |
81 | | - try |
82 | | - { |
83 | | - String text = Files.readString(file.toPath(), StandardCharsets.UTF_8); |
84 | | - String[] lines = text.split("\n"); |
85 | | - if(lines.length > 0) |
86 | | - { |
87 | | - String line = lines[0]; |
88 | | - if(line.startsWith(LINE_START)) |
89 | | - { |
90 | | - return line.substring(LINE_START.length(), line.length()); |
91 | | - } |
92 | | - else if(line.startsWith(LINE_START2)) |
93 | | - { |
94 | | - return line.substring(LINE_START2.length(), line.length()); |
95 | | - } |
96 | | - } |
97 | | - } |
98 | | - catch(IOException ignored) |
99 | | - { |
100 | | - } |
101 | | - return "0.0"; |
102 | | - } |
103 | | - |
104 | | - @Override |
105 | | - public void setupSdkPaths(Sdk sdk) |
106 | | - { |
107 | | - SdkModificator sdkModificator = sdk.getSdkModificator(); |
108 | | - |
109 | | - VirtualFile homeDirectory = sdk.getHomeDirectory(); |
110 | | - if(homeDirectory == null) |
111 | | - { |
112 | | - sdkModificator.commitChanges(); |
113 | | - return; |
114 | | - } |
115 | | - |
116 | | - for(VirtualFile virtualFile : homeDirectory.getChildren()) |
117 | | - { |
118 | | - String extension = virtualFile.getExtension(); |
119 | | - String name = virtualFile.getNameWithoutExtension(); |
120 | | - |
121 | | - if(Comparing.equal(extension, "jar")) |
122 | | - { |
123 | | - if(name.endsWith("-src") || name.endsWith("-sources")) |
124 | | - { |
125 | | - sdkModificator.addRoot(ArchiveVfsUtil.getArchiveRootForLocalFile(virtualFile), SourcesOrderRootType.getInstance()); |
126 | | - } |
127 | | - else if(!name.endsWith("+src")) |
128 | | - { |
129 | | - sdkModificator.addRoot(ArchiveVfsUtil.getArchiveRootForLocalFile(virtualFile), BinariesOrderRootType.getInstance()); |
130 | | - } |
131 | | - |
132 | | - if(name.equals("gwt-user")) |
133 | | - { |
134 | | - sdkModificator.addRoot(ArchiveVfsUtil.getArchiveRootForLocalFile(virtualFile), SourcesOrderRootType.getInstance()); |
135 | | - } |
136 | | - } |
137 | | - else if(name.equals("doc") && virtualFile.isDirectory()) |
138 | | - { |
139 | | - VirtualFile javadoc = virtualFile.findChild("javadoc"); |
140 | | - if(javadoc != null) |
141 | | - { |
142 | | - sdkModificator.addRoot(javadoc, DocumentationOrderRootType.getInstance()); |
143 | | - } |
144 | | - } |
145 | | - } |
146 | | - |
147 | | - sdkModificator.commitChanges(); |
148 | | - } |
149 | | - |
150 | | - @Override |
151 | | - public String suggestSdkName(String currentSdkName, String sdkHome) |
152 | | - { |
153 | | - return getPresentableName() + " " + getVersionString(sdkHome); |
154 | | - } |
155 | | - |
156 | | - @Nonnull |
157 | | - @Override |
158 | | - public String getPresentableName() |
159 | | - { |
160 | | - return "GWT"; |
161 | | - } |
| 29 | +public class GoogleGwtSdkType extends GwtSdkBaseType { |
| 30 | + private static final String LINE_START = "Google Web Toolkit "; |
| 31 | + private static final String LINE_START2 = "GWT "; |
| 32 | + |
| 33 | + public GoogleGwtSdkType() { |
| 34 | + super("GOOGLE_GWT_SDK", LocalizeValue.localizeTODO("GWT"), GwtIconGroup.gwt()); |
| 35 | + } |
| 36 | + |
| 37 | + @Override |
| 38 | + @Nonnull |
| 39 | + public GwtVersion getVersion(Sdk sdk) { |
| 40 | + return GwtSdkUtil.detectVersion(sdk); |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + @Nullable |
| 45 | + public String getDevJarPath(Sdk sdk) { |
| 46 | + return GwtSdkUtil.getDevJarPath(sdk.getHomePath()); |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + @Nullable |
| 51 | + public String getUserJarPath(Sdk sdk) { |
| 52 | + return GwtSdkUtil.getUserJarPath(sdk.getHomePath()); |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public boolean isValidSdkHome(String s) { |
| 57 | + File file = new File(s, "gwt-dev.jar"); |
| 58 | + return file.exists(); |
| 59 | + } |
| 60 | + |
| 61 | + @Nullable |
| 62 | + @Override |
| 63 | + public String getVersionString(String s) { |
| 64 | + File file = new File(s, "about.txt"); |
| 65 | + if (!file.exists()) { |
| 66 | + return "0.0"; |
| 67 | + } |
| 68 | + try { |
| 69 | + String text = Files.readString(file.toPath(), StandardCharsets.UTF_8); |
| 70 | + String[] lines = text.split("\n"); |
| 71 | + if (lines.length > 0) { |
| 72 | + String line = lines[0]; |
| 73 | + if (line.startsWith(LINE_START)) { |
| 74 | + return line.substring(LINE_START.length(), line.length()); |
| 75 | + } |
| 76 | + else if (line.startsWith(LINE_START2)) { |
| 77 | + return line.substring(LINE_START2.length(), line.length()); |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + catch (IOException ignored) { |
| 82 | + } |
| 83 | + return "0.0"; |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public void setupSdkPaths(Sdk sdk) { |
| 88 | + SdkModificator sdkModificator = sdk.getSdkModificator(); |
| 89 | + |
| 90 | + VirtualFile homeDirectory = sdk.getHomeDirectory(); |
| 91 | + if (homeDirectory == null) { |
| 92 | + sdkModificator.commitChanges(); |
| 93 | + return; |
| 94 | + } |
| 95 | + |
| 96 | + for (VirtualFile virtualFile : homeDirectory.getChildren()) { |
| 97 | + String extension = virtualFile.getExtension(); |
| 98 | + String name = virtualFile.getNameWithoutExtension(); |
| 99 | + |
| 100 | + if (Comparing.equal(extension, "jar")) { |
| 101 | + if (name.endsWith("-src") || name.endsWith("-sources")) { |
| 102 | + sdkModificator.addRoot(ArchiveVfsUtil.getArchiveRootForLocalFile(virtualFile), SourcesOrderRootType.getInstance()); |
| 103 | + } |
| 104 | + else if (!name.endsWith("+src")) { |
| 105 | + sdkModificator.addRoot(ArchiveVfsUtil.getArchiveRootForLocalFile(virtualFile), BinariesOrderRootType.getInstance()); |
| 106 | + } |
| 107 | + |
| 108 | + if (name.equals("gwt-user")) { |
| 109 | + sdkModificator.addRoot(ArchiveVfsUtil.getArchiveRootForLocalFile(virtualFile), SourcesOrderRootType.getInstance()); |
| 110 | + } |
| 111 | + } |
| 112 | + else if (name.equals("doc") && virtualFile.isDirectory()) { |
| 113 | + VirtualFile javadoc = virtualFile.findChild("javadoc"); |
| 114 | + if (javadoc != null) { |
| 115 | + sdkModificator.addRoot(javadoc, DocumentationOrderRootType.getInstance()); |
| 116 | + } |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + sdkModificator.commitChanges(); |
| 121 | + } |
162 | 122 | } |
0 commit comments