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


Java Model类代码示例

本文整理汇总了Java中org.apache.maven.model.Model的典型用法代码示例。如果您正苦于以下问题:Java Model类的具体用法?Java Model怎么用?Java Model使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: CustomModelBuilder

import org.apache.maven.model.Model; //导入依赖的package包/类
public CustomModelBuilder(Model model) {
    ExecuteManager executeManager = new ExecuteManagerImpl();
    setProp(executeManager.getClass(), executeManager, "log",
            new PlexusLoggerAdapter(LoggerFactory.getLogger(ExecuteManagerImpl.class)));
    setProp(ModelBuilder.class, this, "executeManager", executeManager);
    setProp(ModelBuilder.class, this, "log",
            new PlexusLoggerAdapter(LoggerFactory.getLogger(ModelBuilder.class)));
    try {
        initialize();
    } catch (InitializationException e) {
        throw new RuntimeException(e);
    }
    Map factories = (Map) getProp(FactoryBuilderSupport.class, this, "factories");
    factories.remove("project");
    ModelFactory modelFactory = new ModelFactory(model);
    registerFactory(modelFactory.getName(), null, modelFactory);
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:18,代码来源:CustomModelBuilder.java

示例2: addStrategies

import org.apache.maven.model.Model; //导入依赖的package包/类
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);
    }
 
开发者ID:arquillian,项目名称:smart-testing,代码行数:20,代码来源:DependencyResolver.java

示例3: should_remove_custom_provider_dependency_and_create_info_file_when_set_in_config

import org.apache.maven.model.Model; //导入依赖的package包/类
@Test
public void should_remove_custom_provider_dependency_and_create_info_file_when_set_in_config() {
    // given
    Configuration config = ConfigurationLoader.load(tmpFolder);
    config.setCustomProviders(new String[] {"org.foo.provider:my-custom-provider=org.foo.impl.SurefireProvider"});
    DependencyResolver dependencyResolver = new DependencyResolver(config);
    Dependency customDep = createDependency("org.foo.provider", "my-custom-provider", "1.2.3");
    Model model = Mockito.mock(Model.class);
    Plugin plugin = prepareModelWithPluginDep(model, customDep);

    // when
    dependencyResolver.removeAndRegisterFirstCustomProvider(model, plugin);

    // then
    verifyDependencyIsRemovedAndFileCreated(plugin, customDep, "org.foo.impl.SurefireProvider");
}
 
开发者ID:arquillian,项目名称:smart-testing,代码行数:17,代码来源:CustomProvidersTest.java

示例4: createModelLineage

import org.apache.maven.model.Model; //导入依赖的package包/类
/**
     * Creates a list of POM models in an inheritance lineage.
     * Each resulting model is "raw", so contains no interpolation or inheritance.
     * In particular beware that groupId and/or version may be null if inherited from a parent; use {@link Model#getParent} to resolve.
     * Internally calls <code>executeModelBuilder</code> so if you need to call both just use the execute method.
     * @param pom a POM to inspect
     * @param embedder an embedder to use
     * @return a list of models, starting with the specified POM, going through any parents, finishing with the Maven superpom (with a null artifactId)
     * @throws ModelBuildingException if the POM or parents could not even be parsed; warnings are not reported
     */
    public List<Model> createModelLineage(File pom) throws ModelBuildingException {
        ModelBuildingResult res = executeModelBuilder(pom);
        List<Model> toRet = new ArrayList<Model>();

        for (String id : res.getModelIds()) {
            Model m = res.getRawModel(id);
            normalizePath(m);
            toRet.add(m);
        }
//        for (ModelProblem p : res.getProblems()) {
//            System.out.println("problem=" + p);
//            if (p.getException() != null) {
//                p.getException().printStackTrace();
//            }
//        }
        return toRet;
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:MavenEmbedder.java

示例5: build

import org.apache.maven.model.Model; //导入依赖的package包/类
@Override
public ModelBuildingResult build(ModelBuildingRequest request) throws ModelBuildingException {
    ModelBuildingResult toRet = super.build(request);
    Model eff = toRet.getEffectiveModel();
    InputSource source = new InputSource();
    source.setLocation("");
    InputLocation location = new InputLocation(-1, -1, source);
    eff.setLocation(NETBEANS_PROFILES, location);
    for (String id : toRet.getModelIds()) {
        Model mdl = toRet.getRawModel(id);
        for (Profile p : mdl.getProfiles()) {
            source.setLocation(source.getLocation() + "|" + p.getId());
        }
    }
    return toRet;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:NBModelBuilder.java

示例6: write

import org.apache.maven.model.Model; //导入依赖的package包/类
public static void write( Writer w, Model newModel, boolean namespaceDeclaration )
    throws IOException
{
    Element root = new Element( "project" );

    if ( namespaceDeclaration )
    {
        String modelVersion = newModel.getModelVersion();

        Namespace pomNamespace = Namespace.getNamespace( "", "http://maven.apache.org/POM/" + modelVersion );

        root.setNamespace( pomNamespace );

        Namespace xsiNamespace = Namespace.getNamespace( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );

        root.addNamespaceDeclaration( xsiNamespace );

        if ( root.getAttribute( "schemaLocation", xsiNamespace ) == null )
        {
            root.setAttribute( "schemaLocation",
                               "http://maven.apache.org/POM/" + modelVersion + " http://maven.apache.org/maven-v"
                                   + modelVersion.replace( '.', '_' ) + ".xsd", xsiNamespace );
        }
    }

    Document doc = new Document( root );

    MavenJDOMWriter writer = new MavenJDOMWriter();

    String encoding = newModel.getModelEncoding() != null ? newModel.getModelEncoding() : "UTF-8";

    Format format = Format.getPrettyFormat().setEncoding( encoding );

    writer.write( newModel, doc, w, format );
}
 
开发者ID:javiersigler,项目名称:apache-maven-shade-plugin,代码行数:36,代码来源:PomWriter.java

示例7: ModelTree

import org.apache.maven.model.Model; //导入依赖的package包/类
/**
     * This is a tree of Maven artifacts, which are represented by {@link Model} objects.
     * The idea here is, given a list of Maven pom.xml {@link File} objects, create a tree
     * based on dependency among them, but specifying explicitly which Maven artifact should
     * be at the root of the tree. That means, if any artifact in the list is not a child,
     * directly or indirectly, of the root artifact, then it will end up no being in the tree.
     * <br>
     * As a result of building this tree, it is possible to know, out of the initial pom.xml files list,
     * which ones actually inherit, directly or not, from the root artifact. The result is retrieved
     * by calling {@link #getPomFilesInTree()}
     *
     * @param rootGroupId the group id of the artifact that should be at the root of the tree
     * @param rootArtifactId the artifact id of the artifact that should be at the root of the tree
     * @param rootVersion the version of the artifact that should be at the root of the tree
     * @param pomFiles a list of pom.xml files used to make the tree
     */
    public ModelTree(String rootGroupId, String rootArtifactId, String rootVersion, List<File> pomFiles) {
        Model rootModel = new Model();
        rootModel.setGroupId(rootGroupId);
        rootModel.setArtifactId(rootArtifactId);
        rootModel.setVersion(rootVersion);

        List<Model> models = new ArrayList<>();
        models.add(rootModel);

        for (File pomFile : pomFiles) {
            models.add(createModel(pomFile));
        }

// TODO we can comment this out in the future if we need this feature
//        modelsNotInTree = add(models);
        add(models);
    }
 
开发者ID:paypal,项目名称:butterfly,代码行数:34,代码来源:ModelTree.java

示例8: changeVersionTest

import org.apache.maven.model.Model; //导入依赖的package包/类
@Test
public void changeVersionTest() throws IOException, XmlPullParserException {
    Model pomModelBeforeChange = getOriginalPomModel("pom.xml");
    assertEquals(pomModelBeforeChange.getParent().getVersion(), "1.0");

    PomChangeParent pomChangeParent = new PomChangeParent("2.0").relative("pom.xml");

    assertNull(pomChangeParent.getGroupId());
    assertNull(pomChangeParent.getArtifactId());
    assertEquals(pomChangeParent.getVersion(), "2.0");

    TOExecutionResult executionResult = pomChangeParent.execution(transformedAppFolder, transformationContext);
    assertEquals(executionResult.getType(), TOExecutionResult.Type.SUCCESS);
    assertEquals(pomChangeParent.getDescription(), "Change parent artifact in POM file pom.xml");
    assertNull(executionResult.getException());

    Model pomModelAfterChange = getTransformedPomModel("pom.xml");
    assertEquals(pomModelAfterChange.getParent().getVersion(), "2.0");
}
 
开发者ID:paypal,项目名称:butterfly,代码行数:20,代码来源:PomChangeParentTest.java

示例9: changeParentTest

import org.apache.maven.model.Model; //导入依赖的package包/类
@Test
public void changeParentTest() throws IOException, XmlPullParserException {
    Model pomModelBeforeChange = getOriginalPomModel("pom.xml");

    assertEquals(pomModelBeforeChange.getParent().getGroupId(), "com.test");
    assertEquals(pomModelBeforeChange.getParent().getArtifactId(), "foo-parent");
    assertEquals(pomModelBeforeChange.getParent().getVersion(), "1.0");

    PomChangeParent pomChangeParent = new PomChangeParent().setGroupId("com.newgroupid").setArtifactId("newartifactid").setVersion("2.0").relative("pom.xml");

    assertEquals(pomChangeParent.getGroupId(), "com.newgroupid");
    assertEquals(pomChangeParent.getArtifactId(), "newartifactid");
    assertEquals(pomChangeParent.getVersion(), "2.0");


    TOExecutionResult executionResult = pomChangeParent.execution(transformedAppFolder, transformationContext);
    assertEquals(executionResult.getType(), TOExecutionResult.Type.SUCCESS);
    assertEquals(pomChangeParent.getDescription(), "Change parent artifact in POM file pom.xml");
    assertNull(executionResult.getException());

    Model pomModelAfterChange = getTransformedPomModel("pom.xml");
    assertEquals(pomModelAfterChange.getParent().getGroupId(), "com.newgroupid");
    assertEquals(pomModelAfterChange.getParent().getArtifactId(), "newartifactid");
    assertEquals(pomModelAfterChange.getParent().getVersion(), "2.0");
}
 
开发者ID:paypal,项目名称:butterfly,代码行数:26,代码来源:PomChangeParentTest.java

示例10: failTest

import org.apache.maven.model.Model; //导入依赖的package包/类
@Test
public void failTest() throws IOException, XmlPullParserException, CloneNotSupportedException {
    Model pomModelBeforeChange = getOriginalPomModel("/src/main/resources/no_parent_pom.xml");
    assertNull(pomModelBeforeChange.getParent());

    PomChangeParent pomChangeParent = new PomChangeParent("2.0").relative("/src/main/resources/no_parent_pom.xml");

    assertNull(pomChangeParent.getGroupId());
    assertNull(pomChangeParent.getArtifactId());
    assertEquals(pomChangeParent.getVersion(), "2.0");

    TOExecutionResult executionResult = pomChangeParent.execution(transformedAppFolder, transformationContext);
    assertEquals(executionResult.getType(), TOExecutionResult.Type.ERROR);
    assertEquals(pomChangeParent.getDescription(), "Change parent artifact in POM file /src/main/resources/no_parent_pom.xml");
    assertEquals(executionResult.getException().getClass(), TransformationOperationException.class);
    assertEquals(executionResult.getException().getMessage(), "Pom file /src/main/resources/no_parent_pom.xml does not have a parent");

    Model pomModelAfterChange = getTransformedPomModel("/src/main/resources/no_parent_pom.xml");
    assertNull(pomModelAfterChange.getParent());

    executionResult = pomChangeParent.clone().failIfNotPresent().execution(transformedAppFolder, transformationContext);
    assertEquals(executionResult.getType(), TOExecutionResult.Type.ERROR);
}
 
开发者ID:paypal,项目名称:butterfly,代码行数:24,代码来源:PomChangeParentTest.java

示例11: invalidOperationTest

import org.apache.maven.model.Model; //导入依赖的package包/类
@Test
public void invalidOperationTest() throws IOException, XmlPullParserException {
    // You have to either set the version only, or the group id AND artifact id AND version.
    // Here only the group id is being set
    PomChangeParent pomChangeParent = new PomChangeParent().setGroupId("com.test").relative("pom.xml");

    assertEquals(pomChangeParent.getGroupId(), "com.test");
    assertNull(pomChangeParent.getArtifactId());
    assertNull(pomChangeParent.getVersion());

    TOExecutionResult executionResult = pomChangeParent.execution(transformedAppFolder, transformationContext);
    assertEquals(executionResult.getType(), TOExecutionResult.Type.ERROR);
    assertEquals(pomChangeParent.getDescription(), "Change parent artifact in POM file pom.xml");
    assertEquals(executionResult.getException().getClass(), TransformationOperationException.class);
    assertEquals(executionResult.getException().getMessage(), "Invalid POM parent transformation operation");

    Model pomModelAfterChange = getTransformedPomModel("pom.xml");
    assertEquals(pomModelAfterChange.getParent().getGroupId(), "com.test");
    assertEquals(pomModelAfterChange.getParent().getArtifactId(), "foo-parent");
    assertEquals(pomModelAfterChange.getParent().getVersion(), "1.0");
}
 
开发者ID:paypal,项目名称:butterfly,代码行数:22,代码来源:PomChangeParentTest.java

示例12: addPluginWithVersionTest

import org.apache.maven.model.Model; //导入依赖的package包/类
@Test
public void addPluginWithVersionTest() throws IOException, XmlPullParserException {
	Model pomModelBeforeChange = getOriginalPomModel("pom.xml");
	assertEquals(pomModelBeforeChange.getBuild().getPlugins().size(), 1);
	assertEquals(pomModelBeforeChange.getBuild().getPlugins().get(0).getGroupId(), "org.codehaus.mojo");
	assertEquals(pomModelBeforeChange.getBuild().getPlugins().get(0).getArtifactId(), "cobertura-maven-plugin");

       PomAddPlugin pomAddPlugin = new PomAddPlugin("org.apache.maven.plugins", "maven-javadoc-plugin", "2.10.4").relative("pom.xml");
	TOExecutionResult executionResult = pomAddPlugin.execution(transformedAppFolder, transformationContext);
	assertEquals(executionResult.getType(), TOExecutionResult.Type.SUCCESS);

	Model pomModelAfterChange = getTransformedPomModel("pom.xml");
	assertEquals(pomModelAfterChange.getBuild().getPlugins().size(), 2);
       Plugin plugin = new Plugin();
       plugin.setGroupId("org.apache.maven.plugins");
       plugin.setArtifactId("maven-javadoc-plugin");
       assertTrue(pomModelAfterChange.getBuild().getPlugins().contains(plugin));
       assertEquals(pomModelAfterChange.getBuild().getPluginsAsMap().get("org.apache.maven.plugins:maven-javadoc-plugin").getVersion(), "2.10.4");
}
 
开发者ID:paypal,项目名称:butterfly,代码行数:20,代码来源:PomAddPluginTest.java

示例13: defaultIfPresentTest

import org.apache.maven.model.Model; //导入依赖的package包/类
@Test
public void defaultIfPresentTest() throws IOException, XmlPullParserException {
    Model pomModelBeforeChange = getOriginalPomModel("pom.xml");
    assertEquals(pomModelBeforeChange.getBuild().getPlugins().size(), 1);
    assertEquals(pomModelBeforeChange.getBuild().getPlugins().get(0).getGroupId(), "org.codehaus.mojo");
    assertEquals(pomModelBeforeChange.getBuild().getPlugins().get(0).getArtifactId(), "cobertura-maven-plugin");

    // Trying to add the same plugin
    PomAddPlugin pomAddPlugin = new PomAddPlugin().setArtifact("org.codehaus.mojo:cobertura-maven-plugin").relative("pom.xml");
    TOExecutionResult executionResult = pomAddPlugin.execution(transformedAppFolder, transformationContext);
    assertEquals(executionResult.getType(), TOExecutionResult.Type.ERROR);
    assertNull(executionResult.getDetails());
    assertEquals(executionResult.getException().getMessage(), "Plugin org.codehaus.mojo:cobertura-maven-plugin is already present in pom.xml");

    Model pomModelAfterChange = getTransformedPomModel("pom.xml");
    assertEquals(pomModelAfterChange.getBuild().getPlugins().size(), 1);
    assertEquals(pomModelAfterChange.getBuild().getPlugins().size(), 1);
    assertEquals(pomModelAfterChange.getBuild().getPlugins().get(0).getGroupId(), "org.codehaus.mojo");
    assertEquals(pomModelAfterChange.getBuild().getPlugins().get(0).getArtifactId(), "cobertura-maven-plugin");
}
 
开发者ID:paypal,项目名称:butterfly,代码行数:21,代码来源:PomAddPluginTest.java

示例14: getEffectiveModel

import org.apache.maven.model.Model; //导入依赖的package包/类
public Model getEffectiveModel(ModelSource modelSource) {
  DefaultModelBuildingRequest request = new DefaultModelBuildingRequest();
  request.setModelResolver(this);
  request.setModelSource(modelSource);
  Model model;
  try {
    ModelBuildingResult result = modelBuilder.build(request);
    model = result.getEffectiveModel();
  } catch (ModelBuildingException | IllegalArgumentException e) {
    // IllegalArg can be thrown if the parent POM cannot be resolved.
    logger.warning(
        "Unable to resolve Maven model from "
            + modelSource.getLocation()
            + ": "
            + e.getMessage());
    return null;
  }
  return model;
}
 
开发者ID:bazelbuild,项目名称:migration-tooling,代码行数:20,代码来源:DefaultModelResolver.java

示例15: scopesHonoredForRoot

import org.apache.maven.model.Model; //导入依赖的package包/类
@Test
public void scopesHonoredForRoot() throws Exception {
  Model mockModel = mock(Model.class);
  // Only "compile" should go through.
  when(mockModel.getDependencies())
      .thenReturn(
          ImmutableList.of(
              getDependency("a:b:1.0", "compile"), getDependency("c:d:1.0", "test")));

  Aether aether = mock(Aether.class);
  when(aether.requestVersionRange(fromCoords("a:b:[1.0,)"))).thenReturn(newArrayList("1.0"));
  when(aether.requestVersionRange(fromCoords("c:d:[1.0,)"))).thenReturn(newArrayList("1.0"));
  VersionResolver versionResolver = new VersionResolver(aether);

  Resolver resolver = new Resolver(mock(DefaultModelResolver.class), versionResolver, ALIASES);

  resolver.traverseDeps(mockModel, Sets.newHashSet("compile"), Sets.newHashSet(), null);
  Collection<Rule> rules = resolver.getRules();
  assertThat(rules).hasSize(1);
  Rule actual = rules.iterator().next();
  assertThat(actual.name()).isEqualTo("a_b");
}
 
开发者ID:bazelbuild,项目名称:migration-tooling,代码行数:23,代码来源:ResolverTest.java


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