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.onosproject.yang.compiler.plugin.maven.YangPluginUtils.java

License:Apache License

/**
 * Adds generated source directory to the compilation root.
 *
 * @param source  directory/*w w w  .  j a  va  2 s  .c om*/
 * @param project current maven project
 * @param context current build context
 */
static void addToCompilationRoot(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.onosproject.yangutils.utils.io.impl.YangIoUtils.java

License:Apache License

/**
 * Adds generated source directory to the compilation root.
 *
 * @param source directory//from   w ww  . j a  v a 2  s.  c om
 * @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.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator.java

License:Open Source License

@Override
public void setMavenProject(final MavenProject project) {
    this.projectBaseDir = project.getBasedir();
    LOG.debug("{}: project base dir: {}", getClass().getCanonicalName(), projectBaseDir);
}

From source file:org.opendaylight.controller.sal.rest.doc.maven.StaticDocGenerator.java

License:Open Source License

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

From source file:org.opendaylight.mdsal.binding.javav2.maven.api.gen.plugin.CodeGeneratorImpl.java

License:Open Source License

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

From source file:org.opendaylight.yangtools.yang2sources.plugin.YangProvider.java

License:Open Source License

void addYangsToMetaInf(final MavenProject project, final File yangFilesRootDir,
        final Collection<File> excludedFiles) throws MojoFailureException {

    // copy project's src/main/yang/*.yang to target/generated-sources/yang/META-INF/yang/*.yang

    File generatedYangDir = new File(project.getBasedir(), CodeGeneratorArg.YANG_GENERATED_DIR);
    addYangsToMetaInf(project, yangFilesRootDir, excludedFiles, generatedYangDir);

    // Also copy to the actual build output dir if different than "target". When running in
    // Eclipse this can differ (eg "target-ide").

    File actualGeneratedYangDir = new File(project.getBuild().getDirectory(),
            CodeGeneratorArg.YANG_GENERATED_DIR.replace("target" + File.separator, ""));
    if (!actualGeneratedYangDir.equals(generatedYangDir)) {
        addYangsToMetaInf(project, yangFilesRootDir, excludedFiles, actualGeneratedYangDir);
    }/*from w  ww.j  a  v a2  s .c o m*/
}

From source file:org.opennms.maven.plugins.tgz.AbstractAssemblyMojo.java

License:Apache License

private void processModules(Archiver archiver, List moduleSets, boolean includeBaseDirectory)
        throws MojoFailureException, MojoExecutionException {
    for (Iterator i = moduleSets.iterator(); i.hasNext();) {
        ModuleSet moduleSet = (ModuleSet) i.next();

        AndArtifactFilter filter = new AndArtifactFilter();

        if (!moduleSet.getIncludes().isEmpty()) {
            filter.add(new AssemblyIncludesArtifactFilter(moduleSet.getIncludes()));
        }//  w  w  w. java  2s. c  o  m
        if (!moduleSet.getExcludes().isEmpty()) {
            filter.add(new AssemblyExcludesArtifactFilter(moduleSet.getExcludes()));
        }

        Set set = getModulesFromReactor(getExecutedProject());

        List moduleFileSets = new ArrayList();

        for (Iterator j = set.iterator(); j.hasNext();) {
            MavenProject moduleProject = (MavenProject) j.next();

            if (filter.include(moduleProject.getArtifact())) {
                String name = moduleProject.getBuild().getFinalName();

                ModuleSources sources = moduleSet.getSources();

                if (sources != null) {
                    String output = sources.getOutputDirectory();
                    output = getOutputDirectory(output, moduleProject, includeBaseDirectory);

                    FileSet moduleFileSet = new FileSet();

                    moduleFileSet.setDirectory(moduleProject.getBasedir().getAbsolutePath());
                    moduleFileSet.setOutputDirectory(output);

                    List excludesList = new ArrayList();
                    excludesList.add(PathUtils.toRelative(moduleProject.getBasedir(),
                            moduleProject.getBuild().getDirectory()) + "/**");
                    excludesList.add(PathUtils.toRelative(moduleProject.getBasedir(),
                            moduleProject.getBuild().getOutputDirectory()) + "/**");
                    excludesList.add(PathUtils.toRelative(moduleProject.getBasedir(),
                            moduleProject.getBuild().getTestOutputDirectory()) + "/**");
                    excludesList.add(PathUtils.toRelative(moduleProject.getBasedir(),
                            moduleProject.getReporting().getOutputDirectory()) + "/**");
                    moduleFileSet.setExcludes(excludesList);

                    moduleFileSets.add(moduleFileSet);
                }

                ModuleBinaries binaries = moduleSet.getBinaries();

                if (binaries != null) {
                    Artifact artifact = moduleProject.getArtifact();

                    if (artifact.getFile() == null) {
                        throw new MojoExecutionException("Included module: " + moduleProject.getId()
                                + " does not have an artifact with a file. Please ensure the package phase is run before the assembly is generated.");
                    }

                    String output = binaries.getOutputDirectory();
                    output = getOutputDirectory(output, moduleProject, includeBaseDirectory);

                    archiver.setDefaultDirectoryMode(Integer.parseInt(binaries.getDirectoryMode(), 8));

                    archiver.setDefaultFileMode(Integer.parseInt(binaries.getFileMode(), 8));

                    getLog().debug("ModuleSet[" + output + "]" + " dir perms: "
                            + Integer.toString(archiver.getDefaultDirectoryMode(), 8) + " file perms: "
                            + Integer.toString(archiver.getDefaultFileMode(), 8));

                    if (binaries.isUnpack()) {
                        // TODO: something like zipfileset in plexus-archiver
                        //                        archiver.addJar(  )

                        // TODO refactor into the AbstractUnpackMojo
                        File tempLocation = new File(workDirectory, name);
                        boolean process = false;
                        if (!tempLocation.exists()) {
                            tempLocation.mkdirs();
                            process = true;
                        } else if (artifact.getFile().lastModified() > tempLocation.lastModified()) {
                            process = true;
                        }

                        if (process) {
                            try {
                                unpack(artifact.getFile(), tempLocation);

                                if (binaries.isIncludeDependencies()) {
                                    Set artifactSet = moduleProject.getArtifacts();

                                    for (Iterator artifacts = artifactSet.iterator(); artifacts.hasNext();) {
                                        Artifact dependencyArtifact = (Artifact) artifacts.next();

                                        unpack(dependencyArtifact.getFile(), tempLocation);
                                    }
                                }
                            } catch (NoSuchArchiverException e) {
                                throw new MojoExecutionException(
                                        "Unable to obtain unarchiver: " + e.getMessage(), e);
                            }

                            /*
                            * If the assembly is 'jar-with-dependencies', remove the security files in all dependencies
                            * that will prevent the uberjar to execute.  Please see MASSEMBLY-64 for details.
                            */
                            if (archiver instanceof JarArchiver) {
                                String[] securityFiles = { "*.RSA", "*.DSA", "*.SF", "*.rsa", "*.dsa", "*.sf" };
                                org.apache.maven.shared.model.fileset.FileSet securityFileSet = new org.apache.maven.shared.model.fileset.FileSet();
                                securityFileSet.setDirectory(tempLocation.getAbsolutePath() + "/META-INF/");

                                for (int sfsi = 0; sfsi < securityFiles.length; sfsi++) {
                                    securityFileSet.addInclude(securityFiles[sfsi]);
                                }

                                FileSetManager fsm = new FileSetManager(getLog());
                                try {
                                    fsm.delete(securityFileSet);
                                } catch (IOException e) {
                                    throw new MojoExecutionException(
                                            "Failed to delete security files: " + e.getMessage(), e);
                                }
                            }
                        }

                        addDirectory(archiver, tempLocation, output, null,
                                FileUtils.getDefaultExcludesAsList());
                    } else {
                        try {
                            String outputFileNameMapping = binaries.getOutputFileNameMapping();

                            archiver.addFile(artifact.getFile(),
                                    output + evaluateFileNameMapping(artifact, outputFileNameMapping));

                            if (binaries.isIncludeDependencies()) {
                                Set artifactSet = moduleProject.getArtifacts();

                                for (Iterator artifacts = artifactSet.iterator(); artifacts.hasNext();) {
                                    Artifact dependencyArtifact = (Artifact) artifacts.next();

                                    archiver.addFile(dependencyArtifact.getFile(),
                                            output + evaluateFileNameMapping(dependencyArtifact,
                                                    outputFileNameMapping));
                                }
                            }
                        } catch (ArchiverException e) {
                            throw new MojoExecutionException("Error adding file to archive: " + e.getMessage(),
                                    e);
                        }
                    }
                }

            } else {
                // would be better to have a way to find out when a specified include or exclude
                // is never triggered and warn() it.
                getLog().debug("module: " + moduleProject.getId() + " not included");
            }

            if (!moduleFileSets.isEmpty()) {
                // TODO: includes and excludes
                processFileSets(archiver, moduleFileSets, includeBaseDirectory);
            }
        }
    }
}

From source file:org.ops4j.pax.construct.clone.CloneMojo.java

License:Apache License

/**
 * Analyze major project and build the right pax-create-project call
 * //from  www.j  av  a  2s.co m
 * @param script build script
 * @param project major Maven project
 */
private void handleMajorProject(PaxScript script, MavenProject project) {
    if (unify && !project.isExecutionRoot()) {
        // exclude the local poms settings from the unified project
        m_handledDirs.add(new File(project.getBasedir(), "poms"));
        return;
    }

    PaxCommandBuilder command = script.call(PaxScript.CREATE_PROJECT);

    command.option('g', project.getGroupId());
    command.option('a', project.getArtifactId());
    command.option('v', project.getVersion());

    setTargetDirectory(command, project.getBasedir().getParentFile());
    registerProject(project);

    m_majorProjectMap.put(project, command);
}

From source file:org.ops4j.pax.construct.clone.CloneMojo.java

License:Apache License

/**
 * Analyze bundle project and determine if any pax-create-bundle or pax-wrap-jar calls are needed
 * //from  w  w w . j  a va 2  s .  c  o  m
 * @param script build script
 * @param project Maven bundle project
 * @throws MojoExecutionException
 */
private void handleBundleProject(PaxScript script, MavenProject project) throws MojoExecutionException {
    PaxCommandBuilder command;
    String bundleName;

    String namespace = findBundleNamespace(project);
    if (null != namespace) {
        bundleName = project.getArtifactId();

        command = script.call(PaxScript.CREATE_BUNDLE);
        command.option('p', namespace);
        if (!bundleName.equals(namespace)) {
            command.option('n', bundleName);
        }
        command.option('v', project.getVersion());
        command.maven().flag("noDeps");
    } else {
        Dependency wrappee = findWrappee(project);
        if (wrappee != null) {
            command = script.call(PaxScript.WRAP_JAR);
            command.option('g', wrappee.getGroupId());
            command.option('a', wrappee.getArtifactId());
            command.option('v', wrappee.getVersion());

            if (repair) {
                // this is expected to be the generated bundle name
                bundleName = PomUtils.getCompoundId(wrappee.getGroupId(), wrappee.getArtifactId());

                // detect if we need to add the version back later on...
                if (project.getArtifactId().endsWith(wrappee.getVersion())) {
                    command.maven().flag("addVersion");
                }
            } else {
                bundleName = project.getArtifactId();

                // need to retain the old name and version settings
                command.maven().option("bundleName", bundleName);
                command.maven().option("bundleVersion", project.getVersion());
            }
        } else {
            getLog().warn("Unable to clone bundle project " + project.getId());
            return;
        }
    }

    Pom customizedPom = null;

    if (repair) {
        // fix references to local bundles by re-importing
        customizedPom = repairBundleImports(script, project);
    } else {
        // need to keep old groupId intact (name is already retained)
        command.maven().option("bundleGroupId", project.getGroupId());
    }

    addFragmentToCommand(command, createBundleArchetype(project, namespace, customizedPom));

    setTargetDirectory(command, project.getBasedir().getParentFile());
    registerProject(project);

    registerBundleName(project, bundleName);
}

From source file:org.ops4j.pax.construct.clone.CloneMojo.java

License:Apache License

/**
 * Analyze the position of this project in the tree, as not all projects need their own distinct set of "poms"
 * //from   ww w.j  a  va 2 s  . c o  m
 * @param project Maven POM project
 * @return true if this project requires a pax-create-project call
 */
private boolean isMajorProject(MavenProject project) {
    if (project.isExecutionRoot()) {
        // top-most project
        return true;
    }

    // disconnected project, or project with its own set of "poms" where settings can be customized
    return (null == project.getParent() || new File(project.getBasedir(), "poms").isDirectory());
}