This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
calculate-transitive-dependencies.sh
executable file
·206 lines (177 loc) · 7.79 KB
/
calculate-transitive-dependencies.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#! /usr/bin/env bash
#
# Copyright contributors to the Galasa project
#
# SPDX-License-Identifier: EPL-2.0
#
#-----------------------------------------------------------------------------------------
#
# Objectives: Calculate transient dependencies so we can include them in the bnd bundle
#
#-----------------------------------------------------------------------------------------
# Where is this script executing from ?
BASEDIR=$(dirname "$0");pushd $BASEDIR 2>&1 >> /dev/null ;BASEDIR=$(pwd);popd 2>&1 >> /dev/null
# echo "Running from directory ${BASEDIR}"
export ORIGINAL_DIR=$(pwd)
cd "${BASEDIR}"
cd "${BASEDIR}/.."
WORKSPACE_DIR=$(pwd)
cd "${BASEDIR}"
#-----------------------------------------------------------------------------------------
#
# Set Colors
#
#-----------------------------------------------------------------------------------------
bold=$(tput bold)
underline=$(tput sgr 0 1)
reset=$(tput sgr0)
red=$(tput setaf 1)
green=$(tput setaf 76)
white=$(tput setaf 7)
tan=$(tput setaf 202)
blue=$(tput setaf 25)
#-----------------------------------------------------------------------------------------
#
# Headers and Logging
#
#-----------------------------------------------------------------------------------------
underline() { printf "${underline}${bold}%s${reset}\n" "$@" ;}
h1() { printf "\n${underline}${bold}${blue}%s${reset}\n" "$@" ;}
h2() { printf "\n${underline}${bold}${white}%s${reset}\n" "$@" ;}
debug() { printf "${white}%s${reset}\n" "$@" ;}
info() { printf "${white}➜ %s${reset}\n" "$@" ;}
success() { printf "${green}✔ %s${reset}\n" "$@" ;}
error() { printf "${red}✖ %s${reset}\n" "$@" ;}
warn() { printf "${tan}➜ %s${reset}\n" "$@" ;}
bold() { printf "${bold}%s${reset}\n" "$@" ;}
note() { printf "\n${underline}${bold}${blue}Note:${reset} ${blue}%s${reset}\n" "$@" ;}
#-----------------------------------------------------------------------------------------
# Functions
#-----------------------------------------------------------------------------------------
function usage {
info "Syntax: calculate-dependencies.sh [OPTIONS]"
cat << EOF
Options are:
<none>
Environment variables used:
<none>
EOF
}
function create_temp_project {
h2 "Creating a temporary project so we can calculate the dependencies it has"
mkdir -p ${BASEDIR}/temp
cat << EOF > ${BASEDIR}/temp/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>dev.galasa</groupId>
<artifactId>dependency-finder</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>io.etcd</groupId>
<artifactId>jetcd-core</artifactId>
<version>0.5.9</version>
</dependency>
</dependencies>
</project>
EOF
success "OK"
}
function list_transient_dependencies_using_maven {
cd ${BASEDIR}/temp
h2 "This might be good in the bnd file of the cps extension:"
mvn dependency:tree | sed "s/\[INFO\]//g" | grep -v "BUILD SUCCESS" | grep -v "\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-" | grep -v "Total time" | grep -v "Finished at" \
| grep -v "Scanning for projects" | grep -v "Building dependency-finder" | grep -v "maven-dependency-plugin" | grep -v "dev.galasa:dependency-finder" \
| grep -v "^[ \t]*$" | sed "s/^[|+ \t\\\-]*//" | sed "s/:compile.*//g" | sed "s/:runtime.*//g" \
| cut -d ':' -f2,4 \
| sed "s/:/-/g" | sed "s/$/.jar; lib:=true,\\\/" | sed "s/^/ /" \
| sort | uniq \
> $BASEDIR/temp/dependencies_maven.txt
info "See $BASEDIR/temp/dependencies_maven.txt"
success "OK"
h2 "This might be good in the gradle file of the cps extension:"
mvn dependency:tree | sed "s/\[INFO\]//g" | grep -v "BUILD SUCCESS" | grep -v "\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-" | grep -v "Total time" | grep -v "Finished at" \
| grep -v "Scanning for projects" | grep -v "Building dependency-finder" | grep -v "maven-dependency-plugin" | grep -v "dev.galasa:dependency-finder" \
| grep -v "^[ \t]*$" | sed "s/^[|+ \t\\\-]*//" | sed "s/:compile.*//g" | sed "s/:runtime.*//g" \
| sed "s/^/ implementation ('/" \
| sed "s/$/')/" \
| sed "s/:jar:/:/" \
| sort | uniq \
> $BASEDIR/temp/dependencies_maven_imports.txt
info "See $BASEDIR/temp/dependencies_maven_imports.txt"
success "OK"
# mvn dependency:tree | sed "s/\[INFO\]//g" | grep -v "BUILD SUCCESS" | grep -v "\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-" | grep -v "Total time" | grep -v "Finished at" \
# | grep -v "Scanning for projects" | grep -v "Building dependency-finder" | grep -v "maven-dependency-plugin" | grep -v "dev.galasa:dependency-finder"
}
function list_transient_dependencies_using_gradle {
cd ${BASEDIR}/*parent
h2 "This might be good in the bnd file of the cps extension:"
gradle dev.galasa.cps.etcd:dependencies --configuration runtimeClasspath > $BASEDIR/temp/dependencies.txt
sed '/Indicates repeated occurrences/,$d' $BASEDIR/temp/dependencies.txt > $BASEDIR/temp/dependencies2.txt
cd ${BASEDIR}/temp
csplit $BASEDIR/temp/dependencies2.txt "/Runtime classpath of source set/" > /dev/null
mv $BASEDIR/temp/xx01 $BASEDIR/temp/dependencies3.txt
cat $BASEDIR/temp/dependencies3.txt | grep -v "runtimeClasspath - Runtime classpath of source set" \
| sed "s/^[+ \\|\-]*//" \
| cut -d ':' -f2,3 \
| sed "s/:[a-zA-Z0-9.\\-]* -> /:/" \
| sed "s/ [(][*][)]$//" \
| sed "s/:/-/" \
| grep -v "^[ \t]*$" \
| sed "s/$/.jar/" \
| sed "s/^/ /" \
| sed "s/$/; lib:=true,\\\/" \
| grep -v "dev.galasa" \
| grep -v "bcel" \
| grep -v "commons-io-.*.jar" \
| grep -v "commons-lang3-.*.jar" \
| grep -v "commons-logging-" \
| grep -v "easymock-.*.jar" \
| grep -v "log4j-api-.*.jar" \
| grep -v "log4j-core-.*.jar" \
| grep -v "log4j-slf4j-impl-.*.jar" \
| grep -v "org.apache.felix.bundlerepository-.*.jar" \
| grep -v "org.osgi" \
| sort | uniq \
> $BASEDIR/temp/dependencies_gradle.txt
# cat $BASEDIR/temp/dependencies_gradle.txt
#
rm $BASEDIR/temp/dependencies2.txt $BASEDIR/temp/dependencies3.txt
info "See $BASEDIR/temp/dependencies_gradle.txt"
success "OK"
cd ${BASEDIR}/*parent
h2 "This might be good in the gradle file of the cps extension:"
gradle dev.galasa.cps.etcd:dependencies --configuration runtimeClasspath > $BASEDIR/temp/dependencies.txt
sed '/Indicates repeated occurrences/,$d' $BASEDIR/temp/dependencies.txt > $BASEDIR/temp/dependencies2.txt
cd ${BASEDIR}/temp
csplit $BASEDIR/temp/dependencies2.txt "/Runtime classpath of source set/" > /dev/null
mv $BASEDIR/temp/xx01 $BASEDIR/temp/dependencies3.txt
cat $BASEDIR/temp/dependencies3.txt | grep -v "runtimeClasspath - Runtime classpath of source set" \
| sed "s/^[+ \\|\-]*//" \
| sed "s/:[a-zA-Z0-9.\\-]* -> /:/" \
| sed "s/ [(][*][)]$//" \
| grep -v "dev.galasa" \
| grep -v "bcel" \
| grep -v "commons-io" \
| grep -v "commons-lang3" \
| grep -v "commons-logging" \
| grep -v "easymock" \
| grep -v "org.apache.felix.bundlerepository" \
| grep -v "org.osgi" \
| sed "s/^/ implementation('/" \
| sed "s/$/')/" \
| grep -v " implementation('')" \
| sort | uniq \
> $BASEDIR/temp/dependencies_gradle_imports.txt
# | grep -v "log4j-api" \
# | grep -v "log4j-core" \
# | grep -v "log4j-slf4j-impl" \
info "See $BASEDIR/temp/dependencies_gradle_imports.txt"
success "OK"
}
create_temp_project
# list_transient_dependencies_using_maven
list_transient_dependencies_using_gradle