Skip to content

Commit

Permalink
Merge pull request #9 from castor-software/issue7_jar_deployment
Browse files Browse the repository at this point in the history
Deploy specialized jars to local Maven repo
  • Loading branch information
cesarsotovalero authored Oct 26, 2022
2 parents 64fd31a + 1d8aead commit 2376b17
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/main/java/se/kth/deptrim/DepTrimManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Set;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.apache.maven.execution.MavenSession;
import se.kth.depclean.core.analysis.AnalysisFailureException;
import se.kth.depclean.core.analysis.DefaultProjectDependencyAnalyzer;
import se.kth.depclean.core.analysis.model.ProjectDependencyAnalysis;
Expand All @@ -22,6 +23,7 @@ public class DepTrimManager {

private static final String SEPARATOR = "-------------------------------------------------------";
private final DependencyManagerWrapper dependencyManager;
private final MavenSession session;
private final boolean skipDepTrim;
private final boolean ignoreTests;
private final Set<String> ignoreScopes;
Expand Down Expand Up @@ -68,7 +70,7 @@ public ProjectDependencyAnalysis execute() throws AnalysisFailureException {
// Trimming dependencies.
getLog().info("STARTING TRIMMING DEPENDENCIES");
Trimmer trimmer = new Trimmer(dependencyManager, ignoreScopes);
trimmer.trimLibClasses(analysis, trimDependencies);
trimmer.trimLibClasses(analysis, trimDependencies, session);
consolePrinter.printDependencyUsageAnalysis(analysis);

// Print execution time.
Expand Down
1 change: 1 addition & 0 deletions src/main/java/se/kth/deptrim/DepTrimMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public final void execute() {
session,
dependencyGraphBuilder
),
session,
skipDepTrim,
ignoreTests,
ignoreScopes,
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/se/kth/deptrim/core/Trimmer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.maven.execution.MavenSession;
import se.kth.depclean.core.analysis.model.ProjectDependencyAnalysis;
import se.kth.depclean.core.model.ClassName;
import se.kth.depclean.core.wrapper.DependencyManagerWrapper;
Expand All @@ -23,6 +24,7 @@ public class Trimmer {

private static final String DIRECTORY_TO_EXTRACT_DEPENDENCIES = "dependency";
private static final String DIRECTORY_TO_LOCATE_THE_DEBLOATED_DEPENDENCIES = "dependency-debloated";
private static final String GROUP_ID_OF_SPECIALIZED_JAR = "se.kth.castor.deptrim.spl";
private DependencyManagerWrapper dependencyManager;
private Set<String> ignoreScopes;

Expand All @@ -35,10 +37,11 @@ public Trimmer(DependencyManagerWrapper dependencyManager, Set<String> ignoreSco
* Trim the unused classes from the dependencies specified by the user based on the usage analysis results.
*
* @param analysis The dependency usage analysis results
* @param session The MavenSession being analyzed, to get access to local Maven repository for deployment
* @param trimDependencies The dependencies to be trimmed, if empty then trims all the dependencies.
*/
@SneakyThrows
public void trimLibClasses(ProjectDependencyAnalysis analysis, Set<String> trimDependencies) {
public void trimLibClasses(ProjectDependencyAnalysis analysis, Set<String> trimDependencies, MavenSession session) {
analysis
.getDependencyClassesMap()
.forEach((key, value) -> {
Expand Down Expand Up @@ -84,14 +87,16 @@ public void trimLibClasses(ProjectDependencyAnalysis analysis, Set<String> trimD

// Install the dependency in the local repository.
try {
MavenInvoker.runCommand(
"mvn deploy:deploy-file -Durl=" + libDeptrimPath
String mvnLocalRepoUrl = session.getLocalRepository().getUrl();
log.info("Deploying specialized jar to local Maven repository " + mvnLocalRepoUrl);
String mavenDeployCommand = "mvn deploy:deploy-file -Durl=" + mvnLocalRepoUrl
+ " -Dpackaging=jar"
+ " -Dfile=" + jarFile.getAbsolutePath()
+ " -DgroupId=" + key.getGroupId()
+ " -DgroupId=" + GROUP_ID_OF_SPECIALIZED_JAR
+ " -DartifactId=" + key.getDependencyId()
+ " -Dversion=" + key.getVersion(),
null);
+ " -Dversion=" + key.getVersion();
log.info(mavenDeployCommand);
MavenInvoker.runCommand(mavenDeployCommand, null);
} catch (IOException | InterruptedException e) {
log.error("Error installing the trimmed dependency jar in local repo");
}
Expand Down

0 comments on commit 2376b17

Please sign in to comment.