Skip to content
Snippets Groups Projects
Commit 4fe665ec authored by Philipp Spohr's avatar Philipp Spohr
Browse files

Basic sanity checks for lib loading

parent 502e0e3d
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,8 @@ package de.hhu.ba.yoshikoWrapper.core; ...@@ -23,6 +23,8 @@ package de.hhu.ba.yoshikoWrapper.core;
import java.io.File; import java.io.File;
import javax.swing.JOptionPane;
import org.slf4j.Logger; import org.slf4j.Logger;
import de.hhu.ba.yoshikoWrapper.logging.YoshikoLogger; import de.hhu.ba.yoshikoWrapper.logging.YoshikoLogger;
...@@ -30,6 +32,8 @@ import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface; ...@@ -30,6 +32,8 @@ import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface;
public class YoshikoLoader { public class YoshikoLoader {
public static final String REQUIRED_VERSION = "2.1";
private static boolean isLoaded; private static boolean isLoaded;
//Symbolic Links //Symbolic Links
...@@ -46,12 +50,15 @@ public class YoshikoLoader { ...@@ -46,12 +50,15 @@ public class YoshikoLoader {
try { try {
System.out.println("Attempting to load library @: "+libPath); System.out.println("Attempting to load library @: "+libPath);
if (!libPath.substring(0,libPath.lastIndexOf(".")).endsWith(REQUIRED_VERSION)) {
throw new Exception(LocalizationManager.get("libFail")+" "+REQUIRED_VERSION);
}
System.load(libPath); System.load(libPath);
//update cfg //update cfg
CyCore.cm.getProperties().setProperty("pathToYoshiko", libPath); CyCore.cm.getProperties().setProperty("pathToYoshiko", libPath);
} }
catch(Exception e) { catch(Exception e) {
//e.printStackTrace(); JOptionPane.showMessageDialog(null, LocalizationManager.get("libFail")+" "+REQUIRED_VERSION);
return; return;
} }
LibraryInterface.setVerbosity(3); LibraryInterface.setVerbosity(3);
......
...@@ -29,7 +29,6 @@ import java.net.URI; ...@@ -29,7 +29,6 @@ import java.net.URI;
import javax.swing.GroupLayout; import javax.swing.GroupLayout;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.GroupLayout.Alignment; import javax.swing.GroupLayout.Alignment;
...@@ -38,9 +37,7 @@ import org.cytoscape.util.swing.BasicCollapsiblePanel; ...@@ -38,9 +37,7 @@ import org.cytoscape.util.swing.BasicCollapsiblePanel;
import de.hhu.ba.yoshikoWrapper.core.LocalizationManager; import de.hhu.ba.yoshikoWrapper.core.LocalizationManager;
import de.hhu.ba.yoshikoWrapper.core.YoshikoLoader; import de.hhu.ba.yoshikoWrapper.core.YoshikoLoader;
import de.hhu.ba.yoshikoWrapper.logging.YoshikoLogger; import de.hhu.ba.yoshikoWrapper.logging.YoshikoLogger;
import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface;
import de.hhu.ba.yoshikoWrapper.swing.components.LibStatusPanel; import de.hhu.ba.yoshikoWrapper.swing.components.LibStatusPanel;
import de.hhu.ba.yoshikoWrapper.swing.components.YLibChooser;
public class LibraryPanelFactory{ public class LibraryPanelFactory{
...@@ -50,32 +47,26 @@ public class LibraryPanelFactory{ ...@@ -50,32 +47,26 @@ public class LibraryPanelFactory{
final LibStatusPanel libStatusPanel; final LibStatusPanel libStatusPanel;
final JButton searchLibButton; final JButton searchLibButton;
final JLabel yoshikoVersionLabel;
final JButton getYoshiko; final JButton getYoshiko;
//SWING COMPONENT INITIALIZATION //SWING COMPONENT INITIALIZATION
libStatusPanel = new LibStatusPanel(); libStatusPanel = new LibStatusPanel();
searchLibButton = new JButton(LocalizationManager.get("resolveLibPath")); searchLibButton = new JButton(LocalizationManager.get("resolveLibPath"));
yoshikoVersionLabel = new JLabel();
libStatusPanel.setStyle(YoshikoLoader.isLibraryLoaded()); libStatusPanel.setStyle(YoshikoLoader.isLibraryLoaded());
if (YoshikoLoader.isLibraryLoaded()) { searchLibButton.setEnabled(!YoshikoLoader.isLibraryLoaded());
yoshikoVersionLabel.setText(LibraryInterface.getVersionString());
searchLibButton.setEnabled(false);
}
searchLibButton.addActionListener(new ActionListener() { searchLibButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
final YLibChooser c = new YLibChooser(); final JFileChooser c = new JFileChooser();
int returnVal = c.showOpenDialog(ret); int returnVal = c.showOpenDialog(ret);
if (returnVal == JFileChooser.APPROVE_OPTION) { if (returnVal == JFileChooser.APPROVE_OPTION) {
YoshikoLoader.loadLibrary(c.getSelectedFile().getAbsolutePath()); YoshikoLoader.loadLibrary(c.getSelectedFile().getAbsolutePath());
} }
libStatusPanel.setStyle(YoshikoLoader.isLibraryLoaded()); libStatusPanel.setStyle(YoshikoLoader.isLibraryLoaded());
yoshikoVersionLabel.setText(LocalizationManager.get("yoshVersion")+" "+LibraryInterface.getVersionString()); searchLibButton.setEnabled(!YoshikoLoader.isLibraryLoaded());
searchLibButton.setEnabled(false);
} }
}); });
...@@ -102,7 +93,6 @@ public class LibraryPanelFactory{ ...@@ -102,7 +93,6 @@ public class LibraryPanelFactory{
SwingUtil.addAll(ret, SwingUtil.addAll(ret,
libStatusPanel, libStatusPanel,
yoshikoVersionLabel,
searchLibButton, searchLibButton,
getYoshiko getYoshiko
); );
...@@ -112,14 +102,12 @@ public class LibraryPanelFactory{ ...@@ -112,14 +102,12 @@ public class LibraryPanelFactory{
layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING,true) layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING,true)
.addComponent(libStatusPanel) .addComponent(libStatusPanel)
.addComponent(yoshikoVersionLabel)
.addComponent(searchLibButton) .addComponent(searchLibButton)
.addComponent(getYoshiko) .addComponent(getYoshiko)
); );
layout.setVerticalGroup(layout.createSequentialGroup() layout.setVerticalGroup(layout.createSequentialGroup()
.addComponent(libStatusPanel) .addComponent(libStatusPanel)
.addComponent(yoshikoVersionLabel)
.addComponent(searchLibButton) .addComponent(searchLibButton)
.addComponent(getYoshiko) .addComponent(getYoshiko)
); );
......
...@@ -24,25 +24,37 @@ package de.hhu.ba.yoshikoWrapper.swing.components; ...@@ -24,25 +24,37 @@ package de.hhu.ba.yoshikoWrapper.swing.components;
import java.awt.Color; import java.awt.Color;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel;
import de.hhu.ba.yoshikoWrapper.core.LocalizationManager;
import de.hhu.ba.yoshikoWrapper.core.YoshikoLoader;
import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface;
import de.hhu.ba.yoshikoWrapper.swing.GraphicsLoader; import de.hhu.ba.yoshikoWrapper.swing.GraphicsLoader;
/** /**
* Simple JLabel visually representing whether or not the Yoshiko Lib is loaded * Simple JPanel visually representing whether or not the Yoshiko Lib is loaded and showing some basic info
* *
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class LibStatusPanel extends JLabel { public class LibStatusPanel extends JPanel {
final JLabel yoshikoVersionLabel;
public LibStatusPanel() {
yoshikoVersionLabel = new JLabel();
this.add(yoshikoVersionLabel);
}
/** /**
* Adjusts the style accordingly by changing its color and updating its text * Adjusts the style accordingly by changing its color and updating its text
*/ */
public void setStyle(boolean libraryLoaded) { public void setStyle(boolean libraryLoaded) {
if(libraryLoaded) { if(libraryLoaded) {
this.setText("YOSHIKO LIBRARY READY!"); yoshikoVersionLabel.setText(LocalizationManager.get("yoshVersion")+" "+YoshikoLoader.REQUIRED_VERSION+"("+LibraryInterface.getVersionString()+")");
this.setForeground(GraphicsLoader.yoshikoGreen); yoshikoVersionLabel.setForeground(GraphicsLoader.yoshikoGreen);
} }
else { else {
this.setText("YOSHIKO LIBRARY NOT LOADED :("); yoshikoVersionLabel.setText(LocalizationManager.get("noLibTitle"));
this.setForeground(Color.RED); yoshikoVersionLabel.setForeground(Color.RED);
} }
} }
......
/*******************************************************************************
* Copyright (C) 2017 Philipp Spohr
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
******************************************************************************/
package de.hhu.ba.yoshikoWrapper.swing.components;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
/**Implementation of the JFileChooser that limits choices to shared library
* TODO: Perform basic sanity checks on the selected file (Checksum?)
* @author Philipp Spohr, Aug 6, 2017
*
*/
@SuppressWarnings("serial")
public class YLibChooser extends JFileChooser {
/**
* Default constructor
*/
public YLibChooser() {
super();
this.setFileFilter(new FileFilter() {
@Override
public boolean accept(File f) {
//TODO
return true;
}
@Override
public String getDescription() {
return "Compiled Yoshiko-Libraries";
}
});
}
}
...@@ -42,6 +42,7 @@ icTooltip = This value is used to determine what the algorithm pays when inserti ...@@ -42,6 +42,7 @@ icTooltip = This value is used to determine what the algorithm pays when inserti
ilpMarker = ILP Properties ilpMarker = ILP Properties
incompleteResult = This run yielded no usable result! incompleteResult = This run yielded no usable result!
instance = Instance instance = Instance
libFail = Failed to load library! Make sure you got the right file. The required version for this version of the wrapper is:
libraryPanel = Library libraryPanel = Library
metaGraph = Meta Graph metaGraph = Meta Graph
multFactor = Multiplicative Factor for SNR: multFactor = Multiplicative Factor for SNR:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment