Child: [r22] (diff)

Download this file

ExtensionControl.java    130 lines (107 with data), 3.6 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
/*
* SPDXVersion: SPDX-1.1
* Creator: Person: Nuno Brito (nuno.brito@triplecheck.de)
* Creator: Organization: TripleCheck (contact@triplecheck.de)
* Created: 2013-11-16T00:00:00Z
* LicenseName: NOASSERTION
* FileName: ExtensionControl.java
* FileType: SOURCE
* FileCopyrightText: <text> Copyright 2013 Nuno Brito, TripleCheck </text>
* FileComment: <text> Ensures that we can read all the available file
* extensions and generate optimized ways of processing their information.
* </text>
*/
package FileExtension;
import definitions.is;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import script.FileExtension;
import script.log;
import spdxlib.ContentType;
import main.core;
/**
*
* @author Nuno Brito, 16th of November 2013 in Darmstadt, Germany.
* nuno.brito@triplecheck.de | http://nunobrito.eu
*/
public final class ExtensionControl {
public static HashMap<String, FileExtension>
list = new HashMap();
// the public list of extensions that can be read as source code files
private String
textList = "",
ignoreList = "",
fullList = "";
;
/**
* Public constructor
*/
public ExtensionControl(){
//addExtensions();
}
/**
* Add a single extension to our list
*/
public void add(FileExtension extension){
list.put(extension.getIdentifierShort(), extension);
}
/**
* Add up all the extensions that we have available on disk
*/
public void addExtensions() {
// clear up the list to avoid duplicates
list.clear();
File folder = core.getExtensionsFolder();
ArrayList<File> files = utils.files.findFilesFiltered(folder, ".java", 2);
for(File file : files){
core.script.runJava(file, null, is.extension);
}
// output some statistics about the number of extensions registered
log.write(is.INFO, "Extensions recognized: %1", "" + list.size());
//TODO we are still listing the template class as a file type.
buildTextList();
}
/**
* Create a list of acceptable file extensions to be read as text files
*/
private void buildTextList() {
String
tempTextList = "",
tempIgnoreList = "",
tempFullList = "";
// iterate throught the list of extensions, get the text ones
for(FileExtension extension : list.values()){
if(extension.getContentType() == ContentType.TEXT){
tempTextList += ">"+extension.getIdentifierShort();
continue;
}else {
tempIgnoreList += ">"+extension.getIdentifierShort();
}
tempFullList += ">"+extension.getIdentifierShort();
}
// write back our changes
textList = tempTextList + ">";
ignoreList = tempIgnoreList + ">";
fullList = tempFullList + ">";
}
/**
* Verifies if we have a given extension in our list
* @param extension
* @return
*/
public Boolean has(String extension){
return list.containsKey(extension);
}
public FileExtension get(String extension){
return list.get(extension);
}
public Boolean isIgnored(String extension){
if(list.containsKey(extension)==false){
return true;
}
if(list.get(extension).getContentType() == ContentType.TEXT)
return false;
return true;
}
}