Example usage for org.apache.maven.project MavenProject getTestCompileSourceRoots

List of usage examples for org.apache.maven.project MavenProject getTestCompileSourceRoots

Introduction

In this page you can find the example usage for org.apache.maven.project MavenProject getTestCompileSourceRoots.

Prototype

public List<String> getTestCompileSourceRoots() 

Source Link

Usage

From source file:org.sonar.batch.MavenProjectConverter.java

License:Open Source License

public static void synchronizeFileSystem(MavenProject pom, ProjectDefinition into) {
    into.setBaseDir(pom.getBasedir());/*from   ww w.  ja v  a  2s  .  c  om*/
    into.setWorkDir(new File(resolvePath(pom.getBuild().getDirectory(), pom.getBasedir()), "sonar"));
    into.setSourceDirs(
            (String[]) pom.getCompileSourceRoots().toArray(new String[pom.getCompileSourceRoots().size()]));
    into.setTestDirs((String[]) pom.getTestCompileSourceRoots()
            .toArray(new String[pom.getTestCompileSourceRoots().size()]));
}

From source file:org.sonar.batch.scan.maven.MavenProjectConverter.java

License:Open Source License

public static void synchronizeFileSystem(MavenProject pom, ProjectDefinition into) {
    into.setBaseDir(pom.getBasedir());/*w w  w .  j  a  v  a  2  s.c om*/
    File buildDir = resolvePath(pom.getBuild().getDirectory(), pom.getBasedir());
    if (buildDir != null) {
        into.setBuildDir(buildDir);
        into.setWorkDir(new File(buildDir, "sonar"));
    }
    into.setSourceDirs(
            (String[]) pom.getCompileSourceRoots().toArray(new String[pom.getCompileSourceRoots().size()]));
    into.setTestDirs((String[]) pom.getTestCompileSourceRoots()
            .toArray(new String[pom.getTestCompileSourceRoots().size()]));
    File binaryDir = resolvePath(pom.getBuild().getOutputDirectory(), pom.getBasedir());
    if (binaryDir != null) {
        into.addBinaryDir(binaryDir);
    }
}

From source file:org.sonar.batch.scan.maven.MavenProjectConverter.java

License:Open Source License

public static void synchronizeFileSystem(MavenProject pom, DefaultModuleFileSystem into) {
    into.resetDirs(pom.getBasedir(), resolvePath(pom.getBuild().getDirectory(), pom.getBasedir()),
            resolvePaths((List<String>) pom.getCompileSourceRoots(), pom.getBasedir()),
            resolvePaths((List<String>) pom.getTestCompileSourceRoots(), pom.getBasedir()),
            Arrays.asList(resolvePath(pom.getBuild().getOutputDirectory(), pom.getBasedir())));
}

From source file:org.sonar.plugins.maven.MavenProjectConverter.java

License:Open Source License

public static void synchronizeFileSystem(MavenProject pom, ProjectDefinition into) {
    into.setBaseDir(pom.getBasedir());/*from   w  w  w . j ava2 s  .c  om*/
    File buildDir = getBuildDir(pom);
    if (buildDir != null) {
        into.setBuildDir(buildDir);
        into.setWorkDir(getSonarWorkDir(pom));
    }
    List<String> filteredCompileSourceRoots = filterExisting(pom.getCompileSourceRoots(), pom.getBasedir());
    List<String> filteredTestCompileSourceRoots = filterExisting(pom.getTestCompileSourceRoots(),
            pom.getBasedir());
    into.setSourceDirs(
            (String[]) filteredCompileSourceRoots.toArray(new String[filteredCompileSourceRoots.size()]));
    into.setTestDirs((String[]) filteredTestCompileSourceRoots
            .toArray(new String[filteredTestCompileSourceRoots.size()]));
    File binaryDir = resolvePath(pom.getBuild().getOutputDirectory(), pom.getBasedir());
    if (binaryDir != null) {
        into.addBinaryDir(binaryDir);
    }
}

From source file:org.sonar.plugins.maven.MavenProjectConverter.java

License:Open Source License

public static void synchronizeFileSystem(MavenProject pom, DefaultModuleFileSystem into) {
    into.resetDirs(pom.getBasedir(), getBuildDir(pom),
            resolvePaths(pom.getCompileSourceRoots(), pom.getBasedir()),
            resolvePaths(pom.getTestCompileSourceRoots(), pom.getBasedir()),
            Arrays.asList(resolvePath(pom.getBuild().getOutputDirectory(), pom.getBasedir())));
}

From source file:org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter.java

License:Open Source License

private List<File> testSources(MavenProject pom) throws MojoExecutionException {
    return sourcePaths(pom, ScanProperties.PROJECT_TEST_DIRS, pom.getTestCompileSourceRoots());
}

From source file:org.wisdom.maven.utils.MavenUtils.java

License:Apache License

/**
 * Gets the default set of properties for the given project.
 *
 * @param currentProject the project//w  w  w  .  java  2s  .  c o  m
 * @return the set of properties, containing default bundle packaging instructions.
 */
public static Properties getDefaultProperties(MavenProject currentProject) {
    Properties properties = new Properties();
    String bsn = DefaultMaven2OsgiConverter.getBundleSymbolicName(currentProject.getArtifact());

    // Setup defaults
    properties.put(MAVEN_SYMBOLICNAME, bsn);
    properties.put("bundle.file.name",
            DefaultMaven2OsgiConverter.getBundleFileName(currentProject.getArtifact()));
    properties.put(Analyzer.BUNDLE_SYMBOLICNAME, bsn);
    properties.put(Analyzer.IMPORT_PACKAGE, "*");
    properties.put(Analyzer.BUNDLE_VERSION, DefaultMaven2OsgiConverter.getVersion(currentProject.getVersion()));

    header(properties, Analyzer.BUNDLE_DESCRIPTION, currentProject.getDescription());
    StringBuilder licenseText = printLicenses(currentProject.getLicenses());
    if (licenseText != null) {
        header(properties, Analyzer.BUNDLE_LICENSE, licenseText);
    }
    header(properties, Analyzer.BUNDLE_NAME, currentProject.getName());

    if (currentProject.getOrganization() != null) {
        if (currentProject.getOrganization().getName() != null) {
            String organizationName = currentProject.getOrganization().getName();
            header(properties, Analyzer.BUNDLE_VENDOR, organizationName);
            properties.put("project.organization.name", organizationName);
            properties.put("pom.organization.name", organizationName);
        }
        if (currentProject.getOrganization().getUrl() != null) {
            String organizationUrl = currentProject.getOrganization().getUrl();
            header(properties, Analyzer.BUNDLE_DOCURL, organizationUrl);
            properties.put("project.organization.url", organizationUrl);
            properties.put("pom.organization.url", organizationUrl);
        }
    }

    properties.putAll(currentProject.getModel().getProperties());

    for (String s : currentProject.getFilters()) {
        File filterFile = new File(s);
        if (filterFile.isFile()) {
            properties.putAll(PropertyUtils.loadProperties(filterFile));
        }
    }

    properties.putAll(getProperties(currentProject.getModel(), "project.build."));
    properties.putAll(getProperties(currentProject.getModel(), "pom."));
    properties.putAll(getProperties(currentProject.getModel(), "project."));

    properties.put("project.baseDir", currentProject.getBasedir().getAbsolutePath());
    properties.put("project.build.directory", currentProject.getBuild().getDirectory());
    properties.put("project.build.outputdirectory", currentProject.getBuild().getOutputDirectory());

    properties.put("project.source.roots", getArray(currentProject.getCompileSourceRoots()));
    properties.put("project.testSource.roots", getArray(currentProject.getTestCompileSourceRoots()));

    properties.put("project.resources", toString(currentProject.getResources()));
    properties.put("project.testResources", toString(currentProject.getTestResources()));

    return properties;
}

From source file:se.jguru.nazgul.tools.plugin.checkstyle.exec.DefaultCheckstyleExecutor.java

License:Apache License

public CheckstyleResults executeCheckstyle(CheckstyleExecutorRequest request)
        throws CheckstyleExecutorException, CheckstyleException {

    // Checkstyle will always use the context classloader in order
    // to load resources (dtds), so we have to fix it
    // olamy this hack is not anymore needed in Maven 3.x
    ClassLoader checkstyleClassLoader = PackageNamesLoader.class.getClassLoader();
    Thread.currentThread().setContextClassLoader(checkstyleClassLoader);

    if (getLogger().isDebugEnabled()) {
        getLogger().debug("executeCheckstyle start headerLocation : " + request.getHeaderLocation());
    }//from  w  ww.  ja  v a2s.  c o m

    MavenProject project = request.getProject();

    configureResourceLocator(locator, request, null);

    configureResourceLocator(licenseLocator, request, request.getLicenseArtifacts());

    // Config is less critical than License, locator can still be used.
    // configureResourceLocator( configurationLocator, request, request.getConfigurationArtifacts() );

    List<File> files;
    try {
        files = getFilesToProcess(request);
    } catch (IOException e) {
        throw new CheckstyleExecutorException("Error getting files to process", e);
    }

    final String suppressionsFilePath = getSuppressionsFilePath(request);
    FilterSet filterSet = getSuppressionsFilterSet(suppressionsFilePath);

    Checker checker = new Checker();

    // setup classloader, needed to avoid "Unable to get class information for ..." errors
    List<String> classPathStrings = new ArrayList<>();
    List<String> outputDirectories = new ArrayList<>();

    // stand-alone
    Collection<File> sourceDirectories = null;
    Collection<File> testSourceDirectories = request.getTestSourceDirectories();

    // aggregator
    Map<MavenProject, Collection<File>> sourceDirectoriesByProject = new HashMap<>();
    Map<MavenProject, Collection<File>> testSourceDirectoriesByProject = new HashMap<>();

    if (request.isAggregate()) {
        for (MavenProject childProject : request.getReactorProjects()) {
            sourceDirectories = new ArrayList<>(childProject.getCompileSourceRoots().size());
            List<String> compileSourceRoots = childProject.getCompileSourceRoots();
            for (String compileSourceRoot : compileSourceRoots) {
                sourceDirectories.add(new File(compileSourceRoot));
            }
            sourceDirectoriesByProject.put(childProject, sourceDirectories);

            testSourceDirectories = new ArrayList<>(childProject.getTestCompileSourceRoots().size());
            List<String> testCompileSourceRoots = childProject.getTestCompileSourceRoots();
            for (String testCompileSourceRoot : testCompileSourceRoots) {
                testSourceDirectories.add(new File(testCompileSourceRoot));
            }
            testSourceDirectoriesByProject.put(childProject, testSourceDirectories);

            prepareCheckstylePaths(request, childProject, classPathStrings, outputDirectories,
                    sourceDirectories, testSourceDirectories);
        }
    } else {
        sourceDirectories = request.getSourceDirectories();
        prepareCheckstylePaths(request, project, classPathStrings, outputDirectories, sourceDirectories,
                testSourceDirectories);
    }

    final List<URL> urls = new ArrayList<>(classPathStrings.size());

    for (String path : classPathStrings) {
        try {
            urls.add(new File(path).toURL());
        } catch (MalformedURLException e) {
            throw new CheckstyleExecutorException(e.getMessage(), e);
        }
    }

    for (String outputDirectoryString : outputDirectories) {
        try {
            if (outputDirectoryString != null) {
                File outputDirectoryFile = new File(outputDirectoryString);
                if (outputDirectoryFile.exists()) {
                    URL outputDirectoryUrl = outputDirectoryFile.toURL();
                    getLogger().debug("Adding the outputDirectory " + outputDirectoryUrl.toString()
                            + " to the Checkstyle class path");
                    urls.add(outputDirectoryUrl);
                }
            }
        } catch (MalformedURLException e) {
            throw new CheckstyleExecutorException(e.getMessage(), e);
        }
    }

    URLClassLoader projectClassLoader = AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() {
        public URLClassLoader run() {
            return new URLClassLoader(urls.toArray(new URL[urls.size()]), null);
        }
    });

    checker.setClassLoader(projectClassLoader);

    checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());

    if (filterSet != null) {
        checker.addFilter(filterSet);
    }
    Configuration configuration = getConfiguration(request);
    checker.configure(configuration);

    AuditListener listener = request.getListener();

    if (listener != null) {
        checker.addListener(listener);
    }

    if (request.isConsoleOutput()) {
        checker.addListener(request.getConsoleListener());
    }

    CheckstyleCheckerListener checkerListener = new CheckstyleCheckerListener(configuration);
    if (request.isAggregate()) {
        for (MavenProject childProject : request.getReactorProjects()) {
            sourceDirectories = sourceDirectoriesByProject.get(childProject);
            testSourceDirectories = testSourceDirectoriesByProject.get(childProject);
            addSourceDirectory(checkerListener, sourceDirectories, testSourceDirectories,
                    childProject.getResources(), request);
        }
    } else {
        addSourceDirectory(checkerListener, sourceDirectories, testSourceDirectories, request.getResources(),
                request);
    }

    checker.addListener(checkerListener);

    int nbErrors = checker.process(files);

    checker.destroy();

    if (projectClassLoader instanceof Closeable) {
        try {
            ((Closeable) projectClassLoader).close();
        } catch (IOException ex) {
            // Nothing we can do - and not detrimental to the build (save running out of file handles).
            getLogger().info("Failed to close custom Classloader - this indicated a bug in the code.", ex);
        }
    }

    if (request.getStringOutputStream() != null) {
        String message = request.getStringOutputStream().toString().trim();

        if (message.length() > 0) {
            getLogger().info(message);
        }
    }

    if (nbErrors > 0) {
        StringBuilder message = new StringBuilder("There ");
        if (nbErrors == 1) {
            message.append("is");
        } else {
            message.append("are");
        }
        message.append(" ");
        message.append(nbErrors);
        message.append(" error");
        if (nbErrors != 1) {
            message.append("s");
        }
        message.append(" reported by Checkstyle");
        String version = getCheckstyleVersion();
        if (version != null) {
            message.append(" ");
            message.append(version);
        }
        message.append(" with ");
        message.append(request.getConfigLocation());
        message.append(" ruleset.");

        if (request.isFailsOnError()) {
            // TODO: should be a failure, not an error. Report is not meant to
            // throw an exception here (so site would
            // work regardless of config), but should record this information
            throw new CheckstyleExecutorException(message.toString());
        } else {
            getLogger().info(message.toString());
        }
    }

    return checkerListener.getResults();
}

From source file:se.jguru.nazgul.tools.plugin.checkstyle.exec.DefaultCheckstyleExecutor.java

License:Apache License

private List<File> getFilesToProcess(CheckstyleExecutorRequest request) throws IOException {
    StringBuilder excludesStr = new StringBuilder();

    if (StringUtils.isNotEmpty(request.getExcludes())) {
        excludesStr.append(request.getExcludes());
    }//from w ww.j a  v a2  s .  c  om

    String[] defaultExcludes = FileUtils.getDefaultExcludes();
    for (String defaultExclude : defaultExcludes) {
        if (excludesStr.length() > 0) {
            excludesStr.append(",");
        }

        excludesStr.append(defaultExclude);
    }

    Set<File> files = new LinkedHashSet<>();
    if (request.isAggregate()) {
        for (MavenProject project : request.getReactorProjects()) {
            Set<File> sourceDirectories = new LinkedHashSet<>();

            // CompileSourceRoots are absolute paths
            List<String> compileSourceRoots = project.getCompileSourceRoots();
            for (String compileSourceRoot : compileSourceRoots) {
                sourceDirectories.add(new File(compileSourceRoot));
            }

            Set<File> testSourceDirectories = new LinkedHashSet<>();
            // CompileSourceRoots are absolute paths
            List<String> testCompileSourceRoots = project.getTestCompileSourceRoots();
            for (String testCompileSourceRoot : testCompileSourceRoots) {
                testSourceDirectories.add(new File(testCompileSourceRoot));
            }

            addFilesToProcess(request, sourceDirectories, project.getResources(), project.getTestResources(),
                    files, testSourceDirectories);
        }
    } else {
        Collection<File> sourceDirectories = request.getSourceDirectories();
        addFilesToProcess(request, sourceDirectories, request.getResources(), request.getTestResources(), files,
                request.getTestSourceDirectories());
    }

    getLogger().debug("Added " + files.size() + " files to process.");

    return new ArrayList<>(files);
}