• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java DefaultMaven类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: runMavenRequest

import org.apache.maven.DefaultMaven; //导入依赖的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);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:23,代码来源:MavenServerImpl.java


示例2: executeWithMavenSession

import org.apache.maven.DefaultMaven; //导入依赖的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);
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:20,代码来源:Maven3ServerEmbedderImpl.java


示例3: loadParentOf

import org.apache.maven.DefaultMaven; //导入依赖的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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:45,代码来源:NbMavenProjectImpl.java


示例4: runMavenValidationImpl

import org.apache.maven.DefaultMaven; //导入依赖的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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:EffectivePomMD.java


示例5: MavenEmbedder

import org.apache.maven.DefaultMaven; //导入依赖的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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:MavenEmbedder.java


示例6: runMavenValidationImpl

import org.apache.maven.DefaultMaven; //导入依赖的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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:StatusProvider.java


示例7: newMavenSession

import org.apache.maven.DefaultMaven; //导入依赖的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);
    }
}
 
开发者ID:ahgittin,项目名称:license-audit-maven-plugin,代码行数:34,代码来源:BetterAbstractMojoTestCase.java


示例8: newMavenSession

import org.apache.maven.DefaultMaven; //导入依赖的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);
    }
}
 
开发者ID:walokra,项目名称:markdown-page-generator-plugin,代码行数:34,代码来源:BetterAbstractMojoTestCase.java


示例9: resolveArtifact

import org.apache.maven.DefaultMaven; //导入依赖的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);
}
 
开发者ID:eclipse,项目名称:che,代码行数:66,代码来源:MavenServerImpl.java


示例10: lookupConfiguredMojo

import org.apache.maven.DefaultMaven; //导入依赖的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;
	}
 
开发者ID:coastland,项目名称:gsp-dba-maven-plugin,代码行数:52,代码来源:AbstractDdlMojoTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ParquetMetadataConverter类代码示例发布时间:2022-05-22
下一篇:
Java AttributeStatementBuilder类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap