本文整理汇总了Java中org.apache.maven.Maven类的典型用法代码示例。如果您正苦于以下问题:Java Maven类的具体用法?Java Maven怎么用?Java Maven使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Maven类属于org.apache.maven包,在下文中一共展示了Maven类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runMavenRequest
import org.apache.maven.Maven; //导入依赖的package包/类
public void runMavenRequest(MavenExecutionRequest request, Runnable runnable) {
DefaultMaven maven = (DefaultMaven) getMavenComponent(Maven.class);
RepositorySystemSession repositorySystemSession = maven.newRepositorySession(request);
request.getProjectBuildingRequest().setRepositorySession(repositorySystemSession);
MavenSession mavenSession =
new MavenSession(
container, repositorySystemSession, request, new DefaultMavenExecutionResult());
LegacySupport legacySupport = getMavenComponent(LegacySupport.class);
MavenSession previousSession = legacySupport.getSession();
legacySupport.setSession(mavenSession);
try {
for (AbstractMavenLifecycleParticipant participant :
getLifecycleParticipants(Collections.emptyList())) {
participant.afterSessionStart(mavenSession);
}
runnable.run();
} catch (MavenExecutionException e) {
throw new RuntimeException(e);
} finally {
legacySupport.setSession(previousSession);
}
}
示例2: executeWithMavenSession
import org.apache.maven.Maven; //导入依赖的package包/类
public void executeWithMavenSession(MavenExecutionRequest request, Runnable runnable) {
DefaultMaven maven = (DefaultMaven)getComponent(Maven.class);
RepositorySystemSession repositorySession = maven.newRepositorySession(request);
request.getProjectBuildingRequest().setRepositorySession(repositorySession);
MavenSession mavenSession = new MavenSession(myContainer, repositorySession, request, new DefaultMavenExecutionResult());
LegacySupport legacySupport = getComponent(LegacySupport.class);
MavenSession oldSession = legacySupport.getSession();
legacySupport.setSession(mavenSession);
try {
runnable.run();
}
finally {
legacySupport.setSession(oldSession);
}
}
示例3: checkSupport
import org.apache.maven.Maven; //导入依赖的package包/类
private void checkSupport() {
Properties properties = new Properties();
try (InputStream in = Maven.class.getResourceAsStream("/META-INF/maven/org.apache.maven/maven-core/pom.properties")) {
if (in != null) {
properties.load(in);
}
} catch (IOException e) {
log.error("Unable determine maven version, deploy at end might fail", e);
return;
}
String mavenVersion = properties.getProperty("version");
if (mavenVersion != null) {
int c = new DefaultArtifactVersion(mavenVersion).compareTo(new DefaultArtifactVersion("3.3.1"));
if (c < 0) {
throw new IllegalStateException("Deploy-at-end is not supported on maven versions <3.3.1");
}
} else {
log.error("Unable determine maven version, deploy at end might fail");
}
}
示例4: loadParentOf
import org.apache.maven.Maven; //导入依赖的package包/类
/**
* replacement for MavenProject.getParent() which has bad long term memory behaviour. We offset it by recalculating/reparsing everything
* therefore should not be used lightly!
* pass a MavenProject instance and current configuration and other settings will be applied when loading the parent.
* @param project
* @return null or the parent mavenproject
*/
public MavenProject loadParentOf(MavenEmbedder embedder, MavenProject project) throws ProjectBuildingException {
MavenProject parent = null;
ProjectBuilder builder = embedder.lookupComponent(ProjectBuilder.class);
MavenExecutionRequest req = embedder.createMavenExecutionRequest();
M2Configuration active = configProvider.getActiveConfiguration();
req.addActiveProfiles(active.getActivatedProfiles());
req.setNoSnapshotUpdates(true);
req.setUpdateSnapshots(false);
req.setInteractiveMode(false);
req.setRecursive(false);
req.setOffline(true);
//#238800 important to merge, not replace
Properties uprops = req.getUserProperties();
uprops.putAll(MavenProjectCache.createUserPropsForProjectLoading(active.getProperties()));
req.setUserProperties(uprops);
ProjectBuildingRequest request = req.getProjectBuildingRequest();
request.setRemoteRepositories(project.getRemoteArtifactRepositories());
DefaultMaven maven = (DefaultMaven) embedder.lookupComponent(Maven.class);
request.setRepositorySession(maven.newRepositorySession(req));
if (project.getParentFile() != null) {
parent = builder.build(project.getParentFile(), request).getProject();
} else if (project.getModel().getParent() != null) {
parent = builder.build(project.getParentArtifact(), request).getProject();
}
//clear the project building request, it references multiple Maven Models via the RepositorySession cache
//is not used in maven itself, most likely used by m2e only..
if (parent != null) {
parent.setProjectBuildingRequest(null);
}
MavenEmbedder.normalizePaths(parent);
return parent;
}
示例5: runMavenValidationImpl
import org.apache.maven.Maven; //导入依赖的package包/类
static List<ModelProblem> runMavenValidationImpl(final File pom) {
//TODO profiles based on current configuration??
MavenEmbedder embedder = EmbedderFactory.getProjectEmbedder();
MavenExecutionRequest meReq = embedder.createMavenExecutionRequest();
ProjectBuildingRequest req = meReq.getProjectBuildingRequest();
req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1); // currently enables just <reporting> warning
req.setLocalRepository(embedder.getLocalRepository());
List<ArtifactRepository> remoteRepos = RepositoryPreferences.getInstance().remoteRepositories(embedder);
req.setRemoteRepositories(remoteRepos);
req.setRepositorySession(((DefaultMaven) embedder.lookupComponent(Maven.class)).newRepositorySession(meReq));
List<ModelProblem> problems;
try {
problems = embedder.lookupComponent(ProjectBuilder.class).build(pom, req).getProblems();
} catch (ProjectBuildingException x) {
problems = new ArrayList<ModelProblem>();
List<ProjectBuildingResult> results = x.getResults();
if (results != null) { //one code point throwing ProjectBuildingException contains results,
for (ProjectBuildingResult result : results) {
problems.addAll(result.getProblems());
}
} else {
// another code point throwing ProjectBuildingException doesn't contain results..
Throwable cause = x.getCause();
if (cause instanceof ModelBuildingException) {
problems.addAll(((ModelBuildingException) cause).getProblems());
}
}
}
return problems;
}
示例6: MavenEmbedder
import org.apache.maven.Maven; //导入依赖的package包/类
MavenEmbedder(EmbedderConfiguration configuration) throws ComponentLookupException {
embedderConfiguration = configuration;
plexus = configuration.getContainer();
this.maven = (DefaultMaven) plexus.lookup(Maven.class);
this.projectBuilder = plexus.lookup(ProjectBuilder.class);
this.repositorySystem = plexus.lookup(RepositorySystem.class);
this.settingsBuilder = plexus.lookup(SettingsBuilder.class);
this.populator = plexus.lookup(MavenExecutionRequestPopulator.class);
settingsDecrypter = plexus.lookup(SettingsDecrypter.class);
}
示例7: runMavenValidationImpl
import org.apache.maven.Maven; //导入依赖的package包/类
static List<ModelProblem> runMavenValidationImpl(final File pom) {
MavenEmbedder embedder = EmbedderFactory.getProjectEmbedder();
MavenExecutionRequest meReq = embedder.createMavenExecutionRequest();
ProjectBuildingRequest req = meReq.getProjectBuildingRequest();
req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0); // 3.1 currently enables just <reporting> warning, see issue 223562 for details on why it's bad to show.
req.setLocalRepository(embedder.getLocalRepository());
List<ArtifactRepository> remoteRepos = RepositoryPreferences.getInstance().remoteRepositories(embedder);
req.setRemoteRepositories(remoteRepos);
req.setRepositorySession(((DefaultMaven) embedder.lookupComponent(Maven.class)).newRepositorySession(meReq));
List<ModelProblem> problems;
try {
problems = embedder.lookupComponent(ProjectBuilder.class).build(pom, req).getProblems();
} catch (ProjectBuildingException x) {
problems = new ArrayList<ModelProblem>();
List<ProjectBuildingResult> results = x.getResults();
if (results != null) { //one code point throwing ProjectBuildingException contains results,
for (ProjectBuildingResult result : results) {
problems.addAll(result.getProblems());
}
} else {
// another code point throwing ProjectBuildingException doesn't contain results..
Throwable cause = x.getCause();
if (cause instanceof ModelBuildingException) {
problems.addAll(((ModelBuildingException) cause).getProblems());
}
}
}
List<ModelProblem> toRet = new LinkedList<ModelProblem>();
for (ModelProblem problem : problems) {
if(ModelUtils.checkByCLIMavenValidationLevel(problem)) {
toRet.add(problem);
}
}
return toRet;
}
示例8: newMavenSession
import org.apache.maven.Maven; //导入依赖的package包/类
protected MavenSession newMavenSession() {
try {
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
MavenExecutionResult result = new DefaultMavenExecutionResult();
// populate sensible defaults, including repository basedir and remote repos
MavenExecutionRequestPopulator populator;
populator = getContainer().lookup( MavenExecutionRequestPopulator.class );
populator.populateDefaults( request );
// this is needed to allow java profiles to get resolved; i.e. avoid during project builds:
// [ERROR] Failed to determine Java version for profile java-1.5-detected @ org.apache.commons:commons-parent:22, /Users/alex/.m2/repository/org/apache/commons/commons-parent/22/commons-parent-22.pom, line 909, column 14
request.setSystemProperties( System.getProperties() );
// and this is needed so that the repo session in the maven session
// has a repo manager, and it points at the local repo
// (cf MavenRepositorySystemUtils.newSession() which is what is otherwise done)
DefaultMaven maven = (DefaultMaven) getContainer().lookup( Maven.class );
DefaultRepositorySystemSession repoSession =
(DefaultRepositorySystemSession) maven.newRepositorySession( request );
repoSession.setLocalRepositoryManager(
new SimpleLocalRepositoryManagerFactory().newInstance(repoSession,
new LocalRepository( request.getLocalRepository().getBasedir() ) ));
@SuppressWarnings("deprecation")
MavenSession session = new MavenSession( getContainer(),
repoSession,
request, result );
return session;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例9: doExecute
import org.apache.maven.Maven; //导入依赖的package包/类
private MavenExecutionResult doExecute(@NotNull final File file,
@NotNull final List<String> activeProfiles,
@NotNull final List<String> inactiveProfiles,
@NotNull final List<String> goals,
@NotNull final List<String> selectedProjects,
boolean alsoMake,
boolean alsoMakeDependents) throws RemoteException {
MavenExecutionRequest request = createRequest(file, activeProfiles, inactiveProfiles, goals);
if (!selectedProjects.isEmpty()) {
request.setRecursive(true);
request.setSelectedProjects(selectedProjects);
if (alsoMake && alsoMakeDependents) {
request.setMakeBehavior(ReactorManager.MAKE_BOTH_MODE);
}
else if (alsoMake) {
request.setMakeBehavior(ReactorManager.MAKE_MODE);
}
else if (alsoMakeDependents) {
request.setMakeBehavior(ReactorManager.MAKE_DEPENDENTS_MODE);
}
}
Maven maven = getComponent(Maven.class);
org.apache.maven.execution.MavenExecutionResult executionResult = maven.execute(request);
return new MavenExecutionResult(executionResult.getProject(), filterExceptions(executionResult.getExceptions()));
}
示例10: execute
import org.apache.maven.Maven; //导入依赖的package包/类
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
try {
String version = getLocalVersion(getClass().getClassLoader(), GROUP_ID, ARTIFACT_ID);
if (version == null) {
log.debug("Could not determine {}:{} version, skipping update check", GROUP_ID, ARTIFACT_ID);
return; // TODO generate maven pom.properties inside m2e
}
Preferences preferences = Preferences.userRoot().node(GROUP_ID.replace('.', '/')).node(ARTIFACT_ID).node(version.toString());
final long timestamp = System.currentTimeMillis();
if (timestamp - preferences.getLong(UPDATE_CHECK_TIMESTAMP_PREF, 0) < ONE_WEEK_MS) {
// only check for update once a week
return;
}
preferences.putLong(UPDATE_CHECK_TIMESTAMP_PREF, timestamp);
preferences.flush();
String mavenVersion = getLocalVersion(Maven.class.getClassLoader(), "org.apache.maven", "maven-core");
String javaVersion = System.getProperty("java.version");
// doing url encoding correctly is apparently hard in java https://github.com/google/guava/issues/1756
String query = String.format("m=%s&j=%s", mavenVersion, javaVersion);
URLConnection conn = new URL(REMOTE_URL + "?" + query).openConnection();
conn.addRequestProperty("User-Agent", "takari-lifecycle/" + version.toString());
conn.setConnectTimeout(UPDATE_TIMEOUT_MS);
conn.setReadTimeout(UPDATE_TIMEOUT_MS);
try (InputStream is = conn.getInputStream()) {
String latestVersion = getVersion(is);
if (latestVersion != null && new DefaultArtifactVersion(version).compareTo(new DefaultArtifactVersion(latestVersion)) < 0) {
log.warn("Takari Lifecycle version {} is outdated, consider upgrade to {}", version, latestVersion);
}
}
} catch (IOException | BackingStoreException ignored) {
// this is a just courtesy to the user, no need to break the build
}
}
示例11: PrintStreamLogger
import org.apache.maven.Maven; //导入依赖的package包/类
public PrintStreamLogger( Provider provider )
{
super( Logger.LEVEL_INFO, Maven.class.getName() );
if ( provider == null )
{
throw new IllegalArgumentException( "output stream provider missing" );
}
this.provider = provider;
}
示例12: newMavenSession
import org.apache.maven.Maven; //导入依赖的package包/类
protected MavenSession newMavenSession() {
try {
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
MavenExecutionResult result = new DefaultMavenExecutionResult();
// populate sensible defaults, including repository basedir and remote repos
MavenExecutionRequestPopulator populator;
populator = getContainer().lookup(MavenExecutionRequestPopulator.class);
populator.populateDefaults(request);
// this is needed to allow java profiles to get resolved; i.e. avoid during project builds:
// [ERROR] Failed to determine Java version for profile java-1.5-detected @ org.apache.commons:commons-parent:22, /Users/alex/.m2/repository/org/apache/commons/commons-parent/22/commons-parent-22.pom, line 909, column 14
request.setSystemProperties(System.getProperties());
// and this is needed so that the repo session in the maven session
// has a repo manager, and it points at the local repo
// (cf MavenRepositorySystemUtils.newSession() which is what is otherwise done)
DefaultMaven maven = (DefaultMaven) getContainer().lookup(Maven.class);
DefaultRepositorySystemSession repoSession =
(DefaultRepositorySystemSession) maven.newRepositorySession(request);
repoSession.setLocalRepositoryManager(
new SimpleLocalRepositoryManagerFactory().newInstance(repoSession,
new LocalRepository(request.getLocalRepository().getBasedir())));
@SuppressWarnings("deprecation")
MavenSession session = new MavenSession(getContainer(),
repoSession,
request, result);
return session;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例13: resolveArtifact
import org.apache.maven.Maven; //导入依赖的package包/类
@Override
public MavenArtifact resolveArtifact(
MavenArtifactKey artifactKey, List<MavenRemoteRepository> repositories)
throws RemoteException {
Artifact artifact =
getMavenComponent(ArtifactFactory.class)
.createArtifactWithClassifier(
artifactKey.getGroupId(),
artifactKey.getArtifactId(),
artifactKey.getVersion(),
artifactKey.getPackaging(),
artifactKey.getClassifier());
List<ArtifactRepository> repos = new ArrayList<>();
ArtifactRepositoryFactory factory = getMavenComponent(ArtifactRepositoryFactory.class);
for (MavenRemoteRepository repository : repositories) {
try {
ArtifactRepository artifactRepository =
ProjectUtils.buildArtifactRepository(
MavenModelUtil.convertToMavenRepository(repository), factory, container);
repos.add(artifactRepository);
} catch (InvalidRepositoryException e) {
MavenServerContext.getLogger().error(e);
}
}
MavenExecutionRequest request =
newMavenRequest(
null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
repos.forEach(request::addRemoteRepository);
DefaultMaven maven = (DefaultMaven) getMavenComponent(Maven.class);
RepositorySystemSession repositorySystemSession = maven.newRepositorySession(request);
org.eclipse.aether.impl.ArtifactResolver artifactResolver =
getMavenComponent(org.eclipse.aether.impl.ArtifactResolver.class);
InternalLoggerFactory loggerFactory = new InternalLoggerFactory();
if (artifactResolver instanceof DefaultArtifactResolver) {
((DefaultArtifactResolver) artifactResolver).setLoggerFactory(loggerFactory);
}
org.eclipse.aether.RepositorySystem repositorySystem =
getMavenComponent(org.eclipse.aether.RepositorySystem.class);
if (repositorySystem instanceof DefaultRepositorySystem) {
((DefaultRepositorySystem) repositorySystem).setLoggerFactory(loggerFactory);
}
List<RemoteRepository> remoteRepositories =
RepositoryUtils.toRepos(request.getRemoteRepositories());
remoteRepositories =
repositorySystem.newResolutionRepositories(repositorySystemSession, remoteRepositories);
try {
ArtifactResult artifactResult =
repositorySystem.resolveArtifact(
repositorySystemSession,
new ArtifactRequest(RepositoryUtils.toArtifact(artifact), remoteRepositories, null));
return MavenModelUtil.convertArtifact(
RepositoryUtils.toArtifact(artifactResult.getArtifact()), localRepository);
} catch (ArtifactResolutionException ignored) {
// we need ignore exception, it's some times has class that client doesn't has
// .printStackTrace() may be solution, but it will spam wsagent logs
}
return MavenModelUtil.convertArtifact(artifact, localRepository);
}
示例14: lookupConfiguredMojo
import org.apache.maven.Maven; //导入依赖的package包/类
public E lookupConfiguredMojo(File pom, String goal, TestDB testDb) throws Exception {
// Mojoテストリソースディレクトリのパスをシステムプロパティに設定しておく
// System.setProperty("MojoTestRoot", getMojoTestRoot());
// 各DBの接続情報をシステムプロパティへマージする
Properties prop = new Properties();
prop.load(new FileInputStream(new File(Thread.currentThread().getContextClassLoader().getResource("jdbc_test.properties").getPath())));
System.getProperties().putAll(prop);
// Maven実行リクエスト初期化
MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
// テスト用のsettingファイルで初期化
// File settings = new File(this.getClass().getResource("settings.xml").getPath());
File settings = new File(Thread.currentThread().getContextClassLoader().getResource("settings.xml").getPath());
MavenExecutionRequestPopulator populator = getContainer().lookup(MavenExecutionRequestPopulator.class);
MavenSettingsBuilder mb = this.lookup(MavenSettingsBuilder.class);
Settings st = mb.buildSettings(settings);
populator.populateFromSettings(executionRequest, st);
// カレントディレクトリをセット
executionRequest.setBaseDirectory(pom.getParentFile());
// プロファイルを指定DBのプロファイルにセット
executionRequest.setActiveProfiles(Collections.singletonList(testDb.name()));
// ローカルリポジトリオブジェクトのセット
String localRepoPath = this.getClass().getResource("testLocalRepo").toURI().toURL().toString();
executionRequest.setLocalRepository(new MavenArtifactRepository(RepositorySystem.DEFAULT_LOCAL_REPO_ID,
localRepoPath, new DefaultRepositoryLayout(),
new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy()));
// 実行プロジェクトを作成
ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
DefaultMaven maven = (DefaultMaven) getContainer().lookup(Maven.class);
DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) maven
.newRepositorySession(executionRequest);
repoSession.setOffline(true);
buildingRequest.setRepositorySession(repoSession);
ProjectBuilder projectBuilder = this.lookup(ProjectBuilder.class);
MavenProject project = projectBuilder.build(pom, buildingRequest).getProject();
currentMavenExecutionRequest = executionRequest;
// 指定ゴールを持つMojoを取得
Mojo mojo = this.lookupConfiguredMojo(project, goal);
currentProject = project;
return (E) mojo;
}