Issue#15 some basic code review

This commit is contained in:
Didier Clermonté 2016-06-19 22:37:05 +02:00
parent 72517c89f3
commit ae7271cdd5
12 changed files with 27 additions and 45 deletions

View File

@ -36,7 +36,6 @@ import org.slf4j.LoggerFactory;
*/
public class Siba
{
public static final Logger logger = LoggerFactory.getLogger(Siba.class);
public static void main(final String[] args)

View File

@ -22,12 +22,11 @@ package org.dclermonte.siba;
/**
*
* @author dclermonte
* @author Didier Clermonté (dclermonte@april.org)
*
*/
public class SibaException extends Exception
{
private static final long serialVersionUID = 2909630770291570845L;
public SibaException()

View File

@ -34,7 +34,6 @@ import org.slf4j.LoggerFactory;
*
*/
public class SibaCLI
{
public static final Logger logger = LoggerFactory.getLogger(SibaCLI.class);
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.cli.messages"); //$NON-NLS-1$
@ -44,7 +43,6 @@ public class SibaCLI
File result;
result = SibaManager.backup(directoryToSave);
System.out.println(BUNDLE.getString("confirmDialog.text") + result.getName()); //$NON-NLS-1$
}
/**
@ -60,7 +58,6 @@ public class SibaCLI
File result;
result = SibaManager.backup(directoryToSave, targetDirectory);
System.out.println(BUNDLE.getString("confirmDialog.text") + result.getName()); //$NON-NLS-1$
}
/**
@ -71,7 +68,6 @@ public class SibaCLI
* @throws SibaException
*/
public static void check(final File fileToCheck) throws SibaException
{
boolean result;
result = SibaManager.check(fileToCheck);
@ -94,13 +90,11 @@ public class SibaCLI
*/
public static void help()
{
System.out.println("usage :");
System.out.println("Siba :");
System.out.println("Siba [-h |-help| --help]");
System.out.println("siba backup directoryToSave [target]");
System.out.println("siba check [filename | filename.tgz | filename.tgz.md5]");
}
/**
@ -189,6 +183,5 @@ public class SibaCLI
}
help();
}
}
}

View File

@ -42,7 +42,6 @@ import javax.swing.JTextPane;
*/
public class AboutDialog extends JDialog
{
private static final long serialVersionUID = 8868109575782482455L;
/**
@ -78,7 +77,6 @@ public class AboutDialog extends JDialog
getRootPane().setDefaultButton(okButton);
}
}
JPanel panel = new JPanel();
panel.setBackground(Color.GREEN);
getContentPane().add(panel, BorderLayout.CENTER);
@ -112,5 +110,4 @@ public class AboutDialog extends JDialog
e.printStackTrace();
}
}
}

View File

@ -54,18 +54,15 @@ import com.jgoodies.forms.layout.RowSpec;
public class BackupPanel extends JPanel
{
private static final long serialVersionUID = 4714383090458639282L;
static private ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
private static ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
private JTextField sourceDirectoryField;
private JTextField targetDirectoryField;
/**
* This is the constructor for this panel.
*/
public BackupPanel() throws SibaException
{
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
setLayout(new BorderLayout(0, 0));
@ -111,16 +108,13 @@ public class BackupPanel extends JPanel
});
choosePanel.add(btnNewButton, "6, 2");
JLabel lblTargetDirectory = new JLabel(BUNDLE.getString("BackupPanel.lblTargetDirectory.text")); //$NON-NLS-1$
choosePanel.add(lblTargetDirectory, "2, 4");
lblTargetDirectory.setVerticalAlignment(SwingConstants.TOP);
lblTargetDirectory.setHorizontalAlignment(SwingConstants.LEFT);
this.targetDirectoryField = new JTextField();
choosePanel.add(this.targetDirectoryField, "4, 4");
this.targetDirectoryField.setColumns(10);
JButton btnNewButton_1 = new JButton(BUNDLE.getString("BackupPanel.btnNewButton_1.text")); //$NON-NLS-1$
btnNewButton_1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
btnNewButton_1.addActionListener(new ActionListener()
@ -128,21 +122,16 @@ public class BackupPanel extends JPanel
@Override
public void actionPerformed(final ActionEvent e)
{
File file = TargetDirectorySelector.showSelectorDialog(BackupPanel.this, null);
if (file != null)
{
BackupPanel.this.targetDirectoryField.setText(file.getPath());
}
}
});
choosePanel.add(btnNewButton_1, "6, 4");
btnNewButton_1.setHorizontalAlignment(SwingConstants.RIGHT);
JPanel actionPanel = new JPanel();
add(actionPanel, BorderLayout.SOUTH);
actionPanel.setLayout(new BoxLayout(actionPanel, BoxLayout.Y_AXIS));
@ -189,7 +178,6 @@ public class BackupPanel extends JPanel
String titleWarning = BUNDLE.getString("BackupPanel.TitleWarning.text");
JOptionPane.showMessageDialog(BackupPanel.this, dataMissing, titleWarning,
JOptionPane.INFORMATION_MESSAGE);
}
}
catch (SibaException sibaException)
@ -218,5 +206,4 @@ public class BackupPanel extends JPanel
{
this.sourceDirectoryField.setText(sourceDirectory);
}
}

View File

@ -16,14 +16,13 @@ import org.apache.commons.lang3.StringUtils;
*
*/
public class CheckDirectorySelector extends JFileChooser
/**
*
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
*/
{
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
private static final long serialVersionUID = 3782597353602048214L;
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
/**
*
@ -38,7 +37,6 @@ public class CheckDirectorySelector extends JFileChooser
if ((targetFile == null) || (StringUtils.isBlank(targetFile.getAbsolutePath())))
{
file = null;
}
else if (targetFile.isFile())
{

View File

@ -49,8 +49,8 @@ import com.jgoodies.forms.layout.Sizes;
*/
public class CheckPanel extends JPanel
{
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
private static final long serialVersionUID = -1580485684838045920L;
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
private JTextField fileToCheckField;
private File choosenFile;
@ -87,7 +87,6 @@ public class CheckPanel extends JPanel
try
{
CheckPanel.this.choosenFile = choosenDirectory();
}
catch (IOException e1)
{
@ -144,18 +143,22 @@ public class CheckPanel extends JPanel
JOptionPane.INFORMATION_MESSAGE);
}
}
catch (SibaException exception)
{
// TODO Auto-generated catch block
exception.printStackTrace();
}
}
});
add(btnNewButton_1, "3, 4");
}
/**
*
* @return
* @throws IOException
* @throws NoSuchAlgorithmException
*/
public File choosenDirectory() throws IOException, NoSuchAlgorithmException
{
File result;
@ -170,6 +173,8 @@ public class CheckPanel extends JPanel
{
result = null;
}
//
return result;
}

View File

@ -15,8 +15,8 @@ import org.apache.commons.lang3.StringUtils;
*/
public class SourceDirectorySelector extends JFileChooser
{
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
private static final long serialVersionUID = 3782597353602048214L;
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
/**
*
@ -31,7 +31,6 @@ public class SourceDirectorySelector extends JFileChooser
if ((targetFile == null) || (StringUtils.isBlank(targetFile.getAbsolutePath())))
{
file = null;
}
else if (targetFile.isFile())
{

View File

@ -15,8 +15,8 @@ import org.apache.commons.lang3.StringUtils;
*/
public class TargetDirectorySelector extends JFileChooser
{
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
private static final long serialVersionUID = 3782597353602048214L;
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
/**
*

View File

@ -32,11 +32,6 @@ import javax.swing.UIManager;
*/
public class GUIToolBox
{
/**
*
* @return
*/
public static List<String> availableLookAndFeels()
{
List<String> result;

View File

@ -41,7 +41,6 @@ import org.dclermonte.siba.SibaException;
* @author Didier Clermonté (dclermonte@april.org)
*
*/
public class SibaManager
{
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.model.messages"); //$NON-NLS-1$
@ -56,8 +55,10 @@ public class SibaManager
public static File backup(final File fileToSave) throws SibaException
{
File result;
File target = new File(System.getProperty("user.dir"));
result = backup(fileToSave, target);
//
return result;
}
@ -73,6 +74,7 @@ public class SibaManager
public static File backup(final File fileToSave, final File target) throws SibaException
{
File result;
TarArchiveOutputStream out = null;
OutputStream gzipOutputStream = null;
try
@ -154,6 +156,7 @@ public class SibaManager
{
throw new SibaException(BUNDLE.getString("noSuchAlgorithm.text"), noSuchAlgorithmException); //$NON-NLS-1$
}
//
return result;
}

View File

@ -31,6 +31,11 @@ import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.apache.commons.compress.utils.IOUtils;
/**
*
* @author Didier Clermonté (dclermonte@april.org)
*
*/
public class SibaUtils
{
/**
@ -68,6 +73,7 @@ public class SibaUtils
public static String md5(final File input) throws IOException, NoSuchAlgorithmException
{
String result;
StringBuilder hashString = new StringBuilder();
FileInputStream fileInputStream = null;
try
@ -103,6 +109,7 @@ public class SibaUtils
{
IOUtils.closeQuietly(fileInputStream);
}
//
return result;
}
@ -116,8 +123,8 @@ public class SibaUtils
public static File readFileNameToCheck(final File choosenFile) throws IOException
{
File result;
result = null;
result = null;
if (choosenFile.exists() && (choosenFile.length() > 32))
{
FileReader fileReader = new FileReader(choosenFile);
@ -136,8 +143,8 @@ public class SibaUtils
result = new File(path + "/" + fileNameToString);
}
}
//
//
return result;
}