@Override public void addElementsToDirectory( @NotNull Artifact artifact, @NotNull String relativePath, @NotNull PackagingElement<?> element) { addElementsToDirectory(artifact, relativePath, Collections.singletonList(element)); }
@Override public ArtifactManagerState getState() { final ArtifactManagerState state = new ArtifactManagerState(); for (Artifact artifact : getAllArtifactsIncludingInvalid()) { final ArtifactState artifactState; if (artifact instanceof InvalidArtifact) { artifactState = ((InvalidArtifact) artifact).getState(); } else { artifactState = new ArtifactState(); artifactState.setBuildOnMake(artifact.isBuildOnMake()); artifactState.setName(artifact.getName()); artifactState.setOutputPath(artifact.getOutputPath()); artifactState.setRootElement(serializePackagingElement(artifact.getRootElement())); artifactState.setArtifactType(artifact.getArtifactType().getId()); for (ArtifactPropertiesProvider provider : artifact.getPropertiesProviders()) { final ArtifactPropertiesState propertiesState = serializeProperties(provider, artifact.getProperties(provider)); if (propertiesState != null) { artifactState.getPropertiesList().add(propertiesState); } } Collections.sort( artifactState.getPropertiesList(), new Comparator<ArtifactPropertiesState>() { @Override public int compare( @NotNull ArtifactPropertiesState o1, @NotNull ArtifactPropertiesState o2) { return o1.getId().compareTo(o2.getId()); } }); } state.getArtifacts().add(artifactState); } return state; }
public static List<VirtualFile> findSourceFilesByOutputPath( CompositePackagingElement<?> parent, final String outputPath, final PackagingElementResolvingContext context, final ArtifactType artifactType) { final String path = StringUtil.trimStart(outputPath, "/"); if (path.length() == 0) { return Collections.emptyList(); } int i = path.indexOf('/'); final String firstName = i != -1 ? path.substring(0, i) : path; final String tail = i != -1 ? path.substring(i + 1) : ""; final List<VirtualFile> result = new SmartList<VirtualFile>(); processElementsWithSubstitutions( parent.getChildren(), context, artifactType, PackagingElementPath.EMPTY, new PackagingElementProcessor<PackagingElement<?>>() { @Override public boolean process( @NotNull PackagingElement<?> element, @NotNull PackagingElementPath elementPath) { // todo[nik] replace by method findSourceFile() in PackagingElement if (element instanceof CompositePackagingElement) { final CompositePackagingElement<?> compositeElement = (CompositePackagingElement<?>) element; if (firstName.equals(compositeElement.getName())) { result.addAll( findSourceFilesByOutputPath(compositeElement, tail, context, artifactType)); } } else if (element instanceof FileCopyPackagingElement) { final FileCopyPackagingElement fileCopyElement = (FileCopyPackagingElement) element; if (firstName.equals(fileCopyElement.getOutputFileName()) && tail.length() == 0) { ContainerUtil.addIfNotNull(fileCopyElement.findFile(), result); } } else if (element instanceof DirectoryCopyPackagingElement || element instanceof ExtractedDirectoryPackagingElement) { final VirtualFile sourceRoot = ((FileOrDirectoryCopyPackagingElement<?>) element).findFile(); if (sourceRoot != null) { ContainerUtil.addIfNotNull(sourceRoot.findFileByRelativePath(path), result); } } else if (element instanceof ModuleOutputPackagingElement) { final CompilerConfiguration compilerConfiguration = CompilerConfiguration.getInstance(context.getProject()); for (VirtualFile sourceRoot : ((ModuleOutputPackagingElement) element).getSourceRoots(context)) { final VirtualFile sourceFile = sourceRoot.findFileByRelativePath(path); if (sourceFile != null && compilerConfiguration.isResourceFile(sourceFile)) { result.add(sourceFile); } } } return true; } }); return result; }