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

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

Introduction

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

Prototype

public void addCompileSourceRoot(String path) 

Source Link

Usage

From source file:org.onosproject.yangutils.utils.io.impl.YangIoUtils.java

License:Apache License

/**
 * Adds generated source directory to the compilation root.
 *
 * @param source directory/*from   ww w. j a v a2  s .  c  o  m*/
 * @param project current maven project
 * @param context current build context
 */
public static void addToSource(String source, MavenProject project, BuildContext context) {

    project.addCompileSourceRoot(source);
    context.refresh(project.getBasedir());
    log.info("Source directory added to compilation root: " + source);
}

From source file:org.sonar.api.test.MavenTestUtils.java

License:Open Source License

public static MavenProject loadPom(String pomUrlInClasspath) {
    FileReader fileReader = null;
    try {/*from w ww .j a  v a 2 s .  com*/
        File pomFile = new File(MavenTestUtils.class.getResource(pomUrlInClasspath).toURI());
        MavenXpp3Reader pomReader = new MavenXpp3Reader();
        fileReader = new FileReader(pomFile);
        Model model = pomReader.read(fileReader);
        MavenProject project = new MavenProject(model);
        project.setFile(pomFile);
        project.getBuild().setDirectory(pomFile.getParentFile().getPath());
        project.addCompileSourceRoot(pomFile.getParentFile().getPath() + "/src/main/java");
        project.addTestCompileSourceRoot(pomFile.getParentFile().getPath() + "/src/test/java");
        return project;
    } catch (Exception e) {
        throw new SonarException("Failed to read Maven project file : " + pomUrlInClasspath, e);

    } finally {
        IOUtils.closeQuietly(fileReader);
    }
}

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

License:Open Source License

public MavenProject create() {
    File workDir = project.getWorkDir();
    String buildDirectory = workDir.getAbsolutePath() + "/target";
    Properties properties = project.getProperties();

    if (project.getBinaries().size() == 0) {
        project.addBinaryDir(buildDirectory + "/classes");
    }//from w  w w. ja v  a 2  s .c  o  m

    final MavenProject pom = new MavenProject() {
        /**
         * This allows to specify base directory without specifying location of a pom.xml
         */
        @Override
        public File getBasedir() {
            return project.getBaseDir();
        };

        /**
         * This allows to specify project classpath (binaries + libraries).
         */
        @Override
        public List<String> getCompileClasspathElements() throws DependencyResolutionRequiredException {
            List<String> cp = new ArrayList<String>();
            cp.addAll(project.getBinaries());
            cp.addAll(project.getLibraries());
            return cp;
        }
    };

    String key = getPropertyOrDie(properties, CoreProperties.PROJECT_KEY_PROPERTY);
    String[] keys = key.split(":");
    pom.setGroupId(keys[0]);
    pom.setArtifactId(keys[1]);
    pom.setVersion(getPropertyOrDie(properties, CoreProperties.PROJECT_VERSION_PROPERTY));

    pom.setName(properties.getProperty(CoreProperties.PROJECT_NAME_PROPERTY, "Unnamed - " + key));
    pom.setDescription(properties.getProperty(CoreProperties.PROJECT_DESCRIPTION_PROPERTY, ""));

    pom.getModel().setProperties(properties);

    pom.setArtifacts(Collections.EMPTY_SET);

    // Configure fake directories
    pom.getBuild().setDirectory(buildDirectory);
    pom.getBuild().setOutputDirectory(project.getBinaries().get(0));
    Reporting reporting = new Reporting();
    String reportingOutputDirectory = buildDirectory + "/site";
    reporting.setOutputDirectory(reportingOutputDirectory);
    pom.setReporting(reporting);

    // Configure source directories
    for (String dir : project.getSourceDirs()) {
        pom.addCompileSourceRoot(dir);
    }

    // Configure test directories
    for (String dir : project.getTestDirs()) {
        pom.addTestCompileSourceRoot(dir);
    }

    return pom;
}

From source file:ws.epigraph.java.mojo.MainCodegenMojo.java

License:Apache License

@Override
protected Collection<? extends String> getSourceRoots(@NotNull MavenProject project) throws IOException {
    project.addCompileSourceRoot(sourceDirectory.getCanonicalPath());
    return project.getCompileSourceRoots();
}

From source file:ws.epigraph.scala.mojo.MainCodegenMojo.java

License:Apache License

@Override
protected void addGeneratedSourcesToProject(MavenProject project, String path) {
    project.addCompileSourceRoot(path);
}