コード例 #1
0
 public static MavenModel assembleInheritance(MavenModel model, MavenModel parentModel)
     throws RemoteException {
   Model result = MavenModelConverter.toNativeModel(model);
   new DefaultModelInheritanceAssembler()
       .assembleModelInheritance(result, MavenModelConverter.toNativeModel(parentModel));
   return MavenModelConverter.convertModel(result, null);
 }
コード例 #2
0
  public static MavenModel interpolateAndAlignModel(MavenModel model, File basedir)
      throws RemoteException {
    Model result = MavenModelConverter.toNativeModel(model);
    result = doInterpolate(result, basedir);

    PathTranslator pathTranslator = new DefaultPathTranslator();
    pathTranslator.alignToBaseDirectory(result, basedir);

    return MavenModelConverter.convertModel(result, null);
  }
コード例 #3
0
  @NotNull
  private MavenServerExecutionResult createExecutionResult(
      File file, MavenExecutionResult result, DependencyNode rootNode) throws RemoteException {
    Collection<MavenProjectProblem> problems = MavenProjectProblem.createProblemsList();
    THashSet<MavenId> unresolvedArtifacts = new THashSet<MavenId>();

    validate(file, result.getExceptions(), problems, unresolvedArtifacts);

    MavenProject mavenProject = result.getMavenProject();
    if (mavenProject == null)
      return new MavenServerExecutionResult(null, problems, unresolvedArtifacts);

    MavenModel model =
        MavenModelConverter.convertModel(
            mavenProject.getModel(),
            mavenProject.getCompileSourceRoots(),
            mavenProject.getTestCompileSourceRoots(),
            mavenProject.getArtifacts(),
            (rootNode == null ? Collections.emptyList() : rootNode.getChildren()),
            mavenProject.getExtensionArtifacts(),
            getLocalRepositoryFile());

    RemoteNativeMavenProjectHolder holder = new RemoteNativeMavenProjectHolder(mavenProject);
    try {
      UnicastRemoteObject.exportObject(holder, 0);
    } catch (RemoteException e) {
      throw new RuntimeException(e);
    }

    Collection<String> activatedProfiles = collectActivatedProfiles(mavenProject);

    MavenServerExecutionResult.ProjectData data =
        new MavenServerExecutionResult.ProjectData(
            model,
            MavenModelConverter.convertToMap(mavenProject.getModel()),
            holder,
            activatedProfiles);
    return new MavenServerExecutionResult(data, problems, unresolvedArtifacts);
  }
コード例 #4
0
 private List<ArtifactRepository> convertRepositories(List<MavenRemoteRepository> repositories)
     throws RemoteException {
   List<ArtifactRepository> result = new ArrayList<ArtifactRepository>();
   for (MavenRemoteRepository each : repositories) {
     try {
       ArtifactRepositoryFactory factory = getComponent(ArtifactRepositoryFactory.class);
       result.add(
           ProjectUtils.buildArtifactRepository(
               MavenModelConverter.toNativeRepository(each), factory, myContainer));
     } catch (InvalidRepositoryException e) {
       Maven3ServerGlobals.getLogger().warn(e);
     }
   }
   return result;
 }
コード例 #5
0
  @NotNull
  @Override
  public List<MavenArtifact> resolveTransitively(
      @NotNull List<MavenArtifactInfo> artifacts,
      @NotNull List<MavenRemoteRepository> remoteRepositories)
      throws RemoteException, MavenServerProcessCanceledException {

    try {
      Set<Artifact> toResolve = new LinkedHashSet<Artifact>();
      for (MavenArtifactInfo each : artifacts) {
        toResolve.add(createArtifact(each));
      }

      Artifact project =
          getComponent(ArtifactFactory.class).createBuildArtifact("temp", "temp", "666", "pom");

      Set<Artifact> res =
          getComponent(ArtifactResolver.class)
              .resolveTransitively(
                  toResolve,
                  project,
                  Collections.EMPTY_MAP,
                  myLocalRepository,
                  convertRepositories(remoteRepositories),
                  getComponent(ArtifactMetadataSource.class))
              .getArtifacts();

      return MavenModelConverter.convertArtifacts(
          res, new THashMap<Artifact, MavenArtifact>(), getLocalRepositoryFile());
    } catch (ArtifactResolutionException e) {
      Maven3ServerGlobals.getLogger().info(e);
    } catch (ArtifactNotFoundException e) {
      Maven3ServerGlobals.getLogger().info(e);
    } catch (Exception e) {
      throw rethrowException(e);
    }

    return Collections.emptyList();
  }
コード例 #6
0
  public static ProfileApplicationResult applyProfiles(
      MavenModel model,
      File basedir,
      Collection<String> explicitProfiles,
      Collection<String> alwaysOnProfiles)
      throws RemoteException {
    Model nativeModel = MavenModelConverter.toNativeModel(model);

    List<Profile> activatedPom = new ArrayList<Profile>();
    List<Profile> activatedExternal = new ArrayList<Profile>();
    List<Profile> activeByDefault = new ArrayList<Profile>();

    List<Profile> rawProfiles = nativeModel.getProfiles();
    List<Profile> expandedProfilesCache = null;

    for (int i = 0; i < rawProfiles.size(); i++) {
      Profile eachRawProfile = rawProfiles.get(i);

      boolean shouldAdd =
          explicitProfiles.contains(eachRawProfile.getId())
              || alwaysOnProfiles.contains(eachRawProfile.getId());

      Activation activation = eachRawProfile.getActivation();
      if (activation != null) {
        if (activation.isActiveByDefault()) {
          activeByDefault.add(eachRawProfile);
        }

        // expand only if necessary
        if (expandedProfilesCache == null)
          expandedProfilesCache = doInterpolate(nativeModel, basedir).getProfiles();
        Profile eachExpandedProfile = expandedProfilesCache.get(i);

        for (ProfileActivator eachActivator : getProfileActivators(basedir)) {
          try {
            if (eachActivator.canDetermineActivation(eachExpandedProfile)
                && eachActivator.isActive(eachExpandedProfile)) {
              shouldAdd = true;
              break;
            }
          } catch (ProfileActivationException e) {
            Maven3ServerGlobals.getLogger().warn(e);
          }
        }
      }

      if (shouldAdd) {
        if (MavenConstants.PROFILE_FROM_POM.equals(eachRawProfile.getSource())) {
          activatedPom.add(eachRawProfile);
        } else {
          activatedExternal.add(eachRawProfile);
        }
      }
    }

    List<Profile> activatedProfiles =
        new ArrayList<Profile>(activatedPom.isEmpty() ? activeByDefault : activatedPom);
    activatedProfiles.addAll(activatedExternal);

    for (Profile each : activatedProfiles) {
      new DefaultProfileInjector().injectProfile(nativeModel, each, null, null);
    }

    return new ProfileApplicationResult(
        MavenModelConverter.convertModel(nativeModel, null), collectProfilesIds(activatedProfiles));
  }
コード例 #7
0
 private MavenArtifact doResolve(
     MavenArtifactInfo info, List<MavenRemoteRepository> remoteRepositories)
     throws RemoteException {
   Artifact resolved = doResolve(createArtifact(info), convertRepositories(remoteRepositories));
   return MavenModelConverter.convertArtifact(resolved, getLocalRepositoryFile());
 }