+Version 1.2.3
+-------------
+
+Add openResource and getVersion in IOUtils
+ The file VERSION is supposed to exist
+
+Give more informartion on AssertErrors
+ The TestCase were not always helpful in case of AssertExceptions; they
+ now print the stacktrace (they only used to do it for non-assert
+ exceptions)
+
+Fix configure.sh
+ The VERSION file was not added, the Main method was not the correct
+ one (so it was not producing working runnable JAR, yet it stated so)
+
Version 1.2.2
-------------
fi;
-echo "MAIN = be/nikiroo/utils/resources/TransBundle" > Makefile
-echo "MORE = be/nikiroo/utils/StringUtils be/nikiroo/utils/IOUtils be/nikiroo/utils/MarkableFileInputStream be/nikiroo/utils/ui/UIUtils be/nikiroo/utils/ui/WrapLayout be/nikiroo/utils/ui/ProgressBar be/nikiroo/utils/test/TestLauncher" >> Makefile
+echo "MAIN = be/nikiroo/utils/test/Test" > Makefile
+echo "MORE = be/nikiroo/utils/StringUtils be/nikiroo/utils/IOUtils be/nikiroo/utils/MarkableFileInputStream be/nikiroo/utils/ui/UIUtils be/nikiroo/utils/ui/WrapLayout be/nikiroo/utils/ui/ProgressBar be/nikiroo/utils/resources/TransBundle" >> Makefile
echo "TEST = be/nikiroo/utils/test/Test" >> Makefile
echo "TEST_PARAMS = $cols $ok $ko" >> Makefile
echo "NAME = nikiroo-utils" >> Makefile
echo "PREFIX = $PREFIX" >> Makefile
-echo "JAR_FLAGS += -C bin/ be" >> Makefile
+echo "JAR_FLAGS += -C bin/ be -C bin/ VERSION" >> Makefile
echo "SJAR_FLAGS += -C src/ be" >> Makefile
cat Makefile.base >> Makefile
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
* @throws IOException
* in case of IO error
*/
- static public BufferedImage toImage(InputStream in) throws IOException {
+ public static BufferedImage toImage(InputStream in) throws IOException {
MarkableFileInputStream tmpIn = null;
File tmp = null;
try {
return image;
}
+ /**
+ * Return the version of the program if it follows the VERSION convention
+ * (i.e., if it has a file called VERSION containing the version as a
+ * {@link String} on its binary root).
+ *
+ * @return the version, or NULL
+ */
+ public static String getVersion() {
+ String version = null;
+
+ InputStream in = openResource("VERSION");
+ if (in != null) {
+ try {
+ ByteArrayOutputStream ba = new ByteArrayOutputStream();
+ write(in, ba);
+ in.close();
+
+ version = ba.toString("UTF-8");
+ } catch (IOException e) {
+ }
+ }
+
+ return version;
+ }
+
+ /**
+ * Open the given /-separated resource (from the binary root).
+ *
+ * @param name
+ * the resource name
+ *
+ * @return the opened resource if found, NLL if not
+ */
+ public static InputStream openResource(String name) {
+ ClassLoader loader = IOUtils.class.getClassLoader();
+ if (loader == null) {
+ loader = ClassLoader.getSystemClassLoader();
+ }
+
+ return loader.getResourceAsStream(name);
+ }
+
/**
* Return the EXIF transformation flag of this image if any.
*
* @throws IOException
* in case of IO error
*/
- static private int getExifTransorm(InputStream in) throws IOException {
+ private static int getExifTransorm(InputStream in) throws IOException {
int[] exif_data = new int[100];
int set_flag = 0;
int is_motorola = 0;
name = Progress.this.name;
}
- setTotalProgress(name, (int) (total * (max - min)));
+ setTotalProgress(name, (int) Math.round(total * (max - min)));
}
});
--- /dev/null
+package be.nikiroo.utils.test;
+
+import java.io.InputStream;
+
+import be.nikiroo.utils.IOUtils;
+
+public class IOUtilsTest extends TestLauncher {
+
+ public IOUtilsTest(String[] args) {
+ super("IOUtils test", args);
+
+ addTest(new TestCase("openResource") {
+ @Override
+ public void test() throws Exception {
+ InputStream in = IOUtils.openResource("VERSION");
+ assertNotNull(
+ "The VERSION file is supposed to be present in the binaries",
+ in);
+ in.close();
+ }
+ });
+
+ addTest(new TestCase("getVersion") {
+ @Override
+ public void test() throws Exception {
+ assertNotNull("The VERSION is not defined",
+ IOUtils.getVersion());
+ }
+ });
+ }
+}
addSeries(new ProgressTest(args));
addSeries(new BundleTest(args));
+ addSeries(new IOUtilsTest(args));
}
/**
assertEquals(errorMessage, new Double(expected), new Double(actual));
}
+ /**
+ * Check that given {@link Object} is not NULL.
+ *
+ * @param the
+ * error message to display if it is NULL
+ * @param actual
+ * the actual value
+ *
+ * @throws AssertException
+ * in case they differ
+ */
+ public void assertNotNull(String errorMessage, Object actual)
+ throws AssertException {
+ if (actual == null) {
+ if (errorMessage == null) {
+ errorMessage = String.format("" //
+ + "Assertion failed!\n" //
+ + "Object should have been NULL: [%s]", actual);
+ }
+ throw new AssertException(errorMessage);
+ }
+ }
+
/**
* Generate the default assert message for 2 different values that were
* supposed to be equals.
import java.util.ArrayList;
import java.util.List;
-import be.nikiroo.utils.test.TestCase.AssertException;
-
/**
* A {@link TestLauncher} starts a series of {@link TestCase}s and displays the
* result to the user.
private void print(int depth, Exception error) {
if (error != null) {
System.out.println(" " + koString);
- String lines = error.getMessage() + "";
- if (!(error instanceof AssertException)) {
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- error.printStackTrace(pw);
- lines = sw.toString();
- }
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ error.printStackTrace(pw);
+ String lines = sw.toString();
for (String line : lines.split("\n")) {
System.out.println(prefix(depth, false) + "\t\t" + line);
}