This repository was archived by the owner on Sep 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented ChangeProcessor methods, so the files and the changes cou…
…ld be processed one-by-one.
- Loading branch information
Showing
8 changed files
with
180 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/main/java/hu/bme/mit/codemodel/jamoppdiscoverer/utils/ChangeProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package hu.bme.mit.codemodel.jamoppdiscoverer.utils; | ||
|
||
import hu.bme.mit.codemodel.jamoppdiscoverer.whitepages.pojo.Dependency; | ||
import hu.bme.mit.codemodel.jamoppdiscoverer.whitepages.utils.DependencyManager; | ||
|
||
import java.io.File; | ||
import java.net.UnknownHostException; | ||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class ChangeProcessor { | ||
|
||
/** | ||
* The set of files to be processed in the second iteration. Beside every modification, the relevant files also need | ||
* to be reprocessed. This includes every file, that depends on the modified ones and every one in the same package. | ||
*/ | ||
protected static Set<String> filesToProcess = new HashSet<>(); | ||
|
||
protected static DependencyCollector dependencyCollector = new DependencyCollector(); | ||
|
||
// ----------------------------------------------------------------------------------------------------------------- | ||
|
||
/** | ||
* Process a newly added file. | ||
* | ||
* When a new file is added, the dependency information should be saved in the database. The dependencies already in | ||
* the system had been processed processed, and the new ones will be processed in this iteration. | ||
* | ||
* The only file to be processed is the one added. | ||
* | ||
* @param filePath | ||
* The path of the newly added file. | ||
*/ | ||
public static void addedNewFile(String filePath) { | ||
dependencyCollector.execute(new File(filePath)); | ||
filesToProcess.add(filePath); | ||
|
||
System.out.println("Added a new file: " + RelativePath.of(filePath)); | ||
} | ||
|
||
/** | ||
* Process a deleted file. | ||
* | ||
* When a file is deleted, its dependency information should be deleted, and every file, that depends on it should | ||
* be reprocessed. | ||
* | ||
* @param filePath | ||
* The path of the deleted file. | ||
*/ | ||
public static void deletedFile(String filePath) { | ||
DependencyManager dm = null; | ||
try { | ||
dm = DependencyManager.getInstance(); | ||
Dependency dependency = dm.find(RelativePath.of(filePath)); | ||
|
||
if (dependency == null) { | ||
System.out.println("File is not in the database.\t" + RelativePath.of(filePath)); | ||
return; | ||
} | ||
|
||
Set<String> usedBy = dependency.getUsedBy(); | ||
filesToProcess.addAll(usedBy); | ||
dm.removeDescriptor(dependency); | ||
|
||
// process the files in the same package | ||
for (Dependency dInPackage : dm.findAll(PackageName.of(dependency.getFQN()))) { | ||
filesToProcess.add(dInPackage.getRelativeLocation()); | ||
} | ||
|
||
System.out.println("Deleted the file: " + RelativePath.of(filePath)); | ||
System.out.println("\tNeeds to be reprocessed:\t" + Arrays.toString(usedBy.toArray())); | ||
|
||
} catch (UnknownHostException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
/** | ||
* Process a modified file. | ||
* | ||
* When a file is modified, all of its dependencies should be deleted and reprocessed. Every file, that depends on | ||
* it should be also reprocessed. | ||
* | ||
* @param filePath | ||
* The path of the modified file. | ||
*/ | ||
public static void modifiedFile(String filePath) { | ||
deletedFile(filePath); // marks the files depending on the file to be reprocessed | ||
addedNewFile(filePath); // updates the dependencies of the file | ||
} | ||
|
||
// ----------------------------------------------------------------------------------------------------------------- | ||
|
||
public static Set<String> getFilesToProcess() { | ||
return filesToProcess; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/hu/bme/mit/codemodel/jamoppdiscoverer/utils/InitializationIterator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package hu.bme.mit.codemodel.jamoppdiscoverer.utils; | ||
|
||
import java.io.File; | ||
|
||
public class InitializationIterator implements FileIterator.Function { | ||
@Override | ||
public void execute(File file) { | ||
ChangeProcessor.addedNewFile(file.getAbsolutePath()); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/hu/bme/mit/codemodel/jamoppdiscoverer/utils/PackageName.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package hu.bme.mit.codemodel.jamoppdiscoverer.utils; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class PackageName { | ||
|
||
protected static final Pattern PACKAGENAME_PATTERN = Pattern.compile("^(.*)\\..*?$"); | ||
|
||
public static String of(String FQN) { | ||
Matcher matcher = PACKAGENAME_PATTERN.matcher(FQN); | ||
if (matcher.matches()) { | ||
return matcher.group(1); | ||
} | ||
|
||
return FQN; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/hu/bme/mit/codemodel/jamoppdiscoverer/utils/RelativePath.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package hu.bme.mit.codemodel.jamoppdiscoverer.utils; | ||
|
||
import java.io.File; | ||
|
||
public class RelativePath { | ||
|
||
protected static String root = new File("").getAbsolutePath() + "/"; | ||
|
||
public static String of(String absolutePath) { | ||
return absolutePath.replace(root, ""); | ||
} | ||
|
||
public static String rev(String relativePath) {return root + relativePath; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters