#FROM ubuntu:23.04
# 23.04 is the defects4j version, but now support seems to be ended
# Maybe go back to a LTS version?
FROM ubuntu:22.04

#############################################################################
# Requirements
#############################################################################

RUN \
  apt-get update -y && \
  apt-get install software-properties-common -y && \
  apt-get update -y && \
  #apt-get install -y openjdk-8-jdk \
  apt-get install -y openjdk-11-jdk \
  git \
  build-essential \
  subversion \
  perl \
  curl \
  unzip \
  cpanminus \
  make \
  python3 \
  python3-pip \
  vim \
  && \
  rm -rf /var/lib/apt/lists/*

# Java version
#ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64
ENV JAVA_HOME /usr/lib/jvm/java-11-openjdk-amd64
# ^ THIS GETS REPLACED IN PYTHON IF ARM64.
#  bit of a hack. There is probably a way to do in Docker
#  instead but not sure the interaction with epicbox.
#ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-arm64/
# Timezone
ENV TZ=America/Los_Angeles
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone


#############################################################################
# Setup Defects4J
#############################################################################

# ----------- Step 1. Clone defects4j from github --------------
WORKDIR /
RUN git clone https://github.com/rjust/defects4j.git defects4j

# ----------- Step 2. Initialize Defects4J ---------------------
WORKDIR /defects4j
RUN cpanm --installdeps .
RUN ./init.sh

# ----------- Step 3. Add Defects4J's executables to PATH: ------
ENV PATH="/defects4j/framework/bin:${PATH}"
#--------------

# Install pandas
#RUN pip install --break-system-packages pandas
RUN python3 -m pip install --upgrade pip
RUN python3 -m pip install --break-system-packages pandas

# Copy scripts, dataset, and build config
COPY dataset.py .
COPY Defects4J_oneLiner_metadata.csv .
COPY defects4j.build.xml /defects4j/framework/projects/defects4j.build.xml

# Download all repositories
RUN python3 dataset.py
CMD [ "bash", "defects4j", "info", "-p", "Lang"]
