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);
}
}
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;
}
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();
}
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);
}
}
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);
}
}
Aggregations