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

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

Introduction

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

Prototype

public List<Dependency> getDependencies() 

Source Link

Usage

From source file:org.wso2.maven.core.utils.MavenUtils.java

License:Open Source License

public static void addMavenDependency(MavenProject mavenProject, Dependency... dependencies) {
    List<String> dependencyStrings = new ArrayList<String>();
    List<Dependency> currentDependencyList = mavenProject.getDependencies();
    for (Dependency dependency : currentDependencyList) {
        String ds = getDependencyString(dependency);
        dependencyStrings.add(ds);/* w ww.j  a v a2  s  . c o m*/
    }
    for (Dependency dependency : dependencies) {
        String dependencyString = getDependencyString(dependency);
        if (!dependencyStrings.contains(dependencyString)) {
            mavenProject.getDependencies().add(dependency);
            dependencyStrings.add(dependencyString);
        }
    }
}

From source file:org.wso2.maven.p2.utils.DependencyResolver.java

License:Open Source License

/**
 * Resolve the given project dependencies into CarbonArtifact objects. Dependencies are categorized into
 * OSGI bundles and Carbon features./*from www  . j  ava  2 s .co m*/
 *
 * @param project            MavenProject  Maven Project
 * @param repositorySystem   RepositorySystem object
 * @param remoteRepositories collection of remote repositories
 * @param localRepository    local repository representation
 * @return Return a {@code List<HashMap<String, CarbonArtifact>>}, 1st item being {@code HashMap<String,
 * CarbonArtifact>} containing osgi bundles specified as dependencies and 2nd item being {@code HashMap<String,
 * CarbonArtifact>} containing carbon features specified as dependencies.
 * @throws IOException throws when unable to retrieve a given maven artifact
 */
public static List<HashMap<String, CarbonArtifact>> getDependenciesForProject(MavenProject project,
        RepositorySystem repositorySystem, List<ArtifactRepository> remoteRepositories,
        ArtifactRepository localRepository) throws IOException {

    List<HashMap<String, CarbonArtifact>> results = new ArrayList<>();
    HashMap<String, CarbonArtifact> bundles = new HashMap<>();
    HashMap<String, CarbonArtifact> features = new HashMap<>();
    results.add(bundles);
    results.add(features);
    List<Dependency> dependencies = project.getDependencies();

    DependencyManagement dependencyManagement = project.getDependencyManagement();
    if (dependencyManagement != null) {
        dependencies.addAll(dependencyManagement.getDependencies());
    }
    for (Dependency dependency : dependencies) {
        CarbonArtifact carbonArtifact = new CarbonArtifact();
        carbonArtifact.setGroupId(dependency.getGroupId());
        carbonArtifact.setArtifactId(dependency.getArtifactId());
        carbonArtifact.setVersion(dependency.getVersion());
        carbonArtifact.setType(dependency.getType());
        Artifact mavenArtifact = MavenUtils.getResolvedArtifact(carbonArtifact, repositorySystem,
                remoteRepositories, localRepository);
        carbonArtifact.setArtifact(mavenArtifact);
        String key;
        if (carbonArtifact.getType().equals("jar")) {
            if (resolveOSGIInfo(carbonArtifact)) {
                key = carbonArtifact.getSymbolicName() + "_" + carbonArtifact.getBundleVersion();
                bundles.put(key, carbonArtifact);
            }
        } else {
            key = carbonArtifact.getArtifactId() + "_" + carbonArtifact.getVersion();
            features.put(key, carbonArtifact);
        }
    }
    return results;
}

From source file:org.wso2.maven.pckg.prepare.PackagePrepareDefaultScopeMojo.java

License:Open Source License

private boolean updatePomFile(MavenProject cappMavenProject) {
    @SuppressWarnings("unchecked")
    List<Dependency> dependencies = cappMavenProject.getDependencies();
    for (Dependency dependency : dependencies) {
        // Set default scope
        dependency.setScope(null);/* w  w  w.  j a v  a  2s  . c o  m*/
        dependency.setSystemPath(null);
    }

    try {
        MavenUtils.saveMavenProject(cappMavenProject, cappMavenProject.getFile());
    } catch (Exception e) {
        log.error("Failed to save the pom file", e);
        return false;
    }
    log.info("All dependencies were converted to default scope");
    return true;
}

From source file:org.wso2.maven.pckg.prepare.PackagePrepareSystemScopeMojo.java

License:Open Source License

private boolean updatePomFile(MavenProject cappMavenProject) {
    @SuppressWarnings("unchecked")
    List<Dependency> dependencies = cappMavenProject.getDependencies();
    for (Dependency dependency : dependencies) {
        dependency.setScope(Artifact.SCOPE_SYSTEM);
        String absoluteSystemPath = resolveDependencySystemPath(dependency);
        if (StringUtils.isNotEmpty(absoluteSystemPath)) {
            // Derive system path relative to this CAPP project
            StringBuilder systemPathBuilder = new StringBuilder();
            systemPathBuilder.append(MavenConstants.MAVEN_BASE_DIR_PREFIX);
            systemPathBuilder.append(File.separator);
            systemPathBuilder.append(FileUtils.getRelativePath(
                    new File(cappMavenProject.getBasedir().toString()), new File(absoluteSystemPath)));

            dependency.setSystemPath(systemPathBuilder.toString());
        } else {/*from w w  w  .j a  v a 2  s . com*/
            // Reason is logged in a previous step
            return false;
        }
    }
    try {
        MavenUtils.saveMavenProject(cappMavenProject, cappMavenProject.getFile());
    } catch (Exception e) {
        log.error("Failed to save the pom file", e);
        return false;
    }
    log.info("All dependencies were converted to system scope");
    return true;
}

From source file:se.jguru.nazgul.tools.codestyle.enforcer.rules.ProjectType.java

License:Apache License

/**
 * Acquires the ProjectType instance for the provided MavenProject,
 * or throws an IllegalArgumentException holding an exception message
 * if a ProjectType could not be found for the provided MavenProject.
 *
 * @param project The MavenProject to classify.
 * @return The corresponding ProjectType.
 * @throws IllegalArgumentException if the given project could not be mapped to a [single] ProjectType.
 *                                  The exception message holds
 *///from w w w .ja v a  2 s  . c  o  m
public static ProjectType getProjectType(final MavenProject project) throws IllegalArgumentException {

    Validate.notNull(project, "Cannot handle null project argument.");

    final List<ProjectType> matches = findCandidates(project.getGroupId(), project.getArtifactId(),
            project.getPackaging(), "Incorrect project type definition for [" + project.getGroupId() + " :: "
                    + project.getArtifactId() + " :: " + project.getVersion() + "]: ");

    // Validate the internal requirements for the two different pom projects.
    final ProjectType toReturn = matches.get(0);
    switch (toReturn) {
    case PARENT:
    case ASSEMBLY:
        // This project should not contain modules.
        if (project.getModules() != null && !project.getModules().isEmpty()) {
            throw new IllegalArgumentException(
                    ProjectType.PARENT + " projects may not contain module definitions. "
                            + "(Modules are reserved for reactor projects).");
        }
        break;

    case REACTOR:
        // This project not contain dependency definitions.
        final List<?> dependencies = project.getDependencies();
        if (dependencies != null && !dependencies.isEmpty()) {
            throw new IllegalArgumentException(
                    ProjectType.REACTOR + " projects may not contain dependency definitions."
                            + " (Dependencies should be defined within parent projects).");
        }

        final DependencyManagement dependencyManagement = project.getDependencyManagement();
        if (dependencyManagement != null) {

            // Dig out all dependency management-defined dependencies.
            final List<Dependency> templateDependencies = dependencyManagement.getDependencies();
            if (templateDependencies != null && !templateDependencies.isEmpty()) {
                throw new IllegalArgumentException(
                        ProjectType.REACTOR + " projects may not contain dependency [management] definitions."
                                + " (Dependencies should be defined within parent projects).");
            }
        }
        break;

    // No action should be taken for other project types.
    default:
        break;
    }

    // All done.
    return toReturn;
}

From source file:uk.ac.ox.oucs.plugins.DiscoverMojo.java

License:Apache License

private void addToDependencies() {
    List dependencies = project.getDependencies();
    for (Artifact artifact : toDeploy) {
        getLog().info("Deploy: " + artifact.toString());
        MavenProject project = locateImplmentation(artifact.getGroupId(), artifact.getArtifactId(),
                artifact.getVersion());/*from   w ww .  ja  v a 2s  .com*/
        //deployProjectToContainer(project);
        Dependency dependency = new Dependency();
        dependency.setArtifactId(artifact.getArtifactId());
        dependency.setGroupId(artifact.getGroupId());
        dependency.setVersion(artifact.getVersion());
        dependency.setType(artifact.getType());
        dependencies.add(dependency);
    }

    project.setDependencies(dependencies);

    toDeploy = new HashSet<Artifact>();
}