Skip to content
Snippets Groups Projects
Commit cec236b3 authored by hvanwelbergen's avatar hvanwelbergen
Browse files

x

parent 00075398
No related branches found
No related tags found
No related merge requests found
...@@ -35,8 +35,10 @@ import javax.swing.JOptionPane; ...@@ -35,8 +35,10 @@ import javax.swing.JOptionPane;
*/ */
public final class Info public final class Info
{ {
private Info(){} private Info()
{
}
private static Package pack = new Info().getClass().getPackage(); private static Package pack = new Info().getClass().getPackage();
public final static String packageName = pack.getName(); public final static String packageName = pack.getName();
...@@ -52,33 +54,27 @@ public final class Info ...@@ -52,33 +54,27 @@ public final class Info
buf.append("\n"); buf.append("\n");
if (pack.getSpecificationTitle() != null) if (pack.getSpecificationTitle() != null)
{ {
buf.append("Specification-Title: " + pack.getSpecificationTitle() buf.append("Specification-Title: " + pack.getSpecificationTitle() + "\n");
+ "\n");
} }
if (pack.getSpecificationVersion() != null) if (pack.getSpecificationVersion() != null)
{ {
buf.append("Specification-Version: " buf.append("Specification-Version: " + pack.getSpecificationVersion() + "\n");
+ pack.getSpecificationVersion() + "\n");
} }
if (pack.getSpecificationVendor() != null) if (pack.getSpecificationVendor() != null)
{ {
buf.append("Specification-Vendor: " + pack.getSpecificationVendor() buf.append("Specification-Vendor: " + pack.getSpecificationVendor() + "\n");
+ "\n");
} }
if (pack.getImplementationTitle() != null) if (pack.getImplementationTitle() != null)
{ {
buf.append("Implementation-Title: " + pack.getImplementationTitle() buf.append("Implementation-Title: " + pack.getImplementationTitle() + "\n");
+ "\n");
} }
if (pack.getImplementationVersion() != null) if (pack.getImplementationVersion() != null)
{ {
buf.append("Implementation-Version: " buf.append("Implementation-Version: " + pack.getImplementationVersion() + "\n");
+ pack.getImplementationVersion() + "\n");
} }
if (pack.getImplementationVendor() != null) if (pack.getImplementationVendor() != null)
{ {
buf.append("Implementation-Vendor: " buf.append("Implementation-Vendor: " + pack.getImplementationVendor() + "\n");
+ pack.getImplementationVendor() + "\n");
} }
return buf.toString(); return buf.toString();
} }
...@@ -90,15 +86,11 @@ public final class Info ...@@ -90,15 +86,11 @@ public final class Info
*/ */
public static void requireVersion(String requiredVersion) public static void requireVersion(String requiredVersion)
{ {
if (pack.getSpecificationVersion() == null) if (pack.getSpecificationVersion() == null) return; // no check possible, so assume ok
return; // no check possible, so assume ok if (pack.isCompatibleWith(requiredVersion)) return;
if (pack.isCompatibleWith(requiredVersion)) String msg = "Package " + packageName + " Version " + pack.getSpecificationVersion() + " does not meet the required version "
return; + requiredVersion;
String msg = "Package " + packageName + " Version " JOptionPane.showMessageDialog(null, msg, "Package Info", JOptionPane.PLAIN_MESSAGE);
+ pack.getSpecificationVersion()
+ " does not meet the required version " + requiredVersion;
JOptionPane.showMessageDialog(null, msg, "Package Info",
JOptionPane.PLAIN_MESSAGE);
throw new RuntimeException(msg); throw new RuntimeException(msg);
} }
...@@ -126,8 +118,7 @@ public final class Info ...@@ -126,8 +118,7 @@ public final class Info
public static boolean isCompatibleWith(String desiredVersion) public static boolean isCompatibleWith(String desiredVersion)
{ {
String specificationVersion = pack.getSpecificationVersion(); String specificationVersion = pack.getSpecificationVersion();
if (specificationVersion == null) if (specificationVersion == null) return true; // no spec version available, so assume ok
return true; // no spec version available, so assume ok
String[] desiredNums = desiredVersion.split("[.]"); String[] desiredNums = desiredVersion.split("[.]");
String[] specificationNums = specificationVersion.split("[.]"); String[] specificationNums = specificationVersion.split("[.]");
int desired, specified; int desired, specified;
...@@ -148,19 +139,15 @@ public final class Info ...@@ -148,19 +139,15 @@ public final class Info
specified = 0; specified = 0;
} }
if (desired < specified) if (desired < specified) return true;
return true; if (desired > specified) return false;
if (desired > specified)
return false;
} }
return true; return true;
} }
catch (NumberFormatException e) catch (NumberFormatException e)
{ {
System.out System.out.println(packageName + ".Info.isCompatibelWith method: illegal version numbers: " + desiredVersion + " / "
.println(packageName + specificationVersion);
+ ".Info.isCompatibelWith method: illegal version numbers: "
+ desiredVersion + " / " + specificationVersion);
return false; return false;
} }
} }
...@@ -170,8 +157,7 @@ public final class Info ...@@ -170,8 +157,7 @@ public final class Info
*/ */
public static void main(String[] arg) public static void main(String[] arg)
{ {
JOptionPane.showMessageDialog(null, Info.manifestInfo(), JOptionPane.showMessageDialog(null, Info.manifestInfo(), "Package Info", JOptionPane.PLAIN_MESSAGE);
"Package Info", JOptionPane.PLAIN_MESSAGE);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment