Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
build_imagej+ad_plugins.sh 4.76 KiB
#!/bin/bash
# T. Guruswamy <tguruswamy@anl.gov>, 2020
# Download and build ImageJ and ADViewers EPICS plugins

# Select from http://wsr.imagej.net/distros/linux/
IMAGEJ_VER="153"
# Select from https://github.com/areaDetector/ADViewers/tags
ADVIEWERS_VER="R1-7"
# Select from https://github.com/fiji/HDF5_Vibez/tags
HDF5PLUGIN_VER="HDF5_Vibez-1.1.1"
# Select from https://unlimited.ethz.ch/display/JHDF/Download+Page
JHDF5_VER="19.04.1"

# Add Andrea Brewe's patches to ADViewers
ABREWE_PATCH=Y

# Fetch ImageJ
if [ ! -d ImageJ ]; then
    wget -c "http://wsr.imagej.net/distros/linux/ij${IMAGEJ_VER}-linux64-java8.zip"
    unzip -q "ij${IMAGEJ_VER}-linux64-java8.zip"
    # Don't use git version, it's not built
    #wget -c "https://github.com/imagej/ImageJ/archive/${IMAGEJ_VER}/ImageJ-v1.54d.tar.gz"
    #tar xf "ImageJ-${IMAGEJ_VER}.tar.gz"
    #mv "ImageJ-${IMAGEJ_VER#v}" ImageJ
fi

if [ ! -d ImageJ ]; then
    echo "NO ImageJ folder found."
    exit 64
fi

# Fetch ADViewers, including ImageJ plugins
if [ ! -d ADViewers-${ADVIEWERS_VER} ]; then
    wget -c "https://github.com/areaDetector/ADViewers/archive/${ADVIEWERS_VER}/ADViewers-${ADVIEWERS_VER}.tar.gz"
    tar xf "ADViewers-${ADVIEWERS_VER}.tar.gz"
    # Or you can use git version
    #git clone -q -b master https://github.com/areaDetector/ADViewers.git
    #git checkout "$ADVIEWERS_VER"
fi

if [ ! -d ADViewers-${ADVIEWERS_VER} ]; then
    echo "NO ADViewers folder found."
    exit 64
fi

if [ -n $ABREWE_PATCH ]; then
    if [ ! -f ADViewers-${ADVIEWERS_VER}/ImageJ/EPICS_areaDetector/LiveFitter_EPICSUserCalc.java ]; then
    wget -O ADViewers-ABrewe-log_gui.patch -c "https://patch-diff.githubusercontent.com/raw/areaDetector/ADViewers/pull/22.patch"
    wget -O ADViewers-ABrewe-live_fitting.patch -c "https://patch-diff.githubusercontent.com/raw/areaDetector/ADViewers/pull/23.patch"
    pushd ADViewers-${ADVIEWERS_VER}
        patch -f -r - -p1 < ../ADViewers-ABrewe-log_gui.patch
        patch -f -r - -p1 < ../ADViewers-ABrewe-live_fitting.patch
    popd
    fi
fi

# Copy ADViewer plugins into ImageJ folder
cp -a "ADViewers-${ADVIEWERS_VER}/ImageJ/EPICS_areaDetector" ImageJ/plugins/

# Fetch Fiji HDF5 plugin
if [ ! -d HDF5_Vibez-${HDF5PLUGIN_VER} ]; then
    wget -c "https://github.com/fiji/HDF5_Vibez/archive/refs/tags/${HDF5PLUGIN_VER}.tar.gz"
    tar xf "${HDF5PLUGIN_VER}.tar.gz"
fi

if [ ! -d HDF5_Vibez-${HDF5PLUGIN_VER} ]; then
    echo "NO HDF5 Plugin found."
    exit 64
fi

# Copy HDF5 plugins into ImageJ folder
cp -a "HDF5_Vibez-${HDF5PLUGIN_VER}/src/main/java/sc/fiji/hdf5/" ImageJ/plugins/
sed -i 's/package sc\.fiji\.hdf5/package hdf5/g' ImageJ/plugins/hdf5/*.java

# If you want a test HDF5 file
#wget -c "https://lmb.informatik.uni-freiburg.de/resources/opensource/imagej_plugins/samples/pollen.h5"
#cp -a pollen.h5 ImageJ/plugins/hdf5/

# Fetch JHDF5 library
if [ ! -d sis-jhdf5 ]; then
    wget --content-disposition -c "https://unlimited.ethz.ch/download/attachments/92867433/sis-jhdf5-${JHDF5_VER}.zip?version=1&api=v2"
    unzip -q "sis-jhdf5-${JHDF5_VER}.zip"
fi

if [ ! -d sis-jhdf5 ]; then
    echo "NO JHDF5 library found."
    exit 64
fi

# Copy JHDF5 library into ImageJ folder
cp -a sis-jhdf5/lib/*.jar ImageJ/plugins/hdf5/

# Compile all plugins
pushd ImageJ

# Not all files are plugins. Look for 'implements PlugIn' in source
plugins=(
    "EPICS_areaDetector/EPICS_AD_Viewer.java" 
    "EPICS_areaDetector/EPICS_AD_Controller.java" 
    "EPICS_areaDetector/EPICS_NTNDA_Viewer.java" 
    "EPICS_areaDetector/Gaussian_Profiler.java" 
    "EPICS_areaDetector/Dynamic_Profiler.java"
    "hdf5/HDF5_Reader_Vibez.java"
    "hdf5/HDF5_Simple_Custom_Reader.java"
    "hdf5/HDF5_Simple_Reader.java"
    "hdf5/HDF5_Simple_Writer.java"
    "hdf5/HDF5_Writer_Vibez.java"
    "hdf5/Vibez_Validate.java"
)

if [ -n $ABREWE_PATCH ]; then
plugins+=( "EPICS_areaDetector/LiveFitter_EPICSUserCalc.java" )
fi

for plugin in "${plugins[@]}"; do
    echo "Compiling ${plugin}"
    plugin_basedir=$(dirname ./plugins/${plugin})
    # The classpath is constructed from every *.jar file in the plugin folder. Do not include .jars from *other* plugins!
    PLUGIN_CLASSPATH="$(find ./plugins/jars ${plugin_basedir} -name "*.jar" -print | tr '\n' ':')"
    PLUGIN_CLASSPATH="./ij.jar:${plugin_basedir}/:./plugins/:${PLUGIN_CLASSPATH%:}"
    #echo "PLUGIN_CLASSPATH= ${PLUGIN_CLASSPATH}"
    # This command was extracted from the ImageJ logs after manually running "Plugins -> Compile and Run..."
    # If you are having compilation issues, add -verbose
    javac -source 1.8 -target 1.8 -Xlint:unchecked -deprecation -classpath "${PLUGIN_CLASSPATH}" "plugins/${plugin}"
done

popd

# Detector Pool pre-configured ImageJ profiles for specific detectors
if [ -d "ImageJ_Profiles" ]; then
    cp -a "ImageJ_Profiles" "ImageJ"
fi

# Make permissions consistent
chmod -R ug+rwX,o+rX ImageJ