TESTNAME=MixedSigningAndTrustedOnly

SRC_NAME1=$(TESTNAME)Class1
SRC_NAME2=$(TESTNAME)Class2
SRC_FILE1=$(SRC_NAME1).java
SRC_FILE2=$(SRC_NAME2).java
COMPILED_FILES1=$(SRC_NAME1)*.class
COMPILED_FILES2=$(SRC_NAME2)*.class

JAVAC_CLASSPATH=$(TEST_EXTENSIONS_DIR):$(NETX_DIR)/lib/classes.jar
JAVAC=$(EXPORTED_JAVAC)
JAR=$(EXPORTED_JAR)
JARSIGNER=$(EXPORTED_JARSIGNER)
JARSIGNER_CMD=$(JARSIGNER) -keystore $(TOP_BUILD_DIR)/$(PRIVATE_KEYSTORE_NAME) -storepass $(PRIVATE_KEYSTORE_PASS) -keypass $(PRIVATE_KEYSTORE_PASS)
SIGFILE=-sigfile Alpha

SIGNED1=$(TESTNAME)BothSigned.jar
SIGNED2=$(TESTNAME)FirstSigned.jar
SIGNED3=$(TESTNAME)SecondSigned.jar
UNSIGNED1=$(TESTNAME)BothUnsigned.jar
UNSIGNED2=$(TESTNAME)FirstUnsigned.jar
UNSIGNED3=$(TESTNAME)SecondUnsigned.jar

MSIGNED1=$(TESTNAME)BothSignedManifest.jar
MSIGNED2=$(TESTNAME)FirstSignedManifest.jar
MSIGNED3=$(TESTNAME)SecondSignedManifest.jar
MUNSIGNED1=$(TESTNAME)BothUnsignedManifest.jar
MUNSIGNED2=$(TESTNAME)FirstUnsignedManifest.jar
MUNSIGNED3=$(TESTNAME)SecondUnsignedManifest.jar

MANIFEST=MANIFEST.MF
ifeq ($(OS), Windows_NT)
	TMPDIR:=$(shell cygpath -p -m $(shell mktemp -d))
else
	TMPDIR:=$(shell mktemp -d)
endif

prepare-reproducer:
	echo PREPARING REPRODUCER $(TESTNAME) ; \
	$(JAVAC) -d $(TMPDIR) -classpath $(JAVAC_CLASSPATH) $(SRC_FILE1) $(SRC_FILE2); \
	cp ../resources/* $(REPRODUCERS_TESTS_SERVER_DEPLOYDIR); \
	pushd $(TMPDIR); \
	$(JAR) cf $(SIGNED1) $(COMPILED_FILES1) $(COMPILED_FILES2); \
	$(JAR) cf $(SIGNED2) $(COMPILED_FILES1) ; \
	$(JAR) cf $(SIGNED3) $(COMPILED_FILES2); \
	$(JAR) cf $(UNSIGNED1) $(COMPILED_FILES1) $(COMPILED_FILES2); \
	$(JAR) cf $(UNSIGNED2) $(COMPILED_FILES1) ; \
	$(JAR) cf $(UNSIGNED3) $(COMPILED_FILES2); \
	popd ; \
	cp $(MANIFEST) $(TMPDIR) ; \
	pushd $(TMPDIR); \
	$(JAR) cfm  $(MSIGNED1)   $(MANIFEST) $(COMPILED_FILES1) $(COMPILED_FILES2); \
	$(JAR) cfm  $(MSIGNED2)   $(MANIFEST) $(COMPILED_FILES1) ; \
	$(JAR) cfm  $(MSIGNED3)   $(MANIFEST) $(COMPILED_FILES2); \
	$(JAR) cfm  $(MUNSIGNED1) $(MANIFEST) $(COMPILED_FILES1) $(COMPILED_FILES2); \
	$(JAR) cfm  $(MUNSIGNED2) $(MANIFEST) $(COMPILED_FILES1) ; \
	$(JAR) cfm  $(MUNSIGNED3) $(MANIFEST) $(COMPILED_FILES2); \
	popd ; \
	$(JARSIGNER_CMD) $(SIGFILE) $(TMPDIR)/$(SIGNED1) $(TEST_CERT_ALIAS)_signed; \
	$(JARSIGNER_CMD) $(SIGFILE) $(TMPDIR)/$(SIGNED2) $(TEST_CERT_ALIAS)_signed; \
	$(JARSIGNER_CMD) $(SIGFILE) $(TMPDIR)/$(SIGNED3) $(TEST_CERT_ALIAS)_signed; \
	$(JARSIGNER_CMD) $(SIGFILE) $(TMPDIR)/$(MSIGNED1) $(TEST_CERT_ALIAS)_signed; \
	$(JARSIGNER_CMD) $(SIGFILE) $(TMPDIR)/$(MSIGNED2) $(TEST_CERT_ALIAS)_signed; \
	$(JARSIGNER_CMD) $(SIGFILE) $(TMPDIR)/$(MSIGNED3) $(TEST_CERT_ALIAS)_signed; \
	cp $(TMPDIR)/{$(SIGNED1),$(SIGNED2),$(SIGNED3)} $(REPRODUCERS_TESTS_SERVER_DEPLOYDIR); \
	cp $(TMPDIR)/{$(UNSIGNED1),$(UNSIGNED2),$(UNSIGNED3)} $(REPRODUCERS_TESTS_SERVER_DEPLOYDIR); \
	cp $(TMPDIR)/{$(MSIGNED1),$(MSIGNED2),$(MSIGNED3)} $(REPRODUCERS_TESTS_SERVER_DEPLOYDIR); \
	cp $(TMPDIR)/{$(MUNSIGNED1),$(MUNSIGNED2),$(MUNSIGNED3)} $(REPRODUCERS_TESTS_SERVER_DEPLOYDIR); \
	echo PREPARED REPRODUCER $(TESTNAME), removing $(TMPDIR); \
	rm -rf $(TMPDIR); 

clean-reproducer:
	echo NOTHING TO CLEAN FOR $(TESTNAME)
