23
23
24
24
public class AddServiceStackRefHandler {
25
25
26
- private static final String dependencyGroupId = "net.servicestack" ;
27
- private static final String androidPackageId = "android" ;
28
- //Fallback version of dependencies if GitHub tags can't be checked.
29
- private static String dependencyVersion = "1.0.38" ;
30
- private static final String clientPackageId = "client" ;
31
-
32
26
private static INativeTypesHandler defaultNativeTypesHandler ;
33
27
34
- public static void setDependencyVersion (String version ) {
35
- dependencyVersion = version ;
36
- }
37
-
38
-
39
28
public static void handleOk (String addressUrl , String qualifiedPackageName ,
40
29
String fileName , String selectedDirectory ,
41
30
Module module , StringBuilder errorMessage ) {
@@ -53,7 +42,7 @@ public static void handleOk(String addressUrl, String qualifiedPackageName,
53
42
} catch (FileNotFoundException e ) {
54
43
e .printStackTrace ();
55
44
String message = "Failed to update build.gradle with '" +
56
- dependencyGroupId + ":" + clientPackageId + ":" + dependencyVersion +
45
+ DepConfig . getClientVersionString () +
57
46
"'. " + e .getLocalizedMessage ();
58
47
Notification notification = new Notification (
59
48
"ServiceStackIDEA" ,
@@ -95,13 +84,9 @@ private static List<String> getDtoLines(String addressUrl, String qualifiedPacka
95
84
return null ;
96
85
}
97
86
}
98
- catch (URISyntaxException e ) {
99
- e .printStackTrace ();
100
- DialogErrorMessages .appendInvalidEnpoint (errorMessage , addressUrl , e );
101
- return null ;
102
- } catch (MalformedURLException e ) {
87
+ catch (URISyntaxException | MalformedURLException e ) {
103
88
e .printStackTrace ();
104
- DialogErrorMessages .appendInvalidEnpoint (errorMessage , addressUrl , e );
89
+ DialogErrorMessages .appendInvalidEndpoint (errorMessage , addressUrl , e );
105
90
return null ;
106
91
} catch (IOException e ) {
107
92
e .printStackTrace ();
@@ -122,7 +107,7 @@ private static INativeTypesHandler getNativeTypesHandler(String fileName) {
122
107
private static boolean tryAddMavenDependency (Module module ) {
123
108
boolean showDto ;
124
109
String message = "Unable to locate module pom.xml file. Can't add required dependency '" +
125
- dependencyGroupId + ":" + clientPackageId + ":" + dependencyVersion +
110
+ DepConfig . getClientVersionString () +
126
111
"'." ;
127
112
Notification notification = new Notification (
128
113
"ServiceStackIDEA" ,
@@ -137,7 +122,8 @@ private static boolean tryAddMavenDependency(Module module) {
137
122
return false ;
138
123
}
139
124
File pomLibFile = new File (pomFilePath );
140
- showDto = pomFileHelper .addMavenDependency (module ,pomLibFile , dependencyGroupId , clientPackageId , dependencyVersion );
125
+ showDto = pomFileHelper .addMavenDependency (module ,pomLibFile , DepConfig .servicestackGroupId , DepConfig .clientPackageId , DepConfig .servicestackVersion ) ||
126
+ pomFileHelper .addMavenDependency (module ,pomLibFile , DepConfig .gsonGroupId , DepConfig .gsonPackageId , DepConfig .gsonVersion );
141
127
IDEAUtils .refreshFile (module ,pomFilePath ,showDto );
142
128
} catch (Exception e ) {
143
129
showDto = false ;
@@ -153,12 +139,12 @@ private static boolean tryAddMavenDependency(Module module) {
153
139
}
154
140
155
141
private static boolean addGradleDependencyIfRequired (Module module ) throws FileNotFoundException {
156
- boolean result = false ;
157
- if (GradleBuildFileHelper .addDependency (module ,dependencyGroupId , androidPackageId , dependencyVersion )) {
158
- result = true ;
142
+ if (GradleBuildFileHelper .addDependency (module , DepConfig .servicestackGroupId , DepConfig .androidPackageId , DepConfig .servicestackVersion ) ||
143
+ GradleBuildFileHelper .addDependency (module , DepConfig .gsonGroupId , DepConfig .gsonPackageId , DepConfig .gsonVersion )) {
159
144
IDEAUtils .refreshBuildFile (module );
145
+ return true ;
160
146
}
161
- return result ;
147
+ return false ;
162
148
}
163
149
164
150
private static String getDtoPath (Module module , String qualifiedPackageName , String selectedDirectory , String fileName , StringBuilder errorMessage ) throws FileNotFoundException {
@@ -199,8 +185,7 @@ private static String getDtoPath(Module module, String qualifiedPackageName, Str
199
185
public static String getDtoFileName (String name ) {
200
186
INativeTypesHandler nativeTypesHandler = getNativeTypesHandler (name );
201
187
int p = name .lastIndexOf ("." );
202
- String e = name .substring (p );
203
- if (p == -1 || !e .equals (nativeTypesHandler .getFileExtension ())) {
188
+ if (p == -1 || !name .substring (p ).equals (nativeTypesHandler .getFileExtension ())) {
204
189
/* file has no extension */
205
190
return name + nativeTypesHandler .getFileExtension ();
206
191
} else {
@@ -212,8 +197,7 @@ public static String getDtoFileName(String name) {
212
197
public static String getDtoNameWithoutExtension (String name ) {
213
198
INativeTypesHandler nativeTypesHandler = getNativeTypesHandler (name );
214
199
int p = name .lastIndexOf ("." );
215
- String e = name .substring (p );
216
- if (p == -1 || !e .equals (nativeTypesHandler .getFileExtension ())) {
200
+ if (p == -1 || !name .substring (p ).equals (nativeTypesHandler .getFileExtension ())) {
217
201
/* file has no extension */
218
202
return name ;
219
203
} else {
0 commit comments