|
a/tool/run/plugins/spdx/create.java |
|
b/tool/run/plugins/spdx/create.java |
|
... |
|
... |
10 |
* FileComment: <text> Add the node of tools inside the tree view. </text>
|
10 |
* FileComment: <text> Add the node of tools inside the tree view. </text>
|
11 |
*/
|
11 |
*/
|
12 |
|
12 |
|
13 |
package spdx;
|
13 |
package spdx;
|
14 |
|
14 |
|
|
|
15 |
import GUI.swingUtils;
|
15 |
import spdxlib.DocumentCreate;
|
16 |
import spdxlib.DocumentCreate;
|
16 |
import definitions.Messages;
|
17 |
import definitions.Messages;
|
|
|
18 |
import definitions.is;
|
17 |
import java.io.File;
|
19 |
import java.io.File;
|
18 |
import java.io.IOException;
|
20 |
import java.io.IOException;
|
19 |
import java.util.logging.Level;
|
21 |
import java.util.logging.Level;
|
20 |
import java.util.logging.Logger;
|
22 |
import java.util.logging.Logger;
|
21 |
import script.Plugin;
|
23 |
import script.Plugin;
|
|
... |
|
... |
27 |
import org.rauschig.jarchivelib.ArchiverFactory;
|
29 |
import org.rauschig.jarchivelib.ArchiverFactory;
|
28 |
import org.rauschig.jarchivelib.CompressionType;
|
30 |
import org.rauschig.jarchivelib.CompressionType;
|
29 |
import script.DownloadBigFile;
|
31 |
import script.DownloadBigFile;
|
30 |
import script.RunningTask;
|
32 |
import script.RunningTask;
|
31 |
import utils.html;
|
33 |
import utils.html;
|
|
|
34 |
import www.Form;
|
|
|
35 |
import www.RequestOrigin;
|
32 |
import www.WebRequest;
|
36 |
import www.WebRequest;
|
33 |
|
37 |
|
34 |
|
38 |
|
35 |
/**
|
39 |
/**
|
36 |
*
|
40 |
*
|
|
... |
|
... |
38 |
* nuno.brito@triplecheck.de | http://nunobrito.eu
|
42 |
* nuno.brito@triplecheck.de | http://nunobrito.eu
|
39 |
*/
|
43 |
*/
|
40 |
public class create extends Plugin{
|
44 |
public class create extends Plugin{
|
41 |
|
45 |
|
42 |
final String
|
46 |
final String
|
|
|
47 |
id = "Create SPDX",
|
43 |
LastFolderNewSPDX = "LastFolderNewSPDX",
|
48 |
LastFolderNewSPDX = "LastFolderNewSPDX";
|
44 |
id = "Create New SPDX";
|
49 |
|
45 |
|
|
|
46 |
final String acceptedExtension =
|
50 |
final String acceptedExtension =
|
47 |
".tar.gz"
|
51 |
".tar.gz"
|
48 |
+ ">>"
|
52 |
+ ">>"
|
49 |
+ "zip";
|
53 |
+ "zip";
|
50 |
|
54 |
|
|
... |
|
... |
59 |
/**
|
63 |
/**
|
60 |
* Add our toolbox node to the treeview.
|
64 |
* Add our toolbox node to the treeview.
|
61 |
*/
|
65 |
*/
|
62 |
public void addNode(){
|
66 |
public void addNode(){
|
63 |
addTreeNode(id, "box--plus.png", "main");
|
67 |
addTreeNode(id, "box--plus.png", "main");
|
|
|
68 |
|
|
|
69 |
addChildNode("from web", "application-dock-270.png", "mainWeb");
|
|
|
70 |
addChildNode("from folder", "folder-smiley.png", "mainFolder");
|
|
|
71 |
addChildNode("from zipped file", "vise-drawer.png", "mainZip");
|
|
|
72 |
|
64 |
}
|
73 |
}
|
65 |
|
74 |
|
66 |
/**
|
75 |
/**
|
67 |
* Displays the menu for creating new SPDX documents
|
76 |
* Displays the menu for creating new SPDX documents
|
68 |
* @param request the request for this method
|
77 |
* @param request the request for this method
|
69 |
*/
|
78 |
*/
|
70 |
@Override
|
79 |
@Override
|
71 |
public void main(WebRequest request){
|
80 |
public void main(WebRequest request){
|
|
|
81 |
//request.setPage("spdxDialog.html");
|
|
|
82 |
String result = "<html>\n" +
|
|
|
83 |
"<head>\n" +
|
|
|
84 |
"<style type=\"text/css\">body {font-family:verdana,arial,"
|
|
|
85 |
+ "sans-serif;font-size:10pt;margin:30px;}</style>"
|
|
|
86 |
+ "</head>\n" +
|
|
|
87 |
"\n" +
|
|
|
88 |
"<body>"
|
|
|
89 |
+ ""
|
|
|
90 |
+ "Testing stuff!"
|
|
|
91 |
+ ""
|
|
|
92 |
+ "</body>"
|
|
|
93 |
+ "</html>";
|
|
|
94 |
request.setAnswer(result);
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
public void mainWeb(WebRequest request){
|
72 |
request.setPage("spdxDialog.html");
|
99 |
request.setPage("spdxDialog.html");
|
73 |
}
|
100 |
}
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
public void mainZip(WebRequest request){
|
|
|
104 |
//request.setPage("spdxDialog.html");
|
|
|
105 |
String result = "Hello there Zip!";
|
|
|
106 |
request.setAnswer(result);
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
/**
|
|
|
111 |
* Dialog for creating a new SPDX document from a folder on disk
|
|
|
112 |
* @param request
|
|
|
113 |
*/
|
|
|
114 |
public void mainFolder(WebRequest request){
|
|
|
115 |
// no support for requests from the browser
|
|
|
116 |
// if(request.requestOrigin == RequestOrigin.BROWSER){
|
|
|
117 |
// log.write(is.ERROR, "Support to SPDX creation from folder on disk "
|
|
|
118 |
// + "is not yet implemented");
|
|
|
119 |
// return;
|
|
|
120 |
// }
|
|
|
121 |
|
|
|
122 |
// get the value used before
|
|
|
123 |
String selectedFolder = settings.read(LastFolderNewSPDX, "");
|
|
|
124 |
|
|
|
125 |
// if nothign is chosen, just show it as "none"
|
|
|
126 |
if(selectedFolder.isEmpty()){
|
|
|
127 |
selectedFolder = "NONE";
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
String result =
|
|
|
131 |
html.div()
|
|
|
132 |
+ html.h2("Create a new SPDX from folder on disk")
|
|
|
133 |
+ "Use this page to create an SPDX document from a given "
|
|
|
134 |
+ "folder on your disk. "
|
|
|
135 |
+ html.br
|
|
|
136 |
+ html.br
|
|
|
137 |
+ html.h3("Selected Folder")
|
|
|
138 |
+ selectedFolder
|
|
|
139 |
+ html.br
|
|
|
140 |
|
|
|
141 |
+ html.br
|
|
|
142 |
+ html.link("Choose a folder", "create?x=folder")
|
|
|
143 |
|
|
|
144 |
+ html.br
|
|
|
145 |
+ html.br
|
|
|
146 |
+ html.link("Start", "create?x=foldercreate")
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
+ html._div
|
|
|
150 |
;
|
|
|
151 |
|
|
|
152 |
request.setAnswer(result);
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
|
|
|
156 |
|
|
|
157 |
/**
|
|
|
158 |
* Chooses a folder to be used as source for creating a new SPDX
|
|
|
159 |
* @param request
|
|
|
160 |
*/
|
|
|
161 |
public void foldercreate(WebRequest request){
|
|
|
162 |
// what should we use as source?
|
|
|
163 |
String selectedFolder = settings.read(LastFolderNewSPDX);
|
|
|
164 |
// start our action
|
|
|
165 |
log.write(is.INFO, "Creating an SPDX document using as source: %1",
|
|
|
166 |
selectedFolder );
|
|
|
167 |
|
|
|
168 |
// transform the thing into a file pointer
|
|
|
169 |
final File source = new File(selectedFolder);
|
|
|
170 |
|
|
|
171 |
if(source.exists() == false){
|
|
|
172 |
// we have a problem, exit here
|
|
|
173 |
log.write(is.ERROR, "SPDX create - Source folder doesn't exist: %1",
|
|
|
174 |
source.getAbsolutePath());
|
|
|
175 |
return;
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
final WebRequest what = request;
|
|
|
179 |
|
|
|
180 |
RunningTask task = new RunningTask(){
|
|
|
181 |
@Override
|
|
|
182 |
public void doTask(){
|
|
|
183 |
setTitle("Creating SPDX from source folder");
|
|
|
184 |
|
|
|
185 |
|
|
|
186 |
// third step, create the SPDX document from the extracted files
|
|
|
187 |
String result = createDocument(source, this);
|
|
|
188 |
|
|
|
189 |
// all done here, explain where the SPDX document can be found
|
|
|
190 |
nextStep =
|
|
|
191 |
html.link("SPDX summary",
|
|
|
192 |
"/spdx/show?x=summary&"
|
|
|
193 |
+ param.spdx + "=" + result)
|
|
|
194 |
+ " | " +
|
|
|
195 |
html.link("Show full text",
|
|
|
196 |
"/spdx/show?x=full&"
|
|
|
197 |
+ param.spdx + "=" + result)
|
|
|
198 |
;
|
|
|
199 |
|
|
|
200 |
}
|
|
|
201 |
};
|
|
|
202 |
task.launch();
|
|
|
203 |
|
|
|
204 |
|
|
|
205 |
//request.setAnswer("Process launched as " + task.getUID());
|
|
|
206 |
request.setAnswer(utils.html.redirect("/basic/status"
|
|
|
207 |
+ "?ID=" + task.getUID(), 0, ""));
|
|
|
208 |
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
|
|
|
212 |
|
|
|
213 |
/**
|
|
|
214 |
* Chooses a folder to be used as source for creating a new SPDX
|
|
|
215 |
* @param request
|
|
|
216 |
*/
|
|
|
217 |
public void folder(WebRequest request){
|
|
|
218 |
// no support for requests from the browser
|
|
|
219 |
if(request.requestOrigin == RequestOrigin.BROWSER){
|
|
|
220 |
log.write(is.ERROR, "Support to SPDX creation from folder on disk "
|
|
|
221 |
+ "is not yet implemented");
|
|
|
222 |
request.setAnswer("Not supported from browser");
|
|
|
223 |
return;
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
// do we want an older located defined?
|
|
|
227 |
String selectedFolder = settings.read(LastFolderNewSPDX);
|
|
|
228 |
|
|
|
229 |
|
|
|
230 |
// show the dialog
|
|
|
231 |
File result = swingUtils.chooseFolder(new File(selectedFolder));
|
|
|
232 |
|
|
|
233 |
// place the result in our settings
|
|
|
234 |
if(result != null){
|
|
|
235 |
settings.write(LastFolderNewSPDX, result.getAbsolutePath());
|
|
|
236 |
}
|
|
|
237 |
|
|
|
238 |
String output = html.redirect("/spdx/create?x=mainFolder", 2,
|
|
|
239 |
" Returning to previous page..");
|
|
|
240 |
|
|
|
241 |
request.setAnswer(output);
|
|
|
242 |
|
|
|
243 |
}
|
|
|
244 |
|
74 |
|
245 |
|
75 |
/**
|
246 |
/**
|
76 |
* The part where we create the SPDX document
|
247 |
* The part where we create the SPDX document
|
77 |
* @param request
|
248 |
* @param request
|
78 |
*/
|
249 |
*/
|