Example usage for org.eclipse.jdt.apt.core.internal.util FactoryPath getEnabledContainers

List of usage examples for org.eclipse.jdt.apt.core.internal.util FactoryPath getEnabledContainers

Introduction

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

Prototype

public Map<FactoryContainer, Attributes> getEnabledContainers() 

Source Link

Usage

From source file:org.eclipse.ajdt.internal.core.ajde.CoreCompilerConfiguration.java

License:Open Source License

public String getProcessorPath() {
    // Grab the factory entries from the Java Compiler annotation project properties page
    IJavaProject jp = JavaCore.create(project);
    FactoryPath fp = FactoryPathUtil.getFactoryPath(jp);
    Map<FactoryContainer, FactoryPath.Attributes> containers = fp.getEnabledContainers();
    ArrayList<File> fileList = new ArrayList<File>(containers.size());
    for (Map.Entry<FactoryContainer, FactoryPath.Attributes> entry : containers.entrySet()) {
        FactoryPath.Attributes attr = entry.getValue();
        FactoryContainer fc = entry.getKey();
        if (!attr.runInBatchMode() && fc instanceof JarFactoryContainer) {
            JarFactoryContainer jfc = (JarFactoryContainer) fc;
            fileList.add(jfc.getJarFile());
        }//from   ww  w.  j a  v a 2 s .com
    }
    StringBuilder fcp = new StringBuilder();
    for (File f : fileList) {
        fcp.append(f.getAbsolutePath());
    }
    return fcp.toString();
}

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  .  j a v  a 2s .  c o m*/

    // 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();/*from  w  w w  .  j a v  a 2s .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);
}