-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
164f30c
commit 4e6d6de
Showing
3 changed files
with
100 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,9 @@ | ||
package se.kth.transitive_changes; | ||
|
||
import se.kth.breaking_changes.ApiMetadata; | ||
import se.kth.data.JsonUtils; | ||
import se.kth.japianalysis.BreakingChange; | ||
|
||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import static se.kth.transitive_changes.Dependency.findUniqueDependencies; | ||
|
||
public class Main { | ||
|
||
|
||
public static void main(String[] args) { | ||
|
||
ApiMetadata apiMetadata = new ApiMetadata(Path.of("/Users/frank/Documents/Work/PHD/Explaining/breaking-good/projects/db02c6bcb989a5b0f08861c3344b532769530467/asto-core-v1.13.0.jar")); | ||
ApiMetadata apiMetadata2 = new ApiMetadata(Path.of("/Users/frank/Documents/Work/PHD/Explaining/breaking-good/projects/db02c6bcb989a5b0f08861c3344b532769530467/asto-core-v1.15.3.jar")); | ||
|
||
Dependency oldVersion = new Dependency("com.artipie", "asto-core", "v1.13.0", "jar", "compile"); | ||
Dependency newVersion = new Dependency("com.artipie", "asto-core", "v1.15.3", "jar", "compile"); | ||
|
||
|
||
Set<Dependency> v1 = MavenTree.read(apiMetadata, oldVersion); | ||
Set<Dependency> v2 = MavenTree.read(apiMetadata2, newVersion); | ||
|
||
Set<PairTransitiveDependency> transitiveDependencies = MavenTree.diff(v1, v2); | ||
|
||
|
||
Set<Dependency> newDependencies = findUniqueDependencies(v1, v2); | ||
|
||
|
||
|
||
Set<DependencyRecord> changedDependencies = Dependency.findChangedDependenciesBySemVer(v1, v2); | ||
System.out.println("Dependencias que han cambiado según SemVer:"); | ||
for (DependencyRecord record : changedDependencies) { | ||
System.out.println(record.oldDependency().getArtifactId() + " - " + record.changeType() + ": " + | ||
record.oldDependency().getVersion() + " -> " + record.newDependency().getVersion()); | ||
} | ||
|
||
System.out.println(); | ||
|
||
// Encontrar dependencias que han modificado solo versión y tipo | ||
Set<DependencyRecord> modifiedDependencies = Dependency.findModifiedDependenciesByVersionAndScope(v1, v2); | ||
System.out.println("Dependencias que han modificado solo versión y tipo:"); | ||
for (DependencyRecord record : modifiedDependencies) { | ||
System.out.println(record.oldDependency().getArtifactId() + ": " + | ||
record.oldDependency().getVersion() + " -> " + record.newDependency().getVersion()); | ||
} | ||
|
||
|
||
Set<Dependency> removedDependencies = findUniqueDependencies(v2, v1); | ||
|
||
for (PairTransitiveDependency pair : transitiveDependencies) { | ||
try { | ||
System.out.println("Comparing " + pair.newVersion() + " and " + pair.oldVersion()); | ||
CompareTransitiveDependency compareTransitiveDependency = new CompareTransitiveDependency(pair.newVersion(), pair.oldVersion()); | ||
List<BreakingChange> changes = compareTransitiveDependency.getChangesBetweenDependencies(); | ||
System.out.println("Breaking changes for " + pair.newVersion() + " and " + pair.oldVersion()); | ||
System.out.println("Breaking Changes amount: " + changes.size()); | ||
|
||
JsonUtils.writeToFile(Path.of("breaking-changes-%s.json".formatted(pair.oldVersion().getArtifactId())), compareTransitiveDependency); | ||
|
||
|
||
|
||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package util; | ||
|
||
import com.fasterxml.jackson.databind.JavaType; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.type.TypeFactory; | ||
import com.fasterxml.jackson.databind.util.StdDateFormat; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.StandardOpenOption; | ||
|
||
/** | ||
* The JsonUtils class provides a simple interface for writing and reading JSON files | ||
* | ||
* @author <a href="mailto:[email protected]">Gabriel Skoglund</a> | ||
*/ | ||
public class JsonUtils { | ||
|
||
/** The default JSON file ending ".json" */ | ||
public static final String JSON_FILE_ENDING = ".json"; | ||
|
||
/** The string representing an empty JSON object */ | ||
public static final String EMPTY_JSON_OBJECT = "{}"; | ||
|
||
private static final ObjectMapper mapper = | ||
new ObjectMapper().setDateFormat(new StdDateFormat()); | ||
|
||
private JsonUtils() { /* Nothing to see here... */ } | ||
|
||
/** | ||
* Read a JSON object from file | ||
* @param file the path to the JSON file to read. | ||
* @param jsonType the type that the data should be considered as. | ||
* @return an object of the specified type as read from the given file. | ||
*/ | ||
public static <T> T readFromFile(Path file, Class<T> jsonType) { | ||
try { | ||
return mapper.readValue(Files.readString(file), jsonType); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
/** | ||
* Read a JSON object from file | ||
* @param file the path to the JSON file to read. | ||
* @param jsonType the type that the data should be considered as. | ||
* @return an object of the specified type as read from the given file. | ||
*/ | ||
public static <T> T readFromFile(Path file, JavaType jsonType) { | ||
try { | ||
return mapper.readValue(Files.readString(file), jsonType); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
/** | ||
* Read a JSON object from file which can be empty | ||
* @param file the path to the JSON file to read which can be empty. | ||
* @param jsonType the type that the data should be considered as. | ||
* @return an object of the specified type as read from the given file. | ||
*/ | ||
public static <T> T readFromNullableFile(Path file, JavaType jsonType) { | ||
try { | ||
if (Files.readString(file).isEmpty()) { | ||
// Handle empty JSON file. | ||
return null; | ||
} else { | ||
return mapper.readValue(Files.readString(file), jsonType); | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
/** | ||
* Write an object to a JSON file. | ||
* @param outputFilePath the file path where the data should be written. | ||
* @param data the object to be stored as JSON. | ||
*/ | ||
public static void writeToFile(Path outputFilePath, Object data) { | ||
try { | ||
String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(data); | ||
Files.writeString(outputFilePath, json, StandardOpenOption.WRITE, StandardOpenOption.CREATE, | ||
StandardOpenOption.TRUNCATE_EXISTING); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
/** | ||
* @return a {@link TypeFactory} from the underlying {@link ObjectMapper}. | ||
*/ | ||
public static TypeFactory getTypeFactory() { | ||
return mapper.getTypeFactory(); | ||
} | ||
} |