-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate Java call graphs from local JARs in OPALPlugin
#459
Open
mir-am
wants to merge
6
commits into
develop
Choose a base branch
from
opal-read-local-jars
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+282
−195
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
076ba74
Change the `DataWriter` interface to `DataRW` to read/write from/to t…
mir-am c2b6d0a
Add the `toPath` method to `MavenCoordinate`
mir-am 05016df
In `OPALPlugin`, generate a call graph from a local JAR file if avail…
mir-am 3b12da6
Make `toPath()` cross-platform and return `Path` in `MavenCoordinate`
mir-am b79f313
Extend `MavenArtifactDownloader` to download Maven artifacts into a g…
mir-am 2c4d825
Adapt `OPALPartialCallGraphConstructor`'s `createPartialJavaCG` to us…
mir-am File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -18,18 +18,16 @@ | |
|
||
package eu.fasten.analyzer.javacgopal.data; | ||
|
||
import com.google.common.collect.Lists; | ||
import eu.fasten.analyzer.javacgopal.data.analysis.OPALClassHierarchy; | ||
import eu.fasten.analyzer.javacgopal.data.analysis.OPALMethod; | ||
import eu.fasten.analyzer.javacgopal.data.analysis.OPALType; | ||
import eu.fasten.core.data.Constants; | ||
import eu.fasten.core.data.JavaGraph; | ||
import eu.fasten.core.data.PartialJavaCallGraph; | ||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.Comparator; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.NoSuchElementException; | ||
import java.util.Set; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import eu.fasten.core.data.opal.MavenArtifactDownloader; | ||
import eu.fasten.core.data.opal.MavenCoordinate; | ||
import eu.fasten.core.data.opal.exceptions.OPALException; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
import org.apache.commons.text.StringEscapeUtils; | ||
import org.opalj.br.Annotation; | ||
|
@@ -45,20 +43,21 @@ | |
import org.opalj.value.ValueInformation; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.google.common.collect.Lists; | ||
|
||
import eu.fasten.analyzer.javacgopal.data.analysis.OPALClassHierarchy; | ||
import eu.fasten.analyzer.javacgopal.data.analysis.OPALMethod; | ||
import eu.fasten.analyzer.javacgopal.data.analysis.OPALType; | ||
import eu.fasten.core.data.Constants; | ||
import eu.fasten.core.data.JavaGraph; | ||
import eu.fasten.core.data.opal.MavenArtifactDownloader; | ||
import eu.fasten.core.data.opal.MavenCoordinate; | ||
import eu.fasten.core.data.opal.exceptions.OPALException; | ||
import scala.Function1; | ||
import scala.collection.JavaConverters; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.util.ArrayList; | ||
import java.util.Comparator; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.NoSuchElementException; | ||
import java.util.Set; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
/** | ||
* Call graphs that are not still fully resolved. i.e. isolated call graphs which within-artifact | ||
* calls (edges) are known as internal calls and Cross-artifact calls are known as external calls. | ||
|
@@ -127,12 +126,39 @@ public static PartialJavaCallGraph createPartialJavaCG( | |
partialCallGraph.graph); | ||
} finally { | ||
if (file != null) { | ||
// TODO use apache commons FileUtils instead | ||
// TODO use apache commons FileUtils instead | ||
file.delete(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Creates RevisionCallGraph from a local JAR given a Maven coordinate. | ||
* | ||
* @param coordinate maven coordinate of the revision to be processed | ||
* @param timestamp timestamp of the revision release | ||
* @return RevisionCallGraph of the given coordinate. | ||
* @throws FileNotFoundException | ||
*/ | ||
public static PartialJavaCallGraph createPCGFromLocalJar(final MavenCoordinate coordinate, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please merge the two There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 2c4d825 |
||
final long timestamp, String jarFilePath, | ||
CGAlgorithm algorithm, CallPreservationStrategy callSiteOnly) throws FileNotFoundException { | ||
|
||
var file = new File(jarFilePath); | ||
if (!file.exists()) { | ||
throw new FileNotFoundException("Couldn't find the local JAR on filesystem for " + coordinate.toString()); | ||
} | ||
final var opalCG = new OPALCallGraphConstructor().construct(file, algorithm); | ||
|
||
final var partialCallGraph = new OPALPartialCallGraphConstructor().construct(opalCG, callSiteOnly); | ||
|
||
return new PartialJavaCallGraph(Constants.mvnForge, coordinate.getProduct(), | ||
coordinate.getVersionConstraint(), timestamp, | ||
Constants.opalGenerator, | ||
partialCallGraph.classHierarchy, | ||
partialCallGraph.graph); | ||
} | ||
|
||
/** | ||
* Creates a class hierarchy for the given call graph's artifact with entries | ||
* only in internalCHA. ExternalCHA to be added at a later stage. | ||
|
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use exception handling for programming logic! Concrete proposal: There is no need to have two separate methods, one
createPartialCG
method should be enough, which just takes a path to the jar to be analyzed. The only difference is where the path comes from: eithermavenCoord.getPath()
exists or the .jar is downloaded and a path to the downloaded file is provided. As the jar should always exist locally in our setup, I would be fine with just throwing an error when the file is missing.