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

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

Introduction

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

Prototype

public File getBasedir() 

Source Link

Usage

From source file:org.lib4j.maven.mojo.FileSetMojo.java

License:Open Source License

private static LinkedHashSet<URL> getFiles(final MavenProject project, final List<Resource> projectResources,
        final FileSetMojo fileSet) throws MalformedURLException {
    final LinkedHashSet<URL> urls = new LinkedHashSet<>();
    for (final Resource projectResource : projectResources) {
        final File dir = new File(projectResource.getDirectory());
        final List<File> xmlFiles = Files.listAll(dir, FileSetMojo.filter(project.getBasedir(), fileSet));
        if (xmlFiles != null)
            for (final File file : xmlFiles)
                urls.add(file.toURI().toURL());
    }// www. j  a  v a2 s. c  om

    return urls;
}

From source file:org.lib4j.maven.mojo.Specification.java

License:Open Source License

private static Specification parse(final Xpp3Dom manifest, final MavenProject project)
        throws MojoFailureException {
    if (manifest == null)
        throw new MojoFailureException("Manifest is required");

    File destDir = null;//w ww . j av a 2 s .  com
    final LinkedHashSet<URL> resources = new LinkedHashSet<>();
    boolean overwrite = true;

    try {
        for (int j = 0; j < manifest.getChildCount(); j++) {
            final Xpp3Dom element = manifest.getChild(j);
            if ("destDir".equals(element.getName())) {
                destDir = Paths.isAbsolute(element.getValue()) ? new File(element.getValue())
                        : new File(project.getBasedir(), element.getValue());
                for (final String attribute : element.getAttributeNames()) {
                    if (attribute.endsWith("overwrite"))
                        overwrite = Boolean.parseBoolean(element.getAttribute(attribute));
                }
            } else if ("resources".equals(element.getName())) {
                for (int k = 0; k < element.getChildCount(); k++) {
                    final Xpp3Dom schema = element.getChild(k);
                    if ("resource".equals(schema.getName())) {
                        resources.add(buildURL(project.getFile().getParentFile().getAbsoluteFile(),
                                schema.getValue()));
                    }
                }
            }
        }
    } catch (final IOException e) {
        throw new MojoFailureException(e.getMessage(), e);
    }

    if (destDir == null)
        throw new MojoFailureException("Manifest.destDir is required");

    return new Specification(overwrite, destDir, resources);
}

From source file:org.mobicents.maven.plugin.EclipseMojo.java

License:Open Source License

/**
 * Retrieves any additional source directories which are defined within the andromda-multi-source-plugin.
 *
 * @param project the maven project from which to retrieve the extra source directories.
 * @return the list of extra source directories.
 *//*from   w  ww  .j a  v a2s  . c  o m*/
private List getExtraSourceDirectories(final MavenProject project) {
    final List sourceDirectories = new ArrayList();
    final Build build = project.getBuild();
    if (build != null) {
        final PluginManagement pluginManagement = build.getPluginManagement();
        if (pluginManagement != null && !pluginManagement.getPlugins().isEmpty()) {
            Plugin multiSourcePlugin = null;
            for (final Iterator iterator = pluginManagement.getPlugins().iterator(); iterator.hasNext();) {
                final Plugin plugin = (Plugin) iterator.next();
                if (MULTI_SOURCE_PLUGIN_ARTIFACT_ID.equals(plugin.getArtifactId())) {
                    multiSourcePlugin = plugin;
                    break;
                }
            }
            final Xpp3Dom configuration = this.getConfiguration(multiSourcePlugin);
            if (configuration != null && configuration.getChildCount() > 0) {
                final Xpp3Dom directories = configuration.getChild(0);
                if (directories != null) {
                    final int childCount = directories.getChildCount();
                    if (childCount > 0) {
                        final String baseDirectory = PathNormalizer
                                .normalizePath(ObjectUtils.toString(project.getBasedir()) + '/');
                        final Xpp3Dom[] children = directories.getChildren();
                        for (int ctr = 0; ctr < childCount; ctr++) {
                            final Xpp3Dom child = children[ctr];
                            if (child != null) {
                                String directoryValue = PathNormalizer.normalizePath(child.getValue());
                                if (directoryValue != null) {
                                    if (!directoryValue.startsWith(baseDirectory)) {
                                        directoryValue = PathNormalizer
                                                .normalizePath(baseDirectory + directoryValue.trim());
                                    }
                                    sourceDirectories.add(directoryValue);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return sourceDirectories;
}

From source file:org.mobicents.maven.plugin.utils.ProjectUtils.java

License:Open Source License

/**
 * Attempts to retrieve the Maven project for the given <code>pom</code>.
 *
 * @param pom the POM to find./*from w w w .j  a  va  2s  . c  om*/
 * @return the maven project with the matching POM.
 */
private static MavenProject getProjectFromSession(final MavenSession session, final File pom) {
    MavenProject foundProject = null;
    for (final Iterator projectIterator = session.getSortedProjects().iterator(); projectIterator.hasNext();) {
        final MavenProject project = (MavenProject) projectIterator.next();
        final File projectPom = new File(project.getBasedir(), POM_FILE);
        if (projectPom.equals(pom)) {
            foundProject = project;
        }
    }
    return foundProject;
}

From source file:org.nanoko.coffee.mill.mojos.others.WatchMojo.java

License:Apache License

private void setupMonitor(MavenProject project) throws FileSystemException {
    File baseDir = project.getBasedir();
    getLog().info("Set up file monitor on " + baseDir);
    FileSystemManager fsManager = VFS.getManager();
    FileObject dir = fsManager.resolveFile(baseDir.getAbsolutePath());

    DefaultFileMonitor fm = new DefaultFileMonitor(this);
    fm.setRecursive(true);//from w  w  w .j a  v a2s  .co m
    fm.addFile(dir);
    fm.start();
}

From source file:org.nanoko.coffee.mill.utils.JasmineUtils.java

License:Apache License

public static void prepareJasmineMojo(AbstractCoffeeMillMojo mill, AbstractJasmineMojo mojo,
        List<String> aggregation) {
    MavenProject project = mill.project;
    mojo.setLog(mill.getLog());//from   w  ww  .j a  va2 s .co  m
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "jsSrcDir",
            new File(project.getBasedir(), "src/main/coffee")); //TODO This should be configurable.
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "jsTestSrcDir",
            new File(project.getBasedir(), "src/test/js")); //TODO This should be configurable.
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "webDriverClassName",
            "org.openqa.selenium.htmlunit.HtmlUnitDriver"); //TODO This should be configurable.
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "browserVersion", "FIREFOX_3"); //TODO This should be configurable.
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "format", "documentation"); //TODO This should be configurable.
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "jasmineTargetDir",
            new File(project.getBuild().getDirectory(), "jasmine"));
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "specDirectoryName", "spec");
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "srcDirectoryName", "src");
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "manualSpecRunnerHtmlFileName",
            "ManualSpecRunner.html");
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "specRunnerHtmlFileName", "SpecRunner.html");
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "junitXmlReportFileName", TEST_JASMINE_XML);
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "mavenProject", project);
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "specRunnerTemplate", "DEFAULT");
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "haltOnFailure", true);

    List<String> deps = new ArrayList<String>();
    for (Dependency dep : (Collection<Dependency>) project.getDependencies()) {
        if ("js".equals(dep.getType())) {
            String filename = dep.getArtifactId() + ".js";
            if (dep.getClassifier() != null && !dep.getClassifier().equals("min")) {
                filename = dep.getArtifactId() + "-" + dep.getClassifier() + ".js";
            }
            File file = new File(mill.getLibDirectory(), filename);

            if (!file.exists()) {
                mill.getLog().error("Cannot preload " + dep.getArtifactId() + ":" + dep.getVersion() + " : "
                        + file.getAbsolutePath() + " not found");
            } else {
                try {
                    FileUtils.copyFileToDirectory(file, getJasmineDirectory(project));
                } catch (IOException e) {
                    e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
                }
                deps.add(filename);
            }
        }
    }
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "preloadSources", deps);

    // If javaScriptAggregation is set, use the right order.
    if (aggregation != null) {
        InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "sourceIncludes", aggregation);
    }

    // TODO Parameter.
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "timeout", 300);

}

From source file:org.nanoko.coffeemill.utils.JasmineUtils.java

License:Apache License

public static void prepareJasmineMojo(AbstractCoffeeMillMojo mill, AbstractJasmineMojo mojo,
        List<String> aggregation) {
    MavenProject project = mill.project;
    mojo.setLog(mill.getLog());/*from w w  w. j a  v  a 2 s .  c  om*/
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "jsSrcDir",
            new File(project.getBasedir(), "src/main/coffee"));
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "jsTestSrcDir",
            new File(project.getBasedir(), "src/test/js"));
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "webDriverClassName",
            "org.openqa.selenium.htmlunit.HtmlUnitDriver");
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "browserVersion", "FIREFOX_3");
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "format", "documentation");
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "jasmineTargetDir",
            new File(project.getBuild().getDirectory(), "jasmine"));
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "specDirectoryName", "spec");
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "srcDirectoryName", "src");
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "manualSpecRunnerHtmlFileName",
            "ManualSpecRunner.html");
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "specRunnerHtmlFileName", "SpecRunner.html");
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "junitXmlReportFileName", TEST_JASMINE_XML);
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "mavenProject", project);
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "specRunnerTemplate", "DEFAULT");
    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "haltOnFailure", true);

    Collection<File> files = FileUtils.listFiles(mill.getLibDirectory(), new String[] { "js" }, true);

    if (files.isEmpty()) {
        mill.getLog().warn(
                "JavaScript sources directory " + mill.getLibDirectory().getAbsolutePath() + " is empty !");
        return;
    }

    List<String> deps = new ArrayList<String>();
    for (File file : files) {
        try {
            FileUtils.copyFileToDirectory(file, getJasmineDirectory(project));
        } catch (IOException e) {
            mill.getLog().error("Error during copy files to Jasmine directory "
                    + getJasmineDirectory(project).getAbsolutePath(), e);
        }
        deps.add(file.getName());
    }

    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "preloadSources", deps);

    // If javaScriptAggregation is set, use the right order.
    if (aggregation != null) {
        InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "sourceIncludes", aggregation);
    }

    InjectionHelper.inject(mojo, AbstractJasmineMojo.class, "timeout", 300);// TODO Parameter.

}

From source file:org.novelang.maven.SourceAggregatorMojo.java

License:Open Source License

private static File findParentRoot(final MavenProject project) {
    MavenProject maybeRoot = project;
    while (true) {
        final MavenProject parent = maybeRoot.getParent();
        if (parent == null) {
            break;
        } else {// w w w  .j  a  v a  2s .  co  m
            maybeRoot = parent;
        }
    }
    return maybeRoot.getBasedir();
}

From source file:org.onos.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl.java

License:Open Source License

@Override
public void setMavenProject(final MavenProject project) {
    this.mavenProject = project;
    this.projectBaseDir = project.getBasedir();
}

From source file:org.onos.yangtools.yang2sources.plugin.ConfigArg.java

License:Open Source License

public File getOutputBaseDir(MavenProject project) {
    if (outputBaseDir == null) {
        return null;
    }/*  w ww.  jav  a  2 s  .co  m*/
    if (outputBaseDir.isAbsolute()) {
        return outputBaseDir;
    } else {
        return new File(project.getBasedir(), outputBaseDir.getPath());
    }
}