Parent: [r8] (diff)

Child: [r25] (diff)

Download this file

actions.java    314 lines (283 with data), 12.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/*
* SPDXVersion: SPDX-1.1
* Creator: Person: Nuno Brito (nuno.brito@triplecheck.de)
* Creator: Organization: TripleCheck (contact@triplecheck.de)
* Created: 2013-09-13T00:00:00Z
* LicenseName: NOASSERTION
* FileName: actions.java
* FileType: SOURCE
* FileCopyrightText: <text> Copyright 2013 Nuno Brito, TripleCheck </text>
* FileComment: <text> A simple static class to provide default actions
* related to SPDX handling </text>
*/
package main;
import GUI.NodeType;
import GUI.TreeNodeSPDX;
import GUI.swingUtils;
import static GUI.swingUtils.nodeCreate;
import definitions.definition;
import definitions.is;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTree;
import script.log;
import spdxlib.SPDXfile;
public class actions {
/**
* This method adds up all the licenses found on the licenses folder
*/
public static void addLicenses(){
File folder = new File(core.getWorkFolder(), "licenses");
ArrayList<File> files = utils.files.findFilesFiltered(folder, ".java", 2);
for(File file : files){
core.script.runJava(file, null, is.license);
}
}
/**
* Find all files within a given folder, return the respective
* details such as hashes and other details relevant for SPDX processing
* @param folder The folder location where we will look for SPDX files
* @return
*/
public static ArrayList<SPDXfile> findSPDX(File folder){
// only find the SPDX documents with .SPDX extension
ArrayList<File> files = utils.files.findFilesFiltered(folder, ".spdx", 25);
ArrayList<SPDXfile> list = new ArrayList();
try {
for(File file: files){
String filePath = file.getCanonicalPath();
// ignore SVN folders of any kind
if(filePath.contains(".svn")){
continue;
}
SPDXfile spdxFile;
spdxFile = new SPDXfile(file.getCanonicalFile());
list.add(spdxFile);
}
String pathName = folder.getCanonicalPath();
pathName = "."
+ pathName.replace(core.getWorkFolder().getCanonicalPath(), "");
// System.err.println(core.getWorkFolder().getCanonicalPath());
log.write(is.INFO, "Found %1 files in %2",
files.size()
+"", pathName);
} catch (IOException ex) {
Logger.getLogger(actions.class.getName()).log(Level.SEVERE, null, ex);
System.exit(-100);
}
return list;
}
/**
* This is a critical method. It will look for all SPDX files inside a given
* folder and them as tree nodes
* @param tree
*/
public static void addTreeSPDX(JTree tree) {
// only find the SPDX documents with .SPDX extension
ArrayList<File> fileList = utils.files
.findFilesFiltered(core.getProductsFolder(), ".spdx", 25);
if(fileList.isEmpty()){
// no need to continue, just leave here
return;
}
// get the root node where we have our treeview
TreeNodeSPDX rootNode = swingUtils.getRootNode(tree);
// create the node for hosting our list of SPDX documents
TreeNodeSPDX softwareNode = nodeCreate(
definition.nodeSoftware
//+ " (" + fileList.size() + ")"
, NodeType.other, rootNode);
// add the identification to this tag
softwareNode.id = definition.nodeSoftware;
softwareNode.setIcon("box-label.png");
// create a tree based on folder tree on disk
findFolders(core.getProductsFolder(), 25, softwareNode);
}
/**
* Find all subfolders in a given folder.
* @param where A file object of the start folder
* @param maxDeep How deep is the crawl allowed to proceed
* @param rootNode
// * @return An array containing all the found files, returns null if none is
// * found
* @return the number of relevant children that should be accounted
*/
public static int findFolders(File where, int maxDeep
, TreeNodeSPDX rootNode){
// get a list of the current files on this folder
File[] files = where.listFiles();
// we use this for counting files that were added
int count = 0;
// go through all the files/folders that were listed
if(files != null)
for (File file : files) {
// only accept folders, ignore files
if ( (file.isDirectory())
&&( maxDeep-1 > 0 ) ){
String folderName = file.getName();
// ignore SVN folders
if(folderName.equals(".svn")){
continue;
}
// create a new node for the current folder
TreeNodeSPDX node = new TreeNodeSPDX(folderName);
node.setIcon("folder-horizontal.png");
node.setIconWhenSelected("folder-horizontal-open.png");
node.nodeType = NodeType.folder;
node.id = folderName;
// we want to track if something new was added
int oldCount = count;
// do the recursive crawling
count += findFolders(file, maxDeep-1, node);
// only add this node if we found something interesting there
if(count > oldCount){
// add the node as a child of the root node
rootNode.add(node);
}
}
// perhaps we can add this file if it is an SPDX?
if(file.isFile()){
String fileName = file.getName();
// we only want files with an SPDX extension
if(file.getName().endsWith(".spdx")==false){
continue;
}
// we don't generic SPDX files here
if(file.getName().endsWith("-info.spdx")){
continue;
}
// create the new node
TreeNodeSPDX node = new TreeNodeSPDX(fileName);
node.setIcon("box.png");
node.nodeType = NodeType.SPDX;
node.id = fileName;
// set here what we want to happen when the user clicks on it
File scriptFile = new File(core.getPluginsFolder(), "/spdx/show.java");
node.scriptFile = scriptFile;
node.scriptFolder = scriptFile.getParentFile();
node.scriptMethod = "summary";
// create the correct parameters
String relativePath =
file.getAbsolutePath().replace(core.getProductsFolder().getAbsolutePath(), "");
node.scriptParameters.add(new String[]{param.spdx, relativePath});
// add it up
rootNode.add(node);
count++;
}
}
// how many files were found here?
rootNode.setCounter(count);
return count;
}
// /**
// * This is a critical method. It will look for all SPDX files inside a given
// * folder and them as tree nodes
// * @param tree
// */
// public static void addTreeSPDXOld(JTree tree) {
// // only find the SPDX documents with .SPDX extension
// ArrayList<File> initialFileList = utils.files
// .findFilesFiltered(core.getProductsFolder(), ".spdx", 25);
//
// if(initialFileList.isEmpty()){
// // no need to continue, just leave here
// return;
// }
//
// // this is used for filtering duplicate folders in the initial indexing
// ArrayList<File> tempFolderList = new ArrayList();
// // where are our spdx files stored?
// String baseFolder = core.getProductsFolder().getAbsolutePath();
// // get the root node where we have our treeview
// TreeNodeSPDX rootNode = swingUtils.getRootNode(tree);
//
// // where we place all results after being filtered
// ArrayList<File> fileList = new ArrayList();
// // iterate all files in our array that were found as products
// for(File file: initialFileList){
// // now we need to filter what we don't want to have in our array
// String filename = file.getName();
// // we don't need SVN files, ignore them completely
// if(filename.endsWith(".svn-base")){
// continue;
// }
// // add this file to our final list
// fileList.add(file);
// // now take care of the folder where this file was placed
// // get only the folder base, be careful with path separators here
// String folderName = file.getParent().replace(baseFolder, "");
// // no need to add in case the folder is the root
// if(folderName.isEmpty()){
// continue;
// }
// File folder = file.getParentFile();
// // no need to continue in case this folder was already added before
// if(tempFolderList.contains(folder)){
// continue;
// }
// // add it up
// tempFolderList.add(folder);
// }
//
// // create the node for hosting our list of SPDX documents
// TreeNodeSPDX softwareNode = nodeCreate(
// "Software (" + fileList.size() + ")"
// , NodeType.other, rootNode);
// // add the identification to this tag
// softwareNode.id = "Software";
// softwareNode.setIcon("box.png");
//
// // we need to map a list of spdx folders and files
// HashMap<File, TreeNodeSPDX> folderList = new HashMap();
// // first pass to add up all nodes and folders
// for(File folder : tempFolderList){
// TreeNodeSPDX node = new TreeNodeSPDX(folder.getName());
// node.setIcon("envelope.png");
// folderList.put(folder, node);
// }
//
//
//
// // second pass to add them all up on the tree view
// for(File folder : folderList.keySet()){
// TreeNodeSPDX node = folderList.get(folder);
// softwareNode.add(node);
// }
//
//
//
// //System.exit(-1981);
// }
//
//
// // iterate through the final list, build the folder list, add tree nodes
// for(File file: fileList){
// // get only the folder base, be careful with path separators here
// String folderName = file.getParent().replace(baseFolder, "");
// // no need to add in case the folder is the root
// if(folderName.isEmpty()){
// continue;
// }
// // no need to continue in case this folder was already added before
// if(folderList.containsKey(folderName)){
// continue;
// }
//
// String simpleFolderName = file.getParentFile().getName();
//
// // create the node for hosting our list of SPDX documents
// TreeNodeSPDX node = nodeCreate(
// simpleFolderName // get the normal name (no path components)
// , NodeType.folder // just a normal folder
// , rootNode); // add
// // add the identification to this tag
// softwareNode.id = "";
//
// // build up our list of folders
// System.err.println(folderName);
// folderList.put(folderName, rootNode);
// }
}