2020import java .net .URL ;
2121import java .util .ArrayList ;
2222import java .util .Collection ;
23+ import java .util .Iterator ;
24+ import java .util .concurrent .ExecutorService ;
25+ import java .util .concurrent .Executors ;
2326import org .vast .xml .DOMHelper ;
2427import com .google .gson .Gson ;
2528import com .google .gson .JsonArray ;
2629import com .google .gson .JsonElement ;
2730import com .google .gson .JsonObject ;
2831import com .google .gson .JsonParser ;
2932import com .google .gson .reflect .TypeToken ;
33+ import com .vaadin .data .Item ;
3034import com .vaadin .server .ExternalResource ;
3135import com .vaadin .ui .Component ;
3236import com .vaadin .ui .HorizontalLayout ;
@@ -58,18 +62,20 @@ public class DownloadModulesPopup extends Window
5862 private static final String BINTRAY_WEB_ROOT = "https://bintray.com/" + BINTRAY_SUBJECT + "/" + BINTRAY_REPO + "/" ;
5963 private static final String BINTRAY_CONTENT_ROOT = "https://dl.bintray.com/" + BINTRAY_SUBJECT + "/" + BINTRAY_REPO + "/" ;
6064 private static final String LINK_TARGET = "osh-bintray" ;
65+ private static final String LOADING_MSG = "Loading..." ;
6166
6267 TreeTable table ;
68+ ExecutorService exec = Executors .newFixedThreadPool (2 );
6369
6470
6571 static class BintrayArtifact
6672 {
6773 public String name ;
6874 public String path ;
6975 public String label ;
70- public String desc ;
76+ public String desc = LOADING_MSG ;
7177 public String version ;
72- public String author ;
78+ public String author = LOADING_MSG ;
7379 }
7480
7581
@@ -104,19 +110,33 @@ public DownloadModulesPopup()
104110 center ();
105111
106112 // load info in separate thread
107- Thread t = new Thread ()
113+ exec . execute ( new Runnable ()
108114 {
109115 public void run ()
110116 {
111117 try
112118 {
113- for (final String name : getBintrayPackageNames ())
119+ for (final String pkgName : getBintrayPackageNames ())
114120 {
121+ // don't list core modules
122+ if (pkgName .equals ("osh-core" ))
123+ continue ;
124+
115125 try
116126 {
117- final BintrayPackage pkg = getBintrayPackageInfo (name );
118- pkg .files = getBintrayPackageFiles (name );
127+ final BintrayPackage pkg = getBintrayPackageInfo (pkgName );
128+ pkg .files = getBintrayPackageFiles (pkgName );
129+
130+ // remove non-executable jar files
131+ Iterator <BintrayArtifact > it = pkg .files .iterator ();
132+ while (it .hasNext ())
133+ {
134+ String fName = it .next ().name ;
135+ if (!fName .endsWith ("jar" ) || fName .endsWith ("-sources.jar" ) || fName .endsWith ("-javadoc.jar" ))
136+ it .remove ();
137+ }
119138
139+ // draw table in UI thread
120140 getUI ().access (new Runnable () {
121141 public void run ()
122142 {
@@ -127,35 +147,62 @@ public void run()
127147 table = new TreeTable ();
128148 table .setSizeFull ();
129149 table .setSelectable (false );
130- table .addContainerProperty ("name" , Component .class , null );
131- table .addContainerProperty ("desc" , String .class , null );
132- table .addContainerProperty ("version" , String .class , null );
133- table .addContainerProperty ("author" , String .class , null );
134- table .setColumnHeaders (new String [] {"Add-On Name " , "Description " , "Version " , "Author" });
135- table .setColumnWidth ("name" , 300 );
136- table .setColumnExpandRatio ("desc" , 10 );
150+ table .addContainerProperty (ModuleTypeSelectionPopup . PROP_NAME , Component .class , null );
151+ table .addContainerProperty (ModuleTypeSelectionPopup . PROP_VERSION , String .class , null );
152+ table .addContainerProperty (ModuleTypeSelectionPopup . PROP_DESC , String .class , null );
153+ table .addContainerProperty (ModuleTypeSelectionPopup . PROP_AUTHOR , String .class , null );
154+ table .setColumnHeaders (new String [] {"Package " , "OSH Version " , "Description " , "Author" });
155+ table .setColumnWidth (ModuleTypeSelectionPopup . PROP_NAME , 300 );
156+ table .setColumnExpandRatio (ModuleTypeSelectionPopup . PROP_DESC , 10 );
137157 layout .addComponent (table , 0 );
138158 }
139159
140160 // add package info
141161 String href = BINTRAY_WEB_ROOT + pkg .name ;
142162 Link link = new Link (pkg .name , new ExternalResource (href ), LINK_TARGET , 0 , 0 , null );
143- Object parentId = table .addItem (new Object [] {link , pkg .desc , null , null }, null );
144-
145- // add all jar files
163+ Object parentId = table .addItem (new Object [] {link , null , pkg .desc , null }, null );
164+
165+ // add artifacts to table
146166 for (BintrayArtifact f : pkg .files )
147167 {
148- if (f .name .endsWith ("jar" ) && !f .name .endsWith ("-sources.jar" ) && !f .name .endsWith ("-javadoc.jar" ))
149- {
150- href = BINTRAY_CONTENT_ROOT + f .path ;
151- link = new Link (f .label , new ExternalResource (href ), "_self" , 0 , 0 , null );
152- Object id = table .addItem (new Object [] {link , f .desc , f .version , f .author }, null );
153- table .setParent (id , parentId );
154- table .setChildrenAllowed (id , false );
155- }
168+ href = BINTRAY_CONTENT_ROOT + f .path ;
169+ link = new Link (f .name , new ExternalResource (href ), "_self" , 0 , 0 , null );
170+ Object id = table .addItem (new Object [] {link , f .version , f .desc , f .author }, f .name );
171+ table .setParent (id , parentId );
172+ table .setChildrenAllowed (id , false );
156173 }
157174
158175 getUI ().push ();
176+
177+ // also load info from POM in separate thread
178+ exec .execute (new Runnable ()
179+ {
180+ public void run ()
181+ {
182+ try
183+ {
184+ for (final BintrayArtifact f : pkg .files )
185+ {
186+ String pomUrl = BINTRAY_CONTENT_ROOT + f .path .replaceAll (".jar" , ".pom" );
187+ readInfoFromPom (pomUrl , f );
188+
189+ getUI ().access (new Runnable () {
190+ public void run ()
191+ {
192+ Item item = table .getItem (f .name );
193+ item .getItemProperty (ModuleTypeSelectionPopup .PROP_DESC ).setValue (f .desc );
194+ item .getItemProperty (ModuleTypeSelectionPopup .PROP_AUTHOR ).setValue (f .author );
195+ getUI ().push ();
196+ }
197+ });
198+ }
199+ }
200+ catch (Exception e )
201+ {
202+
203+ }
204+ }
205+ });
159206 }
160207 });
161208 }
@@ -164,7 +211,7 @@ public void run()
164211 getUI ().access (new Runnable () {
165212 public void run ()
166213 {
167- table .addItem (new Object [] {null , "Error loading package " + name , null , null }, null );
214+ table .addItem (new Object [] {null , "Error loading package " + pkgName , null , null }, null );
168215 getUI ().push ();
169216 }
170217 });
@@ -191,8 +238,7 @@ public void run()
191238 });
192239 }
193240 }
194- };
195- t .start ();
241+ });
196242 }
197243
198244
@@ -233,22 +279,15 @@ protected BintrayPackage getBintrayPackageInfo(String pkgName) throws Exception
233279
234280 protected Collection <BintrayArtifact > getBintrayPackageFiles (String pkgName ) throws Exception
235281 {
236- Collection <BintrayArtifact > files ;
282+ final Collection <BintrayArtifact > files ;
237283
238284 URL url = new URL (BINTRAY_API_ROOT + BINTRAY_PKG + pkgName + "/files" );
239285 try (BufferedReader reader = new BufferedReader (new InputStreamReader (url .openStream ())))
240286 {
241287 Gson gson = new Gson ();
242288 Type collectionType = new TypeToken <Collection <BintrayArtifact >>(){}.getType ();
243289 files = gson .fromJson (reader , collectionType );
244- }
245-
246- // also load info from POM
247- for (BintrayArtifact file : files )
248- {
249- String pomUrl = BINTRAY_CONTENT_ROOT + file .path .replaceAll (".jar" , ".pom" );
250- readInfoFromPom (pomUrl , file );
251- }
290+ }
252291
253292 return files ;
254293 }
@@ -263,8 +302,6 @@ protected void readInfoFromPom(String url, BintrayArtifact item) throws Exceptio
263302 String pomName = dom .getElementValue ("name" );
264303 if (pomName != null && !pomName .isEmpty ())
265304 item .label = pomName ;
266- else
267- item .label = item .name ;
268305 item .desc = dom .getElementValue ("description" );
269306 item .author = dom .getElementValue ("developers/developer/organization" );
270307 }
0 commit comments