120 lines
4.2 KiB
Java
120 lines
4.2 KiB
Java
package org.gcube.dataanalysis.dataminerpoolmanager;
|
|
|
|
***REMOVED***
|
|
import java.io.InputStream;
|
|
import java.net.ProxySelector;
|
|
***REMOVED***
|
|
***REMOVED***
|
|
import java.util.Vector;
|
|
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Algorithm;
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.AlgorithmSet;
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.process.AddAlgorithmCommand;
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.process.AlgorithmPackageParser;
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.util.PropertiesBasedProxySelector;
|
|
|
|
public class AlgorithmPackageParserTest {
|
|
|
|
private static int BUFFER_SIZE = 2048;
|
|
|
|
public void extractAllAlgorithms() throws IOException {
|
|
String url = "http:***REMOVED***svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-analysis/DataMinerConfiguration/algorithms/dev/algorithms";
|
|
List<String> commands = this.extractAddAlgorithmCommands(url);
|
|
AlgorithmSet algorithms = new AlgorithmSet();
|
|
for (String cmd : commands) {
|
|
System.out.println("-----------------------------------------");
|
|
System.out.println(cmd);
|
|
AddAlgorithmCommand aac = new AddAlgorithmCommand(cmd);
|
|
System.out.println(aac);
|
|
|
|
***REMOVED*** start creating the algo from the command
|
|
Algorithm algo = new Algorithm();
|
|
algo.setAlgorithmType(aac.getAlgorithmType());
|
|
algo.setCategory(aac.getCategory());
|
|
algo.setClazz(aac.getClazz());
|
|
algo.setDescription(aac.getDescription());
|
|
algo.setName(aac.getName());
|
|
algo.setPackageURL(aac.getUrl());
|
|
algo.setSkipJava(aac.getSkipjava());
|
|
|
|
***REMOVED*** then override with info from the package
|
|
if (aac.getUrl().length() > 4) {
|
|
Algorithm packagedAlgo = this.extractAlgorithm(aac.getUrl());
|
|
if (packagedAlgo != null) {
|
|
algo.setDependencies(packagedAlgo.getDependencies());
|
|
***REMOVED***
|
|
***REMOVED***
|
|
algorithms.addAlgorithm(algo);
|
|
break;
|
|
***REMOVED***
|
|
***REMOVED***to uncomment
|
|
***REMOVED*** new DataminerPoolManager().addAlgorithmsToVRE(algorithms,
|
|
***REMOVED*** "/gcube/devNext/NextNext");
|
|
***REMOVED***
|
|
|
|
/**
|
|
* Extract 'addAlgorithm' commands from a file containing wiki-table-style
|
|
* entries for algorithm.
|
|
*
|
|
* @return
|
|
* @throws IOException
|
|
*/
|
|
private List<String> extractAddAlgorithmCommands(String listUrl)
|
|
throws IOException {
|
|
URL url = new URL(listUrl);
|
|
InputStream is = url.openStream();
|
|
|
|
StringBuilder s = new StringBuilder();
|
|
byte[] buffer = new byte[BUFFER_SIZE];
|
|
int read = 0;
|
|
while ((read = is.read(buffer)) != -1) {
|
|
s.append(new String(buffer, 0, read));
|
|
***REMOVED***
|
|
List<String> out = new Vector<>();
|
|
String[] lines = s.toString().split("\n");
|
|
for (String line : lines) {
|
|
System.out.println("--------------------");
|
|
if (!line.isEmpty()) {
|
|
String[] parts = line.split("\\|");
|
|
int c = 1;
|
|
for (String part : parts) {
|
|
if (part == null || part.trim().isEmpty()) {
|
|
continue;
|
|
***REMOVED***
|
|
System.out.println(c + ". " + part);
|
|
c++;
|
|
if (part.contains("addAlgorithm.sh")) {
|
|
String cmd = part.trim();
|
|
cmd = cmd.replaceAll("<notextile>", "");
|
|
cmd = cmd.replaceAll("</notextile>", "");
|
|
System.out.println(cmd);
|
|
***REMOVED*** AddAlgorithmCommand aac = new AddAlgorithmCommand(cmd);
|
|
***REMOVED*** System.out.println(aac);
|
|
out.add(cmd);
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
return out;
|
|
***REMOVED***
|
|
|
|
/**
|
|
* Create an Algorithm starting from the algorithm jar.
|
|
*
|
|
* @param url
|
|
* @return
|
|
* @throws IOException
|
|
*/
|
|
private Algorithm extractAlgorithm(String url) throws IOException {
|
|
return new AlgorithmPackageParser().parsePackage(url);
|
|
***REMOVED***
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
***REMOVED*** ProxySelector.setDefault(new PropertiesBasedProxySelector(
|
|
***REMOVED*** "/home/ngalante/.proxy-settings"));
|
|
|
|
new AlgorithmPackageParserTest().extractAllAlgorithms();
|
|
***REMOVED***
|
|
|
|
***REMOVED***
|