/* $Id: Architecture.java,v 1.2 2005-12-02 13:35:12 tomassoni Exp $
*
* (C)Copyright 2005 by Dipartimento Pianificazione Territoriale e Urbanistica
* University "La Sapienza", Rome, Italy
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* This source is part of the Stan's application
*
* Created on 24 Marzo 2005, 10.49
*
* $Log: not supported by cvs2svn $
* Revision 1.1.1.1 2005/11/28 16:04:01 tomassoni
* initial import
*
*/
import it.uniroma1.dptu.glpk.rt.Loader;
import java.io.IOException;
import java.util.regex.Pattern;
import java.util.Properties;
import java.util.Iterator;
class Architecture {
static protected final Pattern patInvalids = Pattern.compile("[ \t.]");
public static void main(String args[]) {
final String osArch = System.getProperty("os.arch");
final String osName = System.getProperty("os.name");
final String osVer = System.getProperty("os.version");
String id = new StringBuffer(osArch)
.append('-')
.append(osName)
.append('-')
.append(osVer)
.toString();
Loader loader = new Loader();
String nmResource = loader.getLibResource(osArch, osName, osVer);
if(nmResource == null) {
// This architecture is not yet known to the package and a new jni
// plugin needs to be build and defined.
Properties props;
try { props = loader.getMappings(); }
catch(IOException ex)
{ props = new Properties(); }
// Attempts hinting a plug-in name for this architecture
next: for(int i = 0;; ++i) {
StringBuffer sb = new StringBuffer()
.append(patInvalids.matcher(osName).replaceAll(""))
.append('.')
;
if(i > 0)
sb.append(i).append('.');
nmResource = sb
.append(patInvalids.matcher(osArch).replaceAll(""))
.append(".bin")
.toString()
;
for(Iterator j = props.values().iterator(); j.hasNext();)
if(nmResource.equals(j.next()))
continue next;
break;
}
System.err.print(
"\n\n" +
"ATTENTION ***********************************************\n" +
"Current architecture is not yet known to this package,\n" +
"so your effort in porting the GLPK JNI plugin to it is\n" +
"welcome. In order to do this you have to add a line in\n" +
"the src/java/it/uniroma1/dptu/glpk/rt/mappings.properties\n" +
"file like the following one:\n\n" +
id + "\t" + nmResource + "\n\n" +
"and port the plugin.\n" +
"\n"+
"Please note that the left values supports wildcards\n" +
"and that the right value shown above is just a hint: you\n" +
"may choose whatever name you like, provided it is unique\n" +
"in the file.\n" +
"*********************************************************\n" +
"\n\n"
);
System.exit(1);
} else {
// This architecture is already known to the package: a jni plugin
// for it is defined.
System.out.println(nmResource);
System.err.println(nmResource + " for " + id);
System.exit(0);
}
}
}