|
From: <jom...@us...> - 2016-05-02 14:45:23
|
Revision: 1911
http://sourceforge.net/p/jason/svn/1911
Author: jomifred
Date: 2016-05-02 14:45:20 +0000 (Mon, 02 May 2016)
Log Message:
-----------
improve config
Modified Paths:
--------------
trunk/src/jason/util/Config.java
trunk/src/jason/util/ConfigGUI.java
Modified: trunk/src/jason/util/Config.java
===================================================================
--- trunk/src/jason/util/Config.java 2016-04-29 11:22:47 UTC (rev 1910)
+++ trunk/src/jason/util/Config.java 2016-05-02 14:45:20 UTC (rev 1911)
@@ -266,11 +266,11 @@
/** Set most important parameters with default values */
public void fix() {
- tryToFixJarFileConf(JASON_JAR, "jason.jar", 700000);
- tryToFixJarFileConf(JADE_JAR, "jade.jar", 2000000);
- tryToFixJarFileConf(MOISE_JAR, "moise.jar", 300000);
- tryToFixJarFileConf(JACAMO_JAR, "jacamo.jar", 5000);
- tryToFixJarFileConf(JASON_JAR, "jason.jar", 700000); // in case jacamo is found
+ tryToFixJarFileConf(JASON_JAR, "jason", 700000);
+ tryToFixJarFileConf(JADE_JAR, "jade", 2000000);
+ tryToFixJarFileConf(MOISE_JAR, "moise", 300000);
+ tryToFixJarFileConf(JACAMO_JAR, "jacamo", 5000);
+ tryToFixJarFileConf(JASON_JAR, "jason", 700000); // in case jacamo is found
// fix java home
if (get(JAVA_HOME) == null || !checkJavaHomePath(getProperty(JAVA_HOME))) {
@@ -455,7 +455,12 @@
try {
Properties p = new Properties();
p.load(Config.class.getResource(getDistPropFile()).openStream());
- return p.getProperty("version") + "." + p.getProperty("release");
+ String v = p.getProperty("version");
+ if (v == null)
+ v = "";
+ else if (! v.isEmpty())
+ v = v + ".";
+ return v + p.getProperty("release");
} catch (Exception ex1) {
try {
Properties p = new Properties();
@@ -480,13 +485,13 @@
}
}
- void tryToFixJarFileConf(String jarEntry, String jarName, int minSize) {
+ void tryToFixJarFileConf(String jarEntry, String jarFilePrefix, int minSize) {
String jarFile = getProperty(jarEntry);
if (jarFile == null || !checkJar(jarFile, minSize)) {
- System.out.println("Wrong configuration for " + jarName + ", current is " + jarFile);
+ System.out.println("Wrong configuration for " + jarFilePrefix + ", current is " + jarFile);
// try eclipse installation
- jarFile = getJarFromEclipseInstallation(jarName);
+ jarFile = getJarFromEclipseInstallation(jarFilePrefix);
if (checkJar(jarFile, minSize)) {
put(jarEntry, jarFile);
System.out.println("found at " + jarFile+" in eclipse installation");
@@ -494,7 +499,7 @@
}
// try to get from classpath
- jarFile = getJarFromClassPath(jarName);
+ jarFile = getJarFromClassPath(jarFilePrefix);
if (checkJar(jarFile, minSize)) {
put(jarEntry, jarFile);
System.out.println("found at " + jarFile+" by classpath");
@@ -504,7 +509,7 @@
try {
// try jason jar
File jasonjardir = new File(getJasonJar()).getAbsoluteFile().getCanonicalFile().getParentFile();
- jarFile = jasonjardir+File.separator+jarName;
+ jarFile = findJarInDirectory(jasonjardir, jarFilePrefix);
if (checkJar(jarFile, minSize)) {
put(jarEntry, jarFile);
System.out.println("found at " + jarFile+" by jason.jar directory");
@@ -515,7 +520,7 @@
try {
// try jacamo jar
File jacamojardir= new File(getProperty(JACAMO_JAR)).getAbsoluteFile().getCanonicalFile().getParentFile();
- jarFile = jacamojardir+File.separator+jarName;
+ jarFile = findJarInDirectory(jacamojardir, jarFilePrefix);
if (checkJar(jarFile, minSize)) {
put(jarEntry, jarFile);
System.out.println("found at " + jarFile+" by jacamo.jar directory");
@@ -524,7 +529,7 @@
} catch (Exception e) {}
// try current dir
- jarFile = "." + File.separator + jarName;
+ jarFile = findJarInDirectory(new File("."), jarFilePrefix);
if (checkJar(jarFile, minSize)) {
try {
put(jarEntry, new File(jarFile).getCanonicalFile().getAbsolutePath());
@@ -536,7 +541,7 @@
}
// try current dir + lib
- jarFile = ".." + File.separator + "lib" + File.separator + jarName;
+ jarFile = findJarInDirectory(new File(".." + File.separator + "lib"), jarFilePrefix);
if (checkJar(jarFile, minSize)) {
try {
put(jarEntry, new File(jarFile).getCanonicalFile().getAbsolutePath());
@@ -546,7 +551,7 @@
e.printStackTrace();
}
}
- jarFile = "." + File.separator + "lib" + File.separator + jarName;
+ jarFile = findJarInDirectory(new File("lib"), jarFilePrefix);
if (checkJar(jarFile, minSize)) {
try {
put(jarEntry, new File(jarFile).getCanonicalFile().getAbsolutePath());
@@ -558,7 +563,7 @@
}
// try current dir + bin
- jarFile = "." + File.separator + "bin" + File.separator + jarName;
+ jarFile = findJarInDirectory(new File("bin"), jarFilePrefix);
if (checkJar(jarFile, minSize)) {
try {
put(jarEntry, new File(jarFile).getCanonicalFile().getAbsolutePath());
@@ -580,8 +585,8 @@
}
}
if (jwsDir != null) {
- jarFile = findFile(new File(jwsDir), jarName, minSize);
- System.out.print("Searching " + jarName + " in " + jwsDir + " ... ");
+ jarFile = findFile(new File(jwsDir), jarFilePrefix, minSize);
+ System.out.print("Searching " + jarFilePrefix + " in " + jwsDir + " ... ");
if (jarFile != null && checkJar(jarFile)) {
System.out.println("found at " + jarFile);
put(jarEntry, jarFile);
@@ -590,7 +595,7 @@
put(jarEntry, File.separator);
}
}
- System.out.println(jarName+" not found");
+ System.out.println(jarFilePrefix+" not found");
}
}
@@ -613,6 +618,15 @@
}
return null;
}
+
+ String findJarInDirectory(File dir, String prefix) {
+ for (File f: dir.listFiles()) {
+ if (f.getName().startsWith(prefix) && f.getName().endsWith(".jar")) {
+ return f.getAbsolutePath();
+ }
+ }
+ return null;
+ }
public static boolean checkJar(String jar) {
try {
@@ -682,8 +696,9 @@
StringTokenizer st = new StringTokenizer(System.getProperty("java.class.path"), File.pathSeparator);
while (st.hasMoreTokens()) {
String token = st.nextToken();
- if (token.endsWith(file)) {
- return new File(token).getAbsolutePath();
+ File f = new File(token);
+ if (f.getName().startsWith(file)) {
+ return f.getAbsolutePath();
}
}
return null;
@@ -700,9 +715,7 @@
File f = (new File(eclipse)).getParentFile().getParentFile();
if (eclipse.contains("Eclipse.app/Contents")) // MacOs case
f = f.getParentFile().getParentFile();
- f = new File(f+"/"+getEclipseInstallationDirectory()+"/lib/"+file);
- if (f.exists())
- return f.getAbsolutePath();
+ return findJarInDirectory(new File(f+"/"+getEclipseInstallationDirectory()+"/lib"), file);
}
return null;
}
Modified: trunk/src/jason/util/ConfigGUI.java
===================================================================
--- trunk/src/jason/util/ConfigGUI.java 2016-04-29 11:22:47 UTC (rev 1910)
+++ trunk/src/jason/util/ConfigGUI.java 2016-05-02 14:45:20 UTC (rev 1911)
@@ -328,7 +328,7 @@
try {
JFileChooser chooser = new JFileChooser(System.getProperty("user.dir"));
chooser.setDialogTitle("Select the "+jarfile+" file");
- chooser.setFileFilter(new JarFileFilter(jarfile, "The "+jarfile+" file"));
+ chooser.setFileFilter(new JarFileFilter("The "+jarfile+" file"));
//chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
String selJar = (new File(chooser.getSelectedFile().getPath())).getCanonicalPath();
@@ -394,13 +394,12 @@
}
class JarFileFilter extends FileFilter {
- String jar,ds;
- public JarFileFilter(String jar, String ds) {
- this.jar = jar;
+ String ds;
+ public JarFileFilter(String ds) {
this.ds = ds;
}
public boolean accept(File f) {
- if (f.getName().endsWith(jar) || f.isDirectory()) {
+ if (f.getName().endsWith("jar") || f.isDirectory()) {
return true;
} else {
return false;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|