当前位置: 首页>>代码示例>>Java>>正文


Java Dependency.setScope方法代码示例

本文整理汇总了Java中org.netbeans.modules.maven.model.pom.Dependency.setScope方法的典型用法代码示例。如果您正苦于以下问题:Java Dependency.setScope方法的具体用法?Java Dependency.setScope怎么用?Java Dependency.setScope使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.netbeans.modules.maven.model.pom.Dependency的用法示例。


在下文中一共展示了Dependency.setScope方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addBom

import org.netbeans.modules.maven.model.pom.Dependency; //导入方法依赖的package包/类
private void addBom(JsonNode depsMeta, String bomId) {
    JsonNode bomInfo = depsMeta.path("boms").path(bomId);
    // create dependency management section in pom if missing
    DependencyManagement depMan = model.getProject().getDependencyManagement();
    if (depMan == null) {
        depMan = model.getFactory().createDependencyManagement();
        model.getProject().setDependencyManagement(depMan);
    }
    // add a dependency with type pom and scope import
    Dependency dep = model.getFactory().createDependency();
    dep.setGroupId(bomInfo.path("groupId").asText());
    dep.setArtifactId(bomInfo.path("artifactId").asText());
    dep.setVersion(bomInfo.path("version").asText());
    dep.setType("pom");
    dep.setScope("import");
    depMan.addDependency(dep);
    // bom may require extra repositories
    if (bomInfo.hasNonNull("repositories")) {
        for (JsonNode rep : bomInfo.path("repositories")) {
            addRepository(depsMeta, rep.asText());
            addPluginRepository(depsMeta, rep.asText());
        }
    }
}
 
开发者ID:AlexFalappa,项目名称:nb-springboot,代码行数:25,代码来源:InjectSpringBootGenerator.java

示例2: addDependency

import org.netbeans.modules.maven.model.pom.Dependency; //导入方法依赖的package包/类
/**
 * 
 * @param pom       FileObject that represents POM
 * @param group     
 * @param artifact
 * @param version
 * @param type
 * @param scope
 * @param classifier
 * @param acceptNull accept null values to scope,type and classifier.
 *                   If true null values will remove corresponding tag.
 */
public static void addDependency(FileObject pom,
        final String group,
        final String artifact,
        final String version,
        final String type,
        final String scope,
        final String classifier, final boolean acceptNull)
{
    ModelOperation<POMModel> operation = new ModelOperation<POMModel>() {
        private static final String BUNDLE_TYPE = "bundle"; //NOI18N
        @Override
        public void performOperation(POMModel model) {
            Dependency dep = checkModelDependency(model, group, artifact, true);
            dep.setVersion(version);
            if (acceptNull || scope != null) {
                dep.setScope(scope);
            }
            if (acceptNull || (type != null && !BUNDLE_TYPE.equals(type))) {
                dep.setType(type);
            }
            if (acceptNull || classifier != null) {
                dep.setClassifier(classifier);
            }
        }
    };
    Utilities.performPOMModelOperations(pom, Collections.singletonList(operation));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:40,代码来源:ModelUtils.java

示例3: addRemoveJAR

import org.netbeans.modules.maven.model.pom.Dependency; //导入方法依赖的package包/类
private boolean addRemoveJAR(File jar, POMModel mdl, String scope, boolean add) throws IOException {
    if (!add) {
        throw new UnsupportedOperationException("removing JARs not yet supported");
    }
    NBVersionInfo dep = null;
    for (NBVersionInfo _dep : RepositoryQueries.findBySHA1Result(jar, RepositoryPreferences.getInstance().getRepositoryInfos()).getResults()) {
        if (!"unknown.binary".equals(_dep.getGroupId())) {
            dep = _dep;
            break;
        }
    }
    if (dep == null) {
        dep = new NBVersionInfo(null, "unknown.binary", jar.getName().replaceFirst("[.]jar$", ""), "SNAPSHOT", null, null, null, null, null);
        addJarToPrivateRepo(jar, mdl, dep);
    }
    //if not found anywhere, add to a custom file:// based repository structure within the project's directory.
    boolean added = false;
    Dependency dependency = ModelUtils.checkModelDependency(mdl, dep.getGroupId(), dep.getArtifactId(), false);
    if (dependency == null) {
        dependency = ModelUtils.checkModelDependency(mdl, dep.getGroupId(), dep.getArtifactId(), true);
        LOG.log(Level.FINE, "added new dep {0} as {1}", new Object[] {jar, dep});
        added = true;
    }
    if (!Utilities.compareObjects(dep.getVersion(), dependency.getVersion())) {
        dependency.setVersion(dep.getVersion());
        LOG.log(Level.FINE, "upgraded version on {0} as {1}", new Object[] {jar, dep});
        added = true;
    }
    if (!Utilities.compareObjects(scope, dependency.getScope())) {
        dependency.setScope(scope);
        LOG.log(Level.FINE, "changed scope on {0} as {1}", new Object[] {jar, dep});
        added = true;
    }
    return added;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:CPExtender.java

示例4: configureProject

import org.netbeans.modules.maven.model.pom.Dependency; //导入方法依赖的package包/类
@NbBundle.Messages("remove_junit3_when_adding_testng=Removing JUnit 3.x dependency as TestNG has transitive dependency to JUnit 4.x.")
public void configureProject(FileObject createdFile) {
    ClassPath cp = ClassPath.getClassPath(createdFile, ClassPath.COMPILE);
    FileObject ng = cp.findResource("org.testng.annotations.Test"); //NOI18N
    if (ng == null) {
        final Project p = FileOwnerQuery.getOwner(createdFile);
        FileObject pom = p.getProjectDirectory().getFileObject("pom.xml"); //NOI18N
        ModelOperation<POMModel> operation = new ModelOperation<POMModel>() {
            public @Override
            void performOperation(POMModel model) {
                String groupID = "org.testng"; //NOI18N
                String artifactID = "testng"; //NOI18N
                if (!hasEffectiveDependency(groupID, artifactID, p.getLookup().lookup(NbMavenProject.class))) {
                    fixJUnitDependency(model, p.getLookup().lookup(NbMavenProject.class));
                    Dependency dep = ModelUtils.checkModelDependency(model, groupID, artifactID, true);
                    dep.setVersion("6.8.1"); //NOI18N
                    dep.setScope("test"); //NOI18N
                }
            }
        };
        Utilities.performPOMModelOperations(pom, Collections.singletonList(operation));
        RequestProcessor RP = new RequestProcessor("Configure TestNG project task", 1, true); //NOI18N
        RP.post(new Runnable() {

            public void run() {
                p.getLookup().lookup(NbMavenProject.class).downloadDependencyAndJavadocSource(true);
            }
        });
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:MavenTestNGSupport.java

示例5: createDependency

import org.netbeans.modules.maven.model.pom.Dependency; //导入方法依赖的package包/类
private Dependency createDependency(org.apache.maven.model.Dependency source) {
    Dependency target = pomModel.getFactory().createDependency();
    target.setGroupId(source.getGroupId());
    target.setArtifactId(source.getArtifactId());
    target.setClassifier(source.getClassifier());
    if (!"jar".equals(source.getType())) {
        target.setType(source.getType());
    }
    target.setScope(source.getScope());
    return target;
}
 
开发者ID:jeddict,项目名称:jCode,代码行数:12,代码来源:POMManager.java

示例6: addProjects

import org.netbeans.modules.maven.model.pom.Dependency; //导入方法依赖的package包/类
@Override
protected boolean addProjects(final Project[] projects, SourceGroup sg, String classPathType) throws IOException, UnsupportedOperationException {
    final AtomicBoolean added = new AtomicBoolean();
    final AtomicBoolean nonMavenError = new AtomicBoolean();
    final String scope = findScope(sg, classPathType);
    ModelOperation<POMModel> operation = new ModelOperation<POMModel>() {
        public @Override void performOperation(POMModel model) {
            Set<Artifact> arts = project.getLookup().lookup(NbMavenProject.class).getMavenProject().getArtifacts();
            for (Project prj: projects) {
                NbMavenProject nbprj = prj.getLookup().lookup(NbMavenProject.class);
                if (nbprj != null) {
                    MavenProject mp = nbprj.getMavenProject();
                    String id = mp.getArtifact().getId();
                    for (Artifact a : arts) {
                        if (a.getId().equals(id)) {
                            //already there..
                            continue;
                        }
                    }
                    Dependency dependency = ModelUtils.checkModelDependency(model, mp.getGroupId(), mp.getArtifactId(), true);
                    dependency.setVersion(mp.getVersion());
                    if (scope != null) {
                        dependency.setScope(scope);
                    }
                    added.set(true);
                } else {
                    // unsupported usecase, not a maven project
                    nonMavenError.set(true);
                }
            }
        }
    };
    FileObject pom = project.getProjectDirectory().getFileObject(POM_XML);//NOI18N
    org.netbeans.modules.maven.model.Utilities.performPOMModelOperations(pom, Collections.singletonList(operation));
    if (nonMavenError.get()) {
        //throw late to prevent the pom model to go bust eventually
        throw new UnsupportedOperationException("Attempting to add a non-Maven project dependency to a Maven project, not supported."); //NOI18N
    }

    return added.get();

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:43,代码来源:CPExtender.java

示例7: addDeps

import org.netbeans.modules.maven.model.pom.Dependency; //导入方法依赖的package包/类
private void addDeps(String bootVersion, final Set<String> selectedDeps) throws Exception {
    logger.log(Level.INFO, "Adding Spring Boot dependencies: {0}", selectedDeps.toString());
    JsonNode depsMeta = InitializrService.getInstance().getDependencies(bootVersion);
    Iterator<Map.Entry<String, JsonNode>> it = depsMeta.path("dependencies").fields();
    int newPos = component.getCaretPosition();
    try {
        if (model.startTransaction()) {
            DependencyContainer container = model.getProject();
            // iterate on "dependencies" JSON object (fields are dependency ids)
            while (it.hasNext()) {
                Map.Entry<String, JsonNode> entry = it.next();
                if (selectedDeps.contains(entry.getKey())) {
                    JsonNode depInfo = entry.getValue();
                    String groupId = depInfo.path("groupId").asText();
                    String artifactId = depInfo.path("artifactId").asText();
                    String scope = depInfo.path("scope").asText();
                    Dependency dep = container.findDependencyById(groupId, artifactId, null);
                    if (dep == null) {
                        dep = model.getFactory().createDependency();
                        dep.setGroupId(groupId);
                        dep.setArtifactId(artifactId);
                        // set scope only if not 'compile'
                        if (!scope.equals("compile")) {
                            if (scope.equals("compileOnly")) {
                                dep.setOptional(Boolean.TRUE);
                            } else {
                                // scope is 'runtime' or 'test'
                                dep.setScope(scope);
                            }
                        }
                        // manage optional version
                        if (depInfo.hasNonNull("version")) {
                            dep.setVersion(depInfo.get("version").asText());
                        }
                        // manage optional need of extra repository
                        if (depInfo.hasNonNull("repository")) {
                            addRepository(depsMeta, depInfo.get("repository").asText());
                            addPluginRepository(depsMeta, depInfo.get("repository").asText());
                        }
                        // manage optional need of BOM inclusion
                        if (depInfo.hasNonNull("bom")) {
                            addBom(depsMeta, depInfo.get("bom").asText());
                        }
                        container.addDependency(dep);
                        newPos = model.getAccess().findPosition(dep.getPeer());
                    }
                }
            }
        }
    } finally {
        try {
            model.endTransaction();
        } catch (IllegalStateException ex) {
            StatusDisplayer.getDefault().setStatusText("Cannot write to the model: " + ex.getMessage(),
                    StatusDisplayer.IMPORTANCE_ERROR_HIGHLIGHT);
        }
    }
    component.setCaretPosition(newPos);
}
 
开发者ID:AlexFalappa,项目名称:nb-springboot,代码行数:60,代码来源:InjectSpringBootGenerator.java


注:本文中的org.netbeans.modules.maven.model.pom.Dependency.setScope方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。