Java 类org.apache.maven.model.Dependency 实例源码

项目:Reer    文件:DefaultPomDependenciesConverter.java   
public List<Dependency> convert(Conf2ScopeMappingContainer conf2ScopeMappingContainer, Set<Configuration> configurations) {
    Map<ModuleDependency, Set<Configuration>> dependencyToConfigurations = createDependencyToConfigurationsMap(configurations);
    Map<ModuleDependency, Conf2ScopeMapping> dependenciesMap = createDependencyToScopeMap(conf2ScopeMappingContainer, dependencyToConfigurations);
    Map<Dependency, Integer> dependenciesWithPriorities = new LinkedHashMap<Dependency, Integer>();
    for (ModuleDependency dependency : dependenciesMap.keySet()) {
        Conf2ScopeMapping conf2ScopeMapping = dependenciesMap.get(dependency);
        String scope = conf2ScopeMapping.getScope();
        Integer priority = conf2ScopeMapping.getPriority() == null ? 0 : conf2ScopeMapping.getPriority();
        Set<Configuration> dependencyConfigurations = dependencyToConfigurations.get(dependency);
        if (dependency.getArtifacts().size() == 0) {
            addFromDependencyDescriptor(dependenciesWithPriorities, dependency, scope, priority, dependencyConfigurations);
        } else {
            addFromArtifactDescriptor(dependenciesWithPriorities, dependency, scope, priority, dependencyConfigurations);
        }
    }
    return new ArrayList<Dependency>(dependenciesWithPriorities.keySet());
}
项目:apache-maven-shade-plugin    文件:ShadeMojo.java   
private Dependency createDependency( Artifact artifact )
{
    Dependency dep = new Dependency();
    dep.setArtifactId( artifact.getArtifactId() );
    if ( artifact.hasClassifier() )
    {
        dep.setClassifier( artifact.getClassifier() );
    }
    dep.setGroupId( artifact.getGroupId() );
    dep.setOptional( artifact.isOptional() );
    dep.setScope( artifact.getScope() );
    dep.setType( artifact.getType() );
    if ( useBaseVersion )
    {
        dep.setVersion( artifact.getBaseVersion() );
    }
    else
    {
        dep.setVersion( artifact.getVersion() );
    }
    return dep;
}
项目:Reer    文件:MavenPomFileGenerator.java   
private void addDependency(MavenDependencyInternal dependency, String artifactId, String scope, String type, String classifier) {
    Dependency mavenDependency = new Dependency();
    mavenDependency.setGroupId(dependency.getGroupId());
    mavenDependency.setArtifactId(artifactId);
    mavenDependency.setVersion(mapToMavenSyntax(dependency.getVersion()));
    mavenDependency.setType(type);
    mavenDependency.setScope(scope);
    mavenDependency.setClassifier(classifier);

    for (ExcludeRule excludeRule : dependency.getExcludeRules()) {
        Exclusion exclusion = new Exclusion();
        exclusion.setGroupId(GUtil.elvis(excludeRule.getGroup(), "*"));
        exclusion.setArtifactId(GUtil.elvis(excludeRule.getModule(), "*"));
        mavenDependency.addExclusion(exclusion);
    }

    getModel().addDependency(mavenDependency);
}
项目:EM    文件:Dependencies.java   
@SuppressWarnings("deprecation")
public Artifact asArtifact (ProjectBuildingRequest projectBuildingRequest, Dependency dependency) throws MavenExecutionException {
    DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
    coordinate.setGroupId(dependency.getGroupId());
    coordinate.setArtifactId(dependency.getArtifactId());
    coordinate.setVersion(dependency.getVersion());
    coordinate.setExtension(dependency.getType());
    coordinate.setClassifier(dependency.getClassifier());

    ArtifactResult ar;
    try {
        ar = artifactResolver.resolveArtifact(projectBuildingRequest, coordinate);
    } catch (ArtifactResolverException e) {
        throw new MavenExecutionException("Failed to resolve artifact " + coordinate, e);
    }
    return ar.getArtifact();

}
项目:incubator-netbeans    文件:AddDependencyPanel.java   
/**
 * @return 0 -> no conflicts, 1 -> conflict in version, 2 -> conflict in scope
 */
private static int findConflict (List<Dependency> deps, String groupId, String artifactId, String version, String scope) {
    if (deps == null) {
        return 0;
    }
    for (Dependency dep : deps) {
        if (artifactId != null && artifactId.equals(dep.getArtifactId()) &&
                groupId != null && groupId.equals(dep.getGroupId())) {
            if (version != null && !version.equals(dep.getVersion())) {
                return 1;
            }
            if (scope != null) {
                if (!scope.equals(dep.getScope())) {
                    return 2;
                }
            } else if (dep.getScope() != null) {
                return 2;
            }

        }
    }

    return 0;
}
项目:incubator-netbeans    文件:ArtifactDependencyIndexCreator.java   
@Override public void populateArtifactInfo(ArtifactContext context) throws IOException {
    ArtifactInfo ai = context.getArtifactInfo();
    if (ai.getClassifier() != null) {
        return;
    }
    try {
        MavenProject mp = load(ai);
        if (mp != null) {
            List<Dependency> dependencies = mp.getDependencies();
            LOG.log(Level.FINER, "Successfully loaded project model from repository for {0} with {1} dependencies", new Object[] {ai, dependencies.size()});
            dependenciesByArtifact.put(ai, dependencies);
        }
    } catch (InvalidArtifactRTException ex) {
        ex.printStackTrace();
    }
}
项目:Pogamut3    文件:AbstractFromConfigurationMojo.java   
/**
 * Tries to find missing version from a list of dependencies. If found, the
 * artifact is updated with the correct version.
 * 
 * @param artifact
 *            representing configured file.
 * @param list
 *            list of dependencies to search.
 * @param looseMatch
 *            only look at artifactId and groupId
 * @return the found dependency
 */
private boolean findDependencyVersion( ArtifactItem artifact, List list, boolean looseMatch )
{
    boolean result = false;

    for ( int i = 0; i < list.size(); i++ )
    {
        Dependency dependency = (Dependency) list.get( i );
        if ( StringUtils.equals( dependency.getArtifactId(), artifact.getArtifactId() )
            && StringUtils.equals( dependency.getGroupId(), artifact.getGroupId() )
            && ( looseMatch || StringUtils.equals( dependency.getClassifier(), artifact.getClassifier() ) )
            && ( looseMatch || StringUtils.equals( dependency.getType(), artifact.getType() ) ) )
        {

            artifact.setVersion( dependency.getVersion() );

            result = true;
            break;
        }
    }

    return result;
}
项目:Pogamut3    文件:TestUnpackMojo.java   
public List getDependencyList( ArtifactItem item )
{
    Dependency dep = new Dependency();
    dep.setArtifactId( item.getArtifactId() );
    dep.setClassifier( item.getClassifier() );
    dep.setGroupId( item.getGroupId() );
    dep.setType( item.getType() );
    dep.setVersion( "2.0-SNAPSHOT" );

    Dependency dep2 = new Dependency();
    dep2.setArtifactId( item.getArtifactId() );
    dep2.setClassifier( "classifier" );
    dep2.setGroupId( item.getGroupId() );
    dep2.setType( item.getType() );
    dep2.setVersion( "2.1" );

    List list = new ArrayList( 2 );
    list.add( dep2 );
    list.add( dep );

    return list;
}
项目:Pogamut3    文件:TestUnpackMojo.java   
public List getDependencyMgtList( ArtifactItem item )
{
    Dependency dep = new Dependency();
    dep.setArtifactId( item.getArtifactId() );
    dep.setClassifier( item.getClassifier() );
    dep.setGroupId( item.getGroupId() );
    dep.setType( item.getType() );
    dep.setVersion( "3.0-SNAPSHOT" );

    Dependency dep2 = new Dependency();
    dep2.setArtifactId( item.getArtifactId() );
    dep2.setClassifier( "classifier" );
    dep2.setGroupId( item.getGroupId() );
    dep2.setType( item.getType() );
    dep2.setVersion( "3.1" );

    List list = new ArrayList( 2 );
    list.add( dep2 );
    list.add( dep );

    return list;
}
项目:featurea    文件:MavenUtil.java   
private static void retrieveDependencyProjectsRecursively(List<MavenProject> result, MavenProject parent, ProjectBuilder projectBuilder, MavenSession session) {
    result.add(parent);
    List<Dependency> children = parent.getDependencies();
    if (children != null) {
        for (Dependency child : children) {
            if (COMPILE_SCOPE.equals(child.getScope())) {
                ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
                buildingRequest.setProject(null);
                Artifact artifact = convertDependencyToJarArtifact(child);
                try {
                    MavenProject dependencyProject = projectBuilder.build(artifact, buildingRequest).getProject();
                    retrieveDependencyProjectsRecursively(result, dependencyProject, projectBuilder, session);
                } catch (ProjectBuildingException skip) {
                    // no op
                }
            }
        }
    }
}
项目:butterfly    文件:PomAddDependencyTest.java   
/**
 * Get dependency list from a maven model. Note: This is needed because
 * {@link AbstractArtifactPomOperation#getDependencyInList(List, String, String)}
 * does not accept a version as argument.
 */
private Dependency getDependencyInList(Model model, String groupId, String artifactId, String version) {
    List<Dependency> dependencyList = model.getDependencies();
    if (dependencyList == null || dependencyList.size() == 0) {
        return null;
    }

    Dependency dependency = null;
    for (Dependency d : dependencyList) {
        if (d.getArtifactId().equals(artifactId) && d.getGroupId().equals(groupId)
                && d.getVersion().equals(version)) {
            dependency = d;
            break;
        }
    }

    return dependency;
}
项目:syndesis    文件:GenerateMetadataMojo.java   
protected void includeDependencies() {
    Stream<Artifact> artifacts;

    if (Boolean.TRUE.equals(listAllArtifacts)) {
        artifacts = project.getArtifacts().stream()
            .filter(artifact -> StringUtils.equals(artifact.getScope(), DefaultArtifact.SCOPE_PROVIDED));
    } else {
        artifacts = this.project.getDependencies().stream()
            .filter(dependency -> StringUtils.equals(dependency.getScope(), DefaultArtifact.SCOPE_PROVIDED))
            .map(this::toArtifact);
    }

    artifacts.map(Artifact::getId)
        .sorted()
        .map(io.syndesis.model.Dependency::maven)
        .forEachOrdered(extensionBuilder::addDependency);
}
项目:smart-testing    文件:DependencyResolver.java   
private void addStrategies(Model model) {

        final StrategyDependencyResolver strategyDependencyResolver = new StrategyDependencyResolver(configuration.getCustomStrategies());
        final Map<String, Dependency> dependencies = strategyDependencyResolver.resolveDependencies();
        final List<String> errorMessages = new ArrayList<>();

        configuration.autocorrectStrategies(dependencies.keySet(), errorMessages);
        errorMessages.forEach(msg -> LOGGER.error(msg));
        if (!errorMessages.isEmpty()) {
            throw new IllegalStateException("Unknown strategies (see above). Please refer to http://arquillian.org/smart-testing/#_strategies "
                + "for the list of available strategies.");
        }
        final String[] strategies = configuration.getStrategies();
        Arrays.stream(strategies).forEach(strategy -> {
            final Dependency dependency = dependencies.get(strategy);
            model.addDependency(dependency);
        });
        configuration.loadStrategyConfigurations(strategies);
    }
项目:smart-testing    文件:MavenCoordinatesResolverTest.java   
@Test
public void should_create_dependency_from_gav_with_exclusions() {
    // when
    Dependency dependency =
        MavenCoordinatesResolver.createDependencyFromCoordinates(String.join(":", groupId, artifactId, version),
            true);

    // then
    assertThat(dependency)
        .hasGroupId(groupId)
        .hasArtifactId(artifactId)
        .hasVersion(version)
        .hasType("jar")
        .hasClassifier(null)
        .exclusions().hasSize(1);
    Exclusion exclusion = dependency.getExclusions().get(0);
    Assertions.assertThat(exclusion.getGroupId()).isEqualTo("*");
    Assertions.assertThat(exclusion.getArtifactId()).isEqualTo("*");
}
项目:smart-testing    文件:MavenCoordinatesResolverTest.java   
@Test
public void should_create_dependency_from_ga_with_st_version_with_shaded_classifier() {
    // when
    Dependency dependency =
        MavenCoordinatesResolver.createDependencyFromCoordinates(
            String.join(":", groupId, artifactId, "", classifier), false);

    // then
    assertThat(dependency)
        .hasGroupId(groupId)
        .hasArtifactId(artifactId)
        .hasVersion(ExtensionVersion.version().toString())
        .hasType("jar")
        .hasClassifier(classifier)
        .exclusions().isEmpty();
}
项目:smart-testing    文件:MavenCoordinatesResolverTest.java   
@Test
public void should_create_dependency_from_whole_coordinates() {
    // when
    Dependency dependency =
        MavenCoordinatesResolver.createDependencyFromCoordinates(
            String.join(":", groupId, artifactId, packaging, classifier, version,scope), false);

    // then
    assertThat(dependency)
        .hasGroupId(groupId)
        .hasArtifactId(artifactId)
        .hasVersion(version)
        .hasType(packaging)
        .hasClassifier(classifier)
        .hasScope(scope)
        .exclusions().isEmpty();
}
项目:smart-testing    文件:StrategyDependencyResolverTest.java   
@Test
public void should_resolve_dependencies_based_on_default_property_file_when_nothing_more_is_specified() throws Exception {
    // given
    final StrategyDependencyResolver strategyDependencyResolver = new StrategyDependencyResolver();

    // when
    Map<String, Dependency> dependencies = strategyDependencyResolver.resolveDependencies();

    // then
    assertThat(dependencies.values()).hasSize(5)
        .extracting(
            dependency -> dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersion())
        .contains("org.arquillian.smart.testing:strategy-changed:" + ExtensionVersion.version().toString(),
                  "org.arquillian.smart.testing:strategy-failed:" + ExtensionVersion.version().toString(),
                  "org.arquillian.smart.testing:strategy-changed:" + ExtensionVersion.version().toString(),
                  "org.arquillian.smart.testing:strategy-affected:" + ExtensionVersion.version().toString(),
                  "org.arquillian.smart.testing:strategy-categorized:" + ExtensionVersion.version().toString());
}
项目:smart-testing    文件:StrategyDependencyResolverTest.java   
@Test
public void should_overwrite_default_version_for_new_strategy_when_system_property_is_defined()
    throws Exception {
    // given
    System.setProperty("smart.testing.strategy.new",
        "org.arquillian.smart.testing:strategy-changed:0.0.5-SNAPSHOT");

    final StrategyDependencyResolver strategyDependencyResolver = new StrategyDependencyResolver();

    // when
    Map<String, Dependency> dependencies = strategyDependencyResolver.resolveDependencies();

    // then
    assertThat(dependencies)
        .hasEntrySatisfying("new",
        dependency -> "org.arquillian.smart.testing:strategy-changed:0.0.5-SNAPSHOT".equals(
            dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersion())
    );
}
项目:smart-testing    文件:StrategyDependencyResolverTest.java   
@Test
public void should_register_custom_strategies_if_specified_as_array() {
    // given
    String[] customStrategies = new String[] { "smart.testing.strategy.cool=org.arquillian.smart.testing:strategy-cool:1.0.0" };
    final StrategyDependencyResolver strategyDependencyResolver = new StrategyDependencyResolver(customStrategies);

    // when
    Map<String, Dependency> dependencies = strategyDependencyResolver.resolveDependencies();

    // then
    assertThat(dependencies.values()).hasSize(6)
        .extracting(
            dependency -> dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersion())
        .contains("org.arquillian.smart.testing:strategy-changed:" + ExtensionVersion.version().toString(),
            "org.arquillian.smart.testing:strategy-failed:" + ExtensionVersion.version().toString(),
            "org.arquillian.smart.testing:strategy-affected:" + ExtensionVersion.version().toString(),
            "org.arquillian.smart.testing:strategy-categorized:" + ExtensionVersion.version().toString(),
            "org.arquillian.smart.testing:strategy-cool:1.0.0");
}
项目:smart-testing    文件:StrategyDependencyResolverTest.java   
@Test
public void should_register_last_custom_strategy_with_same_name() {
    // given
    String[] customStrategies =
        new String[] {"smart.testing.strategy.cool=org.arquillian.smart.testing:strategy-cool:1.0.0",
            "smart.testing.strategy.cool=org.arquillian.smart.testing:strategy-cool:1.0.1"};
    final StrategyDependencyResolver strategyDependencyResolver = new StrategyDependencyResolver(customStrategies);

    // when
    Map<String, Dependency> dependencies = strategyDependencyResolver.resolveDependencies();

    // then
    assertThat(dependencies.values()).hasSize(6)
        .extracting(
            dependency -> dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersion())
        .contains("org.arquillian.smart.testing:strategy-changed:" + ExtensionVersion.version().toString(),
            "org.arquillian.smart.testing:strategy-failed:" + ExtensionVersion.version().toString(),
            "org.arquillian.smart.testing:strategy-affected:" + ExtensionVersion.version().toString(),
            "org.arquillian.smart.testing:strategy-categorized:" + ExtensionVersion.version().toString(),
            "org.arquillian.smart.testing:strategy-cool:1.0.1");
}
项目:gemnasium-maven-plugin    文件:ProjectsUtils.java   
public static ArrayNode getJsonDependencies(List<Artifact> artifacts, List<Dependency> directDependencies) {
    HashMap<String, String> requirements = new HashMap<String, String>(directDependencies.size());
    for (Dependency dep : directDependencies) {
        requirements.put(dep.getGroupId() + ":" + dep.getArtifactId(), dep.getVersion());
    }

    ObjectMapper mapper = new ObjectMapper();
    ArrayNode arrayNode = mapper.createArrayNode();
    for (Artifact art : artifacts) {
        ObjectNode artNode = depToJsonNode(mapper, art);
        String requirement;
        requirement = requirements.get(art.getGroupId() + ":" + art.getArtifactId());
        // Temporary workaround for transitive dependencies
        if (requirement == null){
            requirement = art.getVersion();
        }
        artNode.put("requirement", requirement);
        arrayNode.add(artNode);
    }
    return arrayNode;
}
项目:apache-maven-shade-plugin    文件:MavenJDOMWriter.java   
/**
 * Method updateDependency
 *
 * @param value
 * @param element
 * @param counter
 * @param xmlTag
 */
protected void updateDependency( Dependency value, String xmlTag, Counter counter, Element element )
{
    Element root = element;
    Counter innerCount = new Counter( counter.getDepth() + 1 );
    findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), null );
    findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
    findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
    findAndReplaceSimpleElement( innerCount, root, "type", value.getType(), "jar" );
    findAndReplaceSimpleElement( innerCount, root, "classifier", value.getClassifier(), null );
    findAndReplaceSimpleElement( innerCount, root, "scope", value.getScope(), null );
    findAndReplaceSimpleElement( innerCount, root, "systemPath", value.getSystemPath(), null );
    iterateExclusion( innerCount, root, value.getExclusions(), "exclusions", "exclusion" );
    findAndReplaceSimpleElement( innerCount, root, "optional",
                                 !value.isOptional() ? null : String.valueOf( value.isOptional() ), "false" );
}
项目:Reer    文件:DefaultMavenPom.java   
@SuppressWarnings("unchecked")
public List<Dependency> getGeneratedDependencies() {
    if (configurations == null) {
        return Collections.emptyList();
    }
    return (List<Dependency>) pomDependenciesConverter.convert(getScopeMappings(), configurations);
}
项目:Reer    文件:DefaultPomDependenciesConverter.java   
private void addFromArtifactDescriptor(Map<Dependency, Integer> dependenciesPriorityMap,
                                       ModuleDependency dependency, String scope, Integer priority,
                                       Set<Configuration> configurations) {
    for (DependencyArtifact artifact : dependency.getArtifacts()) {
        addMavenDependencies(dependenciesPriorityMap, dependency, artifact.getName(), artifact.getType(), scope, artifact.getClassifier(), priority, configurations);
    }
}
项目:featurea    文件:MavenUtil.java   
private static Artifact convertDependencyToJarArtifact(Dependency dependency) {
    String groupId = dependency.getGroupId();
    String artifactId = dependency.getArtifactId();
    String version = dependency.getVersion();
    String scope = dependency.getScope();
    String type = dependency.getType();
    String classifier = dependency.getClassifier();
    DefaultArtifact artifact = new DefaultArtifact(groupId, artifactId, version, scope, type, classifier, JAR_ARTIFACT_HANDLER);
    return artifact;
}
项目:athena    文件:YangPluginUtils.java   
/**
 * Returns list of jar path.
 *
 * @param project         maven project
 * @param localRepository local repository
 * @param remoteRepos     remote repository
 * @return list of jar paths
 */
private static List<String> resolveDependecyJarPath(MavenProject project, ArtifactRepository localRepository,
                                                    List<ArtifactRepository> remoteRepos) {

    StringBuilder path = new StringBuilder();
    List<String> jarPaths = new ArrayList<>();
    for (Dependency dependency : project.getDependencies()) {

        path.append(localRepository.getBasedir());
        path.append(SLASH);
        path.append(getPackageDirPathFromJavaJPackage(dependency.getGroupId()));
        path.append(SLASH);
        path.append(dependency.getArtifactId());
        path.append(SLASH);
        path.append(dependency.getVersion());
        path.append(SLASH);
        path.append(dependency.getArtifactId() + HYPHEN + dependency.getVersion() + PERIOD + JAR);
        File jarFile = new File(path.toString());
        if (jarFile.exists()) {
            jarPaths.add(path.toString());
        }
        path.delete(0, path.length());
    }

    for (ArtifactRepository repo : remoteRepos) {
        // TODO: add resolver for remote repo.
    }
    return jarPaths;
}
项目:incubator-netbeans    文件:DependencyNode.java   
public boolean isManaged() {
    DependencyManagement dm = project.getLookup().lookup(NbMavenProject.class).getMavenProject().getDependencyManagement();
    if (dm != null) {
        List<Dependency> dmList = dm.getDependencies();
        for (Dependency d : dmList) {
            if (art.getGroupId().equals(d.getGroupId())
                    && art.getArtifactId().equals(d.getArtifactId())) {
                return true;
            }
        }
    }
    return false;
}
项目:incubator-netbeans    文件:DependencyNode.java   
@Override
public void actionPerformed(ActionEvent event) {
    final Collection<? extends Artifact> artifacts = lkp.lookupAll(Artifact.class);
    if (artifacts.isEmpty()) {
        return;
    }
    Collection<? extends NbMavenProjectImpl> res = lkp.lookupAll(NbMavenProjectImpl.class);
    Set<NbMavenProjectImpl> prjs = new HashSet<NbMavenProjectImpl>(res);
    if (prjs.size() != 1) {
        return;
    }

    final NbMavenProjectImpl project = prjs.iterator().next();
    final List<Artifact> unremoved = new ArrayList<Artifact>();

    final ModelOperation<POMModel> operation = new ModelOperation<POMModel>() {
        @Override
        public void performOperation(POMModel model) {
            for (Artifact art : artifacts) {
                org.netbeans.modules.maven.model.pom.Dependency dep =
                        model.getProject().findDependencyById(art.getGroupId(), art.getArtifactId(), null);
                if (dep != null) {
                    model.getProject().removeDependency(dep);
                } else {
                    unremoved.add(art);
                }
            }
        }
    };
    RP.post(new Runnable() {
        @Override
        public void run() {
            FileObject fo = FileUtil.toFileObject(project.getPOMFile());
            Utilities.performPOMModelOperations(fo, Collections.singletonList(operation));
            if (unremoved.size() > 0) {
                StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(DependencyNode.class, "MSG_Located_In_Parent", unremoved.size()), Integer.MAX_VALUE);
            }
        }
    });
}
项目:incubator-netbeans    文件:DependencyNode.java   
private Relocation getRelocation(org.netbeans.modules.maven.model.pom.Dependency d) {
    ProjectBuildingRequest dpbr = EmbedderFactory.getProjectEmbedder().createMavenExecutionRequest().getProjectBuildingRequest();
    dpbr.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
    dpbr.setProcessPlugins(false);
    dpbr.setResolveDependencies(false);
    ArrayList<ArtifactRepository> remoteRepos = new ArrayList<>();
    dpbr.setRemoteRepositories(remoteRepos);
    String groupId = d.getGroupId();
    String artifactId = d.getArtifactId();
    String version = d.getVersion();
    if(groupId != null && !"".equals(groupId.trim()) &&
       artifactId != null && !"".equals(artifactId.trim()) &&
       version != null && !"".equals(version.trim())) 
    {           
        MavenEmbedder embedder = EmbedderFactory.getProjectEmbedder();
        Artifact a = embedder.createProjectArtifact(groupId, artifactId, version);
        try {
            ProjectBuildingResult r = embedder.buildProject(a, dpbr);
            DistributionManagement dm = r.getProject().getDistributionManagement();
            return dm != null ? dm.getRelocation() : null;
        } catch (ProjectBuildingException ex) {
            // just log and hope for the best ...
            Logger.getLogger(DependencyNode.class.getName()).log(Level.INFO, version, ex);                
        }
    }
    return null;
}
项目:incubator-netbeans    文件:AddDependencyPanel.java   
private static List<Dependency> getDependenciesFromDM(MavenProject project, Project nbprj) {
    NbMavenProjectImpl p = nbprj.getLookup().lookup(NbMavenProjectImpl.class);
    MavenProject localProj = project;
    DependencyManagement curDM;
    List<Dependency> result = new ArrayList<Dependency>();
    //mkleint: without the managementKey checks I got some entries multiple times.
    // do we actually need to traverse the parent poms, are they completely resolved anyway?
    //XXX
    Set<String> knownKeys = new HashSet<String>();

    while (localProj != null) {
        curDM = localProj.getDependencyManagement();
        if (curDM != null) {
            @SuppressWarnings("unchecked")
            List<Dependency> ds = curDM.getDependencies();
            for (Dependency d : ds) {
                if (knownKeys.contains(d.getManagementKey())) {
                    continue;
                }
                result.add(d);
                knownKeys.add(d.getManagementKey());
            }
        }
        try {
            localProj = p.loadParentOf(EmbedderFactory.getProjectEmbedder(), localProj);
        } catch (ProjectBuildingException x) {
            break;
        }
    }
    Collections.sort(result, new Comparator<Dependency>() {

        @Override
        public int compare(Dependency o1, Dependency o2) {
            return o1.getManagementKey().compareTo(o2.getManagementKey());
        }
    });
    return result;
}
项目:incubator-netbeans    文件:LocationAwareMavenXpp3Writer.java   
private void writeDependencyManagement(DependencyManagement dependencyManagement, String tagName, XmlSerializer serializer)
        throws java.io.IOException {
    serializer.startTag(NAMESPACE, tagName);
    if ((dependencyManagement.getDependencies() != null) && (dependencyManagement.getDependencies().size() > 0)) {
        serializer.startTag(NAMESPACE, "dependencies");
        for (Iterator iter = dependencyManagement.getDependencies().iterator(); iter.hasNext();) {
            Dependency o = (Dependency) iter.next();
            writeDependency(o, "dependency", serializer);
        }
        serializer.endTag(NAMESPACE, "dependencies");
    }
    serializer.endTag(NAMESPACE, tagName);
}
项目:incubator-netbeans    文件:MavenNbmGrammar.java   
@Override
protected Enumeration<GrammarResult> getDynamicValueCompletion(String path, HintContext hintCtx, Element lowestParent) {
    if ("/nbm/dependencies/dependency/type".equals(path)) { //NOI18N
        return createTextValueList(new String[] {
            "spec", //NOI18N
            "impl", //NOI18N
            "loose" //NOI18N
            }, hintCtx);
    }
    if ("/nbm/moduleType".equals(path)) { //NOI18N
        return createTextValueList(new String[] {
            "normal", //NOI18N
            "autoload", //NOI18N
            "eager" //NOI18N
            }, hintCtx);

    }
    if ("/nbm/dependencies/dependency/id".equals(path) || //NOI18N
        "/nbm/libraries/library".equals(path)) { //NOI18N
        //TODO could be nice to filter out the dependencies that are already being used..
        List<GrammarResult> toRet = new ArrayList<GrammarResult>();
        MavenProject project = getMavenProject();
        if (project != null) {
            @SuppressWarnings("unchecked")
            Iterator<Dependency> it = project.getCompileDependencies().iterator();
            while (it.hasNext()) {
                Dependency elem = it.next();
                String str = elem.getGroupId() + ":" + elem.getArtifactId(); //NOI18N
                if (str.startsWith(hintCtx.getCurrentPrefix())) {
                    toRet.add(new MyTextElement(str, hintCtx.getCurrentPrefix()));
                }
            }
        }
        return Collections.enumeration(toRet);
    }
    return null;
}
项目:incubator-netbeans    文件:GraphConstructor.java   
private int obtainManagedState(MavenDependencyNode dependencyNode) {        
    if (proj == null) {
        return GraphNode.UNMANAGED;
    }

    DependencyManagement dm = proj.getDependencyManagement();
    if (dm == null) {
        return GraphNode.UNMANAGED;
    }

    @SuppressWarnings("unchecked")
    List<Dependency> deps = dm.getDependencies();
    if (deps == null) {
        return GraphNode.UNMANAGED;
    }

    Artifact artifact = dependencyNode.getArtifact();
    String id = artifact.getArtifactId();
    String groupId = artifact.getGroupId();
    String version = artifact.getVersion();

    for (Dependency dep : deps) {
        if (id.equals(dep.getArtifactId()) && groupId.equals(dep.getGroupId())) {
            if (!version.equals(dep.getVersion())) {
                return GraphNode.OVERRIDES_MANAGED;
            } else {
                return GraphNode.MANAGED;
            }
        }
    }

    return GraphNode.UNMANAGED;
}
项目:incubator-netbeans    文件:SearchDependencyUI.java   
private HeuristicsComparator() {
    String packaging = project.getLookup().lookup(NbMavenProject.class).getPackagingType();
    if (NbMavenProject.TYPE_NBM.equalsIgnoreCase(packaging)) {
        privilegedGroupIds.add("org.netbeans.api"); //NOI18N
    }
    if (NbMavenProject.TYPE_WAR.equalsIgnoreCase(packaging) || 
        NbMavenProject.TYPE_EAR.equalsIgnoreCase(packaging) || 
        NbMavenProject.TYPE_EJB.equalsIgnoreCase(packaging)) {
        privilegedGroupIds.add("javax.activation");//NOI18N
        privilegedGroupIds.add("javax.ejb");//NOI18N
        privilegedGroupIds.add("javax.faces");//NOI18N
        privilegedGroupIds.add("javax.j2ee");//NOI18N
        privilegedGroupIds.add("javax.jdo");//NOI18N
        privilegedGroupIds.add("javax.jms");//NOI18N
        privilegedGroupIds.add("javax.mail");//NOI18N
        privilegedGroupIds.add("javax.management");//NOI18N
        privilegedGroupIds.add("javax.naming");//NOI18N
        privilegedGroupIds.add("javax.persistence");//NOI18N
        privilegedGroupIds.add("javax.portlet");//NOI18N
        privilegedGroupIds.add("javax.resource");//NOI18N
        privilegedGroupIds.add("javax.security");//NOI18N
        privilegedGroupIds.add("javax.servlet");//NOI18N
        privilegedGroupIds.add("javax.sql");//NOI18N
        privilegedGroupIds.add("javax.transaction");//NOI18N
        privilegedGroupIds.add("javax.xml");//NOI18N
    }
    //TODO add some more heuristics
    NbMavenProject mavenproject = project.getLookup().lookup(NbMavenProject.class);
    List<Dependency> deps = mavenproject.getMavenProject().getDependencies();
    for (Dependency d : deps) {
        privilegedGroupIds.add(d.getGroupId());
    }
}
项目:incubator-netbeans    文件:SearchClassDependencyInRepo.java   
private Collection<NBVersionInfo> filter(NbMavenProject mavProj, List<NBVersionInfo> nbvis, boolean test) {


        Map<String, NBVersionInfo> items = new HashMap<String, NBVersionInfo>();
        //check dependency already added
        List<Dependency> dependencies = new ArrayList<Dependency>();
        MavenProject prj = mavProj.getMavenProject();
        if (test) {
            dependencies.addAll(prj.getTestDependencies());
        } else {
            dependencies.addAll(prj.getDependencies());
        }

        for (NBVersionInfo info : nbvis) {
            String key = info.getGroupId() + ":" + info.getArtifactId();

            boolean b = items.containsKey(key);
            if (!b) {
                items.put(key, info);
            }
            for (Dependency dependency : dependencies) {
                //check group id and ArtifactId and Scope even
                if (dependency.getGroupId() != null && dependency.getGroupId().equals(info.getGroupId())) {
                    if (dependency.getArtifactId() != null && dependency.getArtifactId().equals(info.getArtifactId())) {
                        if (!test && dependency.getScope() != null && ("compile".equals(dependency.getScope()))) {//NOI18N

                            return Collections.emptyList();
                        }
                    }
                }
            }

        }
        List<NBVersionInfo> filterd = new ArrayList<NBVersionInfo>(items.values());

        return filterd;

    }
项目:incubator-netbeans    文件:ArtifactDependencyIndexCreator.java   
@Override public void updateDocument(ArtifactInfo ai, Document doc) {
    List<Dependency> dependencies = dependenciesByArtifact.get(ai);
    if (dependencies != null) {
        for (Dependency d : dependencies) {
            doc.add(FLD_NB_DEPENDENCY_GROUP.toField(d.getGroupId()));
            doc.add(FLD_NB_DEPENDENCY_ARTIFACT.toField(d.getArtifactId()));
            doc.add(FLD_NB_DEPENDENCY_VERSION.toField(d.getVersion()));
        }
    }
}
项目:butterfly    文件:PomRemoveManagedDependency.java   
@Override
protected TOExecutionResult pomExecution(String relativePomFile, Model model) {
    TOExecutionResult result = null;
    String details;

    Dependency dependency = getManagedDependency(model, groupId, artifactId);
    if (dependency != null) {
        model.getDependencyManagement().removeDependency(dependency);
        details = String.format("Managed dependency %s:%s has been removed from POM file %s", groupId, artifactId, relativePomFile);
        result = TOExecutionResult.success(this, details);
    } else {
        details = String.format("Managed dependency %s:%s has NOT been removed from POM file %s because it is not present", groupId, artifactId, relativePomFile);
        switch (ifNotPresent) {
            case Warn:
                result = TOExecutionResult.warning(this, new TransformationOperationException(details));
                break;
            case NoOp:
                result = TOExecutionResult.noOp(this, details);
                break;
            case Fail:
                // Fail is the default
            default:
                result = TOExecutionResult.error(this, new TransformationOperationException(details));
                break;
        }
    }

    return result;
}
项目:butterfly    文件:PomRemoveDependency.java   
@Override
protected TOExecutionResult pomExecution(String relativePomFile, Model model) {
    TOExecutionResult result = null;
    String details;

    Dependency dependency = getDependency(model, groupId, artifactId);
    if (dependency != null) {
        model.removeDependency(dependency);
        details = String.format("Dependency %s:%s has been removed from POM file %s", groupId, artifactId, relativePomFile);
        result = TOExecutionResult.success(this, details);
    } else {
        details = String.format("Dependency %s:%s has NOT been removed from POM file %s because it is not present", groupId, artifactId, relativePomFile);
        switch (ifNotPresent) {
            case Warn:
                result = TOExecutionResult.warning(this, new TransformationOperationException(details));
                break;
            case NoOp:
                result = TOExecutionResult.noOp(this, details);
                break;
            case Fail:
                // Fail is the default
            default:
                result = TOExecutionResult.error(this, new TransformationOperationException(details));
                break;
        }
    }

    return result;
}
项目:butterfly    文件:PomChangeDependency.java   
@Override
protected TOExecutionResult pomExecution(String relativePomFile, Model model) {
    TOExecutionResult result;

    Dependency dependency = getDependency(model, groupId, artifactId);
    if (dependency != null) {
        model.removeDependency(dependency);

        if (removeVersion) dependency.setVersion(null); else if (version != null) dependency.setVersion(version);
        if (removeScope) dependency.setScope(null); else if (scope != null) dependency.setScope(scope);
        if (removeType) dependency.setType(null); else if (type != null) dependency.setType(type);
        if (removeOptional) dependency.setOptional(null); else dependency.setOptional(optional);

        model.addDependency(dependency);

        String details = String.format("Dependency %s:%s has been changed in %s", groupId, artifactId, getRelativePath());
        result = TOExecutionResult.success(this, details);
    } else {
        String message = String.format("Dependency %s:%s is not present in %s", groupId, artifactId, getRelativePath());

        switch (ifNotPresent) {
            case Warn:
                result = TOExecutionResult.warning(this, new TransformationOperationException(message));
                break;
            case NoOp:
                result = TOExecutionResult.noOp(this, message);
                break;
            case Fail:
                // Fail is the default
            default:
                result = TOExecutionResult.error(this, new TransformationOperationException(message));
                break;
        }
    }

    return result;
}
项目:butterfly    文件:AbstractArtifactPomOperation.java   
private Dependency getDependencyInList(List<Dependency> dependencyList, String groupId, String artifactId) {
    if (dependencyList == null || dependencyList.size() == 0) {
        return null;
    }

    Dependency dependency = null;
    for (Dependency d : dependencyList) {
        if(d.getArtifactId().equals(artifactId) && d.getGroupId().equals(groupId)) {
            dependency = d;
            break;
        }
    }

    return dependency;
}