Author: hibou
Date: Sun Sep 1 18:08:36 2013
New Revision: 1519300
URL: http://svn.apache.org/r1519300
Log:
- make the buildobr task a post resolve task, so that it can work with set of
resolved artifacts
- document how to manage an OSGi target platform, with samples
Added:
ant/ivy/core/trunk/doc/samples/target-platform/ (with props)
ant/ivy/core/trunk/doc/samples/target-platform/build.xml (with props)
ant/ivy/core/trunk/doc/samples/target-platform/ivy.xml (with props)
ant/ivy/core/trunk/doc/samples/target-platform/ivysettings.xml (with
props)
ant/ivy/core/trunk/src/java/org/apache/ivy/ant/BuildOBRTask.java
- copied, changed from r1518386,
ant/ivy/core/trunk/src/java/org/apache/ivy/ant/BuildBundleRepoDescriptorTask.java
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/ArtifactReportManifestIterable.java
(with props)
ant/ivy/core/trunk/test/java/org/apache/ivy/ant/BuildOBRTaskTest.java
(with props)
ant/ivy/core/trunk/test/test-repo/bundlerepo/ivysettings.xml (with props)
ant/ivy/core/trunk/test/test-repo/ivy-test-buildobr.xml (with props)
Removed:
ant/ivy/core/trunk/src/java/org/apache/ivy/ant/BuildBundleRepoDescriptorTask.java
Modified:
ant/ivy/core/trunk/CHANGES.txt
ant/ivy/core/trunk/doc/osgi/target-platform.html
ant/ivy/core/trunk/doc/use/buildobr.html
ant/ivy/core/trunk/src/java/org/apache/ivy/ant/antlib.xml
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/AbstractFSManifestIterable.java
Modified: ant/ivy/core/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=1519300&r1=1519299&r2=1519300&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Sun Sep 1 18:08:36 2013
@@ -139,6 +139,7 @@ for detailed view of each issue, please
=====================================
- DOCUMENTATION: Broken link in <dependency> documentation (IVY-1405)
+- NEW: the buildobr task can now work a set of resolved artifacts: useful for
managing an OSGi target platform
- NEW: fixdeps task: serializes transitively resolved dependencies into an
ivy.xml file
- NEW: IvyDependencyTree task : display a dependency tree on the console
- NEW: Support Conditional Setting of a Property (IVY-1367)
Modified: ant/ivy/core/trunk/doc/osgi/target-platform.html
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/doc/osgi/target-platform.html?rev=1519300&r1=1519299&r2=1519300&view=diff
==============================================================================
--- ant/ivy/core/trunk/doc/osgi/target-platform.html (original)
+++ ant/ivy/core/trunk/doc/osgi/target-platform.html Sun Sep 1 18:08:36 2013
@@ -35,18 +35,33 @@
</tr>
</table>
-<hr />
-<center><b>TODO - WORK IN PROGRESS</b></center>
-<hr />
-
-Building an OSGi™ bundle with standard tools like <tt>javac</tt> and a
classpath computed by Apache Ivy™ can be erroneous as these tools doesn't
take into account the package visibility enforced by the OSGi metadata. Then
switching to OSGi dedicated tools like the Eclipse™ JDT can be prefered.
This kind of tools still need a "target platform", a set of jars against to
compile and then later run. A target platform can be easily managed with Ivy
and its OSGi capabilities.
-
-<ul>Some links of interest:
- <li><a href="../resolver/obr.html">OSGi Bundle Repository Resolver</a></li>
- <li><a href="../resolver/updatesite.html">Eclipse updatesite
Resolver</a></li>
- <li><a href="../use/retrieve.html">Ant ivy:retrieve task</a></li>
+The concept of "target platform" is a concept introduced by Eclipse™ to
describe the set of bundle which will run together in an OSGi™
environement. Then when developping an OSGi bundle, we expect it to run in a
such "target platform".
+
+When developping a single OSGi bundle, a single ivy.xml (together with the use
of the <a href="../use/fixdeps.html">fixdeps</a> task) is sufficent to describe
precisely how the bundle requirements.
+
+But when developping several bundles, it will be error prone to declare for
each bundle its dependencies. Because once deployed in an OSGi environement,
the bindings are sensitive to the available bundles. So when developping, we
must ensure that the set of bundles will be the same set as the one at deploy
time.
+
+The concept of "target platform" is a perfect fit to describe the set of
bundles to resolve against. Here is a recipe to handle it with just Ant+Ivy.
+
+<h1>A Target Platform Project</h1>
+
+First you need a project (basically a folder) in which you will manage your
target platform. In this project you'll need 3 files:
+<ul>
+<li>an <a href="../samples/target-platform/ivy.xml">ivy.xml</a> in which you
will describe the bundles you need,</li>
+<li>an <a
href="../samples/target-platform/ivysettings.xml">ivysettings.xml</a> which
will describe where to download bundles from,</li>
+<li>and a <a href="../samples/target-platform/build.xml">build.xml</a> with
which you'll manage your target platform.</li>
</ul>
+In the build there is a first important target:
<tt>'update-dependencies'</tt>. Since the OSGi dependencies are very sensible
to the available resources to resolve against, it is important to make the
resolve as tight and reproductible as possible. First this target will do a
resolve with the <tt>ivy.xml</tt>: a resolve which is very sensible to the
content of the remote repo, thus not much reproductible. And it is will
generate an <tt>ivy-fixed.xml</tt> from the resolved depedencies: this Ivy file
contains only fixed non transitive dependencies (see the <a
href="../use/fixdeps.html">fixdeps</a> task for further info). With that
<tt>ivy-fixed.xml</tt> file, resolves are then reproductible and will always
generate the same set of artifacts.
+
+Once generated, it is recommended to share that <tt>ivy-fixed.xml</tt> file
into you version control system (subversion, git, etc...). The target
<tt>'update-dependencies'</tt> is then to be launched each time you edit the
<tt>ivy.xml</tt>, when you want to change the content of your target platform.
+
+The second target <tt>'generate-target-platform'</tt> will generate an
<tt>obr.xml</tt>, a OSGi Bundle repository descriptor. This file will list
every artifact wich has been resolved by the <tt>ivy-fixed.xml</tt>. Then each
of your bundles you develop will do its resolve against that <tt>obr.xml</tt>
(see the <a href="../resolver/obr.html">obr resolver</a>).
+
+The generated <tt>obr.xml</tt> contains paths to the local filesystem, so it
is recommended to not share it between developpers.
+
+If it is required to develop your plugin with the Eclipse PDE plugin, you can
then use the alternative target <tt>generate-retrieved-target-platform</tt>. It
has the same principle than the <tt>'generate-target-platform'</tt> but the
artifacts are also retrieved in a single folder, just like are plugins in an
Eclipse install. That way you can define your target platform within Eclipse
quite easily.
+
</textarea>
<script type="text/javascript">xooki.postProcess();</script>
</body>
Propchange: ant/ivy/core/trunk/doc/samples/target-platform/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Sep 1 18:08:36 2013
@@ -0,0 +1,4 @@
+bundles
+cache
+ivy-fixed.xml
+obr.xml
Added: ant/ivy/core/trunk/doc/samples/target-platform/build.xml
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/doc/samples/target-platform/build.xml?rev=1519300&view=auto
==============================================================================
--- ant/ivy/core/trunk/doc/samples/target-platform/build.xml (added)
+++ ant/ivy/core/trunk/doc/samples/target-platform/build.xml Sun Sep 1
18:08:36 2013
@@ -0,0 +1,56 @@
+<!--
+ 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="target-platform" xmlns:ivy="ivy">
+
+ <!-- Load Ivy ant tasks -->
+ <taskdef uri="ivy" resource="org/apache/ivy/ant/antlib.xml" />
+ <!-- If Ivy is not in Ant's classpath, get the jar of Ivy and use the
folowing -->
+ <!-- taskdef rather than the above one -->
+ <!--path id="ivy.classpath">
+ <fileset dir="${basedir}">
+ <include name="ivy.jar" />
+ </fileset>
+ </path>
+ <taskdef uri="ivy" resource="org/apache/ivy/ant/antlib.xml"
classpathref="ivy.classpath" /-->
+
+ <target name="update-dependencies" description="Update the dependencies">
+ <ivy:configure file="${basedir}/ivysettings.xml" />
+ <ivy:resolve file="ivy.xml" conf="*" />
+ <ivy:fixdeps tofile="ivy-fixed.xml" />
+ </target>
+
+ <!--
+ Two choices: either the jars stas in the cache, or they are retrive in
a dedicated folder
+ Having the bundle retrieved in a folder is helpfull to manage target
platforms with the PDE of Eclipse
+ -->
+
+ <target name="generate-target-platform" description="Generate the obr.xml
of the target platform">
+ <ivy:configure file="${basedir}/ivysettings.xml" />
+ <ivy:resolve file="ivy-fixed.xml" conf="*" />
+ <ivy:buildobr out="obr.xml" />
+ </target>
+
+ <target name="generate-retrieved-target-platform" description="Generate
the obr.xml of the retrieved target platform">
+ <ivy:configure file="${basedir}/ivysettings.xml" />
+ <ivy:resolve file="ivy-fixed.xml" conf="*" />
+ <ivy:retrieve
pattern="${basedir}/bundles/[type]s/[artifact]_[revision].[ext]" />
+ <ivy:buildobr basedir="${basedir}/bundles" out="obr.xml" />
+ </target>
+
+</project>
Propchange: ant/ivy/core/trunk/doc/samples/target-platform/build.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ant/ivy/core/trunk/doc/samples/target-platform/build.xml
------------------------------------------------------------------------------
svn:keywords = Date Revision Author HeadURL Id
Propchange: ant/ivy/core/trunk/doc/samples/target-platform/build.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: ant/ivy/core/trunk/doc/samples/target-platform/ivy.xml
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/doc/samples/target-platform/ivy.xml?rev=1519300&view=auto
==============================================================================
--- ant/ivy/core/trunk/doc/samples/target-platform/ivy.xml (added)
+++ ant/ivy/core/trunk/doc/samples/target-platform/ivy.xml Sun Sep 1 18:08:36
2013
@@ -0,0 +1,24 @@
+<!--
+ 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.
+-->
+<ivy-module version="2.0">
+ <info organisation="com.acme" module="target-platform" />
+ <dependencies>
+ <dependency org="bundle" name="org.eclipse.jdt.core"
rev="3.8.3.v20130121-145325" />
+ </dependencies>
+</ivy-module>
\ No newline at end of file
Propchange: ant/ivy/core/trunk/doc/samples/target-platform/ivy.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ant/ivy/core/trunk/doc/samples/target-platform/ivy.xml
------------------------------------------------------------------------------
svn:keywords = Date Revision Author HeadURL Id
Propchange: ant/ivy/core/trunk/doc/samples/target-platform/ivy.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: ant/ivy/core/trunk/doc/samples/target-platform/ivysettings.xml
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/doc/samples/target-platform/ivysettings.xml?rev=1519300&view=auto
==============================================================================
--- ant/ivy/core/trunk/doc/samples/target-platform/ivysettings.xml (added)
+++ ant/ivy/core/trunk/doc/samples/target-platform/ivysettings.xml Sun Sep 1
18:08:36 2013
@@ -0,0 +1,33 @@
+<!--
+ 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>
+
+ <settings defaultResolver="eclipse-juno"
defaultLatestStrategy="latest-osgi" />
+
+ <!-- These are usual cache setup -->
+ <caches resolutionCacheDir="${ivy.settings.dir}/cache/resolution"
useOrigin="true">
+ <cache name="eclipse-juno"
basedir="${ivy.settings.dir}/cache/eclipse-juno" />
+ </caches>
+
+ <!-- The resolvers from which we will find our bundles -->
+ <resolvers>
+ <updatesite name="eclipse-juno"
url="http://download.eclipse.org/releases/juno" cache="eclipse-juno"
requirementStrategy="first" />
+ </resolvers>
+
+</ivysettings>
Propchange: ant/ivy/core/trunk/doc/samples/target-platform/ivysettings.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ant/ivy/core/trunk/doc/samples/target-platform/ivysettings.xml
------------------------------------------------------------------------------
svn:keywords = Date Revision Author HeadURL Id
Propchange: ant/ivy/core/trunk/doc/samples/target-platform/ivysettings.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified: ant/ivy/core/trunk/doc/use/buildobr.html
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/doc/use/buildobr.html?rev=1519300&r1=1519299&r2=1519300&view=diff
==============================================================================
--- ant/ivy/core/trunk/doc/use/buildobr.html (original)
+++ ant/ivy/core/trunk/doc/use/buildobr.html Sun Sep 1 18:08:36 2013
@@ -25,7 +25,21 @@
</head>
<body>
<textarea id="xooki-source">
-<span class="since">since 2.3</span> From a bunch of jar artifacts, generate
an OBR (OSGi Bundle Repository) descriptor. It could be then used by the <a
href="../resolver/obr.html">obr resolver</a>.
+<span class="since">since 2.3</span> From a set of jar artifacts, this task
generates an OBR (OSGi Bundle Repository) descriptor. It could be then used by
the <a href="../resolver/obr.html">obr resolver</a>.
+
+The set of jars which will be described by the OBR can be defined in 4
exclusive ways:
+<ul>
+<li>via an Ivy resolver: every jar listed by the resolver will be taken into
account</li>
+<li>by defining a root directory: every jar found recursively in that folder
will be taken into account</li>
+<li>via the name of an Ivy cache: every artifact contained in the cache will
be taken into account</li>
+<li><span class="since">since 2.4</span> via a resolve: this task is a
[[ant:postresolvetask post resolve task]] (with all the behaviour and
attributes common to all post resolve tasks), thus ever artifact which has been
resolved will be taken into account; it is especially useful for building a <a
href="../osgi/target-platform.html">target platform</a></li>
+</ul>
+
+NB: among every listed files or artifacts, only the actually OSGi bundles will
be described by the OBR descriptor; the other files are ignored.
+
+<h1>Attributes</h1>
+
+<span class="since">since 2.4</span> This is a [[ant:postresolvetask post
resolve task]], with all the behaviour and attributes common to all post
resolve tasks.
<table class="ant">
<thead>
@@ -35,7 +49,7 @@
<tr><td>out</td><td>the location of the descriptor file to
generate</td><td>Yes</td></tr>
<tr><td>resolverName</td><td>the name of the resolver from which the jars
should be to gathered</td><td>No</td></tr>
<tr><td>cacheName</td><td>the name of the cache from which the jars should
be to gathered</td><td>No</td></tr>
- <tr><td>baseDir</td><td>the folder into whicch the jars should be gather
recursively</td><td>No</td></tr>
+ <tr><td>baseDir</td><td>the folder into which the jars should be gather
recursively</td><td>No</td></tr>
<tr><td>encoding</td><td>The encoding of the resulting xml
file</td><td>No. Defaults to <tt>UTF-8</tt></td></tr>
<tr><td>indent</td><td>Specify if the xml result file should be
indented</td><td>No. Defaults to <tt>true</tt></td></tr>
<tr><td>quiet</td><td>Log as debug rather than warning the rejected jars
as they are illformed</td><td>No. Defaults to <tt>false</tt></td></tr>
@@ -62,6 +76,14 @@ Configure an Ivy settings and builds an
</code>
Configure an Ivy settings and builds an OBR descriptor from jars contained in
the defined cache.
+<hr/>
+<code type="xml">
+ <ivy:configure file="ivysettings.xml" />
+ <ivy:resolve file="ivy.xml" />
+ <ivy:buildobr out="${basedir}/target-platform-obr.xml" />
+</code>
+Launch a resolve and then build an obr.xml describing the resolved artifacts.
+
</textarea>
<script type="text/javascript">xooki.postProcess();</script>
</body>
Copied: ant/ivy/core/trunk/src/java/org/apache/ivy/ant/BuildOBRTask.java (from
r1518386,
ant/ivy/core/trunk/src/java/org/apache/ivy/ant/BuildBundleRepoDescriptorTask.java)
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/BuildOBRTask.java?p2=ant/ivy/core/trunk/src/java/org/apache/ivy/ant/BuildOBRTask.java&p1=ant/ivy/core/trunk/src/java/org/apache/ivy/ant/BuildBundleRepoDescriptorTask.java&r1=1518386&r2=1519300&rev=1519300&view=diff
==============================================================================
---
ant/ivy/core/trunk/src/java/org/apache/ivy/ant/BuildBundleRepoDescriptorTask.java
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/ant/BuildOBRTask.java Sun Sep 1
18:08:36 2013
@@ -22,6 +22,7 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.text.ParseException;
import java.util.Iterator;
import javax.xml.transform.TransformerConfigurationException;
@@ -32,6 +33,7 @@ import org.apache.ivy.core.cache.Default
import org.apache.ivy.core.cache.RepositoryCacheManager;
import org.apache.ivy.core.settings.IvySettings;
import org.apache.ivy.osgi.obr.xml.OBRXMLWriter;
+import org.apache.ivy.osgi.repo.ArtifactReportManifestIterable;
import org.apache.ivy.osgi.repo.FSManifestIterable;
import org.apache.ivy.osgi.repo.ResolverManifestIterable;
import org.apache.ivy.plugins.resolver.BasicResolver;
@@ -41,7 +43,7 @@ import org.apache.tools.ant.BuildExcepti
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
-public class BuildBundleRepoDescriptorTask extends IvyTask {
+public class BuildOBRTask extends IvyCacheTask {
private String resolverName = null;
@@ -134,9 +136,16 @@ public class BuildBundleRepoDescriptorTa
File basedir = ((DefaultRepositoryCacheManager)
cacheManager).getBasedir();
it = new FSManifestIterable(basedir).iterator();
} else {
- throw new BuildException(
- "No resolver, cache or basedir specified: "
- + "please provide one of them through the
attribute 'resolver', 'cache' or 'dir'");
+ prepareAndCheck();
+ try {
+ it = new
ArtifactReportManifestIterable(getArtifactReports()).iterator();
+ } catch (ParseException e) {
+ throw new BuildException("Impossible to parse the artifact
reports: "
+ + e.getMessage(), e);
+ } catch (IOException e) {
+ throw new BuildException("Impossible to read the artifact
reports: "
+ + e.getMessage(), e);
+ }
}
OutputStream out;
@@ -155,7 +164,7 @@ public class BuildBundleRepoDescriptorTa
class AntMessageLogger2 extends AntMessageLogger {
AntMessageLogger2() {
- super(BuildBundleRepoDescriptorTask.this);
+ super(BuildOBRTask.this);
}
}
IvyContext.getContext().getMessageLogger();
Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/ant/antlib.xml
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/antlib.xml?rev=1519300&r1=1519299&r2=1519300&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/ant/antlib.xml (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/ant/antlib.xml Sun Sep 1
18:08:36 2013
@@ -44,7 +44,7 @@
<taskdef name="findrevision"
classname="org.apache.ivy.ant.IvyFindRevision"/>
<taskdef name="buildnumber"
classname="org.apache.ivy.ant.IvyBuildNumber"/>
<taskdef name="cleancache"
classname="org.apache.ivy.ant.IvyCleanCache"/>
- <taskdef name="buildobr"
classname="org.apache.ivy.ant.BuildBundleRepoDescriptorTask" />
+ <taskdef name="buildobr" classname="org.apache.ivy.ant.BuildOBRTask" />
<taskdef name="convertmanifest"
classname="org.apache.ivy.ant.ConvertManifestTask" />
<taskdef name="fixdeps" classname="org.apache.ivy.ant.FixDepsTask" />
<taskdef name="dependencytree"
classname="org.apache.ivy.ant.IvyDependencyTree"/>
Modified:
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/AbstractFSManifestIterable.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/AbstractFSManifestIterable.java?rev=1519300&r1=1519299&r2=1519300&view=diff
==============================================================================
---
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/AbstractFSManifestIterable.java
(original)
+++
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/AbstractFSManifestIterable.java
Sun Sep 1 18:08:36 2013
@@ -41,7 +41,7 @@ public abstract class AbstractFSManifest
}
public Iterator/* <ManifestAndLocation> */iterator() {
- return new FSManifestIterator(root);
+ return new FSManifestIterator();
}
abstract protected List/* <T> */listBundleFiles(Object/* T */dir) throws
IOException;
@@ -71,7 +71,7 @@ public abstract class AbstractFSManifest
private Object/* T */currentDir = null;
- FSManifestIterator(Object /* T */root) {
+ FSManifestIterator() {
dirs.add(Collections.singleton(root).iterator());
}
Added:
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/ArtifactReportManifestIterable.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/ArtifactReportManifestIterable.java?rev=1519300&view=auto
==============================================================================
---
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/ArtifactReportManifestIterable.java
(added)
+++
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/ArtifactReportManifestIterable.java
Sun Sep 1 18:08:36 2013
@@ -0,0 +1,103 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.ivy.osgi.repo;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.jar.JarInputStream;
+import java.util.jar.Manifest;
+
+import org.apache.ivy.core.report.ArtifactDownloadReport;
+import org.apache.ivy.util.Message;
+
+public class ArtifactReportManifestIterable /* implements
Iterable<ManifestAndLocation> */{
+
+ private final List/* <ArtifactDownloadReport> */artifactReports;
+
+ public ArtifactReportManifestIterable(List/* <ArtifactDownloadReport>
*/artifactReports) {
+ this.artifactReports = artifactReports;
+ }
+
+ public Iterator/* <ManifestAndLocation> */iterator() {
+ return new ArtifactReportManifestIterator();
+ }
+
+ class ArtifactReportManifestIterator implements Iterator/*
<ManifestAndLocation> */{
+
+ private ManifestAndLocation next = null;
+
+ private Iterator it;
+
+ public ArtifactReportManifestIterator() {
+ it = artifactReports.iterator();
+ }
+
+ public boolean hasNext() {
+ while (next == null && it.hasNext()) {
+ ArtifactDownloadReport report = (ArtifactDownloadReport)
it.next();
+ File artifact = report.getLocalFile();
+ JarInputStream in = null;
+ try {
+ in = new JarInputStream(new FileInputStream(artifact));
+ Manifest manifest = in.getManifest();
+ if (manifest != null) {
+ next = new ManifestAndLocation(manifest,
artifact.toURI());
+ return true;
+ }
+ Message.debug("No manifest in jar: " + artifact);
+ } catch (FileNotFoundException e) {
+ Message.debug("Jar file just removed: " + artifact, e);
+ } catch (IOException e) {
+ Message.warn("Unreadable jar: " + artifact, e);
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ // Don't care
+ }
+ }
+ }
+ }
+ if (next == null) {
+ return false;
+ }
+ return true;
+ }
+
+ public Object next() {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
+ ManifestAndLocation manifest = next;
+ next = null;
+ return manifest;
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+}
\ No newline at end of file
Propchange:
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/ArtifactReportManifestIterable.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/ArtifactReportManifestIterable.java
------------------------------------------------------------------------------
svn:keywords = Date Revision Author HeadURL Id
Propchange:
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/ArtifactReportManifestIterable.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: ant/ivy/core/trunk/test/java/org/apache/ivy/ant/BuildOBRTaskTest.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/ant/BuildOBRTaskTest.java?rev=1519300&view=auto
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/ant/BuildOBRTaskTest.java
(added)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/ant/BuildOBRTaskTest.java Sun
Sep 1 18:08:36 2013
@@ -0,0 +1,136 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.ivy.ant;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.text.ParseException;
+
+import junit.framework.TestCase;
+
+import org.apache.ivy.osgi.obr.xml.OBRXMLParser;
+import org.apache.ivy.osgi.repo.BundleRepoDescriptor;
+import org.apache.ivy.util.CollectionUtils;
+import org.apache.tools.ant.DefaultLogger;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.Delete;
+import org.xml.sax.SAXException;
+
+public class BuildOBRTaskTest extends TestCase {
+
+ private File cache;
+
+ private BuildOBRTask buildObr;
+
+ private Project project;
+
+ protected void setUp() throws Exception {
+ createCache();
+ project = new Project();
+ DefaultLogger logger = new DefaultLogger();
+ logger.setMessageOutputLevel(Project.MSG_INFO);
+ logger.setOutputPrintStream(System.out);
+ logger.setErrorPrintStream(System.err);
+ project.addBuildListener(logger);
+
+ buildObr = new BuildOBRTask();
+ buildObr.setProject(project);
+ System.setProperty("ivy.cache.dir", cache.getAbsolutePath());
+ }
+
+ private void createCache() {
+ cache = new File("build/cache");
+ cache.mkdirs();
+ }
+
+ protected void tearDown() throws Exception {
+ cleanCache();
+ }
+
+ private void cleanCache() {
+ Delete del = new Delete();
+ del.setProject(new Project());
+ del.setDir(cache);
+ del.execute();
+ }
+
+ private BundleRepoDescriptor readObr(File obrFile) throws
FileNotFoundException,
+ ParseException, IOException, SAXException {
+ BundleRepoDescriptor obr;
+ FileInputStream in = new FileInputStream(obrFile);
+ try {
+ obr = OBRXMLParser.parse(obrFile.toURI(), in);
+ } finally {
+ in.close();
+ }
+ return obr;
+ }
+
+ public void testDir() throws Exception {
+ buildObr.setBaseDir(new File("test/test-repo/bundlerepo"));
+ File obrFile = new File("build/cache/obr.xml");
+ buildObr.setOut(obrFile);
+ buildObr.execute();
+
+ BundleRepoDescriptor obr = readObr(obrFile);
+
+ assertEquals(12, CollectionUtils.toList(obr.getModules()).size());
+ }
+
+ public void testEmptyDir() throws Exception {
+ buildObr.setBaseDir(new File("test/test-p2/composite"));
+ File obrFile = new File("build/cache/obr.xml");
+ buildObr.setOut(obrFile);
+ buildObr.execute();
+
+ BundleRepoDescriptor obr = readObr(obrFile);
+
+ assertEquals(0, CollectionUtils.toList(obr.getModules()).size());
+ }
+
+ public void testResolve() throws Exception {
+ Project otherProject = new Project();
+ DefaultLogger logger = new DefaultLogger();
+ logger.setOutputPrintStream(System.out);
+ logger.setErrorPrintStream(System.err);
+ logger.setMessageOutputLevel(Project.MSG_INFO);
+ otherProject.addBuildListener(logger);
+
+ otherProject.setProperty("ivy.settings.file",
"test/test-repo/bundlerepo/ivysettings.xml");
+
+ IvyResolve resolve = new IvyResolve();
+ resolve.setProject(otherProject);
+ resolve.setFile(new File("test/test-repo/ivy-test-buildobr.xml"));
+ resolve.setResolveId("withResolveId");
+ resolve.execute();
+
+ File obrFile = new File("build/cache/obr.xml");
+
+ buildObr.setProject(otherProject);
+ buildObr.setResolveId("withResolveId");
+ buildObr.setOut(obrFile);
+ buildObr.execute();
+
+ BundleRepoDescriptor obr = readObr(obrFile);
+
+ assertEquals(1, CollectionUtils.toList(obr.getModules()).size());
+ }
+
+}
Propchange:
ant/ivy/core/trunk/test/java/org/apache/ivy/ant/BuildOBRTaskTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
ant/ivy/core/trunk/test/java/org/apache/ivy/ant/BuildOBRTaskTest.java
------------------------------------------------------------------------------
svn:keywords = Date Revision Author HeadURL Id
Propchange:
ant/ivy/core/trunk/test/java/org/apache/ivy/ant/BuildOBRTaskTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: ant/ivy/core/trunk/test/test-repo/bundlerepo/ivysettings.xml
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/test-repo/bundlerepo/ivysettings.xml?rev=1519300&view=auto
==============================================================================
--- ant/ivy/core/trunk/test/test-repo/bundlerepo/ivysettings.xml (added)
+++ ant/ivy/core/trunk/test/test-repo/bundlerepo/ivysettings.xml Sun Sep 1
18:08:36 2013
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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>
+ <settings defaultResolver="obr" />
+ <resolvers>
+ <obr name="obr" repoXmlFile="${ivy.settings.dir}/repo.xml" />
+ </resolvers>
+</ivysettings>
\ No newline at end of file
Propchange: ant/ivy/core/trunk/test/test-repo/bundlerepo/ivysettings.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ant/ivy/core/trunk/test/test-repo/bundlerepo/ivysettings.xml
------------------------------------------------------------------------------
svn:keywords = Date Revision Author HeadURL Id
Propchange: ant/ivy/core/trunk/test/test-repo/bundlerepo/ivysettings.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: ant/ivy/core/trunk/test/test-repo/ivy-test-buildobr.xml
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/test-repo/ivy-test-buildobr.xml?rev=1519300&view=auto
==============================================================================
--- ant/ivy/core/trunk/test/test-repo/ivy-test-buildobr.xml (added)
+++ ant/ivy/core/trunk/test/test-repo/ivy-test-buildobr.xml Sun Sep 1 18:08:36
2013
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<ivy-module version="2.3">
+ <info organisation="org.apache.ivy" module="test-buildobr" />
+ <dependencies>
+ <dependency org="bundle" name="org.apache.ivy.osgi.testbundle"
rev="1.2.3"/>
+ </dependencies>
+</ivy-module>
\ No newline at end of file
Propchange: ant/ivy/core/trunk/test/test-repo/ivy-test-buildobr.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ant/ivy/core/trunk/test/test-repo/ivy-test-buildobr.xml
------------------------------------------------------------------------------
svn:keywords = Date Revision Author HeadURL Id
Propchange: ant/ivy/core/trunk/test/test-repo/ivy-test-buildobr.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml