aboutsummaryrefslogtreecommitdiffstats
path: root/maven-meeper/src/bin/bundle-upload/deploy-bundle
blob: 59f3bbaccdfedfadf87cafcd7d8378b4e8fd37bf (plain)
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
207
208
#!/bin/sh

BUNDLEURL=$1
GROUPID=$2
VERSION=$3

[ "${BUNDLEURL}" = "" ] && echo && echo "You must specify a bundle URL!" && echo && exit

WORKDIR=bundle.tmp

SCRIPTDIR=`dirname ${0}`

[ -d $SCRIPTDIR ] || SCRIPTDIR=.

echo "Script directory is: ${SCRIPTDIR}"

# repo dir relative to WORKDIR
REPODIR=$HOME/repository-staging/to-ibiblio/maven
REPO2DIR=$HOME/repository-staging/to-ibiblio/maven2

rm -rf $WORKDIR > /dev/null 2>&1

mkdir $WORKDIR

cd $WORKDIR

echo "Retrieving URL: '${BUNDLEURL}'"
wget $BUNDLEURL
BUNDLE=`echo $BUNDLEURL | sed -e 's#^.*/##;'`

echo $BUNDLE
mv $BUNDLE tmp.jar
BUNDLE=tmp.jar

(

  echo "Unzipping original bundle."
  jar xf $BUNDLE || unzip $BUNDLE

  # copy files in subdirs to workdir
  echo "Copying files to working directory."
  for d in `find ./* -type d` ; do
    for f in `find $d -type f` ; do cp $f .; done;
  done

  echo "Searching for POM:"
  echo "...checking for 'project.xml'"
  POM=project.xml
  if [ ! -f ${POM} ]
  then
    echo "...checking for 'pom.xml'"
    POM=pom.xml
  fi

  if [ ! -f ${POM} ]
  then
    echo "...searching for **/*.pom"
    POM=`find . -iname *.pom`
  fi

  [ "" == "${POM}" ] && echo && echo "Cannot deploy without the pom.xml or project.xml file!" && echo && exit
  [ ! -f ${POM} ] && echo && echo "Cannot deploy without the pom.xml or project.xml file!" && echo && exit

  echo "POM is: '${POM}'"
  dos2unix ${POM}
  less $POM

  if [ ! -z $VERSION ]
  then
    version=$VERSION
  else
    version=`cat ${POM} | tr '\n' ' ' | sed 's#<build>.*</build>##' | sed 's#<versions>.*</versions>##' | sed 's#<dependencies>.*</dependencies>##' | sed 's#<reporting>.*</reporting>##' | sed 's#<parent>.*</parent>##' | grep '<version>' | sed -e 's#^.*<version>##;s#</version>.*$##'`

    if [ -z $version ]
    then
      version=`grep currentVersion ${POM} | sed -e 's#^.*<currentVersion>##;s#</currentVersion>.*$##'`
    fi
  fi

  artifactId=`cat ${POM} | tr '\n' ' ' | sed 's#<build>.*</build>##' | sed 's#<dependencies>.*</dependencies>##' | sed 's#<contributors>.*</contributors>##' | sed 's#<dependencies>.*</dependencies>##' | sed 's#<reporting>.*</reporting>##' | sed 's#<parent>.*</parent>##' | grep '<artifactId>' | sed -e 's#^.*<artifactId>##;s#</artifactId>.*$##'`

  if [ -z $artifactId ]
  then
    artifactId=`cat ${POM} | tr '\n' ' ' | sed 's#<build>.*</build>##' | sed 's#<versions>.*</versions>##' | sed 's#<developers>.*</developers>##' | sed 's#<dependencies>.*</dependencies>##' | sed 's#<reporting>.*</reporting>##' | sed 's#<contributors>.*</contributors>##' | sed 's#<parent>.*</parent>##' | grep '<id>' | sed -e 's#^.*<id>##;s#</id>.*$##'`
  fi
  
  if [ ! -z $GROUPID ]
  then
    groupId=${GROUPID}
  else
    groupId=`cat ${POM} | tr '\n' ' ' | sed 's#<build>.*</build>##' | sed 's#<dependencies>.*</dependencies>##' | sed 's#<reporting>.*</reporting>##' | sed 's#<parent>.*</parent>##' | grep '<groupId>' | sed -e 's#^.*<groupId>##;s#</groupId>.*$##'`  

    if [ -z $groupId ]
    then
      groupId=${artifactId}
    fi
  fi

  version=`echo ${version} | sed -e 's/ *$//'`
  artifactId=`echo ${artifactId} | sed -e 's/ *$//'`
  groupId=`echo ${groupId} | sed -e 's/ *$//'`  
  groupDir=`echo ${groupId} | sed -e 's/\./\//g'`  

  maven2=`cat ${POM} | grep '<modelVersion>'`

  echo
  if [ ! -z "${maven2}" ]
  then
    echo " ========= MAVEN 2 ========= "
  fi

  echo
  echo "   version: [${version}]"
  echo "   groupId: [${groupId}]"  
  echo "artifactId: [${artifactId}]"
  echo

  if [ -d $REPO2DIR/${groupDir} ]
  then
    echo "The group already exists"
  else
    echo "The group does NOT already exist"
  fi

  echo
  echo -n Hit Enter to continue or Ctrl-C to abort...
  read

  LIC=LICENSE.txt

  # A little help for manually created upload bundles
  [ -f license.txt ] && mv license.txt $LIC

  if [ -f $LIC ]
  then
    $SCRIPTDIR/d2u $LIC
    mkdir -p $REPODIR/${groupId}/licenses
    cp -i $LIC $REPODIR/${groupId}/licenses/${artifactId}-${version}.license  
  fi

  cp ${POM} ${artifactId}-${version}.pom

  m2dir=$REPO2DIR/${groupDir}/${artifactId}/${version}

  mkdir -p ${m2dir}

  if [ -z "${maven2}" ]
  then
    # Maven 1
    mkdir -p $REPODIR/${groupId}/poms
    cp -i ${artifactId}-${version}.pom $REPODIR/${groupId}/poms
  else
    # Maven 2
    cp -i ${artifactId}-${version}.pom ${m2dir}
    md5sum  ${m2dir}/${artifactId}-${version}.pom > ${m2dir}/${artifactId}-${version}.pom.md5
    sha1sum ${m2dir}/${artifactId}-${version}.pom > ${m2dir}/${artifactId}-${version}.pom.sha1
  fi

  artifactType=`echo ${artifactId} | sed -e 's/maven-.*-plugin//'`
  
  if [ -z ${artifactType} ]
  then
    echo "Deploying Plugin ..."
    mkdir -p $REPODIR/${groupId}/plugins
    cp -i ${artifactId}-${version}.jar $REPODIR/${groupId}/plugins
  else
    echo "Deploying JAR ..."

    if [ -z "${maven2}" ]
    then
      # Maven 1
      mkdir -p $REPODIR/${groupId}/jars
      cp -i ${artifactId}-${version}.jar $REPODIR/${groupId}/jars
    fi

    cp -i ${artifactId}-${version}.jar ${m2dir}
    if [ -f ${m2dir}/${artifactId}-${version}.jar ]
    then
      md5sum  ${m2dir}/${artifactId}-${version}.jar > ${m2dir}/${artifactId}-${version}.jar.md5
      sha1sum ${m2dir}/${artifactId}-${version}.jar > ${m2dir}/${artifactId}-${version}.jar.sha1
    fi
  fi
  
  if [ -f ${artifactId}-${version}-sources.jar ]
  then
    echo "Deploying Java sources ..."
    #mkdir -p $REPODIR/${groupId}/java-sources
    #cp -i ${artifactId}-${version}-sources.jar $REPODIR/${groupId}/java-sources
    cp -i ${artifactId}-${version}-sources.jar ${m2dir}
    md5sum  ${m2dir}/${artifactId}-${version}-sources.jar > ${m2dir}/${artifactId}-${version}-sources.jar.md5
    sha1sum ${m2dir}/${artifactId}-${version}-sources.jar > ${m2dir}/${artifactId}-${version}-sources.jar.sha1
  else
    echo "No Java sources available in upload bundle, skipping ..."
  fi

  if [ -f ${artifactId}-${version}-javadoc.jar ]
  then
    echo "Deploying Javadocs ..."
    #mkdir -p $REPODIR/${groupId}/javadoc
    #cp -i ${artifactId}-${version}-javadoc.jar $REPODIR/${groupId}/javadoc
    cp -i ${artifactId}-${version}-javadoc.jar ${m2dir}
    md5sum  ${m2dir}/${artifactId}-${version}-javadoc.jar > ${m2dir}/${artifactId}-${version}-javadoc.jar.md5
    sha1sum ${m2dir}/${artifactId}-${version}-javadoc.jar > ${m2dir}/${artifactId}-${version}-javadoc.jar.sha1
  else
    echo "No Javadocs available in upload bundle, skipping ..."
  fi

)