#!/bin/bash -e
#with this script we want to build the eclipse jars (bundles) used by tycho
#this will install all bundles into a single jar (could be improved...)

#was: 3.10.100.v20150602-1500
osgiV='debian'
eclipseV='4.5.6'
BUNDLES="./eclipse-bundles"

# this is a writeable, temporary, maven repository
REPO=$1
BUILD=$2

cd $BUNDLES

mkdir -p $BUILD/src/main/java

echo "Copying files..."
cp -r org.eclipse.core.runtime/* $BUILD/src/main/java
cp -r org.eclipse.core.contenttype/src/* $BUILD/src/main/java
cp -r org.eclipse.core.jobs/src/* $BUILD/src/main/java
cp -r org.eclipse.equinox.p2.core/* $BUILD/src/main/java
cp -r org.eclipse.equinox.p2.metadata/* $BUILD/src/main/java
cp -r org.eclipse.equinox.p2.publisher/src/* $BUILD/src/main/java
cp -r org.eclipse.equinox.p2.publisher.eclipse/* $BUILD/src/main/java
cp -r org.eclipse.equinox.p2.repository/* $BUILD/src/main/java
cp -r org.eclipse.equinox.p2.metadata.repository/* $BUILD/src/main/java
cp -r org.eclipse.equinox.p2.artifact.repository/src/* $BUILD/src/main/java
cp -r org.eclipse.equinox.p2.jarprocessor/src/* $BUILD/src/main/java
cp -r org.eclipse.equinox.simpleconfigurator/src/* $BUILD/src/main/java
cp -r org.eclipse.equinox.simpleconfigurator.manipulator/* $BUILD/src/main/java
cp -r org.eclipse.equinox.frameworkadmin/src/* $BUILD/src/main/java
cp -r org.eclipse.equinox.frameworkadmin.equinox/src/* $BUILD/src/main/java
cp -r org.eclipse.osgi.util/src/* $BUILD/src/main/java
cp -r org.eclipse.osgi/container/src/* $BUILD/src/main/java
cp -r org.eclipse.osgi/supplement/src/* $BUILD/src/main/java
cp -r org.eclipse.equinox.preferences/src/* $BUILD/src/main/java
cp -r org.eclipse.equinox.preferences/src/* $BUILD/src/main/java
cp -r org.eclipse.equinox.common/src/* $BUILD/src/main/java
cp -r org.eclipse.equinox.security/src/* $BUILD/src/main/java
cp -r org.eclipse.equinox.app/src/* $BUILD/src/main/java
cp -r org.eclipse.equinox.registry/src/* $BUILD/src/main/java

cp -r org.eclipse.osgi.compatibility.state/src/* $BUILD/src/main/java	#compat. include osgi.internal...
cp -r org.eclipse.osgi/felix/src/* $BUILD/src/main/java

cp -r org.eclipse.equinox.p2.repository.tools/* $BUILD/src/main/java
cp -r org.eclipse.osgi/osgi/src/* $BUILD/src/main/java
cp -r org.eclipse.equinox.app/osgi/* $BUILD/src/main/java
cp -r org.eclipse.osgi.services/src/* $BUILD/src/main/java
cp -r org.eclipse.equinox.p2.director/src/* $BUILD/src/main/java
cp -r org.eclipse.equinox.p2.engine/* $BUILD/src/main/java
cp -r org.eclipse.equinox.p2.jarprocessor/src_ant/* $BUILD/src/main/java

#$MAVEN_BIN compile              #first 1546 files 26sec

#need SteppedTimeoutLexicoHelper from sat4j 2.3.4

cp -r org.eclipse.equinox.p2.touchpoint.eclipse/src/* $BUILD/src/main/java
cp -r org.eclipse.equinox.p2.garbagecollector/src/* $BUILD/src/main/java
cp -r org.eclipse.equinox.p2.updatesite/src/* $BUILD/src/main/java
cp -r org.eclipse.equinox.p2.director.app/src/* $BUILD/src/main/java
cp -r org.eclipse.core.net/src/* $BUILD/src/main/java

#$MAVEN_BIN compile             #here 1663 files 28sec

cp -r org.eclipse.swt/Eclipse\ SWT/common/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT/cairo/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT/gtk/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT/emulated/taskbar/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT/emulated/bidi/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT/emulated/coolbar/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT/common_j2se/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT\ Custom\ Widgets/common/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT\ Printing/common/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT\ Printing/gtk/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT\ Drag\ and\ Drop/common/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT\ Drag\ and\ Drop/gtk/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT\ PI/common/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT\ PI/common_j2se/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT\ PI/cairo/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT\ PI/gtk/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT\ Accessibility/common/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT\ Accessibility/gtk/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT\ Browser/common/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT\ Browser/gtk/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT\ Mozilla/common/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT\ Mozilla/gtk/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT\ WebKit/gtk/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT\ Program/common/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT\ Program/gtk/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT\ Program/gnome/* $BUILD/src/main/java
cp -r org.eclipse.swt/Eclipse\ SWT\ Program/cde/* $BUILD/src/main/java

#$MAVEN_BIN compile             #here 2226 files 35sec

cp -r org.eclipse.jdt.core/compiler/* $BUILD/src/main/java	#org.eclipse.jdt...
cp -r org.eclipse.jdt.core/batch/* $BUILD/src/main/java
cp -r org.eclipse.jdt.core/model/* $BUILD/src/main/java
cp -r org.eclipse.jdt.core/codeassist/* $BUILD/src/main/java
cp -r org.eclipse.jdt.core/search/* $BUILD/src/main/java
cp -r org.eclipse.jdt.core/dom/* $BUILD/src/main/java
cp -r org.eclipse.jdt.core/formatter/* $BUILD/src/main/java
cp -r org.eclipse.jdt.core/eval/* $BUILD/src/main/java
cp -r org.eclipse.text/src/* $BUILD/src/main/java
cp -r org.eclipse.text/projection/* $BUILD/src/main/java
cp -r org.eclipse.jface.text/src/* $BUILD/src/main/java
cp -r org.eclipse.jface.text/projection/* $BUILD/src/main/java
cp -r org.eclipse.core.commands/* $BUILD/src/main/java
cp -r org.eclipse.jface/src/* $BUILD/src/main/java
cp -r org.eclipse.core.expressions/src/* $BUILD/src/main/java
cp -r org.eclipse.equinox.bidi/src/* $BUILD/src/main/java
cp -r org.eclipse.core.resources/src/* $BUILD/src/main/java
cp -r org.eclipse.core.filesystem/src/* $BUILD/src/main/java

#$MAVEN_BIN compile              #4811 files 71sec

cp pom.xml $BUILD

cd $BUILD

#mvn -o -Dmaven.repo.local=$REPO -Dmaven.test.skip=true install

#FIXME libequinox-osgi-java ?
#provo a schermarlo per usare maven-repo-helper
#echo "installing tycho artifacts..."
#
#function fake_tycho_artifact() {
#  ARTIFACTID=$1
#  VERSION=$2
#  mkdir -p $REPO/org/eclipse/tycho/$ARTIFACTID/$VERSION
#  ln -sf $REPO/org/eclipse/eclipse-bootstrap/${eclipseV}/eclipse-bootstrap-${eclipseV}.jar $REPO/org/eclipse/tycho/$ARTIFACTID/$VERSION/$ARTIFACTID-$VERSION.jar
#  cp debian/$ARTIFACTID.pom.xml $REPO/org/eclipse/tycho/$ARTIFACTID/$VERSION/$ARTIFACTID-$VERSION.pom
#}
#
#fake_tycho_artifact org.eclipse.osgi ${osgiV}
#fake_tycho_artifact org.eclipse.osgi.compatibility.state ${osgiV}
#fake_tycho_artifact org.eclipse.jdt.core ${osgiV}
#fake_tycho_artifact org.eclipse.jdt.compiler.apt ${osgiV}

