Search in sources :

Example 41 with JpsArtifact

use of org.jetbrains.jps.model.artifact.JpsArtifact in project intellij-community by JetBrains.

the class IncArtifactBuilder method build.

@Override
public void build(@NotNull ArtifactBuildTarget target, @NotNull DirtyFilesHolder<ArtifactRootDescriptor, ArtifactBuildTarget> holder, @NotNull BuildOutputConsumer outputConsumer, @NotNull final CompileContext context) throws ProjectBuildException {
    JpsArtifact artifact = target.getArtifact();
    String outputFilePath = artifact.getOutputFilePath();
    if (StringUtil.isEmpty(outputFilePath)) {
        context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, "Cannot build '" + artifact.getName() + "' artifact: output path is not specified"));
        return;
    }
    final ProjectDescriptor pd = context.getProjectDescriptor();
    final ArtifactSorter sorter = new ArtifactSorter(pd.getModel());
    final Map<JpsArtifact, JpsArtifact> selfIncludingNameMap = sorter.getArtifactToSelfIncludingNameMap();
    final JpsArtifact selfIncluding = selfIncludingNameMap.get(artifact);
    if (selfIncluding != null) {
        String name = selfIncluding.equals(artifact) ? "it" : "'" + selfIncluding.getName() + "' artifact";
        context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, "Cannot build '" + artifact.getName() + "' artifact: " + name + " includes itself in the output layout"));
        return;
    }
    try {
        final Collection<String> deletedFiles = holder.getRemovedFiles(target);
        String messageText = "Building artifact '" + artifact.getName() + "'...";
        context.processMessage(new ProgressMessage(messageText));
        LOG.debug(messageText);
        runArtifactTasks(context, target.getArtifact(), ArtifactBuildTaskProvider.ArtifactBuildPhase.PRE_PROCESSING);
        final SourceToOutputMapping srcOutMapping = pd.dataManager.getSourceToOutputMap(target);
        final ArtifactOutputToSourceMapping outSrcMapping = pd.dataManager.getStorage(target, ArtifactOutToSourceStorageProvider.INSTANCE);
        final TIntObjectHashMap<Set<String>> filesToProcess = new TIntObjectHashMap<>();
        final MultiMap<String, String> filesToDelete = new MultiMap<>();
        final Set<String> deletedOutputPaths = new THashSet<>(FileUtil.PATH_HASHING_STRATEGY);
        for (String sourcePath : deletedFiles) {
            final Collection<String> outputPaths = srcOutMapping.getOutputs(sourcePath);
            if (outputPaths != null) {
                for (String outputPath : outputPaths) {
                    if (deletedOutputPaths.add(outputPath)) {
                        collectSourcesCorrespondingToOutput(outputPath, sourcePath, deletedFiles, outSrcMapping, filesToProcess, filesToDelete);
                    }
                }
            }
        }
        final Set<String> changedOutputPaths = new THashSet<>(FileUtil.PATH_HASHING_STRATEGY);
        holder.processDirtyFiles(new FileProcessor<ArtifactRootDescriptor, ArtifactBuildTarget>() {

            @Override
            public boolean apply(ArtifactBuildTarget target, File file, ArtifactRootDescriptor root) throws IOException {
                int rootIndex = root.getRootIndex();
                String sourcePath = FileUtil.toSystemIndependentName(file.getPath());
                addFileToProcess(filesToProcess, rootIndex, sourcePath, deletedFiles);
                final Collection<String> outputPaths = srcOutMapping.getOutputs(sourcePath);
                if (outputPaths != null) {
                    for (String outputPath : outputPaths) {
                        if (changedOutputPaths.add(outputPath)) {
                            collectSourcesCorrespondingToOutput(outputPath, sourcePath, deletedFiles, outSrcMapping, filesToProcess, filesToDelete);
                        }
                    }
                }
                return true;
            }
        });
        BuildOperations.cleanOutputsCorrespondingToChangedFiles(context, holder);
        for (String outputPath : changedOutputPaths) {
            outSrcMapping.remove(outputPath);
        }
        if (filesToDelete.isEmpty() && filesToProcess.isEmpty()) {
            return;
        }
        deleteOutdatedFiles(filesToDelete, context, srcOutMapping, outSrcMapping);
        context.checkCanceled();
        context.processMessage(new ProgressMessage("Building artifact '" + artifact.getName() + "': copying files..."));
        final Set<JarInfo> changedJars = new THashSet<>();
        for (ArtifactRootDescriptor descriptor : pd.getBuildRootIndex().getTargetRoots(target, context)) {
            context.checkCanceled();
            final Set<String> sourcePaths = filesToProcess.get(descriptor.getRootIndex());
            if (sourcePaths == null)
                continue;
            for (String sourcePath : sourcePaths) {
                if (!descriptor.getFilter().shouldBeCopied(sourcePath, pd)) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("File " + sourcePath + " will be skipped because it isn't accepted by filter");
                    }
                    continue;
                }
                DestinationInfo destination = descriptor.getDestinationInfo();
                if (destination instanceof ExplodedDestinationInfo) {
                    descriptor.copyFromRoot(sourcePath, descriptor.getRootIndex(), destination.getOutputPath(), context, outputConsumer, outSrcMapping);
                } else {
                    List<ArtifactOutputToSourceMapping.SourcePathAndRootIndex> sources = outSrcMapping.getState(destination.getOutputFilePath());
                    if (sources == null || sources.size() > 0 && sources.get(0).getRootIndex() == descriptor.getRootIndex()) {
                        outSrcMapping.update(destination.getOutputFilePath(), Collections.<ArtifactOutputToSourceMapping.SourcePathAndRootIndex>emptyList());
                        changedJars.add(((JarDestinationInfo) destination).getJarInfo());
                    }
                }
            }
        }
        context.checkCanceled();
        JarsBuilder builder = new JarsBuilder(changedJars, context, outputConsumer, outSrcMapping);
        builder.buildJars();
        runArtifactTasks(context, artifact, ArtifactBuildTaskProvider.ArtifactBuildPhase.FINISHING_BUILD);
        runArtifactTasks(context, artifact, ArtifactBuildTaskProvider.ArtifactBuildPhase.POST_PROCESSING);
    } catch (IOException e) {
        throw new ProjectBuildException(e);
    }
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) SourceToOutputMapping(org.jetbrains.jps.builders.storage.SourceToOutputMapping) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) THashSet(gnu.trove.THashSet) MultiMap(com.intellij.util.containers.MultiMap) ArtifactSorter(org.jetbrains.jps.incremental.artifacts.impl.ArtifactSorter) JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact) IOException(java.io.IOException) THashSet(gnu.trove.THashSet) JarsBuilder(org.jetbrains.jps.incremental.artifacts.impl.JarsBuilder) ProjectDescriptor(org.jetbrains.jps.cmdline.ProjectDescriptor) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) File(java.io.File)

Example 42 with JpsArtifact

use of org.jetbrains.jps.model.artifact.JpsArtifact in project intellij-community by JetBrains.

the class ArtifactSorter method computeArtifactToSelfIncludingNameMap.

private Map<JpsArtifact, JpsArtifact> computeArtifactToSelfIncludingNameMap() {
    final Map<JpsArtifact, JpsArtifact> result = new HashMap<>();
    final Graph<JpsArtifact> graph = createArtifactsGraph();
    for (JpsArtifact artifact : graph.getNodes()) {
        final Iterator<JpsArtifact> in = graph.getIn(artifact);
        while (in.hasNext()) {
            JpsArtifact next = in.next();
            if (next.equals(artifact)) {
                result.put(artifact, artifact);
                break;
            }
        }
    }
    final DFSTBuilder<JpsArtifact> builder = new DFSTBuilder<>(graph);
    if (builder.isAcyclic() && result.isEmpty())
        return Collections.emptyMap();
    for (Collection<JpsArtifact> component : builder.getComponents()) {
        if (component.size() > 1) {
            for (JpsArtifact artifact : component) {
                result.put(artifact, artifact);
            }
        }
    }
    for (int i = 0; i < graph.getNodes().size(); i++) {
        final JpsArtifact artifact = builder.getNodeByTNumber(i);
        if (!result.containsKey(artifact)) {
            final Iterator<JpsArtifact> in = graph.getIn(artifact);
            while (in.hasNext()) {
                final JpsArtifact next = result.get(in.next());
                if (next != null) {
                    result.put(artifact, next);
                }
            }
        }
    }
    return result;
}
Also used : JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact)

Example 43 with JpsArtifact

use of org.jetbrains.jps.model.artifact.JpsArtifact in project intellij-community by JetBrains.

the class JpsBuilderArtifactServiceImpl method getSyntheticArtifacts.

public List<JpsArtifact> getSyntheticArtifacts(final JpsModel model) {
    JpsElementCollection<JpsArtifact> artifactsCollection = model.getProject().getContainer().getChild(SYNTHETIC_ARTIFACTS);
    if (artifactsCollection == null) {
        List<JpsArtifact> artifactList = computeSyntheticArtifacts(model);
        artifactsCollection = model.getProject().getContainer().setChild(SYNTHETIC_ARTIFACTS);
        for (JpsArtifact artifact : artifactList) {
            artifactsCollection.addChild(artifact);
        }
    }
    return artifactsCollection.getElements();
}
Also used : JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact)

Example 44 with JpsArtifact

use of org.jetbrains.jps.model.artifact.JpsArtifact in project intellij-community by JetBrains.

the class JpsArtifactSerializationTest method testSaveProject.

public void testSaveProject() {
    loadProject(SAMPLE_PROJECT_PATH);
    File[] artifactFiles = new File(getTestDataFileAbsolutePath(SAMPLE_PROJECT_PATH + "/.idea/artifacts")).listFiles();
    assertNotNull(artifactFiles);
    for (File file : artifactFiles) {
        JpsArtifact artifact = getService().createReference(FileUtil.getNameWithoutExtension(file)).asExternal(myModel).resolve();
        assertNotNull(artifact);
        doTestSaveArtifact(artifact, file);
    }
}
Also used : JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact) File(java.io.File)

Example 45 with JpsArtifact

use of org.jetbrains.jps.model.artifact.JpsArtifact in project intellij-community by JetBrains.

the class JpsArtifactOutputPackagingElementImpl method getSubstitution.

@Override
public List<JpsPackagingElement> getSubstitution() {
    JpsArtifact artifact = getArtifactReference().resolve();
    if (artifact == null)
        return Collections.emptyList();
    JpsCompositePackagingElement rootElement = artifact.getRootElement();
    if (rootElement instanceof JpsArtifactRootElement) {
        return new ArrayList<>(rootElement.getChildren());
    } else {
        return Collections.<JpsPackagingElement>singletonList(rootElement);
    }
}
Also used : JpsPackagingElement(org.jetbrains.jps.model.artifact.elements.JpsPackagingElement) JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact) ArrayList(java.util.ArrayList) JpsArtifactRootElement(org.jetbrains.jps.model.artifact.elements.JpsArtifactRootElement) JpsCompositePackagingElement(org.jetbrains.jps.model.artifact.elements.JpsCompositePackagingElement)

Aggregations

JpsArtifact (org.jetbrains.jps.model.artifact.JpsArtifact)85 File (java.io.File)10 JpsModule (org.jetbrains.jps.model.module.JpsModule)10 JarFile (java.util.jar.JarFile)4 ZipFile (java.util.zip.ZipFile)4 IOException (java.io.IOException)3 NotNull (org.jetbrains.annotations.NotNull)3 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)3 JpsCompositePackagingElement (org.jetbrains.jps.model.artifact.elements.JpsCompositePackagingElement)3 THashSet (gnu.trove.THashSet)2 JpsAndroidModuleExtension (org.jetbrains.jps.android.model.JpsAndroidModuleExtension)2 JpsElement (org.jetbrains.jps.model.JpsElement)2 JpsPackagingElement (org.jetbrains.jps.model.artifact.elements.JpsPackagingElement)2 JpsLibrary (org.jetbrains.jps.model.library.JpsLibrary)2 BuildFileProperty (com.intellij.lang.ant.config.impl.BuildFileProperty)1 SmartList (com.intellij.util.SmartList)1 HashMap (com.intellij.util.containers.HashMap)1 HashSet (com.intellij.util.containers.HashSet)1 MultiMap (com.intellij.util.containers.MultiMap)1 TIntObjectHashMap (gnu.trove.TIntObjectHashMap)1