Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/org/scijava/InstantiableException.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
*/
public class InstantiableException extends Exception {

private static final long serialVersionUID = 1L;

public InstantiableException() {
super();
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/scijava/MenuPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
*/
public class MenuPath extends ArrayList<MenuEntry> {

private static final long serialVersionUID = 1L;

/** The separator between elements of a menu path string. */
public static final String PATH_SEPARATOR = ">";

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/scijava/NoSuchServiceException.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
*/
public class NoSuchServiceException extends RuntimeException {

private static final long serialVersionUID = 1L;

public NoSuchServiceException() {
super();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/scijava/object/ObjectIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,13 @@ protected boolean remove(final Object o, final Class<?> type,
}

protected boolean addToList(final E obj, final List<E> list,
@SuppressWarnings("unused") final boolean batch)
final boolean batch)
{
return list.add(obj);
}

protected boolean removeFromList(final Object obj, final List<E> list,
@SuppressWarnings("unused") final boolean batch)
final boolean batch)
{
return list.remove(obj);
}
Expand Down
51 changes: 34 additions & 17 deletions src/main/java/org/scijava/util/CheckSezpoz.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.DigestInputStream;
import java.security.MessageDigest;
Expand All @@ -57,6 +58,8 @@
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
Expand Down Expand Up @@ -363,30 +366,14 @@ protected static boolean hasAnnotation(final File file) {
* @return whether anything in {@code META-INF/annotations/*} changed
*/
public static boolean fix(final File classes, final File sources) {
final Method aptProcess;
try {
final Class<?> aptClass =
CheckSezpoz.class.getClassLoader().loadClass("com.sun.tools.apt.Main");
aptProcess =
aptClass.getMethod("process", new Class[] { String[].class });
}
catch (final Exception e) {
e.printStackTrace();
System.err
.println("ERROR: Could not fix " + sources + ": apt not found");
return false;
}
if (!sources.exists()) {
System.err.println("ERROR: Sources are not in the expected place: " +
sources);
return false;
}

final List<String> aptArgs = new ArrayList<String>();
aptArgs.add("-nocompile");
if (verbose) aptArgs.add("-verbose");
aptArgs.add("-factory");
aptArgs.add("net.java.sezpoz.impl.IndexerFactory");
aptArgs.add("-d");
aptArgs.add(classes.getPath());
final int count = aptArgs.size();
Expand All @@ -412,7 +399,7 @@ public static boolean fix(final File classes, final File sources) {
final String[] args = aptArgs.toArray(new String[aptArgs.size()]);
try {
System.err.println("WARN: Updating the annotation index in " + classes);
aptProcess.invoke(null, new Object[] { args });
runApt(args);
}
catch (final Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -440,6 +427,36 @@ public static boolean fix(final File classes, final File sources) {
return result;
}

private static void runApt(String[] args) throws ClassNotFoundException,
SecurityException, NoSuchMethodException, IllegalArgumentException,
IllegalAccessException, InvocationTargetException
{
final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
if (compiler != null) {
final List<String> aptArgs = new ArrayList<String>();
aptArgs.add("-proc:only");
aptArgs.add("-processor");
aptArgs.add("net.java.sezpoz.impl.Indexer6");
aptArgs.addAll(Arrays.asList(args));
compiler.run(null, null, null, args);
return;
}

System.err.println("WARN: falling back to calling the 'apt' Main class directly");
final List<String> aptArgs = new ArrayList<String>();
aptArgs.add("-nocompile");
aptArgs.add("-factory");
aptArgs.add("net.java.sezpoz.impl.IndexerFactory");
aptArgs.addAll(Arrays.asList(args));

final Method aptProcess;
final Class<?> aptClass =
ToolProvider.getSystemToolClassLoader().loadClass("com.sun.tools.apt.Main");
aptProcess =
aptClass.getMethod("process", new Class[] { String[].class });
aptProcess.invoke(null, aptArgs.toArray());
}

private static MessageDigest digest;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/scijava/util/SizableArrayList.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
*/
public class SizableArrayList<E> extends ArrayList<E> implements Sizable {

private static final long serialVersionUID = 1L;

// -- Constructors --

public SizableArrayList(final int initialCapacity) {
Expand Down
11 changes: 9 additions & 2 deletions src/test/java/org/scijava/util/CheckSezpozTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -50,6 +51,9 @@
import java.net.URL;
import java.net.URLClassLoader;

import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;

import net.java.sezpoz.Index;
import net.java.sezpoz.IndexItem;

Expand Down Expand Up @@ -115,8 +119,11 @@ public void testBasic() throws Exception {
+ "}\n");
writer.close();

ProcessUtils.exec(sources, System.err, System.out, "javac", "-classpath",
System.getProperty("java.class.path"), "Annotated.java");
final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
if (compiler == null) System.err.println("WARN: running in a JRE; Skipping CheckSezpozTest!");
assumeTrue(compiler != null);
compiler.run(null, null, null, "-classpath",
System.getProperty("java.class.path"), new File(sources, "Annotated.java").getAbsolutePath());

// to make sure the annotation processor "has not run",
// we need to copy the .class file
Expand Down