use of org.jetbrains.jps.builders.logging.ProjectBuilderLogger in project intellij-community by JetBrains.
the class JarsBuilder method buildJar.
private void buildJar(final JarInfo jar) throws IOException {
final String emptyArchiveMessage = "Archive '" + jar.getPresentableDestination() + "' doesn't contain files so it won't be created";
if (jar.getContent().isEmpty()) {
myContext.processMessage(new CompilerMessage(IncArtifactBuilder.BUILDER_NAME, BuildMessage.Kind.WARNING, emptyArchiveMessage));
return;
}
myContext.processMessage(new ProgressMessage("Building " + jar.getPresentableDestination() + "..."));
File jarFile = FileUtil.createTempFile("artifactCompiler", "tmp");
myBuiltJars.put(jar, jarFile);
FileUtil.createParentDirs(jarFile);
final String targetJarPath = jar.getDestination().getOutputFilePath();
List<String> packedFilePaths = new ArrayList<>();
Manifest manifest = loadManifest(jar, packedFilePaths);
final JarOutputStream jarOutputStream = createJarOutputStream(jarFile, manifest);
final THashSet<String> writtenPaths = new THashSet<>();
try {
if (manifest != null) {
writtenPaths.add(JarFile.MANIFEST_NAME);
}
for (Pair<String, Object> pair : jar.getContent()) {
final String relativePath = pair.getFirst();
if (pair.getSecond() instanceof ArtifactRootDescriptor) {
final ArtifactRootDescriptor descriptor = (ArtifactRootDescriptor) pair.getSecond();
final int rootIndex = descriptor.getRootIndex();
if (descriptor instanceof FileBasedArtifactRootDescriptor) {
addFileToJar(jarOutputStream, jarFile, descriptor.getRootFile(), descriptor.getFilter(), relativePath, targetJarPath, writtenPaths, packedFilePaths, rootIndex);
} else {
final String filePath = FileUtil.toSystemIndependentName(descriptor.getRootFile().getAbsolutePath());
packedFilePaths.add(filePath);
myOutSrcMapping.appendData(targetJarPath, rootIndex, filePath);
extractFileAndAddToJar(jarOutputStream, (JarBasedArtifactRootDescriptor) descriptor, relativePath, writtenPaths);
}
} else {
JarInfo nestedJar = (JarInfo) pair.getSecond();
File nestedJarFile = myBuiltJars.get(nestedJar);
if (nestedJarFile != null) {
addFileToJar(jarOutputStream, jarFile, nestedJarFile, SourceFileFilter.ALL, relativePath, targetJarPath, writtenPaths, packedFilePaths, -1);
} else {
LOG.debug("nested JAR file " + relativePath + " for " + jar.getPresentableDestination() + " not found");
}
}
}
if (writtenPaths.isEmpty()) {
myContext.processMessage(new CompilerMessage(IncArtifactBuilder.BUILDER_NAME, BuildMessage.Kind.WARNING, emptyArchiveMessage));
return;
}
final ProjectBuilderLogger logger = myContext.getLoggingManager().getProjectBuilderLogger();
if (logger.isEnabled()) {
logger.logCompiledPaths(packedFilePaths, IncArtifactBuilder.BUILDER_NAME, "Packing files:");
}
myOutputConsumer.registerOutputFile(new File(targetJarPath), packedFilePaths);
} finally {
if (writtenPaths.isEmpty()) {
try {
jarOutputStream.close();
} catch (IOException ignored) {
}
FileUtil.delete(jarFile);
myBuiltJars.remove(jar);
} else {
jarOutputStream.close();
}
}
}
use of org.jetbrains.jps.builders.logging.ProjectBuilderLogger in project intellij-community by JetBrains.
the class FileBasedArtifactRootDescriptor method copyFromRoot.
public void copyFromRoot(String filePath, int rootIndex, String outputPath, CompileContext context, BuildOutputConsumer outputConsumer, ArtifactOutputToSourceMapping outSrcMapping) throws IOException, ProjectBuildException {
final File file = new File(filePath);
if (!file.exists())
return;
String targetPath;
if (!FileUtil.filesEqual(file, getRootFile())) {
final String relativePath = FileUtil.getRelativePath(FileUtil.toSystemIndependentName(getRootFile().getPath()), filePath, '/');
if (relativePath == null || relativePath.startsWith("..")) {
throw new ProjectBuildException(new AssertionError(filePath + " is not under " + getRootFile().getPath()));
}
targetPath = JpsArtifactPathUtil.appendToPath(outputPath, relativePath);
} else {
targetPath = outputPath;
}
final File targetFile = new File(targetPath);
if (FileUtil.filesEqual(file, targetFile)) {
//do not process file if should be copied to itself. Otherwise the file will be included to source-to-output mapping and will be deleted by rebuild
return;
}
if (outSrcMapping.getState(targetPath) == null) {
ProjectBuilderLogger logger = context.getLoggingManager().getProjectBuilderLogger();
if (logger.isEnabled()) {
logger.logCompiledFiles(Collections.singletonList(file), IncArtifactBuilder.BUILDER_NAME, "Copying file:");
}
myCopyingHandler.copyFile(file, targetFile, context);
outputConsumer.registerOutputFile(targetFile, Collections.singletonList(filePath));
} else if (LOG.isDebugEnabled()) {
LOG.debug("Target path " + targetPath + " is already registered so " + filePath + " won't be copied");
}
outSrcMapping.appendData(targetPath, rootIndex, filePath);
}
use of org.jetbrains.jps.builders.logging.ProjectBuilderLogger in project intellij-community by JetBrains.
the class JarBasedArtifactRootDescriptor method copyFromRoot.
public void copyFromRoot(final String filePath, final int rootIndex, final String outputPath, CompileContext context, final BuildOutputConsumer outputConsumer, final ArtifactOutputToSourceMapping outSrcMapping) throws IOException {
if (!myRoot.isFile())
return;
ProjectBuilderLogger logger = context.getLoggingManager().getProjectBuilderLogger();
if (logger.isEnabled()) {
logger.logCompiledPaths(Collections.singletonList(filePath), IncArtifactBuilder.BUILDER_NAME, "Extracting archive:");
}
processEntries(new EntryProcessor() {
@Override
public void process(@Nullable InputStream inputStream, @NotNull String relativePath, ZipEntry entry) throws IOException {
final String fullOutputPath = JpsArtifactPathUtil.appendToPath(outputPath, relativePath);
final File outputFile = new File(fullOutputPath);
FileUtil.createParentDirs(outputFile);
if (inputStream == null) {
outputFile.mkdir();
} else {
if (outSrcMapping.getState(fullOutputPath) == null) {
final BufferedInputStream from = new BufferedInputStream(inputStream);
final BufferedOutputStream to = new BufferedOutputStream(new FileOutputStream(outputFile));
try {
FileUtil.copy(from, to);
} finally {
from.close();
to.close();
}
outputConsumer.registerOutputFile(outputFile, Collections.singletonList(filePath));
}
outSrcMapping.appendData(fullOutputPath, rootIndex, filePath);
}
}
});
}
use of org.jetbrains.jps.builders.logging.ProjectBuilderLogger in project intellij-community by JetBrains.
the class JavaBuilder method doBuild.
public ExitCode doBuild(@NotNull CompileContext context, @NotNull ModuleChunk chunk, @NotNull DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, @NotNull OutputConsumer outputConsumer, @NotNull JavaCompilingTool compilingTool) throws ProjectBuildException, IOException {
try {
final Set<File> filesToCompile = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
dirtyFilesHolder.processDirtyFiles(new FileProcessor<JavaSourceRootDescriptor, ModuleBuildTarget>() {
@Override
public boolean apply(ModuleBuildTarget target, File file, JavaSourceRootDescriptor descriptor) throws IOException {
if (JAVA_SOURCES_FILTER.accept(file) && ourCompilableModuleTypes.contains(target.getModule().getModuleType())) {
filesToCompile.add(file);
}
return true;
}
});
if ((!filesToCompile.isEmpty() || dirtyFilesHolder.hasRemovedFiles()) && JpsJavaSdkType.parseVersion(getLanguageLevel(ContainerUtil.getFirstItem(chunk.getModules()))) >= 9) {
// at the moment, there is no incremental compilation for module-info files, so they should be rebuilt on every change
JavaModuleIndex index = getJavaModuleIndex(context);
for (JpsModule module : chunk.getModules()) {
ContainerUtil.addIfNotNull(filesToCompile, index.getModuleInfoFile(module));
}
}
if (JavaBuilderUtil.isCompileJavaIncrementally(context)) {
ProjectBuilderLogger logger = context.getLoggingManager().getProjectBuilderLogger();
if (logger.isEnabled() && !filesToCompile.isEmpty()) {
logger.logCompiledFiles(filesToCompile, BUILDER_NAME, "Compiling files:");
}
}
return compile(context, chunk, dirtyFilesHolder, filesToCompile, outputConsumer, compilingTool);
} catch (BuildDataCorruptedException | PersistentEnumeratorBase.CorruptedException | ProjectBuildException e) {
throw e;
} catch (Exception e) {
LOG.info(e);
String message = e.getMessage();
if (message == null) {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final PrintStream stream = new PrintStream(out);
try {
e.printStackTrace(stream);
} finally {
stream.close();
}
message = "Internal error: \n" + out;
}
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, message));
throw new StopBuildException();
}
}
use of org.jetbrains.jps.builders.logging.ProjectBuilderLogger in project intellij-plugins by JetBrains.
the class OsgiBuildSession method build.
public void build(@NotNull OsmorcBuildTarget target, @NotNull CompileContext context) throws IOException {
myTarget = target;
myContext = context;
myExtension = target.getExtension();
myModule = target.getModule();
myMessagePrefix = "[" + myModule.getName() + "] ";
progress("Building OSGi bundle");
try {
prepare();
doBuild();
} catch (OsgiBuildException e) {
error(e.getMessage(), e.getCause(), e.getSourcePath(), -1);
return;
}
for (File jarFile : myOutputJarFiles) {
if (!jarFile.exists()) {
error("Bundle was not built: " + jarFile, null, null, -1);
return;
}
}
ProjectBuilderLogger logger = context.getLoggingManager().getProjectBuilderLogger();
if (logger.isEnabled()) {
logger.logCompiledFiles(myOutputJarFiles, OsmorcBuilder.ID, "Built OSGi bundles:");
}
context.processMessage(DoneSomethingNotification.INSTANCE);
}
Aggregations