summaryrefslogtreecommitdiff
path: root/src/de/lmu/ifi/dbs/elki/application/internal/CheckELKIServices.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/application/internal/CheckELKIServices.java')
-rw-r--r--src/de/lmu/ifi/dbs/elki/application/internal/CheckELKIServices.java83
1 files changed, 65 insertions, 18 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/application/internal/CheckELKIServices.java b/src/de/lmu/ifi/dbs/elki/application/internal/CheckELKIServices.java
index 21b8c698..cfa57c80 100644
--- a/src/de/lmu/ifi/dbs/elki/application/internal/CheckELKIServices.java
+++ b/src/de/lmu/ifi/dbs/elki/application/internal/CheckELKIServices.java
@@ -25,9 +25,11 @@ package de.lmu.ifi.dbs.elki.application.internal;
import java.io.BufferedReader;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.PrintStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
@@ -55,7 +57,7 @@ public class CheckELKIServices {
/**
* The logger for this class.
*/
- private static final Logging logger = Logging.getLogger(CheckELKIServices.class);
+ private static final Logging LOG = Logging.getLogger(CheckELKIServices.class);
/**
* Pattern to strip comments, while keeping commented class names.
@@ -73,23 +75,36 @@ public class CheckELKIServices {
* @param argv Command line arguments
*/
public static void main(String[] argv) {
- new CheckELKIServices().checkServices();
+ boolean update = false, noskip = false;
+ for(String arg : argv) {
+ if("-update".equals(arg)) {
+ update = true;
+ }
+ if("-all".equals(arg)) {
+ noskip = true;
+ }
+ }
+ new CheckELKIServices().checkServices(update, noskip);
}
/**
* Retrieve all properties and check them.
+ *
+ * @param update Flag to enable automatic updating
+ * @param noskip Override filters, include all (in particular,
+ * experimentalcode)
*/
- public void checkServices() {
+ public void checkServices(boolean update, boolean noskip) {
URL u = getClass().getClassLoader().getResource(ELKIServiceLoader.PREFIX);
try {
for(String prop : new File(u.toURI()).list()) {
- if (".svn".equals(prop)) {
+ if(".svn".equals(prop)) {
continue;
}
- if (logger.isVerbose()) {
- logger.verbose("Checking property: "+prop);
+ if(LOG.isVerbose()) {
+ LOG.verbose("Checking property: " + prop);
}
- checkService(prop);
+ checkService(prop, update, noskip);
}
}
catch(URISyntaxException e) {
@@ -101,14 +116,17 @@ public class CheckELKIServices {
* Check a single service class
*
* @param prop Class name.
+ * @param update Flag to enable automatic updating
+ * @param noskip Override filters, include all (in particular,
+ * experimentalcode)
*/
- private void checkService(String prop) {
+ private void checkService(String prop, boolean update, boolean noskip) {
Class<?> cls;
try {
cls = Class.forName(prop);
}
catch(ClassNotFoundException e) {
- logger.warning("Property is not a class name: " + prop);
+ LOG.warning("Property is not a class name: " + prop);
return;
}
List<Class<?>> impls = InspectionUtil.findAllImplementations(cls, false);
@@ -121,7 +139,7 @@ public class CheckELKIServices {
break;
}
}
- if(skip) {
+ if(!noskip && skip) {
continue;
}
names.add(c2.getName());
@@ -144,29 +162,58 @@ public class CheckELKIServices {
names.remove(stripped);
}
else {
- logger.warning("Name " + stripped + " found for property " + prop + " but no class discovered (or referenced twice?).");
+ LOG.warning("Name " + stripped + " found for property " + prop + " but no class discovered (or referenced twice?).");
}
}
}
else {
- logger.warning("Line: " + line + " didn't match regexp.");
+ LOG.warning("Line: " + line + " didn't match regexp.");
}
}
}
catch(IOException e) {
- logger.exception(e);
+ LOG.exception(e);
}
if(names.size() > 0) {
- StringBuffer message = new StringBuffer();
- message.append("Class " + prop + " lacks suggestions:" + FormatUtil.NEWLINE);
// format for copy & paste to properties file:
ArrayList<String> sorted = new ArrayList<String>(names);
// TODO: sort by package, then classname
Collections.sort(sorted);
- for(String remaining : sorted) {
- message.append("# " + remaining + FormatUtil.NEWLINE);
+ if(!update) {
+ StringBuilder message = new StringBuilder();
+ message.append("Class ").append(prop).append(" lacks suggestions:").append(FormatUtil.NEWLINE);
+ for(String remaining : sorted) {
+ message.append("# ").append(remaining).append(FormatUtil.NEWLINE);
+ }
+ LOG.warning(message.toString());
+ }
+ else {
+ // Try to automatically update:
+ URL f = getClass().getClassLoader().getResource(ELKIServiceLoader.PREFIX + cls.getName());
+ String fnam = f.getFile();
+ if(fnam == null) {
+ LOG.warning("Cannot update: " + f + " seems to be in a jar file.");
+ }
+ else {
+ try {
+ FileOutputStream out = new FileOutputStream(fnam, true);
+ PrintStream pr = new PrintStream(out);
+ pr.println();
+ pr.println("### Automatically appended entries:");
+ for(String remaining : sorted) {
+ pr.println(remaining);
+ }
+ pr.flush();
+ pr.close();
+ out.flush();
+ out.close();
+ LOG.warning("Updated: " + fnam);
+ }
+ catch(IOException e) {
+ LOG.exception(e);
+ }
+ }
}
- logger.warning(message.toString());
}
}
}