Skip to content

Commit 67fa22b

Browse files
committed
Update pmd/pmd-eclipse-plugin-p2-site for snapshot and release builds
1 parent 13d12f6 commit 67fa22b

File tree

1 file changed

+122
-2
lines changed

1 file changed

+122
-2
lines changed

.ci/build.sh

Lines changed: 122 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,25 @@ function snapshot_build() {
6262
cd net.sourceforge.pmd.eclipse.p2updatesite
6363
./cleanup-bintray-snapshots.sh
6464
)
65+
66+
# Add snapshot to update site
67+
pmd_ci_log_info "Updating pmd-eclipse-plugin-p2-site..."
68+
prepare_local_p2_site
69+
(
70+
cd current-p2-site
71+
72+
rm -rf snapshot
73+
unzip -q -d snapshot "../net.sourceforge.pmd.eclipse.p2updatesite/target/net.sourceforge.pmd.eclipse.p2updatesite-*.zip"
74+
echo -e "This is a Eclipse Update Site for the PMD Eclipse Plugin for version ${PMD_CI_MAVEN_PROJECT_VERSION} ($(date -Iminutes)).\n\n<https://github.com/pmd/pmd-eclipse-plugin/>" > snapshot/index.md
75+
git add snapshot
76+
77+
# create a new single commit
78+
git checkout --orphan=gh-pages-2
79+
git commit -a -m "Update pmd/pmd-eclipse-plugin-p2-site"
80+
git push --force origin gh-pages-2:gh-pages
81+
pmd_ci_log_success "Successfully updated https://pmd.github.io/pmd-eclipse-plugin-p2-site/"
82+
)
83+
6584
pmd_ci_log_group_end
6685
}
6786

@@ -73,7 +92,7 @@ function release_build() {
7392
pmd_ci_gh_releases_createDraftRelease "${PMD_CI_TAG}" "$(git rev-list -n 1 "${PMD_CI_TAG}")"
7493
GH_RELEASE="$RESULT"
7594

76-
# Deploy the update site to bintray
95+
# Build and deploy the update site to bintray
7796
xvfb-run --auto-servernum ./mvnw clean verify --show-version --errors --batch-mode \
7897
--no-transfer-progress \
7998
--activate-profiles release-composite
@@ -98,10 +117,111 @@ $(head -$END_LINE ReleaseNotes.md | tail -$((END_LINE - BEGIN_LINE)))
98117
# Upload it to sourceforge
99118
pmd_ci_sourceforge_uploadFile "pmd-eclipse/zipped" "net.sourceforge.pmd.eclipse.p2updatesite/target/net.sourceforge.pmd.eclipse.p2updatesite-${PMD_CI_MAVEN_PROJECT_VERSION}.zip"
100119

101-
# Publish release
120+
# Add new release to update site
121+
pmd_ci_log_info "Updating pmd-eclipse-plugin-p2-site..."
122+
prepare_local_p2_site
123+
(
124+
cd current-p2-site
125+
126+
unzip -q -d "${PMD_CI_MAVEN_PROJECT_VERSION}" "net.sourceforge.pmd.eclipse.p2updatesite/target/net.sourceforge.pmd.eclipse.p2updatesite-${PMD_CI_MAVEN_PROJECT_VERSION}.zip"
127+
git add "${PMD_CI_MAVEN_PROJECT_VERSION}"
128+
regenerate_metadata
129+
130+
# create a new single commit
131+
git checkout --orphan=gh-pages-2
132+
git commit -a -m "Update pmd/pmd-eclipse-plugin-p2-site"
133+
git push --force origin gh-pages-2:gh-pages
134+
pmd_ci_log_success "Successfully updated https://pmd.github.io/pmd-eclipse-plugin-p2-site/"
135+
)
136+
137+
# Publish release - this sends out notifications on github
102138
pmd_ci_gh_releases_publishRelease "$GH_RELEASE"
103139

104140
pmd_ci_log_group_end
105141
}
106142

143+
144+
function prepare_local_p2_site() {
145+
pmd_ci_log_info "Preparing local copy of p2-site..."
146+
rm -rf current-p2-site
147+
mkdir current-p2-site
148+
(
149+
cd current-p2-site
150+
git init -q
151+
git config user.name "PMD CI (pmd-bot)"
152+
git config user.email "[email protected]"
153+
git remote add origin [email protected]:pmd/pmd-eclipse-plugin-p2-site.git
154+
git pull origin gh-pages
155+
)
156+
}
157+
158+
function regenerate_metadata() {
159+
pmd_ci_log_info "Regenerating metadata for p2-site..."
160+
local releases=($(find . -maxdepth 1 -type d -regex "\./[0-9]+\.[0-9]+\.[0-9]+\..*" -printf '%TY-%Tm-%Td\0%f\n' | sort -t '\0' -r|awk -F '\0' '{print $2}'))
161+
# remove old releases
162+
for i in "${releases[@]:5}"; do
163+
pmd_ci_log_info "Removing old release $i..."
164+
rm -rf "$i"
165+
done
166+
releases=("${releases[@]:0:5}")
167+
168+
# regenerate metadata
169+
local now
170+
now=$(date +%s000)
171+
local children=""
172+
local children_index=""
173+
for i in "${releases[@]}"; do
174+
children="${children} <child location=\"$i\"/>\n"
175+
children_index="${children_index} * [$i]($i/)\n"
176+
echo -e "This is a Eclipse Update Site for the PMD Eclipse Plugin for version $i.\n\n<https://github.com/pmd/pmd-eclipse-plugin/>" > "$i"/index.md
177+
git add "$i"/index.md
178+
done
179+
180+
local site_name="PMD for Eclipse - Update Site"
181+
local artifactsTemplate="<?xml version=\"1.0\" encoding=\"UTF-8\"?>
182+
<?compositeArtifactRepository version=\"1.0.0\"?>
183+
<repository name=\"${site_name}\" type=\"org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository\" version=\"1.0.0\">
184+
<properties size=\"2\">
185+
<property name=\"p2.timestamp\" value=\"${now}\"/>
186+
<property name=\"p2.atomic.composite.loading\" value=\"true\"/>
187+
</properties>
188+
<children size=\"${#releases[@]}\">
189+
${children} </children>
190+
</repository>"
191+
echo -e "${artifactsTemplate}" > compositeArtifacts.xml
192+
193+
local contentTemplate="<?xml version=\"1.0\" encoding=\"UTF-8\"?>
194+
<?compositeMetadataRepository version=\"1.0.0\"?>
195+
<repository name=\"${site_name}\" type=\"org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository\" version=\"1.0.0\">
196+
<properties size=\"2\">
197+
<property name=\"p2.timestamp\" value=\"${now}\"/>
198+
<property name=\"p2.atomic.composite.loading\" value=\"true\"/>
199+
</properties>
200+
<children size=\"${#releases[@]}\">
201+
${children} </children>
202+
</repository>"
203+
echo -e "${contentTemplate}" > compositeContent.xml
204+
205+
# p2.index
206+
local p2_index="version = 1
207+
metadata.repository.factory.order = compositeContent.xml,\!
208+
artifact.repository.factory.order = compositeArtifacts.xml,\!"
209+
echo -e "${p2_index}" > p2.index
210+
211+
# regenerate index.md
212+
local index_md="This URL is a composite Eclipse Update Site for the PMD Eclipse Plugin.
213+
214+
Github: <https://github.com/pmd/pmd-eclipse-plugin/>
215+
216+
----
217+
218+
Versions available at <https://pmd.github.io/pmd-eclipse-plugin-p2-site/>:
219+
220+
${children_index}
221+
222+
For older versions, see <https://sourceforge.net/projects/pmd/files/pmd-eclipse/zipped/>
223+
"
224+
echo -e "${index_md}" > index.md
225+
}
226+
107227
build

0 commit comments

Comments
 (0)