Skip to content

Commit

Permalink
0.3.5 zip project
Browse files Browse the repository at this point in the history
  • Loading branch information
JakkuSakura committed Aug 4, 2021
1 parent 5959751 commit cbe3221
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 21 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
# IntelliJ Idea Astor Plugin ChangeLog

## [Unreleased]
## [0.3.5]
- Zip project
- Disable line wrap
- Colored logging level

## [0.3.4]
- Simplify cleaning code step

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

pluginGroup = org.bytecamp.program_repair.astor_plugin
pluginName = IntelliJ Idea Astor Plugin
pluginVersion = 0.3.4
pluginVersion = 0.3.5

# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,29 +1,43 @@
package org.bytecamp.program_repair.astor_plugin.services

import com.google.protobuf.ByteString
import com.intellij.notification.NotificationGroupManager
import com.intellij.notification.NotificationType
import com.intellij.openapi.project.Project
import io.grpc.ManagedChannel
import io.grpc.ManagedChannelBuilder
import org.bytecamp.program_repair.astor_plugin.configs.AppSettingsState
import org.bytecamp.program_repair.astor_plugin.utils.ZipManager
import org.bytecamp.program_repair.astor_plugin.window.AstorNotification
import org.bytecamp.program_repair.astor_plugin.window.AstorWindowFactory
import org.bytecamp.program_repair.backend.grpc.RepairServerGrpc
import org.bytecamp.program_repair.backend.grpc.RepairTaskRequest
import org.bytecamp.program_repair.backend.grpc.RepairTaskResponse
import org.bytecamp.program_repair.backend.grpc.RepairTaskResult
import java.io.ByteArrayOutputStream
import java.io.File


class AstorProjectService(val project: Project) {
private val logger = com.intellij.openapi.diagnostic.Logger.getInstance(AstorProjectService::class.java)

var lastResults: List<RepairTaskResult>? = null
val window = AstorWindowFactory.getAstorOutput(project)!!
private fun includeFiles(node: File, collector: ArrayList<File>) {
if (node.name.startsWith(".")) return
if (node.isFile) {
collector.add(node)
} else if (node.isDirectory) {
for (child in node.listFiles())
includeFiles(child, collector)
}
}

fun execute(): List<RepairTaskResult>? {
window.clear()
lastResults = null
try {
val projectBase = project.basePath!!
val settings = AppSettingsState.instance
val spt = settings.backendAddress.split(":")
val host = spt[0]
Expand All @@ -33,12 +47,29 @@ class AstorProjectService(val project: Project) {
.build()

val grpcStub = RepairServerGrpc.newBlockingStub(channel)
val request = RepairTaskRequest.newBuilder()
.setLocationType(RepairTaskRequest.LocationType.PATH)
.setLocation(project.basePath)
.setAlgorithm(settings.algorithm)
val builder = RepairTaskRequest.newBuilder().setProject(project.name)
if (host == "localhost") {
builder
.setLocationType(RepairTaskRequest.LocationType.PATH)
.setLocation(projectBase)

} else {
val out = ByteArrayOutputStream()
val files = ArrayList<File>()
includeFiles(File(projectBase), files)
ZipManager.zip(File(projectBase), files, out)
builder
.setLocationType(RepairTaskRequest.LocationType.ZIP)
.setContent(ByteString.copyFrom(out.toByteArray()))
}

val request = builder.setAlgorithm(settings.algorithm)
.build()

val request2 = builder.setContent(ByteString.EMPTY)
.build()
window.appendText("\nRequesting with args $request\n")
window.appendText("\nRequesting with args $request2\n")

var results: List<RepairTaskResult>? = null
for (resp in grpcStub.submitTask(request)) {
when (resp.frameType) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.bytecamp.program_repair.astor_plugin.utils

import java.io.File
import java.io.FileInputStream
import java.io.OutputStream
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream

object ZipManager {

fun zip(base: File, files: List<File>, out: OutputStream) {
val buf = ByteArray(1024);

val zos = ZipOutputStream(out);
for (file in files) {
val fis = FileInputStream(file);
zos.putNextEntry(ZipEntry(file.relativeTo(base).path));

while (true) {
val len = fis.read(buf)
if (len < 0)
break
zos.write(buf, 0, len)
}
zos.closeEntry()
fis.close()
}
zos.close();

}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.bytecamp.program_repair.astor_plugin.window

import org.jetbrains.debugger.sourcemap.doCanonicalize
import java.awt.BorderLayout
import javax.swing.JPanel
import javax.swing.JTextArea
Expand Down

0 comments on commit cbe3221

Please sign in to comment.