/** * Produces the {@link JavaDocBuilder} used to analyze classes and source files. * * @param parent parent classloader * @return The {@link JavaDocBuilder} used to analyze classes and source files. * @throws MojoExecutionException If we fail to produce the {@link JavaDocBuilder}. (Fail early.) */ private JavaDocBuilder createJavaDocBuilder(ClassLoader parent) throws MojoExecutionException { JavaDocBuilder builder = new JavaDocBuilder(); builder.addSourceTree(new File(project.getBuild().getSourceDirectory())); // Quick and dirty hack for adding Classloaders with the definitions of // classes the sources depend upon. try { URLClassLoader loader = getProjectClassLoader(parent); builder.getClassLibrary().addClassLoader(loader); } catch (InvalidDependencyVersionException idve) { idve.printStackTrace(); } catch (MalformedURLException e) { throw new MojoExecutionException("Malformed artifact URLs.", e); } return builder; }
/** Creates summary of the run */ public void generateReport(List<XmlSuite> xml, List<ISuite> suites, String outdir) { try { m_out = createWriter(outdir); } catch (IOException e) { L.error("output file", e); return; } ConfigReader cr = ConfigReader.getInstance(); builder.setEncoding(cr.getSrouceCodeEncoding()); builder.addSourceTree(new File(cr.getSourceCodeDir())); startHtml(m_out); generateSuiteSummaryReport(suites); testIds.clear(); generateMethodSummaryReport(suites); testIds.clear(); generateMethodDetailReport(suites); testIds.clear(); endHtml(m_out); m_out.flush(); m_out.close(); }
public void processSources( File[] sourceDirectories, File outputFile, boolean containerDescriptor, ComponentDescriptor[] roleDefaults) throws ComponentDescriptorCreatorException { // ---------------------------------------------------------------------- // Check and register all directories to scan // ---------------------------------------------------------------------- JavaSource[] javaSources; JavaDocBuilder builder = new JavaDocBuilder(); getLogger().debug("Source directories: "); for (int it = 0; it < sourceDirectories.length; it++) { File sourceDirectory = sourceDirectories[it]; if (!sourceDirectory.isDirectory()) { getLogger() .debug( "Specified source directory isn't a directory: " + "'" + sourceDirectory.getAbsolutePath() + "'."); } getLogger().debug(" - " + sourceDirectory.getAbsolutePath()); builder.addSourceTree(sourceDirectory); } // ---------------------------------------------------------------------- // Scan the sources // ---------------------------------------------------------------------- javaSources = builder.getSources(); Map defaultsByRole = new HashMap(); if (roleDefaults != null) { for (int i = 0; i < roleDefaults.length; i++) { // TODO: fail if role is null defaultsByRole.put(roleDefaults[i].getRole(), roleDefaults[i]); } } List componentDescriptors = new ArrayList(); for (int i = 0; i < javaSources.length; i++) { JavaClass javaClass = getJavaClass(javaSources[i]); ComponentDescriptor componentDescriptor = gleaner.glean(builder, javaClass); if (componentDescriptor != null && !javaClass.isAbstract()) { // TODO: better merge, perhaps pass it into glean as the starting point instead if (defaultsByRole.containsKey(componentDescriptor.getRole())) { ComponentDescriptor desc = (ComponentDescriptor) defaultsByRole.get(componentDescriptor.getRole()); if (componentDescriptor.getInstantiationStrategy() == null) { componentDescriptor.setInstantiationStrategy(desc.getInstantiationStrategy()); } } componentDescriptors.add(componentDescriptor); } } ComponentSetDescriptor componentSetDescriptor = new ComponentSetDescriptor(); componentSetDescriptor.setComponents(componentDescriptors); // ---------------------------------------------------------------------- // Convert the Maven dependencies to Plexus component dependencies // ---------------------------------------------------------------------- // List componentDependencies = convertDependencies( mavenProject.getDependencies() ); // // componentSetDescriptor.setDependencies( componentDependencies ); // TODO: for now componentSetDescriptor.setDependencies(Collections.EMPTY_LIST); // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- validateConfiguration(componentSetDescriptor); // ---------------------------------------------------------------------- // Write out the component descriptor // ---------------------------------------------------------------------- if (componentDescriptors.size() == 0 && componentSetDescriptor.getDependencies().size() == 0) { getLogger().debug("No components or dependencies found, not writing components.xml"); return; } File parentFile = outputFile.getParentFile(); if (!parentFile.exists()) { if (!parentFile.mkdirs()) { throw new ComponentDescriptorCreatorException( "Could not make parent directory: '" + parentFile.getAbsolutePath() + "'."); } } try { FileWriter writer = new FileWriter(outputFile); XMLWriter w = new PrettyPrintXMLWriter(writer); w.startElement(containerDescriptor ? "plexus" : "component-set"); writeComponents(w, componentDescriptors); writeDependencies(w, componentSetDescriptor); w.endElement(); writer.write(LS); writer.close(); } catch (PlexusConfigurationException e) { throw new ComponentDescriptorCreatorException( "Internal error while writing out the configuration", e); } catch (IOException e) { throw new ComponentDescriptorCreatorException( "Error while writing the component descriptor to: " + "'" + outputFile.getAbsolutePath() + "'.", e); } }
/** * Adds a source tree to the builder. * * @param srcDir the source tree to getJavaMethods */ public QDoxParser(final String srcDir) { m_builder.addSourceTree(new File(srcDir)); }