Initial commit of Sigil contribution. (FELIX-1142)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@793581 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/sigil/bld-ivy/test/multi-project/common/build.properties b/sigil/bld-ivy/test/multi-project/common/build.properties
new file mode 100644
index 0000000..9552b4a
--- /dev/null
+++ b/sigil/bld-ivy/test/multi-project/common/build.properties
@@ -0,0 +1,30 @@
+# ***************************************************************
+# * Licensed to the Apache Software Foundation (ASF) under one
+# * or more contributor license agreements. See the NOTICE file
+# * distributed with this work for additional information
+# * regarding copyright ownership. The ASF licenses this file
+# * to you under the Apache License, Version 2.0 (the
+# * "License"); you may not use this file except in compliance
+# * with the License. You may obtain a copy of the License at
+# *
+# * http://www.apache.org/licenses/LICENSE-2.0
+# *
+# * Unless required by applicable law or agreed to in writing,
+# * software distributed under the License is distributed on an
+# * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# * KIND, either express or implied. See the License for the
+# * specific language governing permissions and limitations
+# * under the License.
+# ***************************************************************
+lib.dir = ${basedir}/lib
+build.dir = ${basedir}/build
+classes.dir = ${build.dir}/classes
+src.dir = ${basedir}/src
+repository.dir=${common.dir}/../repository
+
+ivy.file = ${basedir}/ivy.xml
+
+jar.file = ${build.dir}/${ant.project.name}.jar
+main.class.name = ${ant.project.name}.Main
+
+module.version.target = 1.0
diff --git a/sigil/bld-ivy/test/multi-project/common/common.xml b/sigil/bld-ivy/test/multi-project/common/common.xml
new file mode 100644
index 0000000..4e54d1d
--- /dev/null
+++ b/sigil/bld-ivy/test/multi-project/common/common.xml
@@ -0,0 +1,232 @@
+<?xml version="1.0">
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project name="common"
+ xmlns:ivy="antlib:org.apache.ivy.ant">
+ <!-- a sample common ant build file, used for ivy multi-project tutorial
+ feel free to copy and adapt it to your own needs
+ Note that the only targets specific to ivy are:
+ load-ivy
+ resolve
+ report
+ ivy-new-version
+ publish
+ publish-local
+
+ All other targets are usual ant based targets, which could have been written
+ in a build not depending at all on ivy:
+ resolve constructs a lib directory based upon ivy dependencies, and then the lib dir
+ is used as in any classical ant build
+ -->
+
+ <property file="${common.dir}/build.properties"/>
+
+ <property name="ivy.jar.dir" value="/opt/apache-ivy-2.0.0-rc2" />
+ <property name="ivy.jar.file" value="${ivy.jar.dir}/ivy-2.0.0-rc2.jar" />
+ <property name="sigil-ivy-plugin.jar" value="${common.dir}/../../../target/sigil-ivy-plugin.jar"/>
+
+ <target name="hello">
+ <echo message="${ant.project.name}"/>
+ </target>
+
+ <!-- =================================
+ target: load-ivy
+ this target is not necessary if you put ivy.jar in your ant lib directory
+ if you already have ivy 2.0 in your ant lib, you can simply remove this
+ target
+ ================================= -->
+ <path id="ivy.lib.path">
+ <path location="${ivy.jar.file}"/>
+ <path location="${sigil-ivy-plugin.jar}"/>
+ <!--
+ <path location="${user.home}/src/tmp/ivy/build/ivy.jar"/>
+ -->
+ </path>
+
+ <target name="load-ivy" depends="ivy-taskdefs">
+ <ivy:settings file="${common.dir}/ivysettings.xml" />
+ </target>
+
+ <target name="ivy-taskdefs" unless="ivy.loaded">
+ <property name="ivy.loaded" value="true"/>
+ <echo message="Loading Ivy ..."/>
+ <!--
+ <taskdef resource="org/apache/ivy/ant/antlib.xml"
+ uri="antlib:org.apache.ivy.ant" classpath="${ivy.jar.file}"/>
+ -->
+ <taskdef resource="org/apache/ivy/ant/antlib.xml"
+ uri="antlib:org.apache.ivy.ant"
+ loaderRef="ivyLoader"
+ classpath="${ivy.jar.file}"/>
+
+ <taskdef name="sigil.bundle"
+ classname="org.cauldron.bld.ant.BundleTask"
+ classpath="${sigil-ivy-plugin.jar}:${bndlib.jar}"/>
+ </target>
+
+ <path id="lib.path.id">
+ <fileset dir="${lib.dir}" />
+ </path>
+
+ <path id="run.path.id">
+ <path refid="lib.path.id" />
+ <path location="${classes.dir}" />
+ </path>
+
+
+ <!-- setup ivy default configuration with some custom info -->
+ <property name="ivy.local.default.root" value="${repository.dir}/local"/>
+ <property name="ivy.shared.default.root" value="${repository.dir}/shared"/>
+
+ <!-- here is how we would have configured ivy if we had our own ivysettings file
+ <ivy:settings file="${common.dir}/ivysettings.xml" />
+ -->
+
+
+ <!-- =================================
+ target: resolve
+ ================================= -->
+ <target name="resolve" depends="clean-lib, load-ivy" description="--> resolve and retrieve dependencies with ivy">
+ <mkdir dir="${lib.dir}"/> <!-- not usually necessary, ivy creates the directory IF there are dependencies -->
+
+ <!-- the call to resolve is not mandatory, retrieve makes an implicit call if we don't -->
+ <ivy:resolve file="${ivy.file}"/>
+ <ivy:retrieve pattern="${lib.dir}/[artifact].[ext]" />
+ </target>
+
+ <!-- =================================
+ target: report
+ ================================= -->
+ <target name="report" depends="resolve" description="--> generates a report of dependencies">
+ <ivy:report todir="${build.dir}"/>
+ </target>
+
+ <!-- =================================
+ target: compile
+ ================================= -->
+ <target name="compile" depends="resolve" description="--> compile the project">
+ <mkdir dir="${classes.dir}" />
+ <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="lib.path.id" debug="true" />
+ </target>
+
+ <!-- =================================
+ target: run
+ ================================= -->
+ <target name="run" depends="version, compile" description="--> compile and run the project">
+ <java classpathref="run.path.id" classname="${main.class.name}"/>
+ </target>
+
+ <target name="ivy-new-version" depends="load-ivy" unless="ivy.new.revision">
+ <!-- default module version prefix value -->
+ <property name="module.version.prefix" value="${module.version.target}-dev-b" />
+
+ <!-- asks to ivy an available version number -->
+ <ivy:info file="${ivy.file}" />
+ <ivy:buildnumber
+ organisation="${ivy.organisation}" module="${ivy.module}"
+ revision="${module.version.prefix}" defaultBuildNumber="1" revSep=""/>
+ </target>
+
+ <target name="local-version">
+ <tstamp>
+ <format property="now" pattern="yyyyMMddHHmmss"/>
+ </tstamp>
+ <property name="ivy.new.revision" value="${module.version.target}-local-${now}"/>
+ </target>
+
+ <target name="version" depends="ivy-new-version">
+ <!-- create version file in classpath for later inclusion in jar -->
+ <mkdir dir="${classes.dir}"/>
+ <echo message="version=${ivy.new.revision}" file="${classes.dir}/${ant.project.name}.properties" append="false" />
+
+ <!-- load generated version properties file -->
+ <property file="${classes.dir}/${ant.project.name}.properties" />
+ </target>
+
+ <!-- =================================
+ target: jar
+ ================================= -->
+ <target name="jar" depends="version, compile" description="--> make a jar file for this project">
+
+ <!--
+ <jar destfile="${jar.file}">
+ <fileset dir="${classes.dir}" />
+ <manifest>
+ <attribute name="Built-By" value="${user.name}"/>
+ <attribute name="Build-Version" value="${version}" />
+ </manifest>
+ </jar>
+ -->
+
+ <sigil.bundle destpattern="${build.dir}/[id].[ext]"
+ classpathref="run.path.id"/>
+ </target>
+
+ <!-- =================================
+ target: publish
+ ================================= -->
+ <target name="publish" depends="clean-build, jar" description="--> publish this project in the ivy repository">
+ <ivy:publish artifactspattern="${build.dir}/[artifact].[ext]"
+ resolver="shared"
+ pubrevision="${version}"
+ status="release"
+ />
+ <echo message="project ${ant.project.name} released with version ${version}" />
+ </target>
+
+ <!-- =================================
+ target: publish-local
+ ================================= -->
+ <target name="publish-local" depends="local-version, jar" description="--> publish this project in the local ivy repository">
+ <ivy:publish artifactspattern="${build.dir}/[artifact].[ext]"
+ resolver="local"
+ pubrevision="${version}"
+ pubdate="${now}"
+ status="integration"
+ forcedeliver="true"
+ />
+ <echo message="project ${ant.project.name} published locally with version ${version}" />
+ </target>
+
+ <!-- =================================
+ target: clean-local
+ ================================= -->
+ <target name="clean-local" description="--> cleans the local repository for the current module">
+ <delete dir="${ivy.local.default.root}/${ant.project.name}"/>
+ </target>
+
+ <!-- =================================
+ target: clean-lib
+ ================================= -->
+ <target name="clean-lib" description="--> clean the project libraries directory (dependencies)">
+ <delete includeemptydirs="true" dir="${lib.dir}"/>
+ </target>
+
+ <!-- =================================
+ target: clean-build
+ ================================= -->
+ <target name="clean-build" description="--> clean the project built files">
+ <delete includeemptydirs="true" dir="${build.dir}"/>
+ </target>
+
+ <!-- =================================
+ target: clean
+ ================================= -->
+ <target name="clean" depends="clean-build, clean-lib" description="--> clean the project" />
+</project>
diff --git a/sigil/bld-ivy/test/multi-project/common/ivysettings.xml b/sigil/bld-ivy/test/multi-project/common/ivysettings.xml
new file mode 100644
index 0000000..03440c4
--- /dev/null
+++ b/sigil/bld-ivy/test/multi-project/common/ivysettings.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0">
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<ivysettings>
+ <properties file="${ivy.settings.dir}/build.properties"/>
+ <caches defaultCacheDir="${ivy.settings.dir}/../ivy-cache" />
+
+ <settings defaultResolver="shared"
+ circularDependencyStrategy="error" />
+
+ <classpath file="${ivy.settings.dir}/../../../target/sigil-ivy-plugin.jar" />
+ <!--
+ Ant tasks "subant" and "ant" cause IvySettings to be re-loaded,
+ which then re-loads SigilParser in a new URLClassLoader,
+ which causes ProjectRepository to be re-initialised. Outch!
+
+ Better if Ivy classpath cached its classloader, or provided a
+ loaderRef attribute, like ant does.
+
+ Loading sigil-ivy-plugin.jar in ivy-taskdefs, uses the same ClassLoader
+ to load sigil-ivy-plugin, and thus avoids re-initialising ProjectRepositiory.
+ -->
+ <typedef name="sigil-parser" classname="org.cauldron.bld.ivy.SigilParser" />
+ <typedef name="sigil" classname="org.cauldron.bld.ivy.SigilResolver" />
+
+ <parsers>
+ <sigil-parser quiet="true"/>
+ </parsers>
+
+ <resolvers>
+ <sigil name="sigil" config="${ivy.settings.dir}/sigil-repos.properties" />
+ <filesystem name="local">
+ <ivy pattern="${repository.dir}/local/[module]-[revision].xml" />
+ <artifact pattern="${repository.dir}/local/[artifact]-[revision].[ext]" />
+ </filesystem>
+ <filesystem name="shared">
+ <ivy pattern="${repository.dir}/shared/[module]-[revision].xml" />
+ <artifact pattern="${repository.dir}/shared/[module]/[artifact]-[revision].[ext]" />
+ </filesystem>
+ </resolvers>
+ <modules>
+ <!--<module organisation="org.apache.ivy.example" name=".*" resolver="shared"/>
+ -->
+ <module organisation="sigil" resolver="sigil"/>
+ </modules>
+</ivysettings>
diff --git a/sigil/bld-ivy/test/multi-project/common/sigil-gen.sh b/sigil/bld-ivy/test/multi-project/common/sigil-gen.sh
new file mode 100755
index 0000000..2f7e184
--- /dev/null
+++ b/sigil/bld-ivy/test/multi-project/common/sigil-gen.sh
@@ -0,0 +1,107 @@
+#!/bin/sh
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# sigilgen build.xml ..
+
+function a2s() {
+ find ${1:?} -name '*.java' -o -name '*.spring' -o -name '*.sca' |
+ perl -e '
+ use strict;
+ use FileHandle;
+
+ my %imports;
+ my %exports;
+
+ while (<>) {
+ chomp($_);
+ my $path = $_;
+ my $fh = new FileHandle($path);
+
+ my $testFile = ($path =~ m!Test[^/]+$!);
+
+ while (my $line = <$fh>) {
+ chomp($line);
+
+ if ($line =~ /^\s*package\s+([\w.]+)\s*;\s*$/) {
+ my $exp = $1;
+ if (!($testFile && ($exp !~ /^test[.]/))) {
+ $exports{$exp} = 1;
+ }
+ }
+ elsif ($line =~ /^\s*import\s+([a-z_0-9.]+)([.][A-Z][^.]+)+;\s*$/) {
+ my $imp = $1;
+ $imports{$imp} = 1 unless ($imp =~ /^java[.]/);
+ }
+ elsif (($line !~ m!^\s*(//|\*|\@)!) &&
+ ($line =~ /(\W)((([a-z0-9]{2,})[.]){3,})[A-Z]/)) {
+ my $quot = $1;
+ my $imp = $2;
+ $imp =~ s/.$//;
+
+ if (($imp !~ /^java[.]/) &&
+ ($quot ne "\"" || ($path !~ /[.]java$/))) {
+ $imports{$imp} = 1;
+ }
+ }
+ }
+ $fh->close();
+ }
+
+ if (keys(%exports) == () && keys(%imports) == ()) {
+ exit(1);
+ }
+
+ print "-exports: \\\n";
+ foreach my $key (sort keys(%exports)) {
+ print "\t$key, \\\n";
+ }
+ print "\n";
+
+ print "-imports: \\\n";
+ foreach my $key (sort keys(%imports)) {
+ print "\t$key, \\\n";
+ }
+ print "\n";
+
+ exit(0);
+ '
+ return $?
+}
+
+for file in $*; do
+ echo "converting $file"
+ name=$(perl -ne 'print $1 if (/project name="([^"]*)"/);' $file)
+ dir=$(dirname $file)
+
+ if [ -f $dir/sigil.properties ]; then
+ rm -f $dir/sigil.properties.old
+ mv $dir/sigil.properties $dir/sigil.properties.old
+ fi
+
+ (
+ echo "# generated by sigilgen on $(date)"
+ echo
+ echo "-bundles: $name"
+ echo
+ a2s $dir && mv $dir/sigil.properties-part $dir/sigil.properties
+ ) > $dir/sigil.properties-part
+
+ rm -f $dir/sigil.properties-part
+
+done
diff --git a/sigil/bld-ivy/test/multi-project/common/sigil-repos.properties b/sigil/bld-ivy/test/multi-project/common/sigil-repos.properties
new file mode 100644
index 0000000..d98b618
--- /dev/null
+++ b/sigil/bld-ivy/test/multi-project/common/sigil-repos.properties
@@ -0,0 +1,26 @@
+
+# repository config
+
+-repositories: system, project, newton, spring
+
+system;provider: system
+system;level: -1
+#system;framework: osgi.core.jar
+#system;profile: J2SE-1.5
+
+project;provider: project
+project;level: 0
+project;pattern: ../projects/**/[sigilproject]
+
+newton;provider: filesystem
+newton;level: 1
+newton;recurse: true
+#newton;dir: /opt/newton-1.2.5/lib
+newton;dir: /Users/derek/devl/Newton/src/target/newton-dist.dir/lib
+
+spring;provider: obr
+spring;level: 2
+spring;url: http://sigil.codecauldron.org/spring-external.obr
+spring;index: ../settings/spring-external.obr
+
+# end