6666
6767public final class ProjectCommand {
6868
69- public static class MainClassInfo {
69+ private static class MainClassInfo {
7070
7171 public String name ;
7272
@@ -78,10 +78,25 @@ public MainClassInfo(String name, String path) {
7878 }
7979 }
8080
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 ();
85100
86101 public static List <PackageNode > listProjects (List <Object > arguments , IProgressMonitor monitor ) {
87102 String workspaceUri = (String ) arguments .get (0 );
@@ -95,9 +110,11 @@ public static List<PackageNode> listProjects(List<Object> arguments, IProgressMo
95110 if (!project .isAccessible () || !ProjectUtils .isJavaProject (project )) {
96111 continue ;
97112 }
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.
99115 // 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 ))) {
101118 continue ;
102119 }
103120 PackageNode projectNode = PackageNode .createNodeForProject (JavaCore .create (project ));
@@ -115,7 +132,8 @@ public static boolean refreshLibraries(List<Object> arguments, IProgressMonitor
115132 String projectName = ProjectUtils .getWorkspaceInvisibleProjectName (workspacePath );
116133 IProject project = getWorkspaceRoot ().getProject (projectName );
117134 try {
118- ReferencedLibraries libraries = JavaLanguageServerPlugin .getPreferencesManager ().getPreferences ().getReferencedLibraries ();
135+ ReferencedLibraries libraries = JavaLanguageServerPlugin .getPreferencesManager ().getPreferences ()
136+ .getReferencedLibraries ();
119137 UpdateClasspathJob .getInstance ().updateClasspath (JavaCore .create (project ), libraries );
120138 return true ;
121139 } catch (Exception e ) {
@@ -128,48 +146,47 @@ private static IWorkspaceRoot getWorkspaceRoot() {
128146 return ResourcesPlugin .getWorkspace ().getRoot ();
129147 }
130148
131- public static boolean exportJar (List <Object > arguments , IProgressMonitor monitor ) {
149+ public static exportResult exportJar (List <Object > arguments , IProgressMonitor monitor ) {
132150 if (arguments .size () < 3 ) {
133- return false ;
151+ return new exportResult ( false , "Invalid export Arguments" ) ;
134152 }
135153 String mainMethod = gson .fromJson (gson .toJson (arguments .get (0 )), String .class );
136154 String [] classpaths = gson .fromJson (gson .toJson (arguments .get (1 )), String [].class );
137155 String destination = gson .fromJson (gson .toJson (arguments .get (2 )), String .class );
138156 Manifest manifest = new Manifest ();
139157 manifest .getMainAttributes ().put (Attributes .Name .MANIFEST_VERSION , "1.0" );
140158 if (mainMethod .length () > 0 ) {
141- manifest .getMainAttributes ().put (Attributes .Name .MAIN_CLASS ,mainMethod );
159+ manifest .getMainAttributes ().put (Attributes .Name .MAIN_CLASS , mainMethod );
142160 }
143161 try (JarOutputStream target = new JarOutputStream (new FileOutputStream (destination ), manifest )) {
144- Set <String > fDirectories = new HashSet <>();
162+ Set <String > directories = new HashSet <>();
145163 for (String classpath : classpaths ) {
146164 if (classpath != null ) {
147- if (classpath .endsWith (".jar" )) {
165+ if (classpath .endsWith (".jar" )) {
148166 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 {
152169 File folder = new File (classpath );
153- writeFileRecursively (folder , target , fDirectories , folder .getAbsolutePath ().length () + 1 );
170+ writeFileRecursively (folder , target , directories , folder .getAbsolutePath ().length () + 1 );
154171 }
155172 }
156173 }
157174 } catch (Exception e ) {
158- return false ;
175+ return new exportResult ( false , e . getMessage ()) ;
159176 }
160- return true ;
177+ return new exportResult ( true ) ;
161178 }
162179
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 ) {
164182 File [] files = folder .listFiles ();
165183 for (File file : files ) {
166184 if (file .isDirectory ()) {
167- writeFileRecursively (file , fJarOutputStream , fDirectories , len );
185+ writeFileRecursively (file , jarOutputStream , directories , len );
168186 } else if (file .isFile ()) {
169187 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 ) {
173190 // do nothing
174191 }
175192 }
@@ -219,8 +236,8 @@ public void acceptSearchMatch(SearchMatch match) {
219236 };
220237 SearchEngine searchEngine = new SearchEngine ();
221238 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 ());
224241 } catch (CoreException e ) {
225242 // ignore
226243 }
0 commit comments