public static Set<Artifact> getArtifactsToBuild(
      final Project project,
      final CompileScope compileScope,
      final boolean addIncludedArtifactsWithOutputPathsOnly) {
    final Artifact[] artifactsFromScope = getArtifacts(compileScope);
    final ArtifactManager artifactManager = ArtifactManager.getInstance(project);
    PackagingElementResolvingContext context = artifactManager.getResolvingContext();
    if (artifactsFromScope != null) {
      return addIncludedArtifacts(
          Arrays.asList(artifactsFromScope), context, addIncludedArtifactsWithOutputPathsOnly);
    }

    final Set<Artifact> cached = compileScope.getUserData(CACHED_ARTIFACTS_KEY);
    if (cached != null) {
      return cached;
    }

    Set<Artifact> artifacts = new HashSet<Artifact>();
    final Set<Module> modules =
        new HashSet<Module>(Arrays.asList(compileScope.getAffectedModules()));
    final List<Module> allModules = Arrays.asList(ModuleManager.getInstance(project).getModules());
    for (Artifact artifact : artifactManager.getArtifacts()) {
      if (artifact.isBuildOnMake()) {
        if (modules.containsAll(allModules) || containsModuleOutput(artifact, modules, context)) {
          artifacts.add(artifact);
        }
      }
    }
    Set<Artifact> result =
        addIncludedArtifacts(artifacts, context, addIncludedArtifactsWithOutputPathsOnly);
    compileScope.putUserData(CACHED_ARTIFACTS_KEY, result);
    return result;
  }
Exemplo n.º 2
0
 public static List<Artifact> getArtifactWithOutputPaths(Project project) {
   final List<Artifact> result = new ArrayList<Artifact>();
   for (Artifact artifact : ArtifactManager.getInstance(project).getSortedArtifacts()) {
     if (!StringUtil.isEmpty(artifact.getOutputPath())) {
       result.add(artifact);
     }
   }
   return result;
 }
Exemplo n.º 3
0
 public static Collection<Trinity<Artifact, PackagingElementPath, String>>
     findContainingArtifactsWithOutputPaths(
         @NotNull final VirtualFile file, @NotNull Project project) {
   final boolean isResourceFile = CompilerConfiguration.getInstance(project).isResourceFile(file);
   final List<Trinity<Artifact, PackagingElementPath, String>> artifacts =
       new ArrayList<Trinity<Artifact, PackagingElementPath, String>>();
   final PackagingElementResolvingContext context =
       ArtifactManager.getInstance(project).getResolvingContext();
   for (final Artifact artifact : ArtifactManager.getInstance(project).getArtifacts()) {
     processPackagingElements(
         artifact,
         null,
         new PackagingElementProcessor<PackagingElement<?>>() {
           @Override
           public boolean process(
               @NotNull PackagingElement<?> element, @NotNull PackagingElementPath path) {
             if (element instanceof FileOrDirectoryCopyPackagingElement<?>) {
               final VirtualFile root = ((FileOrDirectoryCopyPackagingElement) element).findFile();
               if (root != null && VfsUtil.isAncestor(root, file, false)) {
                 final String relativePath;
                 if (root.equals(file) && element instanceof FileCopyPackagingElement) {
                   relativePath = ((FileCopyPackagingElement) element).getOutputFileName();
                 } else {
                   relativePath = VfsUtilCore.getRelativePath(file, root, '/');
                 }
                 artifacts.add(Trinity.create(artifact, path, relativePath));
                 return false;
               }
             } else if (isResourceFile && element instanceof ModuleOutputPackagingElement) {
               final String relativePath =
                   getRelativePathInSources(file, (ModuleOutputPackagingElement) element, context);
               if (relativePath != null) {
                 artifacts.add(Trinity.create(artifact, path, relativePath));
                 return false;
               }
             }
             return true;
           }
         },
         context,
         true);
   }
   return artifacts;
 }
 @NotNull
 @Override
 public List<DeploymentSource> createArtifactDeploymentSources(
     Project project, ArtifactType... artifactTypes) {
   if (project.isDefault()) return Collections.emptyList();
   Artifact[] artifacts = ArtifactManager.getInstance(project).getArtifacts();
   List<Artifact> supportedArtifacts = new ArrayList<>();
   Set<ArtifactType> typeSet = ContainerUtil.set(artifactTypes);
   for (Artifact artifact : artifacts) {
     if (typeSet.contains(artifact.getArtifactType())) {
       supportedArtifacts.add(artifact);
     }
   }
   return createArtifactDeploymentSources(project, supportedArtifacts);
 }
 @NotNull
 private static Artifact findOrCreateWebArtifact(AppEngineFacet appEngineFacet) {
   Module module = appEngineFacet.getModule();
   ArtifactType webArtifactType =
       AppEngineWebIntegration.getInstance().getAppEngineWebArtifactType();
   final Collection<Artifact> artifacts = ArtifactUtil.getArtifactsContainingModuleOutput(module);
   for (Artifact artifact : artifacts) {
     if (webArtifactType.equals(artifact.getArtifactType())) {
       return artifact;
     }
   }
   ArtifactManager artifactManager = ArtifactManager.getInstance(module.getProject());
   PackagingElementFactory elementFactory = PackagingElementFactory.getInstance();
   ArtifactRootElement<?> root = elementFactory.createArtifactRootElement();
   elementFactory
       .getOrCreateDirectory(root, "WEB-INF/classes")
       .addOrFindChild(elementFactory.createModuleOutput(module));
   return artifactManager.addArtifact(module.getName(), webArtifactType, root);
 }
Exemplo n.º 6
0
 public static Set<Module> getModulesIncludedInArtifacts(
     final @NotNull Collection<? extends Artifact> artifacts, final @NotNull Project project) {
   final Set<Module> modules = new HashSet<Module>();
   final PackagingElementResolvingContext resolvingContext =
       ArtifactManager.getInstance(project).getResolvingContext();
   for (Artifact artifact : artifacts) {
     processPackagingElements(
         artifact,
         null,
         new Processor<PackagingElement<?>>() {
           @Override
           public boolean process(PackagingElement<?> element) {
             if (element instanceof ModuleOutputPackagingElement) {
               ContainerUtil.addIfNotNull(
                   modules, ((ModuleOutputPackagingElement) element).findModule(resolvingContext));
             }
             return true;
           }
         },
         resolvingContext,
         true);
   }
   return modules;
 }
 protected ArtifactManager getArtifactManager() {
   return ArtifactManager.getInstance(myProject);
 }