List of usage examples for org.eclipse.jdt.apt.core.util AptConfig getProcessorOptions
@Deprecated public static Map<String, String> getProcessorOptions(IJavaProject jproj)
From source file:org.jboss.tools.maven.apt.internal.AbstractAptConfiguratorDelegate.java
License:Open Source License
/** * Configures APT for the specified Maven project. *///from w w w. j a v a 2 s. co m public void configureProject(IProgressMonitor monitor) throws CoreException { IProject eclipseProject = mavenFacade.getProject(); AnnotationProcessorConfiguration configuration = getAnnotationProcessorConfiguration(monitor); if (configuration == null) { return; } // In case the Javaconfigurator was not called yet (eg. maven-processor-plugin being bound to process-sources, // that project configurator runs first) We need to add the Java Nature before setting the APT config. if (!eclipseProject.hasNature(JavaCore.NATURE_ID)) { AbstractProjectConfigurator.addNature(eclipseProject, JavaCore.NATURE_ID, monitor); } File generatedSourcesDirectory = configuration.getOutputDirectory(); // If this project has no valid generatedSourcesDirectory, we have nothing to do if (generatedSourcesDirectory == null) return; IJavaProject javaProject = JavaCore.create(eclipseProject); //The plugin dependencies are added first to the classpath LinkedHashSet<File> resolvedJarArtifacts = new LinkedHashSet<File>(configuration.getDependencies()); // Get the project's dependencies List<Artifact> artifacts = getProjectArtifacts(mavenFacade); resolvedJarArtifacts.addAll(filterToResolvedJars(artifacts)); // Inspect the dependencies to see if any contain APT processors boolean isAnnotationProcessingEnabled = configuration.isAnnotationProcessingEnabled() && containsAptProcessors(resolvedJarArtifacts); // Enable/Disable APT (depends on whether APT processors were found) AptConfig.setEnabled(javaProject, isAnnotationProcessingEnabled); //If no annotation processor is disabled, we can leave. if (!isAnnotationProcessingEnabled) { return; } LOG.debug("Enabling APT support on {}", eclipseProject.getName()); // Configure APT output path File generatedSourcesRelativeDirectory = convertToProjectRelativePath(eclipseProject, generatedSourcesDirectory); String generatedSourcesRelativeDirectoryPath = generatedSourcesRelativeDirectory.getPath(); AptConfig.setGenSrcDir(javaProject, generatedSourcesRelativeDirectoryPath); /* * Add all of the compile-scoped JAR artifacts to a new IFactoryPath (in * addition to the workspace's default entries). * * Please note that--until JDT-APT supports project factory path entries * (as opposed to just JARs)--this will be a bit wonky. Specifically, any * project dependencies will be excluded, but their transitive JAR * dependencies will be included. * * Also note: we add the artifacts in reverse order as * IFactoryPath.addExternalJar(File) adds items to the top of the factory * list. */ List<File> resolvedJarArtifactsInReverseOrder = new ArrayList<File>(resolvedJarArtifacts); Collections.reverse(resolvedJarArtifactsInReverseOrder); IFactoryPath factoryPath = AptConfig.getDefaultFactoryPath(javaProject); IPath m2RepoPath = JavaCore.getClasspathVariable(M2_REPO); for (File resolvedJarArtifact : resolvedJarArtifactsInReverseOrder) { IPath absolutePath = new Path(resolvedJarArtifact.getAbsolutePath()); //reference jars in a portable way if (m2RepoPath != null && m2RepoPath.isPrefixOf(absolutePath)) { IPath relativePath = absolutePath.removeFirstSegments(m2RepoPath.segmentCount()).makeRelative() .setDevice(null); IPath variablePath = new Path(M2_REPO).append(relativePath); factoryPath.addVarJar(variablePath); } else { //fall back on using absolute references. factoryPath.addExternalJar(resolvedJarArtifact); } } Map<String, String> currentOptions = AptConfig.getProcessorOptions(javaProject); Map<String, String> newOptions = configuration.getAnnotationProcessorOptions(); if (!currentOptions.equals(newOptions)) { AptConfig.setProcessorOptions(newOptions, javaProject); } // Apply that IFactoryPath to the project AptConfig.setFactoryPath(javaProject, factoryPath); }
From source file:org.jboss.tools.maven.apt.tests.M2eAptProjectconfiguratorTest.java
License:Open Source License
private IProject testAnnotationProcessorArguments(String projectName, Map<String, String> expectedOptions) throws Exception { IProject p = importProject("projects/" + projectName + "/pom.xml"); waitForJobsToComplete();//from w w w . java 2 s .c o m IJavaProject javaProject = JavaCore.create(p); assertNotNull(javaProject); assertTrue("Annotation processing is disabled for " + projectName, AptConfig.isEnabled(javaProject)); Map<String, String> options = AptConfig.getProcessorOptions(javaProject); for (Map.Entry<String, String> option : expectedOptions.entrySet()) { assertEquals(option.getValue(), options.get(option.getKey())); if (option.getValue() == null) { assertTrue(option.getKey() + " is missing ", options.containsKey(option.getKey())); } } return p; }