66
66
67
67
public final class ProjectCommand {
68
68
69
- public static class MainClassInfo {
69
+ private static class MainClassInfo {
70
70
71
71
public String name ;
72
72
@@ -78,10 +78,25 @@ public MainClassInfo(String name, String path) {
78
78
}
79
79
}
80
80
81
- private static final Gson gson = new GsonBuilder ()
82
- .registerTypeAdapterFactory (new CollectionTypeAdapter .Factory ())
83
- .registerTypeAdapterFactory (new EnumTypeAdapter .Factory ())
84
- .create ();
81
+ private static class exportResult {
82
+ public boolean result ;
83
+ public String message ;
84
+ public String log ;
85
+
86
+ exportResult (boolean result ) {
87
+ this .result = result ;
88
+ this .log = "" ;
89
+ }
90
+
91
+ exportResult (boolean result , String message ) {
92
+ this .result = result ;
93
+ this .message = message ;
94
+ this .log = "" ;
95
+ }
96
+ }
97
+
98
+ private static final Gson gson = new GsonBuilder ().registerTypeAdapterFactory (new CollectionTypeAdapter .Factory ())
99
+ .registerTypeAdapterFactory (new EnumTypeAdapter .Factory ()).create ();
85
100
86
101
public static List <PackageNode > listProjects (List <Object > arguments , IProgressMonitor monitor ) {
87
102
String workspaceUri = (String ) arguments .get (0 );
@@ -95,9 +110,11 @@ public static List<PackageNode> listProjects(List<Object> arguments, IProgressMo
95
110
if (!project .isAccessible () || !ProjectUtils .isJavaProject (project )) {
96
111
continue ;
97
112
}
98
- // Ignore all the projects that's not contained in the workspace folder, except for the invisible project.
113
+ // Ignore all the projects that's not contained in the workspace folder, except
114
+ // for the invisible project.
99
115
// This check is needed in multi-root scenario.
100
- if ((!ResourceUtils .isContainedIn (project .getLocation (), paths ) && !Objects .equals (project .getName (), invisibleProjectName ))) {
116
+ if ((!ResourceUtils .isContainedIn (project .getLocation (), paths )
117
+ && !Objects .equals (project .getName (), invisibleProjectName ))) {
101
118
continue ;
102
119
}
103
120
PackageNode projectNode = PackageNode .createNodeForProject (JavaCore .create (project ));
@@ -115,7 +132,8 @@ public static boolean refreshLibraries(List<Object> arguments, IProgressMonitor
115
132
String projectName = ProjectUtils .getWorkspaceInvisibleProjectName (workspacePath );
116
133
IProject project = getWorkspaceRoot ().getProject (projectName );
117
134
try {
118
- ReferencedLibraries libraries = JavaLanguageServerPlugin .getPreferencesManager ().getPreferences ().getReferencedLibraries ();
135
+ ReferencedLibraries libraries = JavaLanguageServerPlugin .getPreferencesManager ().getPreferences ()
136
+ .getReferencedLibraries ();
119
137
UpdateClasspathJob .getInstance ().updateClasspath (JavaCore .create (project ), libraries );
120
138
return true ;
121
139
} catch (Exception e ) {
@@ -128,48 +146,47 @@ private static IWorkspaceRoot getWorkspaceRoot() {
128
146
return ResourcesPlugin .getWorkspace ().getRoot ();
129
147
}
130
148
131
- public static boolean exportJar (List <Object > arguments , IProgressMonitor monitor ) {
149
+ public static exportResult exportJar (List <Object > arguments , IProgressMonitor monitor ) {
132
150
if (arguments .size () < 3 ) {
133
- return false ;
151
+ return new exportResult ( false , "Invalid export Arguments" ) ;
134
152
}
135
153
String mainMethod = gson .fromJson (gson .toJson (arguments .get (0 )), String .class );
136
154
String [] classpaths = gson .fromJson (gson .toJson (arguments .get (1 )), String [].class );
137
155
String destination = gson .fromJson (gson .toJson (arguments .get (2 )), String .class );
138
156
Manifest manifest = new Manifest ();
139
157
manifest .getMainAttributes ().put (Attributes .Name .MANIFEST_VERSION , "1.0" );
140
158
if (mainMethod .length () > 0 ) {
141
- manifest .getMainAttributes ().put (Attributes .Name .MAIN_CLASS ,mainMethod );
159
+ manifest .getMainAttributes ().put (Attributes .Name .MAIN_CLASS , mainMethod );
142
160
}
143
161
try (JarOutputStream target = new JarOutputStream (new FileOutputStream (destination ), manifest )) {
144
- Set <String > fDirectories = new HashSet <>();
162
+ Set <String > directories = new HashSet <>();
145
163
for (String classpath : classpaths ) {
146
164
if (classpath != null ) {
147
- if (classpath .endsWith (".jar" )) {
165
+ if (classpath .endsWith (".jar" )) {
148
166
ZipFile zip = new ZipFile (classpath );
149
- writeArchive (zip , true , true , target , fDirectories , monitor );
150
- }
151
- else {
167
+ writeArchive (zip , true , true , target , directories , monitor );
168
+ } else {
152
169
File folder = new File (classpath );
153
- writeFileRecursively (folder , target , fDirectories , folder .getAbsolutePath ().length () + 1 );
170
+ writeFileRecursively (folder , target , directories , folder .getAbsolutePath ().length () + 1 );
154
171
}
155
172
}
156
173
}
157
174
} catch (Exception e ) {
158
- return false ;
175
+ return new exportResult ( false , e . getMessage ()) ;
159
176
}
160
- return true ;
177
+ return new exportResult ( true ) ;
161
178
}
162
179
163
- private static void writeFileRecursively (File folder , JarOutputStream fJarOutputStream , Set <String > fDirectories , int len ) {
180
+ private static void writeFileRecursively (File folder , JarOutputStream jarOutputStream , Set <String > directories ,
181
+ int len ) {
164
182
File [] files = folder .listFiles ();
165
183
for (File file : files ) {
166
184
if (file .isDirectory ()) {
167
- writeFileRecursively (file , fJarOutputStream , fDirectories , len );
185
+ writeFileRecursively (file , jarOutputStream , directories , len );
168
186
} else if (file .isFile ()) {
169
187
try {
170
- writeFile (file , new Path (file .getAbsolutePath ().substring (len )), true , true , fJarOutputStream , fDirectories );
171
- }
172
- catch (Exception e ) {
188
+ writeFile (file , new Path (file .getAbsolutePath ().substring (len )), true , true , jarOutputStream , directories );
189
+ } catch (Exception e ) {
173
190
// do nothing
174
191
}
175
192
}
@@ -219,8 +236,8 @@ public void acceptSearchMatch(SearchMatch match) {
219
236
};
220
237
SearchEngine searchEngine = new SearchEngine ();
221
238
try {
222
- searchEngine .search (pattern , new SearchParticipant [] {SearchEngine .getDefaultSearchParticipant ()} ,
223
- scope , requestor , new NullProgressMonitor ());
239
+ searchEngine .search (pattern , new SearchParticipant [] { SearchEngine .getDefaultSearchParticipant () }, scope ,
240
+ requestor , new NullProgressMonitor ());
224
241
} catch (CoreException e ) {
225
242
// ignore
226
243
}
0 commit comments