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:com.argonio.gora.GenerateMojo.java

License:Apache License

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

From source file:com.coderplus.m2e.jaxwscore.CoderPlusBuildParticipant.java

License:Open Source License

@Override
public Set<IProject> build(final int kind, final IProgressMonitor monitor) throws Exception {

    final MojoExecution execution = getMojoExecution();

    if (execution == null) {
        return null;
    }/*from ww  w  .j  a v a  2 s .c o  m*/
    IMaven maven = MavenPlugin.getMaven();
    MavenProject mavenProject = getMavenProjectFacade().getMavenProject();
    final BuildContext buildContext = getBuildContext();
    boolean skip = Boolean.TRUE.equals(maven.getMojoParameterValue(mavenProject, execution, SKIP, Boolean.class,
            new NullProgressMonitor()));
    if (skip) {
        return null;
    }
    File staleFile = maven.getMojoParameterValue(mavenProject, execution, STALE_FILE, File.class,
            new NullProgressMonitor());

    boolean xnocompile = Boolean.TRUE.equals(maven.getMojoParameterValue(mavenProject, execution, XNOCOMPILE,
            Boolean.class, new NullProgressMonitor()));
    boolean keep = Boolean.TRUE.equals(maven.getMojoParameterValue(mavenProject, execution, KEEP, Boolean.class,
            new NullProgressMonitor()));
    File outputDirectory = maven.getMojoParameterValue(mavenProject, execution, OUTPUT_DIRECTORY, File.class,
            new NullProgressMonitor());
    if ((keep || xnocompile) && outputDirectory != null) {
        if (WSIMPORT_TEST.equals(execution.getGoal()) || WSGEN_TEST.equals(execution.getGoal())) {
            mavenProject.addTestCompileSourceRoot(outputDirectory.getAbsolutePath());

        } else {
            mavenProject.addCompileSourceRoot(outputDirectory.getAbsolutePath());
        }
    }

    if (buildContext.isIncremental() && staleFile != null && staleFile.exists()) {
        File wsdlDirectory = maven.getMojoParameterValue(mavenProject, execution, WSDL_DIRECTORY, File.class,
                new NullProgressMonitor());
        File bindingDirectory = maven.getMojoParameterValue(mavenProject, execution, BINDING_DIRECTORY,
                File.class, new NullProgressMonitor());
        Scanner wsdlScanner = buildContext.newScanner(wsdlDirectory);
        Scanner bindingScanner = buildContext.newScanner(bindingDirectory);
        String[] includedBindingFiles = null;
        String[] includedWsdlFiles = null;
        if (bindingScanner != null) {
            bindingScanner.scan();
            includedBindingFiles = bindingScanner.getIncludedFiles();
        }
        if (wsdlScanner != null) {
            wsdlScanner.scan();
            includedWsdlFiles = wsdlScanner.getIncludedFiles();
        }

        if ((includedWsdlFiles == null || includedWsdlFiles.length == 0)
                && (includedBindingFiles == null || includedBindingFiles.length == 0)) {
            //ignore if there were no changes to the resources and was an incremental build
            return null;
        }
    }

    setTaskName(monitor);
    //execute the maven mojo
    final Set<IProject> result = executeMojo(kind, monitor);

    //refresh the output directory
    if (outputDirectory != null && outputDirectory.exists()) {
        buildContext.refresh(outputDirectory);
    }
    return result;
}

From source file:com.nominum.build.RouteCompilerMojo.java

License:Apache License

/** This static method is usable by other Mojos */
public static void compileRoutes(File confDirectory, File outputDir, MavenProject project,
        boolean generateReverseRouter) throws MojoExecutionException {
    project.addCompileSourceRoot(outputDir.getAbsolutePath());

    if (!outputDir.exists()) {
        boolean created = outputDir.mkdirs();
        if (!created)
            throw new MojoExecutionException("Failed to create output directory");
    }// w w w .jav a 2  s .  c  om

    PlayRoutesCompiler routesCompiler = new PlayRoutesCompiler();
    routesCompiler.compile(confDirectory, outputDir, new scala.collection.mutable.ArrayBuffer<String>(),
            generateReverseRouter);
}

From source file:com.nominum.build.TemplateCompilerMojo.java

License:Apache License

/** This static method is usable by other Mojos */
public static void compileTemplates(File outputDir, MavenProject project, File sourceDir, boolean forJava)
        throws MojoExecutionException {
    project.addCompileSourceRoot(outputDir.getAbsolutePath());

    if (!outputDir.exists()) {
        boolean created = outputDir.mkdirs();
        if (!created)
            throw new MojoExecutionException("Failed to create output directory");
    }//from   w ww.ja va  2  s . c o  m

    List<File> classpathFiles = new ArrayList<File>();
    String classpath = System.getProperty("java.class.path");
    for (String path : classpath.split(":")) {
        classpathFiles.add(new File(path));
    }

    TemplateCompiler templateCompiler = new TemplateCompiler(
            JavaConversions.asScalaBuffer(classpathFiles).toList(), forJava);
    templateCompiler.compile(sourceDir, outputDir);
}

From source file:com.sixdegreeshq.sitenav.GeneratorMojo.java

License:Apache License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    try {//  ww  w  .ja va2  s  . com

        MavenProject project = MavenProject.class.cast(getPluginContext().get("project"));

        project.addCompileSourceRoot(outputFolder.getAbsolutePath());

        if (testing) {
            project.addTestCompileSourceRoot(outputFolder.getAbsolutePath());
        } else {
            project.addCompileSourceRoot(outputFolder.getAbsolutePath());
        }

        ClassLoader cl = getProjectClassLoader(project);

        SitenavHandler sitenavHandler = new SitenavHandler();

        SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
        parser.parse(new InputSource(cl.getResourceAsStream(inputResourceLocation)), sitenavHandler);

        File packageDir = new File(outputFolder, outputPackage.replace('.', '/'));
        packageDir.mkdirs();

        if (sitenavHandler.getRoot().getChildren() != null) {
            String pageSB = readResource("/com/sixdegreeshq/sitenav/tpl/Page.tpl");

            String pageContent = pageSB.toString().replace("${packageName}", outputPackage);
            FileOutputStream pageFOS = new FileOutputStream(new File(packageDir, "Page.java"));
            pageFOS.write(pageContent.getBytes());
            pageFOS.close();

            for (Page topLevelNode : sitenavHandler.getRoot().getChildren()) {
                String className = topLevelNode.alias;
                File javaFile = new File(packageDir, className + ".java");
                PrintWriter pw = new PrintWriter(javaFile, "UTF-8");

                String nodeSB = readResource("/com/sixdegreeshq/sitenav/tpl/Node.tpl");
                ;
                String nodeContent = nodeSB.toString().replace("${localeDeclaration}", localeResolutionCode)
                        .replace("${className}", className)
                        .replace("${packageDeclaration}", "package " + outputPackage + ";")
                        .replace("${alias}", className)
                        .replace("${langs}", toString(topLevelNode.getPaths(), true))
                        .replace("${paths}", toString(topLevelNode.getPaths(), false))
                        .replace("${pathsDeclarations}", getDeclarations(topLevelNode.getPaths()))
                        .replace("${classModifier}", "");

                nodeContent = nodeContent.replace("${childrenDeclaration}", navigate(topLevelNode));
                nodeContent = nodeContent.replace("${children}", children(topLevelNode));

                FileOutputStream nodeFOS = new FileOutputStream(new File(packageDir, className + ".java"));
                nodeFOS.write(nodeContent.getBytes());
                nodeFOS.close();
            }
        }

    } catch (Throwable t) {
        t.printStackTrace();
        throw new MojoExecutionException(t.getMessage(), t);
    }

}

From source file:com.undebugged.maven.RouteCompilerMojo.java

License:Apache License

public static void compileRoutes(File confDirectory, File outputDir, MavenProject project)
        throws MojoExecutionException {

    project.addCompileSourceRoot(outputDir.getAbsolutePath());

    if (!outputDir.exists()) {
        boolean created = outputDir.mkdirs();
        if (!created)
            throw new MojoExecutionException("Failed to create output directory");
    }//  w  w w .  j  a  v a 2 s  .c  o  m

    RoutesCompiler routesCompiler = new RoutesCompiler();
    routesCompiler.compile(confDirectory, outputDir, new scala.collection.mutable.ArrayBuffer<String>());
}

From source file:com.undebugged.maven.TemplateCompilerMojo.java

License:Apache License

/** This static method is usable by other Mojos */
public static void compileTemplates(File outputDir, MavenProject project, File sourceDir)
        throws MojoExecutionException {
    project.addCompileSourceRoot(outputDir.getAbsolutePath());

    if (!outputDir.exists()) {
        boolean created = outputDir.mkdirs();
        if (!created) {
            throw new MojoExecutionException("Failed to create output directory");
        }/*from  w w  w .  j  av a 2 s.  com*/
    }

    List<File> classpathFiles = new ArrayList<File>();
    String classpath = System.getProperty("java.class.path");
    for (String path : classpath.split(":")) {
        classpathFiles.add(new File(path));
    }

    TemplateCompiler templateCompiler = new TemplateCompiler(
            JavaConversions.asScalaBuffer(classpathFiles).toList(), true);
    templateCompiler.compile(sourceDir, outputDir);

}

From source file:com.webguys.maven.plugin.st.Template.java

License:Open Source License

private void prepareCompilerSourceRoot(File file, MavenProject project, Log log) {
    String path = file.getPath();
    if (file.getName().endsWith("java") && path.contains("generated-sources")) {
        int index = path.indexOf("generated-sources") + 18;
        index = path.indexOf(File.separator, index);
        String sourceRoot = path.substring(0, index);
        log.info("Adding compile source root: " + sourceRoot);
        project.addCompileSourceRoot(sourceRoot);
    }//www.java  2  s.c  o  m
}

From source file:io.sarl.maven.compiler.CompileMojo.java

License:Apache License

private void compileSARL() throws MojoExecutionException, MojoFailureException {
    final Log log = getLog();
    File outputDirectory = getOutput();
    log.info(Locale.getString(CompileMojo.class, "COMPILING_SARL")); //$NON-NLS-1$
    if (log.isDebugEnabled()) {
        final StringBuilder properties = new StringBuilder();
        buildPropertyString(properties);
        log.debug(properties.toString());
    }//from   w  w  w  .j a  v a2s. c  o m
    // If output is not explicitly set try to read SARL prefs from eclipse .settings folder
    if (getDefaultOutput().equals(getOutput())) {
        final String settingsValue = readSarlEclipseSetting(getProject().getBuild().getSourceDirectory());
        if (settingsValue != null && !settingsValue.isEmpty()) {
            outputDirectory = new File(settingsValue);
            getLog().info(Locale.getString(CompileMojo.class, "OUTPUT_DIR_UPDATE", outputDirectory)); //$NON-NLS-1$
        }
    }
    final MavenProject project = getProject();
    final List<File> compileSourceRoots = new ArrayList<>();
    for (final String filename : project.getCompileSourceRoots()) {
        final File file = new File(filename);
        if (!file.equals(outputDirectory)) {
            compileSourceRoots.add(file);
        }
    }
    final List<File> classPath = getClassPath();
    project.addCompileSourceRoot(outputDirectory.getAbsolutePath());
    compile(classPath, compileSourceRoots, outputDirectory);
}

From source file:net.java.javabuild.SourceFoldersUtils.java

License:Apache License

public static void addSourceFolders(MavenProject project) {
    project.addTestCompileSourceRoot(BuilderFolders.BUILD_SOURCES);
    project.addTestResource(toResource(BuilderFolders.BUILD_RESOURCES, project));
    project.addCompileSourceRoot(BuilderFolders.GENERATED_SOURCES);
    project.addResource(toResource(BuilderFolders.GENERATED_RESOURCES, project));
    project.addTestCompileSourceRoot(BuilderFolders.GENERATED_TEST_SOURCES);
    project.addTestResource(toResource(BuilderFolders.GENERATED_TEST_RESOURCES, project));
}