List of usage examples for org.apache.commons.attributes.compiler AttributeCompiler execute
public void execute() throws BuildException
From source file:org.codehaus.mojo.commons.attributes.AbstractCommonsAttributeMojo.java
public void execute(String sourcePath, File outputDirectory, Set includes, Set excludes) throws MojoExecutionException { File sourceDirectory = new File(sourcePath); if (!shouldExecute(sourceDirectory)) { return;//w w w . j av a 2 s. c o m } outputDirectory.mkdirs(); Project antProject = new Project(); AttributeCompiler compiler = new AttributeCompiler(); compiler.setProject(antProject); compiler.setDestdir(outputDirectory); /* setting includes / excludes */ FileSet fs = new FileSet(); fs.setIncludes(includes.isEmpty() ? "**/*.java" : setToFileSet(includes)); if (!excludes.isEmpty()) { fs.setExcludes(setToFileSet(excludes)); } fs.setDir(sourceDirectory); compiler.addFileset(fs); compiler.execute(); }
From source file:org.springframework.metadata.commons.CommonsAttributeCompilerUtils.java
public static void ideAttributeCompile(String testWildcards) { System.out.println("Compiling attributes under IDE"); Project project = new Project(); //URL markerUrl = CommonsAttributeCompilerUtils.class.getResource(MARKER_FILE); //File markerFile = new File(markerUrl.getFile()); // we know marker is in /target/test-classes File root = new File("./"); project.setBaseDir(root);//from w ww.j a va2s .c om project.init(); AttributeCompiler commonsAttributesCompiler = new AttributeCompiler(); commonsAttributesCompiler.setProject(project); //commonsAttributesCompiler.setSourcepathref("test"); String tempPath = "target/generated-commons-attributes-src"; commonsAttributesCompiler.setDestdir(new File(tempPath)); FileSet fileset = new FileSet(); fileset.setDir(new File(root.getPath() + File.separator + "test")); String attributeClasses = testWildcards; fileset.setIncludes(attributeClasses); commonsAttributesCompiler.addFileset(fileset); commonsAttributesCompiler.execute(); System.out.println( "Compiling Java sources generated by Commons Attributes using Javac: requires tools.jar on Eclipse project classpath"); // We now have the generated Java source: compile it. // This requires Javac on the source path Javac javac = new Javac(); javac.setProject(project); //project.setCoreLoader(Thread.currentThread().getContextClassLoader()); Path path = new Path(project, tempPath); javac.setSrcdir(path); // Couldn't get this to work: trying to use Eclipse //javac.setCompiler("org.eclipse.jdt.core.JDTCompilerAdapter"); File destDir = new File(root.getPath() + File.separator + "target/test-classes"); if (!destDir.exists()) { destDir.mkdir(); } javac.setDestdir(destDir); javac.setIncludes(attributeClasses); javac.execute(); }