Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send sources to roboRIO on deploy #739

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,19 @@ public FRCExtension(Project project, DeployExtension deployExtension) {
t.getDebugFile().set(project.getLayout().getBuildDirectory().file("debug/debug_info.json"));
});

zipSourcesTask = project.getTasks().register("writeSourcesZip", ZipSourcesTask.class, t -> {
t.setBuildDirectory(project.getLayout().getBuildDirectory().toString());
t.setProjectDirectory(project.getProjectDir().toString());
});

deployExtension.getDeployTask().configure(t -> {
t.dependsOn(debugFileTask);
t.dependsOn(zipSourcesTask);
});
}

private final TaskProvider<DebugFileTask> debugFileTask;
private final TaskProvider<ZipSourcesTask> zipSourcesTask;

public TaskProvider<DebugFileTask> getDebugFileTask() {
return debugFileTask;
Expand Down
73 changes: 73 additions & 0 deletions src/main/java/edu/wpi/first/gradlerio/deploy/ZipSourcesTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package edu.wpi.first.gradlerio.deploy;

import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.OutputFile;

import java.util.zip.ZipOutputStream;
import java.util.zip.ZipEntry;
import java.io.File;
import java.io.IOException;
import java.io.FileOutputStream;
import java.io.FileInputStream;

public class ZipSourcesTask extends DefaultTask {
private String m_buildDirectory;
private String m_projectDirectory;
private FileOutputStream m_outFOS;

public void setBuildDirectory(String buildDirectory) {
m_buildDirectory = buildDirectory;
}

public void setProjectDirectory(String projectDirectory) {
m_projectDirectory = projectDirectory;
}

@TaskAction
public void execute() throws IOException {
m_outFOS = new FileOutputStream(m_buildDirectory + "/sources.zip");
ZipOutputStream zipOut = new ZipOutputStream(m_outFOS);

File fileToZip = new File(m_projectDirectory);
zipFile(fileToZip, fileToZip.getName(), zipOut);
zipOut.close();
m_outFOS.close();
}

@OutputFile
public FileOutputStream getSourcesZip() {
return m_outFOS;
};

private static void zipFile(File fileToZip, String fileName, ZipOutputStream zipOut) throws IOException {
if (fileToZip.isHidden()) {
return;
}
if (fileToZip.isDirectory()) {
if (fileName.endsWith("/")) {
zipOut.putNextEntry(new ZipEntry(fileName));
zipOut.closeEntry();
} else {
zipOut.putNextEntry(new ZipEntry(fileName + "/"));
zipOut.closeEntry();
}
File[] children = fileToZip.listFiles();
for (File childFile : children) {
if (children.toString() != "build") {
zipFile(childFile, fileName + "/" + childFile.getName(), zipOut);
}
}
return;
}
FileInputStream fis = new FileInputStream(fileToZip);
ZipEntry zipEntry = new ZipEntry(fileName);
zipOut.putNextEntry(zipEntry);
byte[] bytes = new byte[1024];
int length;
while ((length = fis.read(bytes)) >= 0) {
zipOut.write(bytes, 0, length);
}
fis.close();
}
}
Loading