From notifications-return-16808-apmail-ant-notifications-archive=ant.apache.org@ant.apache.org Sun Sep 4 21:34:10 2011 Return-Path: X-Original-To: apmail-ant-notifications-archive@minotaur.apache.org Delivered-To: apmail-ant-notifications-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3A44070F8 for ; Sun, 4 Sep 2011 21:34:09 +0000 (UTC) Received: (qmail 2127 invoked by uid 500); 4 Sep 2011 21:34:08 -0000 Delivered-To: apmail-ant-notifications-archive@ant.apache.org Received: (qmail 2049 invoked by uid 500); 4 Sep 2011 21:34:08 -0000 Mailing-List: contact notifications-help@ant.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ant.apache.org Delivered-To: mailing list notifications@ant.apache.org Received: (qmail 2040 invoked by uid 99); 4 Sep 2011 21:34:08 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 04 Sep 2011 21:34:07 +0000 X-ASF-Spam-Status: No, hits=-1996.5 required=5.0 tests=ALL_TRUSTED,URIBL_BLACK X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 04 Sep 2011 21:34:02 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 387412388A68 for ; Sun, 4 Sep 2011 21:33:40 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1165117 - in /ant/ivy/core/trunk: ./ doc/ doc/resolver/ doc/settings/ src/java/org/apache/ivy/core/settings/ src/java/org/apache/ivy/plugins/repository/jar/ src/java/org/apache/ivy/plugins/resolver/ test/ test/java/org/apache/ivy/plugins/r... Date: Sun, 04 Sep 2011 21:33:39 -0000 To: notifications@ant.apache.org From: hibou@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110904213340.387412388A68@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: hibou Date: Sun Sep 4 21:33:39 2011 New Revision: 1165117 URL: http://svn.apache.org/viewvc?rev=1165117&view=rev Log: IVY-1312: - implementation, test and documentation of the jar resolver Added: ant/ivy/core/trunk/doc/resolver/jar.html (with props) ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/jar/ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/jar/JarRepository.java (with props) ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/jar/JarResource.java (with props) ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/JarResolver.java (with props) ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/resolver/JarResolverTest.java (with props) Modified: ant/ivy/core/trunk/CHANGES.txt ant/ivy/core/trunk/build.xml ant/ivy/core/trunk/doc/settings/resolvers.html ant/ivy/core/trunk/doc/toc.json ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/typedef.properties ant/ivy/core/trunk/test/ (props changed) Modified: ant/ivy/core/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=1165117&r1=1165116&r2=1165117&view=diff ============================================================================== --- ant/ivy/core/trunk/CHANGES.txt (original) +++ ant/ivy/core/trunk/CHANGES.txt Sun Sep 4 21:33:39 2011 @@ -127,6 +127,7 @@ for detailed view of each issue, please - NEW: ivy:resolve and post resole task can now have inlined dependencies declaration. - NEW: Import Bushel into Ivy core (IVY-1241) - NEW: An new resolver 'mirroredurl' which can handle a list of mirrored URL repositories (IVY-468) +- NEW: Support for a jar resolver (IVY-1312) - IMPROVEMENT: ivy:makepom ignores the artifact type in generated dependencies (IVY-1229) (thanks to Douglas Palmer) - IMPROVEMENT: ivy:makepom now honors exclusion of artifacts in generated pom files (IVY-1294) (thanks to Jens Rohloff) Modified: ant/ivy/core/trunk/build.xml URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/build.xml?rev=1165117&r1=1165116&r2=1165117&view=diff ============================================================================== --- ant/ivy/core/trunk/build.xml (original) +++ ant/ivy/core/trunk/build.xml Sun Sep 4 21:33:39 2011 @@ -431,6 +431,15 @@ + + + + + + + + + Added: ant/ivy/core/trunk/doc/resolver/jar.html URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/doc/resolver/jar.html?rev=1165117&view=auto ============================================================================== --- ant/ivy/core/trunk/doc/resolver/jar.html (added) +++ ant/ivy/core/trunk/doc/resolver/jar.html Sun Sep 4 21:33:39 2011 @@ -0,0 +1,89 @@ + + + + + + + + + + + + Propchange: ant/ivy/core/trunk/doc/resolver/jar.html ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ant/ivy/core/trunk/doc/resolver/jar.html ------------------------------------------------------------------------------ svn:keywords = Date Revision Author HeadURL Id Propchange: ant/ivy/core/trunk/doc/resolver/jar.html ------------------------------------------------------------------------------ svn:mime-type = text/html Modified: ant/ivy/core/trunk/doc/settings/resolvers.html URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/doc/settings/resolvers.html?rev=1165117&r1=1165116&r2=1165117&view=diff ============================================================================== --- ant/ivy/core/trunk/doc/settings/resolvers.html (original) +++ ant/ivy/core/trunk/doc/settings/resolvers.html Sun Sep 4 21:33:39 2011 @@ -68,6 +68,7 @@ Here is the list of built-in resolvers: VfsStandardFinds ivy files and artifacts in any repository accessible with apache commons vfs. sshStandardFinds ivy files and artifacts in any repository accessible with ssh. sftpStandardFinds ivy files and artifacts in any repository accessible with sftp. +JarStandardFinds ivy files and artifacts within a specified jar. ChainCompositeDelegates the finding to a chain of sub resolvers. DualCompositeDelegates the finding of ivy files to one resolver and of artifacts to another. OBRStandardResolve modules as OSGi bundles listed by an OSGi obr.xml. Modified: ant/ivy/core/trunk/doc/toc.json URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/doc/toc.json?rev=1165117&r1=1165116&r2=1165117&view=diff ============================================================================== --- ant/ivy/core/trunk/doc/toc.json (original) +++ ant/ivy/core/trunk/doc/toc.json Sun Sep 4 21:33:39 2011 @@ -359,7 +359,14 @@ }, { "id":"resolver/vfs", - "title":"vfs", + "title":"vfs resolver", + "children": [ + + ] + }, + { + "id":"resolver/jar", + "title":"Jar resolver", "children": [ ] Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/typedef.properties URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/typedef.properties?rev=1165117&r1=1165116&r2=1165117&view=diff ============================================================================== --- ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/typedef.properties (original) +++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/typedef.properties Sun Sep 4 21:33:39 2011 @@ -26,6 +26,7 @@ ssh = org.apache.ivy.plugins.res sftp = org.apache.ivy.plugins.resolver.SFTPResolver vsftp = org.apache.ivy.plugins.resolver.VsftpResolver vfs = org.apache.ivy.plugins.resolver.VfsResolver +jar = org.apache.ivy.plugins.resolver.JarResolver cache = org.apache.ivy.plugins.resolver.CacheResolver packager = org.apache.ivy.plugins.resolver.packager.PackagerResolver obr = org.apache.ivy.osgi.obr.OBRResolver Added: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/jar/JarRepository.java URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/jar/JarRepository.java?rev=1165117&view=auto ============================================================================== --- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/jar/JarRepository.java (added) +++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/jar/JarRepository.java Sun Sep 4 21:33:39 2011 @@ -0,0 +1,89 @@ +/* + * 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.plugins.repository.jar; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.jar.JarFile; +import java.util.zip.ZipEntry; + +import org.apache.ivy.plugins.repository.AbstractRepository; +import org.apache.ivy.plugins.repository.RepositoryCopyProgressListener; +import org.apache.ivy.plugins.repository.Resource; +import org.apache.ivy.plugins.repository.TransferEvent; +import org.apache.ivy.util.FileUtil; + +public class JarRepository extends AbstractRepository { + + private RepositoryCopyProgressListener progress = new RepositoryCopyProgressListener(this); + + private JarFile jarFile; + + public void setJarFile(JarFile jarFile) { + this.jarFile = jarFile; + } + + public Resource getResource(String source) throws IOException { + return new JarResource(jarFile, source); + } + + protected RepositoryCopyProgressListener getProgressListener() { + return progress; + } + + public void get(String source, File destination) throws IOException { + fireTransferInitiated(getResource(source), TransferEvent.REQUEST_GET); + try { + ZipEntry entry = jarFile.getEntry(source); + if (entry == null) { + throw new FileNotFoundException(); + } + getProgressListener().setTotalLength(new Long(entry.getSize())); + FileUtil.copy(jarFile.getInputStream(entry), destination, getProgressListener()); + } catch (IOException ex) { + fireTransferError(ex); + throw ex; + } catch (RuntimeException ex) { + fireTransferError(ex); + throw ex; + } finally { + getProgressListener().setTotalLength(null); + } + } + + public List/* */list(String parent) throws IOException { + ZipEntry parentEntry = jarFile.getEntry(parent); + if (parentEntry == null || !parentEntry.isDirectory()) { + return null; + } + List/* */children = new ArrayList(); + Enumeration entries = jarFile.entries(); + while (entries.hasMoreElements()) { + ZipEntry entry = (ZipEntry) entries.nextElement(); + if (entry.getName().startsWith(parent) && entry.getName().equals(parentEntry.getName())) { + children.add(entry.getName()); + } + } + return children; + } + +} Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/jar/JarRepository.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/jar/JarRepository.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Author HeadURL Id Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/jar/JarRepository.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/jar/JarResource.java URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/jar/JarResource.java?rev=1165117&view=auto ============================================================================== --- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/jar/JarResource.java (added) +++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/jar/JarResource.java Sun Sep 4 21:33:39 2011 @@ -0,0 +1,69 @@ +/* + * 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.plugins.repository.jar; + +import java.io.IOException; +import java.io.InputStream; +import java.util.jar.JarFile; +import java.util.zip.ZipEntry; + +import org.apache.ivy.plugins.repository.Resource; + +public class JarResource implements Resource { + + private final JarFile jarFile; + + private final String path; + + private ZipEntry entry; + + public JarResource(JarFile jarFile, String path) { + this.jarFile = jarFile; + this.path = path; + entry = jarFile.getEntry(path); + } + + public String getName() { + return path; + } + + public long getLastModified() { + return entry.getTime(); + } + + public long getContentLength() { + return entry.getSize(); + } + + public boolean exists() { + return entry != null; + } + + public boolean isLocal() { + return true; + } + + public Resource clone(String cloneName) { + return new JarResource(jarFile, cloneName); + } + + public InputStream openStream() throws IOException { + return jarFile.getInputStream(entry); + } + +} Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/jar/JarResource.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/jar/JarResource.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Author HeadURL Id Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/jar/JarResource.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/JarResolver.java URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/JarResolver.java?rev=1165117&view=auto ============================================================================== --- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/JarResolver.java (added) +++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/JarResolver.java Sun Sep 4 21:33:39 2011 @@ -0,0 +1,89 @@ +/* + * 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.plugins.resolver; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.jar.JarFile; + +import org.apache.ivy.core.cache.CacheResourceOptions; +import org.apache.ivy.core.event.EventManager; +import org.apache.ivy.core.report.ArtifactDownloadReport; +import org.apache.ivy.plugins.repository.Resource; +import org.apache.ivy.plugins.repository.jar.JarRepository; +import org.apache.ivy.plugins.repository.url.URLResource; + +public class JarResolver extends RepositoryResolver { + + public JarResolver() { + setRepository(new JarRepository()); + } + + public String getTypeName() { + return "jar"; + } + + public void setFile(String jarFile) { + setJarFile(new File(jarFile)); + } + + public void setUrl(String jarUrl) { + URL url; + try { + url = new URL(jarUrl); + } catch (MalformedURLException e) { + throw new RuntimeException("the jar repository " + getName() + + " has an malformed url : " + jarUrl + " (" + e.getMessage() + ")"); + } + + ArtifactDownloadReport report; + EventManager eventManager = getEventManager(); + try { + if (eventManager != null) { + getRepository().addTransferListener(eventManager); + } + Resource jarResource = new URLResource(url); + CacheResourceOptions options = new CacheResourceOptions(); + report = getRepositoryCacheManager().downloadRepositoryResource(jarResource, + "jarrepository", "jar", "jar", options, getRepository()); + } finally { + if (eventManager != null) { + getRepository().removeTransferListener(eventManager); + } + } + setJarFile(report.getLocalFile()); + } + + public JarRepository getJarRepository() { + return (JarRepository) super.getRepository(); + } + + private void setJarFile(File jarLocalFile) { + JarFile jar; + try { + jar = new JarFile(jarLocalFile); + } catch (IOException e) { + throw new RuntimeException("the jar repository " + getName() + " could not be read (" + + e.getMessage() + ")", e); + } + getJarRepository().setJarFile(jar); + } + +} Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/JarResolver.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/JarResolver.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Author HeadURL Id Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/JarResolver.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Propchange: ant/ivy/core/trunk/test/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Sun Sep 4 21:33:39 2011 @@ -0,0 +1 @@ +jar-repos Added: ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/resolver/JarResolverTest.java URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/resolver/JarResolverTest.java?rev=1165117&view=auto ============================================================================== --- ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/resolver/JarResolverTest.java (added) +++ ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/resolver/JarResolverTest.java Sun Sep 4 21:33:39 2011 @@ -0,0 +1,91 @@ +/* + * 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.plugins.resolver; + +import java.io.File; + +import junit.framework.TestCase; + +import org.apache.ivy.core.cache.DefaultRepositoryCacheManager; +import org.apache.ivy.core.event.EventManager; +import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.resolve.ResolveData; +import org.apache.ivy.core.resolve.ResolveEngine; +import org.apache.ivy.core.resolve.ResolveOptions; +import org.apache.ivy.core.resolve.ResolvedModuleRevision; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.core.sort.SortEngine; +import org.apache.ivy.util.CacheCleaner; + +public class JarResolverTest extends TestCase { + + private IvySettings settings; + + private File cache; + + private ResolveEngine engine; + + private ResolveData data; + + private DefaultRepositoryCacheManager cacheManager; + + protected void setUp() throws Exception { + settings = new IvySettings(); + engine = new ResolveEngine(settings, new EventManager(), new SortEngine(settings)); + cache = new File("build/cache"); + data = new ResolveData(engine, new ResolveOptions()); + cache.mkdirs(); + settings.setDefaultCache(cache); + cacheManager = (DefaultRepositoryCacheManager) settings.getDefaultRepositoryCacheManager(); + } + + protected void tearDown() throws Exception { + CacheCleaner.deleteDir(cache); + } + + public void testSimpleFile() throws Exception { + JarResolver resolver = new JarResolver(); + resolver.setName("jarresolver1"); + resolver.setSettings(settings); + resolver.setFile(new File("test/jar-repos/jarrepo1.jar").getAbsolutePath()); + resolver.addIvyPattern("[organisation]/[module]/ivys/ivy-[revision].xml"); + resolver.addArtifactPattern("[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"); + ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, + false), data); + assertNotNull(rmr); + + } + + public void testSubdirInFile() throws Exception { + JarResolver resolver = new JarResolver(); + resolver.setName("jarresolver1_subdir"); + resolver.setSettings(settings); + resolver.setFile(new File("test/jar-repos/jarrepo1_subdir.jar").getAbsolutePath()); + resolver.addIvyPattern("1/[organisation]/[module]/ivys/ivy-[revision].xml"); + resolver.addArtifactPattern("1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"); + ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, + false), data); + assertNotNull(rmr); + + } +} Propchange: ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/resolver/JarResolverTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/resolver/JarResolverTest.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Author HeadURL Id Propchange: ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/resolver/JarResolverTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain