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:fr.brouillard.oss.jgitver.JGitverUtils.java

License:Apache License

/**
 * Changes the pom file of the given project.
 * @param project the project to change the pom
 * @param newPom the pom file to set on the project
 * @param logger a logger to use /*from w ww.  j  av a  2 s  .co m*/
 */
public static void setProjectPomFile(MavenProject project, File newPom, Logger logger) {
    try {
        project.setPomFile(newPom);
    } catch (Throwable unused) {
        logger.warn("maven version might be <= 3.2.4, changing pom file using old mechanism");
        File initialBaseDir = project.getBasedir();
        project.setFile(newPom);
        File newBaseDir = project.getBasedir();
        try {
            if (!initialBaseDir.getCanonicalPath().equals(newBaseDir.getCanonicalPath())) {
                changeBaseDir(project, initialBaseDir);
            }
        } catch (Exception ex) {
            GAV gav = GAV.from(project);
            logger.warn("cannot reset basedir of project " + gav.toString(), ex);
        }
    }
}

From source file:fr.brouillard.oss.jgitver.JGitverUtils.java

License:Apache License

/**
 * Calculates the version to use of the given project. 
 * @param rootProject the root project for which a version has to be calculated
 * @param properties a property object that will be filled with additional information 
 * @param logger a logger to use/*  w ww.ja v  a 2s.c  o m*/
 * @return a non null container for the version 
 * @throws IOException if an error ocurred while calculating the version
 */
public static JGitverVersion calculateVersionForProject(MavenProject rootProject, Properties properties,
        Logger logger) throws IOException {
    JGitverVersion jGitverVersion = null;

    logger.debug("using " + EXTENSION_PREFIX + " on directory: " + rootProject.getBasedir());
    try (GitVersionCalculator gitVersionCalculator = GitVersionCalculator.location(rootProject.getBasedir())) {
        Plugin plugin = rootProject.getPlugin("fr.brouillard.oss:jgitver-maven-plugin");

        JGitverPluginConfiguration pluginConfig = new JGitverPluginConfiguration(
                Optional.ofNullable(plugin).map(Plugin::getConfiguration).map(Xpp3Dom.class::cast));

        gitVersionCalculator.setMavenLike(pluginConfig.mavenLike())
                .setAutoIncrementPatch(pluginConfig.autoIncrementPatch())
                .setUseDistance(pluginConfig.useCommitDistance())
                .setUseGitCommitId(pluginConfig.useGitCommitId())
                .setGitCommitIdLength(pluginConfig.gitCommitIdLength()).setUseDirty(pluginConfig.useDirty())
                .setNonQualifierBranches(
                        pluginConfig.nonQualifierBranches().stream().collect(Collectors.joining(",")));

        jGitverVersion = new JGitverVersion(gitVersionCalculator);
        fillPropertiesFromMetadatas(properties, jGitverVersion, logger);
    } catch (Exception ex) {
        throw new IOException(ex.getMessage(), ex);
    }

    return jGitverVersion;
}

From source file:fr.brouillard.oss.maven.external.jgit.JGitverStrategy.java

License:Apache License

@Override
public String getVersion(MavenProject mavenProject) throws ExternalVersionException {
    GitVersionCalculator calculator = GitVersionCalculator.location(mavenProject.getBasedir());

    calculator.setAutoIncrementPatch(true);
    calculator.setUseDistance(true);/*from w  ww .j a  va 2 s. c  o m*/

    calculator.setNonQualifierBranches(Optional.ofNullable(nonQualifierBranches).orElse("master"));
    calculator.setUseGitCommitId(Optional.ofNullable(appendGitCommitId).orElse(Boolean.FALSE));
    calculator.setGitCommitIdLength(Optional.ofNullable(gitCommitIdLength).orElse(8));

    return calculator.getVersion();
}

From source file:fr.fastconnect.factory.tibco.bw.maven.builtin.CopyBWSourcesMojo.java

License:Apache License

@Override
protected List<Resource> getResources() {
    List<Resource> result = new ArrayList<Resource>();
    if (resources != null) {
        result.addAll(resources);//from w ww  . ja  va2 s.c  om
    }

    if (isContainerEnabled(getProject())) {
        result.clear(); // ignore configuration from Plexus 'components.xml'

        getLog().debug(getProject().getProperties().toString());
        getLog().debug(getProject().getProperties().getProperty("project.build.directory.src"));
        File buildSrcDirectory = new File(
                getProject().getProperties().getProperty("project.build.directory.src"));
        buildSrcDirectory.mkdirs(); // create "target/src" directory

        // define a ".archive" file to merge all ".archive" found in other projects
        String bwProjectArchiveBuilder = getProject().getProperties().getProperty("bw.project.archive.builder");
        File bwProjectArchiveMerged = new File(
                buildSrcDirectory.getAbsolutePath() + File.separator + bwProjectArchiveBuilder);
        getLog().debug(".archive: " + bwProjectArchiveMerged.getAbsolutePath());

        // create an empty Archive Builder (".archive" file)
        ArchiveBuilder mergedArchiveBuilder = new ArchiveBuilder();

        List<MavenProject> projectsToAggregate = new ArrayList<MavenProject>();

        MavenProject aggregator = getProject().getParent();
        @SuppressWarnings("unchecked")
        List<String> modules = aggregator.getModules();

        for (String module : modules) {
            getLog().debug(module);
            String pom = aggregator.getBasedir() + File.separator + module + File.separator + "pom.xml";
            File pomFile = new File(pom);

            try {
                projectsToAggregate.add(new MavenProject(POMManager.getModelFromPOM(pomFile, getLog())));
            } catch (Exception e) {
                getLog().debug("Unable to add project from module: " + module);
            }
        }

        List<MavenProject> projects = new ArrayList<MavenProject>();
        projects.addAll(getSession().getProjects());

        for (Iterator<MavenProject> it = projects.iterator(); it.hasNext();) {
            MavenProject p = (MavenProject) it.next();
            if (!isProjectToAggregate(p, projectsToAggregate)) {
                it.remove();
            }
        }

        if (projects.size() > 0) {
            for (MavenProject p : projects) {
                if (p.getPackaging().equals(AbstractBWMojo.BWEAR_TYPE) && !isContainerEnabled(p)) {
                    // initialize project information
                    String basedir = p.getBasedir().getAbsolutePath();
                    String bwProjectLocation = p.getProperties().getProperty("bw.project.location");
                    bwProjectArchiveBuilder = p.getProperties().getProperty("bw.project.archive.builder"); // the ".archive" of the project
                    getLog().debug(basedir);
                    getLog().debug(bwProjectLocation);

                    File bwProjectArchive = new File(basedir + File.separator + bwProjectLocation
                            + File.separator + bwProjectArchiveBuilder);
                    getLog().debug(bwProjectArchive.getAbsolutePath());
                    //

                    mergedArchiveBuilder.merge(bwProjectArchive);

                    // add sources from the project to the container sources
                    File srcDirectory = new File(basedir + File.separator + bwProjectLocation);
                    result.add(addResource(srcDirectory));
                }
            }

            mergedArchiveBuilder.setSharedArchiveAuthor(pluginDescriptor.getArtifactId());
            mergedArchiveBuilder.setEnterpriseArchiveAuthor(pluginDescriptor.getArtifactId());
            mergedArchiveBuilder.setEnterpriseArchiveFileLocationProperty(
                    this.getProject().getArtifactId() + AbstractBWMojo.BWEAR_EXTENSION);
            mergedArchiveBuilder.setEnterpriseArchiveName(enterpriseArchiveName);
            mergedArchiveBuilder.setFirstProcessArchiveName(processArchiveName);
            mergedArchiveBuilder.removeDuplicateProcesses();
            mergedArchiveBuilder.save(bwProjectArchiveMerged);
        }
    }

    return result;
}

From source file:fr.fastconnect.factory.tibco.bw.maven.deployment.DeployEARMojo.java

License:Apache License

@Override
public ArrayList<String> arguments() {
    File ear = getOutputFile();//  w w  w . j  a v a  2  s  .c o m
    if (ear == null || !ear.exists()) {
        MavenProject project = getProject();
        if (project != null && project.getBasedir() != null && project.getBasedir().exists()) {
            ear = getArtifactFile(getProject().getBasedir(), finalName, classifier);
        }
    }

    getLog().info(USING_EAR + ear.getAbsolutePath());
    getLog().info(USING_XML + deploymentDescriptorFinal.getAbsolutePath());

    ArrayList<String> arguments = super.commonArguments();
    arguments.add("-deploy");
    arguments.add("-ear");
    arguments.add(ear.getAbsolutePath());
    arguments.add("-deployConfig");
    arguments.add(deploymentDescriptorFinal.getAbsolutePath());
    if (serialize) {
        arguments.add("-serialize");
    }
    if (noStart) {
        arguments.add("-nostart");
    }
    if (noStop) {
        arguments.add("-nostop");
    }
    arguments.add("-force");

    return arguments;
}

From source file:fr.fastconnect.factory.tibco.bw.maven.packaging.pom.GenerateRootDeploymentPOM.java

License:Apache License

private List<String> addModules(MavenProject project, List<MavenProject> activeProjects)
        throws IOException, XmlPullParserException {
    return addModules(project.getBasedir() + File.separator, project.getModel(),
            getActiveProfiles(activeProjects), activeProjects);
}

From source file:fr.paris.lutece.maven.xdoc2md.XDoc2MarkdownMojo.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    getLog().info("Create or update file README.md from src/site/xdoc/index.xml");

    MavenProject project = (MavenProject) getPluginContext().get("project");
    String strBaseDir = project.getBasedir().getAbsolutePath();
    getLog().info("Basedir :" + strBaseDir);

    String strInput = strBaseDir + File.separator + "src/site/xdoc/index.xml";
    String strOutput = strBaseDir + File.separator + "README.md";
    transform(project.getArtifactId(), strInput, strOutput);
}

From source file:hudson.gridmaven.reporters.MavenSiteArchiver.java

License:Open Source License

/**
 * In multi module builds pomBaseDir of the parent project is the same as parent build module root.
 *
 * @param build//from  ww  w  .  ja v a  2  s  . co m
 * @param pom
 *
 * @return the relative path component to copy sites of multi module builds.
 * @throws IOException
 * @throws InterruptedException 
 */
private String getModuleName(MavenBuildProxy build, MavenProject pom) throws IOException, InterruptedException {
    String moduleRoot = build.execute(new BuildCallable<String, IOException>() {
        private static final long serialVersionUID = 1L;

        //@Override
        public String call(MavenBuild mavenBuild) throws IOException, InterruptedException {
            MavenModuleSetBuild moduleSetBuild = mavenBuild.getModuleSetBuild();
            if (moduleSetBuild == null) {
                throw new IOException("Parent build not found!");
            }
            return moduleSetBuild.getModuleRoot().getRemote();
        }
    });
    final File pomBaseDir = pom.getBasedir();
    final File remoteWorkspaceDir = new File(moduleRoot);
    if (pomBaseDir.equals(remoteWorkspaceDir)) {
        return "";
    } else {
        return pom.getArtifactId();
    }
}

From source file:hudson.gridmaven.reporters.SurefireArchiver.java

License:Open Source License

public boolean postExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo, final BuildListener listener,
        Throwable error) throws InterruptedException, IOException {
    if (!isSurefireTest(mojo))
        return true;

    listener.getLogger().println(Messages.SurefireArchiver_Recording());

    File reportsDir;//ww w  . j a  va2 s. co m
    if (mojo.is("org.apache.maven.plugins", "maven-surefire-plugin", "test")
            || mojo.is("org.apache.maven.plugins", "maven-failsafe-plugin", "integration-test")) {
        try {
            reportsDir = mojo.getConfigurationValue("reportsDirectory", File.class);
        } catch (ComponentConfigurationException e) {
            e.printStackTrace(listener.fatalError(Messages.SurefireArchiver_NoReportsDir()));
            build.setResult(Result.FAILURE);
            return true;
        }
    } else {
        reportsDir = new File(pom.getBasedir(), "target/surefire-reports");
    }

    if (reportsDir.exists()) {
        // surefire:test just skips itself when the current project is not a java project

        synchronized (build) {
            FileSet fileSet = getFileSet(reportsDir);

            DirectoryScanner ds = fileSet.getDirectoryScanner();

            if (ds.getIncludedFilesCount() == 0)
                // no test in this module
                return true;

            String[] reportFiles = ds.getIncludedFiles();
            rememberCheckedFiles(reportsDir, reportFiles);

            if (result == null)
                result = new TestResult();
            result.parse(System.currentTimeMillis() - build.getMilliSecsSinceBuildStart(), reportsDir,
                    reportFiles);

            // final reference in order to serialize it:
            final TestResult r = result;

            int failCount = build.execute(new BuildCallable<Integer, IOException>() {
                private static final long serialVersionUID = -1023888330720922136L;

                public Integer call(MavenBuild build) throws IOException, InterruptedException {
                    SurefireReport sr = build.getAction(SurefireReport.class);
                    if (sr == null)
                        build.getActions().add(new SurefireReport(build, r, listener));
                    else
                        sr.setResult(r, listener);
                    if (r.getFailCount() > 0)
                        build.setResult(Result.UNSTABLE);
                    build.registerAsProjectAction(new FactoryImpl());
                    return r.getFailCount();
                }
            });

            // if surefire plugin is going to kill maven because of a test failure,
            // intercept that (or otherwise build will be marked as failure)
            if (failCount > 0) {
                markBuildAsSuccess(error, build.getMavenBuildInformation());
            }
        }
    }

    return true;
}

From source file:info.mikaelsvensson.devtools.sitesearch.SiteSearchPlugin.java

License:Apache License

private Map<String, String> getProperties() {
    if (null == properties) {
        properties = new HashMap<String, String>();
        try {// ww  w. j a v a  2 s.  c o  m
            File dir = baseDirectory;
            MavenProject proj = project;
            while (proj != null) {
                File file = siteTool.getSiteDescriptorFromBasedir(siteDirectory, dir, null);
                if (file.exists() && file.isFile()) {
                    DecorationModel decorationModel = getDecorationModel(file);
                    Xpp3Dom custom = (Xpp3Dom) decorationModel.getCustom();
                    if (custom != null) {
                        Xpp3Dom siteSearchPluginElement = custom.getChild("siteSearchPlugin");
                        if (null != siteSearchPluginElement) {
                            Xpp3Dom[] propertyElements = siteSearchPluginElement.getChildren();
                            for (Xpp3Dom propertyElement : propertyElements) {
                                if (!properties.containsKey(propertyElement.getName())) {
                                    properties.put(propertyElement.getName(), propertyElement.getValue());
                                }
                            }
                            getLog().info(
                                    "Loaded configuration parameters from " + file.getAbsolutePath() + ".");
                        } else {
                            getLog().info("No site indexer configuration parameters defined in "
                                    + file.getAbsolutePath() + ".");
                        }
                    }
                } else {
                    getLog().info("Looked for " + file.getAbsolutePath() + " but couldn't find it.");
                }
                proj = proj.getParent();
                dir = proj != null ? proj.getBasedir() : null;
            }
        } catch (XmlPullParserException e) {
            getLog().warn(e);
        } catch (IOException e) {
            getLog().warn(e);
        }
    }
    return properties;
}