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:aQute.bnd.maven.plugin.BndMavenPlugin.java

License:Open Source License

private File loadProjectProperties(Builder builder, MavenProject project) throws Exception {
    // Load parent project properties first
    MavenProject parentProject = project.getParent();
    if (parentProject != null) {
        loadProjectProperties(builder, parentProject);
    }//  w ww . j  a  v  a2  s .co  m

    // Merge in current project properties
    Xpp3Dom configuration = project.getGoalConfiguration("biz.aQute.bnd", "bnd-maven-plugin",
            mojoExecution.getExecutionId(), mojoExecution.getGoal());
    File baseDir = project.getBasedir();
    if (baseDir != null) { // file system based pom
        File pomFile = project.getFile();
        builder.updateModified(pomFile.lastModified(), "POM: " + pomFile);
        // check for bnd file
        String bndFileName = Project.BNDFILE;
        if (configuration != null) {
            Xpp3Dom bndfileElement = configuration.getChild("bndfile");
            if (bndfileElement != null) {
                bndFileName = bndfileElement.getValue();
            }
        }
        File bndFile = IO.getFile(baseDir, bndFileName);
        if (bndFile.isFile()) {
            logger.debug("loading bnd properties from file: {}", bndFile);
            // we use setProperties to handle -include
            builder.setProperties(bndFile.getParentFile(), builder.loadProperties(bndFile));
            return bndFile;
        }
        // no bnd file found, so we fall through
    }
    // check for bnd-in-pom configuration
    if (configuration != null) {
        Xpp3Dom bndElement = configuration.getChild("bnd");
        if (bndElement != null) {
            logger.debug("loading bnd properties from bnd element in pom: {}", project);
            UTF8Properties properties = new UTF8Properties();
            properties.load(bndElement.getValue(), project.getFile(), builder);
            if (baseDir != null) {
                String here = baseDir.toURI().getPath();
                here = Matcher.quoteReplacement(here.substring(0, here.length() - 1));
                properties = properties.replaceAll("\\$\\{\\.\\}", here);
            }
            // we use setProperties to handle -include
            builder.setProperties(baseDir, properties);
        }
    }
    return project.getFile();
}

From source file:at.nonblocking.maven.nonsnapshot.impl.ModuleTraverserDefaultImpl.java

License:Apache License

@Override
public List<Model> findAllModules(MavenProject baseProject, List<Profile> activeProfiles) {
    LOG.info("Scanning for Maven modules... Active profiles: {}", activeProfiles);

    List<Model> modelList = new ArrayList<>();
    recursiveFindModules(baseProject.getBasedir(), modelList, activeProfiles);
    return modelList;
}

From source file:br.com.anteros.restdoc.maven.plugin.util.ResourceResolver.java

License:Apache License

private static List<JavadocBundle> resolveBundleFromProject(SourceResolverConfig config, MavenProject project,
        Artifact artifact) throws IOException {
    List<JavadocBundle> bundles = new ArrayList<JavadocBundle>();

    List<String> classifiers = new ArrayList<String>();
    if (config.includeCompileSources()) {
        classifiers.add(AbstractJavadocMojo.JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER);
    }//from   w w w.  ja  va 2 s  .co m

    if (config.includeTestSources()) {
        classifiers.add(AbstractJavadocMojo.TEST_JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER);
    }

    for (String classifier : classifiers) {
        File optionsFile = new File(project.getBuild().getDirectory(),
                "javadoc-bundle-options/javadoc-options-" + classifier + ".xml");
        if (!optionsFile.exists()) {
            continue;
        }

        FileInputStream stream = null;
        try {
            stream = new FileInputStream(optionsFile);
            JavadocOptions options = new JavadocOptionsXpp3Reader().read(stream);

            bundles.add(new JavadocBundle(options,
                    new File(project.getBasedir(), options.getJavadocResourcesDirectory())));
        } catch (XmlPullParserException e) {
            IOException error = new IOException(
                    "Failed to read javadoc options from: " + optionsFile + "\nReason: " + e.getMessage());
            error.initCause(e);

            throw error;
        } finally {
            close(stream);
        }
    }

    return bundles;
}

From source file:ch.rotscher.maven.plugins.InstallWithVersionOverrideMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    try {//from   w w w .  ja v  a  2 s  .co m

        String versionOverride = System.getProperty("version.override");
        if (versionOverride != null) {
            MavenProject project = getMavenProject();
            if (project != null) {
                getLog().info(
                        "version.override: rewrite the version in the original pom.xom in target/pom.xml");

                //it's very important to set the absolute file name as some classes are using File.equals for comparing
                //to file instances
                File targetDir = new File(project.getBasedir(), "target");
                if (!targetDir.exists()) {
                    targetDir.mkdir();
                }
                File newPomFile = new File(targetDir, "pom.xml");
                newPomFile.createNewFile();
                replaceVersion(project.getFile(), newPomFile, versionOverride);
                project.setFile(newPomFile);
            } else {
                getLog().warn(
                        "could not access the project in InstallMojo: install with version.override did not work!");
            }
        }

    } catch (IOException e) {
        getLog().warn(e);
    } catch (JDOMException e) {
        getLog().warn(e);
    }

    super.execute();
}

From source file:ch.sourcepond.maven.release.providers.DefaultRootProject.java

License:Apache License

@Override
public String calculateModulePath(final MavenProject project) throws ReactorException {
    // Getting canonical files because on Windows, it's possible one returns
    // "C:\..." and the other "c:\..." which is rather amazing
    File projectRoot;//from   www  . j  a  v  a 2s  . c  o m
    File moduleRoot;
    try {
        projectRoot = getProject().getBasedir().getCanonicalFile();
        moduleRoot = project.getBasedir().getCanonicalFile();
    } catch (final IOException e) {
        throw new ReactorException(e, "Could not find directory paths for maven project");
    }
    String relativePathToModule = Repository.stripWorkDir(projectRoot, moduleRoot);
    if (relativePathToModule.length() == 0) {
        relativePathToModule = ".";
    }
    return relativePathToModule;
}

From source file:com.adobe.ac.maven.ncss.NcssReportMojo.java

License:Apache License

private void generateAggregateReport(final Locale locale) throws MavenReportException {
    // All this work just to get "target" so that we can scan the filesystem for
    // child javancss xml files...
    final String basedir = project.getBasedir().toString();
    final String output = xmlOutputDirectory.toString();
    if (getLog().isDebugEnabled()) {
        getLog().debug("basedir: " + basedir);
        getLog().debug("output: " + output);
    }/*from   w w  w. j ava  2s.  c  om*/
    String relative = null;
    if (output.startsWith(basedir)) {
        relative = output.substring(basedir.length() + 1);
    } else {
        getLog().error("Unable to aggregate report because I can't "
                + "determine the relative location of the XML report");
        return;
    }
    getLog().debug("relative: " + relative);
    final List<ModuleReport> reports = new ArrayList<ModuleReport>();
    for (final Iterator<MavenProject> it = reactorProjects.iterator(); it.hasNext();) {
        final MavenProject child = (MavenProject) it.next();
        final File xmlReport = new File(child.getBasedir() + File.separator + relative, tempFileName);
        if (xmlReport.exists()) {
            reports.add(new ModuleReport(child, loadDocument(xmlReport)));
        } else {
            getLog().debug("xml file not found: " + xmlReport);
        }
    }
    getLog().debug("Aggregating " + reports.size() + " JavaNCSS reports");

    // parse the freshly generated file and write the report
    final NcssAggregateReportGenerator reportGenerator = new NcssAggregateReportGenerator(getSink(),
            getBundle(locale), getLog());
    reportGenerator.doReport(locale, reports, lineThreshold);
}

From source file:com.adobe.ac.pmd.metrics.maven.FlexMetricsReportMojo.java

License:Apache License

private void generateAggregateReport(final Locale locale) throws MavenReportException {
    final String basedir = project.getBasedir().toString();
    final String output = xmlOutputDirectory.toString();
    if (getLog().isDebugEnabled()) {
        getLog().debug("basedir: " + basedir);
        getLog().debug("output: " + output);
    }//  ww w. j  a  va2  s .  c o  m
    String relative = null;
    if (output.startsWith(basedir)) {
        relative = output.substring(basedir.length() + 1);
    } else {
        getLog().error("Unable to aggregate report because I can't "
                + "determine the relative location of the XML report");
        return;
    }
    getLog().debug("relative: " + relative);
    final List<ModuleReport> reports = new ArrayList<ModuleReport>();

    if (reactorProjects != null) {
        for (final MavenProject mavenProject : reactorProjects) {
            final MavenProject child = mavenProject;
            final File xmlReport = new File(child.getBasedir() // NOPMD
                    + File.separator + relative, tempFileName);
            if (xmlReport.exists()) {
                reports.add(new ModuleReport(child, loadDocument(xmlReport))); // NOPMD
            } else {
                getLog().debug("xml file not found: " + xmlReport);
            }
        }
        getLog().debug("Aggregating " + reports.size() + " JavaNCSS reports");

        new NcssAggregateReportGenerator(getSink(), getBundle(), getLog()).doReport(locale, reports,
                lineThreshold);
    }
}

From source file:com.agilejava.docbkx.maven.AbstractTransformerMojo.java

License:Apache License

/**
 * Configures and executes the given ant tasks, mainly preprocess and postprocess defined in the pom configuration.
 *
 * @param antTasks The tasks to execute/*ww  w  . j av  a  2 s  .  co m*/
 * @param mavenProject The current maven project
 * @throws MojoExecutionException If something wrong occurs while executing the ant tasks.
 */
protected void executeTasks(Target antTasks, MavenProject mavenProject) throws MojoExecutionException {
    try {
        ExpressionEvaluator exprEvaluator = (ExpressionEvaluator) antTasks.getProject()
                .getReference("maven.expressionEvaluator");
        Project antProject = antTasks.getProject();
        PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(antProject);
        propertyHelper.setNext(new AntPropertyHelper(exprEvaluator, getLog()));
        DefaultLogger antLogger = new DefaultLogger();
        antLogger.setOutputPrintStream(System.out);
        antLogger.setErrorPrintStream(System.err);
        antLogger.setMessageOutputLevel(2);
        antProject.addBuildListener(antLogger);
        antProject.setBaseDir(mavenProject.getBasedir());
        Path p = new Path(antProject);
        p.setPath(StringUtils.join(mavenProject.getArtifacts().iterator(), File.pathSeparator));
        antProject.addReference("maven.dependency.classpath", p);
        p = new Path(antProject);
        p.setPath(StringUtils.join(mavenProject.getCompileClasspathElements().iterator(), File.pathSeparator));
        antProject.addReference("maven.compile.classpath", p);
        p = new Path(antProject);
        p.setPath(StringUtils.join(mavenProject.getRuntimeClasspathElements().iterator(), File.pathSeparator));
        antProject.addReference("maven.runtime.classpath", p);
        p = new Path(antProject);
        p.setPath(StringUtils.join(mavenProject.getTestClasspathElements().iterator(), File.pathSeparator));
        antProject.addReference("maven.test.classpath", p);
        List artifacts = getArtifacts();
        List list = new ArrayList(artifacts.size());
        File file;
        for (Iterator i = artifacts.iterator(); i.hasNext(); list.add(file.getPath())) {
            Artifact a = (Artifact) i.next();
            file = a.getFile();
            if (file == null)
                throw new DependencyResolutionRequiredException(a);
        }

        p = new Path(antProject);
        p.setPath(StringUtils.join(list.iterator(), File.pathSeparator));
        antProject.addReference("maven.plugin.classpath", p);
        getLog().info("Executing tasks");
        antTasks.execute();
        getLog().info("Executed tasks");
    } catch (Exception e) {
        throw new MojoExecutionException("Error executing ant tasks", e);
    }
}

From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.EclipsePlugin.java

License:Apache License

/**
 * Utility method that locates a project producing the given artifact
 * and verifies if it's a valid Eclipse project.
 *
 * @param artifact the artifact a project should produce.
 * @return <code>true</code> if the artifact is produced by a reactor projectart.
 *//*  w  w  w.jav  a2 s  .c  o m*/
protected boolean isAvailableAsAReactorProject(Artifact artifact) {
    MavenProject project = getReactorProject(artifact);
    return (project != null && new File(project.getBasedir(), ".project").exists());
}

From source file:com.alibaba.citrus.maven.eclipse.base.ide.IdeDependency.java

License:Apache License

/**
 * Is this dependency System scoped outside the eclipse project. This is NOT complete because in reality the check
 * should mean that any module in the reactor contains the system scope locally!
 *
 * @return Returns this dependency is systemScoped outside the project.
 *//*w w  w.ja va2s  . c o m*/
public boolean isSystemScopedOutsideProject(MavenProject project) {
    File modulesTop = project.getBasedir();
    while (new File(modulesTop.getParentFile(), "pom.xml").exists()) {
        modulesTop = modulesTop.getParentFile();
    }
    return isSystemScoped() && !getFile().getAbsolutePath().startsWith(modulesTop.getAbsolutePath());
}