/** * Resolve the file to assign as the source of the content frame in the generated documentation. * * <p>Tries to resolve the main source and defaults to a blank page if not found. * * @return The path to the page to use in the generated documentation. */ @SuppressWarnings("unchecked") protected String getContentFrameSource() { File mainSourceFile = SourceFileResolver.resolveSourceFile( project.getCompileSourceRoots(), null, project.getGroupId(), project.getArtifactId()); return (mainSourceFile == null) ? "about:blank" : mainSourceFile.getName() + ".html"; }
private void copySourceFilesToTargetDir() throws IOException { for (String src : (List<String>) project.getCompileSourceRoots()) { File srcDir = new File(src); FileUtils.copyDirectory(srcDir, new File(target, srcDir.getName())); } File srcDir = new File(project.getBuild().getDirectory(), "classes"); FileUtils.copyDirectoryStructure(srcDir, new File(target, "classes")); srcDir = new File(project.getBuild().getDirectory(), "gen-mvn"); FileUtils.copyDirectoryStructure(srcDir, new File(target, "classes")); }
@Override protected Iterator<File> getSourceFiles() { ArrayList<File> files = new ArrayList<File>(); @SuppressWarnings("unchecked") final Iterator<String> i = project.getCompileSourceRoots().iterator(); // FELIX-509: check for excludes String[] includes = new String[] {"**/*.java"}; if (includeString != null) { includes = StringUtils.split(includeString, ","); } final String[] excludes; if (excludeString != null) { excludes = StringUtils.split(excludeString, ","); } else { excludes = null; } while (i.hasNext()) { final String tree = i.next(); final File directory = new File(tree); if (!directory.exists()) { this.log.warn("Source tree does not exist. Ignoring " + tree); continue; } this.log.debug("Scanning source tree " + tree); final DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir(directory); if (excludes != null && excludes.length > 0) { scanner.setExcludes(excludes); } scanner.addDefaultExcludes(); scanner.setIncludes(includes); scanner.scan(); for (String fileName : scanner.getIncludedFiles()) { files.add(new File(directory, fileName)); } } return files.iterator(); }
@Test public void testLoadIncludesWithEmptyChanges() throws MojoExecutionException { final List<String> changedFiles = Collections.emptyList(); JacocoReportChangesMojo mojo = new JacocoReportChangesMojo() { @Override public List<String> loadChangedFiles(String branchName) throws MojoExecutionException { return changedFiles; } }; MavenProject project = mock(MavenProject.class); when(project.getCompileSourceRoots()).thenReturn(Arrays.asList("src/main/java")); when(project.getBasedir()).thenReturn(new File(System.getProperty("user.dir"))); mojo.setProject(project); List<String> result = mojo.loadIncludes(); assertEquals(1, result.size()); assertEquals("", result.get(0)); }
protected void generateDescriptor(String scope, File outputFile) throws MojoExecutionException { ExtractorConfiguration ec = new ExtractorConfiguration(); try { if (scope.equals(COMPILE_SCOPE)) { ec.classpath = mavenProject.getCompileClasspathElements(); ec.outputDirectory = new File(mavenProject.getBuild().getOutputDirectory()); ec.sourceDirectories = mavenProject.getCompileSourceRoots(); } else if (scope.equals(TEST_SCOPE)) { ec.classpath = mavenProject.getTestClasspathElements(); ec.outputDirectory = new File(mavenProject.getBuild().getTestOutputDirectory()); ec.sourceDirectories = mavenProject.getTestCompileSourceRoots(); } metadataGenerator.generateDescriptor(ec, outputFile); } catch (Exception e) { throw new MojoExecutionException("Error generating metadata: ", e); } }
@Test public void testLoadIncludes() throws MojoExecutionException { final List<String> changedFiles = Arrays.asList("src/main/java/a/A.java", "src/test/java/a/B.java", "src/main/java/a/C.txt"); JacocoReportChangesMojo mojo = new JacocoReportChangesMojo() { @Override public List<String> loadChangedFiles(String branchName) throws MojoExecutionException { return changedFiles; } }; MavenProject project = mock(MavenProject.class); when(project.getCompileSourceRoots()).thenReturn(Arrays.asList("src/main/java")); when(project.getBasedir()).thenReturn(new File(System.getProperty("user.dir"))); mojo.setProject(project); assertEquals( Arrays.asList("a" + System.getProperty("file.separator") + "A" + CLASS_SUFFIX), mojo.loadIncludes()); }
@NotNull private MavenServerExecutionResult createExecutionResult( File file, MavenExecutionResult result, DependencyNode rootNode) throws RemoteException { Collection<MavenProjectProblem> problems = MavenProjectProblem.createProblemsList(); THashSet<MavenId> unresolvedArtifacts = new THashSet<MavenId>(); validate(file, result.getExceptions(), problems, unresolvedArtifacts); MavenProject mavenProject = result.getMavenProject(); if (mavenProject == null) return new MavenServerExecutionResult(null, problems, unresolvedArtifacts); MavenModel model = MavenModelConverter.convertModel( mavenProject.getModel(), mavenProject.getCompileSourceRoots(), mavenProject.getTestCompileSourceRoots(), mavenProject.getArtifacts(), (rootNode == null ? Collections.emptyList() : rootNode.getChildren()), mavenProject.getExtensionArtifacts(), getLocalRepositoryFile()); RemoteNativeMavenProjectHolder holder = new RemoteNativeMavenProjectHolder(mavenProject); try { UnicastRemoteObject.exportObject(holder, 0); } catch (RemoteException e) { throw new RuntimeException(e); } Collection<String> activatedProfiles = collectActivatedProfiles(mavenProject); MavenServerExecutionResult.ProjectData data = new MavenServerExecutionResult.ProjectData( model, MavenModelConverter.convertToMap(mavenProject.getModel()), holder, activatedProfiles); return new MavenServerExecutionResult(data, problems, unresolvedArtifacts); }
/** * Create an eclipse launch configuration file for the specified test * * @param test the GWTTestCase * @param testSrc the source directory where the test lives * @throws MojoExecutionException some error occured */ private void createLaunchConfigurationForGwtTestCase(File testSrc, String test) throws MojoExecutionException { File testFile = new File(testSrc, test); String fqcn = test.replace(File.separatorChar, '.').substring(0, test.lastIndexOf('.')); File launchFile = new File(getProject().getBasedir(), fqcn + ".launch"); if (launchFile.exists() && launchFile.lastModified() > testFile.lastModified()) { return; } Configuration cfg = new Configuration(); cfg.setClassForTemplateLoading(EclipseTestMojo.class, ""); Map<String, Object> context = new HashMap<String, Object>(); List<String> sources = new LinkedList<String>(); sources.addAll(executedProject.getTestCompileSourceRoots()); sources.addAll(executedProject.getCompileSourceRoots()); context.put("sources", sources); context.put("test", fqcn); int basedir = getProject().getBasedir().getAbsolutePath().length(); context.put("out", testOutputDirectory.getAbsolutePath().substring(basedir + 1)); context.put("extraJvmArgs", getExtraJvmArgs()); context.put("project", eclipseUtil.getProjectName(getProject())); try { // context.put( "gwtDevJarPath", getGwtDevJar().getAbsolutePath() ); Writer configWriter = WriterFactory.newXmlWriter(launchFile); Template template = cfg.getTemplate("test-launch.fm", "UTF-8"); template.process(context, configWriter); configWriter.flush(); configWriter.close(); getLog().info("Write launch configuration for GWT test : " + launchFile.getAbsolutePath()); } catch (IOException ioe) { throw new MojoExecutionException("Unable to write launch configuration", ioe); } catch (TemplateException te) { throw new MojoExecutionException("Unable to merge freemarker template", te); } }
@SuppressWarnings("unchecked") private void executeWithExceptionsHandled() throws Exception { if (outputDirectory == null) { outputDirectory = getDefaultOutputDirectory(); } ensureOutputDirectoryExists(); addOutputToSourcesIfNeeded(); JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null); final String includesString = (includes == null || includes.length == 0) ? "**/*.java" : StringUtils.join(includes, ","); final String excludesString = (excludes == null || excludes.length == 0) ? null : StringUtils.join(excludes, ","); List<File> filesToCompile = new ArrayList<File>(100); for (Object sourceDirectory : project.getCompileSourceRoots()) { File directory = new File((String) sourceDirectory); if (directory.exists()) { if (!directory.equals(outputDirectory)) { filesToCompile.addAll(FileUtils.getFiles(directory, includesString, excludesString)); } } } if (filesToCompile.isEmpty()) { getLog().warn("no source file(s) detected! processor compilationTask will be skipped!"); return; } List<String> options = new ArrayList<String>(10); options.add("-cp"); options.add(buildCompileClasspath()); options.add("-proc:only"); String processor = buildProcessor(); if (processor != null) { options.add("-processor"); options.add(processor); } else { getLog().info("No processors specified. Using default discovery mechanism."); } options.add("-d"); options.add(getOutputClassDirectory().getPath()); options.add("-s"); options.add(outputDirectory.getPath()); if (encoding != null) { options.add("-encoding"); options.add(encoding); } addCompilerArguments(options); setSystemProperties(); CompilationTask compilationTask = compiler.getTask( new PrintWriter(System.out), fileManager, createDiagnosticListener(), options, null, fileManager.getJavaFileObjectsFromFiles(filesToCompile)); // Perform the compilation compilationTask. if (!compilationTask.call()) { throw new Exception( "An error ocurred while the DevKit was generating Java code. Check the logs for further details."); } }