1 | // Copyright 2015 Georg-August-Universität Göttingen, Germany
|
---|
2 | //
|
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
4 | // you may not use this file except in compliance with the License.
|
---|
5 | // You may obtain a copy of the License at
|
---|
6 | //
|
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
8 | //
|
---|
9 | // Unless required by applicable law or agreed to in writing, software
|
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
12 | // See the License for the specific language governing permissions and
|
---|
13 | // limitations under the License.
|
---|
14 |
|
---|
15 | package de.ugoe.cs.cpdp.loader;
|
---|
16 |
|
---|
17 | import java.io.File;
|
---|
18 | import java.util.ArrayList;
|
---|
19 | import java.util.LinkedList;
|
---|
20 | import java.util.List;
|
---|
21 |
|
---|
22 | import weka.core.Attribute;
|
---|
23 | import weka.core.Instances;
|
---|
24 |
|
---|
25 | import de.ugoe.cs.cpdp.versions.SoftwareVersion;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Abstract class for loading data from a folder. The subfolders of a defined folder define the
|
---|
29 | * projects, the file contained in the subfolder are the versions of a project.
|
---|
30 | *
|
---|
31 | * @author Steffen Herbold
|
---|
32 | */
|
---|
33 | public abstract class AbstractFolderLoader implements IVersionLoader {
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Path of the data.
|
---|
37 | */
|
---|
38 | protected String path = "";
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * @see de.ugoe.cs.cpdp.loader.IVersionLoader#setLocation(java.lang.String)
|
---|
42 | */
|
---|
43 | @Override
|
---|
44 | public void setLocation(String location) {
|
---|
45 | path = location;
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * @see de.ugoe.cs.cpdp.loader.IVersionLoader#load()
|
---|
50 | */
|
---|
51 | @Override
|
---|
52 | public List<SoftwareVersion> load() {
|
---|
53 | final List<SoftwareVersion> versions = new LinkedList<SoftwareVersion>();
|
---|
54 |
|
---|
55 | final File dataDir = new File(path);
|
---|
56 | final SingleVersionLoader instancesLoader = getSingleLoader();
|
---|
57 | if (dataDir.listFiles() == null) {
|
---|
58 | return versions;
|
---|
59 | }
|
---|
60 | for (File projectDir : dataDir.listFiles()) {
|
---|
61 | if (projectDir.isDirectory()) {
|
---|
62 | String projectName = projectDir.getName();
|
---|
63 | if (projectDir.listFiles() != null) {
|
---|
64 | for (File versionFile : projectDir.listFiles()) {
|
---|
65 | if (versionFile.isFile() &&
|
---|
66 | instancesLoader.filenameFilter(versionFile.getName()))
|
---|
67 | {
|
---|
68 | Instances data = instancesLoader.load(versionFile);
|
---|
69 | String versionName = data.relationName();
|
---|
70 | List<Double> efforts = getEfforts(data);
|
---|
71 | versions.add(new SoftwareVersion(projectName, versionName, data, efforts));
|
---|
72 | }
|
---|
73 | }
|
---|
74 | }
|
---|
75 | }
|
---|
76 | }
|
---|
77 | return versions;
|
---|
78 | }
|
---|
79 |
|
---|
80 | private List<Double> getEfforts(Instances data) {
|
---|
81 | // attribute in the JURECZKO data and default
|
---|
82 | Attribute effortAtt = data.attribute("loc");
|
---|
83 | if (effortAtt == null) {
|
---|
84 | // attribute in the NASA/SOFTMINE/MDP data
|
---|
85 | effortAtt = data.attribute("LOC_EXECUTABLE");
|
---|
86 | }
|
---|
87 | if (effortAtt == null) {
|
---|
88 | // attribute in the AEEEM data
|
---|
89 | effortAtt = data.attribute("numberOfLinesOfCode");
|
---|
90 | }
|
---|
91 | if (effortAtt == null) {
|
---|
92 | // attribute in the RELINK data
|
---|
93 | effortAtt = data.attribute("CountLineCodeExe");
|
---|
94 | }
|
---|
95 | if( effortAtt == null ) {
|
---|
96 | return null;
|
---|
97 | }
|
---|
98 | List<Double> efforts = new ArrayList<>(data.size());
|
---|
99 | for( int i=0; i<data.size(); i++ ) {
|
---|
100 | efforts.add(data.get(i).value(effortAtt));
|
---|
101 | }
|
---|
102 | return efforts;
|
---|
103 | }
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * Returns the concrete {@link SingleVersionLoader} to be used with this folder loader.
|
---|
107 | *
|
---|
108 | * @return
|
---|
109 | */
|
---|
110 | abstract protected SingleVersionLoader getSingleLoader();
|
---|
111 | }
|
---|