Skip to content

Commit af54d55

Browse files
committed
adding file selection
1 parent e82fef5 commit af54d55

File tree

4 files changed

+128
-6
lines changed

4 files changed

+128
-6
lines changed

LabCodeRepoSetup/build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ dependencies {
2626
// Use JUnit test framework
2727
testImplementation 'junit:junit:4.12'
2828
compile group: 'org.kohsuke', name: 'github-api', version: '1.94'
29-
implementation 'com.google.code.gson:gson:2.8.5'
29+
implementation 'com.google.code.gson:gson:2.8.5'
30+
compile 'com.google.crypto.tink:tink:1.3.0-rc1'
31+
compile group: 'org.json', name: 'json', version: '20180813'
32+
compile group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '4.0.1.201506240215-r'
33+
compile group: 'com.neuronrobotics', name:'GithubPasswordManager', version:'0.0.3'
34+
35+
3036
}
3137

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package edu.wpi.rbe;
2+
3+
4+
import java.io.File;
5+
6+
import javafx.application.Platform;
7+
import javafx.stage.DirectoryChooser;
8+
import javafx.stage.FileChooser;
9+
import javafx.stage.FileChooser.ExtensionFilter;
10+
11+
12+
public class FileSelectionFactory {
13+
14+
15+
private FileSelectionFactory() {
16+
}
17+
private static class fileHolder{
18+
private boolean done=false;
19+
private File file=null;
20+
public boolean isDone() {
21+
return done;
22+
}
23+
public void setDone(boolean done) {
24+
this.done = done;
25+
}
26+
public File getFile() {
27+
return file;
28+
}
29+
public void setFile(File file) {
30+
this.file = file;
31+
}
32+
}
33+
public static File GetFile(File start, boolean save, ExtensionFilter... filter) {
34+
if(start==null)
35+
throw new NullPointerException();
36+
37+
final fileHolder file=new fileHolder();
38+
com.sun.javafx.application.PlatformImpl.startup(()->{});
39+
Platform.runLater(() -> {
40+
FileChooser fileChooser = new FileChooser();
41+
42+
fileChooser.setInitialDirectory(start.isDirectory()?start:start.getParentFile());
43+
if(filter!=null)
44+
fileChooser.getExtensionFilters().addAll(filter);
45+
fileChooser.setTitle("Bowler File Chooser");
46+
if(save)
47+
file.setFile(fileChooser.showSaveDialog(null));
48+
else
49+
file.setFile(fileChooser.showOpenDialog(null));
50+
file.setDone(true);
51+
52+
});
53+
while(!file.isDone()){
54+
try {
55+
Thread.sleep(16);
56+
} catch (InterruptedException e) {
57+
// TODO Auto-generated catch block
58+
e.printStackTrace();
59+
}
60+
}
61+
62+
return file.getFile();
63+
}
64+
public static File GetFile(File start, ExtensionFilter... filter) {
65+
return GetFile(start, false,filter);
66+
}
67+
68+
public static File GetDirectory(File start) {
69+
if(start==null)
70+
throw new NullPointerException();
71+
72+
final fileHolder file=new fileHolder();
73+
Platform.runLater(() -> {
74+
DirectoryChooser fileChooser = new DirectoryChooser();
75+
76+
fileChooser.setInitialDirectory(start.isDirectory()?start:start.getParentFile());
77+
fileChooser.setTitle("Bowler File Chooser");
78+
file.setFile(fileChooser.showDialog(null));
79+
file.setDone(true);
80+
81+
});
82+
while(!file.isDone()){
83+
try {
84+
Thread.sleep(16);
85+
} catch (InterruptedException e) {
86+
// TODO Auto-generated catch block
87+
e.printStackTrace();
88+
}
89+
}
90+
91+
return file.getFile();
92+
}
93+
94+
}

LabCodeRepoSetup/src/main/java/edu/wpi/rbe/LabCodeRepoSetupMain.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
import com.google.gson.Gson;
3030
import com.google.gson.GsonBuilder;
3131
import com.google.gson.reflect.TypeToken;
32+
import com.neuronrobotics.bowlerstudio.scripting.PasswordManager;
33+
34+
import javafx.stage.FileChooser.ExtensionFilter;
3235

3336
/**
3437
* @author hephaestus
@@ -43,7 +46,12 @@ public class LabCodeRepoSetupMain {
4346
*/
4447
public static void main(String[] args) throws Exception {
4548
HashSet<GHUser> allStudents = new HashSet<>();
46-
String teamAssignmentsFile = args[0];
49+
String path = FileSelectionFactory.GetFile(
50+
new File(".")
51+
,new ExtensionFilter("json file","*.JSON","*.json")
52+
)
53+
.getAbsolutePath();
54+
String teamAssignmentsFile = path;
4755
int numberOfTeams = 0;
4856

4957
Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();
@@ -106,7 +114,21 @@ public static void main(String[] args) throws Exception {
106114
}
107115
}
108116

109-
GitHub github = GitHub.connect();
117+
118+
File workspace = new File(System.getProperty("user.home") + "/bowler-workspace/");
119+
if (!workspace.exists()) {
120+
workspace.mkdir();
121+
}
122+
try {
123+
PasswordManager.loadLoginData(workspace);
124+
} catch (Exception e) {
125+
// TODO Auto-generated catch block
126+
e.printStackTrace();
127+
}
128+
PasswordManager.login();
129+
GitHub github = PasswordManager.getGithub();
130+
131+
110132
GHOrganization dest = github.getMyOrganizations().get(projectDestBaseName);
111133

112134
if (dest == null) {

LabCodeRepoSetup/teamAssignments2001.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"projectName":["RBE200x-lab"],
44
"repoDestBaseNames":["RBE2001Code"],
55
"teamDestBaseName":["RBE200xTeam"],
6-
"numberOfTeams":["21"],
6+
"numberOfTeams":["22"],
77
"RBE2001Code":["WPIRoboticsEngineering","RBE2001_template"],
88

9-
"21": ["madhephaestus"]
10-
}
9+
"22": ["madhephaestus"]
10+
}

0 commit comments

Comments
 (0)