View Javadoc

1   /*
2    * #%L
3    * prolobjectlink-jpi-jpl-yap
4    * %%
5    * Copyright (C) 2019 Prolobjectlink Project
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as
9    * published by the Free Software Foundation, either version 2.1 of the
10   * License, or (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Lesser Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Lesser Public
18   * License along with this program.  If not, see
19   * <http://www.gnu.org/licenses/lgpl-2.1.html>.
20   * #L%
21   */
22  package io.github.prolobjectlink.prolog.jpl.yap;
23  
24  import java.io.File;
25  import java.util.ArrayList;
26  import java.util.List;
27  
28  import io.github.prolobjectlink.prolog.Licenses;
29  import io.github.prolobjectlink.prolog.PrologEngine;
30  import io.github.prolobjectlink.prolog.PrologProvider;
31  import io.github.prolobjectlink.prolog.jpl.JplEngine;
32  import jpl.JPL;
33  import jpl.Query;
34  import jpl.Term;
35  
36  /**
37   * 
38   * @author Jose Zalacain
39   * @since 1.0
40   */
41  public class YapPrologEngine extends JplEngine implements PrologEngine {
42  
43  	protected YapPrologEngine(PrologProvider provider) {
44  		super(provider);
45  	}
46  
47  	protected YapPrologEngine(PrologProvider provider, String file) {
48  		super(provider, file);
49  	}
50  
51  	public final String getLicense() {
52  		return Licenses.LGPL_V3;
53  	}
54  
55  	public final String getVersion() {
56  		Term yap = (Term) new Query("current_prolog_flag(version_data,Yap)").oneSolution().get("Yap");
57  		return "" + yap.arg(1) + "." + yap.arg(2) + "." + yap.arg(3) + " (JPL v" + JPL.version_string() + ")";
58  	}
59  	
60  	public final String getVendor() {
61  		return "YapProlog";
62  	}
63  
64  	public final String getName() {
65  		return "YapProlog";
66  	}
67  
68  	public final List<String> verify() {
69  		String slash = File.separator;
70  		List<String> list = new ArrayList<String>();
71  		String javaHome = System.getProperty("java.home");
72  		String javaVersion = System.getProperty("java.version");
73  		String pathSeparator = System.getProperty("path.separator");
74  		if (runOnWindows()) {
75  			list.add(javaHome.replace(slash + "jre", slash) + "/jdk" + javaVersion + "/bin" + pathSeparator);
76  			list.add(javaHome.replace(slash + "jre", slash) + "/jdk" + javaVersion + "/lib/tools.jar" + pathSeparator);
77  			list.add(
78  					javaHome.replace(slash + "jre", slash) + "/jdk" + javaVersion + "/jre/lib/rt.jar;" + pathSeparator);
79  			list.add("C:/Program Files/swipl/lib/jpl.jar" + pathSeparator);
80  			list.add("C:/Program Files/swipl/bin");
81  		} else if (runOnOSX()) {
82  			// TODO environment routes for MacOSX
83  		} else if (runOnLinux()) {
84  			list.add("/usr/lib/jvm/java-" + javaVersion + "-openjdk-" + getOSArch() + "/bin" + pathSeparator);
85  			list.add("/usr/lib/jvm/java-" + javaVersion + "-openjdk-" + getOSArch() + "/lib/tools.jar" + pathSeparator);
86  			list.add(
87  					"/usr/lib/jvm/java-" + javaVersion + "-openjdk-" + getOSArch() + "/jre/lib/rt.jar" + pathSeparator);
88  			list.add("/usr/local/bin/swipl/lib/jpl.jar" + pathSeparator);
89  			list.add("/usr/local/bin");
90  		}
91  		return list;
92  	}
93  
94  }