eclipse-ee4j / jakartaee-tck-tools

Other
7 stars 15 forks source link

Missing ear lib that leads to compile error in generated code for unknown jpa_ee_propagation_cm_ext variable #92

Closed scottmarlow closed 1 month ago

scottmarlow commented 1 month ago

I probably missed seeing compile errors for the below generated code that references unknown variable jpa_ee_propagation_cm_ext. The variable name happens to match the deployment name but otherwise isn't used elsewhere in the generated code. I suspect that jpa_ee_propagation_cm_ext is related to the lib/jpa_ee_propagation_cm_ext.jar entry in the EE 10 binary.

The EE 10 TCK jpa_ee_propagation_cm_ext.ear has contents:

META-INF/ META-INF/MANIFEST.MF jpa_ee_propagation_cm_ext_client.jar jpa_ee_propagation_cm_ext_ejb.jar lib/jpa_ee_propagation_cm_ext.jar

The EE 10 jpa_ee_propagation_cm_ext.jar contents:

META-INF/MANIFEST.MF com/sun/ts/tests/jpa/ee/common/A.class com/sun/ts/tests/jpa/ee/common/Account.class com/sun/ts/tests/jpa/ee/common/B.class META-INF/persistence.xml

package ee.jakarta.tck.persistence.ee.propagation.cm.extended;

import ee.jakarta.tck.persistence.ee.propagation.cm.extended.Client;
import java.net.URL;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
import org.jboss.arquillian.container.test.api.OverProtocol;
import org.jboss.arquillian.container.test.api.TargetsContainer;
import org.jboss.arquillian.junit5.ArquillianExtension;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.exporter.ZipExporter;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import tck.arquillian.porting.lib.spi.TestArchiveProcessor;
import tck.arquillian.protocol.common.TargetVehicle;

@ExtendWith(ArquillianExtension.class)
@Tag("javaee")

public class ClientTest extends ee.jakarta.tck.persistence.ee.propagation.cm.extended.Client {
    @TargetsContainer("tck-appclient")
        @OverProtocol("appclient")
        @Deployment(name = "jpa_ee_propagation_cm_ext", order = 2)
        public static EnterpriseArchive createDeployment(@ArquillianResource TestArchiveProcessor archiveProcessor) {
        // Client
            // the jar with the correct archive name
            JavaArchive jpa_ee_propagation_cm_ext_client = ShrinkWrap.create(JavaArchive.class, "jpa_ee_propagation_cm_ext_client.jar");
            // The class files
            jpa_ee_propagation_cm_ext_client.addClasses(
            com.sun.ts.lib.harness.EETest.Fault.class,
            ee.jakarta.tck.persistence.ee.propagation.cm.extended.Stateful3IF.class,
            com.sun.ts.lib.harness.EETest.class,
            ee.jakarta.tck.persistence.ee.propagation.cm.extended.Client.class,
            com.sun.ts.lib.harness.EETest.SetupException.class
            );
            // The application-client.xml descriptor
            URL resURL = Client.class.getResource("/com/sun/ts/tests/jpa/ee/propagation/cm/extended/");
            if(resURL != null) {
              jpa_ee_propagation_cm_ext_client.addAsManifestResource(resURL, "application-client.xml");
            }
            // The sun-application-client.xml file need to be added or should this be in in the vendor Arquillian extension?
            resURL = Client.class.getResource("/com/sun/ts/tests/jpa/ee/propagation/cm/extended/.jar.sun-application-client.xml");
            if(resURL != null) {
              jpa_ee_propagation_cm_ext_client.addAsManifestResource(resURL, "application-client.xml");
            }
            jpa_ee_propagation_cm_ext_client.addAsManifestResource(new StringAsset("Main-Class: " + Client.class.getName() + "\n"), "MANIFEST.MF");
            archiveProcessor.processClientArchive(jpa_ee_propagation_cm_ext_client, Client.class, resURL);

        // Ejb
            // the jar with the correct archive name
            JavaArchive jpa_ee_propagation_cm_ext_ejb = ShrinkWrap.create(JavaArchive.class, "jpa_ee_propagation_cm_ext_ejb.jar");
            // The class files
            jpa_ee_propagation_cm_ext_ejb.addClasses(
                ee.jakarta.tck.persistence.ee.propagation.cm.extended.Stateful3IF.class,
                ee.jakarta.tck.persistence.ee.propagation.cm.extended.TellerBean.class,
                ee.jakarta.tck.persistence.ee.propagation.cm.extended.Teller.class,
                ee.jakarta.tck.persistence.ee.propagation.cm.extended.Stateful3Bean.class
            );
            // The ejb-jar.xml descriptor
            URL ejbResURL = Client.class.getResource("/com/sun/ts/tests/jpa/ee/propagation/cm/extended/");
            if(ejbResURL != null) {
              jpa_ee_propagation_cm_ext_ejb.addAsManifestResource(ejbResURL, "ejb-jar.xml");
            }
            // The sun-ejb-jar.xml file
            ejbResURL = Client.class.getResource("/com/sun/ts/tests/jpa/ee/propagation/cm/extended/.jar.sun-ejb-jar.xml");
            if(ejbResURL != null) {
              jpa_ee_propagation_cm_ext_ejb.addAsManifestResource(ejbResURL, "sun-ejb-jar.xml");
            }
            archiveProcessor.processEjbArchive(jpa_ee_propagation_cm_ext_ejb, Client.class, ejbResURL);

        // Ear
            EnterpriseArchive jpa_ee_propagation_cm_ext_ear = ShrinkWrap.create(EnterpriseArchive.class, "jpa_ee_propagation_cm_ext.ear");

            // Any libraries added to the ear

            // The component jars built by the package target
            jpa_ee_propagation_cm_ext_ear.addAsModule(jpa_ee_propagation_cm_ext_ejb);
            jpa_ee_propagation_cm_ext_ear.addAsModule(jpa_ee_propagation_cm_ext_client);

            jpa_ee_propagation_cm_ext_ear.addAsLibrary(jpa_ee_propagation_cm_ext);

            // The application.xml descriptor
            URL earResURL = Client.class.getResource("/com/sun/ts/tests/jpa/ee/propagation/cm/extended/");
            if(earResURL != null) {
              jpa_ee_propagation_cm_ext_ear.addAsManifestResource(earResURL, "application.xml");
            }
            // The sun-application.xml descriptor
            earResURL = Client.class.getResource("/com/sun/ts/tests/jpa/ee/propagation/cm/extended/.ear.sun-application.xml");
            if(earResURL != null) {
              jpa_ee_propagation_cm_ext_ear.addAsManifestResource(earResURL, "sun-application.xml");
            }
            archiveProcessor.processEarArchive(jpa_ee_propagation_cm_ext_ear, Client.class, earResURL);
        return jpa_ee_propagation_cm_ext_ear;
        }

        @Test
        @Override
        public void test1() throws java.lang.Exception {
            super.test1();
        }

        @Test
        @Override
        public void test2() throws java.lang.Exception {
            super.test2();
        }

        @Test
        @Override
        public void test3() throws java.lang.Exception {
            super.test3();
        }

        @Test
        @Override
        public void test4() throws java.lang.Exception {
            super.test4();
        }

        @Test
        @Override
        public void test5() throws java.lang.Exception {
            super.test5();
        }

        @Test
        @Override
        public void test6() throws java.lang.Exception {
            super.test6();
        }

        @Test
        @Override
        public void test7() throws java.lang.Exception {
            super.test7();
        }

}
scottmarlow commented 1 month ago

Many other test sources handle ear lib correctly for example from platform-tests/src/main/java/ee/jakarta/tck/persistence/jpa22/repeatable/namedstoredprocedurequery/ClientStateful3Test.java:

        // Par
            // the jar with the correct archive name
            JavaArchive jpa_jpa22_repeatable_namedstoredprocedure = ShrinkWrap.create(JavaArchive.class, "jpa_jpa22_repeatable_namedstoredprocedure.jar");
            // The class files
            jpa_jpa22_repeatable_namedstoredprocedure.addClasses(
                ee.jakarta.tck.persistence.jpa22.repeatable.namedstoredprocedurequery.Employee.class
            );
            // The persistence.xml descriptor
            URL parURL = Client.class.getResource("/com/sun/ts/tests/jpa/common/template/modified.persistence.xml");
            if(parURL != null) {
              jpa_jpa22_repeatable_namedstoredprocedure.addAsManifestResource(parURL, "persistence.xml");
            }
            archiveProcessor.processParArchive(jpa_jpa22_repeatable_namedstoredprocedure, Client.class, parURL);
            // The orm.xml file
            parURL = Client.class.getResource("orm.xml");
            if(parURL != null) {
              jpa_jpa22_repeatable_namedstoredprocedure.addAsManifestResource(parURL, "orm.xml");
            }

        // Ear
            EnterpriseArchive jpa_jpa22_repeatable_namedstoredprocedure_vehicles_ear = ShrinkWrap.create(EnterpriseArchive.class, "jpa_jpa22_repeatable_namedstoredprocedure_vehicles.ear");

            // Any libraries added to the ear

            // The component jars built by the package target
            jpa_jpa22_repeatable_namedstoredprocedure_vehicles_ear.addAsModule(jpa_jpa22_repeatable_namedstoredprocedure_stateful3_vehicle_ejb);
            jpa_jpa22_repeatable_namedstoredprocedure_vehicles_ear.addAsModule(jpa_jpa22_repeatable_namedstoredprocedure_stateful3_vehicle_client);

            jpa_jpa22_repeatable_namedstoredprocedure_vehicles_ear.addAsLibrary(jpa_jpa22_repeatable_namedstoredprocedure);
scottmarlow commented 1 month ago

I'm not sure if we have a stg template file for processing the ear lib jars that may or may not have a persistence.xml. For this issue, we are dealing with a test that expects an ear lib jar with a peristence.xml and an (persistence) entity class.

scottmarlow commented 1 month ago

The EE 10 TCK dist/com/sun/ts/tests/jpa/ee/propagation/cm/extended/jpa_ee_propagation_cm_ext.ear contains the test.

scottmarlow commented 1 month ago

@starksm64 which tck-rewrite-ant stg template file should handle an ear lib jar that contains a persistence.xml + some entity classes? Would it be TsEar.stg?

It seems like we are missing adding the code to generate the jar that should of been added to the ear lib. Other tests seem to handle adding the ear lib jar (e.g. platform-tests/src/main/java/ee/jakarta/tck/persistence/jpa22/repeatable/namedstoredprocedurequery/ClientStateful3Test.java was correctly generated I think).

How do we debug or investigate why the code for adding the persistence.xml/entity classes was not generated? We should of created a jpa_ee_propagation_cm_ext JavaArchive but that code didn't get added.

starksm64 commented 1 month ago

How it is supposed to be handled is that libs are collected in the tck.jakarta.platform.ant.Ear POJO associated with the ts.ear task and src/main/resources/TsEar.stg has a genLibJars template that writes out the jar generation. The capture of libs is a little sketchy because it happens outside of the ts.* task usually, and we try to capture them by looking at the actual jar task calls. I'll take a look at this particular jpa case and add a testcase for it.

scottmarlow commented 1 month ago

How it is supposed to be handled is that libs are collected in the tck.jakarta.platform.ant.Ear POJO associated with the ts.ear task and src/main/resources/TsEar.stg has a genLibJars template that writes out the jar generation. The capture of libs is a little sketchy because it happens outside of the ts.* task usually, and we try to capture them by looking at the actual jar task calls. I'll take a look at this particular jpa case and add a testcase for it.

Thanks, I'll try debugging tck.jakarta.platform.ant.Ear with the test case you added.