本文整理匯總了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);
}
示例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);
}
示例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");
}
示例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;
}
示例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;
}
示例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 );
}
示例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);
}
示例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");
}
示例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");
}
示例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);
}
示例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");
}
示例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");
}
示例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");
}
示例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;
}
示例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");
}