use of org.jetbrains.kotlin.backend.common.output.OutputFile in project kotlin by JetBrains.
the class CompileEnvironmentUtil method doWriteToJar.
// TODO: includeRuntime should be not a flag but a path to runtime
private static void doWriteToJar(OutputFileCollection outputFiles, OutputStream fos, @Nullable FqName mainClass, boolean includeRuntime) {
try {
Manifest manifest = new Manifest();
Attributes mainAttributes = manifest.getMainAttributes();
mainAttributes.putValue("Manifest-Version", "1.0");
mainAttributes.putValue("Created-By", "JetBrains Kotlin");
if (mainClass != null) {
mainAttributes.putValue("Main-Class", mainClass.asString());
}
JarOutputStream stream = new JarOutputStream(fos, manifest);
for (OutputFile outputFile : outputFiles.asList()) {
stream.putNextEntry(new JarEntry(outputFile.getRelativePath()));
stream.write(outputFile.asByteArray());
}
if (includeRuntime) {
writeRuntimeToJar(stream);
}
stream.finish();
} catch (IOException e) {
throw new CompileEnvironmentException("Failed to generate jar file", e);
}
}
use of org.jetbrains.kotlin.backend.common.output.OutputFile in project kotlin by JetBrains.
the class InlineCodegenUtil method buildClassReaderByInternalName.
@NotNull
static /* package */
ClassReader buildClassReaderByInternalName(@NotNull GenerationState state, @NotNull String internalName) {
//try to find just compiled classes then in dependencies
try {
OutputFile outputFile = state.getFactory().get(internalName + ".class");
if (outputFile != null) {
return new ClassReader(outputFile.asByteArray());
}
VirtualFile file = findVirtualFileImprecise(state, internalName);
if (file != null) {
return new ClassReader(file.contentsToByteArray());
}
throw new RuntimeException("Couldn't find virtual file for " + internalName);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.jetbrains.kotlin.backend.common.output.OutputFile in project kotlin by JetBrains.
the class ClassFileFactory method createText.
@NotNull
@TestOnly
public String createText() {
StringBuilder answer = new StringBuilder();
for (OutputFile file : asList()) {
answer.append("@").append(file.getRelativePath()).append('\n');
answer.append(file.asText());
}
return answer.toString();
}
use of org.jetbrains.kotlin.backend.common.output.OutputFile in project kotlin by JetBrains.
the class GeneratedClassLoader method findClass.
@NotNull
@Override
protected Class<?> findClass(@NotNull String name) throws ClassNotFoundException {
String classFilePath = name.replace('.', '/') + ".class";
OutputFile outputFile = factory.get(classFilePath);
if (outputFile != null) {
byte[] bytes = outputFile.asByteArray();
int lastDot = name.lastIndexOf('.');
if (lastDot >= 0) {
String pkgName = name.substring(0, lastDot);
if (getPackage(pkgName) == null) {
definePackage(pkgName, new Manifest(), null);
}
}
return defineClass(name, bytes, 0, bytes.length);
}
return super.findClass(name);
}
Aggregations