diff --git a/.settings/org.eclipse.jdt.ui.prefs b/.settings/org.eclipse.jdt.ui.prefs index 2f18184..0fa52e8 100644 --- a/.settings/org.eclipse.jdt.ui.prefs +++ b/.settings/org.eclipse.jdt.ui.prefs @@ -66,7 +66,7 @@ org.eclipse.jdt.ui.gettersetter.use.is=true org.eclipse.jdt.ui.javadoc=false org.eclipse.jdt.ui.keywordthis=true org.eclipse.jdt.ui.overrideannotation=true -org.eclipse.jdt.ui.text.custom_code_templates= +org.eclipse.jdt.ui.text.custom_code_templates= sp_cleanup.add_default_serial_version_id=true sp_cleanup.add_generated_serial_version_id=false sp_cleanup.add_missing_annotations=true diff --git a/lib/Siba.jar b/lib/Siba.jar index f9ca61f..0e478c6 100644 Binary files a/lib/Siba.jar and b/lib/Siba.jar differ diff --git a/src/org/dclermonte/siba/Cat-Box-256.png b/src/org/dclermonte/siba/Cat-Box-256.png new file mode 100644 index 0000000..1a19ef5 Binary files /dev/null and b/src/org/dclermonte/siba/Cat-Box-256.png differ diff --git a/src/org/dclermonte/siba/SibaException.java b/src/org/dclermonte/siba/SibaException.java index 7eda956..8d5e5f3 100644 --- a/src/org/dclermonte/siba/SibaException.java +++ b/src/org/dclermonte/siba/SibaException.java @@ -1,9 +1,21 @@ /* - * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved. - * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + * Copyright (C) 2016 Didier Clermonté + * Copyright (C) 2016 Christian Pierre Momon * + * This file is part of Siba. * + * Siba is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ package org.dclermonte.siba; @@ -15,7 +27,9 @@ package org.dclermonte.siba; */ public class SibaException extends Exception { - + /** + * + */ private static final long serialVersionUID = 2909630770291570845L; public SibaException() @@ -23,22 +37,29 @@ public class SibaException extends Exception super(); } + /** + * + * @param message + */ public SibaException(final String message) { super(message); } + /** + * + * @param message + * @param cause + */ public SibaException(final String message, final Throwable cause) { super(message, cause); } - protected SibaException(final String message, final Throwable cause, final boolean enableSuppression, - final boolean writableStackTrace) - { - super(message, cause, enableSuppression, writableStackTrace); - } - + /** + * + * @param cause + */ public SibaException(final Throwable cause) { super(cause); diff --git a/src/org/dclermonte/siba/cli/SibaCLI.java b/src/org/dclermonte/siba/cli/SibaCLI.java index 9117a1d..edc1197 100644 --- a/src/org/dclermonte/siba/cli/SibaCLI.java +++ b/src/org/dclermonte/siba/cli/SibaCLI.java @@ -131,8 +131,7 @@ public class SibaCLI } else { - System.out.println(BUNDLE.getString("badUsage.text")); - help(); + throw new SibaException(BUNDLE.getString("ToManyParameter.text")); //$NON-NLS-1$ } } else if (StringUtils.equals(args[0], "check")) @@ -161,8 +160,7 @@ public class SibaCLI } else { - System.out.println(BUNDLE.getString("badUsage.text")); - help(); + throw new SibaException(BUNDLE.getString("ToManyParameter.text")); //$NON-NLS-1$ } } else @@ -180,6 +178,7 @@ public class SibaCLI { System.err.println("SibaException chainée = " + sibaException.getCause().getMessage()); } + help(); } } diff --git a/src/org/dclermonte/siba/cli/messages.properties b/src/org/dclermonte/siba/cli/messages.properties index 68af576..c48d7fe 100644 --- a/src/org/dclermonte/siba/cli/messages.properties +++ b/src/org/dclermonte/siba/cli/messages.properties @@ -9,4 +9,5 @@ directoryNotExist.text = one of the directories does not exist missingFileToCheck.text = Missing the file to check missingTargetFile.text=missing target file NotDirectorySource.text=Source is not a directory -SibaManageralgorithm.text=Algorithm error in sibaManagerexception \ No newline at end of file +SibaManageralgorithm.text=Algorithm error in sibaManagerexception +ToManyParameter.text= Bad number of parameters \ No newline at end of file diff --git a/src/org/dclermonte/siba/cli/messages_fr_FR.properties b/src/org/dclermonte/siba/cli/messages_fr_FR.properties index 82f68d6..49bcd04 100644 --- a/src/org/dclermonte/siba/cli/messages_fr_FR.properties +++ b/src/org/dclermonte/siba/cli/messages_fr_FR.properties @@ -9,4 +9,5 @@ directoryNotExist.text = L'un des r missingFileToCheck.text = Il manque le fichier à vérifier missingTargetFile.text=Le répertoire destination n'existe pas NotDirectorySource.text=La source n'est pas un répertoire -SibaManageralgorithm.text=Erreur d'algorithme dans sibaManager \ No newline at end of file +SibaManageralgorithm.text=Erreur d'algorithme dans sibaManager +ToManyParameter.text= Trop de paramètres \ No newline at end of file diff --git a/src/org/dclermonte/siba/gui/BackupPanel.java b/src/org/dclermonte/siba/gui/BackupPanel.java index 3cee7ef..f41d6ec 100644 --- a/src/org/dclermonte/siba/gui/BackupPanel.java +++ b/src/org/dclermonte/siba/gui/BackupPanel.java @@ -171,8 +171,6 @@ public class BackupPanel extends JPanel panel_2.add(verticalStrut); btnNewButton_2.addActionListener(new ActionListener() { - private Object e1; - @Override public void actionPerformed(final ActionEvent e) { @@ -196,10 +194,16 @@ public class BackupPanel extends JPanel } } - catch (SibaException e1) + catch (SibaException sibaException) { - // TODO Auto-generated catch block - ((Throwable) this.e1).printStackTrace(); + String dataMissing = sibaException.getMessage(); + if (!(sibaException.getCause() == null)) + { + dataMissing.concat(sibaException.getCause().getMessage()); + } + + String titleWarning = BUNDLE.getString("BackupPanel.TitleWarning.text"); + JOptionPane.showMessageDialog(null, dataMissing, titleWarning, JOptionPane.INFORMATION_MESSAGE); } } diff --git a/src/org/dclermonte/siba/gui/CheckPanel.java b/src/org/dclermonte/siba/gui/CheckPanel.java index 9357cb6..8b9d3fe 100644 --- a/src/org/dclermonte/siba/gui/CheckPanel.java +++ b/src/org/dclermonte/siba/gui/CheckPanel.java @@ -134,18 +134,14 @@ public class CheckPanel extends JPanel + BUNDLE.getString("CheckPanel.confirmDialogBad.text"); JOptionPane.showMessageDialog(null, message, titre, JOptionPane.INFORMATION_MESSAGE); } - } else { String dataMissing = BUNDLE.getString("BackupPanel.dataMissing.text"); String titleWarning = BUNDLE.getString("BackupPanel.TitleWarning.text"); JOptionPane.showMessageDialog(null, dataMissing, titleWarning, JOptionPane.INFORMATION_MESSAGE); - } - } - catch (SibaException exception) { // TODO Auto-generated catch block diff --git a/src/org/dclermonte/siba/gui/SibaGUI.java b/src/org/dclermonte/siba/gui/SibaGUI.java index d23d67d..c7cea2b 100644 --- a/src/org/dclermonte/siba/gui/SibaGUI.java +++ b/src/org/dclermonte/siba/gui/SibaGUI.java @@ -27,6 +27,7 @@ import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Font; import java.awt.Point; +import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Locale; @@ -151,6 +152,8 @@ public class SibaGUI private void initialize() throws SibaException { this.frmSimpleBackup = new JFrame(); + this.frmSimpleBackup.setIconImage(Toolkit.getDefaultToolkit() + .getImage(SibaGUI.class.getResource("/org/dclermonte/siba/Cat-Box-256.png"))); this.frmSimpleBackup.getContentPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); this.frmSimpleBackup.setMinimumSize(new Dimension(600, 400)); this.frmSimpleBackup.getContentPane().setBackground(new Color(173, 255, 47)); diff --git a/src/org/dclermonte/siba/model/SibaManager.java b/src/org/dclermonte/siba/model/SibaManager.java index c53f155..594e021 100644 --- a/src/org/dclermonte/siba/model/SibaManager.java +++ b/src/org/dclermonte/siba/model/SibaManager.java @@ -20,6 +20,7 @@ package org.dclermonte.siba.model; import java.io.BufferedOutputStream; +import java.io.Closeable; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -60,18 +61,30 @@ public class SibaManager */ public static File backup(final File fileToSave, File target) throws SibaException { - File result = null; + File result; try { - if (!(fileToSave == null) && fileToSave.exists()) + if ((fileToSave == null) || !(fileToSave.exists())) { - if (fileToSave.isDirectory()) + throw new SibaException(BUNDLE.getString("sourceNotExist.text")); + } + else + { + if (!(fileToSave.isDirectory())) + { + throw new SibaException(BUNDLE.getString("NotDirectorySource.text")); + } + else { if ((target == null)) { target = new File(System.getProperty("user.dir")); } - if (target.isDirectory()) + if (!(target.isDirectory())) + { + throw new SibaException(BUNDLE.getString("NotDirectoryTarget.text")); + } + else { int pathLength = fileToSave.getParentFile().getAbsolutePath().length(); LocalDateTime date = LocalDateTime.now(); @@ -87,27 +100,20 @@ public class SibaManager out.close(); fileCheckMD5(result, target + "/" + outputFileNameWithoutExtension + ".tgz.md5"); } - else - { - throw new SibaException(BUNDLE.getString("NotDirectoryTarget.text")); - } } - else - { - throw new SibaException(BUNDLE.getString("NotDirectorySource.text")); - } - } - else - { - throw new SibaException(BUNDLE.getString("sourceNotExist.text")); } } catch (IOException ioExceptionBackup) { throw new SibaException(BUNDLE.getString("ioExceptionBackup.text"), ioExceptionBackup); //$NON-NLS-1$ } + finally + { + Closeable out = null; + IOUtils.closeQuietly(out); + } + // return result; - } /** @@ -119,7 +125,7 @@ public class SibaManager */ public static boolean check(final File choosenFile) throws SibaException { - boolean result = false; + boolean result; try { if (choosenFile.exists() && (choosenFile.length() > 32)) @@ -173,6 +179,7 @@ public class SibaManager { throw new SibaException(BUNDLE.getString("ioExceptionCheck.text"), ioExceptionCheck); //$NON-NLS-1$ } + // return result; } @@ -252,7 +259,7 @@ public class SibaManager { throw new SibaException(BUNDLE.getString("ioExceptionFileMD5.text"), ioExceptionFileMD5); //$NON-NLS-1$ } - + // return result; } @@ -303,6 +310,7 @@ public class SibaManager throw new SibaException(BUNDLE.getString("ioExceptionMD5.text"), ioException); //$NON-NLS-1$ } result = hashString.toString(); + // return result; }