Example usage for org.eclipse.jdt.apt.core.internal.util FactoryContainer getId

List of usage examples for org.eclipse.jdt.apt.core.internal.util FactoryContainer getId

Introduction

In this page you can find the example usage for org.eclipse.jdt.apt.core.internal.util FactoryContainer getId.

Prototype

public abstract String getId();

Source Link

Document

Returns an ID that is guaranteed to be sufficiently unique for this container -- that is, all necessary state can be reconstructed from just the id and FactoryType.

Usage

From source file:org.jboss.tools.maven.apt.tests.M2eAptProjectconfiguratorTest.java

License:Open Source License

public void testRuntimePluginDependency() throws Exception {

    IProject p = importProject("projects/eclipselink/pom.xml");
    waitForJobsToComplete();/*w w  w .  jav a  2s . c  om*/

    // Import doesn't build, so we trigger it manually
    p.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
    waitForJobsToComplete();

    IJavaProject javaProject = JavaCore.create(p);
    assertNotNull(javaProject);

    assertTrue("Annotation processing is disabled for " + p, AptConfig.isEnabled(javaProject));
    String expectedOutputFolder = "target/generated-sources/annotations";
    IFolder annotationsFolder = p.getFolder(expectedOutputFolder);
    assertTrue(annotationsFolder + " was not generated", annotationsFolder.exists());

    FactoryPath factoryPath = (FactoryPath) AptConfig.getFactoryPath(javaProject);
    String modelGen = "org.eclipse.persistence.jpa.modelgen.processor-2.5.1.jar";
    boolean foundRuntimeDependency = false;
    for (FactoryContainer container : factoryPath.getEnabledContainers().keySet()) {
        if (("M2_REPO/org/eclipse/persistence/org.eclipse.persistence.jpa.modelgen.processor/2.5.1/" + modelGen)
                .equals(container.getId())) {
            foundRuntimeDependency = true;
            break;
        }
    }
    assertTrue(modelGen + " was not found", foundRuntimeDependency);

    /*
    There's an ugly bug in Tycho which makes 
    JavaModelManager.getJavaModelManager().createAnnotationProcessorManager() return null
    as a consequence, no annotation processors are run during Tycho builds
    See http://dev.eclipse.org/mhonarc/lists/tycho-user/msg02344.html
            
    For the time being, only APT configuration can be tested, not APT build outcomes
    */
    if (JavaModelManager.getJavaModelManager().createAnnotationProcessorManager() == null) {
        return;
    }

    IFile generatedFile = p.getFile(expectedOutputFolder + "/foo/bar/Dummy_.java");
    if (!generatedFile.exists()) {
        //APT was triggered during project configuration, i.e. before META-INF/persistence.xml was copied to 
        //target/classes by the maven-resource-plugin build participant. eclipselink modelgen could not find it 
        // and skipped model generation. Pretty annoying and I dunno how to fix that ... yet.

        //Let's check a nudge to Dummy.java fixes this.
        IFile dummy = p.getFile("src/main/java/foo/bar/Dummy.java");
        dummy.touch(monitor);
        p.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
        waitForJobsToComplete();
    }

    assertTrue(generatedFile + " was not generated", generatedFile.exists());
    assertNoErrors(p);
}

From source file:org.jboss.tools.maven.apt.tests.M2eAptProjectconfiguratorTest.java

License:Open Source License

private void defaultTest(String projectName, String expectedOutputFolder) throws Exception {

    IProject p = importProject("projects/" + projectName + "/pom.xml");
    waitForJobsToComplete();//  w  w  w .  ja  v a2 s .c  o  m

    p.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
    waitForJobsToComplete();

    IJavaProject javaProject = JavaCore.create(p);
    assertNotNull(javaProject);

    assertTrue("Annotation processing is disabled for " + p, AptConfig.isEnabled(javaProject));
    IFolder annotationsFolder = p.getFolder(expectedOutputFolder);
    assertTrue(annotationsFolder + " was not generated", annotationsFolder.exists());

    FactoryPath factoryPath = (FactoryPath) AptConfig.getFactoryPath(javaProject);
    Iterator<FactoryContainer> ite = factoryPath.getEnabledContainers().keySet().iterator();
    FactoryContainer jpaModelGen = ite.next();
    assertEquals(FactoryContainer.FactoryType.VARJAR, jpaModelGen.getType());
    assertEquals(
            "M2_REPO/org/hibernate/hibernate-jpamodelgen/1.1.1.Final/hibernate-jpamodelgen-1.1.1.Final.jar",
            jpaModelGen.getId());

    FactoryContainer jpaApi = ite.next();
    assertEquals(FactoryContainer.FactoryType.VARJAR, jpaApi.getType());
    assertEquals(
            "M2_REPO/org/hibernate/javax/persistence/hibernate-jpa-2.0-api/1.0.0.Final/hibernate-jpa-2.0-api-1.0.0.Final.jar",
            jpaApi.getId());

    /*
    There's an ugly bug in Tycho which makes 
    JavaModelManager.getJavaModelManager().createAnnotationProcessorManager() return null
    as a consequence, no annotation processors are run during Tycho builds
    See http://dev.eclipse.org/mhonarc/lists/tycho-user/msg02344.html
            
    For the time being, only APT configuration can be tested, not APT build outcomes
    */
    if (JavaModelManager.getJavaModelManager().createAnnotationProcessorManager() == null) {
        return;
    }

    IFile generatedFile = p.getFile(expectedOutputFolder + "/foo/bar/Dummy_.java");
    assertTrue(generatedFile + " was not generated", generatedFile.exists());
    assertNoErrors(p);
}